parse.ts

Source

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

11 symbols 10 functions 1 modules 10 parameters 9 returns

Reference

fnextractIslandInfo(html: string): Promise<IslandInfo[]>Extract island info without transforming HTML. Useful for analysis/bundling pur…

Extract island info without transforming HTML. Useful for analysis/bundling purposes.

Signature

export async function extractIslandInfo(html: string): Promise<IslandInfo[]>

View source

Parameters

  • html string

Returns

Promise<IslandInfo[]>
fnfindComponentElement(children: Element["children"]): Element | nullFind the component element inside <Island>.

Find the component element inside <Island>.

Signature

function findComponentElement(children: Element["children"]): Element | null

View source

Parameters

  • children Element["children"]

Returns

Element | null
fngenerateHydrationScript(components: string[]): stringGenerate client-side hydration script. This is a minimal script that imports an…

Generate client-side hydration script. This is a minimal script that imports and initializes islands.

Signature

export function generateHydrationScript(components: string[]): string

View source

Parameters

  • components string[]

Returns

string
fngetAttribute(el: Element, name: string): string | undefinedGet element attribute value.

Get element attribute value.

Signature

function getAttribute(el: Element, name: string): string | undefined

View source

Parameters

  • el Element
  • name string

Returns

string | undefined
fngetComponentName(el: Element): stringGet component name from child element.

Get component name from child element.

Signature

function getComponentName(el: Element): string

View source

Parameters

  • el Element

Returns

string
fnhasIslands(html: string): booleanCheck if HTML contains any Island components.

Check if HTML contains any Island components.

Signature

export function hasIslands(html: string): boolean

View source

Parameters

  • html string

Returns

boolean
moduleparseIsland Parser Detects <Island> components in HTML and transforms them into hydration-ready elements with data attribute…

Island Parser

Detects <Island> components in HTML and transforms them into hydration-ready elements with data attributes.

View source

fnparseProps(el: Element): Record<string, unknown>Parse JSX-style props from attributes.

Parse JSX-style props from attributes.

Signature

function parseProps(el: Element): Record<string, unknown>

View source

Parameters

  • el Element

Returns

Record<string, unknown>
fnrehypeIslands(collectedIslands: IslandInfo[])Rehype plugin to transform Island components.

Rehype plugin to transform Island components.

Signature

function rehypeIslands(collectedIslands: IslandInfo[])

View source

Parameters

  • collectedIslands IslandInfo[]
fnresetIslandCounter(): voidReset island counter (for testing).

Reset island counter (for testing).

Signature

export function resetIslandCounter(): void

View source

Returns

void
fntransformIslands(html: string): Promise<ParseIslandsResult>Transform Island components in HTML. Converts: ``html <Island load="visible"> <…

Transform Island components in HTML.

Converts:

<Island load="visible">
  <Counter initial={0} />
</Island>

To:

<div id="ox-island-0"
     data-ox-island="Counter"
     data-ox-load="visible"
     data-ox-props='{"initial":0}'
     class="ox-island">
  <!-- fallback content -->
</div>

Signature

export async function transformIslands(html: string): Promise<ParseIslandsResult>

View source

Parameters

  • html string

Returns

Promise<ParseIslandsResult>