# @slate-serializers/template

> Serialize top-level Slate blocks to HTML strings and custom outputs via per-type serializers.

Latest version **2.8.5** (published 2026-10-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @slate-serializers/template
pnpm add @slate-serializers/template
yarn add @slate-serializers/template
bun add @slate-serializers/template
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.8.5 |
| Published | 2026-10-24 |
| First published | 2023-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 94 |
| Maintainers | thompsonsj |
| Keywords | slate, slate-js, serializer, rich-text, template, cms, slate-to-template |

## Links

- npm: https://www.npmjs.com/package/@slate-serializers/template
- Repository: https://github.com/thompsonsj/slate-serializers
- Homepage: https://github.com/thompsonsj/slate-serializers/tree/main/packages/template#readme
- Issues: https://github.com/thompsonsj/slate-serializers/issues
- npm.io page: https://npm.io/package/@slate-serializers/template

## Dependencies (11)

- [slate](https://npm.io/package/slate.md) ^0.126.2
- [tslib](https://npm.io/package/tslib.md) 2.8.1
- [domutils](https://npm.io/package/domutils.md) ^4.0.0
- [css-select](https://npm.io/package/css-select.md) ^7.0.0
- [domhandler](https://npm.io/package/domhandler.md) ^6.0.0
- [htmlparser2](https://npm.io/package/htmlparser2.md) ^12.0.0
- [html-entities](https://npm.io/package/html-entities.md) ^2.6.0
- [dom-serializer](https://npm.io/package/dom-serializer.md) ^3.1.1
- [slate-hyperscript](https://npm.io/package/slate-hyperscript.md) ^0.125.0
- [@slate-serializers/dom](https://npm.io/package/@slate-serializers/dom.md) 2.8.5
- [@slate-serializers/html](https://npm.io/package/@slate-serializers/html.md) 2.8.5

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 2.8.5 (latest) — 2026-10-24
- 2.8.4 — 2026-10-23
- 2.8.3 — 2026-10-19
- 2.8.2 — 2026-10-10
- 2.8.1 — 2026-10-09
- 2.8.0 — 2026-10-02
- 2.7.0 — 2026-09-28
- 2.6.0 — 2026-09-15
- 2.5.5 — 2026-07-26
- 2.5.4 — 2026-07-20
- 2.5.3 — 2026-04-20
- 2.5.2 — 2026-04-20
- 2.5.1 — 2026-04-18
- 2.5.0 — 2026-04-18
- 2.4.0 — 2026-04-18
- … 21 more at https://npm.io/package/@slate-serializers/template/versions

## README

# @slate-serializers/template

Render Slate JSON as a combination of HTML and custom serializers that you pass to the configuration.

**Docs:** [all packages](https://github.com/thompsonsj/slate-serializers/blob/main/README.md) · [demo](https://thompsonsj.github.io/slate-serializers-demo) — [slateToTemplate](https://thompsonsj.github.io/slate-serializers-demo/slate-to-template/docs)

Returns an array. By default, each array element is the output of `@slate-serializers/html`. If you pass a custom serializers, your serialized output will be included in this array. These serializers match on top-level Slate nodes only using the `type` attribute.

## Usage

### slateToTemplate

```ts
import { slateToTemplate } from '@slate-serializers/template'

const slate = [
  {
    children: [
      {
        text: 'Heading 1',
      },
    ],
    type: 'h1',
  },
  {
    children: [
      {
        text: 'Paragraph 1',
      },
    ],
    type: 'p',
  },
]

const serializedToArray = slateToTemplate(slate)
// output
// ["<h1>Heading 1</h1>", "<p>Paragraph 1</p>"]
```

### Configuration

Define a custom serializer to include any output for top-level Slate nodes of a given type.

```ts
const slate = [
  {
    children: [
      {
        text: 'Paragraph',
      },
    ],
    type: 'p',
  },
  {
    children: [
      {
        buttonType: 'primary',
        text: 'Button',
      },
    ],
    type: 'button',
  },
];

const config: SlateToTemplateConfig = {
  ...defaultTemplateConfig,
  customElementSerializers: {
    button: ({ node }) => {
      return () =>
        `<button class="${node.buttonType}">Button HTML string generated by function</button>`;
    },
  },
};

const serializedToArray = slateToTemplate(slate)
// output
// ["<p>Paragraph</p>", [Function]]
```

---
_Source: https://npm.io/package/@slate-serializers/template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
