YAML front matter

edit

Static site generators and documentation tools put the metadata of a page, such as its title, its date or its tags, in a YAML block at the start of the file. YamlFrontMatter reads this block as a front matter instead of a thematic break and a heading, and the renderer does not write it.

var options = new MarkdownParseOptions { Extensions = MarkdownExtensions.YamlFrontMatter };
var tree = MarkdownSyntaxTree.ParseText("---\ntitle: Hello\ntags: [a, b]\n---\n# Hello\n", options);

var frontMatter = Assert.IsType<MarkdownFrontMatterSyntax>(tree.GetRoot().Blocks[0]);
Assert.Equal("title: Hello\ntags: [a, b]\n", frontMatter.Yaml);

// The renderer does not write the front matter
Assert.Equal("<h1>Hello</h1>\n", MarkdownHtmlRenderer.ToHtml(tree));

The front matter is between --- and --- or ... at the start of the document. It is a MarkdownFrontMatterSyntax, whose Yaml property gives the YAML to give to a YAML parser.