Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rianfuro/commonmark-metadata
A CommonMark extension to parse MultiMarkdown-like metadata at the beginning of a markdown document
https://github.com/rianfuro/commonmark-metadata
Last synced: 29 days ago
JSON representation
A CommonMark extension to parse MultiMarkdown-like metadata at the beginning of a markdown document
- Host: GitHub
- URL: https://github.com/rianfuro/commonmark-metadata
- Owner: RianFuro
- License: mit
- Created: 2021-10-02T18:44:06.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-07T06:22:43.000Z (over 2 years ago)
- Last Synced: 2024-11-25T04:07:05.229Z (29 days ago)
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an extension for [thephpleague/commonmark](https://github.com/thephpleague/commonmark)
to parse [MultiMarkdown-like metadata](https://fletcher.github.io/MultiMarkdown-4/metadata.html) from the top of a Markdown file.# Installation
1. Require the package like any other:
```
composer require rianfuro/commonmark-metadata
```2. Install the extension.
```php
use CommonMark\Extension\Metadata\MetadataExtension;$environment = new Environment([]);
// ... other extensions
$environment->addExtension(new MetadataExtension);new MarkdownConverter($environment);
```# Usage
The extension is used automatically by the CommonMark Parser when included. The extension converts the metadata section into a `MetadataBlock`,
which holds the fields in it's `data` property. You can, for example, use CommonMark's query utility to fetch the Block and get it's data:
```php
$metadata = (new Query())
->where(Query::type(MetadataBlock::class))
->findOne($document);
$metadata->data->export(); // note that this always includes the default `attributes` field
```# Current limitations
The project is in it's super early stages so the parsing is very limited.
Currently the metadata needs to be fenced with yaml-style delimiters (should be optional according to the spec):
```markdown
---
Author: Me
Title: Super Awesome Document
---My Amazing Markdown Document
============================...
```
Additionally, the metadata fields cannot be referenced inside the document.