How to treat single newline as real line break in PHP Markdown?

前端 未结 4 1690
说谎
说谎 2021-02-06 01:44

I was reading http://github.github.com/github-flavored-markdown/

I would like to implement that \"Newline modification\" in PHP Markdown:

Best I could think of

4条回答
  •  滥情空心
    2021-02-06 02:21

    Look for line in your markdown file:

    function doHardBreaks($text) {
    

    and change the preg pattern below it from:

    return preg_replace_callback('/ {2,}\n/', array(&$this, '_doHardBreaks_callback'), $text);
    

    to:

    return preg_replace_callback('/ {2,}\n|\n{1}/', array(&$this, '_doHardBreaks_callback'), $text);
    

    Or you can just extend the markdown class, redeclare 'doHardBreaks' function, and change the return into something like code above

    Regards, Achmad

提交回复
热议问题