jgm/commonmark-hs

Hard line-breaks aren't handled correctly

agrafix opened this issue · 4 comments

Thank you for this awesome library!

I'm getting unexpected results when rendering markdown with hard line-breaks:

Example input:

This is a test for how newlines \
are handled.

\

**Testing** \ 
More \
Okay

Output:

<p>This is a test for how newlines <br />
are handled.</p>
<p>\</p>
<p><strong>Testing</strong> \
More <br />
Okay</p>

Expected Output:

<p>This is a test for how newlines <br />
are handled.</p>
<br />
<p><strong>Testing</strong> <br />
More <br />
Okay</p>
jgm commented

Note: In the terminology of the commonmark spec, these are hard line breaks.

But this behavior accords with the spec, which says:

Hard line breaks are for separating inline content within a block. Neither syntax for hard line breaks works at the end of a paragraph or other block element:

Got it -- thanks for the quick reply! It seems like the free standing \ confuses the parser and that's why the sub-sequent use of it doesn't work anymore in

**Testing** \ 
More \
Okay
jgm commented

Ah, okay, there were two issues here and I only noticed the first (which is not a bug, the \ in a paragraph by itself).

The second issue (the \ after ** ) does look like a bug.

jgm commented

Wait -- you have a space right after the \ on the line with **Testing**. So it doesn't count as a backslash immediately before a newline. Not a bug after all. Expected behavior.