highlight() function is the main entry point for Code Syntactic Sugar. It takes JavaScript/TypeScript code as a string and returns highlighted React elements ready for rendering.
Signature
Parameters
The JavaScript or TypeScript code to highlight as a string.
Optional configuration object for customizing the highlighting behavior.
Returns
A React element containing the highlighted code. The output is a tree of
<span> elements with appropriate CSS classes for styling.Example
Example with Line Modifiers
Notes
The
highlight() function internally calls tokenize() to parse the code, then generate() to create line structures, and finally converts them to React elements.Line numbers in modifier arrays are 1-indexed (not 0-indexed). Out-of-bounds line numbers are automatically ignored.
When multiple modifiers are applied to the same line, the order of precedence is:
highlightedLines(highest priority)addedLinesremovedLines(lowest priority)
The output requires React to be installed in your project as it returns React elements.