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.
Overview
Text alignment in Euclides Rich Editor is implemented as a custom attribute on theparagraph node. Unlike marks (which format text), node attributes modify the entire block structure.
Using setTextAlign
ThesetTextAlign method changes the alignment of the current paragraph:
The
setTextAlign method accepts any string value for alignment. Common values are: 'left', 'center', 'right', and 'justify'.How Alignment Works in the Schema
Custom Paragraph Node
Euclides Editor extends the default paragraph node to include atextAlign attribute:
~/workspace/source/projects/euclides-rich-editor/src/lib/engine/schema/euclides-schema.ts:10-34
Understanding the Implementation
Parse from HTML
When loading HTML content, the
parseDOM rule extracts the alignment from the text-align CSS property:Marks vs. Node Attributes
It’s important to understand why alignment is a node attribute rather than a mark:| Feature | Marks | Node Attributes |
|---|---|---|
| Scope | Inline text within a block | Entire block |
| Examples | Bold, italic, strikethrough | Text alignment, indentation |
| HTML Output | Wraps text: <strong>text</strong> | Block properties: <p style="text-align:center"> |
| Toggle | Can be partial within a block | Applies to whole paragraph |
Implementation Pattern
The alignment system uses ProseMirror’ssetBlockType command:
- Takes the current selection
- Converts it to a paragraph node (if it isn’t already)
- Sets the
textAlignattribute to the specified value - Returns
trueif successful
Storage in the Document
Alignment is stored directly in the document structure:- Alignment persists when you save the document
- It survives copy/paste operations
- It’s preserved when converting to/from HTML
Best Practices
Consider heading support
Currently, alignment only works on paragraphs. To support headings, you’d need to add the
textAlign attribute to heading nodes as well. See Custom Schema for details.Advanced: Reading Current Alignment
To read the current paragraph’s alignment:- Highlighting the active alignment button
- Displaying current formatting state
- Conditional UI updates
Next Steps
- Learn about Text Formatting for inline styles
- See Custom Schema to add alignment to other node types
- Explore Lists to understand more node types