Markdown metadata format

Viewed 50659

Is there a standard or convention for embedding metadata in a Markdown formatted post, such as the publication date or post author for conditional rendering by the renderer?

Looks like this Yaml metadata format might be it.

There are all kinds of strategies, e.g. an accompanying file mypost.meta.edn, but I'm hoping to keep it all in one file.

7 Answers

A workaround use standard syntax and compatible with all other viewers.

I was also looking for a way to add application specific metadata to markdown files while make sure the existing viewers such as vscode and github page will ignore added metadata. Also to use extended markdown syntax is not a good idea because I want to make sure my files can be rendered correctly on different viewers.

So here is my solution: at beginning of markdown file, use following syntax to add metadata:


  [_metadata_:author]:- "daveying"
  [_metadata_:tags]:- "markdown metadata"

This is the standard syntax for link references, and they will not be rendered while your application can extract these data out.

The - after : is just a placeholder for url, I don't use url as value because you cannot have space in urls, but I have scenarios require array values.

The most consistent form of metadata that I've found for Markdown is actually HTML meta tags, since most Markdown interpreters recognize HTML tags and will not render meta tags, meaning that metadata can be stored in a way that will not show up in rendered HTML.

<title>Hello World</title>
<meta name="description" content="The quick brown fox jumped over the lazy dog.">
<meta name="author" content="John Smith">

## Heading
Markdown content begins here

You can try this in something like GitHub Gist or StackEdit.

Correct.

Use the yaml front matter key-value syntax — like MultiMarkdown supports — but (ab)use the official markdown URL syntax to add your metadata.

… my workaround looks like this:

---
[//]: # (Title: My Awesome Title)
[//]: # (Author: Alan Smithee)
[//]: # (Date: 2018-04-27)
[//]: # (Comment: This is my awesome comment. Oh yah.) 
[//]: # (Tags: #foo, #bar)  
[//]: # (CSS: https://path-to-css)  
---

Put this block at the top of your .md doc, with no blank line between the top of the doc and the first ---.

Your fake yaml won't be included when you render to HTML, etc. … it only appears in the .md.

You can also use this technique for adding comments in the body of a markdown doc.

This is not a standard way, but works with Markdown Extra.

I wanted something that worked in the parser, but also didn't leave any clutter when I browse the files on Bitbucket where I store the files.

So I use Abbreviations from the Markdown Extra syntax.

*[blog-date]: 2018-04-27
*[blog-tags]: foo,bar

then I parse them with regexp:

 ^\*\[blog-date\]:\s*(.+)\s*$

As long as I don't write the exact keywords in the text, they leave no trace. So use some prefix obscure enough to hide them.

I haven't seen this mentioned elsewhere here or in various blogs discussing the subject, but in a project for my personal website, I've decided to use a simple JSON object at the top of each markdown file to store metadata. It's a little more cumbersome to type compared to some of the more textual formats above, but it's super easy to parse. Basically I just do a regex such as ^\s*({.*?})\s*(.*)$ (with the s option on to treat . as \n) to capture the json and markdown content, then parse the json with the language's standard method. It allows pretty easily for arbitrary meta fields.

Related