Syntax
Frontmatter
Add a leading YAML block to declare document metadata that Comark parses into tree.frontmatter.
Comark supports YAML frontmatter at the beginning of documents. Parsing is provided by the built-in frontmatter plugin (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
Frontmatter values can be referenced in component props with the :prefix binding syntax:
---
theAnswer: 42
user:
name: Ada
---
::question{:answer="frontmatter.theAnswer"}
::
Hello, :badge{:label="frontmatter.user.name"}Learn more in Data Binding.
Disable
Turn off all default plugins so the --- block is treated as regular markdown:
import { parseMarkdown } from 'comark'
const result = await parseMarkdown(content, {
registerDefaultPlugins: false,
})
// result.frontmatter → {}See the frontmatter plugin for registration and options.