Convert
Convert
The leadtype/convert entry point flattens MDX into clean markdown via the remark plugin stack.
The CLI (leadtype generate) calls convertAllMdx internally — use these APIs directly when you need custom plugin order, in-memory output, or per-file control.
convertAllMdx
Batch convert a docs tree:
| Option | Description |
|---|---|
srcDir | Root directory of .mdx files. |
outDir | Destination for .md output. The directory structure mirrors srcDir. |
remarkPlugins | Plugin array. Usually [remarkInclude?, ...defaultRemarkPlugins]. Order matters. |
enrichFrontmatterFromGit | When true, adds lastModified and lastAuthor from git history. |
The function is concurrent — large trees process in parallel.
convertMdxToMarkdown
Convert one file in memory and get back the markdown plus parsed frontmatter:
Use this when you want to render the output yourself, validate it before writing, or feed it to another pipeline stage without touching disk.
writeMdxFileAsMarkdown
Convert one file and write the output:
Behavior notes
- Frontmatter is preserved. YAML blocks at the top of the source
.mdxsurvive into the output.md. - Synthesized frontmatter. A page without frontmatter gets
title(and sometimesdescription) inferred from the rendered markdown. - Tables and Mermaid blocks are compacted after rendering so agent output stays clean.
- Conversion is concurrent — there is no global state.
Pairing with remark plugins
In most setups, pair convertAllMdx with the default plugin stack and remarkInclude if your docs use partials:
Place remarkInclude before the defaults so includes expand into the source AST before component flattening sees them. See Remark plugins for the full stack and order rationale.
The include plugin supports tags such as <include src="./shared/auth.mdx" /> and section reuse with <include src="./shared/auth.mdx#session-flow" />. Section reuse expects a lowercase <section id="session-flow"> block in the included file.