thephpleague / html-to-markdown

Convert HTML to Markdown with PHP
MIT License
1.77k stars 205 forks source link

Add option to turn <br> tags into {newline} instead of {space}{space}{newline} #112

Closed IllyaMoskvin closed 7 years ago

IllyaMoskvin commented 7 years ago

According to the traditional Markdown spec, inserting <br> requires ending a line with two or more spaces, then typing return. However, various flavors of Markdown, including most notably GitHub Flavored Markdown (GFM), implement hard line breaks, where newline characters inside paragraphs will be turned into <br> tags. See :hard-wrap option in vmg/redcarpet, which GitHub uses to render certain parts of the site. See also the enableNewlines option in cebe/markdown for a PHP implementation.

For terminology, see this StackOverflow question, and this CommonMark spec post.

This is a contentious issue. Users of editors that soft-wrap the text tend to advocate for hard line breaks, while users of editors that hard-wrap the text tend to advocate for soft line breaks. There are many other considerations, including backward compatibility, but the bottom line is that there are strong opposing preferences for both syntaxes.

I propose adding a config flag that enables conversion of <br> to \n instead of {space}{space}\n as is currently the case. This will satisfy those of us who use soft-wrapping editors (e.g. SimpleMDE), and those who prefer GFM over traditional Markdown or CommonMark. The default behavior should remain the same.

I'll attempt to implement this change on the IUAM/html-to-markdown fork and submit a PR.

I'm not sure what to name the flag. Tentatively proposing hard_break. Let me know your thoughts.

I don't want to start a debate about the merits of one syntax over the other. Please refer to the external discussions to voice your view. I just want to give the users of this library an option to use either syntax.

Related External Discussions:

Related Issues:

80, #87