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:

KindTypical scopes
syntax-commentComments and doc blocks
syntax-propertyObject keys and property names
syntax-stringQuoted strings and string delimiters
syntax-numberNumeric literals
syntax-keywordLanguage keywords and modifiers
syntax-operatorArithmetic, logical, and assignment operators
syntax-functionFunction and method names
syntax-typeType annotations and class names
syntax-punctuationBrackets, 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 tokenizers are not picked up automatically; rebuild tokenizers and update the placement when new grammars finish loading.
  • Fixed decoration kinds. Scopes outside the nine syntax-* kinds above receive no decoration.

Next