Service for adding interactive features to content rendered from the Lynkow API.

Accessible via lynkow.enhancements. This is a browser-only service -- all methods are no-ops on the server. Currently provides:

  • Copy button for code blocks (elements with [data-copy-code] attribute)

  • Script activation for inline scripts injected via dangerouslySetInnerHTML

  • Widget iframe auto-resize for embedded Lynkow widgets

  • CSS normalization to ensure content renders correctly with CSS frameworks (Tailwind, etc.)

A MutationObserver automatically detects new content added to the DOM and applies enhancements, making it compatible with SPA frameworks like React/Next.js. Script clones are appended to <head> (not inline) to avoid React DOM reconciliation issues.

Access via: lynkow.enhancements

Methods

3 methods

destroy

TypeScript
destroy(): void

Cleans up all enhancement resources: disconnects the MutationObserver, removes the widget resize listener, cancels any pending animation frame, removes injected styles and cloned scripts from <head>, and resets the initialized state. After calling destroy(), you can re-initialize by calling init() again. No-op on server.

Returns: void


init

TypeScript
init(): void

Initializes content enhancements: injects CSS styles, binds copy-to-clipboard handlers on code blocks, activates inline scripts, starts the widget iframe resize listener, and sets up a MutationObserver to automatically enhance newly added DOM content. Idempotent -- calling multiple times has no effect after the first initialization. No-op on server.

Call this manually if you need to re-initialize after the client is created (e.g. after dynamically loading content outside the initial render).

Returns: void

TypeScript
// Reinitialize enhancements after dynamically loading new content
const html = await fetchArticleContent()
document.getElementById('article').innerHTML = html
lynkow.enhancements.init()

isInitialized

TypeScript
isInitialized(): boolean

Checks whether the enhancements service has been initialized.

Returns: boolean