parsedown icon indicating copy to clipboard operation
parsedown copied to clipboard

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

Open bkdotcom opened this issue 6 years ago • 3 comments

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?

bkdotcom avatar Aug 09 '19 16:08 bkdotcom

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

aidantwoods avatar Aug 09 '19 17:08 aidantwoods

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
);

bkdotcom avatar Aug 09 '19 19:08 bkdotcom

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

shijunti19 avatar Jan 25 '23 09:01 shijunti19