Data workflow guides

Extract YAML front matter and preserve a Markdown document

·

When moving a Markdown article to a content pipeline, choose whether you need only the front matter or the metadata together with the original body. The two output formats serve those separate imports.

Markdown to YAML

Check six typed fields in the sample front matter

Select Load example, choose Front matter only and convert. The result has six metadata fields. Check that code has the quotes around 0012, edition reads 9007199254740993 and draft stays false. The tags list retains the entries travel and notes.

The tool keeps the source spelling of numeric scalars in the mapping. The sample ratio still reads 0.1234567890123456789. A reader that uses binary floating point may display a rounded value after loading the YAML.

YAML 1.2.2 — Collections, scalars and core tagsAstro Docs — Markdown frontmatter

Export the body with its original heading locations

Switch to Document data and convert the sample again. The frontmatter member contains the same fields. The headings list records Café field guide as level 1 on line 9 and Bring a notebook as level 2 on line 12.

Read the markdown member with a YAML parser to recover the Markdown body as text. In the saved source, line ends inside that value appear as escape sequences. The reader restores those line ends when it loads the value.

CommonMark 0.31.2 — ATX and Setext headingsYAML 1.2.2 — Collections, scalars and core tags

Correct a duplicate metadata field before export

Add another title field inside the delimiters and convert. The export stops with a duplicate key error. Choose which value you want to keep, remove the other field and run the conversion again.

YAML 1.2.2 — Collections, scalars and core tags

Common questions

Does document output reformat the Markdown body?

The markdown value stores the original body text after the closing delimiter. The separately generated headings list uses the selected Markdown parser.

Which metadata shape is supported?

The front matter is one YAML 1.2 mapping whose top-level keys are text. Nested lists and maps retain their YAML syntax. Stream directives are outside the input format.

What if the document starts with a line of three dashes?

The converter treats that line as the start of front matter. Move a thematic break below the first line when you want it to remain part of a Markdown-only body.

Sources

Put it into practice.

Related guides