parse.ts

Source

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

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.

View source

Parameters

  • html string

Returns

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

Find the component element inside <Island>.

View source

Parameters

  • children unknown

Returns

Element | literal
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.

View source

Parameters

  • components string[]

Returns

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

Get element attribute value.

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.

View source

Parameters

  • el Element

Returns

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

Check if HTML contains any Island components.

View source

Parameters

  • html string

Returns

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

Parse JSX-style props from attributes.

View source

Parameters

  • el Element

Returns

Record
fnrehypeIslands(collectedIslands: IslandInfo[])Rehype plugin to transform Island components.

Rehype plugin to transform Island components.

View source

Parameters

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

Reset island counter (for testing).

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>

View source

Parameters

  • html string

Returns

Promise