Rich Text Editor
ProFull-featured contenteditable editor with a configurable 35-tool toolbar — fonts, colors, alignment, lists and checklists, link/table/code, emoji, undo/redo, export, source view, fullscreen and word count.
import { SvRichTextEditorComponent } from '@styloviz-pro/rich-editor';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
A comment box
toolbar="comment" — bold, italic, strike, link, code block and blockquote. Presets: full (default), basic, minimal, comment, none.
Exactly these tools
An id list shows only those tools; hiddenTools then takes tools away from whatever toolbar resolved to.
Constrained with counters
Accessible labelling
Give the editor a meaningful accessible name with ariaLabel; the built-in role="textbox" + aria-multiline and aria-pressed toolbar toggles do the rest.
Reactive forms (CVA)
Implements ControlValueAccessor, so it binds with formControlName / ngModel; formControl.disable() disables the toolbar and editor.
Paste cleaning
On by default. Clipboard markup is parsed inertly and rebuilt from an allowlist before it reaches the document — the browser paste is cancelled first, so nothing from the clipboard ever touches a live node.
Paste as plain text
Mentions
The trigger scan is shared with sv-mention, so the rule that stops an email address opening a people-search is one rule. The inserted chip is atomic to the caret.
Mentions that were edited after insertion
contenteditable="false" makes a chip atomic to the caret; it does not make it immutable. A chip reading "@Priya Sharm" still carries Priya's user id.
Merged table cells
Select across cells and merge. The grid model is the HTML spec's slot map, because once a cell has a span the DOM stops telling you which column a cell is in.
The grid model, on its own
Exported, because "which column is this cell in" has no answer in DOM terms once a span exists — and any host doing its own table work needs the same map the editor uses.
Markdown mode
A round trip through Markdown is lossy — Markdown has no colour, no underline and no merged cells — so the conversion returns what it dropped instead of pretending it dropped nothing. The notice is shown on the way in, while the HTML that carried the formatting still exists.
Markdown without the mode toggle
Read and write Markdown directly. While the mode is open, markdown() returns the live textarea rather than a stale conversion of the HTML behind it — an autosave wired to the other choice saves the wrong text, and only for authors who happened to be in Markdown mode when it fired.
Clean markup outside the editor
The sanitiser is exported, so the same rules can be applied to content arriving from anywhere else — an import, a webhook, a migration.
Signal Forms
Bind it with `[formField]` from `@angular/forms/signals` — the control is a ControlValueAccessor, which Signal Forms drives on Angular 21 and 22 alike.
When to use
Authoring formatted content: comments, descriptions, articles, email bodies. You need bold/lists/links/tables without pulling in a heavy third-party editor. For plain short text, a multiline Text Field is lighter.
Compare with
- Markdown Editor — Markdown Editor edits Markdown source in a native textarea with a live preview — pick it when Markdown is what you store. Rich Text Editor edits formatted HTML in place.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | '' | HTML content. Use `[(value)]` for two-way binding. |
| placeholder | string | 'Start typing here…' | Placeholder shown when empty. |
| ariaLabel | string | '' | Accessible name for the editor (announced by screen readers). Falls back to the placeholder. |
| height | string | '320px' | Editor height (CSS length). |
| disabled | boolean | false | Disable editing. |
| readonly | boolean | false | Read-only mode — content visible but not editable. |
| maxLength | number | 0 | Max character count (0 = unlimited). |
| showWordCount | boolean | true | Show the word counter. |
| showCharCount | boolean | true | Show the character counter. |
| autoFocus | boolean | false | Focus the editor on init. |
| toolbarLine | 'wrap' | 'scroll' | 'wrap' | Toolbar overflow behaviour: wrap to multiple rows or scroll. |
| documentTitle | string | '' | Title for a printed or exported document. It becomes the exported document's `<title>`, which is what a browser offers as the default filename in its print dialog — "Document Export" for every document in the product is a folder of indistinguishable PDFs. |
| toolbar | SvRteToolbarPreset | readonly SvRteToolId[] | 'full' | Which tools the toolbar shows: a preset (`'full'` | `'basic'` | `'minimal'` | `'comment'` | `'none'`), or the exact tool ids to show. `hiddenTools` is then taken away from whatever this resolved to. |
| hiddenTools | readonly SvRteToolId[] | [] | Tools to hide, from whatever `toolbar` resolved to. Any SvRteToolId — the original four (SvRichTextEditorTool) keep working unchanged. See SvRichTextEditorTool for why a host would want this. |
| htmlSanitizer | ((html: string) => string) | null | null | Replaces the sanitiser applied to HTML that ENTERS the editing surface from outside — `[value]`, `writeValue` (formControl) and leaving source view — and to the HTML handed to print/PDF/image export. The default is on, and `null` means "the default", not "none": a stored `<img src=x onerror=…>` in a saved document is removed before it reaches a live node. The default is `svSanitizeEditorHtml` from `@styloviz/core`, whose allowlist matches what this editor writes (tables, images, fonts, mentions) so a saved document round-trips unchanged. Pass your own function to use a different policy (e.g. DOMPurify with your configuration). Returning the input unchanged switches sanitising off; only do that for HTML you have already sanitised on the server. This protects the editor, not your app. Sanitise again where the value is stored and wherever else you render it. |
| mentionTriggers | readonly string[] | [] | Trigger characters that open the mention panel, e.g. `['@', '#']`. Empty disables mentions entirely. |
| mentionSuggestions | readonly SvMentionToken[] | [] | Candidates for the open query. The host filters; this component displays. |
| mentionChipClass | string | 'rounded bg-brandaccent-100 px-1 font-m… | Tailwind classes for the inserted chip. |
| slashCommands | boolean | readonly SvRteSlashCommand[] | false | The `/` command menu: `true` for the built-in commands (paragraph, headings, lists, checklist, quote, code block, table, divider), or your own list. Built-in ids run in the editor; every chosen command is emitted as `slashCommand` too. |
| cleanPaste | boolean | true | Clean markup arriving from the clipboard. On by default, and the default is the point. Without it the browser drops whatever the clipboard carried straight into the contenteditable, and this component reads its value back out of `innerHTML` — so a host that persists that value and renders it to another reader has a stored-XSS path whose injection point is somebody else's clipboard. Turning this off is a decision about trusting every author of every document. |
| pastePlainText | boolean | false | Paste everything as plain text, discarding all formatting. |
| allowPastedDataImages | boolean | false | Keep `data:image/*` sources on pasted images. Off by default: pasting a screenshot inlines megabytes of base64 that a persisting host then puts into a database row. |
| saving | boolean | false | True while the document is being saved. |
| savedAt | Date | null | null | When the last successful save completed. Drives the "Saved just now" indicator; `null` means nothing has been saved yet this session. |
| saveError | SvDataError | string | null | null | Failure saving. Kept visible until the next successful save — an editor that silently stops persisting is the worst failure mode this component has, because the user keeps typing into something that is not being kept. |
| conflict | boolean | false | Someone else changed the document since it was loaded. Shown as a warning so the user does not overwrite their colleague without knowing. |
| errorMessage | string | '' | Client-side validation message. |
| serverError | SvServerError | null | A rejection reported by the server about this value. Self-expiring. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| mentionQuery | SvTriggerMatch | Emitted whenever the open query changes, so the host can look candidates up. |
| mentionInserted | SvMentionToken | Emitted when a mention is inserted. |
| slashCommand | SvRteSlashCommand | Emitted with each command chosen from the `/` menu, after the typed `/query` is removed. |
| pasteCleaned | SvPasteResult | Emitted when a paste was cleaned, with what was removed. A sanitiser that eats content silently is indistinguishable from a broken paste, and the author's next move is to paste through Notepad instead. |
| valueChange | string | Emits the editor's HTML after every edit, formatting command, undo or redo — the output half of `[(value)]`. |
| contentChange | string | Emits the same HTML as `valueChange`, on the same edits — for hosts that listen rather than bind `[(value)]`. |
| editorFocus | void | Fires when the editable area gains focus. |
| editorBlur | void | Fires when the editable area loses focus; the same blur marks the form control touched and requests a save (`saveRequest`). |
| saveRequest | string | Persist the current content. Emitted on blur and whenever the host asks via `requestSave()`; the component never saves on a timer of its own, because only the host knows what a save costs. |
| exportFailed | { format: RteExportFormat; error: unknown } | Emitted when an export could not be produced, with the underlying error. |
| markdownChanged | string | Fires with the Markdown text each time the author leaves the mode. |
Customization & theming
Set `height`, `placeholder`, `ariaLabel` and the `toolbarLine` overflow mode (wrap or scroll). Every one of the 35 tools is a switch: `toolbar` takes a preset (`full` — the default — `basic`, `minimal`, `comment`, `none`) or a list of tool ids, and `hiddenTools` takes any tool id away from whatever that resolved to. `SV_RTE_TOOL_GROUPS` exports the 11 groups, so a host can build "everything in `insert` except `image`". Switch between rich and source (HTML) views, fullscreen, and toggle the word / character counters. Two-way bind with `[(value)]` or bind a reactive control (ControlValueAccessor); react to `contentChange`, `editorFocus` and `editorBlur`. Paste cleaning via `cleanPaste` (on by default), `pastePlainText` and `allowPastedDataImages`, with a `pasteCleaned` output naming what was removed. `svCleanPastedHtml`, `svPlainTextFromHtml` and `svIsSafeUrl` are exported for use outside the editor. Merged table cells via `mergeTableCells()`, `splitTableCell()`, `tableMergeRefusal()` and `caretInMergedCell()`. The slot map (`svTableGrid`, `svSelectionRect`, `svMergePlan`, `svSplitCell`) is exported for hosts doing their own table work. Markdown mode via `toggleMarkdownMode()`, `markdown()`, `setMarkdown()`, `markdownNotice()` and the `markdownChanged` output. `svHtmlToMarkdown` returns `{ markdown, lost }`; `svMarkdownToHtml`, `svEscapeMarkdown` and `svMarkdownLossLabel` are exported too. Mentions via `mentionTriggers` (any number of characters — `@` people, `#` topics, `/` commands), `mentionSuggestions`, `mentionQuery` and `mentionInserted`. `mentions()`, `mentionRepairs()` and `plainText()` read the document back. The scan is `svScanTrigger` from `@styloviz/core`, shared with `sv-mention`. Slash commands via `slashCommands` (`true` for the built-ins, or your own `SvRteSlashCommand[]`) and the `slashCommand` output; `checklist` and `emoji` are toolbar tools like any other. Track changes with the `svRteSuggest` directive (`[svRteSuggest]`, `suggestAuthor`, `#s="svRteSuggest"` → `suggestions()`, `accept`, `reject`, `acceptAll`, `rejectAll`, `resolved`); comments, find & replace and the outline are siblings — `sv-rte-comments`, `sv-rte-find-replace`, `sv-rte-outline` — that take the editor as `[editor]`. Revision compare with `svDiffHtml(before, after)`, Word import with `svDocxToHtml(file)`, and real-time collaboration with the `svRteCollab` directive over any `SvEditorCollabAdapter` (`svCreateMemoryCollabHub()` is the in-memory fake peer; a Yjs adapter is in the gallery). Building your own sibling: `surface()` is the editing element, `commitEdit()` records a change you made to it as one undo step, `setFindHandler()` claims Ctrl/Cmd+F and `applyRemoteHtml()` replaces the document keeping the caret.
Forms integration
sv-rich-text-editor— ControlValueAccessor.[formControl],formControlName,[(ngModel)]and Signal Forms[formField]all work.
Best practices
Do: Sanitize the emitted HTML on the server too. `cleanPaste` closes the clipboard path, and it is a client-side control: anything that can POST to your API can send markup that never went through it. Do: Allow `style-src 'unsafe-inline'` in your CSP, or turn the controls that write inline styles off — `hiddenTools` with `'fontColor'`, `'backgroundColor'`, `'alignment'`, `'fontFamily'` and `'fontSize'`. `execCommand('foreColor')` writes inline `style` attributes rather than classes, and the paste allowlist deliberately keeps them — so under `style-src 'self'` the text survives and the colour, highlight and alignment silently do not, in the editor and everywhere the value is later rendered. Nothing throws. A hash or nonce does not help: those apply to `<style>` elements, not to `style` attributes. Do: Add `data:` to `img-src` if you set `allowPastedDataImages`, and decide what `img-src` should say about the third-party hosts your authors paste from. Pasted `http(s)` image sources are kept as-is — those are requests from your page to somebody else's server. Upload and rewrite them at the boundary if they need to be same-origin. Don't: Don't treat the client sanitiser as the security boundary. This component's value is a string and your API accepts that string over HTTP, so anything that can make a request can send one that never passed through `cleanPaste` — curl, a replayed request, an importer, a migration. Validate and sanitise on the server as well. Do: Handle `pasteCleaned` and show the summary. A sanitiser that eats content silently is indistinguishable from a broken paste, and the author's next move is to paste through Notepad. Do: Read mentions with `mentions()` rather than tracking them as you insert them. A list kept beside the document drifts the moment somebody deletes a chip or undoes, and the drift is invisible until a notification goes to the wrong person. Do: Check `mentionRepairs()` before acting on mentions. A chip can be edited after insertion — it stays atomic to the caret but is not immutable — and an edited chip carries a real user id next to a name that is not theirs. Do: Disable your merge button on `tableMergeRefusal()` rather than letting the merge fail — the refusal names which of the three reasons applies, and a merge that went ahead on a region that is not exactly covered leaves rows of different widths. Do: Show `markdownNotice()` when Markdown mode is open, and leave it up. It is computed on the way IN, while the HTML that carried the colour and the merged cell still exists — after the switch there is nothing left to inspect, and `execCommand`'s undo history does not span a mode change. Don't: Don't treat a Markdown round trip as a save format for documents that use colour, alignment, underline or merged cells. It is a text view, not a lossless one, which is why the conversion returns a loss list rather than a string. Do: Set a `maxLength` and surface counters for user-generated content. Do: Pass `ariaLabel` so the editor has a clear accessible name beyond the placeholder. Don't: Don't set `cleanPaste="false"` unless you have decided you trust every author of every document. The editor reads its value back out of `innerHTML`, so whatever the clipboard carried is what gets persisted and rendered to the next reader.
Accessibility
The editing surface is `role="textbox"` with `aria-multiline`; `ariaLabel` sets a meaningful accessible name (falling back to the placeholder). The `role="toolbar"` holds labelled buttons, and formatting toggles (bold, italic, underline, strikethrough, super/subscript, ordered/unordered list, source, fullscreen) expose `aria-pressed`. A toolbar button that shows text is named with that text: the line-height button says the height it shows ("Line height 1.50"), and Export says "Exporting" while it works. The word / character count is an `aria-live="polite"` status region; common shortcuts (Ctrl/Cmd+B/I/U, undo/redo) are supported. Merging keeps the content of every absorbed cell rather than only the top-left one — silently destroying three of four values is not something an author can see happen, and undo is the only way back. The mention panel is a `role="listbox"` that never takes focus: the editor keeps it and announces the active option through `aria-activedescendant`, because moving focus out of the contenteditable loses the caret the insertion needs. Arrows move, Enter and Tab insert, Escape closes — and those keys are only claimed while the panel is open, so Enter still makes a paragraph the rest of the time. The Markdown loss notice is `role="status"`, not an alert: it reports a consequence of the button the author just pressed, and an alert would interrupt a screen reader mid-sentence to announce something they asked for. The Markdown textarea carries its own label, and the rich surface goes `aria-readonly` while the mode is open so it is not announced as two editable regions. Pasting is cleaned rather than blocked: the content the author meant survives (an unknown wrapper is unwrapped, not deleted), and what was removed is reported instead of vanishing — a silent sanitiser is indistinguishable from a broken paste for somebody who cannot see the result. Track changes are `<ins>`/`<del>` — announced as insertions and deletions by screen readers that support them, and shown with an underline or strike as well as colour. The slash menu is the mention panel's pattern: a `role="listbox"` announced through `aria-activedescendant` while the caret stays in the text. The emoji grid is one tab stop with arrow-key movement, and each emoji is named by the screen reader in the user's language rather than by an English label. Checklist boxes are real checkboxes named "Done"; Ctrl/Cmd+Enter ticks the item at the caret, so a keyboard user never has to reach for the box.
Feedback on Rich Text Editor
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.