The document
Every node and mark Blockleaf stores, and the versioning promise around them.
This is the contract. Everything else in the project can be refactored; this cannot, because it lives in other people's databases.
Status: version 2, unstable. The shape below will change before 1.0. Every change bumps schemaVersion and ships a migration.
Envelope
Every document is a single doc node carrying its schema version:
{
"type": "doc",
"attrs": { "schemaVersion": 2 },
"content": [
{
"type": "paragraph",
"content": [{ "type": "text", "text": "Hello" }]
}
]
}schemaVersion is not decoration. Without it, the first breaking change is unshippable — you cannot tell a v1 document from a v2 one, so you cannot migrate it. Store the whole envelope, not just content.
Rules
- Store the envelope verbatim. Don't unwrap
contentand don't re-key anything. If you need a different shape in your database, keep a converter at the boundary and store the original alongside it. - Validate before you store.
isBlockleafDocument()is a cheap structural guard today; a full Zod schema is exported from@blockleaf/editor/validate(Zod is an optional peer, so it costs nothing unless you import it) so hosts can reject malformed client input server-side. - Never hand-edit stored JSON across a version boundary. Run it through
migrate()instead — see Reading an older document. - Block ids are stable. Once a block has an id it keeps it for life — drag handles, anchor links, comments and collaborative cursors all key off it.
Reading an older document
A document keeps the schemaVersion it was saved with. When a later release bumps SCHEMA_VERSION, migrate() brings an older document up to date, one version at a time:
import { migrate } from '@blockleaf/editor';
const current = migrate(stored);- The editor does this for you. A
defaultValueat an older version is migrated before it opens. Nothing is saved until the user edits, and that save carries the current version.editor.commands.setContent()is Tiptap's own and does not migrate — pass itmigrate(doc). - Everywhere else, call it yourself: on the server before validating with
@blockleaf/editor/validate, and before handing a stored document to@blockleaf/renderer. - It never changes its input. A document already at the current version comes back as the same object, so calling it on every read costs nothing.
- It only goes forward. A document newer than your editor comes back untouched; the editor opens it read-only (see
incompatibleDocument). - Anything that is not a Blockleaf document comes back untouched — a value without a whole-number
attrs.schemaVersionof 1 or more.
SCHEMA_VERSION is 2. See version 2 for what changed from 1.
Node set
From Tiptap's StarterKit: doc, paragraph, text, hardBreak, heading, bulletList, orderedList, listItem, blockquote, codeBlock, horizontalRule.
Added on top of it:
| Node | Attributes | Notes |
|---|---|---|
paragraph | textAlign | Version 2, optional: left, center, right or justify; absent means the language's own direction. See text styles. |
heading | level: 1 | 2 | 3 | Capped at three. Deeper levels are a document-structure smell and a renderer problem. Takes textAlign, as paragraph does. |
bulletList / orderedList / listItem | — | Nesting capped at 3 levels. |
taskList / taskItem | checked: boolean | The single most-expected Notion feature. |
codeBlock | language: string | null | Highlighting via lowlight; the language is stored, not inferred at render time. |
image | id, src, alt, width, align | id is the upload adapter's handle, so a host can re-resolve or re-sign src later. Never store a signed URL as the only reference. width is pixels, or since version 2 \"full\". |
callout | emoji: string, tone: string | Cheap to build, instantly reads as "Notion". |
details | open: boolean | A toggle. Its first block is the title and the blocks after it are the body that open shows or hides. |
table | — | Contains tableRow and nothing else. Not nestable: a cell may not contain a table. |
tableRow | — | Contains tableHeader or tableCell. A header row is a row of tableHeader, not a flag on the table. |
tableHeader / tableCell | colspan, rowspan, colwidth | Cells hold block content, so a cell can contain paragraphs and lists. colwidth is number[] | null — pixel widths; see below. |
video | id, src, poster, width, align | Version 2. src is https: or relative, never a data: URL. See media. |
audio | id, src, title | Version 2. title is the player's accessible name. See media. |
attachment | id, src, name, size, mime | Version 2. A file to download; size in bytes. See media. |
figure | — | A captioned block: a table, an image, a video, an audio or an attachment, then its caption, nothing else. See Captions. |
caption | textAlign | Rich text — inline content with marks, so a credit keeps its link. Only ever the last child of a figure. textAlign is version 2; absent follows the block. |
mention | id, label, kind | Inline, version 2. id is your key, label the name when it was mentioned, kind an optional string. See mentions. |
tableOfContents | — | Version 2. Stores nothing but its block id: the entries are the document's headings, listed whenever it is drawn. See table of contents. |
Mark set
| Mark | Attributes | Notes |
|---|---|---|
bold, italic, strike, underline, code | — | |
link | href, target, rel | href is sanitised at the schema level, not in the UI: https:, mailto: and site-relative paths are allowed, everything else — javascript: above all — is dropped on parse. A sanitiser that only runs in the toolbar is not a sanitiser. |
highlight | color: string | null | null is the plain highlight. Since version 2 the editor writes a token here — the background colour, see text styles; a hex or rgb() stored before still renders. |
subscript, superscript | — | Version 2. They exclude each other: a run is never both. See text styles. |
fontFamily | family: string | Version 2. A token — sans, serif, mono, or one you define — never a font name. See text styles. |
fontSize | size: string | Version 2. A token — sm, lg, xl, or one you define — never a length. See text styles. |
textColor | color: string | Version 2. A token — red, or one you define — never a CSS colour. See text styles. |
colwidth, the one presentation attribute
colwidth stores pixel widths inside a document that otherwise stores meaning. It is here because ProseMirror's table implementation expects it, not because storing layout is a good idea. The editor has not written it so far; when column resizing ships (see the roadmap) a dragged width is stored here and shown exactly on every screen, phone included. A table wider than its container scrolls inside its wrapper rather than squeezing, in the editor and in @blockleaf/renderer alike. It is not a precedent: no other node gains a layout attribute without the same argument being made in public, and the table's coming full-width setting stores a named value, not pixels.
A table is a grid of rich-text cells with an optional header row. Nested tables and spreadsheet behaviour are out of scope. A cell background and a vertical alignment are on the roadmap, stored as tokens.
Captions
A captioned block is stored inside a figure, with the caption beside it. The block is a table, or since version 2 an image, a video, an audio clip or a file:
{
"type": "figure",
"attrs": { "id": "…" },
"content": [
{
"type": "image",
"attrs": {
"id": "…",
"src": "https://cdn.test/bridge.png",
"alt": "A suspension bridge in fog"
}
},
{
"type": "caption",
"attrs": { "textAlign": "center" },
"content": [{ "type": "text", "text": "The Golden Gate at 6 a.m." }]
}
]
}- The block inside is stored exactly as it is without a caption. Adding a caption wraps it; removing one unwraps it. Nothing about the table or image changes.
- Beside, not inside. ProseMirror's table implementation reads every child of a
tableas a row, so a caption inside the table would read as a broken row. Beside also leaves an image the single, uneditable block it always was. - One mechanism for every caption. Images, video, audio and files use the same
figureandcaption, and so will embeds on the roadmap. The blocks a figure may hold besides a table are a node group,captionable, so a block from a subpath joins it without the core naming it. - The caption's own alignment.
textAlignon the caption, the same four values as a paragraph's. Absent, it follows its block: under a centred image it is centred. - A caption is not alt text. See caption or alt text.
- Tables needed no
SCHEMA_VERSIONbump.figureandcaptionwere new node types when tables gained them, and no existing node changed. An editor older than this one keeps a captioned table as a placeholder and saves it back intact. An older@blockleaf/rendererrenders nothing for it — the whole table, not only the caption — so upgrade the renderer before the editor. A captioned image is version 2; see below.
Version 2
Version 2 adds node and mark types, and one optional attribute.
mention—{ id: string, label: string, kind: string | null }, inline. See mentions.subscriptandsuperscript— marks with no attributes, which exclude each other.textColor— a mark with{ color }, a token: lower case, a letter first, at most 32 characters. See text styles.fontFamilyandfontSize— marks with{ family }and{ size }, tokens liketextColor's.tableOfContents— a block with no attributes beyond its id. It never stores its entries, so it cannot go stale.textAlignonparagraphandheading—'left' | 'center' | 'right' | 'justify', or absent for the language's own direction. Absent is the default and stores nothing, so an unaligned block is stored exactly as in version 1. It is in every preset, unlike the commands that set it, so an editor without them still keeps it on save.video,audioandattachment— media blocks, each captionable. Their sources arehttps:or relative, neverdata:. See media.width: "full"onimageandvideo— the width of the page, as a name. An image'swidthwas pixels ornullin version 1, and still is unless someone presses Full width. See resizing.- An image in a
figure— a figure may hold animageas well as atable, and itscaptiontakestextAlign, absent to follow the image. An editor that only knows version 1 would refuse an image inside a figure, which is why this is in the bump and not beside it like the table caption was. - The rest of the batch, such as maths and media, joins version 2 before it is released. It is one bump for all of them, not one each. Emoji are not in it: they are stored as plain text.
The migration from 1 changes nothing: every version 1 document is already a valid version 2 one, so migrate() only stamps the new number. The bump is there for the other direction. An editor that only knows version 1 opens a version 2 document read-only rather than editing around nodes it cannot show.
Upgrade @blockleaf/renderer before the editor, as with any schema change. An older renderer skips a node it does not know, so a mention would go missing from the page.
Types this document does not define
A node or mark whose type is a string not listed above is unrecognised.
It may come from a newer version of this schema, from a subpath your editor
did not load, or from someone's own extension. It is still a valid part of a
Blockleaf document, and every part of Blockleaf leaves it alone:
- The validator accepts it anywhere a node or mark may go, does not look
inside it, and returns it exactly as it was. Every type listed above is
still checked in full — a
headingwithlevel: 4is a broken heading, not an unrecognised node, and is refused. A node with no stringtypeat all is refused too. - The editor shows it as a placeholder and saves it back byte for byte, unless the author deletes it. The one exception is an unrecognised node where the schema allows no block at all, such as directly inside a list; that document opens read-only. See a block the editor does not know.
- The renderer renders nothing for an unrecognised node and plain text for
an unrecognised mark, unless you pass an
unknownoverride. See rendering.
In TypeScript these are UnrecognisedNode and UnrecognisedMark. They are
deliberately not members of BlockNode, InlineNode or BlockleafMark,
because a member typed type: string would stop node.type === 'heading'
from narrowing. So code that walks a document needs a default branch: the
types describe what this schema defines, and a stored document can always
hold more.
What is not kept is an unknown attribute on a known node. The validator
strips it and the editor drops it. That is why adding an attribute to an
existing node always needs a SCHEMA_VERSION bump and a migration: an
older editor would lose it. A new node type survives an older editor as a
placeholder, so new types are batched into one planned bump — version 2
carries all of them — rather than bumping for each.
Explicitly out of v0.1
Columns, embeds, footnotes, comments, math. Each is a project of its own, and saying so here is what lets every "can you also…" have somewhere to be pointed.
Tables were on this list until 2026-10-10. They were moved into the first release on purpose, because the schema cost of a table is lowest before the first release and rises permanently after it.
Changing this document
Before the first release — expired
Until 0.1.0 the registry had no @blockleaf/editor at all, so nothing was in anyone's database: additive node work landed inside version 1 rather than bumping to 2, and there was no migration to write because there was nothing to migrate. The table nodes used that exemption.
It expired when 0.1.0 was published on 18 October 2026. The numbered process below now governs every change, without exception. An additive change is cheap exactly once; the whole point of versioning the document is that nobody gets to decide it is cheap a second time.
- Add the change behind the next
SCHEMA_VERSION. - Write the migration from the previous version in the same PR, as a new entry in
migrationsinpackages/editor/src/core/migrate.ts, keyed by the version it migrates from. The runner stamps the new version; the migration only changes the shape. - Update the snapshot fixture; the diff in review is the contract change, so it should be read as one.
- Changeset: a minor while we are on
0.x, a major after1.0.
packages/editor/tests/migrate.test.ts fails until step 2 is done: it wants a migration from every version below SCHEMA_VERSION, and it migrates a frozen version 1 document (tests/fixtures/schema-v1.json, never updated) and validates the result against the current schema.
The snapshot test in packages/editor/tests/schema.test.ts exists to make an accidental change fail loudly. It is not there to make a deliberate change hard — it is there to make it visible.