Skip to content

Type Editor


Type Editor / @type-editor/model / dom-parser/DOMSerializer / DOMSerializer

Class: DOMSerializer

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:18

A DOM serializer knows how to convert ProseMirror nodes and marks of various types to DOM nodes.

Constructors

Constructor

ts
new DOMSerializer(nodes, marks): DOMSerializer;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:38

Create a serializer. nodes should map node names to functions that take a node and return a description of the corresponding DOM. marks does the same for mark names, but also gets an argument that tells it whether the mark's content is block or inline content (for typical use, it'll always be inline). A mark serializer may be null to indicate that marks of that type should not be serialized.

Parameters

ParameterTypeDescription
nodesRecord<string, (node) => DOMOutputSpec>The node serialization functions.
marksRecord<string, (mark, inline) => DOMOutputSpec>The mark serialization functions.

Returns

DOMSerializer

Accessors

marks

Get Signature

ts
get marks(): Record<string, (mark, inline) => DOMOutputSpec>;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:48

Returns

Record<string, (mark, inline) => DOMOutputSpec>


nodes

Get Signature

ts
get nodes(): Record<string, (node) => DOMOutputSpec>;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:44

Returns

Record<string, (node) => DOMOutputSpec>

Methods

serializeFragment()

ts
serializeFragment(
   fragment,
   options?,
   target?): HTMLElement | DocumentFragment;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:300

Serialize the content of this selfPos to a DOM selfPos. When not in the browser, the document option, containing a DOM document, should be passed so that the serializer can create nodes.

Parameters

ParameterType
fragmentFragment
options{ document?: Document; }
options.document?Document
target?HTMLElement | DocumentFragment

Returns

HTMLElement | DocumentFragment


serializeNode()

ts
serializeNode(node, options?): Node;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:360

Serialize this node to a DOM node. This can be useful when you need to serialize a part of a document, as opposed to the whole document. To serialize a whole document, use serializeFragment on its content.

Parameters

ParameterType
nodeNode
options{ document?: Document; }
options.document?Document

Returns

Node


fromSchema()

ts
static fromSchema(schema): DOMSerializer;

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:78

Build a serializer using the toDOM properties in a schema's node and mark specs.

Parameters

ParameterType
schemaSchema

Returns

DOMSerializer


renderSpec()

ts
static renderSpec(
   doc,
   structure,
   xmlNS?): {
  contentDOM?: HTMLElement;
  dom: Node;
};

Defined in: packages/model/src/dom-parser/DOMSerializer.ts:60

Render an output spec to a DOM node. If the spec has a hole (zero) in it, contentDOM will point at the node with the hole.

Parameters

ParameterType
docDocument
structureDOMOutputSpec
xmlNS?string

Returns

ts
{
  contentDOM?: HTMLElement;
  dom: Node;
}
NameTypeDefined in
contentDOM?HTMLElementpackages/model/src/dom-parser/DOMSerializer.ts:62
domNodepackages/model/src/dom-parser/DOMSerializer.ts:61