@usememos/editor 26.10.14 → 26.10.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ A block editor for Markdown, for React or any web app.
6
6
  - Block editing: slash menu, a formatting toolbar, Markdown shortcuts, and a block handle on tables, code blocks and images that stand alone, which opens the block menu.
7
7
  - One package, `@usememos/editor`, with zero runtime dependencies. It works without a framework, and `@usememos/editor/react` is a thin React wrapper.
8
8
 
9
- Status: early releases, published to npm as [`@usememos/editor`](https://www.npmjs.com/package/@usememos/editor). Versions follow memos' CalVer (`26.10`, `26.10.1`) and do not signal breaking changes, so pin an exact version. [docs/syntax.md](docs/syntax.md) specifies the Markdown it reads and writes, and [docs/architecture.md](docs/architecture.md) explains how it works.
9
+ Status: early releases, published to npm as [`@usememos/editor`](https://www.npmjs.com/package/@usememos/editor). Versions follow memos' CalVer (`26.10.0`, `26.10.1`) and do not signal breaking changes, so pin an exact version. [docs/syntax.md](docs/syntax.md) specifies the Markdown it reads and writes, and [docs/architecture.md](docs/architecture.md) explains how it works.
10
10
 
11
11
  ## Use it
12
12
 
@@ -54,6 +54,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
54
54
  | `placeholder` | `string` | Shown when the document is empty. |
55
55
  | `editable` | `boolean` | Default `true`. With `false`, no editing, and links open on click. |
56
56
  | `taskToggle` | `boolean` | Default `false`. While `editable` is `false`, lets the user tick and untick task items, for example for a memo's owner. Each tick emits `change` with Markdown in which only that item's `[ ]` or `[x]` changed. Ignored while `editable` is `true`. |
57
+ | `mode` | `'rich' \| 'source'` | Default `'rich'`. `'source'` shows the whole document as its Markdown text, for people who prefer to edit the text itself. Switching changes no text, emits no `change` and keeps undo history. See [Source mode](#source-mode). |
57
58
  | `autofocus` | `boolean \| 'start' \| 'end'` | Focuses the editor on creation, with the caret at the start or the end. |
58
59
  | `attributes` | `Record<string, string>` | Attributes for the editable root, such as `autocorrect`, `autocapitalize` or `aria-label`. |
59
60
  | `resolveUrl` | `(url, kind) => string \| null` | The URL to use for a link (`kind` `'link'`) or an image (`'image'`), or `null` to drop it: the link is not clickable, the image has no `src`. The saved Markdown keeps the original. Default `defaultResolveUrl`, exported: relative URLs, `http`, `https`, `mailto` and `tel`. Call it from your own policy to extend it, for example to allow `sms:` or to block `http:` images. |
@@ -68,7 +69,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
68
69
  | `slashMenu` | `false \| string[]` | Built-in slash menu items to show, in order, or `false` for none: `text`, `heading1`, `heading2`, `heading3`, `heading4`, `bulletList`, `numberedList`, `todoList`, `quote`, `callout`, `details`, `code`, `table`, `divider`. |
69
70
  | `slashHint` | `boolean` | Shows `labels.slashHint` ("Type '/' for commands") in the empty paragraph that has the caret. Default `false`. No effect when `slashMenu` is `false`. When the document is a single empty paragraph, `placeholder` shows instead. |
70
71
  | `labels` | `Partial<Labels>` | Overrides UI strings, for localization. See `src/labels.ts`. |
71
- | `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout titles and the callout menu), `openLink`, `copyLink`, `editLink` and `removeLink` (the link card), `imageAlignLeft`, `imageAlignCenter` and `imageAlignRight` (an image block's Align choices), `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
72
+ | `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout icons and the callout menu), `openLink`, `copyLink`, `editLink` and `removeLink` (the link card), `imageAlignLeft`, `imageAlignCenter` and `imageAlignRight` (an image block's Align choices), `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
72
73
  | `onChange` | `(markdown: string, editor) => void` | Called after document changes, at most once per animation frame. |
73
74
  | `onSubmit` | `(markdown: string, editor) => void` | Called on Mod+Enter or Ctrl+Enter with the current Markdown, for comment boxes and chat inputs. |
74
75
  | `onFocus`, `onBlur` | `(editor) => void` | Focus events. |
@@ -76,9 +77,9 @@ The same names work in `new Editor(options)` and as React props, except that Rea
76
77
 
77
78
  For note-style Markdown, as in the playground, use `markdown: { breaks: true, setext: false }` and `extensions: [math(), footnotes(), tags(), mentions()]`.
78
79
 
79
- `editor.setOptions({ placeholder, editable, taskToggle, attributes, resolveUrl, onLinkClick, theme })` changes those options while the editor runs. `setOptions({ extensions })` takes new callbacks for `suggestion()` extensions of the same names. The other options are fixed for the editor's lifetime.
80
+ `editor.setOptions({ placeholder, editable, taskToggle, mode, attributes, resolveUrl, onLinkClick, theme })` changes those options while the editor runs. `setOptions({ extensions })` takes new callbacks for `suggestion()` extensions of the same names. The other options are fixed for the editor's lifetime.
80
81
 
81
- In React, `placeholder`, `editable`, `taskToggle`, `attributes`, `resolveUrl`, `onLinkClick` and `theme` update live. A change to the names in `extensions` recreates the editor and keeps its Markdown, so an inline array is fine; with the same names, the callbacks of `suggestion()` extensions update live, so `items` may read React state. Other props are read on mount; change the component's `key` to apply new values. A `ref` gives the core `Editor` instance. A `value` that arrives while an input method (IME) is composing text is applied when the composition ends.
82
+ In React, `placeholder`, `editable`, `taskToggle`, `mode`, `attributes`, `resolveUrl`, `onLinkClick` and `theme` update live. A change to the names in `extensions` recreates the editor and keeps its Markdown, so an inline array is fine; with the same names, the callbacks of `suggestion()` extensions update live, so `items` may read React state. Other props are read on mount; change the component's `key` to apply new values. A `ref` gives the core `Editor` instance. A `value` that arrives while an input method (IME) is composing text is applied when the composition ends.
82
83
 
83
84
  For apps that manage the editor instance themselves, `useEditor(options, deps)` creates one and `<EditorContent editor={editor} />` shows it:
84
85
 
@@ -101,8 +102,8 @@ function Composer() {
101
102
  | `state` | The document and selection, immutable. |
102
103
  | `commands.*` | Edits. Each applies one change, records one undo step, and returns `true` if it did something: `toggleBold`, `toggleItalic`, `toggleStrike`, `toggleCode`, `setParagraph`, `toggleHeading({ level })`, `toggleBulletList`, `toggleOrderedList`, `toggleTaskList`, `toggleBlockquote`, `toggleCallout({ type? })`, `setCallout({ type })`, `toggleDetails`, `toggleCodeBlock({ language? })`, `setLink({ href })`, `unsetLink`, `updateImage({ alt?, title?, align?, width? })`, `insertText(text, { range? })`, `insertMarkdown(markdown, options?)`, `insertTable({ rows?, cols? })`, `insertDivider`, `indent`, `outdent`, `undo`, `redo`, `selectAll`, `selectBlocks`, `focus(position?)`, `blur`, `scrollIntoView`. `selectBlocks` selects the blocks the selection touches as whole blocks, as Escape does; it returns `false` when read-only. `updateImage` changes the selected image; `null` removes its title, alignment or width, and a new width drops a height so the image keeps its aspect ratio. `toggleCallout` turns the selected blocks into a callout (`note` unless `type` says otherwise: `note`, `tip`, `important`, `warning` or `caution`), or back into paragraphs. `setCallout` changes the type of the whole callout or quote with the caret; `type: null` makes it a plain quote. `toggleDetails` makes the block with the caret the title of a collapsible section, or, on a title, removes the section and keeps its blocks. `toggleCallout`, `setCallout` and `toggleDetails` return `false` when the `markdown` option turns that syntax off. `scrollIntoView` changes nothing in the document: it scrolls the caret into view in the editor's scrolling containers and the window, for example after an `insertMarkdown` from code. |
103
104
  | `run(fn)` | Applies a custom command: a function from state to a new state, or `null`. The pure commands are exported as `commands` from the package. |
104
- | `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, `image` (the selection is exactly one image), or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote`, `details` (a collapsible section's title or end), `codeBlock`, `table`, `divider`, `raw`. `attrs` narrows it, for example `isActive('heading', { level: 2 })`. |
105
- | `getAttributes(name)` | `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) of the selected image, `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block, `callout` of a callout (`getAttributes('blockquote')`), `open` (saved open) and `collapsed` (shown collapsed) of a collapsible section title (`getAttributes('details')`). |
105
+ | `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, `image` (the selection is exactly one image), or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote` (also true in a list inside a quote), `details` (a collapsible section's title or end), `codeBlock`, `table`, `divider`, `raw`. `attrs` narrows it, for example `isActive('heading', { level: 2 })`. |
106
+ | `getAttributes(name)` | `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) of the selected image, `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block, `callout` of a callout (`getAttributes('blockquote')`, also in a list item inside a callout), `open` (saved open) and `collapsed` (shown collapsed) of a collapsible section title (`getAttributes('details')`). |
106
107
  | `setSectionCollapsed(blockId, collapsed)`, `isSectionCollapsed(blockId)` | Collapse or expand the collapsible section whose title is `blockId`, or read whether it is collapsed. This changes the view only, not the Markdown or the history. `setSectionCollapsed` returns `false` when the block is not a section title. |
107
108
  | `selectedBlocks` | The blocks of a block selection, in document order, or an empty array when the selection is text. |
108
109
  | `getSelection()`, `setSelection(selection)` | Read or move the selection. `setSelection` also takes a `SelectionJSON`, and clamps one that does not fit the document. |
@@ -116,6 +117,7 @@ function Composer() {
116
117
  | `root` | The editable element: `element`, or for `useEditor`, the element `<EditorContent>` shows. |
117
118
  | `isComposing` | True while an input method (IME) is composing text. Replacing the document then would break the composition; the React wrapper waits for it to end. |
118
119
  | `destroy()`, `isDestroyed` | Removes the editor's content, listeners and popups from the page. After it, every call that would change the editor does nothing and commands return `false`, so a late callback (an upload that finishes after the editor closed) is safe. `getMarkdown()` still returns the last Markdown. |
120
+ | `mode` | `'rich'` or `'source'`: the mode the editor shows now. See [Source mode](#source-mode). |
119
121
  | `hasFocus()`, `focus()`, `blur()`, `isEditable`, `setOptions(options)` | |
120
122
 
121
123
  `insertMarkdown(markdown, { at, block, select })`: `at` is `'selection'` (default; replaces the selection, like a paste), `'end'`, a position, or a widget; the last three replace nothing. A single paragraph is inserted inline unless `block: true`, which inserts it as its own block and splits the block at the target. `select: 'keep'` keeps the current selection instead of moving the caret after the inserted content.
@@ -265,7 +267,7 @@ new Editor({
265
267
  });
266
268
  ```
267
269
 
268
- Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `border`, `popupBackground`, `popupBorder`, `hover`, `danger`, and `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (each callout type's border and title); the other tokens are `font`, `mono`, `fontSize`, `lineHeight`, `radius` and `blockGap` (numbers are pixels). Values can be any CSS, such as `var(--primary)`, so the editor can follow your app's own variables. Menus, the toolbar and the link popover take the same tokens.
270
+ Colors are `text`, `muted`, `background`, `accent`, `link`, `codeBackground`, `border`, `popupBackground`, `popupBorder`, `hover`, `danger`, and `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (each callout type's icon, and a light tint of it behind the text); the other tokens are `font`, `mono`, `fontSize`, `lineHeight`, `radius` and `blockGap` (numbers are pixels). Values can be any CSS, such as `var(--primary)`, so the editor can follow your app's own variables. Menus, the toolbar and the link popover take the same tokens.
269
271
 
270
272
  `colorScheme` picks light or dark: `auto` (the default) follows `prefers-color-scheme`, or `data-theme="light"` or `data-theme="dark"` on the editor or an ancestor; `light` and `dark` force one; `inherit` follows the page's `color-scheme`, for apps that switch it themselves. Switching tokens or the scheme with `setOptions({ theme })` re-renders nothing.
271
273
 
@@ -287,7 +289,7 @@ new Editor({
287
289
  });
288
290
  ```
289
291
 
290
- Keys use the names of `isActive`: `paragraph`, `heading` (by level), `blockquote`, `bulletList`, `orderedList` and `taskList` (each list item; blocks are flat, so there is no list element), `codeBlock`, `table`, `divider` (the `<hr>`), `raw`, `image`, `bold`, `italic`, `strike`, `code`, `link`, and `token` (inline tokens of an extension syntax, by name). Extensions can add classes too; the editor's own `theme` wins for the same key. `setOptions({ theme })` changes them while the editor runs.
292
+ Keys use the names of `isActive`: `paragraph`, `heading` (by level), `blockquote`, `bulletList`, `orderedList` and `taskList` (each list item; blocks are flat, so there is no list element; an item in a quote also gets the `blockquote` classes), `codeBlock`, `table`, `divider` (the `<hr>`), `raw`, `image`, `bold`, `italic`, `strike`, `code`, `link`, and `token` (inline tokens of an extension syntax, by name). Extensions can add classes too; the editor's own `theme` wins for the same key. `setOptions({ theme })` changes them while the editor runs.
291
293
 
292
294
  To style the editor entirely with your own classes, import `@usememos/editor/base.css` instead of `style.css`. Spacing between blocks stays in `base.css`, and its rules are more specific than a single class, so margins in your classes do not change it.
293
295
 
@@ -317,6 +319,8 @@ To style the editor entirely with your own classes, import `@usememos/editor/bas
317
319
 
318
320
  With blocks selected: ArrowUp and ArrowDown select the block above or below, Shift extends the selection, Mod+A selects every block, Backspace and Delete delete them, Mod+C, Mod+X and paste copy, cut and replace them as whole blocks, Mod+D duplicates them, and the block type keys, Tab and the mark keys apply to all of them. Enter, ArrowLeft and ArrowRight go back to editing text. Typing does nothing. See [Block selection](docs/architecture.md#block-selection).
319
321
 
322
+ In source mode the formatting keys do nothing and Enter inserts a line break; see [Source mode](#source-mode).
323
+
320
324
  Markdown shortcuts at the start of a line: `#`–`######`, `-`, `*`, `+`, `1.`, `[ ]`, `[x]`, `>`, `[!note]` and the other callout types, `>>>` (collapsible section), ` ``` `, `---`. Inline: `**bold**`, `*italic*`, `_italic_`, `` `code` ``, `~~strike~~`.
321
325
 
322
326
  ## Images
@@ -336,7 +340,7 @@ A callout is a quote with a type, saved as a [GitHub alert](https://docs.github.
336
340
  > Back up your data first.
337
341
  ```
338
342
 
339
- The types are Note, Tip, Important, Warning and Caution. A callout shows its type's icon and name above the text, with the type's color on its border. Make one with Callout in the slash menu (a Note), or type `[!tip] ` at the start of a paragraph or a quote. Enter adds a line to the callout; Enter on an empty line ends it. Clicking the title, or Mod+/ inside the callout, opens its menu: the five types, and Delete for the whole callout. Pasting an alert copied from a GitHub page keeps it a callout. Renderers without alert support, including CommonMark, show a plain quote whose first line is `[!WARNING]`.
343
+ The types are Note, Tip, Important, Warning and Caution. A callout is a softly tinted box in its type's color, with the type's icon beside the first line; the type's name is the icon's accessible label. Make one with Callout in the slash menu (a Note), or type `[!tip] ` at the start of a paragraph or a quote. Enter adds a line to the callout; Enter on an empty line ends it. Callouts and quotes can hold lists: type `- `, `1. ` or `[ ] ` at the start of a line in one. Clicking the icon, or Mod+/ inside the callout, opens its menu: the five types, and Delete for the whole callout. Pasting an alert copied from a GitHub page keeps it a callout. Renderers without alert support, including CommonMark, show a plain quote whose first line is `[!WARNING]`.
340
344
 
341
345
  ## Collapsible sections
342
346
 
@@ -358,11 +362,45 @@ Make one with Collapsible section in the slash menu, Mod+Shift+6, or `>>> ` at t
358
362
 
359
363
  Only a `<details>` written the way the editor saves it loads as a section: the opening tag and a `<summary>` of plain text, a blank line, Markdown, and `</details>` at the start of a line. Other `<details>`, such as one on a single line, stay raw HTML.
360
364
 
365
+ ## Source mode
366
+
367
+ With `mode: 'source'`, the editor shows the whole document as Markdown text, as Obsidian's source mode and GitLab's plain text editor do. The editor has no button or key for it: the app switches with `setOptions({ mode })` or the React `mode` prop, and remembers the choice if it wants to.
368
+
369
+ ```tsx
370
+ <MarkdownEditor value={markdown} onChange={setMarkdown} mode={showSource ? 'source' : 'rich'} />
371
+ ```
372
+
373
+ **Switching** is a change of view, not an edit. The text shown in source mode is exactly `getMarkdown()`. Going back to rich mode loads the text as `setMarkdown` does, so `getMarkdown()` returns it byte for byte, including lines edited in source mode. A switch emits no `change`, adds no undo step and does not move focus. Undo and redo work across it: undoing an edit made in the other mode restores it in the current mode. The caret stays in the same block, and keeps its column when the text before it in that block has no Markdown syntax; otherwise it goes to the start of the block's text. A switch requested while an input method is composing waits for the composition to end.
374
+
375
+ **What works in source mode.** Source mode is plain text editing, like a `<textarea>` or a code block. It has no autocomplete and no formatting keys.
376
+
377
+ | | |
378
+ | --- | --- |
379
+ | Typing, deleting, input methods, spellcheck | As in a code block |
380
+ | Enter | Inserts a line break |
381
+ | Tab, Shift+Tab | As in a code block: Tab inserts two spaces, or indents the selected lines by two spaces. Shift+Tab removes up to two spaces (or a tab) from the start of those lines |
382
+ | Paste | The clipboard's plain text (`text/plain`). Files go to `fileHandler` as in rich mode |
383
+ | Copy and cut | The selected text, as `text/plain` |
384
+ | Mod+Enter, undo, redo, Mod+A | As in rich mode |
385
+ | Escape | Leaves the editor |
386
+ | Formatting keys (Mod+B, Mod+I, Mod+E, Mod+Shift+X, Mod+Alt+0–4, Mod+Alt+C, Mod+Shift+6–9) | Do nothing. Mod+K is left to the app |
387
+ | Markdown shortcuts, autolinks | Do not run: the text is the Markdown |
388
+ | Autocomplete | Off. `suggestion()` popups, the slash menu and Ctrl+Space do not open |
389
+ | `fileHandler`, `handlePaste`, `handleDrop`, extension key bindings | As in rich mode |
390
+ | `commands.*` | `insertText` and `insertMarkdown` insert the text as written; `insertMarkdown` with `block: true` puts it on lines of its own. `indent`, `outdent`, `undo`, `redo`, `selectAll`, `focus`, `blur` and `scrollIntoView` work. The mark, block type, link, image, table, divider, callout, section and `selectBlocks` commands return `false` |
391
+ | Placeholder | Shown when the text is empty |
392
+ | `addWidget` | Shown below the text. A widget remembers its place in the text, which moves with edits before it, and `insertMarkdown(md, { at: widget })` inserts there |
393
+ | `editable: false` | The text is read-only and can be selected and copied. `taskToggle` has no effect |
394
+
395
+ The toolbar, slash menu, autocomplete popup, block handle, block menu, link card, rendered views, decorations, images and syntax highlighting do not show. `isActive()` returns `false` and `getAttributes()` returns `{}`.
396
+
397
+ **Positions.** In source mode the document is one block that holds all the text, so a `Position` names that block and its `offset` counts UTF-16 code units of the Markdown. `getSelection`, `setSelection`, `selectionToJSON` and `insertText({ range })` use that shape. A selection saved in the other mode is clamped.
398
+
361
399
  ## What saving changes
362
400
 
363
401
  Blocks you did not edit are saved exactly as they were loaded, byte for byte, including the blank lines between them. `getMarkdown()` right after loading returns the input unchanged.
364
402
 
365
- Blocks you edited, and new blocks, are written in a normalized style: `*` for italic, `**` for bold, `-` for bullets, ATX headings, fenced code, tight lists, renumbered ordered lists, and inline links instead of reference links. Soft line breaks become spaces, unless `markdown.breaks` is on. Structure the editor cannot edit as blocks (a list inside a quote, a code block or second paragraph inside a list item, lists nested more than five levels) is kept as a raw block: the original Markdown, shown and edited as source, saved verbatim. Math and footnote blocks from the extensions are raw blocks too.
403
+ Blocks you edited, and new blocks, are written in a normalized style: `*` for italic, `**` for bold, `-` for bullets, ATX headings, fenced code, tight lists, renumbered ordered lists, and inline links instead of reference links. Soft line breaks become spaces, unless `markdown.breaks` is on. Structure the editor cannot edit as blocks (a code block or heading inside a quote, a code block or second paragraph inside a list item, lists nested more than five levels) is kept as a raw block: the original Markdown, saved verbatim. It shows rendered, and its source shows for editing when the caret is in it or it is clicked. Math and footnote blocks from the extensions are raw blocks too.
366
404
 
367
405
  ## Develop
368
406
 
package/dist/base.css CHANGED
@@ -56,16 +56,46 @@
56
56
  :is(.mbe-root, .mbe-flow) > h3.mbe-block { margin-top: 20px; margin-bottom: 6px; }
57
57
  :is(.mbe-root, .mbe-flow) > :is(h4, h5, h6).mbe-block { margin-top: 16px; margin-bottom: 4px; }
58
58
 
59
- /* Quote: the renderer marks a quote block that follows another (see
60
- updateNeighborMarks). The negative margin cancels the gap, and padding
61
- keeps a border unbroken, so consecutive quote blocks read as one quote. */
62
- :is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] { margin-top: calc(-1 * var(--mbe-block-gap)); padding-top: var(--mbe-block-gap); }
59
+ /* Quote: the renderer marks a quote block that follows another of the same
60
+ quote, and one followed by another (see updateNeighborMarks). Margins are
61
+ 0 between the parts of a quote and padding makes the space, so the border
62
+ stays unbroken and consecutive quote blocks read as one quote. A list in a
63
+ quote is a run of blockquote list items (see renderBlock): its items sit
64
+ 2px apart, as outside quotes, with the gap around the list. */
65
+ :is(.mbe-root, .mbe-flow) > blockquote[data-quote-continued] { margin-bottom: 0; }
66
+ :is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] { margin-top: 0; padding-top: var(--mbe-block-gap); }
67
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-quote-joined] { margin-top: 0; }
68
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-quote-joined]:not([data-list-start]) { padding-top: 2px; }
63
69
 
64
- /* Callouts: a title with the type's icon and name above the text. Only the
65
- first block of a callout shows it. Clicking it opens the type menu. */
66
- .mbe-root .mbe-callout-title { display: flex; align-items: center; gap: 8px; user-select: none; -webkit-user-select: none; }
67
- :is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] > .mbe-callout-title { display: none; }
68
- .mbe-root:not(.mbe-readonly) > blockquote > .mbe-callout-title { cursor: pointer; }
70
+ /* Callouts: a padded box with the type's icon in a start column, level with
71
+ the first line. Only the first block of a callout shows the icon; the
72
+ renderer marks a block followed by another of the callout with
73
+ data-quote-continued, so the box pads only its first and last lines.
74
+ Clicking the icon opens the type menu. */
75
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout] {
76
+ --mbe-callout-pad: 12px;
77
+ position: relative;
78
+ padding-block: var(--mbe-callout-pad);
79
+ padding-inline: calc(var(--mbe-callout-pad) + 28px) 16px;
80
+ }
81
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout][data-quote-joined] { padding-top: var(--mbe-block-gap); }
82
+ :is(.mbe-root, .mbe-flow) > blockquote[data-callout][data-quote-continued] { padding-bottom: 0; }
83
+ .mbe-root .mbe-callout-icon {
84
+ position: absolute;
85
+ top: var(--mbe-callout-pad);
86
+ inset-inline-start: calc(var(--mbe-callout-pad) - 2px);
87
+ display: flex;
88
+ align-items: center;
89
+ justify-content: center;
90
+ width: 24px;
91
+ height: 1.5em;
92
+ height: 1lh;
93
+ user-select: none;
94
+ -webkit-user-select: none;
95
+ }
96
+ .mbe-root .mbe-callout-icon > .mbe-icon { width: 18px; height: 18px; }
97
+ :is(.mbe-root, .mbe-flow) > blockquote[data-quote-joined] > .mbe-callout-icon { display: none; }
98
+ .mbe-root:not(.mbe-readonly) > blockquote > .mbe-callout-icon { cursor: pointer; }
69
99
 
70
100
  /* Collapsible sections: the title has a toggle in the indent column, and the
71
101
  blocks inside are indented by one step per section around them (see
@@ -112,11 +142,17 @@
112
142
  }
113
143
  :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-list-start] { margin-top: var(--mbe-block-gap); }
114
144
  /* Attribute rules instead of an inline custom property, so list items share computed styles. */
115
- :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='1'] { padding-inline-start: var(--mbe-indent-size); }
116
- :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='2'] { padding-inline-start: calc(2 * var(--mbe-indent-size)); }
117
- :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='3'] { padding-inline-start: calc(3 * var(--mbe-indent-size)); }
118
- :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='4'] { padding-inline-start: calc(4 * var(--mbe-indent-size)); }
119
- :is(.mbe-root, .mbe-flow) > .mbe-list-item[data-indent='5'] { padding-inline-start: calc(5 * var(--mbe-indent-size)); }
145
+ :is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='1'] { padding-inline-start: var(--mbe-indent-size); }
146
+ :is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='2'] { padding-inline-start: calc(2 * var(--mbe-indent-size)); }
147
+ :is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='3'] { padding-inline-start: calc(3 * var(--mbe-indent-size)); }
148
+ :is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='4'] { padding-inline-start: calc(4 * var(--mbe-indent-size)); }
149
+ :is(.mbe-root, .mbe-flow) > div.mbe-list-item[data-indent='5'] { padding-inline-start: calc(5 * var(--mbe-indent-size)); }
150
+ /* In a quote the item's padding is the quote's, so the marker takes the indent. */
151
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='1'] > .mbe-marker { margin-inline-start: var(--mbe-indent-size); }
152
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='2'] > .mbe-marker { margin-inline-start: calc(2 * var(--mbe-indent-size)); }
153
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='3'] > .mbe-marker { margin-inline-start: calc(3 * var(--mbe-indent-size)); }
154
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='4'] > .mbe-marker { margin-inline-start: calc(4 * var(--mbe-indent-size)); }
155
+ :is(.mbe-root, .mbe-flow) > blockquote.mbe-list-item[data-indent='5'] > .mbe-marker { margin-inline-start: calc(5 * var(--mbe-indent-size)); }
120
156
  .mbe-root .mbe-marker {
121
157
  flex: none;
122
158
  box-sizing: border-box;
@@ -198,6 +234,8 @@
198
234
  }
199
235
  :is(.mbe-root, .mbe-flow) > .mbe-code pre,
200
236
  :is(.mbe-root, .mbe-flow) > pre.mbe-raw { white-space: pre-wrap; tab-size: 2; }
237
+ /* Source mode: the document as plain text in the editor's font. */
238
+ .mbe-root > .mbe-source { white-space: pre-wrap; tab-size: 4; overflow-wrap: anywhere; }
201
239
  :is(.mbe-root, .mbe-flow) > .mbe-code pre { margin: 0; }
202
240
  :is(.mbe-root, .mbe-flow) > .mbe-code pre code { display: block; }
203
241
 
@@ -253,16 +291,18 @@
253
291
  .mbe-root .mbe-empty-content { position: relative; }
254
292
  .mbe-root > .mbe-paragraph.mbe-empty:only-child::before,
255
293
  .mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before,
256
- .mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
294
+ .mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote:not(.mbe-list-item))::before,
257
295
  .mbe-root:not(.mbe-readonly) > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before,
258
- .mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before {
296
+ .mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before,
297
+ .mbe-root > .mbe-source.mbe-empty:only-child > .mbe-source-text::before {
259
298
  opacity: 0.5;
260
299
  pointer-events: none;
261
300
  position: absolute;
262
301
  }
263
- .mbe-root > .mbe-paragraph.mbe-empty:only-child::before { content: var(--mbe-placeholder, ''); }
302
+ .mbe-root > .mbe-paragraph.mbe-empty:only-child::before,
303
+ .mbe-root > .mbe-source.mbe-empty:only-child > .mbe-source-text::before { content: var(--mbe-placeholder, ''); }
264
304
  .mbe-root > .mbe-paragraph.mbe-empty.mbe-show-hint::before { content: var(--mbe-slash-hint, ''); }
265
- .mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote)::before,
305
+ .mbe-root:not(.mbe-readonly) > .mbe-empty[data-hint]:is(h1, h2, h3, h4, h5, h6, blockquote:not(.mbe-list-item))::before,
266
306
  .mbe-root:not(.mbe-readonly) > .mbe-list-item.mbe-empty[data-hint] > .mbe-content::before,
267
307
  .mbe-root:not(.mbe-readonly) > .mbe-details.mbe-empty[data-hint] > .mbe-content::before { content: attr(data-hint); }
268
308