RichTextEditor Methods
RichTextEditor exposes the following methods.
| Method | Description |
|---|---|
duplicateCurrentBlock() | Newer source core builds only (not every released bundle): duplicates the block(s) at the selection and places the caret in the copy. Unique ids and review identities are not cloned. Read-only/comments-only content, unsupported row spans and suggesting mode refuse the operation. A true return can mean a guarded no-op, not proof that content was copied. Check typeof editor.duplicateCurrentBlock before using it with an older runtime. |
recordUndo() | Records the current document and commits its undo step. Call it after a custom DOM edit to make the change available to Undo. |
makePanelResizable(panel, opts) | From core 2.6.11. Adds a draggable, keyboard-operable resize edge (ArrowLeft / ArrowRight / Home / End) to a side panel element. opts: min and max width in px (default 240 / 720), label for screen readers. Fires the panelresized event. Returns the handle element, or null if the panel is missing or already resizable. |
setListStart(n) | Sets the starting number of the ordered list at the selection, including 0. Returns false when no ordered list is selected or n is invalid. |
continueListNumbering() | Continues the selected ordered list from the preceding ordered list. Returns false when no suitable list is found. |
toggleTableCaption() | Adds or removes the selected table's caption and records an undo step. Returns false when no table is selected. |
execCommand(cmd,value) | Executes a command on the current selection, or the given range. |
attachEvent(name,handler) | Registers an event handler.You can interact with it once the editor is loaded and running. |
detachEvent(name,handler) | Removes an EventHandler from an event. |
getHTMLCode() | This method is used for retrieving the content of RichTextEditor as HTML. |
setHTMLCode(html) | This method is used for setting the content of RichTextEditor. |
getReadOnly() | Returns a value indicating whether the editor's state is read-only on the client-side. |
setReadOnly(bReadOnly) | Allows you to enable/disable read-only mode. |
isCommandEnabled(cmd) | Gets whether the specified command is enabled. |
isCommandActive(cmd) | Checks whether this command can currently be performed. |
focus() | Attempt to set the focus of the editor content window. |
setContentCssText(text) | This method is used for setting inline CSS text that will be used by the editable area. |
insertRootParagraph(tagname) | This method is used for inserting a new paragraph at the bottom of editor. |
insertByTagName(tagName) | Inserts an element by tag name. |
surroundByTagName(tagName) | Get the content of selection and place it into an element. Then insert this new element. |
insertElement(element) | Inserts an element. This element must be created by editor.document. |
surroundElement(element) | Creates an element using editor.document. Places the content of selection into the element. Then insert this new element. |
insertText(text) | This method is used for inserting the specified plain text into editor document. |
insertHTML(text) | This method is used for inserting the specified HTML into a range within an editor document. If anything is selected, the selection is replaced with the new HTML and text. |
selectControl(element) | Selects a control. |
selectDoc(bStart) | Selects the document. The bStart is a boolean value: true moves the selection to its start, false to its end. If omitted, it defaults to false. |
collapse(bStart) | Collapses the current selection to a single point. The bStart is a boolean value: true collapses the Range to its start, false to its end. If omitted, it defaults to false. |
delete() | Deletes a selection. |
commitBookmark() | Creates a bookmark for undo record. |
clearHistory() | Clears all undo/redo records. |
notifySelectionChange() | Notifies the editor about any content change. |
htmlEncode(text) | Converts a string into an HTML-encoded string. |
htmlDecode(html) | Converts a string that has been HTML-encoded for HTTP transmission into a decoded string. |
getSelection() | Returns the editor.selection object. |
getDocument() | Returns the editor.document object. |
getEditable() | Returns the root element of the editable area. |
ensureStyleSheetLive(doc,element,id,csstext) | Call this right after appending your own <style> element. Normally it does nothing: it only acts when a strict Content-Security-Policy has emptied the element, and then re-injects the same CSS through the CSSOM so the rules apply instead of being silently dropped. Keeping your <style> element as the primary path is what preserves its place in the cascade. |
injectStyleSheet(doc,id,csstext) | Adds a stylesheet to the given document without using a <style> element, so it survives a strict style-src. Use it when you have no element to preserve; prefer ensureStyleSheetLive() when you do, because the rules land in an adopted stylesheet that sorts after every stylesheet in the document. Re-calling it with the same id and different CSS updates the existing sheet. |
getPlainText() | Returns the editor.document.body.innerText object. |
getJSON() | Available when the structured content bridge is loaded. Returns a semantic JSON document model for the current editor content. |
setJSON(documentModel) | Available when the structured content bridge is loaded. Restores the editor from the structured JSON document model. |
getSelectedControl() | Returns the selected control object. |
getSelectionElement() | Returns the selected element object. |
getSelectedText() | Returns the selected plain text. |
createToolbarButton(cmd) | Creating a button in toolbar with default styles. For details, please refer to plugin example. |
createToolbarDropDown(cmd) | Creating a dropDown in toolbar with default styles. For details, please refer to plugin example. |
createDialog(title,className) | Creating a dialog with default styles. For details, please refer to plugin example. |
closeCurrentPopup() | Attempt to close all popups/dropdowns/menus/dialogs. |
setImageForCommand(element,cmdname) | Adds an image (svg or png) for cmdname to the element. |
destroy() | Tears the editor down and releases its listeners and DOM. Call this when unmounting in a SPA; prepareDestroy() is an alias. |
getHTML() / setHTML(html) | Aliases of getHTMLCode() and setHTMLCode(). |
bindDocumentEvent(type, handler, capture) | From core 2.6.10. Listens on the editing document (keydown, input, ...). Use it instead of getDocument().addEventListener: the editor re-attaches it when the editing frame gets a new document (see the documentreplaced event). |
bindEditableEvent(type, handler, capture) | From core 2.6.10. The same, on the editable body (getEditable()). |
runInSavedView(fn) | From core 2.6.10. Runs fn while the editing area shows exactly what would be SAVED (plugin previews such as merge-field samples are switched off for the call) and returns fn's result. Use it for any export that has to read computed styles or layout. |
cancelUploads(reason) | Cancels every upload still in flight and returns how many were cancelled. Calls the handler's returned abort function when supplied and ignores late results. destroy() cancels uploads too. A result for an image removed from the document is discarded; removal alone does not guarantee an immediate network abort. |
getPendingUploadCount() | How many uploads are still running. |
uploadEmbeddedImages(callback) | Uploads images already embedded in the content as base64 data: URLs - content set with setHTMLCode, pasted from a page, or restored from a draft - through file_upload_handler, replacing each src with the returned URL. The callback receives { uploaded, failed, skipped, errors }. http(s) images are left alone; with no handler configured nothing changes. |
getText() / setText(text) | Aliases of getPlainText() and setPlainText(). |
setPlainText(text) | Replaces the document with plain text; each newline becomes its own block. |
formatChanged(formats, callback) | Subscribes to format/command state changes so a custom toolbar can track active state without polling. Matches TinyMCE's formatChanged(); driven by the same refresh as the built-in toolbar, so a subscriber cannot drift out of step. Also available as editor.formatter.formatChanged. |
getSelectedHTML() | Returns the current selection as an HTML string. |
getStatistics() | Returns the editor's content statistics (word, character and related counts). |
showWordCount() | Opens the word-count dialog. |
showShortcuts() | Opens the keyboard-shortcut cheat sheet (Cmd/Ctrl + /). |
toMarkdown() | Returns the current content as CommonMark. |
fromMarkdown(md, opts) | Replaces the content by parsing CommonMark. |
exportPdf(options) | Exports the document as a vector, tagged PDF. |
printPreview() | Opens the print preview for the current document. |
insertImageByUrl(url, alt) | Inserts an image at the caret from a URL. The optional alt sets the alt text (core 2.6.5+); without it no alt attribute is written. |
openFindDialog() | Opens the find-and-replace dialog. |
findHighlight(query, options) | Highlights every match for a query without opening the dialog. |
clearFindHighlights() | Removes highlights added by findHighlight(). |
markAllOccurrencesOfSelection() | Highlights every occurrence of the current selection. |
toggleReadingMode(state) / isReadingMode() | Switches the distraction-free reading view on or off, and reports its state. |
setCommentsOnly(bVal) / getCommentsOnly() | Restricts editing to commenting only, and reports whether that mode is active. |
applyMathMarkup() / renderMath() | Converts TeX to the editor's math markup, and renders it when KaTeX or MathJax is present on the page. |
setPreviewCssText(text) | Sets inline CSS used by the preview mode. |
getLangText(key) | Looks up a localized UI string for the active language. |
fireEvent(name, ...args) | Invokes an event hook programmatically. |
autoSave | Present when config.autoSave is set. Saves to your own server as the user types: trigger() saves now, retryNow() retries a failed save at once, hasUnsavedChanges() reports whether a save is still outstanding, isDirty() compares the content with the last saved version, and lastSavedAt() returns the timestamp. A failed save retries on a doubling delay and when the browser comes back online, re-sending the snapshot that failed. The autosaved and autosavefailed events report both outcomes. For browser-side drafts instead, see the localDraft option. |