RichTextEditor Methods
RichTextEditor exposes the following methods.
| Method | Description |
|---|---|
| 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. |
| 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(). |
| getText() / setText(text) | Aliases of getPlainText() and setPlainText(). |
| setPlainText(text) | Replaces the document with plain text; each newline becomes its own block. |
| 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) | Inserts an image at the caret from a URL. |
| 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 | Local-draft helper object; see the localDraft option. |