Extensions
pageBreak
A page break.
A block atom with nothing inside, like a horizontal rule: the caret steps over it, Backspace removes the whole thing, and inserting one at a caret in the middle of a paragraph cuts the paragraph around it. On screen it is a labelled dashed line; in print it is where the page ends and nothing else.
The element is marked non-editable in its own DOM, as the YouTube embed is, so an empty `<div>` inside the editor never becomes a line the caret can sit on.
editor.commands.insertPageBreak()1 · Install
One package for every extension · there is no @matrajs/pageBreak to install.
npm i @matrajs/core2 · Add it to the editor
Import it and put it in the extensions array. That array is the whole feature list:
what is not in it is not in your bundle and not in the document's schema.
import { createEditor, document, paragraph, text, pageBreak } from '@matrajs/core'
const editor = createEditor({
extensions: [document, paragraph, text, pageBreak],
element: document.querySelector('#editor'),
})3 · Use it
Run a command, and give focus back · a click on a button takes it away.
editor.commands.insertPageBreak()
editor.focus()Wired to a button, with the pressed state kept in step:
const button = document.querySelector('#insertPageBreak')
button.addEventListener('click', () => {
editor.commands.insertPageBreak()
editor.focus()
})
const read = () => button.setAttribute('aria-pressed', String(editor.isActive('pageBreak')))
editor.on('selectionChange', read)
editor.on('change', read)
read()
Both events, not one. selectionChange covers the caret moving into
it;
change covers the command that changed it without moving anything. A
toolbar wired to only the first goes stale the moment someone uses the keyboard.
Commands
Every one returns true if it changed the document and false
if it could not · a command that does not apply where the caret is says so rather than
throwing.
| Command | Call |
|---|---|
insertPageBreak |
editor.commands.insertPageBreak()
|
Styling
This one needs CSS to look right, and ships the minimum as a string rather than a file · nothing loads unless you load it, and you can ignore it and write your own.
import { pageBreakCSS } from '@matrajs/core'
const style = document.createElement('style')
style.textContent = pageBreakCSS
document.head.append(style)In the document
-
Reads
div[data-page-break]when HTML is pasted or loaded. -
Writes
divingetHTML()andrenderToHTML().