Rich text / foldkit-richtext-code

foldkit-richtext-code

Grammars for highlighting a foldkit-richtext CodeBlock.

A code block's document holds its language and its plain text, never tokens. What a highlighter finds in that text is presentation: a set of decorations, derived for a render and discarded, like a search match. foldkit-richtext owns the contract (CodeTokenizer) and the producer (codeDecorations); this package owns grammars — a tokenizer is a pure function from a block's text to token ranges.

CodeBlock { language, text } ── tokenizer ──> tokens ── codeDecorations ──> DecorationSet ──> renderer

Install

bash
pnpm add foldkit-richtext-code

What it owns

Grammars, and nothing else: no state, no document change, no loading. The document is foldkit-richtext's, drawing the result is the renderer's (foldkit-richtext-dom's read-only view draws a decoration as span[data-decoration=<kind>]), and a grammar that must load before it can run — Shiki — is a separate adapter's, because it needs a Command rather than a pure call.