Skip to content

Rich editor

Formatted text over Markdown that stays byte for byte, on a Tiptap surface.

<div data-mount="default"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/rich-editor.css";

Usage

import "capsomer/markdown-editor.css";
import "capsomer/rich-editor.css";
import { RichEditor } from "capsomer/react/rich-editor";

<RichEditor
  ariaLabel="Post, formatted"
  value={markdown}
  onChange={setMarkdown}
  readOnly={false}
  dialect="site"
  linkTargets={[{ href: "/writing/getting-started", title: "Getting started" }]}
  onUpload={(file, image, signal) => upload(file, image, signal)}
/>;

Examples

Markdown it does not format, kept as source blocks

<div data-mount="source"></div>

Read-only

<div data-mount="readonly"></div>

API reference

RichEditor

PropTypeRequiredDoes
ariaLabelstringYesWhat the editing surface is called to a screen reader, for example "Post, formatted".
valuestringYes
onChange(next: string) => voidYes
readOnlybooleanYes
dialectDialectYes
placeholderstring
scaffoldsScaffold[]
linkTargetsLinkTarget[]
onUpload(file: File, image: ImageDescription, signal: AbortSignal) => Promise<{ url: string }>Called once the image is described, as Capsomer's markdown editor calls it.
imageMarkdown(image: { url: string; alt: string; decorative: boolean; name: string; }) => string
acceptstring
onReady(handle: RichEditorHandle) => void
roomRichRoom

CSS variables

VariableDefault
--cap-md-min12rem

Parts and data attributes

ClassIs
.cap-rich-editorthe root
.cap-rich-editor-hosta part
.cap-rich-editor-slota part
.cap-rich-editor-srca part
.cap-rich-editor-src-inlinea part
.cap-rich-editor-src-kinda part
.cap-rich-editor-src-texta part
.cap-rich-editor-surfacea part
AttributeValues
data-frontpresent or absent
data-hide-frontpresent or absent
StateRead from
:focus-visiblethe platform

Accessibility

KeyDoes
TabEnters the toolbar at its one stop, then the text; Tab in the text leaves it
Left arrow, Right arrow, Home, EndMoves between the toolbar's buttons, wrapping
Ctrl or Cmd B, I, EBold, italic or code
Ctrl or Cmd KOpens the link palette, the selection as its query
Down arrow, Up arrow, Enter, Esc (palette)Moves the active page, links it or the typed address, or puts the selection back
/ alone on a line, then Down arrowOpens the block menu, then enters it
EscCloses the link palette, the block menu or the image step
Ctrl or Cmd Z, Ctrl or Cmd Shift ZUndo, redo
  • The text is a textbox, multiline, named by ariaLabel (for example "Post, formatted"), with aria-placeholder. Each source block's textarea is named by its kind ("Table, Markdown").
  • The toolbar is a toolbar named "Formatting"; each button has a name, a tooltip with its key, and aria-keyshortcuts. The palette is a group with a combobox over a listbox; the block menu is a named list of buttons; the image step is a group named "Describe the image", aria-busy while sending, with a status line and an alert on failure.
  • Source blocks are full-size targets (WCAG 2.5.8); the focus ring is --ring at --ring-width.