TipTap Customization Guide
Extending and customizing the TipTap-based Rich Text Editor
Overview
The Rich Text Editor is a core component: frontend/src/components/RichTextEditor.tsx in studiobrain-core. It is used by the document editor (DocumentEditPage.tsx) and the unified entity field builder. Cloud and the desktop/mobile clients consume it through the pinned @biloxistudios/studiobrain-core-frontend package.
Because core is consumed as one pinned dependency, do not edit the editor in this repo’s tree. Editor changes are a core-repo PR; the monorepo then refreshes its pin.
What ships today
The editor uses TipTap v3 (@tiptap/react, @tiptap/starter-kit) with these extensions:
| Extension | Package |
|---|---|
StarterKit (bullet and ordered lists configured with keepMarks: true) | @tiptap/starter-kit |
| Placeholder | @tiptap/extension-placeholder |
Link (openOnClick: false) | @tiptap/extension-link |
| Image | @tiptap/extension-image |
| Underline | @tiptap/extension-underline |
TextStyle and Color (types: ['textStyle']) | @tiptap/extension-text-style, @tiptap/extension-color |
Tables, task lists, mentions, collaboration and entity references are not part of the editor. Anything below that uses them is an example of how you would add them, not existing behaviour.
Component props (RichTextEditorProps): value, onChange, placeholder, readOnly, onSave, onImportMarkdown, autoSave (default true), autoSaveDelay (default 1000 ms). The toolbar is built from the local ToolbarButton and ToolbarDivider helpers in the same file.
Adding a custom extension
Step 1: Install the package
Install official TipTap extensions at the same major version as the rest of the editor (v3):
npm install @tiptap/extension-table @tiptap/extension-highlightStep 2: Write the extension
A custom inline node for an entity reference, using @tiptap/core (TipTap v3 re-exports the ProseMirror classes it needs, so no direct prosemirror-* import is required for this):
import { Node, mergeAttributes } from '@tiptap/core';
declare module '@tiptap/core' {
interface Commands<ReturnType> {
entityReference: {
insertEntityReference: (entityId: string, entityType: string) => ReturnType;
};
}
}
export const EntityReference = Node.create({
name: 'entityReference',
group: 'inline',
inline: true,
atom: true,
addAttributes() {
return {
entityId: { default: null },
entityType: { default: null },
};
},
parseHTML() {
return [{ tag: 'span[data-entity-reference]' }];
},
renderHTML({ HTMLAttributes }) {
return [
'span',
mergeAttributes(HTMLAttributes, {
'data-entity-reference': '',
class: 'entity-reference',
}),
`${HTMLAttributes.entityType}:${HTMLAttributes.entityId}`,
];
},
addCommands() {
return {
insertEntityReference:
(entityId, entityType) =>
({ commands }) =>
commands.insertContent({
type: this.name,
attrs: { entityId, entityType },
}),
};
},
});Step 3: Register it
Add the extension to the extensions array passed to useEditor in RichTextEditor.tsx (in core):
const editor = useEditor({
extensions: [
StarterKit.configure({ /* ... */ }),
EntityReference,
// existing extensions...
],
// ...
});Step 4: Add a toolbar button
<ToolbarButton
onClick={() => editor.chain().focus().insertEntityReference('rex_marshall', 'character').run()}
title="Insert Entity Reference"
>
<LinkIcon className="w-4 h-4" />
</ToolbarButton>insertTable() and toggleTaskList() only exist after you register the table and task-list extensions.
Custom keyboard shortcuts
Shortcuts belong on the extension (addKeyboardShortcuts() inside Extension.create/Node.create), not in the useEditor options:
import { Extension } from '@tiptap/core';
export const EntityShortcuts = Extension.create({
name: 'entityShortcuts',
addKeyboardShortcuts() {
return {
'Mod-Shift-e': () => this.editor.commands.insertEntityReference('rex_marshall', 'character'),
};
},
});Styling
The editor root gets the classes prose prose-sm max-w-none focus:outline-none min-h-[200px] p-4 through editorProps.attributes, and the toolbar uses the semantic surface classes (for example text-surface-elevated-text-secondary, border-surface-elevated-border). Surface colours are CSS variables defined in core’s frontend/src/app/globals.css (--surface-elevated-bg, --surface-elevated-text, --surface-elevated-border, --surface-primary-bg, --surface-primary-hover, --surface-primary-border, and others). Light values live on :root; dark values are overridden in the dark theme block of the same file.
Core’s stylesheet has no dedicated .ProseMirror rules. To style editor content, add your own rules that reference the surface variables:
.ProseMirror a {
color: var(--surface-primary-bg);
text-decoration: underline;
}
.ProseMirror blockquote {
border-left: 4px solid var(--surface-primary-border);
padding-left: 1rem;
font-style: italic;
}
.entity-reference {
display: inline-flex;
padding: 0.125rem 0.375rem;
border-radius: 0.25rem;
background-color: var(--surface-primary-bg);
cursor: pointer;
}Because the variables switch with the active theme, rules written this way follow dark mode automatically. For the full colour system see Theme Customization.
Content handling
getHTML() returns the editor content and is what onChange receives. getText() returns plain text; the editor uses it for its word and character counters. The built-in markdown export is a small regex-based HTML-to-Markdown conversion in the component, so complex content (tables, nested lists) is not guaranteed to round-trip. Imported markdown is passed to the onImportMarkdown prop.
Commands
Commands used by the existing toolbar come from the registered extensions, for example:
editor.chain().focus().toggleBold().run();
editor.chain().focus().toggleHeading({ level: 2 }).run();
editor.chain().focus().toggleBulletList().run();
editor.chain().focus().toggleCodeBlock().run();
editor.chain().focus().toggleBlockquote().run();
editor.chain().focus().setHorizontalRule().run();
editor.chain().focus().setLink({ href: 'https://example.com' }).run();
editor.chain().focus().setImage({ src: 'image.jpg' }).run();
editor.chain().focus().undo().run();
editor.chain().focus().unsetAllMarks().run();Troubleshooting
- A command is not a function. The extension that provides it is not in the
extensionsarray. - A custom node renders as plain text. Check that
parseHTMLandrenderHTMLagree and that the node’sgroup/inlinesettings match where it is inserted. - Styles do not apply. Confirm the selector targets
.ProseMirrorand that the CSS variables are defined for the active theme. - Shortcut does nothing. Make sure it is returned from
addKeyboardShortcuts()on an extension and does not collide with a browser shortcut.
Related Documentation
- Rich Text Editor API - Core component documentation
- Document Outline - Section navigation
- Theme Customization - Color system
- Component Blocks - Layout components