Rich text / foldkit-richtext-markdown
richtext-markdown
Converting rich-text documents to and from Markdown often forces a choice between lossy converters that silently drop unsupported blocks and raw Markdown storage that breaks node identities during edits. You want lossless round-trips for standard formatting and explicit warnings whenever a block or mark has no Markdown syntax.
foldkit-richtext-markdown prints foldkit-richtext documents to CommonMark (with GFM lists, task items, strikethrough, tables, and optional footnotes), parses Markdown back into validated documents using micromark and mdast, and supplies typing shortcuts and source-mode helpers. See Markdown shortcuts and source editing live in the rich-text playground.
Install
pnpm add foldkit-richtext-markdownA first round trip
Print a foldkit-richtext document to Markdown and inspect any conversion diagnostics:
import * as RichText from 'foldkit-richtext'
import { print } from 'foldkit-richtext-markdown'
const document = RichText.decodeDocument({
version: 1,
children: [
{
type: 'Paragraph',
id: 'p',
children: [{ type: 'Text', id: 't', text: 'hello', marks: [] }],
},
],
})
const { markdown, diagnostics } = print(document)
// markdown === 'hello\n', diagnostics === []print is a pure function of a Document. When a block kind has no Markdown syntax, print outputs its inner content and records an entry in diagnostics so your application can warn or block export. Preserved Unknown blocks are skipped and reported because their payload is opaque. Your application keeps the Document in its Model and uses foldkit-richtext-dom for the editable DOM subtree.