A writing surface for any app: a toolbar with headings, lists, links, code, images and tables, Markdown shortcuts as you type, and the document out as Markdown, HTML or JSON. Pasted content is cleaned, and nothing is fetched inside.
On this page
- Docs and wikis
- Knowledge base articles
- Comments and long replies
- CMS post bodies
- Notes and meeting minutes
Examples
Installation
Installation is part of Pro
Pro components install from a licensed registry. The live preview stays open to everyone.
Props
- value
string|JSONContent- The document, controlled, in format.
- defaultValue
string|JSONContent- The first document when it is not controlled.
- format
"markdown"|"html"|"json"- Default
"markdown" - The format of value, defaultValue and onChange's first argument. HTML in is sanitized before the editor reads it.
- onChange
(value, details) => void- Every edit. details has markdown, html (sanitized), json, text, words and chars.
- toolbar
boolean- Default
true - The fixed toolbar.
- exclude
RichCommand[]- Default
[] - Commands to leave out of the toolbar, the bubble and the slash menu, such as ["table", "image"].
- slash
boolean- Default
true - Type / for the block menu.
- bubble
boolean- Default
true - The bubble over a selection: marks, link and Ask AI.
- dragHandle
boolean- Default
true - The gutter handle: drag a block, or open its menu (turn into, move, duplicate, delete).
- onAsk
(request, signal) => string|Promise<string>|AsyncIterable<string>- Ask AI on the selection. request has action (rewrite, shorten, translate, tone), text, language, tone and the whole document as markdown. Without it there is no Ask AI.
- mentions
{ search(query, signal), serialize?, parse? }- Type @ to mention someone. search returns { id, label, description?, avatar? }[]; a stale search is aborted. Saved as [mention id label], or in your format with serialize and parse (see Ref format).
- refs
{ search(query, signal), trigger?, onOpen?(ref), serialize?, parse? }- Default
trigger "[[" - Type [[ to link a doc, a task or a ticket ({ id, label, kind?, href? }). A click or Enter on the chip calls onOpen. Saved as [ref id label kind href], or in your format (see Ref format).
- extensions
AnyExtension[]- Default
[] - Your own Tiptap extensions, after the built-ins. Their parseMarkdown, renderMarkdown, markdownTokenName and markdownTokenizer take part in Markdown. A built-in with the same name leaves. Read once, on mount.
- removeExtensions
string[]- Default
[] - Built-ins to leave out by name, such as ["image", "table"]. Names inside a kit work too ("strike", "codeBlock"). Leave out the matching toolbar command with exclude.
- suggestion / loading
string|null / boolean- Ghost text after the caret from your model; loading says one is on its way to screen readers.
- onAccept / onDismiss
(text, kind) => void / () => void- Tab took the whole suggestion or ⌘→ one word; Escape dropped it.
- marks / onMarkHover
TextMarkSpec[] / (id, el) => void- Stretches to underline (a long sentence, a repeated word), found by their exact text, as in Prompt Editor.
- onSelectionChange
(text) => void- The selected text changed; an empty string when only the caret is left.
- askLanguages / askTones
string[]- Default
6 languages / 4 tones - What Translate and Change tone offer.
- readOnly
boolean- Default
false - Not editable and no toolbar. The footer says Read only.
- placeholder
string- Default
"Write something, or type Markdown" - Shown in an empty document.
- media
MediaPickerProps- The Media Library the image button opens (assets, loading, onUpload, accept, maxSize ...).
- onUploadImage
(file, signal) => Promise<{ src, alt? }>- Uploads a pasted or dropped image, or one from the file dialog when there is no media. Resolve with the URL to show.
- footer
boolean- Default
true - The hint line and the word and character count.
- footerStart
ReactNode- Something at the start of the footer, such as a SaveState.
- minHeight / maxHeight
string- Default
"14rem" / none - Height of the writing area; it scrolls past maxHeight.
- handle
Ref<RichEditorHandle>- editor(), getMarkdown(), getHTML(), getJSON(), selection(), insertMarkdown(md), append(md), run(command), isActive(command), focus().
- aria-label / aria-labelledby
string- Default
"Document" - The editable area's name.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | JSONContent | - | The document, controlled, in format. |
| defaultValue | string | JSONContent | - | The first document when it is not controlled. |
| format | "markdown" | "html" | "json" | "markdown" | The format of value, defaultValue and onChange's first argument. HTML in is sanitized before the editor reads it. |
| onChange | (value, details) => void | - | Every edit. details has markdown, html (sanitized), json, text, words and chars. |
| toolbar | boolean | true | The fixed toolbar. |
| exclude | RichCommand[] | [] | Commands to leave out of the toolbar, the bubble and the slash menu, such as ["table", "image"]. |
| slash | boolean | true | Type / for the block menu. |
| bubble | boolean | true | The bubble over a selection: marks, link and Ask AI. |
| dragHandle | boolean | true | The gutter handle: drag a block, or open its menu (turn into, move, duplicate, delete). |
| onAsk | (request, signal) => string | Promise<string> | AsyncIterable<string> | - | Ask AI on the selection. request has action (rewrite, shorten, translate, tone), text, language, tone and the whole document as markdown. Without it there is no Ask AI. |
| mentions | { search(query, signal), serialize?, parse? } | - | Type @ to mention someone. search returns { id, label, description?, avatar? }[]; a stale search is aborted. Saved as [mention id label], or in your format with serialize and parse (see Ref format). |
| refs | { search(query, signal), trigger?, onOpen?(ref), serialize?, parse? } | trigger "[[" | Type [[ to link a doc, a task or a ticket ({ id, label, kind?, href? }). A click or Enter on the chip calls onOpen. Saved as [ref id label kind href], or in your format (see Ref format). |
| extensions | AnyExtension[] | [] | Your own Tiptap extensions, after the built-ins. Their parseMarkdown, renderMarkdown, markdownTokenName and markdownTokenizer take part in Markdown. A built-in with the same name leaves. Read once, on mount. |
| removeExtensions | string[] | [] | Built-ins to leave out by name, such as ["image", "table"]. Names inside a kit work too ("strike", "codeBlock"). Leave out the matching toolbar command with exclude. |
| suggestion / loading | string | null / boolean | - | Ghost text after the caret from your model; loading says one is on its way to screen readers. |
| onAccept / onDismiss | (text, kind) => void / () => void | - | Tab took the whole suggestion or ⌘→ one word; Escape dropped it. |
| marks / onMarkHover | TextMarkSpec[] / (id, el) => void | - | Stretches to underline (a long sentence, a repeated word), found by their exact text, as in Prompt Editor. |
| onSelectionChange | (text) => void | - | The selected text changed; an empty string when only the caret is left. |
| askLanguages / askTones | string[] | 6 languages / 4 tones | What Translate and Change tone offer. |
| readOnly | boolean | false | Not editable and no toolbar. The footer says Read only. |
| placeholder | string | "Write something, or type Markdown" | Shown in an empty document. |
| media | MediaPickerProps | - | The Media Library the image button opens (assets, loading, onUpload, accept, maxSize ...). |
| onUploadImage | (file, signal) => Promise<{ src, alt? }> | - | Uploads a pasted or dropped image, or one from the file dialog when there is no media. Resolve with the URL to show. |
| footer | boolean | true | The hint line and the word and character count. |
| footerStart | ReactNode | - | Something at the start of the footer, such as a SaveState. |
| minHeight / maxHeight | string | "14rem" / none | Height of the writing area; it scrolls past maxHeight. |
| handle | Ref<RichEditorHandle> | - | editor(), getMarkdown(), getHTML(), getJSON(), selection(), insertMarkdown(md), append(md), run(command), isActive(command), focus(). |
| aria-label / aria-labelledby | string | "Document" | The editable area's name. |
- useRichAutosave(value, save, options)
RichAutosave- Autosave for any value. save(value, signal, { force }) is yours and may resolve to { conflict: name }. Returns props for Save State, dirty, flush() and reset(value).
- delay
number- Default
1000 - Quiet time after the last change before a save.
- maxWait
number- Default
10000 - Longest a run of edits waits while typing goes on.
- enabled
boolean- Default
true - Off pauses autosave; flush() still saves.
- warnOnLeave
boolean- Default
true - Ask before leaving the page with unsaved edits.
- onKeepTheirs
() => void- Turns on Keep mine and Keep theirs in Save State. Keep mine saves again with force: true; Keep theirs calls this, and you load their copy and call reset(it).
| Option | Type | Default | Description |
|---|---|---|---|
| useRichAutosave(value, save, options) | RichAutosave | - | Autosave for any value. save(value, signal, { force }) is yours and may resolve to { conflict: name }. Returns props for Save State, dirty, flush() and reset(value). |
| delay | number | 1000 | Quiet time after the last change before a save. |
| maxWait | number | 10000 | Longest a run of edits waits while typing goes on. |
| enabled | boolean | true | Off pauses autosave; flush() still saves. |
| warnOnLeave | boolean | true | Ask before leaving the page with unsaved edits. |
| onKeepTheirs | () => void | - | Turns on Keep mine and Keep theirs in Save State. Keep mine saves again with force: true; Keep theirs calls this, and you load their copy and call reset(it). |
Custom extensions
extensions adds your own Tiptap extensions after the built-in ones. They take part in Markdown the way the built-ins do: a node or mark with parseMarkdown and renderMarkdown reads and writes it, markdownTokenName picks the token it reads (such as html), and markdownTokenizer adds new syntax. The list is read once, when the editor mounts.
Names decide clashes. An extension of yours with the name of a built-in (image, link, codeBlock) replaces it, inside StarterKit too, so there are never two of one. removeExtensions leaves built-ins out by name with nothing in their place; its Markdown syntax is then read as plain text. The toolbar does not follow on its own: leave its button out with exclude. For your own image paste or drop, leave onUploadImage unset, so your extension's handler gets the event.
import { Node } from "@tiptap/core";
// Raw HTML blocks stay in the Markdown as written; the editor shows a box, never the HTML itself.
const RawHtml = Node.create({
name: "rawHtml",
group: "block",
atom: true,
addAttributes: () => ({ html: { default: "" } }),
parseHTML: () => [{ tag: "div[data-raw-html]", getAttrs: (el) => ({ html: el.getAttribute("data-html") ?? "" }) }],
renderHTML: ({ node }) => ["div", { "data-raw-html": "", "data-html": node.attrs.html }, "HTML block"],
markdownTokenName: "html",
parseMarkdown: (token, h) => (token.block ? h.createNode("rawHtml", { html: token.raw.trimEnd() }) : []),
renderMarkdown: (node) => node.attrs.html,
});
<RichEditor
value={markdown}
onChange={setMarkdown}
extensions={[RawHtml, MyImage]} // MyImage is named "image", so it replaces the built-in
removeExtensions={["table"]}
exclude={["table"]} // and the toolbar's table button goes too
/>Ref format
Refs and mentions save as shortcodes unless you give serialize and parse. Then your format is the Markdown: serialize writes a chip picked from the list, parse.pattern finds one in the text, and parse.toItem turns the match into an item. A chip read from Markdown always saves as it was written, byte for byte, so loading and saving a document never rewrites it. An id your lookup does not know (toItem returns null) stays a chip marked unresolved: muted, dashed, it opens nothing. The pattern is matched at the start of the text that is left, so a lookbehind sees nothing. Each editor keeps its own format, two on one page included.
Your own ref format
<RichEditor
value={markdown}
onChange={setMarkdown}
refs={{
search: (q, signal) => api.searchIssues(q, { signal }),
serialize: (ref) => `@${ref.kind}/${ref.id}`,
parse: {
pattern: /@(issue|doc)\/([A-Za-z0-9-]+)/,
// Return null for an id you do not know: it shows unresolved and saves as written.
toItem: (m) => cache.get(`${m[1]}/${m[2]}`) ?? null,
},
}}
/>Autosave on its own
useRichAutosave lives in its own file and needs nothing from the editor, so it saves any value: a textarea, a form, a title. On a conflict it holds until the person chooses. Keep mine saves again with force: true; Keep theirs calls onKeepTheirs, where you load their copy and call reset with it.
import { useRichAutosave } from "@/components/ui/knowns/rich-editor/rich-autosave";
import { SaveState } from "@/components/ui/knowns/save-state/save-state";
// Any value works: here a plain textarea.
export function NoteField({ id, initial }: { id: string; initial: { text: string; version: number } }) {
const [text, setText] = useState(initial.text);
const version = useRef(initial.version);
const autosave = useRichAutosave(
text,
async (value, signal, { force }) => {
const res = await fetch(`/api/notes/${id}`, {
method: "PUT",
signal,
body: JSON.stringify({ text: value, baseVersion: force ? null : version.current }),
});
if (res.status === 409) return { conflict: (await res.json()).editedBy };
version.current = (await res.json()).version;
},
{
onKeepTheirs: async () => {
const theirs = await (await fetch(`/api/notes/${id}`)).json();
version.current = theirs.version;
setText(theirs.text);
autosave.reset(theirs.text);
},
},
);
return (
<>
<textarea value={text} onChange={(e) => setText(e.target.value)} />
<SaveState {...autosave.props} />
</>
);
}What it handles
- 01Writes like a document: three heading levels, bold, italic, underline, strike, inline code, links, three list kinds, quotes, code with colour, images, tables, alignment and a divider.
- 02Keeps one toolbar tab stop with arrow keys inside, shows what is on at the caret, and moves whole groups into More when the bar is narrow.
- 03Opens a block menu when you type /, filtered as you type and run from the keyboard: headings, lists, to-do, quote, code, table, image, three callouts and a divider.
- 04Puts marks, link and Ask AI over a selection. Ask AI rewrites, shortens, translates or changes the tone through your callback, and shows the answer as a word diff to accept or discard.
- 05Moves blocks by their gutter handle or with Alt+Shift+arrows, and offers turn into, duplicate and delete on the handle's menu. Every move is read out.
- 06Follows Markdown as you type: # for a heading, - or 1. for a list, [ ] for a to-do, > for a quote, ``` for code, --- for a divider. Callouts are GitHub alerts (> [!NOTE], [!TIP], [!WARNING]) in and out.
States
- First render
- The document paints as it is
- none
- A menu, the bubble or the link panel opens
- It fades in
- 120ms, ease out
- Ask AI is working
- The text it will replace stays tinted; Stop aborts the request
- none
- The answer arrives
- A word diff with Accept, Discard and Try again; focus moves to Accept
- 120ms fade
- @ or [[ typed
- A list of people or links opens under the caret, filtered as you type
- 120ms fade
- Autosave
- Save State goes Saving, then Saved with the time; a failure keeps the edits and offers Retry
- Save State's own
- A ref your lookup does not know
- An unresolved chip: muted, dashed hairline, opens nothing, saves as written
- none
- Dragging a block
- The block dims and a line shows where it lands
- 120ms
- Toolbar states
- A pressed tool tints at once
- none
- Narrow
- Groups move into More, a whole group at a time
- none
- Read only
- No toolbar, the text stays selectable
- none
- Reduced motion
- Menus appear and go at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | The document paints as it is | none |
| A menu, the bubble or the link panel opens | It fades in | 120ms, ease out |
| Ask AI is working | The text it will replace stays tinted; Stop aborts the request | none |
| The answer arrives | A word diff with Accept, Discard and Try again; focus moves to Accept | 120ms fade |
| @ or [[ typed | A list of people or links opens under the caret, filtered as you type | 120ms fade |
| Autosave | Save State goes Saving, then Saved with the time; a failure keeps the edits and offers Retry | Save State's own |
| A ref your lookup does not know | An unresolved chip: muted, dashed hairline, opens nothing, saves as written | none |
| Dragging a block | The block dims and a line shows where it lands | 120ms |
| Toolbar states | A pressed tool tints at once | none |
| Narrow | Groups move into More, a whole group at a time | none |
| Read only | No toolbar, the text stays selectable | none |
| Reduced motion | Menus appear and go at once | 0ms |
Works with
- Media LibraryThe image picker the toolbar opens.
- Prompt EditorThe same Tiptap stack, for prompts with variables.
- Writing AssistantRewrite, shorten or translate the selection, shown as a word diff.
- Save StatePut it in footerStart to say when the document was saved.
- Post EditorA CMS writing page built on it.
When to use
When to use
- Writing a document, an article, a wiki page or a long comment with headings, lists, links, code, images and tables, stored as Markdown, HTML or JSON.
When not to use
- A prompt with {{variables}} and a token count: use Prompt Editor.
- A short message to send: use Chat Composer.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Rich Editor to my app and wire it to my own data.
- I need writing a document, an article, a wiki page or a long comment with headings, lists, links, code, images and tables, stored as Markdown, HTML or JSON. Set that up with the Knowns UI Rich Editor.
- Which Rich Editor props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "rich-editor" }) and search_docs({ query: "rich editor" }). Pro props, full examples and source come back once your license key is in the MCP config.