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.

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

报告相同问题?