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.

Usage

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

const slate = [{ type: 'p', children: [{ text: 'Hello' }] }]
const dom = slateToDom(slate, slateToDomConfig)
// Import types and Element/Text constructors from @slate-serializers/dom or @slate-serializers/html (PR #215, #218).
// Pass nodes to dom-serializer or traverse with domutils.

Additional exports

The package also exports helpers such as extractCssFromStyle, styleMapToAttribs, and isEmptyObject for working with attributes and styles. It re-exports the ChildNode type and the Element and Text constructors from domhandler so you can import them from @slate-serializers/dom or @slate-serializers/html without a direct domhandler dependency — see PR #215 and PR #218. Index: packages/dom/src/index.ts.

@slate-serializers/utilities

A separate package with small shared helpers (nested property access, style object handling, etc.). Most apps consume serializers through @slate-serializers/html or dom without importing utilities directly; reach for it when you extend or debug serializers.

Source: packages/utilities/src/index.ts.

Further reading