MicroLighter ditches spans for CSS's Highlight API, at 2KB
•3 sources
Questions this post answers
How does MicroLighter achieve syntax highlighting without wrapping code tokens in span elements?
MicroLighter uses the CSS Custom Highlights API's `::highlight()` pseudo-element to paint colors onto ranges of plain text based on highlight registrations made in JavaScript, avoiding any DOM manipulation. This eliminates the markup bloat typical of span-based highlighters like Prism.js, and also avoids copy-paste issues caused by code being split into many nested span elements. Developers weighing syntax-highlighter options can track new browser-API-based tools like this one on daily.dev.
Why is MicroLighter only about 2KB compared to other syntax highlighting libraries?
MicroLighter stays around 2KB by loading TextMate grammars, the same grammar format VS Code uses internally, on demand instead of bundling every language and theme upfront. If a page only needs Python and JSON highlighting, only those grammars load, unlike many highlighters that ship hundreds of KB covering themes and language grammars regardless of use. Anyone picking a lightweight highlighter for a docs site can follow tools like this on daily.dev.
478.2K Impressions8 Comments