How to parse Markdown in PHP?

后端 未结 5 928
误落风尘
误落风尘 2020-12-23 20:48

First, I know, there already is a Markdown parser for PHP. I also took a look to this question but it doesn\'t answer to my question.

Obviously, even if the title me

5条回答
  •  心在旅途
    2020-12-23 21:26

    Ciconia - A New Markdown Parser for PHP is a good one I found.

    You just need 3 things to do :

    1.Install Ciconia and parse file according to the document.
    2. Add corresponding css theme to make it nice, like github markdown style or here.
    3. Add syntax highlighting javascript, like google Javascript code prettifier.

    Then everything will look pretty good.

    If you want a complete example, here is my working demo for github style markdown:

    addExtension(new Gfm\FencedCodeBlockExtension());
    $ciconia->addExtension(new Gfm\TaskListExtension());
    $ciconia->addExtension(new Gfm\InlineStyleExtension());
    $ciconia->addExtension(new Gfm\WhiteSpaceExtension());
    $ciconia->addExtension(new Gfm\TableExtension());
    $ciconia->addExtension(new Gfm\UrlAutoLinkExtension());
    $contents = file_get_contents('Readme.md');
    $html = $ciconia->render($contents);
    ?>
    
    
        
            Excel to Lua table - Readme
            
            
            
        
        
            

提交回复
热议问题