RyuseiLight is a beautiful, lightweight and extensible Syntax Highlighter, written in TypeScript. It tokenizes code by regular expressions likewise other popular highlighters. One of the biggest problem of regex based highlighter, however, is how to handle nested syntax, such as a template literal in JavaScript. That usually requires a very complex regex that is hard to understand.
RyuseiLight adopts a state system that can count "open" and "close" symbols, inspired by Monarch. Thanks to the system, it can be simply and correctly tokenized:
// A nested template literal
`container ${
isMobile()
?'is-mobile'
:`container--${page.isFront()?'front':'page'}`
}`;
RyuseiLight does not aim for a strict tokenizer, but for good balance with simplicity and correctness. Currently, (only) 11 languages are supported, sorry!
Here is a summary of features:
Only 10kB (4kB gzipped), including JavaScript, HTML, CSS and XML
Beautiful themes, easy to customize by SASS (SCSS)
Modular for minimal bundle size
Easy to add new languages and extensions
Displaying line numbers
Highlighting lines
Displaying a language name
Displaying a code caption
HTML generation for SSR
Internet Explorer 10
Ryusei(流星, 流=flow, 星=star) is my personal project code, that means a shooting star in Japanese. ⭐