@mdaemon/html-editor
v1.22.0
Published
A TinyMCE-compatible HTML editor built on TipTap
Downloads
1,617
Maintainers
Readme
@mdaemon/html-editor
A TinyMCE-compatible HTML editor built on TipTap
MDHTMLEditor is the core vanilla TypeScript package - for React usage, see @mdaemon/html-editor-react.
Install
npm install @mdaemon/html-editorTipTap and ProseMirror are bundled into the published output (currently TipTap 3.32.x) —
there are no peer dependencies to install and no TipTap version for the host app to match. If
your app uses TipTap directly as well, note that the copy inside this package is separate from
yours; pass content across the boundary as HTML (getContent() / setContent()) rather than
sharing ProseMirror nodes or extension instances between the two.
Usage
Basic usage
import { HTMLEditor } from '@mdaemon/html-editor';
import '@mdaemon/html-editor/styles';
// Create editor with built-in language support
const container = document.getElementById('editor');
const editor = new HTMLEditor(container, {
height: 400,
language: 'de', // German UI — see Localization section for supported codes
basicEditor: false, // Full toolbar
includeTemplates: true,
templates: [
{ title: 'Greeting', content: '<p>Hello!</p>' }
],
fontName: 'Arial',
fontSize: '12pt',
});
// Get/set content
const html = editor.getContent();
editor.setContent('<p>New content</p>');
// Insert content at cursor
editor.insertContent('<b>Bold text</b>');
// Execute commands (TinyMCE compatible)
editor.execCommand('bold');
editor.execCommand('fontsize', false, '14pt');
// Listen to events
editor.on('change', (content) => {
console.log('Content changed:', content);
});
editor.on('dirty', (isDirty) => {
console.log('Editor dirty state:', isDirty);
});
// Clean up
editor.destroy();Browser (UMD)
For static pages without a bundler, load the self-contained UMD bundle via a <script> tag.
It exposes the entire public API under the MDHTMLEditor global. Styles must be loaded
separately — the UMD bundle contains JavaScript only.
<link rel="stylesheet" href="https://unpkg.com/@mdaemon/html-editor/dist/styles.css">
<script src="https://unpkg.com/@mdaemon/html-editor"></script>
<script>
const editor = new MDHTMLEditor.HTMLEditor(
document.getElementById('editor'),
{ height: 400 }
);
</script>unpkg and jsdelivr both serve the package; pin a version for production
(e.g. https://unpkg.com/@mdaemon/[email protected]).
Custom Toolbar Buttons
const editor = new HTMLEditor(container, {
setup: (ed) => {
ed.ui.registry.addButton('myButton', {
tooltip: 'My Custom Button',
text: 'Click Me',
onAction: () => {
ed.insertContent('<p>Custom content!</p>');
},
});
},
});Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| basicEditor | boolean | false | Use simplified toolbar for notes/tasks |
| readonly | boolean | false | Start the editor in read-only mode (see setReadOnly) |
| forced_root_block | 'p' | 'div' | 'p' | Block element produced on Enter. 'div' gives CKEditor ENTER_DIV parity |
| trailingNode | boolean | false | Append an empty trailing paragraph when the document ends in a block node (table, code block) so the cursor can be placed after it |
| includeTemplates | boolean | false | Show template dropdown |
| templates | Template[] | [] | Array of templates |
| dropbox | boolean | false | Enable Dropbox integration |
| images_upload_url | string | - | URL for image uploads |
| images_upload_credentials | boolean | true | Include credentials in CORS upload requests |
| images_upload_base_path | string | '/' | Base path prefix for uploaded image URLs |
| images_upload_max_size | number | 10485760 | Maximum upload file size in bytes (default 10 MB) |
| images_upload_headers | Record<string, string> | - | Custom HTTP headers for upload requests |
| images_file_types | string | (permissive) | Comma/space-separated accepted extensions (e.g. 'jpg,jpeg,png,gif,bmp'). Restricts uploads when set |
| images_upload_validate | (file: File) => string | null | - | Pre-upload hook; return a message to reject the file, or null to allow |
| images_upload_error | (message: string) => void | - | Caller-supplied alert for drag-drop/paste upload rejections & failures (no dialog to show errors in) |
| images_upload_error_message | (response: unknown, status: number) => string | null | undefined | - | Words the message for a failed upload from the server's reply (parsed JSON body, or null, and the HTTP status). Return null/undefined for the editor's own translated message |
| image_advtab | boolean | false | Show the image dialog's Advanced tab: Style, spacing, border, text direction and language. See Image Dialog |
| image_title | boolean | false | Show the image's Title field on the dialog's General tab (without it, Title is on the Advanced tab when that is shown) |
| image_dimensions | boolean | true | Show the image's Width and Height, with Constrain proportions and Reset size |
| image_description | boolean | true | Show the image's Alt text field |
| image_uploadtab | boolean | true | Show the image dialog's Upload tab |
| a11y_advanced_options | boolean | false | Add an "Image is decorative" checkbox to the image dialog, which saves an empty alt |
| object_resizing | boolean | string | true | Show drag handles on a selected image to resize it. A string is a CSS selector, as in TinyMCE: only images that match it can be resized. See Resizing images |
| resize_img_proportional | boolean | true | Corner handles keep the image's aspect ratio. Holding Shift while dragging does the opposite for that drag |
| table_toolbar | string | false | (see Tables) | Buttons of the toolbar shown above a table while the cursor is in it, as a toolbar string. false or '' turns it off. Off by default in the basic editor |
| table_grid | boolean | true | Insert tables from a size grid in the table menu. false opens the Insert table dialog instead |
| table_default_attributes | Record<string, string> | { border: '1' } | Attributes of a table the user inserts. Only border, cellpadding and cellspacing are used |
| table_default_styles | Record<string, string> | { 'border-collapse': 'collapse', width: '100%' } | Style of a table the user inserts, as CSS property/value pairs. Only properties and values a table keeps are used (see Formatting a table keeps) |
| table_default_header_rows | number | 0 | Header rows of a table inserted from the menu, grid or dialog |
| table_default_header_cols | number | 0 | Header columns of a table inserted from the menu, grid or dialog |
| table_tab_navigation | boolean | true | Tab and Shift+Tab move between table cells. false makes them work in a cell as they do outside a table: Tab types a tab at the cursor, and Shift+Tab outdents |
| table_appearance_options | boolean | true | Show Cell spacing, Cell padding, Border width and Caption in the Table properties dialog |
| table_advtab | boolean | true | Show the Advanced tab (border style, border color, background color) in the Table properties dialog |
| table_row_advtab | boolean | true | Show the Advanced tab in the Row properties dialog |
| table_cell_advtab | boolean | true | Show the Advanced tab (adds border width) in the Cell properties dialog |
| table_border_widths | { title, value }[] | 1px to 5px | Choices of the tablecellborderwidth menu |
| table_border_styles | { title, value }[] | every CSS border style | Choices of the tablecellborderstyle menu |
| table_background_color_map | string[] | ColorOption[] | color_map | Palette of the tablecellbackgroundcolor picker |
| table_border_color_map | string[] | ColorOption[] | color_map | Palette of the tablecellbordercolor picker |
| contextmenu | string | boolean | '' | Right-click menu. A string naming table (or true) shows the table menu on a right-click in a table. Off by default, because it replaces the browser's menu and its spelling suggestions — see Right-click menu |
| font_family_formats | string | (TinyMCE defaults) | Semicolon-separated font list (Name=family,...) |
| font_size_formats | string | '8pt 9pt 10pt 12pt 14pt 18pt 24pt 36pt' | Space-separated font sizes |
| font_names | string | - | CKEditor alias for font_family_formats |
| fontSize_sizes | string | - | CKEditor alias for font_size_formats |
| block_formats | string | 'Paragraph=p;Heading 1=h1;…' | Block-format dropdown definitions (blocks button) |
| style_formats | StyleFormat[] | (subset) | Named styles for the Styles dropdown (styles button) |
| color_map | string[] | ColorOption[] | - | Palette for both color pickers (see Color Pickers) |
| color_map_foreground | string[] | ColorOption[] | (40 text colors) | Palette for the forecolor picker; overrides color_map |
| color_map_background | string[] | ColorOption[] | (26 highlight colors) | Palette for the backcolor picker; overrides color_map |
| fontName | string | arial, helvetica, sans-serif | Default font family, inlined on every block element (see Font Family & Size) |
| fontSize | string | 12pt | Default font size, inlined on every paragraph (see Font Family & Size) |
| directionality | 'ltr' | 'rtl' | 'ltr' | Text direction |
| language | string | 'en' | UI language code (built-in translations for 32 languages) |
| height | string | number | 300 | Editor height (fixed) |
| min_height | string | number | - | Minimum editor height |
| max_height | string | number | - | Maximum editor height |
| auto_focus | string | - | Auto-focus the editor on init |
| skin | 'oxide' | 'oxide-dark' | 'confab' | 'confab-dark' | 'oxide' | Theme of the editor and of its menus and dialogs (see Theming) |
| content_css | 'default' | 'dark' | 'confab' | 'confab-dark' | 'default' | Content area styling |
| content_style | string | - | Custom CSS injected into the content area |
| toolbar | string | (see Toolbar section) | Custom toolbar button layout |
| toolbar_mode | 'sliding' | 'floating' | 'wrap' | 'wrap' | Toolbar overflow behavior |
| toolbar_sticky | boolean | true | Keep toolbar pinned at the top while scrolling |
| toolbar_expanded | boolean | false | Start with the More (…) toggle open, showing every toolbar row (see Toolbar Toggle) |
| visualblocks_default_state | boolean | false | Start with Show blocks on: each block outlined and labeled with its tag (see Show Blocks) |
| media_url_resolver | (video) => { href?, thumbnail?, title? } | null, or a promise of one | - | Supplies the link, thumbnail and title of each video the Insert video dialog inserts (see Insert Video) |
| browser_spellcheck | boolean | true | Enable browser spell-check |
| entity_encoding | 'raw' | 'named' | 'numeric' | 'raw' | HTML entity encoding mode |
| convert_unsafe_embeds | boolean | true | Sanitize embedded content |
| format_empty_lines | boolean | true | Preserve blank lines in exported content. When true, every path that hands HTML out of the editor (getContent(), the change event payload, the source dialog, preview) injects a <br> into each empty block so blank lines keep their height in mail clients and other consumers that would otherwise collapse a bare <div></div>/<p></p> to zero height, and every path that brings HTML in (setContent(), insertContent(), the Templates dropdown, saving the source dialog) runs the exact inverse — stripping that <br> back out on import so a blank line is not re-parsed as a doubled line. This keeps setContent(getContent(x)) stable across round-trips (skin/root-block changes, saved-draft reloads). A block holding only a non-breaking space (<div> </div>) is not a blank line — an is visible content that already gives the block height — so it is left exactly as it is by both passes. Set false to pass the engine's output through unchanged in both directions. |
| paste_from_office | boolean | true | Clean and preserve formatting when pasting from Microsoft Word and Excel |
| quote_marker_class | string | - | Class that marks a reply's quoted original. A <blockquote> or <div> whose class is exactly this keeps it — see Quoted original of a reply |
| paste_markdown | boolean | false | Start with paste-as-Markdown mode on. While on, a paste is read as Markdown and inserted as formatting — see Pasting Markdown |
| paste_as_text | boolean | false | Start with paste-as-text mode on (TinyMCE's option): every paste inserts the clipboard's plain text, without formatting. Excludes paste_markdown, and wins when both are set — see Pasting as Text |
| speech_to_text | boolean | true | Enable Speech to Text and Dictate toolbar buttons (requires Web Speech API: Chrome, Edge, Safari) |
| setup | (editor) => void | - | Callback invoked before init — use to register custom buttons |
Toolbar Toggle
The toolbar shows one row of buttons. Buttons that don't fit wrap onto more rows, which stay hidden until the user opens the More toggle (…) at the right of the first row. The toggle only appears when the buttons need more than one row.
A || (double pipe) in the toolbar string starts a new row, so you choose what the first row holds instead of leaving it to the editor's width:
const editor = new HTMLEditor(container, {
// The first row is always visible; the row after || is shown by the More toggle
toolbar: 'bold italic underline strikethrough | fontfamily fontsize || alignleft aligncenter alignright | forecolor backcolor | undo redo',
});A row can still wrap if it is wider than the editor. While the toggle is closed, the buttons on the rows it hides are inert, so Tab and screen readers skip them. Where the toolbar is one line, as in narrow mode (which scrolls instead of wrapping) and the table context toolbar, a || shows as an ordinary separator. The default toolbars contain no ||.
The More toggle starts closed. Set toolbar_expanded: true to start with every row shown. To remember the user's choice, save it from the toolbarexpandedchange event and pass it back as toolbar_expanded next time:
const editor = new HTMLEditor(container, {
toolbar_expanded: loadSetting('toolbarExpanded') === true, // a boolean, not the string 'true'
});
editor.on('toolbarexpandedchange', (expanded) => saveSetting('toolbarExpanded', expanded));editor.isToolbarExpanded() and editor.setToolbarExpanded(true | false) read and change it from code. Narrow mode does not change it: once the editor is wide again, the toolbar is open or closed as the user left it.
API Reference
Methods
getContent(): string- Get HTML content (applies theformat_empty_linesserialization pass; thechangeevent payload is identical)setContent(html: string): void- Set HTML content. Backslash-escaped closing tags (<\/p>, produced by hosts that pass HTML through PHPjson_encodeand similar/→\/encoders) are repaired to real tags before parsing, matching TinyMCE's lenient parser, and theformat_empty_linesimport pass is applied. Insignificant whitespace between block elements is collapsed per the HTML spec, so pretty-printed (indented, multi-line) source imports the same way a browser would render it — see Importing pretty-printed HTMLinsertContent(html: string): void- Insert HTML at cursor (same<\/repair, whitespace handling, andformat_empty_linesimport pass assetContent, so inserting a fragment produced bygetContent()does not double its blank lines)execCommand(cmd: string, ui?: boolean, value?: any): boolean- Execute editor command. A table command returnsfalsewhen it did not apply (outside a table, in a read-only editor, or with nothing to do)queryCommandValue(cmd: string): string- The value of a command at the selection, as TinyMCE's:mceTableRowTypegives'header'or'body',mceTableColTypeandmceTableCellTypegive'th'or'td'.''outside a table and for other commandsisTableCommandEnabled(cmd: string, value?: unknown): boolean- Whether a table command would apply at the selection, without running it. For custom table buttons that should be disabled when they can do nothingisPasteMarkdownEnabled(): boolean- Whether pastes are currently read as MarkdownsetPasteMarkdown(on: boolean): void- Turn paste-as-Markdown on or off. Per editor instance and not remembered between sessions — see Pasting MarkdownisPasteAsTextEnabled(): boolean- Whether pastes insert plain text onlysetPasteAsText(on: boolean): void- Turn paste-as-text on or off; on turns paste-as-Markdown off. Firespasteplaintexttoggleon a change — see Pasting as TextisToolbarExpanded(): boolean- Whether the toolbar's More (…) toggle is open, showing every rowsetToolbarExpanded(expanded: boolean): void- Open or close the More toggle. Firestoolbarexpandedchangewhen the state changes — see Toolbar ToggleisVisualBlocksEnabled(): boolean- Whether Show blocks is onsetVisualBlocks(on: boolean): void- Turn Show blocks on or off. Firesvisualblockswhen the state changes — see Show BlocksgetFontFamily(): string- Font family in effect at the cursor (inline override → block font → configured default). Returns''when the selection spans more than one familygetFontSize(): string- Font size in effect at the cursor (same resolution order). Returns''when the selection spans more than one size, and inside a heading with no inline override (headings size by level)isDirty(): boolean- Check if content has changedsetDirty(state: boolean): void- Set dirty statesetReadOnly(state: boolean): void- Toggle read-only mode (disables editing and dims the toolbar)isReadOnly(): boolean- Check if the editor is read-onlyfocus(): void- Focus the editorhasFocus(): boolean- Check if editor has focussetLanguage(code: string): void- Change UI language at runtime (rebuilds toolbar)getTipTap(): Editor | null- Access the underlying TipTap editor instancegetConfig(): EditorConfig- Get the resolved editor configurationisBasicEditor(): boolean- Check if the editor is in basic modeon(event, callback): void- Subscribe to an editor eventoff(event, callback): void- Unsubscribe from an editor eventfire(event, ...args): void- Fire an editor event manuallydestroy(): void- Clean up and remove editor
Events
init- Editor initializedchange- Content changed (debounced). The payload is byte-identical togetContent(), so saving the event's HTML and pollinggetContent()produce the same resultdirty- Dirty state changedfocus- Editor focusedblur- Editor blurredlanguagechange- UI language changed (receives language code)templatechange- A template was applied (receives theTemplateobject)pastemarkdownchange- Paste-as-Markdown mode was turned on or off (receives the new boolean). Fires only on an actual change, so a host can save the user's choicepasteplaintexttoggle- Paste-as-text mode was turned on or off (receives{ state }, as TinyMCE'sPastePlainTextToggleevent). Fires only on an actual change, so a host can save the user's choicetoolbarexpandedchange- The toolbar's More (…) toggle was opened or closed, by the user orsetToolbarExpanded(receives the new boolean). Fires only on an actual change, not when the editor goes narrow, so a host can save the user's choicevisualblocks- Show blocks was turned on or off, by the user or code (receives{ state }, as TinyMCE'sVisualBlocksevent). Fires only on an actual change, so a host can save the user's choiceobjectresizestart- The user started dragging an image resize handle (receives{ target, width, height, handle }with the starting size)objectresized- The user finished resizing an image (receives{ target, width, height, handle }with the new size). Not fired when the drag is cancelled or the size is unchangedtablemodified- A table command changed a table (receives{ table, structure, style }: the table in the editor, and whether rows, columns or cells changed or only formatting). Not fired by a copy, or by a command that did nothingnewrow/newcell- A table command created a row or cell (receives{ node }, the new<tr>or<td>/<th>in the editor). Fired by inserting and pasting rows and columns, splitting cells, inserting a table, and Tab in the last cell. Table commands include the menus, buttons, dialogs and Tab; dragging a column border, and editing or deleting cell content, fire none of the three
Supported Commands
The following TinyMCE-compatible commands are supported:
mceTogglePasteMarkdown- turn paste-as-Markdown mode on or offmceTogglePlainTextPaste- turn paste-as-text mode on or off, as in TinyMCEbold,italic,underline,strikethroughfontname,fontsize,lineheightforecolor,hilitecolor,backcolor— pass''or'none'as the value to clear the color instead of setting onejustifyleft,justifycenter,justifyright,justifyfullinsertunorderedlist,insertorderedlistindent,outdent— context-aware, see Lists & Indentationundo,redoSelectAll- select the whole document and focus the editormcePrint- print the content (see theprintbutton)mceVisualBlocks- turn Show blocks on or off (see Show Blocks)mceToggleFormatPainter- turn the format painter on (copying the formatting at the selection) or offmceRetrieveFormats- copy the inline formatting at the selection, without turning the painter onmcePaintFormats- paint the copied formatting onto the selection (see Format Painter)mceImage- open the image dialog: Image properties for the selected image, or Insert image (see Image Dialog). Returns false in the basic editor and in a read-only editormceMedia- open the Insert video dialog (see Insert Video). Returns false in the basic editor and in a read-only editorremoveformatmceremoveeditor- Destroys the editor instance- Table commands — see Table commands
Templates
The editor supports a template dropdown that lets users insert predefined HTML snippets. Enable it with includeTemplates: true and provide a templates array.
Template interface
interface Template {
id?: number | string; // Optional identifier
title: string; // Display name in the dropdown (plain text)
description?: string; // Description shown in the dropdown (plain text)
content: string; // HTML content to insert
}Configuration
const editor = new HTMLEditor(container, {
includeTemplates: true,
templates: [
{
id: 1,
title: 'Greeting',
description: 'A simple greeting message',
content: '<h2>Hello!</h2><p>Thank you for reaching out.</p>',
},
{
id: 2,
title: 'Meeting Notes',
description: 'Template for meeting minutes',
content: '<h2>Meeting Notes</h2><p><strong>Date:</strong> [date]</p><h3>Agenda</h3><ol><li>Item 1</li></ol>',
},
],
// Make sure 'template' appears in the toolbar string
toolbar: 'bold italic | template | undo redo',
});Listening for template changes
When a user selects a template, the templatechange event fires with the full Template object:
editor.on('templatechange', (template) => {
console.log('Applied template:', template.title);
console.log('Template ID:', template.id);
console.log('Content:', template.content);
});This event fires in addition to the standard change event, so consumers can distinguish a template insertion from regular edits and react accordingly (e.g. populate form fields, trigger a save, or log analytics).
Importing pretty-printed HTML
Template bodies are often stored as they were authored — indented, one block per line — rather than minified. setContent() and insertContent() collapse the insignificant whitespace between block elements exactly as the HTML spec (and a browser) does, so the source below imports as a two-item list and nothing else:
<div>Last Week</div>
<ul>
<li>
<div>Completed the following</div>
</li>
<li>
<div>Fixed the following</div>
</li>
</ul>The newlines and tabs between <ul> and <li> are dropped rather than becoming empty list items, and the blank lines between top-level blocks do not become empty blocks. Whitespace that is significant is untouched: text inside a block, a non-breaking space ( ), and the contents of a <pre>/code block all survive verbatim. Pasting with Ctrl+V goes through a separate clipboard parser and is unaffected either way.
Importing wrapped HTML
Template bodies also tend to arrive swaddled in container <div>s — mail clients and CMSes nest several around the real content. The editor's schema has one block node per line and a block cannot contain a block, so that nesting cannot survive the parse. On import, a <div> or <p> that contains only block-level children and no text of its own is dissolved and its children hoisted, rather than being left behind as an empty block:
<!-- imported -->
<div><div><div>
<div>Hello</div>
<div>World</div>
</div></div></div>
<!-- becomes two lines, not two blank lines followed by two lines -->
<div>Hello</div>
<div>World</div>Inherited style on a dissolved wrapper (font-family, font-size, font-weight, font-style, color, line-height, text-align, text-indent, direction) is carried down to the children it wrapped, unless a child already states that property. A body wrapped in a single <div style="font-family:Georgia;font-size:10pt"> therefore keeps its font on every line. Box properties (border, background, padding, margin) describe the wrapper itself and cannot be re-expressed on n children, so they are dropped.
Blocks that own their nesting are never dissolved: a <blockquote>, <li> or table cell holding blocks is a real node in the schema, the signature container (<div id="signature">) is left intact, and so is the quoted original of a reply (a <div> whose class is exactly the marker; see Quoted original of a reply). A genuinely empty <div></div> is a blank line the author typed, not a wrapper, and is preserved.
Lines in a signature or table cell take the text style around them. Every line carries its font and size inline (see Font Family & Size), so a font set on the signature container, a table or a cell would otherwise lose to the editor's default on every line. On import, each line inside a <div id="signature">, <td> or <th> takes the font-family, font-size, font-weight, font-style, color and line-height it would inherit from the nearest element around it that sets one. A line's own value always wins, and text sitting directly in the container, or in a list item or quote in it, is put in a line first. This reaches every line in the container, including one in a list, a quote or a <font> around several lines, and a line of a nested table takes its own cell's style first. A relative size is worked out from the absolute size around it (80% in a 10pt table gives 8pt, and 50% in a 1rem table 0.5rem), including a line's own, and so is a line height in % or em; a value that can't be worked out, such as smaller, is left to the default. A list, quote or <span> with text style inside the container passes it on too, also when the container has no style of its own. Where nothing sets a property, the line gets the default as before, so a signature without a font of its own is unchanged:
<!-- imported, with fontName 'tahoma' and fontSize '10pt' -->
<div id="signature" style="font-family: Arial">Jane Doe<br>Example Corp</div>
<!-- each line takes the signature's font, and the default size -->
<div id="signature"><div style="font-family: Arial; font-size: 10pt;">Jane Doe<br>Example Corp</div></div>This applies to setContent() and insertContent(), not to pasted HTML.
Font elements
The obsolete <font face size color> element, which mail clients and older editors still write, becomes a <span> with the same font, size and color, as in TinyMCE. face is the font family, color the text color, and size the matching CSS keyword: 1 is x-small, 3 is medium and 7 is xxx-large. size is read as browsers read it: +n and -n are relative to 3, the result is clamped to 1 to 7, and anything after the digits is ignored (10 is xxx-large, 2px is small). A property the element sets in its own style wins over the attribute. A <font> around whole lines puts its font on each of them. Like the line styles above, this applies to setContent() and insertContent(); a pasted <font> is converted only inside a table pasted from Excel (see Pasting from Excel).
Placeholder links
An <a href=""> — a link whose target the author has not filled in yet, or that an upstream sanitizer has blanked — is preserved as a link on import, matching TinyMCE and CKEditor. URI validation is otherwise unchanged: a javascript: or data: target is still rejected and its anchor unwrapped to plain text (see Link addresses).
Links on images
Images are inline, as in TinyMCE and in mail HTML: an image sits in a line of text, so a link around it is kept on import and paste (<p><a href="https://example.com/"><img src="logo.png"></a></p> comes back unchanged), and an image between words stays in its paragraph. Select an image and use the Link dialog or unlink to link or unlink it. An <img> that is not already in a line of text (at the top level, or directly in a table cell, list item, quote or the signature) is put in one (<p>, or <div> with forced_root_block: 'div'); with <p> lines it then has the paragraph's margin in the saved HTML. When the selection holds an image (or a mention or named anchor), the Link dialog's "Text to display" is disabled, as in TinyMCE, so the selection is relinked rather than replaced by text. A link the editor rejects, such as javascript:, is dropped and the image kept. The image dialog's Link tab also sets, changes or removes the link on an image (see Image Dialog).
Image maps
In the full editor, an image map survives loading, insertContent(), paste and the Source view: the image keeps its usemap, and the <map> keeps its name and its <area> hotspots.
<p><img src="https://example.com/office.jpg" alt="Office" usemap="#office"><map name="office"><area shape="rect" coords="34,44,270,350" href="https://example.com/desk" alt="Desk" target="_blank"></map></p>A map written in the same line as its image stays in that line; one written after the image's paragraph gets a line of its own, which adds no blank line to the saved HTML. Content a <map> holds besides its areas (text links repeating the hotspots, say) is kept, just after the map. Each <area> keeps shape, coords, href, alt, target, title and rel, and each value is checked:
hrefgets the same check as a link's (see Link addresses), so an application scheme such asnotes:is kept, while ajavascript:ordata:target is dropped and the area kept.targetmust be_blank,_self,_parentor_top. An area withtarget="_blank"getsrel="noopener noreferrer"added, as the editor's links do.shapemust be one HTML defines, andcoordsmust be numbers.usemapmust be#followed by a name. A<map>with only anid(the older XHTML form, which browsers also match) keeps it, written out asname. A<map>with neither usable is dropped with its areas.- The values are checked again when the content is written out, so an area added through a command or JSON content gets the same checks.
id,class,style,data-*and event attributes are not kept, and neither is an<area>outside a<map>.
The editor's content is part of the host page rather than an iframe, and a map name is global to the page. So while editing, a map is shown as a small marker instead of a live map, and the image is shown without its usemap (so it can't pick up a map from elsewhere on the page): the hotspots do nothing. They work in the saved HTML. The marker's tooltip says so, translated into the editor's language (Image map: hotspots work in the saved content, not while editing). Maps have no toolbar button: edit them in the Source view. An image with a map has no resize handles (see Resizing images). The basic editor has no images, so it drops maps.
The TipTap node behind this, ImageMap, is exported along with its ImageMapArea and ImageMapOptions types. It also adds the usemap attribute to the image node, and shows an image that has no node view of its own without that attribute. If you give the image node your own node view, leave usemap off the element it shows.
Quoted original of a reply
A host can mark the quoted original of a reply or forward with a class of its choosing and find the quote again by that class in getContent(). Name the class in quote_marker_class and the editor keeps it:
const editor = new HTMLEditor(container, { quote_marker_class: 'quoted-original' });
editor.setContent(
'<p>Thanks, see below.</p>' +
'<blockquote class="quoted-original" style="margin-left: 5px; padding-left: 5px; border-left: 2px solid #000">' +
'<p>The original message.</p></blockquote>'
);
editor.getContent();
// … <blockquote class="quoted-original" style="margin-left: 5px; padding-left: 5px; border-left: 2px solid rgb(0, 0, 0);"><p …>The original message.</p></blockquote>It is off by default, and off for an empty value or one holding more than one class name. With it set:
| Element | Attribute | Kept when |
|---------|-----------|-----------|
| <blockquote> | class | the value is exactly the marker (surrounding whitespace ignored) |
| <div> | class | the same; only then is the <div> kept as a quote rather than handled as an ordinary line or wrapper |
| either, when marked | style | only margin-* and padding-* (0 or a positive px, pt or em length), border-*-width (the same), border-*-style (none, solid, dashed, dotted, double) and border-*-color (hex, rgb()/rgba() or a color name, not inherit, initial, unset or revert) |
The class is written first, so a plain substring search for <blockquote class="quoted-original" finds the quote. Nested quotes keep their own marker. A marked quote is a blockquote to the editor, so the Blockquote button, Enter and Backspace work in it as in any blockquote, and the button never creates a marked one. Splitting a marked quote (lifting a line out of it, say) leaves both halves marked, since both are still the quoted original. Content loaded with setContent() or insertContent() is marked as written. Editing doesn't create a second marked quote that could be found before the real one: while the document holds a marked quote, a marked quote that is pasted in (or part of the quoted original copied and pasted elsewhere in the reply) becomes a plain blockquote, and so does part of a quote dragged out of it or a copy dragged from it. Cutting the quote and pasting it somewhere else, pasting it over itself, or dragging the whole quote to move it keeps the marker. A font on a marked quote reaches the paragraphs directly inside it, not those inside a nested list, table or plain blockquote. Joining a marked quote with a plain blockquote directly next to it (Backspace or Delete at their boundary) merges them into one quote, which is marked only if the first of the two was.
Apart from naming the class, the list is deliberately short and not configurable. The editor's content is part of the host page, not an iframe as in TinyMCE or CKEditor, so a class, id, data-* attribute or style from an email could pick up the host app's CSS (an overlay class, say), collide with its ids, or trigger its data-attribute handlers. A class that only contains the marker (class="foo quoted-original") is not kept, every other class, id, data-* and style is dropped, and adding an entry is a code change.
Toolbar Buttons
All built-in toolbar button names that can be used in the toolbar config string:
| Button | Description |
|--------|-------------|
| bold | Toggle bold |
| italic | Toggle italic |
| underline | Toggle underline |
| strikethrough | Toggle strikethrough |
| subscript | Toggle subscript |
| superscript | Toggle superscript |
| bullist | Toggle bullet list |
| numlist | Toggle numbered list |
| outdent | Decrease indent (see Lists & Indentation) |
| indent | Increase indent (see Lists & Indentation) |
| blockquote | Toggle block quote |
| fontfamily | Font family dropdown (button shows the family at the cursor) |
| fontsize | Font size dropdown (button shows the size at the cursor) |
| lineheight | Line height dropdown (1, 1.2, 1.4, 1.6, 2) |
| blocks | Block format dropdown (Paragraph, Heading 1–6; alias formatselect) |
| styles | Named styles dropdown (configurable via style_formats) |
| table | Table menu: an Insert table size grid, Cell / Row / Column submenus, Table properties, caption and Delete table (see Tables) |
| tableinsertdialog | Open the Insert table dialog |
| tableprops / tablerowprops / tablecellprops | Open the Table / Row / Cell properties dialog |
| tabledelete | Delete the table |
| tableinsertrowbefore / tableinsertrowafter / tabledeleterow | Insert a row above / below, delete the row |
| tableinsertcolbefore / tableinsertcolafter / tabledeletecol | Insert a column left / right, delete the column |
| tablecutrow / tablecopyrow / tablepasterowbefore / tablepasterowafter | Cut or copy the row, paste it above / below |
| tablecutcol / tablecopycol / tablepastecolbefore / tablepastecolafter | Cut or copy the column, paste it left / right |
| tablemergecells / tablesplitcells | Merge the selected cells, split a merged cell |
| tablerowheader / tablecolheader | Toggle the row / column between header cells and data cells |
| tablecaption | Add or remove the table's caption |
| tablecellvalign | Menu: the cells' vertical alignment |
| tablecellborderwidth / tablecellborderstyle | Menus: the cells' border width / style (table_border_widths, table_border_styles) |
| tablecellbackgroundcolor / tablecellbordercolor | Color pickers: the cells' background / border color (table_background_color_map, table_border_color_map) |
| hr | Insert horizontal rule |
| template | Template dropdown (requires includeTemplates: true) |
| alignleft | Align left |
| aligncenter | Align center |
| alignright | Align right |
| alignjustify | Justify text |
| forecolor | Text color picker (40 preset colors + custom hex input + Remove color) |
| backcolor | Highlight color picker (26 preset colors + custom hex input + Remove color) |
| removeformat | Clear all formatting |
| copy | Copy selection |
| cut | Cut selection |
| paste | Paste from clipboard (async Clipboard API; prefers HTML, falls back to plain text). Follows the paste-as-text and Markdown modes when one is on |
| pastemarkdown | Toggle paste-as-Markdown mode. Not in the default toolbars — add it to your toolbar string |
| pastetext | Toggle paste-as-text mode, as TinyMCE's pastetext: while it is pressed, every paste inserts plain text (see Pasting as Text). Not in the default toolbars |
| selectall | Select the whole document, as Ctrl/Cmd+A does. Not in the default toolbars — add it to your toolbar string |
| undo | Undo last change |
| redo | Redo last undo |
| image | Insert an image, or edit the selected one, in the image dialog (see Image Dialog). Shown pressed while an image is selected. Not in the basic editor |
| charmap | Special character picker (currency, math, arrows, symbols, Greek, punctuation) |
| emoticons | Emoji picker (smileys, gestures, hearts, objects, symbols, arrows). Its search matches English emoji names and keywords, such as "heart" or "happy" |
| code | Open HTML source code editor dialog |
| link | Open Insert/Edit Link dialog |
| unlink | Remove the link at the cursor |
| anchor | Insert a named anchor (<a id> target) |
| codesample | Toggle code sample block (also Ctrl+Alt+C, Cmd+Option+C on macOS). In a paragraph with line breaks (<br>, Shift+Enter), only the lines the selection touches become the code block; the lines before and after stay text. A selection across several blocks, and the first line of a list item, still convert whole paragraphs |
| fullscreen | Toggle fullscreen editing mode |
| preview | Open content preview in a new window (the window carries a Content Security Policy that blocks script; images and inline styles still render) |
| print | Print the content on its own, without the page around it, as getContent() returns it. It prints from a hidden frame that can't run script, so no popup opens. With the button in the toolbar, Ctrl+P (Cmd+P on macOS) in the editor prints this way too. Not in the default toolbars |
| visualblocks | Show blocks: outline each block with its tag name while editing (see Show Blocks). Not in the default toolbars |
| formatpainter | Format painter: click to copy the inline formatting at the selection and paint it onto the next selection made with the mouse; double-click to keep painting until clicked again or Esc (see Format Painter). Not in the default toolbars |
| media | Insert video: a YouTube, Vimeo or Dailymotion link goes in as the video's thumbnail, linked to the video (see Insert Video). Not in the default toolbars, nor in the basic editor |
| searchreplace | Open Find & Replace dialog |
| speechtotext | Open Speech to Text dialog (browser support required) |
| dictate | Toggle inline dictation — inserts speech directly at cursor (browser support required) |
| ltr | Set text direction to left-to-right |
| rtl | Set text direction to right-to-left |
Default toolbars
Full toolbar (default when basicEditor: false):
bold italic underline strikethrough subscript superscript | blocks styles | bullist numlist outdent indent blockquote | fontfamily fontsize | lineheight alignleft aligncenter alignright alignjustify | forecolor backcolor | removeformat copy cut paste | undo redo | image table charmap emoticons hr | fullscreen preview | code link unlink anchor codesample | ltr rtl | searchreplaceBasic toolbar (when basicEditor: true):
bold italic underline strikethrough subscript superscript | bullist numlist outdent indent | fontfamily fontsize blockquote | lineheight alignleft aligncenter alignright alignjustify | forecolor backcolor | removeformat copy cut paste | undo redo | charmap emoticons | link unlink | ltr rtl | searchreplaceImage Dialog
The image toolbar button, execCommand('mceImage') and a double-click on an image open the image dialog. With an image selected it opens as Image properties, filled in from that image, and Save changes it in place as one undo step. Otherwise it opens as Insert image and Insert puts a new image at the cursor. The option names and defaults are TinyMCE's.
- General
- Source: the image's address. It must be http(s), relative (without a backslash), or a base64
data:image/…URI; an SVG one, base64 or URL-encoded, is cleaned as an uploaded SVG is. An image's own address is kept as it is when you don't change it (acid:one, for example). - Alt text (
image_description), and Image is decorative (a11y_advanced_options), which savesalt="". An image inserted with no alt text has noaltattribute, and an image's alt is left alone unless you change it. - Title with
image_title. - Width and Height (
image_dimensions): pixels, or a percentage such as50%(not zero). Constrain proportions (on at first) keeps the image's ratio as you change one side, and Reset size fills in the image's own size. - Alignment: None, Left or Right, saved as
float(CKEditor's field; TinyMCE has none). - A preview of the image in sample text, at its size and with its float, spacing and border.
- Source: the image's address. It must be http(s), relative (without a backslash), or a base64
- Link: a URL and Open link in... (current or new window). A bare domain gets
http://, and an address links don't allow (javascript:,data:; see Link addresses) can't be saved. On a linked image the link changes or goes as a whole, even when it also holds text. - Upload (
image_uploadtab): drop or browse for a file. It uploads straight away, then fills in Source and shows the General tab. See Uploading images. - Advanced (
image_advtab): Style, Vertical space, Horizontal space, Border width, Border style, Text direction and Language, and Title whenimage_titleis off. A border width with no border style draws a solid border. The Style field and the others follow each other as you type. - A field whose value can't be saved (a Source that isn't an image address, a link links don't allow, a size, spacing or language an image can't keep) is marked (
aria-invalid), and Save waits until it is fixed or emptied. The arrow keys, Home and End move between the tabs.
const editor = new HTMLEditor(container, {
image_advtab: true, // the Advanced tab
image_title: true, // Title on the General tab
a11y_advanced_options: true, // "Image is decorative"
});What an image keeps
Editor content is part of your page, so an image keeps only checked values:
- its
style, limited tofloat(left, right or none), the four margins, andborder-width,border-styleandborder-color(exported asIMAGE_STYLE_RULES); anything else in a style, such aspositionor aurl(), is dropped; dir(ltrorrtl) andlang(a language tag such asfr-CA);- the older
align="left|right",hspace,vspaceandborderattributes, read into that style on load and saved as CSS; - a size written as style in pixels (
style="width: 200px"), read into thewidthandheightattributes when the image has none.
Images still don't keep id or class. The dialog doesn't write them either. The TipTap extension behind this, ImageAttributes, is exported for hosts that build their own TipTap editor. The ImageDialog class (with its ImageDialogOptions and ImageUploader types) is exported for hosts with their own toolbar; it takes the HTMLEditor it works on. imageSource(value) gives the address the dialog would store for a Source, or null when it would refuse it.
Uploading images
The Upload tab supports JPEG, PNG, GIF, WebP, BMP and SVG. Unlike TinyMCE, it is shown even without images_upload_url, because uploads then embed the image.
If images_upload_url is configured, files are sent as multipart/form-data to that endpoint. The server response must be JSON containing a location, url, or link field with the resulting image URL. When no upload URL is set, images are embedded as base64 data URIs.
An image pasted from the clipboard or dropped on the editor uploads the same way, in place of the paste or drop: an image copied or dragged from a web page goes in as the upload only, not also as the <img> in its HTML. If the upload is refused or fails, nothing goes in. A read-only editor takes no pasted or dropped image. A paste that has text beside its picture is pasted once, as its HTML (or its text, in paste-as-text mode), and the picture isn't uploaded: cells copied from a spreadsheet, for example, carry a picture of themselves as well as their table.
SVG files are automatically sanitized — dangerous elements (<script>, <foreignObject>, <animate*>) and event-handler attributes are stripped before insertion.
const editor = new HTMLEditor(container, {
images_upload_url: '/api/upload',
images_upload_credentials: true, // send cookies with CORS requests
images_upload_base_path: '/files/', // prefix for returned URLs
images_upload_max_size: 5 * 1024 * 1024, // 5 MB limit
images_upload_headers: {
'X-CSRF-Token': token,
},
});Restricting file types and rejecting uploads
images_file_types restricts which extensions are accepted (matched against the
file name, falling back to MIME for clipboard pastes that have no name). The
images_upload_validate hook runs before every upload — return a message to
reject the file. For drag-drop and clipboard-paste uploads there is no dialog to
show the message in, so rejections and failures are routed to images_upload_error
(supply your own alert/notification — the CKEditor simpleuploads newAlert flow).
const editor = new HTMLEditor(container, {
images_upload_url: '/api/upload',
images_file_types: 'jpg,jpeg,png,gif,bmp', // CKEditor simpleuploads parity
images_upload_validate: (file) =>
file.size === 0 ? 'Empty files are not allowed' : null,
images_upload_error: (message) => myApp.showAlert(message),
});Wording failed uploads
When an upload fails, the editor shows a translated message of its own: "No URL
returned from server" for a 2xx reply with no string location, url or link,
"Invalid server response" for a reply that is not a JSON object, and "Upload
failed: " for an HTTP error status. A network error, an aborted request,
an SVG that can't be parsed or a file that can't be read also get translated
messages.
When your server explains a refusal in its reply, images_upload_error_message
lets you word the message yourself. It receives the parsed JSON body (null when
the body is not JSON) and the HTTP status, and returns the message to show, or
null/undefined to keep the editor's own. It is not called for a network
error or an aborted request, which have no reply. The message is shown in the
image dialog as text, and passed to images_upload_error for a dropped or pasted
image.
const UPLOAD_ERRORS: Record<string, string> = {
ContentBlocked: 'Files of this type are blocked.',
UploadRefused: 'The server refused the upload.',
};
const editor = new HTMLEditor(container, {
images_upload_url: '/api/upload',
// The server answers a refusal with HTTP 200 and {"error": "<code or reason>"}
images_upload_error_message: (response) => {
const error = (response as { error?: unknown } | null)?.error;
if (typeof error !== 'string') return null;
return UPLOAD_ERRORS[error] ?? error;
},
images_upload_error: (message) => myApp.showAlert(message),
});Resizing images
Click an image in the full editor to select it. Eight handles appear, one on each corner and one on each side. Drag one to resize the image:
- Corners keep the aspect ratio. Hold Shift to stretch freely instead. With
resize_img_proportional: false, corners stretch freely and Shift keeps the ratio. - Sides change only the width (left and right) or only the height (top and bottom).
- A label shows the size in pixels while you drag. An image can't be made smaller than 20px on either side, or wider than the space it sits in (the editor, or a table cell).
- An image with an image map (
usemap) has no handles: its hotspots'coordsare in the image's pixels, so a new size would move them off what they mark. - Press Escape during a drag to put the image back to its starting size.
- Touch and pen work too. The handles are larger on touch screens.
When you let go, the size is saved in the image's width and height attributes, the same form TinyMCE uses. The resize is one undo step, and it marks the editor dirty and fires change like any other edit:
<img class="md-editor-image" src="photo.jpg" width="320" height="240">The image dialog's Width and Height set the same attributes. A double-click on an image opens the dialog; a double-click on a handle doesn't.
The editor shows a resizable image at its width and height attributes, even when they don't match the picture's own shape. An image wider than the editor is scaled down to fit without being distorted. Images with a percentage size (width="50%") keep that size relative to the editor, and get pixel sizes once they are resized. A resizable image has 1em of space below it, as a paragraph does.
Handles are hidden in read-only mode. Turn resizing off with object_resizing: false. Images then look and behave as they did before this feature. A CSS selector limits resizing to the images that match it ('img[alt]', for example), and TinyMCE's own selector lists work too. Images it doesn't match also look as before. In the editor each image sits inside its own wrapper element, so selectors that use the image's direct parent or its position among siblings (td > img, img:first-child) don't match as they would in the saved HTML; descendant selectors (td img) and attribute selectors do. The basic editor has no images, so these options don't apply to it.
const editor = new HTMLEditor(container, {
object_resizing: 'img', // or true (default) / false / any selector
resize_img_proportional: true, // corners keep the aspect ratio (default)
});
editor.on('objectresized', ({ width, height, handle }) => {
console.log(`Resized to ${width} × ${height} with the ${handle} handle`);
});The TipTap extension behind this, ResizableImage, is exported for use in your own TipTap editor. It is TipTap's Image node with the same name, schema and HTML, plus a proportional option and onResizeStart/onResized callbacks.
Source Code Editor
The code toolbar button opens a modal dialog for viewing and editing the raw HTML source of the editor content. The dialog features a full-size monospace textarea with the current HTML, Cancel and Save buttons, and supports Escape to close and Tab to indent.
The dialog inherits the active skin theme — oxide, oxide-dark, confab, and confab-dark are all supported automatically.
Insert/Edit Link
The link toolbar button opens a modal dialog for inserting or editing hyperlinks with the following fields:
- URL — the link destination
- Text to display — the visible link text (pre-populated from selection)
- Title — the HTML
titleattribute (shown as a tooltip on hover) - Open link in… — dropdown to choose between Current window or New window (
target="_blank")
When editing an existing link, all fields are pre-populated from the current link attributes. With the caret on a link and nothing selected, the dialog edits that whole link, text included, and Save updates it in place. Clearing the URL and saving removes the link. The dialog inherits the active skin theme. The separate unlink toolbar button removes the link at the cursor without opening the dialog.
Typing after a link: after a paste or a link inserted from the dialog leaves the caret at the end of a link, the next text typed is plain, so a pasted URL does not swallow the words that follow it. This covers pasted URLs and email addresses, pasted HTML or Markdown that ends in a link (Ctrl+V or the Paste button), editor.insertContent() (and so the Templates dropdown), and dialog inserts. Otherwise links behave as in the browser's own editing: put the caret at the end of a link and type, and the link extends; select link text and retype it, and the link is kept.
Pasting a URL: a URL or email address pasted at the caret is linked. Pasted over selected text (or a selected inline item such as a mention) within one paragraph, it turns that selection into a link instead of replacing it. Over a larger selection (all content selected with Ctrl+A, or a selection spanning several paragraphs), it replaces the selection like any other paste, and the pasted URL is linked. (Text copied from inside the editor pastes exactly as it was copied, linked or not.)
Clicking a link in the editor places the caret; it does not open the link.
Link style: a link keeps its color, font-family, font-size and text-decoration: none, with values checked; other properties are dropped. text-decoration: none has to be on the link itself, as a style inside a link cannot remove its underline. A link's weight, slant, underline and strikethrough become the bold, italic, underline and strikethrough marks, so the toolbar turns them on and off. Changing a link's URL or title in the dialog keeps its style; retyping its text inserts a new, plain link. Remove color in the text color picker removes a link's own color from the selected text too (the exported LinkStyle extension's unsetLinkColor command).
URL normalization: a URL entered without a scheme that looks like a bare domain (e.g. www.example.com or example.com/path) is saved with http:// prepended, so it resolves as an external link instead of a broken relative path. So is a host with a dot, or localhost, followed by a port and then a path or nothing (example.com:8080/page, 127.0.0.1:3000, localhost:3000), which would otherwise read as a scheme. An application's own scheme is left as typed: example.dms:1|ABC has more than a port after the colon, and x-example-app:12345 has no dot. A dotted scheme followed by digits alone, such as example.dms:12345, can't be told from a host and port, so typed in a dialog it gets http://; load it with setContent() or the Source view instead. Saving a link without changing its URL keeps the address it had, as is. Control characters (a pasted tab, say) are removed from a typed URL. URLs that already carry a scheme (https:, mailto:, tel:, ftp:, …), anchors (#section), absolute/relative paths (/, ./, ../), and protocol-relative URLs (//host) are left exactly as typed.
Link addresses
A link may use any URL scheme, including an application's own: notes://server/db, outlook:00000000ABC, zoommtg:, or one with a dot, such as example.dms:1|ABC. This applies to every way a link gets in: setContent(), pasted HTML, the Source view, the Link dialog, the image dialog's Link tab and an image map's <area href>. Only these schemes are refused:
javascript:,vbscript:andmhtml:, which run script, anddata:, which holds a whole document. TinyMCE refuses these too.file:,blob:andfilesystem:, which point at local files or the page's own objects. TinyMCE keeps these, but they never work for the reader of saved content.
A refused link becomes plain text with its text kept. The Link dialog and the image dialog's Link tab won't save one: the URL field is marked, and the dialog stays open until it is fixed. The scheme is checked after whitespace and control characters are removed, so java	script: is refused too. Addresses without a scheme (#section, /path, page.html) are always allowed.
Named Anchors
The anchor toolbar button opens a dialog to insert a named anchor — an <a id="name"> target for in-page linking. The anchor name is required and may not contain spaces. Existing anchors in loaded content (<a id> with no href) are preserved through the editor's parse/serialize cycle.
// Programmatic insertion via the TipTap command:
editor.getTipTap()?.commands.setAnchor('section-1');Tables
Table editing follows TinyMCE's table plugin: the same menu, toolbar buttons, dialogs, commands, events and options.
Table menu
The table toolbar button opens the table menu:
- Insert table — a 10×10 grid: point at the size you want and click. With
table_grid: falseit opens the Insert table dialog (columns and rows, 1 to 100 each) instead. A new table hasborder="1"andborder-collapse: collapse; width: 100%(table_default_attributes,table_default_styles), so its borders show in mail clients, and no header row unlesstable_default_header_rows/table_default_header_colssay otherwise. - Cell — Cell properties, Merge cells, Split cell.
- Row — Insert row before / after, Delete row, Row properties, Cut / Copy row, Paste row before / after, Toggle header row.
- Column — Insert column before / after, Delete column, Cut / Copy column, Paste column before / after, Toggle header column.
- Table properties, Toggle caption, Delete table.
Items that cannot apply are disabled: everything but Insert table outside a table, Merge cells unless several cells are selected, and the paste items until a row or column was cut or copied. Select several cells by dragging across them, or with Shift+arrow keys; most row, column and cell actions then apply to all of them.
Deleting the last row or the last column of a table deletes the table, as in TinyMCE. Merging cells across whole rows leaves no empty rows behind. Rows and columns are cut, copied and pasted through the editor's own table clipboard, separate from the system clipboard: a pasted row narrower than the table is padded with empty cells, and one wider than it widens the table. Ctrl+C / Ctrl+V of selected cells still use the system clipboard and paste into the cells of the table.
Columns are resized by dragging their borders.
Table context toolbar
While the cursor is in a table, a small toolbar floats above it, with TinyMCE's default buttons: Table properties, Delete table, Insert row before / after, Delete row, Insert column before / after, Delete column. table_toolbar sets its buttons as a toolbar string (any of the table buttons in Toolbar Buttons, and custom buttons), and table_toolbar: false turns it off. It is off by default in the basic editor and hidden while the editor is read-only or does not have focus.
Right-click menu
With contextmenu: 'table', a right-click in a table opens the table menu (without Insert table) for the cell under the pointer, or for the selected cells when it is one of them. It is off by default because it replaces the browser's own menu, and with it the spelling suggestions; Ctrl+right-click still shows the browser's menu, and so does a right-click outside a table.
Properties dialogs
- Table properties — width, height, cell spacing, cell padding, border width, caption and alignment (left and right float the table, center centers it); the Advanced tab has border style, border color and background color.
table_appearance_options: falsehides cell spacing, cell padding, border width and caption, andtable_advtab: falsethe Advanced tab. - Row properties — row type (header or body), alignment and height, with the same Advanced tab (
table_row_advtab). - Cell properties — width, height, cell type (cell or header cell), scope, horizontal and vertical alignment; the Advanced tab adds border width (
table_cell_advtab). A cell's width is its column's, so it applies to every cell in the column.
A size without a unit is pixels. Only the fields you change are applied, so opening a dialog on several rows or cells that differ leaves the rest alone. A value the editor does not keep (see below) is dropped.
Table commands
| Command | Value | Action |
|---------|-------|--------|
| mceInsertTable | { rows, columns, options?: { headerRows, headerColumns } } | Insert a table, of at most 100 rows and 100 columns |
| mceInsertTableDialog | - | Open the Insert table dialog |
| mceTableProps / mceTableRowProps / mceTableCellProps | - | Open the Table / Row / Cell properties dialog |
| mceTableInsertRowBefore / mceTableInsertRowAfter / mceTableDeleteRow | - | Insert a row above / below, delete the selected rows |
| mceTableInsertColBefore / mceTableInsertColAfter / mceTableDeleteCol | - | Insert a column left / right, delete the selected columns |
| mceTableCutRow / mceTableCopyRow / mceTablePasteRowBefore / mceTablePasteRowAfter
