Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 2.19 KB

README.md

File metadata and controls

66 lines (46 loc) · 2.19 KB

CLI Markdown Renderer

<img src="https://github.com/AydinHassan/cli-md-renderer/workflows/CliMdRenderer/badge.svg">

Build Status Windows Build Status Coverage Status

Usage

<?php
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/file.md'));

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

<?php

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:

<?php 
require_once 'vendor/autoload.php';

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

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

$colors = new Color();
$colors->setForceStyle(true);

return new CliRenderer($environment, $colors);

To Do

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