daylerees / kurenai
Multi document parser with metadata support.
Installs: 11 653
Dependents: 5
Suggesters: 1
Security: 0
Stars: 151
Watchers: 8
Forks: 13
Open Issues: 6
Requires
- php: >=5.6.5
- illuminate/support: ^5.2
Requires (Dev)
- erusev/parsedown: ^1.6
- jakub-onderka/php-parallel-lint: ^0.9.2
- league/commonmark: ^0.17
- michelf/php-markdown: ^1.6
- netcarver/textile: ^3.5
- phing/phing: ^2.13
- phpunit/phpunit: >=4.8
- squizlabs/php_codesniffer: ^2.5
- symfony/yaml: ^3.0
Suggests
- erusev/parsedown: Allow for Parsedown markdown parsing.
- league/commonmarl: Allow for CommonMark markdown parsing.
- michelf/php-markdown: Allow markdown and markdown extra content parsing.
- netcarver/textile: Allow for Textile parsing.
- symfony/yaml: Allow for YAML metadata parsing.
This package is not auto-updated.
Last update: 2024-12-21 15:13:52 UTC
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
Content Parsers
Enjoy using Kurenai!