Skip to content

highlight-native.ts#

View Markdown

Source

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

6 symbols 3 functions 2 interfaces 1 modules 4 parameters 5 members 3 returns

Reference#

fngetTextContent(node: Element | Root): stringExtract text content from a hast node.

Extract text content from a hast node.

Signature

export function getTextContent(node: Element | Root): string

View source

Parameters

  • node Element | Root

Returns

string
modulehighlight-nativeThe native tree-sitter highlighting path, plus the small hast helpers the per-block walk uses when the document pass ca…

The native tree-sitter highlighting path, plus the small hast helpers the per-block walk uses when the document pass cannot read the markup.

View source

fnhighlightDocumentNatively(html: string): Promise<NativeDocument | null>Highlights every code block in a rendered document in one native call. Returns…

Highlights every code block in a rendered document in one native call.

Returns the rewritten HTML and the languages it declined. Pending languages stay unhighlighted. Returns null when the native module is unavailable.

Signature

export async function highlightDocumentNatively(html: string): Promise<NativeDocument | null>

View source

Parameters

  • html string

Returns

Promise<NativeDocument | null>
fnhighlightNatively(code: string, lang: string): string | nullHighlights with the native tree-sitter engine, or null when it has no grammar f…

Highlights with the native tree-sitter engine, or null when it has no grammar for lang.

It emits --octc-syntax-* markup so theme-color packages resolve token colors.

Signature

export function highlightNatively(code: string, lang: string): string | null

View source

Parameters

  • code string
  • lang string

Returns

string | null
interfaceNativeDocumentWhat highlightDocumentNatively produced for a page.

What highlightDocumentNatively produced for a page.

Signature

export interface NativeDocument

View source

Members

Properties
NameTypeDescription
html string
pending PendingBlock[]
Well-formed blocks whose language has no native grammar, in order.
skipped string[]
Languages of elements the native pass could not read. Non-empty means the
page has to be produced by the per-block walk instead.
interfacePendingBlockA block the native pass left unhighlighted (no grammar).

A block the native pass left unhighlighted (no grammar).

Signature

export interface PendingBlock

View source

Members

Properties
NameTypeDescription
language string
source string