API
Methods of an editor instance.
| Method | What it does |
|---|---|
getHTML() | Clean HTML to store (editor-only markup removed) |
setHTML(html) | Replace content (sanitized, undoable) |
getText() | Plain text |
insertHTML(html) / insertText(text) | Insert at the caret |
isEmpty() | Nothing written yet? |
getStats() | { chars, charsNoSpace, words, bytes, paragraphs } |
focus() / blur() | Focus |
undo() / redo() | History |
exec(command, value?) | Run a command, e.g. exec('bold'), exec('fontSize', '14pt') |
queryState(command) | Is it on right now (bold etc.) |
setReadOnly(bool) / setTheme(theme) | Switch read-only and theme |
addButton(name, spec) / addCommand(name, fn) | Add a button or command |
on(event, fn) / off(event, fn) | See Events |
destroy() | Remove the editor (a textarea shows again) |
root / content | Outer element / editing element |
const ed = createEditor('#editor');
ed.exec('heading', 'h2');
ed.insertHTML('<p>New paragraph</p>');
console.log(ed.getStats().bytes, 'bytes');