Skip to main content

Overview

The doc extension defines the root document node that serves as the top-level container for all content in a ProseKit editor. Every editor must have exactly one doc node as its root.

Installation

npm install @prosekit/extensions

Usage

import { defineDoc } from '@prosekit/extensions/doc'
import { union } from '@prosekit/core'
import { defineParagraph } from '@prosekit/extensions/paragraph'

const extension = union([
  defineDoc(),
  defineParagraph(),
])

API Reference

defineDoc()

Defines the document node specification. Returns: DocExtension Type Signature:
type DocExtension = Extension<{ Nodes: { doc: Attrs } }>

Node Specification

The doc node is defined with the following properties:
  • name: doc
  • content: block+ (requires at least one block-level node)
  • topNode: true (indicates this is the root node)

Details

Content Model

The doc node accepts one or more block-level nodes as its children. This means you must define at least one block extension (such as paragraph, heading, or codeBlock) for your editor to function properly.

Top Node

The topNode: true property marks this as the root of the document tree. There can only be one top node in a schema, and it cannot be nested inside other nodes.

Examples

Basic Editor Setup

import { createEditor } from '@prosekit/core'
import { defineDoc } from '@prosekit/extensions/doc'
import { defineParagraph } from '@prosekit/extensions/paragraph'
import { defineText } from '@prosekit/extensions/text'
import { union } from '@prosekit/core'

const extension = union([
  defineDoc(),
  defineParagraph(),
  defineText(),
])

const editor = createEditor({ extension })

With Multiple Block Types

import { union } from '@prosekit/core'
import { defineDoc } from '@prosekit/extensions/doc'
import { defineParagraph } from '@prosekit/extensions/paragraph'
import { defineHeading } from '@prosekit/extensions/heading'
import { defineBlockquote } from '@prosekit/extensions/blockquote'
import { defineCodeBlock } from '@prosekit/extensions/code-block'

const extension = union([
  defineDoc(),
  defineParagraph(),
  defineHeading(),
  defineBlockquote(),
  defineCodeBlock(),
])