如何将单个换行符视为PHP Markdown中的实际换行符? [英] How to treat single newline as real line break in PHP Markdown?

查看:93
本文介绍了如何将单个换行符视为PHP Markdown中的实际换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 http://github.github.com/github-flavored-markdown/

我想在PHP Markdown中实现换行修改":

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

我能想到的最好的是:

$my_html = Markdown($my_text);
$my_html = preg_replace("/\n{1}/", "<br/>", $my_html);

但是,这非常不可思议.

But this runs very unexpectable.

推荐答案

在降价文件中查找行:

function doHardBreaks($text) {

,然后从下面更改其预浸图案:

and change the preg pattern below it from:

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

收件人:

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

或者您可以扩展markdown类,重新声明'doHardBreaks'函数,并将返回值更改为类似于上面的代码

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

致谢,阿奇玛德

这篇关于如何将单个换行符视为PHP Markdown中的实际换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆