Skip to content
David Lowry-Duda edited this page Dec 20, 2016 · 3 revisions

metadata extra

The metadata extra enables parsing out of a leading metadata block in a markdown file. A metadata block looks like this:

---
foo: bar
Another-Key: another value
Key-with-long-value: >
  can be given with this form. Greater than sign, followed by
  a block of intended lines.
A-further-key: some other value.
---

# Rest of markdown document

It is also possible to not use ---, and instead interpret the lines until the first blank line as metadata. Such a metablock looks like:

foo: bar
Another-Key: another value
Key-with-long-value: >
  can be given with this form. Greater than sign, followed by
  a block of intended lines.
A-further-key: some other value.

# Rest of markdown document

The metadata is returned as a dictionary as the metadata attribute of the returned HTML:

>>> import markdown2
>>> text = """---
... foo: bar
... ---
... 
... *hi*
... """
>>> html = markdown2.markdown(text, extras=["metadata"])
>>> html
u'<p><em>hi</em></p>\n'
>>> html.metadata
{u'foo': u'bar'}

This is informed a little bit by Jekyll's Front Matter and Python-Markdown's Meta-Data. See initial discussion on issue #77, or later discussion on metadata blocks without --- fences.

(Return to Extras page.)

Clone this wiki locally