Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.71k stars 856 forks source link

A line ending that is preceded by a backslash is not parsed as a hard line break #1464

Closed AUVESY-Nachwuchskraefte closed 3 months ago

AUVESY-Nachwuchskraefte commented 3 months ago

good morning everyone!

when trying to render linebreaks within paragraphs with a backslash at the end of the line as in the spec the backslash will not be used as a formatting character but stay as is.

# linebreaks

asd
asd

das\
das

sad  # 2 spaces
sad

## python-markdown

<h1>linebreaks</h1>
<p>asd
asd</p>
<p>das\
das</p>
<p>sad<br />
sad</p>

## mistletoe

<h1>linebreaks</h1>
<p>asd
asd</p>
<p>das<br />
das</p>
<p>sad<br />
sad</p>
facelessuser commented 3 months ago

@AUVESY-Nachwuchskraefte Python Markdown is an old-school Markdown parser that predates CommonMark. It is not a CommonMark parser, so any expectations that it should adhere to the CommonMark spec need to be set aside.

With that said, you can get the behavior you are looking for with this extension: https://facelessuser.github.io/pymdown-extensions/extensions/escapeall/.

waylan commented 3 months ago

As our documentation notes:

This is not a CommonMark implementation; nor is it trying to be! Python-Markdown was developed long before the CommonMark specification was released and has always (mostly) followed the syntax rules and behavior of the original reference implementation. No accommodations have been made to address the changes which CommonMark has suggested. It is recommended that you look elsewhere if you want an implementation which follows the CommonMark specification.

Note that backslash escapes are only applied to a subset of characters as defined in the rules and a newline is not one of them (see BACKSLASH ESCAPES). Therefore, there should be no expectation that a backslash escape would have any effect on a newline character. Instead, the rules provide for a hard break by preceding a newline with two or more spaces (see PARAGRAPHS AND LINE BREAKS).

Given the above, this is being closed as wontfix.

AUVESY-Nachwuchskraefte commented 3 months ago

Thank you for your response, I overlooked the "note" in your documentation.

@facelessuser thanks for your provided solution, I will try it.