A CLI Markdown Render for league/commonmark compatible AST

1.0.0 2022-11-21 21:02 UTC

This package is auto-updated.

Last update: 2024-02-10 13:33:26 UTC


<img src="">

Build Status Windows Build Status Coverage Status


require_once 'vendor/autoload.php';

use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use PhpSchool\CliMdRenderer\CliRendererFactory;

$parser = new DocParser(Environment::createCommonMarkEnvironment());
$cliRenderer = (new CliRendererFactory)->__invoke();
$ast = $parser->parse(file_get_contents('path/to/'));

echo $cliRenderer->renderBlock($ast);

Syntax Highlighting

FencedCode can be syntax highlighted. By default only PHP source code is Syntax Highlighted using: kadet/keylighter If you want to add syntax highlighting for other languages you should create a class which implements \AydinHassan\CliMdRenderer\SyntaxHighlighterInterface

It accepts code as a string and should return highlighted code as a string. You register your highlighter like so


use PhpSchool\CliMdRenderer\Renderer\FencedCodeRenderer;

$codeRenderer = new FencedCodeRenderer;
$codeRenderer->addSyntaxHighlighter('js', new JsSyntaxHighlighter);

If you need to do this you cannot use the factory so construction will look something like:

require_once 'vendor/autoload.php';

use Colors\Color;
use League\CommonMark\Environment;

$environment = new Environment();
$environment->addExtension(new CliExtension());

$colors = new Color();

return new CliRenderer($environment, $colors);

To Do

  • Make configurable (Line Endings, colors, styles)
  • Image Renderer
  • List Renderer
  • Code Syntax Highlighting
  • Documentation