bredmor/yaro

可扩展的Markdown解析器

0.0.1 2019-03-28 03:53 UTC

This package is auto-updated.

Last update: 2024-09-06 06:37:32 UTC


README

Build Status

Yaro是一个专为Markdown设计的解析器和词法分析框架。默认情况下,Yaro解析 基本 Markdown。

安装/使用

从源代码安装

从GitHub克隆仓库或将解压到您的供应商目录中。Yaro已打包支持PSR-4自动加载。

使用Composer安装

composer require bredmor/yaro

在项目中使用

use bredmor\Yaro\Yaro;
$yaro = new Yaro();
echo $yaro->parse("Your *markdown* text here.");

向默认词法分析器添加新的Markdown标记

$lexer = new bredmor\Yaro\Lexer\DefaultLexer();
$lexer->setToken('/Your PCRE-compat regex here/', function($match) {
    // Any closure, function name or preg_* function compatible replacement string can be used for the 2nd argument
});
$yaro = new Yaro($lexer);
echo $yaro->parse("Your custom markdown text here.");

可扩展性

您可以选择 扩展 默认解析器或词法分析器,或者在自己的自定义类上实现 LexerInterfaceParserInterface

只需在初始化时将任何一个传递给构造函数,它就会替代默认的。

$parser = new MyCustomParser();
$yaro = new Yaro(null, $parser); // Using a NULL value for the parser or lexer in the controller will cause Yaro to use the default class.

您还可以在 任何 时间更改现有的Yaro对象的解析器或词法分析器。这允许您注入已配置的Yaro实例并在运行时切换上下文。

$yaro = new Yaro();
echo $yaro->parse("My markdown string"); // The string is evaluated using the default lexer
$yaro->setLexer($myOtherLexerClass);
echo $yaro->parse("My other markdown string"); // This string is evaluated using the new lexer

要求

PHP 7.2或更高版本。

支持的Markdown

Yaro的默认词法分析器支持以下Markdown

使用星号或下划线标记的 斜体强调

使用星号或下划线标记的 粗体

~~删除线~~

水平线

标题

>引用块 (>, >, |, >> 和 »)

``` 代码块

` 行内代码

无序列表 (*, - 和 +)

  1. 有序列表(任何数字)

[链接](http://example.com)

![嵌入图像](链接_to_image.png)

作者

贡献

欢迎Pull requests、错误报告和功能请求。

许可证

Yaro受GPLv3许可证的许可 - 有关详细信息,请参阅LICENSE文件。

致谢

Yaro是以那个真的希望我为其特定用例编写另一个Markdown解析器的人的名字命名的。