public class CodeHighlighter extends Object implements SyntaxHighlighter
Unified line-oriented syntax highlighter backed by any klyn.code.Tokenizer.
Converts lexical TokenSpan segments produced by klyn.code tokenizers into StyledSpan runs using AnsiSyntax styles, guaranteeing that the concatenated text of the returned spans always matches the input line.
import klyn.code.highlighters
highlighter = CodeHighlighter(["if", "return"], "//")
spans = highlighter.highlight("return 42 // answer")| Modifier and Type | Member | Description |
|---|---|---|
| public | CodeHighlighterCodeHighlighter(keywords as ArrayList<String> = [], lineCommentToken as String = "", caseInsensitiveKeywords as Boolean = false) |
Creates a CodeHighlighter with the given keyword list and line comment delimiter. |
| Modifier and Type | Member | Description |
|---|---|---|
| public static | fromLanguagefromLanguage(languageOrPath as String) as CodeHighlighter |
Creates a CodeHighlighter for a language identifier or file path via LanguageRegistry. |
| public static | fromTokenizerfromTokenizer(tokenizer as Tokenizer) as CodeHighlighter |
Creates a CodeHighlighter wrapping an existing klyn.code.Tokenizer. |
| public | highlighthighlight(line as String) as List<StyledSpan> |
Tokenizes and styles a single line of source code from the default LexicalState.NORMAL state. |
| public | highlightWithStatehighlightWithState(line as String, initialState as LexicalState = null) as List<StyledSpan> |
Tokenizes and styles a single line of source code starting from initialState. |
| public static | styleTokenstyleToken(text as String, kind as TokenKind) as StyledSpan |
Maps a TokenKind and token slice to its corresponding StyledSpan. |