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/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") expect(converter.convert(node)).to include "\n\n one\n two\n three\n\n" end + + it 'preserves new lines as
two
three
one\ntwo\nthree") + 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("
four
foobar
")
@@ -41,6 +46,11 @@
expect(converter.convert(node)).to include "```\nfoo\nbar\n```"
end
+ it 'preserves new lines as one\ntwo\nthree") + expect(converter.convert(node)).to include "```\none\ntwo\nthree\nfour\n```" + end + it 'handles code tags correctly' do node = node_for("
four
foobar
")
expect(converter.convert(node)).to include "```\nfoobar\n```"