Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown metadata format

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.

like image 416
Petrus Theron Avatar asked May 27 '17 10:05

Petrus Theron


People also ask

What is Markdown file format?

What is a MARKDOWN file? A MARKDOWN file is a text file created using one of several possible dialects of the Markdown language. It uses plain text formatting but contains inline text symbols that specify how to format the text (e.g., *bold* for bold text, or other markups for italics, indentation, headers, etc.).

Is Yaml a metadata?

YAML is a human-readable data-serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. It is a common practice to use YAML to add metadata, such as title, tags, and descriptions, to Markdown documents.

What is Markdown example?

Markdown Example In other words, if a broker sells a security to a client at a lower price than the highest bid (selling) price in the securities market among brokers, the price is a markdown price. To illustrate, suppose a broker sells shares of XYZ stock to his clients at $20 per share.

What is front matter Markdown?

The Front Matter extension tries to make it easy to manage your Markdown pages/content. Within a Markdown page, we allow you to fold the file's Front Matter to be less distracting when writing. Also, do we highlight the Front Matter content to create a visual difference between content and metadata.

What is the Markdown meta-data extension?

This extension is included in the standard Markdown library. Meta-data consists of a series of keywords and values defined at the beginning of a markdown document like this: Title: My Document Summary: A brief description of my document.

How do I localized a Markdown document?

In the metadata description and the Markdown main content the word document is localized, because it does not start with a capital D. --- title: Title of the Document author: author-name description: Description for the document no-loc: [Title, Document] --- # Heading 1 of the Document Markdown content within the document.

What is the basic syntax of Markdown?

Basic Syntax. The Markdown elements outlined in John Gruber's design document. Nearly all Markdown applications support the basic syntax outlined in John Gruber’s original design document. There are minor variations and discrepancies between Markdown processors — those are noted inline wherever possible.

What is the difference between Markdown and YAML?

While it has more recently been updated to optionally support YAML deliminators, traditionally, the metadata ends and the Markdown document begins upon the first blank line (if the first line was blank, then no metadata). And while the syntax looks very similar to YAML, only key-value pairs are supported with no implied types.


2 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.

like image 30
David.Da Avatar answered Oct 13 '22 17:10

David.Da


There are two common formats that look very similar but are actually different in some very specific ways. And a third which is very different.

YAML Front Matter

The Jekyll static site generator popularized YAML front matter which is deliminated by YAML section markers. Yes, the dashes are actually part of the YAML syntax. And the metadata is defined using any valid YAML syntax. Here is an example from the Jekyll docs:

--- layout: post title: Blogging Like a Hacker --- 

Note that YAML front matter is not parsed by the Markdown parser, but is removed prior to parsing by Jekyll (or whatever tool you're using) and could actually be used to request a different parser than the default Markdown parser for that page (I don't recall if Jekyll does that, but I have seen some tools which do).

MultiMarkdown Metadata

The older and simpler MultiMarkdown Metadata is actually incorporated into a few Markdown parsers. While it has more recently been updated to optionally support YAML deliminators, traditionally, the metadata ends and the Markdown document begins upon the first blank line (if the first line was blank, then no metadata). And while the syntax looks very similar to YAML, only key-value pairs are supported with no implied types. Here is an example from the MultiMarkdown docs:

Title:    A Sample MultiMarkdown Document   Author:   Fletcher T. Penney   Date:     February 9, 2011   Comment:  This is a comment intended to demonstrate             metadata that spans multiple lines, yet             is treated as a single value.   CSS:      http://example.com/standard.css 

The MultiMarkdown parser includes a bunch of additional options which are unique to that parser, but the key-value metadata is used across multiple parsers. Unfortunately, I have never seen any two which behaved exactly the same. Without the Markdown rules defining such a format everyone has done their own slightly different interpretation resulting in a lot of variety.

The one thing that is more common is the support for YAML deliminators and basic key-value definitions.

Pandoc Title Block

For completeness there is also the Pandoc Title Block. If has a very different syntax and is not easily confused with the other two. To my knowledge, it is only supported by Pandoc (if enabled), and it only supports three types of data: title, author, and date. Here is an example from the Pandoc documentation:

% title % author(s) (separated by semicolons) % date 

Note that Pandoc Title Blocks are one of two style supported by Pandoc. Pandoc also supports YAML Metadata as described above.

like image 138
Waylan Avatar answered Oct 13 '22 18:10

Waylan