Ox Content

parse.ts

Source

getAttribute

function

Get element attribute value.

Source

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

Returns

string | undefined -


parseProps

function

Parse JSX-style props from attributes.

Source

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

Returns

Record<string, unknown> -


findComponentElement

function

Find the component element inside <Island>.

Source

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

Returns

Element | null -


getComponentName

function

Get component name from child element.

Source

function getComponentName(el: Element): string

Returns

string -


resetIslandCounter

function

Reset island counter (for testing).

Source

export function resetIslandCounter(): void

Returns

void -


rehypeIslands

function

Rehype plugin to transform Island components.

Source

function rehypeIslands(collectedIslands: IslandInfo[])

transformIslands

function

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>

Source

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

Returns

Promise<ParseIslandsResult> -


hasIslands

function

Check if HTML contains any Island components.

Source

export function hasIslands(html: string): boolean

Returns

boolean -


extractIslandInfo

function

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

Source

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

Returns

Promise<IslandInfo[]> -


generateHydrationScript

function

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

Source

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

Returns

string -