@mdbase-dev/ui 0.1.0-beta.215 → 0.1.0-beta.218

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.
@@ -3,6 +3,9 @@
3
3
  * Scope it under the editor's own class if an app mixes source and preview editors.
4
4
  */
5
5
 
6
+ /* Formulas (`markdownMath`): KaTeX's layout and fonts. Fonts load only when a formula uses them. */
7
+ @import "katex/dist/katex.min.css";
8
+
6
9
  .cm-lp-mark {
7
10
  color: var(--color-text-faint);
8
11
  }
@@ -370,6 +373,47 @@
370
373
  .cm-lp-code-header button:hover, .cm-lp-callout-header button:hover { background: var(--color-surface); color: var(--color-text); }
371
374
  .cm-lp-code-header button:focus-visible, .cm-lp-callout-header button:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
372
375
 
376
+ .cm-lp-math-source { font-family: var(--mono); font-size: 0.92em; }
377
+ .cm-lp-math-pending, .cm-lp-math-failed { color: var(--color-text-muted); font-family: var(--mono); font-size: 0.92em; white-space: pre-wrap; }
378
+ .cm-lp-math-failed { text-decoration: underline dotted var(--color-danger); }
379
+ .cm-lp-math-block, .cm-lp-math-preview { padding: var(--space-2) 0; overflow-x: auto; overflow-y: hidden; }
380
+ .cm-lp-math-preview { margin-bottom: var(--space-2); padding-inline: var(--space-2); border-radius: var(--radius-md); background: var(--color-surface-subtle); }
381
+ .cm-lp-math-block .katex-display, .cm-lp-math-preview .katex-display { margin: 0; }
382
+ .cm-lp-math-display .katex-display { margin: 0.5em 0; overflow-x: auto; overflow-y: hidden; }
383
+
384
+ .cm-lp-diagram {
385
+ --pele-bg: var(--color-surface);
386
+ --pele-fg: var(--color-text);
387
+ --pele-muted: var(--color-text-muted);
388
+ --pele-line: var(--color-text-soft);
389
+ --pele-surface: var(--color-surface-subtle);
390
+ --pele-surface-alt: var(--color-accent-soft);
391
+ --pele-border: var(--color-border-strong);
392
+ --pele-accent: var(--color-accent);
393
+ --pele-error: var(--color-danger);
394
+ --pele-font-mono: var(--mono);
395
+ --pele-radius: var(--radius-sm);
396
+ --pele-zoom-top: 44px;
397
+ position: relative;
398
+ margin: var(--space-2) 0;
399
+ padding: var(--space-3) var(--space-2);
400
+ }
401
+ .cm-lp-diagram-canvas { position: relative; }
402
+ .cm-lp-diagram-canvas > svg { display: block; margin-inline: auto; }
403
+ .cm-lp-diagram-failed { color: var(--color-text-muted); font-family: var(--sans); font-size: var(--font-size-caption); }
404
+ .cm-lp-diagram-edit {
405
+ position: absolute; top: var(--space-2); right: var(--space-2);
406
+ min-width: 28px; min-height: 28px; padding: 0 var(--space-2);
407
+ border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
408
+ background: var(--color-surface); color: var(--color-text-muted);
409
+ font-family: var(--sans); font-size: var(--font-size-caption); cursor: pointer;
410
+ opacity: 0; transition: opacity 120ms;
411
+ }
412
+ .cm-lp-diagram:hover .cm-lp-diagram-edit, .cm-lp-diagram-edit:focus-visible { opacity: 1; }
413
+ .cm-lp-diagram-edit:hover { color: var(--color-text); }
414
+ .cm-lp-diagram-edit:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
415
+ @media (hover: none) { .cm-lp-diagram-edit { opacity: 1; } }
416
+
373
417
  .cm-lp-callout { background: var(--color-surface-subtle); padding-left: 1em !important; padding-right: 1em !important; }
374
418
  .cm-lp-callout-first { border-radius: var(--radius-md) var(--radius-md) 0 0; padding-top: 0.3em !important; font-weight: 600; }
375
419
  .cm-lp-callout-last { border-radius: 0 0 var(--radius-md) var(--radius-md); padding-bottom: 0.3em !important; }
@@ -3,6 +3,7 @@ import { syntaxTree } from "@codemirror/language";
3
3
  import { StateEffect, StateField } from "@codemirror/state";
4
4
  import { Decoration, EditorView, WidgetType, keymap } from "@codemirror/view";
5
5
  import { i18n as _i18n } from "@lingui/core";
6
+ import { DiagramWidget, isDiagramLanguage } from "./diagram.js";
6
7
  import { isRevealed, revealField } from "./reveal.js";
7
8
  const toggleFold = StateEffect.define({
8
9
  map: (value, changes) => ({
@@ -288,6 +289,14 @@ function build(state) {
288
289
  const codeFrom = fenced ? Math.min(first.to + 1, state.doc.length) : first.from;
289
290
  const codeTo = closed ? Math.max(codeFrom, last.from - 1) : last.to;
290
291
  const code = state.sliceDoc(codeFrom, codeTo);
292
+ // Quote and list markers would be part of a nested diagram's source, so only top-level fences render.
293
+ if (closed && isDiagramLanguage(opening[2]) && code.trim() && node.node.parent?.name === "Document" && !isRevealed(state, node.from, node.to)) {
294
+ ranges.push(Decoration.replace({
295
+ widget: new DiagramWidget(code),
296
+ block: true
297
+ }).range(first.from, last.to));
298
+ return false;
299
+ }
291
300
  for (let n = first.number; n <= last.number; n++) {
292
301
  const line = state.doc.line(n);
293
302
  const edge = `${n === first.number ? "cm-lp-code-first" : ""} ${n === last.number ? "cm-lp-code-last" : ""}`;
@@ -361,7 +370,7 @@ function build(state) {
361
370
  const from = line.from + match.index,
362
371
  to = from + match[0].length;
363
372
  const node = syntaxTree(state).resolveInner(from, 1);
364
- if (["InlineCode", "FencedCode", "CodeBlock", "HTMLBlock"].some(name => {
373
+ if (["InlineCode", "FencedCode", "CodeBlock", "HTMLBlock", "InlineMath", "MathBlock"].some(name => {
365
374
  for (let p = node; p; p = p.parent) if (p.name === name) return true;
366
375
  return false;
367
376
  })) continue;
@@ -0,0 +1,22 @@
1
+ import type { EditorView } from "@codemirror/view";
2
+ import { WidgetType } from "@codemirror/view";
3
+ import "../i18n.js";
4
+ /**
5
+ * A Mermaid diagram, rendered by Pele in place of its fenced source while the
6
+ * selection is elsewhere. Pele and each diagram type load on first use, so a
7
+ * note without diagrams never fetches them.
8
+ *
9
+ * Diagram text is untrusted: Pele escapes it and filters styles and links, the
10
+ * render options are fixed here (never from the note), remote images are off,
11
+ * and links only open in a new tab.
12
+ */
13
+ export declare function isDiagramLanguage(language: string): boolean;
14
+ export declare class DiagramWidget extends WidgetType {
15
+ readonly source: string;
16
+ constructor(source: string);
17
+ eq(other: DiagramWidget): boolean;
18
+ get estimatedHeight(): number;
19
+ toDOM(view: EditorView): HTMLDivElement;
20
+ destroy(dom: HTMLElement): void;
21
+ ignoreEvent(): boolean;
22
+ }
@@ -0,0 +1,153 @@
1
+ import { WidgetType } from "@codemirror/view";
2
+ import { i18n as _i18n } from "@lingui/core";
3
+ import "../i18n.js";
4
+ import { lazily } from "./lazy.js";
5
+ /**
6
+ * A Mermaid diagram, rendered by Pele in place of its fenced source while the
7
+ * selection is elsewhere. Pele and each diagram type load on first use, so a
8
+ * note without diagrams never fetches them.
9
+ *
10
+ * Diagram text is untrusted: Pele escapes it and filters styles and links, the
11
+ * render options are fixed here (never from the note), remote images are off,
12
+ * and links only open in a new tab.
13
+ */
14
+ export function isDiagramLanguage(language) {
15
+ return language.toLowerCase() === "mermaid";
16
+ }
17
+ const loadRenderer = lazily(() => import("pele/lazy"));
18
+ /** Last rendered height per source, so a re-created widget reserves its space before rendering. */
19
+ const heights = new Map();
20
+ const HEIGHT_ENTRIES = 256;
21
+ function rememberHeight(source, height) {
22
+ heights.delete(source);
23
+ heights.set(source, height);
24
+ if (heights.size > HEIGHT_ENTRIES) heights.delete(heights.keys().next().value);
25
+ }
26
+ const mounts = new WeakMap();
27
+ function renderOptions(view, box, source) {
28
+ return {
29
+ images: false,
30
+ linkSchemes: ["http", "https", "mailto"],
31
+ linkRel: "noopener noreferrer",
32
+ zoom: {
33
+ labels: {
34
+ zoomIn: _i18n._(
35
+ /** i18n */
36
+ {
37
+ id: "AWOSPo",
38
+ message: "Zoom in"
39
+ }),
40
+ zoomOut: _i18n._(
41
+ /** i18n */
42
+ {
43
+ id: "FjkaiT",
44
+ message: "Zoom out"
45
+ }),
46
+ reset: _i18n._(
47
+ /** i18n */
48
+ {
49
+ id: "jKibyt",
50
+ message: "Reset zoom"
51
+ })
52
+ }
53
+ },
54
+ onRender: () => view.requestMeasure({
55
+ read: () => box.offsetHeight,
56
+ write: height => {
57
+ if (height > 0) rememberHeight(source, height);
58
+ box.style.minHeight = "";
59
+ }
60
+ })
61
+ };
62
+ }
63
+ export class DiagramWidget extends WidgetType {
64
+ source;
65
+ constructor(source) {
66
+ super();
67
+ this.source = source;
68
+ }
69
+ eq(other) {
70
+ return this.source === other.source;
71
+ }
72
+ get estimatedHeight() {
73
+ return heights.get(this.source) ?? -1;
74
+ }
75
+ toDOM(view) {
76
+ const box = document.createElement("div");
77
+ box.className = "cm-lp-diagram";
78
+ const height = heights.get(this.source);
79
+ if (height) box.style.minHeight = `${height}px`;
80
+ const canvas = document.createElement("div");
81
+ canvas.className = "cm-lp-diagram-canvas";
82
+ const edit = document.createElement("button");
83
+ edit.type = "button";
84
+ edit.className = "cm-lp-diagram-edit";
85
+ edit.textContent = _i18n._(
86
+ /** i18n */
87
+ {
88
+ id: "Q4zUiV",
89
+ message: "Edit",
90
+ context: "diagram"
91
+ });
92
+ edit.setAttribute("aria-label", _i18n._(
93
+ /** i18n */
94
+ {
95
+ id: "j5JzXy",
96
+ message: "Edit diagram source"
97
+ }));
98
+ edit.addEventListener("click", () => editSource(view, box));
99
+ box.addEventListener("click", openLink);
100
+ box.append(canvas, edit);
101
+ const state = {
102
+ destroyed: false
103
+ };
104
+ mounts.set(box, state);
105
+ loadRenderer().then(({
106
+ mountAsync
107
+ }) => {
108
+ if (state.destroyed) return;
109
+ return mountAsync(canvas, this.source, renderOptions(view, box, this.source)).then(mounted => {
110
+ if (state.destroyed) mounted.destroy();else state.mounted = mounted;
111
+ });
112
+ }).catch(() => {
113
+ if (state.destroyed) return;
114
+ box.style.minHeight = "";
115
+ canvas.className = "cm-lp-diagram-canvas cm-lp-diagram-failed";
116
+ canvas.textContent = _i18n._(
117
+ /** i18n */
118
+ {
119
+ id: "MlIz7Y",
120
+ message: "The diagram could not be shown. Check your connection and reopen the note."
121
+ });
122
+ });
123
+ return box;
124
+ }
125
+ destroy(dom) {
126
+ const state = mounts.get(dom);
127
+ if (!state) return;
128
+ state.destroyed = true;
129
+ state.mounted?.destroy();
130
+ }
131
+ ignoreEvent() {
132
+ return true;
133
+ }
134
+ }
135
+ /** Puts the caret on the first line of the diagram's source, which reveals it. */
136
+ function editSource(view, box) {
137
+ const fence = view.state.doc.lineAt(view.posAtDOM(box));
138
+ view.dispatch({
139
+ selection: {
140
+ anchor: Math.min(fence.to + 1, view.state.doc.length)
141
+ },
142
+ scrollIntoView: true
143
+ });
144
+ view.focus();
145
+ }
146
+ /** Links never navigate the app: web and mail links open in a new tab, anything else is inert. */
147
+ function openLink(event) {
148
+ const link = event.target instanceof Element ? event.target.closest("a") : null;
149
+ if (!link) return;
150
+ event.preventDefault();
151
+ const href = link.getAttribute("href") ?? "";
152
+ if (/^(https?|mailto):/i.test(href)) window.open(href, "_blank", "noopener,noreferrer");
153
+ }
@@ -0,0 +1,2 @@
1
+ /** A module loaded on first use and shared by every caller. A failed load is retried by the next call rather than cached. */
2
+ export declare function lazily<T>(load: () => Promise<T>): () => Promise<T>;
@@ -0,0 +1,8 @@
1
+ /** A module loaded on first use and shared by every caller. A failed load is retried by the next call rather than cached. */
2
+ export function lazily(load) {
3
+ let pending;
4
+ return () => pending ??= load().catch(error => {
5
+ pending = undefined;
6
+ throw error;
7
+ });
8
+ }
@@ -0,0 +1,34 @@
1
+ import { EditorView, WidgetType } from "@codemirror/view";
2
+ import type { MarkdownConfig } from "@lezer/markdown";
3
+ import "../i18n.js";
4
+ /**
5
+ * `$…$` and `$$…$$` math as Markdown syntax: `InlineMath` and `MathBlock`
6
+ * nodes, each with two `MathMark` children around the TeX. Add it to the
7
+ * `markdown()` language's `extensions` so the live preview renders formulas
8
+ * and other syntax, such as emphasis, stays out of them.
9
+ *
10
+ * Inline math stays on one line. A single `$` opens only before a non-space
11
+ * and closes only after a non-space and before a non-digit, so prices such as
12
+ * "$5 and $10" stay text. A display block starts with a line that begins with
13
+ * `$$` and ends at the next `$$`; an unclosed block runs to the end of its
14
+ * container, like an unclosed code fence.
15
+ */
16
+ export declare const markdownMath: MarkdownConfig;
17
+ /** Where a formula sits: in text, as a display formula in text, as its own block, or under its revealed source. */
18
+ type MathKind = "inline" | "display" | "block" | "preview";
19
+ /**
20
+ * A formula rendered by KaTeX. Formula text is untrusted: `trust` stays off,
21
+ * so commands such as `\href` and `\includegraphics` render as errors, and
22
+ * sizes are capped. KaTeX loads with the first formula.
23
+ */
24
+ export declare class MathWidget extends WidgetType {
25
+ readonly source: string;
26
+ readonly kind: MathKind;
27
+ constructor(source: string, kind: MathKind);
28
+ eq(other: MathWidget): boolean;
29
+ toDOM(view: EditorView): HTMLDivElement | HTMLSpanElement;
30
+ ignoreEvent(): boolean;
31
+ }
32
+ /** Renders `markdownMath` formulas where the selection is not, and shows a rendered preview under a revealed display block. */
33
+ export declare function mathPreview(): import("@codemirror/state").Extension;
34
+ export {};
@@ -0,0 +1,201 @@
1
+ import { syntaxTree } from "@codemirror/language";
2
+ import { Decoration, EditorView, WidgetType } from "@codemirror/view";
3
+ import { i18n as _i18n } from "@lingui/core";
4
+ import "../i18n.js";
5
+ import { lazily } from "./lazy.js";
6
+ import { isRevealed, revealField } from "./reveal.js";
7
+ const DOLLAR = 36,
8
+ BACKSLASH = 92,
9
+ NEWLINE = 10;
10
+ const isSpace = ch => ch === 32 || ch === 9 || ch === 10 || ch === 13;
11
+ const isDigit = ch => ch >= 48 && ch <= 57;
12
+ /**
13
+ * `$…$` and `$$…$$` math as Markdown syntax: `InlineMath` and `MathBlock`
14
+ * nodes, each with two `MathMark` children around the TeX. Add it to the
15
+ * `markdown()` language's `extensions` so the live preview renders formulas
16
+ * and other syntax, such as emphasis, stays out of them.
17
+ *
18
+ * Inline math stays on one line. A single `$` opens only before a non-space
19
+ * and closes only after a non-space and before a non-digit, so prices such as
20
+ * "$5 and $10" stay text. A display block starts with a line that begins with
21
+ * `$$` and ends at the next `$$`; an unclosed block runs to the end of its
22
+ * container, like an unclosed code fence.
23
+ */
24
+ export const markdownMath = {
25
+ defineNodes: [{
26
+ name: "MathBlock",
27
+ block: true
28
+ }, "InlineMath", "MathMark"],
29
+ parseBlock: [{
30
+ name: "MathBlock",
31
+ before: "FencedCode",
32
+ parse: parseBlock,
33
+ endLeaf: (_cx, line) => blockOpening(line) !== null
34
+ }],
35
+ parseInline: [{
36
+ name: "InlineMath",
37
+ after: "Escape",
38
+ parse: parseInline
39
+ }]
40
+ };
41
+ /** A line opening display math: `$$` followed by no other `$$` ("open"), or one whole-line `$$…$$` formula ("single"). */
42
+ function blockOpening(line) {
43
+ if (line.next !== DOLLAR || line.text.charCodeAt(line.pos + 1) !== DOLLAR) return null;
44
+ const rest = line.text.slice(line.pos + 2);
45
+ const close = rest.indexOf("$$");
46
+ if (close < 0) return "open";
47
+ return rest.slice(0, close).trim() && !rest.slice(close + 2).trim() ? "single" : null;
48
+ }
49
+ function parseBlock(cx, line) {
50
+ const opening = blockOpening(line);
51
+ if (!opening) return false;
52
+ const from = cx.lineStart + line.pos;
53
+ const marks = [cx.elt("MathMark", from, from + 2)];
54
+ if (opening === "single") {
55
+ const close = cx.lineStart + line.text.indexOf("$$", line.pos + 2);
56
+ marks.push(cx.elt("MathMark", close, close + 2));
57
+ cx.nextLine();
58
+ } else {
59
+ // Lezer's own fenced code stops at the first line outside its container
60
+ // the same way. `Line.depth` (the containers a line continues) is not in
61
+ // the typings, but every 1.x release has it.
62
+ while (cx.nextLine() && line.depth >= cx.depth) {
63
+ marks.push(...line.markers);
64
+ const close = line.text.indexOf("$$", line.pos);
65
+ if (close >= 0) {
66
+ marks.push(cx.elt("MathMark", cx.lineStart + close, cx.lineStart + close + 2));
67
+ cx.nextLine();
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ cx.addElement(cx.elt("MathBlock", from, cx.prevLineEnd(), marks));
73
+ return true;
74
+ }
75
+ function parseInline(cx, next, start) {
76
+ if (next !== DOLLAR || start > cx.offset && cx.char(start - 1) === DOLLAR) return -1;
77
+ const size = cx.char(start + 1) === DOLLAR ? 2 : 1;
78
+ const first = cx.char(start + size);
79
+ if (first === DOLLAR || first < 0 || size === 1 && isSpace(first)) return -1;
80
+ for (let pos = start + size; pos < cx.end; pos++) {
81
+ const ch = cx.char(pos);
82
+ if (ch === NEWLINE) return -1;
83
+ if (ch === BACKSLASH) {
84
+ pos++;
85
+ if (cx.char(pos) === NEWLINE) return -1;
86
+ continue;
87
+ }
88
+ if (ch !== DOLLAR) continue;
89
+ if (size === 2) {
90
+ if (cx.char(pos + 1) !== DOLLAR) continue;
91
+ if (!cx.slice(start + 2, pos).trim()) return -1;
92
+ } else if (isSpace(cx.char(pos - 1)) || isDigit(cx.char(pos + 1))) {
93
+ continue;
94
+ }
95
+ const end = pos + size;
96
+ return cx.addElement(cx.elt("InlineMath", start, end, [cx.elt("MathMark", start, start + size), cx.elt("MathMark", pos, end)]));
97
+ }
98
+ return -1;
99
+ }
100
+ const loadKatex = lazily(() => import("katex"));
101
+ let katex;
102
+ /**
103
+ * A formula rendered by KaTeX. Formula text is untrusted: `trust` stays off,
104
+ * so commands such as `\href` and `\includegraphics` render as errors, and
105
+ * sizes are capped. KaTeX loads with the first formula.
106
+ */
107
+ export class MathWidget extends WidgetType {
108
+ source;
109
+ kind;
110
+ constructor(source, kind) {
111
+ super();
112
+ this.source = source;
113
+ this.kind = kind;
114
+ }
115
+ eq(other) {
116
+ return this.source === other.source && this.kind === other.kind;
117
+ }
118
+ toDOM(view) {
119
+ const element = document.createElement(this.kind === "block" || this.kind === "preview" ? "div" : "span");
120
+ element.className = `cm-lp-math cm-lp-math-${this.kind}`;
121
+ if (katex) {
122
+ render(katex, element, this.source, this.kind !== "inline");
123
+ return element;
124
+ }
125
+ element.classList.add("cm-lp-math-pending");
126
+ element.textContent = this.source;
127
+ loadKatex().then(loaded => {
128
+ katex = loaded;
129
+ element.classList.remove("cm-lp-math-pending");
130
+ render(loaded, element, this.source, this.kind !== "inline");
131
+ view.requestMeasure();
132
+ }).catch(() => {
133
+ element.classList.replace("cm-lp-math-pending", "cm-lp-math-failed");
134
+ element.title = _i18n._(
135
+ /** i18n */
136
+ {
137
+ id: "2ORwUL",
138
+ message: "Formulas could not be shown. Check your connection and reopen the note."
139
+ });
140
+ });
141
+ return element;
142
+ }
143
+ // A press on a formula places the caret beside it, which reveals its source.
144
+ ignoreEvent() {
145
+ return false;
146
+ }
147
+ }
148
+ function render(module, element, source, display) {
149
+ // Invalid TeX renders as its source, coloured, with KaTeX's message as the title.
150
+ module.render(source, element, {
151
+ displayMode: display,
152
+ throwOnError: false,
153
+ errorColor: "var(--color-danger)",
154
+ strict: "ignore",
155
+ trust: false,
156
+ maxSize: 20,
157
+ maxExpand: 500
158
+ });
159
+ }
160
+ const sourceMark = Decoration.mark({
161
+ class: "cm-lp-math-source"
162
+ });
163
+ /** Renders `markdownMath` formulas where the selection is not, and shows a rendered preview under a revealed display block. */
164
+ export function mathPreview() {
165
+ return EditorView.decorations.compute(["doc", revealField], build);
166
+ }
167
+ function build(state) {
168
+ const ranges = [];
169
+ syntaxTree(state).iterate({
170
+ enter(node) {
171
+ if (node.name !== "InlineMath" && node.name !== "MathBlock") return;
172
+ const marks = node.node.getChildren("MathMark");
173
+ const source = marks.length === 2 ? state.sliceDoc(marks[0].to, marks[1].from).trim() : "";
174
+ const revealed = isRevealed(state, node.from, node.to);
175
+ const first = state.doc.lineAt(node.from),
176
+ last = state.doc.lineAt(node.to);
177
+ const topLevel = node.name === "MathBlock" && node.node.parent?.name === "Document";
178
+ // Quote and list markers would be part of a nested multi-line formula, so it stays source.
179
+ if (!source || revealed || !topLevel && first.number !== last.number) {
180
+ ranges.push(sourceMark.range(node.from, node.to));
181
+ if (source && revealed && topLevel) ranges.push(Decoration.widget({
182
+ widget: new MathWidget(source, "preview"),
183
+ block: true,
184
+ side: 1
185
+ }).range(last.to));
186
+ } else if (topLevel) {
187
+ ranges.push(Decoration.replace({
188
+ widget: new MathWidget(source, "block"),
189
+ block: true
190
+ }).range(first.from, last.to));
191
+ } else {
192
+ const display = node.name === "MathBlock" || marks[0].to - marks[0].from === 2;
193
+ ranges.push(Decoration.replace({
194
+ widget: new MathWidget(source, display ? "display" : "inline")
195
+ }).range(node.from, node.to));
196
+ }
197
+ return false;
198
+ }
199
+ });
200
+ return Decoration.set(ranges, true);
201
+ }
@@ -3,11 +3,13 @@ import { type LivePreviewOptions } from "./live-preview/inline.js";
3
3
  export type { LivePreviewLink, LivePreviewOptions } from "./live-preview/inline.js";
4
4
  export { isRevealed, revealField as livePreviewReveal } from "./live-preview/reveal.js";
5
5
  export { indentListItem, outdentListItem } from "./live-preview/keys.js";
6
+ export { markdownMath } from "./live-preview/math.js";
6
7
  /**
7
8
  * Live preview for a CodeMirror Markdown editor: the note reads as rendered
8
9
  * text, and each element shows its Markdown only while the selection touches
9
10
  * it. Pair it with `@mdbase-dev/ui/live-preview.css` and the `markdown()`
10
- * language (GFM, for tasks, strikethrough and tables).
11
+ * language (GFM, for tasks, strikethrough and tables) with `markdownMath` in
12
+ * its `extensions`, for `$…$` and `$$…$$` formulas.
11
13
  *
12
14
  * Rendered links carry `data-link-from` (the link's source offset) and
13
15
  * `data-link-format`; opening them is the app's choice. App widgets, such as
@@ -3,21 +3,24 @@ import { inlinePreview } from "./live-preview/inline.js";
3
3
  import { livePreviewKeys } from "./live-preview/keys.js";
4
4
  import { tablePreview } from "./live-preview/table.js";
5
5
  import { blockPreview } from "./live-preview/blocks.js";
6
+ import { mathPreview } from "./live-preview/math.js";
6
7
  import { revealTracking } from "./live-preview/reveal.js";
7
8
  export { isRevealed, revealField as livePreviewReveal } from "./live-preview/reveal.js";
8
9
  export { indentListItem, outdentListItem } from "./live-preview/keys.js";
10
+ export { markdownMath } from "./live-preview/math.js";
9
11
  /**
10
12
  * Live preview for a CodeMirror Markdown editor: the note reads as rendered
11
13
  * text, and each element shows its Markdown only while the selection touches
12
14
  * it. Pair it with `@mdbase-dev/ui/live-preview.css` and the `markdown()`
13
- * language (GFM, for tasks, strikethrough and tables).
15
+ * language (GFM, for tasks, strikethrough and tables) with `markdownMath` in
16
+ * its `extensions`, for `$…$` and `$$…$$` formulas.
14
17
  *
15
18
  * Rendered links carry `data-link-from` (the link's source offset) and
16
19
  * `data-link-format`; opening them is the app's choice. App widgets, such as
17
20
  * embeds, should follow the same rule through `isRevealed`.
18
21
  */
19
22
  export function livePreview(options = {}) {
20
- return [revealTracking(), blockPreview(), inlinePreview(options), tablePreview(), livePreviewKeys, taskToggle];
23
+ return [revealTracking(), blockPreview(), mathPreview(), inlinePreview(options), tablePreview(), livePreviewKeys, taskToggle];
21
24
  }
22
25
  const taskToggle = EditorView.domEventHandlers({
23
26
  mousedown(event, view) {