Skip to content

Everything the core exports

One page of options, methods and attributes. The framework packages re-export all of it.

On this page

createEditor(options)

Every option, with its default. All of them are optional.

createEditor options
OptionTypeDefaultDescription
elementHTMLElement | string | <textarea>Container, CSS selector or textarea (hidden and kept in sync). Omit it to create the editor detached and append editor.root yourself.
contentstring | JSONInitial content: HTML (always sanitized) or ProseMirror JSON.
extensionsAnyExtension[][StarterKit]The feature set.
editablebooleantrueAllow editing.
autofocusboolean | "start" | "end"falseFocus on creation.
placeholderstringText shown when the editor is empty.
ariaLabel, ariaLabelledBy, ariaDescribedBystringAccessible name and description of the editing area.
languagestring<html lang>UI language. Built in: en, ar.
languagesEditorLanguage[]Add or replace UI languages.
labelsPartial<Labels>Override single UI strings.
dir"ltr" | "rtl" | "auto"Base direction of the content.
contentLangstringlang of the content, used for spellcheck and screen readers.
urlPolicyUrlPolicy{ protocols, allowDataImages, allowRelative }. Allowed link and image URLs.
inputRulesbooleantrueMarkdown-style shortcuts: # , * , 1. , > , fenced code, **bold**…
uiUIOptions | falsebuilt-in UIToolbar, custom items, status bar, theme and shortcuts. false = headless.

ui options

The built-in toolbar, status bar and theme. Pass false instead for a headless editor.

ui options
OptionTypeDefaultDescription
toolbarstring[] | falseDEFAULT_TOOLBARItem names and "|" separators. false hides the toolbar.
itemsRecord<string, ItemSpec>Custom or overriding toolbar buttons, referenced by name in toolbar.
statusbar{ elementPath, wordCount, characterCount } | falseStatus bar content. characterCount can take { limit }.
theme"auto" | "light" | "dark""auto"Color theme of the editor.
stickyToolbarbooleantrueKeep the toolbar visible while scrolling long documents.
shortcuts{ toolbar, help, find, link }Alt-F10, Alt-0, Mod-f, Mod-kKey bindings of the built-in UI.

Callbacks

Pass them as options. The framework packages always call the latest function.

Editor callbacks
NameTypeDescription
onCreate(editor) => voidThe editor was created.
onUpdate(editor) => voidThe content changed.
onSelectionUpdate(editor) => voidThe selection changed.
onFocus, onBlur(editor, event) => voidThe editing area gained or lost focus.
onDestroy() => voidThe editor was destroyed.
onContentError(error: Error) => voidContent could not be loaded.

Editor methods

What createEditor() returns.

Editor methods
MethodReturnsDescription
getHTML()stringClean, sanitized HTML. Save this.
getJSON()JSONContentProseMirror JSON.
getText({ blockSeparator })stringPlain text. Blocks are separated by \n\n by default.
setContent(content, { emitUpdate, addToHistory })voidLoad HTML or JSON. emitUpdate and addToHistory are off by default.
clearContent()voidEmpty the document.
isEmpty, isFocused, isEditablebooleanRead-only state flags.
setEditable(editable)voidTurn editing on or off.
setOptions(options)voidChange the runtime options: editable, placeholder, aria*, dir, contentLang.
commands.name()booleanRun one command, e.g. editor.commands.toggleBold().
can().name()booleanWould the command work here?
chain().…run()booleanSeveral commands in one transaction and one undo step.
isActive(name, attrs?)booleanIs a mark or node active, e.g. isActive("heading", { level: 2 }).
getAttributes(name)objectAttributes at the selection, e.g. a link's href.
on(event, fn)() => voidListen to an editor event. Returns an unsubscribe function.
subscribe(fn)() => voidStore-style subscription that fires on every change.
announce(message)voidSend a message to screen readers.
focus(), blur()voidMove focus in or out.
destroy()voidRemove the editor and its listeners.

Commands

Run them with editor.commands.name(), test them with editor.can().name() and combine them with editor.chain()…run().

Commands by area
AreaCommands
MarkstoggleBold toggleItalic toggleUnderline toggleStrike toggleCode toggleSubscript toggleSuperscript unsetAllMarks
ColorsetTextColor(color) unsetTextColor setHighlight(color?) unsetHighlight toggleHighlight(color?)
BlockssetParagraph setHeading(level) toggleHeading(level) clearNodes toggleBlockquote toggleCodeBlock setHorizontalRule setHardBreak
ListstoggleBulletList toggleOrderedList toggleTaskList sinkListItem liftListItem
Links and imagessetLink({ href, text?, title?, newTab? }) unsetLink setImage({ src, alt, caption? }) updateImage
TablesinsertTable({ rows, cols, withHeaderRow, caption }) addRowBefore addRowAfter addColumnBefore addColumnAfter deleteRow deleteColumn deleteTable mergeCells splitCell toggleHeaderRow toggleHeaderColumn setTableCaption
LayoutsetTextAlign("start" | "center" | "end" | "justify") setTextDirection("ltr" | "rtl" | "auto") unsetTextAlign unsetTextDirection
FindsetSearch({ query, caseSensitive, wholeWord }) findNext findPrevious replaceCurrent(text) replaceAll(text) clearSearch
Generalundo redo focus blur selectAll

Attributes

placeholder, readonly, disabled, dir, content-lang and label follow later changes. value, language and toolbar are read when the editor starts.

owe-editor attributes
NameTypeDescription
namestringForm field name. The form submits the editor's HTML under it.
placeholderstringPlaceholder text.
readonlybooleanMakes the content read-only.
disabledbooleanDisables the editor and leaves it out of the form.
dirltr | rtl | autoBase direction of the content.
content-langstringlang of the content (spellcheck and screen readers).
labelstringAccessible name. Or point a <label for> at the element's id.
valueHTML stringInitial content as HTML. Read once, when the editor is created.
languagestringUI language, e.g. ar. Read once. Defaults to <html lang>.
toolbarstringToolbar items separated by spaces ("bold italic | link"), or none. Read once.

Properties

Set options before the element is added to the page.

owe-editor properties
NameTypeDescription
editorEditor | nullThe live editor, or null while the element is not in the document.
valuestringThe content as HTML. Setting it loads new content.
optionsEditorOptionsMore createEditor() options. Set it before the element is added to the page. Attributes win over it.
formHTMLFormElement | nullThe surrounding <form>, or null.

Events

Both bubble, so you can listen on the form.

owe-editor events
NameTypeDescription
inputEventOn every change. event.target.value has the HTML.
changeEventWhen the editor loses focus after a change.

Entry points

What each import path gives you.

Package entry points
ImportTypeDescription
open-wysiwyg-editorESM + CJS + .d.tsThe engine, every extension and the accessible UI.
open-wysiwyg-editor/headlessESM + CJS + .d.tsThe engine and extensions without UI code.
open-wysiwyg-editor/elementESM + CJS + .d.tsDefines the <owe-editor> element.
open-wysiwyg-editor/style.cssCSSEditor, UI and content styles (also style.min.css).
open-wysiwyg-editor/content.cssCSSContent styles only, for pages that display saved HTML (also content.min.css).
dist/open-wysiwyg-editor.global.jsIIFEA script tag build. Exposes window.OpenWysiwygEditor and defines <owe-editor>.

Edit this page on GitHub