syntax_styler.ts

view source

Declarations
#

2 declarations

SyntaxStyler
#

syntax_styler.ts view source

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

readonly

constructor

type new (options?: SyntaxStylerOptions): SyntaxStyler

options

default {}

add_lang

Registers a language (and its aliases).

type (lang: SyntaxLang): void

lang

returns void

has_lang

Whether a language is registered under id (its primary id or an alias).

type (id: string): boolean

id

type string
returns boolean

lex

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

type string

lang

type string
returns LexedSyntax

stylize

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

type string

lang

type string
returns string

SyntaxStylerOptions
#

syntax_styler.ts view source

SyntaxStylerOptions import type {SyntaxStylerOptions} from '@fuzdev/fuz_code/syntax_styler.js';

token_types?

Token-type id space used by the registered lexers. Defaults to the shared token_types_global, which the built-in lexers intern into — inject a separate registry only when every registered lexer interns into that same registry.

type TokenTypeRegistry

Depends on
#

Imported by
#