npm.io
2.8.5 • Published 1 month ago

@slate-serializers/dom

Licence
MIT
Version
2.8.5
Deps
8
Size
49 kB
Vulns
0
Weekly
0
Stars
94

@slate-serializers/dom

Convert Slate JSON to a domhandler document tree (the same DOM model used by htmlparser2 / html-entities).

It is used by @slate-serializers/html (slateToHtml) before serializing to an HTML string. Use slateToDom directly when you want to inspect or manipulate the tree (e.g. with domutils) before calling dom-serializer yourself.

Docs: all packages · demo — slateToDom

Install

npm install @slate-serializers/dom

Usage

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

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

const dom = slateToDom(slate, slateToDomConfig)

Configuration

DOM helpers from this package

Element and Text are re-exported from domhandler so you can use new Element(...) without adding domhandler only for the constructor:

import { Element, type SlateToDomConfig } from '@slate-serializers/dom'

ChildNode is available as import type { ChildNode } only.

Engineering

See Engineering decisions.

Keywords