Open CodeDoctorDE opened 3 years ago
Do you know if this is specified in a spec somewhere? AFAIK, the front matter like you show is not standard...
I saw this methods in jekyll and docusaurus
For further reference,
Note that, not being standarised, the syntax differs from program to program but mostly it can be briefed as:
---
what follows may be a front-matter (note that on YAML it could be ...
but haven't seen any product use that in the front-matter)---
or ...
)I say may be because somebody might (?) start the document with a thematic break and what follows would NOT be a yaml document but the Markdown document itself.
If front-matter processing is opt-in then the assumption could be made that nobody would a) enable front-matter and b) start a document with a thematic break.
To make things more entertaining, some products (like VuePress or Hugo) allow other formats for the front-matter like JSON, TOML and even Org-Mode.
It's also possible that this should live in a separate package maintained by the community.
It's not super hard to do, and it's not really a markdown thing.
If we wanted to do it in this package we'd have to introduce a type that represents yaml-frontmatter and markdown document.
It's probably better if someone creates a generic frontmatter
package, like:
import 'package:frontmatter/frontmatter.yaml';
import 'package:markdown/markdown.yaml';
void main() {
final input = '''
title: Overview
slug: /
id: introduction
---
![Alt](/img/banner.svg)
''';
final doc = FrontmatterDocument.fromString(input);
print(loadYaml(doc.frontmatter));
print(markdownToHtml(doc.content));
}
How would this logic benefit from living in package:markdown
?
For example, we have this markdown file:
It would be cool if I can access to the properties title, slug and id