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 df3819a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion reverse_markdown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 df3819a

Please sign in to comment.