parse
Parses a CSS theme file from assets into a color map. Results are not cached here - callers should use lazy to cache per theme.
Silently returns an empty map on any error. Use parseAsset if you need to distinguish between a missing file and an empty/unparseable theme.
Parses CSS text directly into a color map. Extracts SpanStyle for each .hljs-* selector block.
Implementation: a small recursive-descent parser over a hand-written tokenizer. Highlight.js theme CSS uses a strict, predictable subset of CSS - flat top-level rules, occasional @media / @supports / @keyframes blocks, no nested rules - so a tiny grammar handles every known theme without pulling in a full CSS engine.
The parser:
Skips comments and at-rule blocks (so
@mediarules can't clobber main rules).Walks each top-level
selectors { declarations }rule.Filters individual selectors: only standalone
.hljs[-...]chains are accepted; descendant combinators, pseudo-elements (::selection), and pseudo-classes (:hover) are skipped.Delegates declaration parsing to parseDeclarations (unchanged).
Merges into the result map via mergeSpanStyle so split rules for the same selector accumulate (CSS cascade behaviour).