Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/aydinhassan/cli-md-renderer
- Owner: AydinHassan
- License: mit
- Created: 2015-09-29T20:41:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-19T20:17:37.000Z (almost 3 years ago)
- Last Synced: 2024-10-01T11:08:50.850Z (2 days ago)
- Language: PHP
- Homepage:
- Size: 131 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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