highlight.ts#
4 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference#
modulehighlightSyntax highlighting with the native tree-sitter engine. Markup uses <pre class="ox-highlight css-variables"> and --octc…
Syntax highlighting with the native tree-sitter engine.
Markup uses <pre class="ox-highlight css-variables"> and --octc-syntax-* custom properties so theme-color packages resolve token colors.
fnhighlightCode(html: string, options?: HighlightOptions): Promise<string>Apply the selected syntax-highlighting backend to HTML. Tries the document pass…
Apply the selected syntax-highlighting backend to HTML.
Tries the document pass first. If that pass skips unreadable markup, falls back to a per-block walk. Languages without a supported grammar stay as the original <pre><code>.
Signature
export async function highlightCode(html: string, options?: HighlightOptions): Promise<string>Parameters
-
htmlstring -
optionsHighlightOptionsoptional
Returns
Promise<string>
fnhighlightPageHtml(html: string, mergeHighlightedCodeBlocks: (originalHtml: string, highlightedHtml: string) => string, options?: HighlightOptions): Promise<string>Highlight every code block in a rendered page, preserving original classes and…
Highlight every code block in a rendered page, preserving original classes and per-line metadata when the native document pass cannot read the markup.
Signature
export async function highlightPageHtml(html: string, mergeHighlightedCodeBlocks: (originalHtml: string, highlightedHtml: string) => string, options?: HighlightOptions): Promise<string>Parameters
-
htmlstring -
mergeHighlightedCodeBlocks(originalHtml: string, highlightedHtml: string) => string -
optionsHighlightOptionsoptional
Returns
Promise<string>
fnrehypeCodeHighlight(highlighter?: (code: string, language: string) => Element | null)Per-block walk used when the native document pass cannot read the markup. Unkno…
Per-block walk used when the native document pass cannot read the markup. Unknown languages stay as the original <pre><code>.
Signature
function rehypeCodeHighlight(highlighter?: (code: string, language: string) => Element | null)Parameters
-
highlighter(code: string, language: string) => Element | nulloptional