Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aydinhassan/cli-md-renderer

A CLI Markdown Renderer for league/commonmark compatibile AST
https://github.com/aydinhassan/cli-md-renderer

Last synced: 1 day ago
JSON representation

A CLI Markdown Renderer for league/commonmark compatibile AST

Awesome Lists containing this project

README

        

CLI Markdown Renderer
===========

[![Build Status](https://github.com/AydinHassan/cli-md-renderer/workflows/CliMdRenderer/badge.svg)](https://github.com/AydinHassan/cli-md-renderer/actions)
[![Windows Build Status](https://img.shields.io/appveyor/ci/AydinHassan/cli-md-renderer/master.svg?style=flat-square&label=Windows)](https://ci.appveyor.com/project/AydinHassan/cli-md-renderer)
[![Coverage Status](https://img.shields.io/codecov/c/github/AydinHassan/cli-md-renderer.svg?style=flat-square)](https://codecov.io/github/AydinHassan/cli-md-renderer)

### Usage

```php
addExtension(new CommonMarkCoreExtension()));
$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](https://github.com/kadet1090/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
addSyntaxHighlighter('js', new JsSyntaxHighlighter);

```

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

```php
init();
$codeRender->addSyntaxHighlighter('php', new PhpHighlighter($keyLighter));
$codeRender->addSyntaxHighlighter('js', new JsSyntaxHighlighter);

$blockRenderers = [
Document::class => new DocumentRenderer,
Header::class => new HeaderRenderer,
HorizontalRule::class => new HorizontalRuleRenderer,
Paragraph::class => new ParagraphRenderer,
FencedCode::class => $codeRender,
];

$inlineBlockRenderers = [
Text::class => new TextRenderer,
Code::class => new CodeRenderer,
Emphasis::class => new EmphasisRenderer,
Strong::class => new StrongRenderer,
Newline::class => new NewlineRenderer,
Link::class => new LinkRenderer,
];

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

return new CliRenderer($blockRenderers, $inlineBlockRenderers, $colors);

```

### To Do
- [ ] Make configurable (Line Endings, colors, styles)
- [x] Image Renderer
- [x] List Renderer
- [x] Code Syntax Highlighting
- [x] Documentation