Skip to content

馃悰 FIX: keep the hard line break after a literal backslash - #417

Open
eeshsaxena wants to merge 1 commit into
executablebooks:masterfrom
eeshsaxena:fix/backslash-space-hardbreak
Open

馃悰 FIX: keep the hard line break after a literal backslash#417
eeshsaxena wants to merge 1 commit into
executablebooks:masterfrom
eeshsaxena:fix/backslash-space-hardbreak

Conversation

@eeshsaxena

Copy link
Copy Markdown

markdown-it-py renders a literal backslash immediately before a two-space hard line break as a soft break with a stray space, rather than a hard break:

from markdown_it import MarkdownIt

MarkdownIt("commonmark").render("foo\\  \nbar")
# markdown-it-py: '<p>foo\\ \nbar</p>\n'
# markdown-it:    '<p>foo\\<br />\nbar</p>\n'

markdown-it's escape rule has a dedicated case for this: when a \ is followed by a space it emits just the backslash and leaves the space unconsumed, so the trailing two-space hard break is still detected by the newline rule (its escape.mjs even carries a comment to that effect). This port jumped straight to the generic escape branch, which consumed the space and left only one space before the newline, so the hard break was downgraded to a soft break.

This ports the missing space case so the output matches markdown-it. I added a regression test in test_misc.py, and the test_cmark_spec and test_port suites still pass.

markdown-it's escape rule leaves the space after a literal backslash
unconsumed, so a following two-space hard line break is still detected by
the newline rule. This port jumped straight to the generic escape branch,
which consumed the space, leaving only one space before the newline. As a
result `foo\  \nbar` produced a soft break with a stray backslash-space
instead of `foo\<br />`. Port the missing space case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant