Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

DOMSerializer

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

class DOMSerializer {
constructor(nodes: {
[node: string]: (node: Node) => DOMOutputSpec;
}
, marks: {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
);
readonly marks: {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
;
readonly nodes: {
[node: string]: (node: Node) => DOMOutputSpec;
}
;
 
serializeFragment(
fragment: Fragment,
options?: {
document?: Document;
}
,
target?: HTMLElement | DocumentFragment,
): HTMLElement | DocumentFragment;
serializeNode(node: Node, options?: {
document?: Document;
}
): globalThis.Node;
 
static fromSchema(schema: Schema): DOMSerializer;
static marksFromSchema(schema: Schema): {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
;
static nodesFromSchema(schema: Schema): {
[node: string]: (node: Node) => DOMOutputSpec;
}
;
static renderSpec(
doc: Document,
structure: DOMOutputSpec,
xmlNS?: string | null,
): {
dom: DOMNode;
contentDOM?: HTMLElement;
}
;
}

§Constructors

§
new DOMSerializer(nodes: {
[node: string]: (node: Node) => DOMOutputSpec;
}
, marks: {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
)
[src]

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.

§Properties

§
marks: {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
[src]

The mark serialization functions.

§
nodes: {
[node: string]: (node: Node) => DOMOutputSpec;
}
[src]

The node serialization functions.

§Methods

§
serializeFragment(fragment: Fragment, options?: {
document?: Document;
}
, target?: HTMLElement | DocumentFragment): HTMLElement | DocumentFragment
[src]

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

§
serializeNode(node: Node, options?: {
document?: Document;
}
): globalThis.Node
[src]

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.

§Static Methods

§
fromSchema(schema: Schema): DOMSerializer
[src]

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

§
marksFromSchema(schema: Schema): {
[mark: string]: (mark: Mark, inline: boolean) => DOMOutputSpec;
}
[src]

Gather the serializers in a schema's mark specs into an object.

§
nodesFromSchema(schema: Schema): {
[node: string]: (node: Node) => DOMOutputSpec;
}
[src]

Gather the serializers in a schema's node specs into an object. This can be useful as a base to build a custom serializer from.

§
renderSpec(doc: Document, structure: DOMOutputSpec, xmlNS?: string | null): {
dom: DOMNode;
contentDOM?: HTMLElement;
}
[src]

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.