Reading and readiness
| Method | Result | Contract |
|---|---|---|
| getHTML / getCSS / getText | string | Last applied content/styles/text |
| getJSON | DocumentNode | Independent structured snapshot |
| getConfiguration | ResolvedConfiguration | Independent configuration copy |
| whenReady | Promise<void> | Initial Markdown/CSS; rejection on error |
| whenSourceReady | Promise<void> | Lazy HTML/CSS UI loading and mount |
| getMode | visual/html/markdown | Actual active mode |
| isFullscreen | boolean | Fullscreen state |
| getSelection | SelectionInfo | from/to/text/revision |
| getPluginIds | string | Copy of installed IDs |
Call argumentless names as editor.getHTML() and similarly.
Document changes
| Method | Result | Contract |
|---|---|---|
| setContent(value, options?) | Promise<ImportReport> | format/allowLossy/css; checked atomic document+CSS, one history step; HTML/JSON without CSS applies before Promise return |
| setCSS(css) | Promise<void> | Checks the whole stylesheet, one history step, keeps selection |
| setSelection(from, to?) | void | Structured positions; to defaults to from; does not mutate content |
| replaceRange(range, value, options?) | Promise<ImportReport> | HTML/Markdown, one history step; stale range.revision throws StaleDocumentError |
| replaceText(edits, revision) | boolean | Synchronous atomic plain replacements; RangeError or StaleDocumentError |
| transformText(callback) | boolean | callback(text, startsBlock) returns text; keeps marks/CSS, one history step |
| execute(command) | boolean | Formatting/history/table commands; false when inapplicable |
| insertTable(rows?, cols?, withHeaderRow?) | boolean | Default 3×3/header; integer 1–20, otherwise RangeError |
| insertImage(attributes) | boolean | Validated src/dimensions/attributes, one history step |
| uploadImage(file, options?) | Promise<boolean> | signal/alt, upload callback and captured range; AbortError/StaleDocumentError |
replaceText uses non-overlapping {from,to,text} edits inside individual text blocks, without inline atoms or replacement line breaks. Literal markup remains text. transformText/replaceText in the UI operate only in visual mode. CSS changes increase revision; structured positions are not getText offsets.
Interface, events and extensions
| Method | Result | Contract |
|---|---|---|
| setMode(mode) | void | Errors can keep the current mode; cannot bypass draft validation |
| setFullscreen(enabled) | void | Within the browser/iframe document; no native Fullscreen API; disabled feature throws |
| focus() | void | Returns document focus and selection |
| on(name, listener) | unsubscribe | Event subscription |
| off(name, listener) | void | Remove that listener |
| usePlugin(plugin) | disposer | API 1 installation with ID/version/feature checks |
| removePlugin(id) | void | Plugin cleanup |
| executePluginCommand(id, name) | boolean | Registered command; unknown command throws |
| destroy() | void | Idempotent cleanup; AggregateError possible after resources are released |
Reconnecting the editor
getSourceDraft(): SourceDraft | null captures the active HTML+CSS or Markdown draft, including invalid source. Visual mode returns null. restoreSourceDraft(draft): Promise<void> restores it on a fresh visual instance after initial CSS and lazy source loading. Disabled modes reject. Normal validation, autosave and lossy-import confirmation still apply.
Before destroy(), save getJSON(), getCSS() and getSourceDraft(). Create a new instance with the new language, saved JSON/CSS and new plugin instances, then await restoreSourceDraft(draft) when non-null. Site language switching uses this flow. Document text is not translated. Undo history, open dialogs and source cursor position are not transferred.
execute commands
bold, italic, underline, strike, bulletList, orderedList, blockquote, codeBlock, paragraph, h1, h2, h3, undo, redo, insertTable, addRowAfter, addColumnAfter, deleteRow, deleteColumn, toggleHeaderRow, deleteTable. Import accepts H1–H6. Link/image/html/markdown/fullscreen are UI tools; not every toolbar tool is an execute command. Events, errors, document.
editor.execute('bold');
const range = editor.getSelection();
await editor.replaceRange(range, '<strong>New text</strong>');
editor.execute('undo');