daylerees/kurenai
Composer 安装命令:
composer require daylerees/kurenai
包简介
Multi document parser with metadata support.
README 文档
README
Kurenai
Kurenai is a document with metadata parsing library for PHP. It supports a variety of different document content and metadata parsers.
Installation
Kurenai is available on Packagist for Composer.
composer require daylerees/kurenai
Usage
Kurenai documents look like this:
Some form of metadata here.
===
Some form of content here.
A metadata section, and a content section seperated by three equals === signs or more.
Here's an example using JSON for metadata, and Markdown for content.
{
"title": "Hello world!"
}
===
# Hello World
Well hello there, world!
Formats for metadata and content are interchangable using classes called parsers. First, let's create our parser instance.
$kurenai = new \Kurenai\Parser( new \Kurenai\Parsers\Metadata\JsonParser, new \Kurenai\Parsers\Content\MarkdownParser );
In the above example, we're using a JSON metadata parser, and a Markdown content parser. We can now parse a document.
$document = $kurenai->parse('path/to/document.md');
Our documents can have any filename or extension. You can also pass the parse() function the content of a document directly.
The document instance has a few useful methods.
$document->getRaw();
This will fetch the raw document content. Before Kurenai parsed it.
$document->getMetadata();
This will fetch the metadata, parsed into an array.
$document->getContent();
This will get the content of the document, rendered using the provided content parser.
$document->get('foo.bar');
The get() method uses dot-notation to return a metadata value. For example, the above example would be equivalent to fetching $metadata['foo']['bar'].
If the subject can't be found, null will be returned. You can supply a default value as a second parameter to the method.
Metadata Parsers
| Format | Install Package | Class |
|---|---|---|
| JSON | N/A | Kurenai\Parsers\Metdata\JsonParser |
| YAML | symfony/yaml |
Kurenai\Parsers\Metdata\YamlParser |
| INI | N/A | Kurenai\Parsers\Metdata\IniParser |
Content Parsers
| Format | Install Package | Class |
|---|---|---|
| Plaintext (no parsing) | N/A | Kurenai\Parsers\Content\PlainTextParser |
| CommonMark | league/commonmark |
Kurenai\Parsers\Content\CommonMarkParser |
| Markdown | michelf/php-markdown |
Kurenai\Parsers\Content\MarkdownParser |
| Markdown Extra | michelf/php-markdown |
Kurenai\Parsers\Content\MarkdownExtraParser |
| Parsedown (Github Markdown) | erusev/parsedown |
Kurenai\Parsers\Content\ParsedownParser |
| Textile | netcarver/textile |
Kurenai\Parsers\Content\TextileParser |
Enjoy using Kurenai!
统计信息
- 总下载量: 11.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 152
- 点击次数: 0
- 依赖项目数: 5
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2013-03-16
