hyn / frontmatter
从 frontmatters 解析元信息的 Markdown
1.1.1
2016-12-14 21:39 UTC
Requires
- cebe/markdown: ^1.1
- symfony/yaml: ^3.2
- yosymfony/toml: ^0.3.3
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-09-05 18:36:19 UTC
README
这是一个易于解析包含元数据(通常称为 frontmatter)的任何 Markdown 文件的包。
安装
composer require hyn/frontmatter
用法
最简单的方式是使用控制反转,但您可以自由地以您认为合适的方式实例化类。
$parser = new \Hyn\Frontmatter\Parser(new \cebe\markdown\Markdown); // Uses json per default, but set specifically: $parser->setFrontmatter(\Hyn\Frontmatter\Frontmatters\JsonFrontmatter::class); // Use toml: $parser->setFrontmatter(\Hyn\Frontmatter\Frontmatters\TomlFrontmatter::class); // Or use yaml: $parser->setFrontmatter(\Hyn\Frontmatter\Frontmatters\YamlFrontmatter::class); // And parse the markdown file: $contents = $parser->parse(file_get_contents('the-file.md')); // Get meta $meta = $parser->getMeta();