Repository navigation
@pierre/words v0.3.0
What's Changed
- Pass
islandsto<Markdown>to mount React components fromisland-NAMEfences and inline directives while the stream continues. See Reactive islands below. @fat in #1302 - Import
@pierre/words/no-mathfor the same API with a WebAssembly module about a third smaller, for apps that render no TeX. @kurtextrem in #1306 - Use
allowedHtmlto keep a list of raw HTML tags and their attributes, such as{ details: ['open'], summary: [] }. @ije in #1320 - Code highlighters and renderers now receive
meta, the rest of the fence info string after the language. @ije in #1319 init(module)now replaces only the instance of the entry it is imported from. @ije in #1318- Fixed the first/last child margin reset in
styles.cssbeing overridden. @ije in #1316 - The fade animation no longer merges or removes text nodes in hook output. @ije in #1317
Reactive islands
Write an island-NAME fence with a JSON body, or an inline :NAME[label]{key="value"} directive for an island with inline: true. Keep the fence id stable and unique in the document so the component keeps its state. An inline directive gets an id from its content when it has none:
```island-counter
{"id":"article-votes","label":"Votes"}
```
Open :file[app.tsx]{path="src/app.tsx"} to see the code.import { Markdown, type ReactiveIslands } from '@pierre/words/react';
import { useState } from 'react';
function Counter({ label }: { label: string }) {
const [count, setCount] = useState(0);
return (
<button type="button" onClick={() => setCount((n) => n + 1)}>
{label} ({count})
</button>
);
}
const islands: ReactiveIslands = {
counter: {
fallback: 'Loading counter…',
render: ({ label }) =>
typeof label === 'string' ? <Counter label={label} /> : null,
},
file: {
inline: true,
render: ({ label, path }) =>
typeof label === 'string' && typeof path === 'string' ? (
<a href={`/files/${path}`}>{label}</a>
) : null,
},
};
export function Message({ text, active }: { text: string; active: boolean }) {
return (
<Markdown islands={islands} isAnimating={active}>
{text}
</Markdown>
);
}render(data) returns an element, or null to show the source as code. An open fence is hidden while it streams unless pending is set.
New Contributors
- @kurtextrem made their first contribution in #1306.