Editra documentation

API reference

Initialize Editra, work with document content, execute commands, and observe editor state.

Initialization

const editor = await Editra.init({
  selector: "#editra-editor",
  plugins: ["bold", "italic", "table"],
  toolbar: "bold italic | table | undo redo",
  showMenuBar: true,
  sanitizePaste: false,
  onChange: ({ html }) => console.log(html)
});

Content methods

  • getCode() returns raw editor HTML.
  • getText() returns plain text.
  • getFormatted() returns a normalized cloned DOM element.
  • setCode(html) replaces editor HTML.
  • focus() focuses the editing surface.
  • destroy() removes listeners, UI, and plugin resources.

Commands

Use executeCommand(name, value). Common commands include bold, superscript, subscript, blockQuote, formatPainter, insertDateTime, insertBarcode, insertQrCode, insertCodeBlock, insertTable, insertImage, setPageSize, toggleRuler, and export commands.

Events

Configuration callbacks include onChange, onPaste, onCommand, onFocus, onBlur, onStateChange, onMenuToggle, onToolbarBuild, onThemeToggle, onRulerAdjust, and onPageChange.