import {SyntaxStyler} from '@fuzdev/fuz_code/syntax_styler.js'; Registry and facade over the lexer engine (lexer.ts): registers languages, lexes text to a flat event stream, and renders that stream to syntax-styled HTML.
examples
import {syntax_styler_global} from '@fuzdev/fuz_code/syntax_styler_global.ts';
const html = syntax_styler_global.stylize('const x = 1;', 'ts');langs
Registered languages, keyed by id and by each alias.
type Map<string, SyntaxLang>
token_types
Token-type id space for this styler's languages.
See SyntaxStylerOptions.token_types.
type TokenTypeRegistry
constructor
type new (options?: SyntaxStylerOptions): SyntaxStyler
options
{}add_lang
Registers a language (and its aliases).
type (lang: SyntaxLang): void
lang
voidhas_lang
Whether a language is registered under id (its primary id or an alias).
type (id: string): boolean
id
stringbooleanlex
Lexes text with the language registered as lang, returning the flat
event stream, valid until the next lex (see lex_syntax). Throws when
lang is not registered — see has_lang.
type (text: string, lang: string): LexedSyntax
text
stringlang
stringstylize
Generates syntax-styled HTML (spans with .token_* classes) from
text. Throws when lang is not registered — see has_lang.
type (text: string, lang: string): string
text
stringlang
stringstring