editor

Docs › Reference

API

Methods of an editor instance.

MethodWhat it does
getHTML()Clean HTML to store (editor-only markup removed)
getHTML({ inlineStyles: true })For e-mail and newsletters: fonts, sizes, spacing and borders written into style attributes
getMarkdown() / setMarkdown(md)Content as Markdown, and back (what Markdown cannot say stays as HTML)
moveBlock(block, before)Move a top-level block (one undo step)
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
isDirty() / markClean()Unsaved changes? / Mark the current content as saved (call after your save request; a textarea form submit does it for you)
getImages()Addresses of the images in the content
getUnusedUploads()Images uploaded in this editor that are no longer in the content: send them to your server on save and delete them
destroy()Remove the editor (a textarea shows again)
root / contentOuter element / editing element
const ed = createEditor('#editor');
ed.exec('heading', 'h2');
ed.insertHTML('<p>New paragraph</p>');
console.log(ed.getStats().bytes, 'bytes');