From df3819ad541471dbb91501c83386e279e36f2839 Mon Sep 17 00:00:00 2001 From: Shiva Bhusal Date: Wed, 2 Oct 2019 13:28:45 +0545 Subject: [PATCH] Lets \n to be present in
 tag. solves #77

---
 lib/reverse_markdown/converters/pre.rb           |  3 +++
 reverse_markdown.gemspec                         |  2 +-
 spec/lib/reverse_markdown/converters/pre_spec.rb | 12 +++++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/reverse_markdown/converters/pre.rb b/lib/reverse_markdown/converters/pre.rb
index 72efdff..ceb9049 100644
--- a/lib/reverse_markdown/converters/pre.rb
+++ b/lib/reverse_markdown/converters/pre.rb
@@ -17,6 +17,9 @@ def treat(node, state)
         case node.name
         when 'code'
           node.text
+        when 'text'
+          # Preserve '\n' in the middle of text/words, get rid of indentation spaces
+          ReverseMarkdown.cleaner.remove_leading_newlines(node.text.gsub("\n", '
').strip.gsub('
', "\n")) when 'br' "\n" else diff --git a/reverse_markdown.gemspec b/reverse_markdown.gemspec index bc43d93..c3b3ee7 100644 --- a/reverse_markdown.gemspec +++ b/reverse_markdown.gemspec @@ -24,6 +24,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'simplecov' s.add_development_dependency 'rake' s.add_development_dependency 'kramdown' - # s.add_development_dependency 'byebug' + s.add_development_dependency 'byebug' s.add_development_dependency 'codeclimate-test-reporter' end diff --git a/spec/lib/reverse_markdown/converters/pre_spec.rb b/spec/lib/reverse_markdown/converters/pre_spec.rb index 18f8a9f..02ac94c 100644 --- a/spec/lib/reverse_markdown/converters/pre_spec.rb +++ b/spec/lib/reverse_markdown/converters/pre_spec.rb @@ -12,10 +12,15 @@ expect(converter.convert(node)).to include " puts foo\n" end - it 'preserves new lines' do + it 'preserves new lines as
' do node = node_for("
one
two
three
") expect(converter.convert(node)).to include "\n\n one\n two\n three\n\n" end + + it 'preserves new lines as
and \n' do + node = node_for("
one\ntwo\nthree
four
") + expect(converter.convert(node)).to include "\n\n one\n two\n three\n four\n\n" + end it 'handles code tags correctly' do node = node_for("
foobar
") @@ -41,6 +46,11 @@ expect(converter.convert(node)).to include "```\nfoo\nbar\n```" end + it 'preserves new lines as
and \n' do + node = node_for("
one\ntwo\nthree
four
") + expect(converter.convert(node)).to include "```\none\ntwo\nthree\nfour\n```" + end + it 'handles code tags correctly' do node = node_for("
foobar
") expect(converter.convert(node)).to include "```\nfoobar\n```"