Core architecture
WebEditor is built on three foundational technologies:ProseMirror
Document model and editing engine
React
UI components and rendering
Markdown
Input format and serialization
ProseMirror foundation
At its core, WebEditor uses ProseMirror’s document model to represent content as a structured tree rather than HTML. This provides:- Schema-based validation - Every node and mark is defined in the schema
- Transactions - All changes are atomic and can be undone/redone
- Plugins - Extensible behavior through ProseMirror’s plugin system
- State management - Immutable state with predictable updates
~/workspace/source/packages/webeditor/src/editor/index.tsx:323-343
React integration
WebEditor uses@handlewithcare/react-prosemirror to bridge ProseMirror and React, enabling:
- Custom node views - React components for complex nodes like cards and tabs
- State synchronization - React state tied to ProseMirror state
- Event handling - React event handlers for interactive components
Example node views registration
Schema system
The schema defines what content is allowed in the editor. WebEditor extends ProseMirror’s markdown schema with custom nodes and marks.Node types
Nodes represent block-level content:Standard nodes
Standard nodes
paragraph- Text paragraphsheading- Headings (levels 1-6)bullet_list- Unordered listsordered_list- Ordered listsblockquote- Quote blocks
Custom component nodes
Custom component nodes
card- Card components with titles and iconstabs- Tabbed content interfacescallout- Info/warning/error calloutscode_snippet- Syntax-highlighted code blocksaccordion- Collapsible sectionscolumns- Multi-column layoutsbadge- Inline badgesicon- Lucide iconsstep- Step-by-step instructionsmermaid- Mermaid diagramsfield- Parameter documentationframe- Content frames with captions
Mark types
Marks represent inline formatting:strong- Bold textem- Italic textcode- Inline codestrikethrough- Strikethrough texttooltip_mark- Tooltip annotations
~/workspace/source/packages/webeditor/src/editor/schema.ts:36-79
Plugin system
WebEditor uses ProseMirror plugins for editor behavior:- History
- Keymaps
- Input rules
- Custom plugins
Undo/redo functionality using
prosemirror-history:Document flow
Understanding how content moves through WebEditor:Input processing
Markdown content is preprocessed to handle frontmatter and code blocks, then parsed to HTML using marked.js
State management
WebEditor maintains several layers of state:The editor uses React state for UI (menus, dialogs) and ProseMirror state for document content, keeping concerns separated.
- ProseMirror EditorState - The document content and selection
- React component state - UI state for menus, modals, and controls
- Theme state - Light/dark mode preferences
- Plugin state - History stack, custom plugin data
Next steps
Markdown & JSX
Learn how markdown is parsed and JSX components are handled
Components
Explore the component system and command menu
Marks
Understand text formatting and the marks menu
Theme system
Configure light, dark, and auto theme modes