Can I define a class name on paragraph using Markdown?

后端 未结 10 1041
灰色年华
灰色年华 2020-12-02 08:04

Can I define a class name on paragraph using Markdown? If so, how?

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 08:42

    Dupe: How do I set an HTML class attribute in Markdown?


    Natively? No. But...

    No, Markdown's syntax can't. You can set ID values with Markdown Extra through.

    You can use regular HTML if you like, and add the attribute markdown="1" to continue markdown-conversion within the HTML element. This requires Markdown Extra though.

    **Another paragraph** which allows *Markdown* within it.

    Possible Solution: (Untested and intended for
    )

    I found the following online:

    Function

    function _DoBlockQuotes_callback($matches) {
    
        ...cut...
    
        //add id and class details...
        $id = $class = '';
        if(preg_match_all('/\{(?:([#.][-_:a-zA-Z0-9 ]+)+)\}/',$bq,$matches)) {
            foreach ($matches[1] as $match) {
                if($match[0]=='#') $type = 'id';
                else $type = 'class';
                ${$type} = ' '.$type.'="'.trim($match,'.# ').'"';
            }
            foreach ($matches[0] as $match) {
                $bq = str_replace($match,'',$bq);
            }
        }
    
        return _HashBlock(
            "\n$bq\n"
        ) . "\n\n";
    }
    

    Markdown

    >{.className}{#id}This is the blockquote
    

    Result

    This is the blockquote

提交回复
热议问题