Front matter best practice?


#1

Hi, I scanned http://spec.commonmark.org/0.26/ & https://talk.commonmark.org/search?q=front%20matter and I’m none the wiser.

I need some markup in my Markdown to denote the HTML title for a simple golang static site generator we have at work.

I wrote something crappy a year ago that uses [[!meta key="value"]] which I might re-use: https://github.com/kaihendry/blog/blob/master/meta.go

If there is a simpler way of doing it, I’m keen to learn how!

Cheers!


#2

I have moved this topic to “Extensions” since front matter is not amongst the planned features for 1.0.

There have been some discussions regarding Jekyll style front matter blocks, along with other approaches. See the topics listed under “Meta Data” in the list of proposed extensions.


#3

Front matter is not going to be part of the spec. An application that uses CommonMark can employ its own conventions for extracting lines from the front of the document and parsing them as front matter. In general, the needs will be different for different applications.

If you want something that works out of the box, try my https://github.com/jgm/lcmark, which allows YAML front matter and has a templating system.


#4

Isn’t it worth noting that front matter other than HTML meta tags like <meta name="description" content="Lorem Ipsum"> would need careful filtering?


#5

Yes, precisely. If your application supports front matter, it must strip this off, interpret it, and pass the rest to the CommonMark parser.