github pierrecomputer/pierre words-v0.3.0
@pierre/words v0.3.0

one hour ago

What's Changed

  • Pass islands to <Markdown> to mount React components from island-NAME fences and inline directives while the stream continues. See Reactive islands below. @fat in #1302
  • Import @pierre/words/no-math for the same API with a WebAssembly module about a third smaller, for apps that render no TeX. @kurtextrem in #1306
  • Use allowedHtml to 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.css being 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

Full changelog

Don't miss a new pierre release

NewReleases is sending notifications on new releases.