erusev / parsedown

Better Markdown Parser in PHP
https://parsedown.org
MIT License
14.77k stars 1.12k forks source link

feature request option for \n => <br /> #722

Open bkdotcom opened 5 years ago

bkdotcom commented 5 years ago

I realize that to get a line break in markdown you end the line with two spaces.. Some flavors of markdown don't require two-spaces and automatically convert \n to <br /> (ie this very comment box on github doesn't require two spaces for a line break)

Can this be an option?

aidantwoods commented 5 years ago

Does ->setBreaksEnabled(true) give the functionality you're after (it's not exactly \n -> <br> but it aims to replicate GitHub's behaviour).

bkdotcom commented 5 years ago

It does not. :( But I must admit I didn't know about that method... guilty of not looking at the source.

This seems to work pretty well

$html = \preg_replace(
    '#(?:<br />\n)?<br />(</\w+>)#', 
    '$1', 
    \preg_replace('#^(.+)\n#m', '$1<br />'."\n", $markdown)   // a more selective nl2br
);
shijunti19 commented 1 year ago

支持,打四个空格太麻烦了