Skip to content

highlight.ts#

View Markdown

Source

4 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

4 symbols 3 functions 1 modules 6 parameters 2 returns

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.

View source

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>

View source

Parameters

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>

View source

Parameters

  • html string
  • mergeHighlightedCodeBlocks (originalHtml: string, highlightedHtml: string) => string
  • options HighlightOptions

    optional

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)

View source

Parameters

  • highlighter (code: string, language: string) => Element | null

    optional