slate-serializers
View project on npmView project on GitHub

slateToDom

From @slate-serializers/dom. Converts Slate JSON to a htmlparser2 DOM (nodes use the same model as domhandler). slateToHtml uses this pipeline and then serializes to an HTML string—you only need slateToDom when you want to walk or mutate the DOM before serialization.

Config uses the same shape as slateToHtml. Default: packages/dom/src/lib/config/default.ts.

Usage

import { slateToDom, slateToDomConfig } from '@slate-serializers/dom'

const slate = [{ type: 'p', children: [{ text: 'Hello' }] }]
const dom = slateToDom(slate, slateToDomConfig)
// import { Element, Text } from '@slate-serializers/dom'
// Pass nodes to dom-serializer or traverse with domutils.

Additional exports

Helpers such as extractCssFromStyle, styleMapToAttribs, and isEmptyObject are available for attribute and style work. You can also import the ChildNode type and the Element / Text constructors from @slate-serializers/dom or @slate-serializers/html (no separate domhandler dependency required).

@slate-serializers/utilities

A separate package with small shared helpers (nested property access, style object handling, etc.). Most apps only need @slate-serializers/html or @slate-serializers/dom; import utilities when you extend serializers.

Further reading