Markdown Editor
ProA Markdown source editor on a native textarea — undo, IME, spellcheck and phone keyboards intact — with a toolbar that wraps and unwraps (heading, bold, italic, strikethrough, code, link, quote, bulleted / numbered / task lists, code block, table), Ctrl/Cmd+B/I/K, list-aware Enter and Tab, write / preview / split views with synced scroll, paste-to-link and HTML-to-Markdown paste. The preview is the kit’s safe renderer, so nothing typed can become markup.
import { SvMarkdownEditorComponent } 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
Split view for a docs page
Source and rendered page side by side, scrolled together; stacks under 640px (`stackBelow`). `view` and `splitAt` are models, so a host can remember both.
A comment box
A short toolbar, Write and Preview only, a limit, and Ctrl/Cmd+Enter to send.
Reactive forms (CVA + validator)
Binds with formControl / formControlName / ngModel; reports `required` and `maxlength` in Angular’s error shapes. `[formField]` (Signal Forms) works through the same accessor.
Insert at the caret
`insertText()` replaces the selection with text as one undo step — a snippet, a template, a canned reply. A preview switches back to write first.
Your own toolbar
The edits are pure functions of (text, selection) — each returns the range to replace and where the selection lands.
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
You store Markdown — docs pages, READMEs, release notes, knowledge-base articles, canned replies — and authors should see and own the syntax. A comment or reply box where a few marks (bold, code, a link, a list) are enough and HTML would be a liability. For formatted HTML with fonts, colours and merged cells, use the Rich Text Editor instead.
Compare with
- Rich Text Editor — Rich Text Editor edits formatted HTML in place (fonts, colours, merged cells) and can show a Markdown view of it. Markdown Editor edits the Markdown itself in a plain textarea and previews it — pick it when Markdown is what you store.
- Streaming Markdown — Streaming Markdown only renders. Markdown Editor is the writing side: a source editor whose preview IS a Streaming Markdown.
- Smart Textarea — Smart Textarea is a plain textarea that suggests what comes next. Markdown Editor formats Markdown with a toolbar and a preview.
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 (two-way) | '' | The Markdown source. Two-way bindable with `[(value)]`; also a form control. |
| view | SvMarkdownEditorView (two-way) | 'write' | What is shown: `'write'` (source), `'preview'` (rendered) or `'split'` (both). Two-way bindable. |
| splitAt | number (two-way) | 50 | Share of the width (or height, stacked) the source takes in split view, in %. Two-way bindable. |
| toolbar | readonly SvMarkdownTool[] | SV_MARKDOWN_TOOLS | The formatting tools to show, in toolbar order (as `sv-rich-text-editor`'s `toolbar` takes tool ids). `[]` leaves only the view switch. Shortcuts follow the list: Ctrl/Cmd+B does nothing when `bold` is not in it. |
| views | readonly SvMarkdownEditorView[] | ['write', 'preview', 'split'] | The views the switch offers, in order. One view hides the switch. |
| placeholder | string | '' | Placeholder for an empty source. Not an accessible name — set `ariaLabel` or a `<label for>`. |
| ariaLabel | string | '' | Accessible name of the source textarea. Falls back to "Markdown source". |
| ariaDescribedBy | string | '' | Ids of elements that describe the field (a hint, an error), joined to the editor's own keyboard hint. |
| inputId | string | '' | Id for the textarea, so an external `<label for>` can name it. Generated when empty. |
| height | string | '18rem' | Height of the editing area, as a CSS length. |
| maxLength | number | 0 | Maximum characters (the native `maxlength`, and a counter). `0` is unlimited. |
| disabled | boolean | false | Disable the editor: no editing, no toolbar. A form control's `disable()` does the same. |
| readonly | boolean | false | Read-only: the source can be selected, copied and previewed, not changed. |
| required | boolean | false | Mark the field required (`aria-required`, and a `required` error when bound to a form). |
| invalid | boolean | false | Show the field as invalid (`aria-invalid`, danger border) — bind your form's state. |
| spellcheck | boolean | true | The browser's spellcheck on the source. |
| showCount | boolean | true | Show the word and character count under the editor. |
| syncScroll | boolean | true | In split view, scroll the preview with the source and the source with the preview. |
| stackBelow | number | 640 | Below this width (px) the split view stacks the preview under the source instead of beside it. |
| pasteHtml | SvMarkdownPasteMode | 'markdown' | What an HTML paste becomes: `'markdown'` converts a pasted web page or document through `svHtmlToMarkdown` and reports what Markdown could not carry; `'text'` keeps the browser's plain-text paste. Code copied from an editor (`<pre>`, `white-space: pre`) always pastes as text. |
| headingOffset | number | 0 | Added to every heading level in the preview, so `#` becomes `<h3>` at 2. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| linkClick | MarkdownLinkClick | A link in the preview was activated. |
| pasteConverted | SvMarkdownResult | An HTML paste was converted to Markdown — `lost` lists what Markdown could not carry. |
| submitted | string | Ctrl/Cmd+Enter in the source — the "send" chord of a comment box. Carries the value. |
| valueChange | string | Emits the new `value` whenever it changes — the output half of `[(value)]`. |
| viewChange | SvMarkdownEditorView | Emits the new `view` whenever it changes — the output half of `[(view)]`. |
| splitAtChange | number | Emits the new `splitAt` whenever it changes — the output half of `[(splitAt)]`. |
Customization & theming
`value`, `view` (`write` / `preview` / `split`) and `splitAt` are two-way models; `toolbar` takes tool ids in order (`SV_MARKDOWN_TOOLS` is all twelve), `views` the views the switch offers. `height`, `placeholder`, `maxLength` (native `maxlength` + counter, amber from 90%), `required`, `invalid`, `disabled`, `readonly`, `spellcheck`, `showCount`, `syncScroll`, `stackBelow`, `headingOffset` (preview), `pasteHtml` (`markdown` or `text`). Outputs: `submitted` (Ctrl/Cmd+Enter), `pasteConverted` (`{ markdown, lost }` from `svHtmlToMarkdown`), `linkClick` (a preview link). Methods `insertText()`, `format(tool)`, `focus()`. Every visible string is a label in the `richEditorPro` namespace (the `md…` keys), in 12 language packs. Print shows the rendered document, never the source.
Forms integration
sv-markdown-editor— ControlValueAccessor.[formControl],formControlName,[(ngModel)]and Signal Forms[formField]all work.
Best practices
Do: Give it a name: `ariaLabel`, or a `<label for>` with `inputId`. A placeholder is not an accessible name. Do: Render stored Markdown with `sv-streaming-markdown` — the same parser and URL rules as the preview, so what the author saw is what readers get. Don't: Don’t assign the textarea’s value yourself; bind `[(value)]` or a form control. The editor only writes the textarea when the value really differs, which is what keeps the browser’s undo history. Tip: Use `[toolbar]` to keep a comment box short, and `[views]` to drop split view where there is no room for it.
Accessibility
The source is a native `<textarea>` — screen readers, dictation, IME composition, spellcheck and undo work as they do anywhere else. It carries `aria-required`, `aria-invalid`, `maxlength`, and an `aria-describedby` keyboard hint joined to the host’s own ids. The toolbar is `role="toolbar"` with one tab stop: ←/→ move between buttons (mirrored under RTL), Home/End go to the ends. Tools that cannot act (read-only, preview) stay focusable with `aria-disabled`; view buttons expose `aria-pressed`; shortcuts are in `aria-keyshortcuts` and the tooltip. Tab and Shift+Tab change a list item’s indent and nothing else: outside a list, or Shift+Tab at the margin, they move focus. Escape, then Tab, always leaves the editor — announced through a polite status region, so focus is never trapped. The preview is a focusable, named `role="region"` so it can be scrolled from the keyboard; the split divider is the kit splitter’s `role="separator"` with arrow keys and step buttons. A refused edit (character limit) and a converted paste are announced, not silent. Engine: the ADR-aria row asks for the `@angular/aria` toolbar. The package is not a dependency of the kit yet (adopted from 2.1, ADR rule 1), so the toolbar is an in-house WAI-ARIA toolbar on core’s `svRovingTarget`; moving to Aria later changes no input or output.
Feedback on Markdown 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.