v0.3.0
Added
preview — where a code block's HTML preview opens.
| Field | Type | Description |
|---|---|---|
url |
string or (id) => string |
The page to open. {id} is replaced with the block's id. |
storageKey |
string or (id) => string |
Key the HTML is written to. Defaults to preview-{id}. Only used with url. |
<HyperMarkdown md={markdown} preview={{ url: "/preview-code/{id}" }} />Changed
With nothing configured, a preview now opens as a page in its own right.
The Preview button used to write the HTML to localStorage under preview-<id> and open /preview-code/<id>. Both were one application's conventions, baked into the library — every other consumer got a 404 tab.
The default now opens the HTML from a blob URL: a real document with a real address, which reloads, inspects and views source like any other page, and runs in its own scope rather than the host's. It asks nothing of the host — no route, no storage, no navigation. Where no window can be had at all (a blocked popup, or a host embedded without allow-popups) the block reports it through onAlert, as it already did.
Set preview.url to take the previous behaviour back; a host that already serves a preview page keeps it with one prop, and its storage key is unchanged by default.
Previewed HTML runs with your origin. Serving your own preview page is what lets you decide how far to trust it — rendering it inside a sandboxed iframe, for instance.
Compatibility
No breaking type or signature changes; preview is optional everywhere. The only behaviour change is what happens when it is absent, which previously navigated to a route the library assumed.