Skip to content

Document

The Document node is the invisible root of every editor. It wraps all top-level content and defines the document structure. You never render it directly, but every editor requires it.

Document is included in StarterKit. If you are building a custom setup without StarterKit, add it manually:

import { Editor, Document, Text, Paragraph } from '@domternal/core';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Text, Paragraph],
content: '<p>Hello world</p>',
});
PropertyValue
ProseMirror namedoc
TypeNode
Top nodeYes
Contentblock+
GroupNone
Rendered in DOMNo

The block+ content expression means the document must contain at least one block-level node (such as a Paragraph, Heading, or Blockquote). If you create an editor with null or empty content, the document automatically starts with one empty paragraph.

When you call editor.getJSON(), the document is the outermost node:

{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{ "type": "text", "text": "Hello world" }
]
}
]
}

You can use this format to set or restore editor content:

editor.setContent({
type: 'doc',
content: [
{
type: 'paragraph',
content: [{ type: 'text', text: 'Hello world' }],
},
],
});

The same JSON structure is accepted by the SSR helpers generateHTML and generateText for server-side rendering without a browser DOM.

By default, Document accepts any block nodes (block+). You can extend it to restrict the content model. For example, to enforce that the first child is always a heading:

import { Document } from '@domternal/core';
const CustomDocument = Document.extend({
content: 'heading block*',
});

This schema requires a Heading as the first node, followed by zero or more block nodes. ProseMirror enforces the content model, so the editor will not allow the user to delete the heading.

Other useful content expressions:

ExpressionMeaning
block+One or more block nodes (default)
heading block*A heading followed by any block nodes
(heading | paragraph) block*A heading or paragraph first, then any block nodes
block{1,10}Between 1 and 10 block nodes

Document has no configurable options.

Document adds no commands.

Document adds no keyboard shortcuts.

@domternal/core - Document.ts