Skip to content
Parser
Markdown logo
parsers: [parserMd()]
Officialv5.20.2kubb >=5.8.3node >=22.22

Markdown parser

@kubb/parser-md

Writes .md and .markdown files from the Kubb AST, with YAML frontmatter from a file's meta.

kubb add parser-md
markdownfrontmatterparserdocsyaml

The Markdown parser writes the .md and .markdown files that plugins generate, with YAML frontmatter from each file's meta.frontmatter.

It joins each file's source blocks with blank lines and writes the frontmatter above the content.

Installation

kubb add parser-md

kubb add installs the version the Kubb registry pins and adds parserMd() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

No setup is needed. defineConfig and the bundler integrations register parserMd() by default, next to parserTs() and parserTsx().

A custom parsers array replaces the default set, so add parserMd() to it yourself and list every parser your plugins need. A file that no parser claims is written as its source text only, without imports, exports, banner, or footer.

Options worth knowing

The parser takes no options. A plugin controls the output per file:

File settingDefaultWhat it does
meta.frontmatterNoneWrites the object as YAML frontmatter. null or {} writes none.
bannerNoneGoes above the frontmatter.
footerNoneGoes below the content.

Example

This config sets a custom parsers array that keeps the Markdown parser. A plugin file with meta.frontmatter then prints like this:

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

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

Dependencies

No extension dependencies.