YAML front matter #44

Closed
opened 2026-01-29 14:22:47 +00:00 by claunia · 4 comments
Owner

Originally created by @mcnameej on GitHub (Jul 14, 2016).

Enhancement request

Add support for YAML front matter.

The immediate need is for markdig to recognize and ignore any front matter. Don't try to parse it as Markdown text. Perhaps in the future markdig may find some use for the data.

If you can provide some hints about where this would need to happen in the markdig code, I might be able to add it myself and submit a PR.

(For what it's worth, I'm no fan of YAML, but it seems to be the most common way of adding metadata to Markdown files.)

Originally created by @mcnameej on GitHub (Jul 14, 2016). ### Enhancement request Add support for YAML front matter. The immediate need is for markdig to recognize and ignore any front matter. Don't try to parse it as Markdown text. Perhaps in the future markdig may find some use for the data. If you can provide some hints about where this would need to happen in the markdig code, I might be able to add it myself and submit a PR. (For what it's worth, I'm no fan of YAML, but it seems to be the most common way of adding metadata to Markdown files.)
claunia added the enhancement label 2026-01-29 14:22:47 +00:00
Author
Owner

@xoofx commented on GitHub (Jul 14, 2016):

I'm wondering in which particular usecase you would need this? Typically, a frontmatter is handled at a higher level by the compositing engine (e.g Jekyll, Hugo...etc.) and they use a YAML parser to pre-parse the frontmatter (without interpreting the md document), because a YAML parser is able to understand the document split ---, they stop on the second one as they know that the rest of the document will be of the type of the file extension. As a frontmatter is often used for other type of files (HTML, even css...etc.), you don't want to add frontmatter handling to the HTML parser or the CSS parser... so it should be basically the same for md.

@xoofx commented on GitHub (Jul 14, 2016): I'm wondering in which particular usecase you would need this? Typically, a frontmatter is handled at a higher level by the compositing engine (e.g Jekyll, Hugo...etc.) and they use a YAML parser to pre-parse the frontmatter (without interpreting the md document), because a YAML parser is able to understand the document split `---`, they stop on the second one as they know that the rest of the document will be of the type of the file extension. As a frontmatter is often used for other type of files (HTML, even css...etc.), you don't want to add frontmatter handling to the HTML parser or the CSS parser... so it should be basically the same for md.
Author
Owner

@mcnameej commented on GitHub (Jul 14, 2016):

It's all about the Visual Studio MarkdownEditor, which uses markdig. I want to be able to edit MD files that have YAML front matter, while not having it disrupt the preview in VS.

@mcnameej commented on GitHub (Jul 14, 2016): It's all about the Visual Studio MarkdownEditor, which uses markdig. I want to be able to edit MD files that have YAML front matter, while not having it disrupt the preview in VS.
Author
Owner

@xoofx commented on GitHub (Jul 14, 2016):

Thanks, that makes more sense in this case. Without handling pure YAML parsing (it would simply try to find the --- pattern at the beginning of a line), it should not be much difficult to add this... though there are no extension that work only at a pre-processor level, so it will require a bit more thinking on how to integrate this.

@xoofx commented on GitHub (Jul 14, 2016): Thanks, that makes more sense in this case. Without handling pure YAML parsing (it would simply try to find the `---` pattern at the beginning of a line), it should not be much difficult to add this... though there are no extension that work only at a pre-processor level, so it will require a bit more thinking on how to integrate this.
Author
Owner

@xoofx commented on GitHub (Sep 19, 2016):

The feature is implemented in commit f0ea008

@xoofx commented on GitHub (Sep 19, 2016): The feature is implemented in commit f0ea008
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#44