Officialv5.5.1MITkubb >=5.0.0node >=22

@kubb/parser-md

Emits `.md` and `.markdown` files from the Kubb AST, joining source blocks as plain markdown and prepending YAML frontmatter from a file's meta.

markdownfrontmatterparserdocsyaml
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
132.8K/ mo
Stars
1.8K
Bundle size
22.5 kB
Updated
12h ago

@kubb/parser-md emits .md and .markdown files by joining source blocks with blank lines. It prepends YAML frontmatter from file.meta.frontmatter.

The parser takes no options and runs by default alongside parserTs and parserTsx. A custom parsers array replaces that default set. Include every parser your plugins need. Unmatched files are written as source text.

Installation

bun add -d @kubb/parser-md

Dependencies

No plugin dependencies. The parser registers on defineConfig.parsers.

Frontmatter

To add a YAML frontmatter block to a generated page, set frontmatter on a file's meta inside a plugin. The parser renders those keys and prepends them to the output. Any serializable object works.

Type:Record<string, unknown> | null
plugin.ts
import { ast } from 'kubb/kit'

const file = ast.factory.createFile({
  baseName: 'README.md',
  path: './src/gen/README.md',
  meta: {
    frontmatter: { title: 'API Reference', layout: 'doc' },
  },
  sources: [ast.factory.createSource({ nodes: [ast.factory.createText('# API Reference')] })],
})

The parser turns that meta into:

---
title: API Reference
layout: doc
---

You can also call parserMd().print directly to build a frontmatter envelope. It accepts objects and markdown strings and joins them with blank lines, so parserMd().print({ title: 'Pets', layout: 'doc' }) returns ---\ntitle: Pets\nlayout: doc\n---.

Example

Register the Markdown parser explicitly when overriding the default parser set.

kubb.config.ts
import { defineConfig } from 'kubb'
import { parserMd } from '@kubb/parser-md'
import { parserTs, parserTsx } from '@kubb/parser-ts'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  parsers: [parserTs(), parserTsx(), parserMd()],
  plugins: [],
})

See also