php-school/cli-md-renderer
最新稳定版本:1.0.0
Composer 安装命令:
composer require php-school/cli-md-renderer
包简介
A CLI Markdown Render for league/commonmark compatible AST
README 文档
README
<img src="https://github.com/AydinHassan/cli-md-renderer/workflows/CliMdRenderer/badge.svg">
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
统计信息
- 总下载量: 2.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-14