duanlumei5941 2013-04-17 06:11
浏览 36
已采纳

从PHP Markdown中删除对词内强调的支持

I'm trying to modify PHP Markdown to implement 2 out of the 3 changes Jeff Attwood suggested, namely, enabling return based line breaks and removing support for intra word emphasis.

I was able to do the first quite easily learning from How to treat single newline as real line break in PHP Markdown?, but I'm finding the second very difficult to implement. There is this question on SO that deals with it, but since I don't really understand regexes yet, I don't know how to implement the given solution.

What modification do I need to make to Michel Fortin's PHP Markdown to turn off intra word emphasis?

  • 写回答

1条回答 默认 最新

  • dougezhua0017 2013-04-17 06:21
    关注

    I found the answer later by digging inside PHP Markdown Extra.

    protected $em_relist = array(
        ''  => '(?:(?<!\*)\*(?!\*)|(?<!_)_(?!_))(?=\S|$)(?![\.,:;]\s)',
        '*' => '(?<=\S|^)(?<!\*)\*(?!\*)',
        '_' => '(?<=\S|^)(?<!_)_(?!_)',
        );
    protected $strong_relist = array(
        ''   => '(?:(?<!\*)\*\*(?!\*)|(?<!_)__(?!_))(?=\S|$)(?![\.,:;]\s)',
        '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)',
        '__' => '(?<=\S|^)(?<!_)__(?!_)',
        );
    protected $em_strong_relist = array(
        ''    => '(?:(?<!\*)\*\*\*(?!\*)|(?<!_)___(?!_))(?=\S|$)(?![\.,:;]\s)',
        '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)',
        '___' => '(?<=\S|^)(?<!_)___(?!_)',
        );
    

    to this:

    protected $em_relist = array(
        ''  => '(?:(?<!\*)\*(?!\*)|(?<![a-zA-Z0-9_])_(?!_))(?=\S|$)(?![\.,:;]\s)',
        '*' => '(?<=\S|^)(?<!\*)\*(?!\*)',
        '_' => '(?<=\S|^)(?<!_)_(?![a-zA-Z0-9_])',
        );
    protected $strong_relist = array(
        ''   => '(?:(?<!\*)\*\*(?!\*)|(?<![a-zA-Z0-9_])__(?!_))(?=\S|$)(?![\.,:;]\s)',
        '**' => '(?<=\S|^)(?<!\*)\*\*(?!\*)',
        '__' => '(?<=\S|^)(?<!_)__(?![a-zA-Z0-9_])',
        );
    protected $em_strong_relist = array(
        ''    => '(?:(?<!\*)\*\*\*(?!\*)|(?<![a-zA-Z0-9_])___(?!_))(?=\S|$)(?![\.,:;]\s)',
        '***' => '(?<=\S|^)(?<!\*)\*\*\*(?!\*)',
        '___' => '(?<=\S|^)(?<!_)___(?![a-zA-Z0-9_])',
        );
    

    does the job perfectly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办