A modern, type-safe Svelte renderer for Strapi's Blocks rich text editor. Built for Svelte 5 with full TypeScript support.
npm install @your-scope/blocks-svelte-renderer
or
pnpm add @your-scope/blocks-svelte-renderer
or
yarn add @your-scope/blocks-svelte-renderer
<script lang="ts">
import { BlocksRenderer } from 'blocks-svelte-renderer';
const content = [ { type: 'paragraph', children: [{ type: 'text', text: 'Hello, World!' }] } ];
</script>
<BlocksRenderer {content} />
You can override the default rendering by providing your own Svelte components for blocks and modifiers. Just pass what you want to customize—the rest uses the defaults.
<script lang="ts">
import { BlocksRenderer } from 'blocks-svelte-renderer';
import GreenBold from './GreenBold.svelte';
import RedHeading from './RedHeading.svelte';
const content = [ { type: 'paragraph', children: [{ type: 'text', text: 'Hello, World!' }] } ];
</script>
<BlocksRenderer
content={data.dummydata}
blocks={{ heading: RedHeading }}
modifiers={{ bold: GreenBold }}
/>
(see /routes/+page.svelte for example)
Blocks are container elements that structure your content:
paragraphheadingquotecodeimagelistlist-itemModifiers are inline elements that style text:
bolditalicunderlinestrikethroughcodelinkPass your components via the blocks and modifiers props. Block components receive a node prop with the block data, while modifier components receive children that need to be rendered.
Contributions are welcome! Please see the Contributing Guide for details.
MIT © Tadeáš Maršík
This project is inspired by and strives to maintain compatibility with Strapi's official blocks-react-renderer.