- 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
pnpm add -D @kubb/parser-md
npm install --save-dev @kubb/parser-md
yarn 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 |
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.
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: [],
})