javascriptphpcomposer-phpmarkdownphp-parser

Markdown - PHP parser


Do you know about some markdown PHP parser, with code highlight, etc, like the GitHub markdown parser or https://stackedit.io/editor?

If it is available via Composer then better.

I've tried:

https://packagist.org/packages/michelf/php-markdown

https://packagist.org/packages/league/commonmark

https://packagist.org/packages/erusev/parsedown

but the result of all these are almost plain text.

The best result belongs to michelf/php-markdown as you can see on the following image:

enter image description here

$ composer require michelf/php-markdown

---

use Michelf\MarkdownExtra;

$parser = new MarkdownExtra();
$html = $parser->transform($markdown);

echo $html;

[EDIT 1]

Now I'm almost at my goal.

I used:

https://github.com/sindresorhus/github-markdown-css

And now I get a result very similar to GitHub but the code is not getting highlighted (with colors) according the corresponded language (on this case: html) as you can see on the following image:

enter image description here

Then my QUESTION now is:

what extra step do I need to do in order to get code syntax highlight like GitHub does?. Please, check the following GitHub's output:

enter image description here


Solution

  • I guess you are missing CSS styles for the rendered HTML.

    The generated HTML looks actually ok.

    Try to include the styles in the document where you echo the $html.

    For example use Github styles like this:
    https://github.com/sindresorhus/github-markdown-css