@revideo/2d / code / LezerHighlighter
Class: LezerHighlighter
Defined in: 2d/src/lib/code/LezerHighlighter.ts:13
Describes custom highlighters used by the Code node.
Implements
CodeHighlighter<LezerCache|null>
Constructors
Constructor
new LezerHighlighter(
parser,style?):LezerHighlighter
Defined in: 2d/src/lib/code/LezerHighlighter.ts:17
Parameters
parser
Parser
style?
HighlightStyle = DefaultHighlightStyle
Returns
LezerHighlighter
Methods
highlight()
highlight(
index,cache):HighlightResult
Defined in: 2d/src/lib/code/LezerHighlighter.ts:60
Highlights the code at the given index.
Parameters
index
number
The index of the code to highlight.
cache
LezerCache | null
The result of prepare.
Returns
Implementation of
initialize()
initialize():
boolean
Defined in: 2d/src/lib/code/LezerHighlighter.ts:33
Initializes the highlighter.
Returns
boolean
Remarks
This method is called when collecting async resources for the node. It can be called multiple times so caching the initialization is recommended.
If initialization is asynchronous, a promise should be registered using
DependencyContext.collectPromise and the value of false should
be returned. The hook will be called again when the promise resolves.
This process can be repeated until the value of true is returned which
will mark the highlighter as ready.
Implementation of
prepare()
prepare(
code):LezerCache|null
Defined in: 2d/src/lib/code/LezerHighlighter.ts:37
Prepares the code for highlighting.
Parameters
code
string
The code to prepare.
Returns
LezerCache | null
Remarks
This method is called each time the code changes. It can be used to do any preprocessing of the code before highlighting. The result of this method is cached and passed to highlight when the code is highlighted.
Implementation of
tokenize()
tokenize(
code):string[]
Defined in: 2d/src/lib/code/LezerHighlighter.ts:89
Tokenize the code.
Parameters
code
string
The code to tokenize.
Returns
string[]