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 5e2a294
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/reverse_markdown/converters/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def remove_border_newlines(text)
end

def remove_inner_newlines(text)
text.tr("\r\n\t", ' ').squeeze(' ')
text.tr("\r\t", ' ').squeeze(' ')
end

def preserve_keychars_within_backticks(text)
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 5e2a294

Please sign in to comment.