The Schema is the “dictionary” and “grammar” of your editor. It defines what types of content are allowed and how they behave.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/euclidesseg/euclides-workspace/llms.txt
Use this file to discover all available pages before exploring further.
What is a Schema?
In ProseMirror (and therefore Euclides), the schema defines:- What nodes exist - Block-level structures like paragraphs, headings, lists
- What marks exist - Inline formatting like bold, italic, links
- How they parse from HTML - Converting pasted HTML into the document
- How they serialize to HTML - Converting the document back to HTML
- What attributes they support - Custom properties like text alignment
The schema acts as a contract. Content that doesn’t match the schema cannot exist in the document. This prevents invalid document states.
EuclidesEditorSchema Definition
Euclides extends ProseMirror’s basic schema to add custom features. Here’s the complete schema (euclides-schema.ts:49):- Starts with
prosemirror-schema-basicas the foundation - Adds list support with
addListNodes - Extends the paragraph node with custom attributes
- Adds the
strikemark for strikethrough text
Built-in Nodes
Euclides inherits these nodes fromprosemirror-schema-basic:
| Node | HTML | Description |
|---|---|---|
doc | - | Root document node |
paragraph | <p> | Text paragraph (extended with textAlign) |
heading | <h1>–<h6> | Headings level 1-6 |
blockquote | <blockquote> | Block quotation |
horizontal_rule | <hr> | Horizontal divider |
code_block | <pre><code> | Code block |
text | - | Plain text node |
hard_break | <br> | Line break |
image | <img> | Image |
prosemirror-schema-list:
| Node | HTML | Description |
|---|---|---|
bullet_list | <ul> | Unordered list |
ordered_list | <ol> | Ordered list |
list_item | <li> | List item |
Built-in Marks
Euclides includes these marks:| Mark | HTML | Description |
|---|---|---|
strong | <strong> | Bold text |
em | <em> | Italic text |
link | <a> | Hyperlink |
code | <code> | Inline code |
strike | <s> | Strikethrough (custom addition) |
Custom Node: Paragraph with Text Alignment
Euclides extends the basic paragraph node to support text alignment (euclides-schema.ts:10):The
0 in toDOM indicates where the node’s content should be placed. It’s a ProseMirror convention for “content hole”.How It Works
- attrs - Defines the
textAlignattribute with default value ‘left’ - parseDOM - When pasting HTML, extracts
text-alignfrom the style attribute - toDOM - When rendering, applies the alignment as an inline style
Custom Mark: Strike (Strikethrough)
Euclides adds strikethrough as a custom mark (euclides-schema.ts:37):- Recognizes
<s>,<del>, ortext-decoration: line-throughwhen parsing - Outputs as
<s>tag when serializing - Can be toggled with
toggleMarkcommand
Adding List Support
Lists require special handling because they have hierarchical structure. Euclides uses theprosemirror-schema-list package:
addListNodes function:
- Takes the existing nodes
- Adds
bullet_list,ordered_list, andlist_itemnodes - Configures them to contain
paragraphand other blocks - Returns the extended node collection
Schema Rules and Validation
The schema enforces document structure at all times:Content Expressions
Content Expressions
Each node defines what content it can contain using expressions like:
"inline*"- Zero or more inline elements"block+"- One or more block elements"paragraph block*"- A paragraph followed by any blocks
Groups
Groups
Nodes belong to groups like “block” or “inline”, allowing rules like “accepts any block node”
Marks
Marks
Each node specifies which marks can be applied to its content. By default, inline content accepts all marks.
Attributes
Attributes
Attributes must have default values or be explicitly set when creating nodes. No undefined attributes allowed.
Reading the Schema at Runtime
You can inspect the schema in your code:The component code uses this pattern to access node and mark types when executing commands (euclides-rich-editor.component.ts:67):
Why Schema Matters
Type Safety
The schema prevents invalid document states at runtime
Parsing Control
Define exactly how pasted HTML becomes your document
Serialization
Control how your document converts to HTML
Command Safety
Commands work with schema to ensure valid transforms
Next Steps
Nodes vs Marks
Learn when to use nodes vs marks
Editor State
See how schema integrates with state