vmg / redcarpet

The safe Markdown parser, reloaded.
MIT License
4.99k stars 527 forks source link

Render::HTML.new(hard_wrap: true) + two trailing spaces => extra <br> #701

Open bkazez opened 3 years ago

bkazez commented 3 years ago

Two extra trailing spaces + hard_warp: true => extra
inserted:

markdown_renderer = Redcarpet::Markdown.new(
  Redcarpet::Render::HTML.new(hard_wrap: true),
)
markdown_renderer.render("hello  \nworld")

=>"<p>hello<br><br>\nworld</p>\n"

With just one extra trailing space, or with hard_wrap: false, this does not occur.

dlinch commented 2 years ago

Hi @bkazez, not a maintainer but I noticed this issue locally. If you pass the arguments through to the Redcarpet::Markdown class, you'll see the behavior you're looking for.

# Your Example, passing options into HTML.new
markdown_renderer = Redcarpet::Markdown.new(
  Redcarpet::Render::HTML.new(hard_wrap: true),
)
markdown_renderer.render("hello  \nworld")
=>  "<p>hello<br><br>\nworld</p>\n"

# My Example, passing options as arg to Markdown.new
markdown_renderer = Redcarpet::Markdown.new(
  Redcarpet::Render::HTML.new,
  hard_wrap: true),
)
markdown_renderer.render("hello  \nworld")
=>  "<p>hello<br>\nworld</p>\n"
bkazez commented 2 years ago

Thanks @dlinch! I tried this and don't get any hard wrapping at all — things like\nthis aren't translated into like<br>this.

dlinch commented 2 years ago

@bkazez I found a combination of the hard_wrap and the lax_spacing options generally worked the way I expected.