Frontmatter

Add a leading YAML block to declare document metadata that Comark parses into document.frontmatter.

Comark parses YAML frontmatter at the start of a document using the built-in frontmatter plugin, which is enabled by default.

Syntax

---
title: My Document Title
author: John Doe
date: 2024-01-15
tags:
  - markdown
  - documentation
depth: 3
searchDepth: 2
custom_field: custom value
---

# Document Content

Your Markdown content here...

Rules

  • Must be at the very beginning of the document (no leading blank lines)
  • Enclosed by --- delimiters
  • Body is parsed as YAML
  • Empty frontmatter (---\n--- with no content) is ignored

Parse result

The frontmatter property is available on the parse result:

import { parseMarkdown } from 'comark'

const content = `---
title: My Article
author: Jane Doe
---

# Hello World
`

const { frontmatter, nodes } = await parseMarkdown(content)
/*
frontmatter -> { title: 'My Article', author: 'Jane Doe' }
nodes       -> [ ['h1', { id: 'hello-world' }, 'Hello World'] ]
*/

See Document model for how frontmatter sits on MarkdownDocument.

Data binding

Reference frontmatter values in component props with the :prop binding syntax:

---
theAnswer: 42
user:
  name: Ada
---

::question{:answer="frontmatter.theAnswer"}
::

Hello, :badge{:label="frontmatter.user.name"}

Learn more in Data binding.

Disable

Set registerDefaultPlugins: false to disable the default plugins and treat --- as a standard horizontal rule:

import { parseMarkdown } from 'comark'

const result = await parseMarkdown(content, {
  registerDefaultPlugins: false,
})
// result.frontmatter -> {}

See the frontmatter plugin for registration and options.

© 2026 Vercel, Inc.