Every extension
textDirection
Text direction as an attribute on existing blocks, detected when unset.
A `dir` attribute on every type named, like `textAlign`: a paragraph that knows nothing about direction still keeps, renders and parses it, and a document with a Hebrew heading round-trips through HTML with `dir="rtl"` on the heading. Set it with the commands when the reader knows better than the text.
Left unset, the block's own text decides. Each block whose first strong character is right-to-left is drawn with `dir="rtl"` as a node decoration, so an Arabic paragraph typed into an English document reads the right way round without anybody choosing — and the JSON says nothing about it. The answer is remembered per top-level block on the block node, and the whole set is memoised on the document, so a caret move costs nothing.
editor.commands.setTextDirection('rtl')
editor.commands.unsetTextDirection()
Adding it
import { createEditor, document, paragraph, text, textDirection } from '@matrajs/core'
const editor = createEditor({
extensions: [document, paragraph, text, textDirection({ … })],
element: document.querySelector('#editor'),
})
There is no separate package · textDirection is already in @matrajs/core, and an extension you do not import is not in your bundle. document, paragraph and text are the floor every document needs.
Options
| Field | Type | |
|---|---|---|
types | readonly string[] | Which blocks carry a direction. Default paragraph and heading. |
auto | boolean | Render a block whose text reads right to left that way, with nothing stored. Default true. |
Commands
-
editor.commands.setTextDirection() -
editor.commands.unsetTextDirection()