Skip to content

Commit

Permalink
Lets \n to be present in <pre> tag. solves xijo#77
Browse files Browse the repository at this point in the history
  • Loading branch information
shivabhusal committed Oct 2, 2019
1 parent d18fd18 commit 63b5019
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/reverse_markdown/converters/pre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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", '<br>').strip.gsub('<br>', "\n"))
when 'br'
"\n"
else
Expand Down
12 changes: 11 additions & 1 deletion spec/lib/reverse_markdown/converters/pre_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
expect(converter.convert(node)).to include " puts foo\n"
end

it 'preserves new lines' do
it 'preserves new lines as <br>' do
node = node_for("<pre>one<br>two<br>three</pre>")
expect(converter.convert(node)).to include "\n\n one\n two\n three\n\n"
end

it 'preserves new lines as <br> and \n' do
node = node_for("<pre>one\ntwo\nthree<br>four</pre>")
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("<pre><code>foobar</code></pre>")
Expand All @@ -41,6 +46,11 @@
expect(converter.convert(node)).to include "```\nfoo\nbar\n```"
end

it 'preserves new lines as <br> and \n' do
node = node_for("<pre>one\ntwo\nthree<br>four</pre>")
expect(converter.convert(node)).to include "```\none\ntwo\nthree\nfour\n```"
end

it 'handles code tags correctly' do
node = node_for("<pre><code>foobar</code></pre>")
expect(converter.convert(node)).to include "```\nfoobar\n```"
Expand Down

0 comments on commit 63b5019

Please sign in to comment.