pragdave / earmark

Markdown parser for Elixir
Other
869 stars 136 forks source link

Extra newline generated in HTML #399

Closed stefanchrobot closed 3 years ago

stefanchrobot commented 3 years ago

Hey, why the extra newline inside <h1>? This seems like a regression. Our unit tests started failing.

iex(1)> Earmark.as_html("# Title")
{:ok, "<h1>\nTitle</h1>\n", []}
RobertDober commented 3 years ago

I am sorry it does, I'll have a look as soon as possible.

I do not want to vary the output just for fun of course but I do not consider that kind of behavioural change a bug.

That said, I'll try to accommodate you as much as possible as this behaviour was not planned, given my schedule I would suggest though to make your tests a little bit more tolerant towards formatting.

It is often times considered a good idea to test against parsed HTML e.g. using Floki, but again, if I can change this I will.

RobertDober commented 3 years ago

I just checked the code, and the tests, the pending "\n" has been there for a long time, from which version did you upgrade?

But I must reject this issue, sorry.

Apart from the idea of parsing the HTML maybe you can resolve your issue with the new compact_output option

iex(3)> Earmark.as_html("x")     
{:ok, "<p>\nx</p>\n", []}
iex(4)> Earmark.as_html("x", compact_output: true)
{:ok, "<p>x</p>", []}
stefanchrobot commented 3 years ago

Agreed, semantically there is no change. Though I'd say the redundant whitespace is surprising and a bit of a waste. I upgraded from 1.4.4.