Rich text / foldkit-richtext-code-shiki
How Shiki scopes map to decorations
Shiki's inline colors are ignored. Instead, each token's TextMate scopes are matched by whole segments (so string and string.quoted match, never stringy) against nine syntax-* kinds, with the first match winning:
| Kind | Typical scopes |
|---|---|
syntax-comment | Comments and doc blocks |
syntax-property | Object keys and property names |
syntax-string | Quoted strings and string delimiters |
syntax-number | Numeric literals |
syntax-keyword | Language keywords and modifiers |
syntax-operator | Arithmetic, logical, and assignment operators |
syntax-function | Function and method names |
syntax-type | Type annotations and class names |
syntax-punctuation | Brackets, braces, and separators |
Whitespace and plain identifiers receive no decoration. Style each kind in CSS with [data-decoration="syntax-keyword"] and its siblings.
Caching and performance
Each tokenizer caches the last 64 block strings it tokenized, so an editor that runs decorate on every patch only re-parses the code block whose text changed. Reading TextMate scopes (includeExplanation) is Shiki's slower path, so a very large code block still pays a full parse per edit. The adapter disables Shiki's per-line timeout so a complex line takes longer rather than throwing during render.
Limits
- No asynchronous grammar loading. Grammars loaded after you build
tokenizersare not picked up automatically; rebuildtokenizersand update the placement when new grammars finish loading. - Fixed decoration kinds. Scopes outside the nine
syntax-*kinds above receive no decoration.
Next
- Lightweight JSON highlighting with zero grammar setup:
foldkit-richtext-code - Mount an editor and pass
decorate:foldkit-richtext-dom - Add a language selector and copy button:
foldkit-mixins-richtext