@open-slide/core 2.0.0-beta.5 → 2.0.0
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/dist/index.js +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{zh-tw-B51sMTg3.js → zh-tw-DlZoAc2-.js} +4 -4
- package/package.json +3 -3
- package/src/app/components/note-markdown.test.tsx +42 -0
- package/src/app/components/note-markdown.tsx +85 -0
- package/src/app/lib/export-html.ts +48 -5
- package/src/app/lib/note-markdown.test.ts +147 -0
- package/src/app/lib/note-markdown.ts +116 -0
- package/src/app/routes/presenter.tsx +3 -2
- package/src/locale/en.ts +1 -1
- package/src/locale/ja.ts +1 -1
- package/src/locale/zh-cn.ts +1 -1
- package/src/locale/zh-tw.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as en, n as zhCN, r as ja, t as zhTW } from "./zh-tw-
|
|
1
|
+
import { i as en, n as zhCN, r as ja, t as zhTW } from "./zh-tw-DlZoAc2-.js";
|
|
2
2
|
import { n as defaultDesign, r as designToCssVars, t as cssVarsToString } from "./design-Cpqx7SJs.js";
|
|
3
3
|
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { toast } from "sonner";
|
package/dist/locale/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as en, n as zhCN, r as ja, t as zhTW } from "../zh-tw-
|
|
1
|
+
import { i as en, n as zhCN, r as ja, t as zhTW } from "../zh-tw-DlZoAc2-.js";
|
|
2
2
|
//#region src/locale/format.ts
|
|
3
3
|
function format(template, vars) {
|
|
4
4
|
return template.replace(/\{(\w+)\}/g, (m, key) => {
|
|
@@ -491,7 +491,7 @@ const en = {
|
|
|
491
491
|
notesDrawer: {
|
|
492
492
|
toggle: "Notes",
|
|
493
493
|
pageLabel: "page {n}/{total}",
|
|
494
|
-
placeholder: "Write speaker notes for this slide…",
|
|
494
|
+
placeholder: "Write speaker notes for this slide (Markdown supported)…",
|
|
495
495
|
statusSaving: "Saving…",
|
|
496
496
|
statusSaved: "Saved",
|
|
497
497
|
statusError: "Save failed: {msg}"
|
|
@@ -1009,7 +1009,7 @@ const ja = {
|
|
|
1009
1009
|
notesDrawer: {
|
|
1010
1010
|
toggle: "発表者ノート",
|
|
1011
1011
|
pageLabel: "{n} / {total} ページ",
|
|
1012
|
-
placeholder: "
|
|
1012
|
+
placeholder: "このスライドの発表者ノートを記入(Markdown 対応)…",
|
|
1013
1013
|
statusSaving: "保存中…",
|
|
1014
1014
|
statusSaved: "保存済み",
|
|
1015
1015
|
statusError: "保存に失敗しました: {msg}"
|
|
@@ -1527,7 +1527,7 @@ const zhCN = {
|
|
|
1527
1527
|
notesDrawer: {
|
|
1528
1528
|
toggle: "演讲备注",
|
|
1529
1529
|
pageLabel: "第 {n} / {total} 页",
|
|
1530
|
-
placeholder: "
|
|
1530
|
+
placeholder: "为这一页撰写演讲备注(支持 Markdown)…",
|
|
1531
1531
|
statusSaving: "保存中…",
|
|
1532
1532
|
statusSaved: "已保存",
|
|
1533
1533
|
statusError: "保存失败:{msg}"
|
|
@@ -2045,7 +2045,7 @@ const zhTW = {
|
|
|
2045
2045
|
notesDrawer: {
|
|
2046
2046
|
toggle: "講稿",
|
|
2047
2047
|
pageLabel: "第 {n} / {total} 頁",
|
|
2048
|
-
placeholder: "
|
|
2048
|
+
placeholder: "為這一頁撰寫演講備忘(支援 Markdown)…",
|
|
2049
2049
|
statusSaving: "儲存中…",
|
|
2050
2050
|
statusSaved: "已儲存",
|
|
2051
2051
|
statusError: "儲存失敗:{msg}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-slide/core",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@dnd-kit/core": "^6.3.1",
|
|
66
66
|
"@dnd-kit/sortable": "^10.0.0",
|
|
67
67
|
"@dnd-kit/utilities": "^3.2.2",
|
|
68
|
-
"@fontsource-variable/geist": "^5.
|
|
68
|
+
"@fontsource-variable/geist": "^5.3.0",
|
|
69
69
|
"@tailwindcss/vite": "^4.3.3",
|
|
70
70
|
"@vitejs/plugin-react": "^6.1.1",
|
|
71
71
|
"chalk": "^6.0.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"tailwindcss": "^4.3.3",
|
|
90
90
|
"tw-animate-css": "^1.4.0",
|
|
91
91
|
"use-sync-external-store": "^1.6.0",
|
|
92
|
-
"vite": "^8.
|
|
92
|
+
"vite": "^8.3.0"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@playwright/test": "~1.62.1",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { NoteMarkdown } from './note-markdown';
|
|
4
|
+
|
|
5
|
+
const render = (text: string) => renderToStaticMarkup(<NoteMarkdown text={text} />);
|
|
6
|
+
|
|
7
|
+
describe('NoteMarkdown', () => {
|
|
8
|
+
it('renders inline markdown as semantic elements', () => {
|
|
9
|
+
const html = render('a **bold** and *soft* `cmd`');
|
|
10
|
+
expect(html).toContain('<strong class="font-semibold">bold</strong>');
|
|
11
|
+
expect(html).toContain('<em>soft</em>');
|
|
12
|
+
expect(html).toContain('>cmd</code>');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders headings demoted to h4–h6', () => {
|
|
16
|
+
const html = render('# One\n## Two\n### Three');
|
|
17
|
+
expect(html).toContain('<h4');
|
|
18
|
+
expect(html).toContain('<h5');
|
|
19
|
+
expect(html).toContain('<h6');
|
|
20
|
+
expect(html).not.toContain('<h1');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('renders lists with the right element', () => {
|
|
24
|
+
expect(render('- a\n- b')).toMatch(/<ul[^>]*>.*<li>a<\/li><li>b<\/li>.*<\/ul>/);
|
|
25
|
+
expect(render('1. a\n2. b')).toMatch(/<ol[^>]*>.*<li>a<\/li><li>b<\/li>.*<\/ol>/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('joins paragraph lines with <br/> and splits paragraphs', () => {
|
|
29
|
+
const html = render('one\ntwo\n\nthree');
|
|
30
|
+
expect(html).toMatch(/<p>one<br\/>two<\/p><p>three<\/p>/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('keeps escaped delimiters literal in the output', () => {
|
|
34
|
+
const html = render('\\*keep\\* the stars');
|
|
35
|
+
expect(html).toContain('*keep* the stars');
|
|
36
|
+
expect(html).not.toContain('<em>');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('preserves whitespace via a pre-wrap wrapper', () => {
|
|
40
|
+
expect(render('x')).toContain('whitespace-pre-wrap');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Fragment, type ReactNode, useMemo } from 'react';
|
|
2
|
+
import { type NoteBlock, type NoteInline, parseNoteMarkdown } from '@/lib/note-markdown';
|
|
3
|
+
|
|
4
|
+
const CODE_CLASS = 'rounded-[3px] bg-foreground/12 px-[0.3em] py-[0.1em] font-mono text-[0.9em]';
|
|
5
|
+
|
|
6
|
+
function renderInline(nodes: NoteInline[]): ReactNode {
|
|
7
|
+
return nodes.map((node, i) => {
|
|
8
|
+
switch (node.type) {
|
|
9
|
+
case 'text':
|
|
10
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
11
|
+
return <Fragment key={i}>{node.text}</Fragment>;
|
|
12
|
+
case 'strong':
|
|
13
|
+
return (
|
|
14
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
15
|
+
<strong key={i} className="font-semibold">
|
|
16
|
+
{renderInline(node.children)}
|
|
17
|
+
</strong>
|
|
18
|
+
);
|
|
19
|
+
case 'em':
|
|
20
|
+
return (
|
|
21
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
22
|
+
<em key={i}>{renderInline(node.children)}</em>
|
|
23
|
+
);
|
|
24
|
+
case 'code':
|
|
25
|
+
return (
|
|
26
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
27
|
+
<code key={i} className={CODE_CLASS}>
|
|
28
|
+
{node.text}
|
|
29
|
+
</code>
|
|
30
|
+
);
|
|
31
|
+
default:
|
|
32
|
+
return node satisfies never;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const HEADING_SIZES = { 1: 'text-[1.25em]', 2: 'text-[1.12em]', 3: 'text-[1.05em]' } as const;
|
|
38
|
+
|
|
39
|
+
function renderBlock(block: NoteBlock, key: number): ReactNode {
|
|
40
|
+
switch (block.type) {
|
|
41
|
+
case 'heading': {
|
|
42
|
+
// h4–h6 so note headings stay below the app's own UI headings in the
|
|
43
|
+
// presenter window's document outline.
|
|
44
|
+
const Tag = `h${block.level + 3}` as 'h4' | 'h5' | 'h6';
|
|
45
|
+
return (
|
|
46
|
+
<Tag key={key} className={`font-semibold ${HEADING_SIZES[block.level]}`}>
|
|
47
|
+
{renderInline(block.children)}
|
|
48
|
+
</Tag>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
case 'list': {
|
|
52
|
+
const Tag = block.ordered ? 'ol' : 'ul';
|
|
53
|
+
return (
|
|
54
|
+
<Tag
|
|
55
|
+
key={key}
|
|
56
|
+
className={`space-y-[0.2em] pl-[1.4em] ${block.ordered ? 'list-decimal' : 'list-disc'}`}
|
|
57
|
+
>
|
|
58
|
+
{block.items.map((item, i) => (
|
|
59
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
60
|
+
<li key={i}>{renderInline(item)}</li>
|
|
61
|
+
))}
|
|
62
|
+
</Tag>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
case 'paragraph':
|
|
66
|
+
return (
|
|
67
|
+
<p key={key}>
|
|
68
|
+
{block.lines.map((line, i) => (
|
|
69
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: static parse output, never reordered
|
|
70
|
+
<Fragment key={i}>
|
|
71
|
+
{i > 0 && <br />}
|
|
72
|
+
{renderInline(line)}
|
|
73
|
+
</Fragment>
|
|
74
|
+
))}
|
|
75
|
+
</p>
|
|
76
|
+
);
|
|
77
|
+
default:
|
|
78
|
+
return block satisfies never;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function NoteMarkdown({ text }: { text: string }) {
|
|
83
|
+
const blocks = useMemo(() => parseNoteMarkdown(text), [text]);
|
|
84
|
+
return <div className="space-y-[0.65em] whitespace-pre-wrap">{blocks.map(renderBlock)}</div>;
|
|
85
|
+
}
|
|
@@ -274,14 +274,40 @@ html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-f
|
|
|
274
274
|
(function () {
|
|
275
275
|
var pages = document.querySelectorAll('.os-page');
|
|
276
276
|
var idx = 0;
|
|
277
|
+
var shown = 0;
|
|
277
278
|
var frame = document.getElementById('os-frame');
|
|
278
279
|
var cur = document.getElementById('os-cur');
|
|
279
280
|
function fit() {
|
|
280
281
|
var s = Math.min(window.innerWidth / ${CANVAS_WIDTH}, window.innerHeight / ${CANVAS_HEIGHT});
|
|
281
282
|
frame.style.transform = 'scale(' + s + ')';
|
|
282
283
|
}
|
|
283
|
-
|
|
284
|
+
// Pages authored with <Steps>/<Step> render every step into the markup, so the file still
|
|
285
|
+
// reads with scripting off. This walks them one keypress at a time, the way the player does:
|
|
286
|
+
// arrive forward and the page starts unrevealed, arrive backward and it is already complete.
|
|
287
|
+
function stepsOf(page) {
|
|
288
|
+
return page ? page.querySelectorAll('[data-osd-step]') : [];
|
|
289
|
+
}
|
|
290
|
+
function setStep(el, revealed, animate) {
|
|
291
|
+
var transition = el.style.transition;
|
|
292
|
+
if (!animate) el.style.transition = 'none';
|
|
293
|
+
el.setAttribute('data-osd-step', revealed ? 'revealed' : 'pending');
|
|
294
|
+
el.style.opacity = revealed ? '1' : '0';
|
|
295
|
+
el.style.visibility = revealed ? 'visible' : 'hidden';
|
|
296
|
+
if (!animate) {
|
|
297
|
+
void el.offsetWidth;
|
|
298
|
+
el.style.transition = transition;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function paintSteps(animate) {
|
|
302
|
+
var els = stepsOf(pages[idx]);
|
|
303
|
+
for (var i = 0; i < els.length; i++) setStep(els[i], i < shown, animate);
|
|
304
|
+
}
|
|
305
|
+
function go(i, revealAll) {
|
|
306
|
+
var from = idx;
|
|
284
307
|
idx = Math.max(0, Math.min(pages.length - 1, i));
|
|
308
|
+
if (revealAll) shown = stepsOf(pages[idx]).length;
|
|
309
|
+
else if (idx > from) shown = 0;
|
|
310
|
+
else if (idx < from) shown = stepsOf(pages[idx]).length;
|
|
285
311
|
pages.forEach(function (p, n) {
|
|
286
312
|
p.hidden = n !== idx;
|
|
287
313
|
p.querySelectorAll('video').forEach(function (video) {
|
|
@@ -293,14 +319,31 @@ html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-f
|
|
|
293
319
|
}
|
|
294
320
|
});
|
|
295
321
|
});
|
|
322
|
+
paintSteps(false);
|
|
296
323
|
cur.textContent = String(idx + 1);
|
|
297
324
|
}
|
|
325
|
+
function next() {
|
|
326
|
+
if (shown < stepsOf(pages[idx]).length) {
|
|
327
|
+
shown += 1;
|
|
328
|
+
paintSteps(true);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
go(idx + 1);
|
|
332
|
+
}
|
|
333
|
+
function prev() {
|
|
334
|
+
if (shown > 0) {
|
|
335
|
+
shown -= 1;
|
|
336
|
+
paintSteps(true);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
go(idx - 1);
|
|
340
|
+
}
|
|
298
341
|
window.addEventListener('resize', fit);
|
|
299
342
|
window.addEventListener('keydown', function (e) {
|
|
300
|
-
if (['ArrowRight','ArrowDown','PageDown',' '].indexOf(e.key) >= 0) { e.preventDefault();
|
|
301
|
-
else if (['ArrowLeft','ArrowUp','PageUp'].indexOf(e.key) >= 0) { e.preventDefault();
|
|
302
|
-
else if (e.key === 'Home') { e.preventDefault(); go(0); }
|
|
303
|
-
else if (e.key === 'End') { e.preventDefault(); go(pages.length - 1); }
|
|
343
|
+
if (['ArrowRight','ArrowDown','PageDown',' '].indexOf(e.key) >= 0) { e.preventDefault(); next(); }
|
|
344
|
+
else if (['ArrowLeft','ArrowUp','PageUp'].indexOf(e.key) >= 0) { e.preventDefault(); prev(); }
|
|
345
|
+
else if (e.key === 'Home') { e.preventDefault(); go(0, true); }
|
|
346
|
+
else if (e.key === 'End') { e.preventDefault(); go(pages.length - 1, true); }
|
|
304
347
|
});
|
|
305
348
|
fit();
|
|
306
349
|
go(0);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { type NoteInline, parseInline, parseNoteMarkdown } from './note-markdown.ts';
|
|
3
|
+
|
|
4
|
+
const text = (t: string): NoteInline => ({ type: 'text', text: t });
|
|
5
|
+
|
|
6
|
+
describe('parseInline', () => {
|
|
7
|
+
it('returns plain text untouched', () => {
|
|
8
|
+
expect(parseInline('just a sentence')).toEqual([text('just a sentence')]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('parses bold', () => {
|
|
12
|
+
expect(parseInline('a **key** point')).toEqual([
|
|
13
|
+
text('a '),
|
|
14
|
+
{ type: 'strong', children: [text('key')] },
|
|
15
|
+
text(' point'),
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('parses italic with stars and underscores', () => {
|
|
20
|
+
expect(parseInline('*a* and _b_')).toEqual([
|
|
21
|
+
{ type: 'em', children: [text('a')] },
|
|
22
|
+
text(' and '),
|
|
23
|
+
{ type: 'em', children: [text('b')] },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('parses inline code literally', () => {
|
|
28
|
+
expect(parseInline('run `pnpm **dev**`')).toEqual([
|
|
29
|
+
text('run '),
|
|
30
|
+
{ type: 'code', text: 'pnpm **dev**' },
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('parses italic nested in bold', () => {
|
|
35
|
+
expect(parseInline('**bold _in_ here**')).toEqual([
|
|
36
|
+
{
|
|
37
|
+
type: 'strong',
|
|
38
|
+
children: [text('bold '), { type: 'em', children: [text('in')] }, text(' here')],
|
|
39
|
+
},
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('leaves snake_case and unpaired markers alone', () => {
|
|
44
|
+
expect(parseInline('use snake_case_names here')).toEqual([text('use snake_case_names here')]);
|
|
45
|
+
expect(parseInline('2 * 3 and a_b')).toEqual([text('2 * 3 and a_b')]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('treats backslash-escaped delimiters as literal text', () => {
|
|
49
|
+
expect(parseInline('\\*not italic\\*')).toEqual([text('*not italic*')]);
|
|
50
|
+
expect(parseInline('\\**emphasis**')).toEqual([
|
|
51
|
+
text('*'),
|
|
52
|
+
{ type: 'em', children: [text('emphasis')] },
|
|
53
|
+
text('*'),
|
|
54
|
+
]);
|
|
55
|
+
expect(parseInline('a \\` b and \\\\ done')).toEqual([text('a ` b and \\ done')]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps the backslash inside code spans', () => {
|
|
59
|
+
expect(parseInline('`a\\*b`')).toEqual([{ type: 'code', text: 'a\\*b' }]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('does not pair emphasis markers padded with spaces', () => {
|
|
63
|
+
expect(parseInline('2 * 3 = 6 and 5 * 4')).toEqual([text('2 * 3 = 6 and 5 * 4')]);
|
|
64
|
+
expect(parseInline('a ** b ** c')).toEqual([text('a ** b ** c')]);
|
|
65
|
+
expect(parseInline('a _ b _ c')).toEqual([text('a _ b _ c')]);
|
|
66
|
+
expect(parseInline('*a* and *no trail *')).toEqual([
|
|
67
|
+
{ type: 'em', children: [text('a')] },
|
|
68
|
+
text(' and *no trail *'),
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('parseNoteMarkdown', () => {
|
|
74
|
+
it('splits paragraphs on blank lines and keeps line breaks inside one', () => {
|
|
75
|
+
expect(parseNoteMarkdown('one\ntwo\n\nthree')).toEqual([
|
|
76
|
+
{ type: 'paragraph', lines: [[text('one')], [text('two')]] },
|
|
77
|
+
{ type: 'paragraph', lines: [[text('three')]] },
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('parses headings up to level 3', () => {
|
|
82
|
+
expect(parseNoteMarkdown('# Intro\n#### not a heading')).toEqual([
|
|
83
|
+
{ type: 'heading', level: 1, children: [text('Intro')] },
|
|
84
|
+
{ type: 'paragraph', lines: [[text('#### not a heading')]] },
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('groups consecutive bullets into one list', () => {
|
|
89
|
+
expect(parseNoteMarkdown('- a\n- **b**\ntail')).toEqual([
|
|
90
|
+
{
|
|
91
|
+
type: 'list',
|
|
92
|
+
ordered: false,
|
|
93
|
+
items: [[text('a')], [{ type: 'strong', children: [text('b')] }]],
|
|
94
|
+
},
|
|
95
|
+
{ type: 'paragraph', lines: [[text('tail')]] },
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('parses ordered lists with dot or paren markers', () => {
|
|
100
|
+
expect(parseNoteMarkdown('1. a\n2) b')).toEqual([
|
|
101
|
+
{ type: 'list', ordered: true, items: [[text('a')], [text('b')]] },
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('keeps unordered and ordered runs as separate lists', () => {
|
|
106
|
+
expect(parseNoteMarkdown('- a\n1. b')).toEqual([
|
|
107
|
+
{ type: 'list', ordered: false, items: [[text('a')]] },
|
|
108
|
+
{ type: 'list', ordered: true, items: [[text('b')]] },
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('does not treat a mid-sentence star line as a bullet without a space', () => {
|
|
113
|
+
expect(parseNoteMarkdown('*emphasis line*')).toEqual([
|
|
114
|
+
{ type: 'paragraph', lines: [[{ type: 'em', children: [text('emphasis line')] }]] },
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('escapes disable heading and list markers', () => {
|
|
119
|
+
expect(parseNoteMarkdown('\\# not a heading')).toEqual([
|
|
120
|
+
{ type: 'paragraph', lines: [[text('# not a heading')]] },
|
|
121
|
+
]);
|
|
122
|
+
expect(parseNoteMarkdown('\\- not a bullet\n1\\. not a list')).toEqual([
|
|
123
|
+
{ type: 'paragraph', lines: [[text('- not a bullet')], [text('1. not a list')]] },
|
|
124
|
+
]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('does not treat a 4-digit year line as an ordered list', () => {
|
|
128
|
+
expect(parseNoteMarkdown('1995. the year it began')).toEqual([
|
|
129
|
+
{ type: 'paragraph', lines: [[text('1995. the year it began')]] },
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('treats a bare # without content as plain text', () => {
|
|
134
|
+
expect(parseNoteMarkdown('# ')).toEqual([{ type: 'paragraph', lines: [[text('#')]] }]);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('preserves leading whitespace in paragraph lines', () => {
|
|
138
|
+
expect(parseNoteMarkdown('plan:\n indented detail')).toEqual([
|
|
139
|
+
{ type: 'paragraph', lines: [[text('plan:')], [text(' indented detail')]] },
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('handles empty input', () => {
|
|
144
|
+
expect(parseNoteMarkdown('')).toEqual([]);
|
|
145
|
+
expect(parseNoteMarkdown('\n\n')).toEqual([]);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export type NoteInline =
|
|
2
|
+
| { type: 'text'; text: string }
|
|
3
|
+
| { type: 'strong'; children: NoteInline[] }
|
|
4
|
+
| { type: 'em'; children: NoteInline[] }
|
|
5
|
+
| { type: 'code'; text: string };
|
|
6
|
+
|
|
7
|
+
export type NoteBlock =
|
|
8
|
+
| { type: 'paragraph'; lines: NoteInline[][] }
|
|
9
|
+
| { type: 'heading'; level: 1 | 2 | 3; children: NoteInline[] }
|
|
10
|
+
| { type: 'list'; ordered: boolean; items: NoteInline[][] };
|
|
11
|
+
|
|
12
|
+
const HEADING = /^(#{1,3})\s+(.*)$/;
|
|
13
|
+
// Ordered before the single-star branch so `**bold**` never parses as
|
|
14
|
+
// empty italics. Emphasis content must start and end with non-whitespace
|
|
15
|
+
// (CommonMark) so spaced stars like `2 * 3 … 5 * 4` never pair up, and `_`
|
|
16
|
+
// needs word boundaries to leave snake_case alone.
|
|
17
|
+
const INLINE =
|
|
18
|
+
/`([^`\n]+)`|\*\*(\S(?:[^\n]*?\S)?)\*\*|\*([^\s*](?:[^*\n]*[^\s*])?)\*|(?<![\w])_([^\s_](?:[^_\n]*[^\s_])?)_(?![\w])/g;
|
|
19
|
+
|
|
20
|
+
// Backslash-escaped punctuation is swapped for private-use characters before
|
|
21
|
+
// any block or inline matching, so an escaped delimiter can never open or
|
|
22
|
+
// close anything. Leaves swap them back — code spans keep the backslash,
|
|
23
|
+
// matching CommonMark's "no escapes inside code" rule.
|
|
24
|
+
const ESCAPABLE = '\\`*_#-.)';
|
|
25
|
+
const ESCAPE = /\\([\\`*_#\-.)])/g;
|
|
26
|
+
const HIDDEN = /[-]/g;
|
|
27
|
+
|
|
28
|
+
function hideEscapes(text: string): string {
|
|
29
|
+
return text
|
|
30
|
+
.replace(HIDDEN, '')
|
|
31
|
+
.replace(ESCAPE, (_, ch: string) => String.fromCharCode(0xe000 + ESCAPABLE.indexOf(ch)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function restoreEscapes(text: string, keepBackslash: boolean): string {
|
|
35
|
+
return text.replace(HIDDEN, (ch) => {
|
|
36
|
+
const original = ESCAPABLE[ch.charCodeAt(0) - 0xe000];
|
|
37
|
+
return keepBackslash ? `\\${original}` : original;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function matchListItem(line: string): { ordered: boolean; content: string } | null {
|
|
42
|
+
const unordered = /^\s*[-*]\s+(.*)$/.exec(line);
|
|
43
|
+
if (unordered) return { ordered: false, content: unordered[1] };
|
|
44
|
+
const ordered = /^\s*\d{1,3}[.)]\s+(.*)$/.exec(line);
|
|
45
|
+
if (ordered) return { ordered: true, content: ordered[1] };
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseInlineHidden(text: string): NoteInline[] {
|
|
50
|
+
const out: NoteInline[] = [];
|
|
51
|
+
const pushText = (raw: string) => {
|
|
52
|
+
if (raw) out.push({ type: 'text', text: restoreEscapes(raw, false) });
|
|
53
|
+
};
|
|
54
|
+
let last = 0;
|
|
55
|
+
for (const m of text.matchAll(INLINE)) {
|
|
56
|
+
pushText(text.slice(last, m.index));
|
|
57
|
+
if (m[1] !== undefined) out.push({ type: 'code', text: restoreEscapes(m[1], true) });
|
|
58
|
+
else if (m[2] !== undefined) out.push({ type: 'strong', children: parseInlineHidden(m[2]) });
|
|
59
|
+
else out.push({ type: 'em', children: parseInlineHidden(m[3] ?? m[4]) });
|
|
60
|
+
last = m.index + m[0].length;
|
|
61
|
+
}
|
|
62
|
+
pushText(text.slice(last));
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function parseInline(text: string): NoteInline[] {
|
|
67
|
+
return parseInlineHidden(hideEscapes(text));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function parseNoteMarkdown(text: string): NoteBlock[] {
|
|
71
|
+
const lines = hideEscapes(text).split('\n');
|
|
72
|
+
const blocks: NoteBlock[] = [];
|
|
73
|
+
let i = 0;
|
|
74
|
+
while (i < lines.length) {
|
|
75
|
+
const trimmed = lines[i].trim();
|
|
76
|
+
if (trimmed === '') {
|
|
77
|
+
i++;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const heading = HEADING.exec(trimmed);
|
|
81
|
+
if (heading) {
|
|
82
|
+
blocks.push({
|
|
83
|
+
type: 'heading',
|
|
84
|
+
level: heading[1].length as 1 | 2 | 3,
|
|
85
|
+
children: parseInlineHidden(heading[2].trim()),
|
|
86
|
+
});
|
|
87
|
+
i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const item = matchListItem(lines[i]);
|
|
91
|
+
if (item) {
|
|
92
|
+
const items: NoteInline[][] = [];
|
|
93
|
+
while (i < lines.length) {
|
|
94
|
+
const next = matchListItem(lines[i]);
|
|
95
|
+
if (!next || next.ordered !== item.ordered) break;
|
|
96
|
+
items.push(parseInlineHidden(next.content.trim()));
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
blocks.push({ type: 'list', ordered: item.ordered, items });
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// Paragraph lines keep leading whitespace (rendered with pre-wrap) so
|
|
103
|
+
// plain-text notes don't lose manual indentation or spacing.
|
|
104
|
+
const paragraph = [parseInlineHidden(lines[i].trimEnd())];
|
|
105
|
+
i++;
|
|
106
|
+
while (i < lines.length) {
|
|
107
|
+
const next = lines[i];
|
|
108
|
+
const nextTrimmed = next.trim();
|
|
109
|
+
if (nextTrimmed === '' || HEADING.test(nextTrimmed) || matchListItem(next)) break;
|
|
110
|
+
paragraph.push(parseInlineHidden(next.trimEnd()));
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
blocks.push({ type: 'paragraph', lines: paragraph });
|
|
114
|
+
}
|
|
115
|
+
return blocks;
|
|
116
|
+
}
|
|
@@ -24,6 +24,7 @@ import { hasModifier, isBackwardKey, isForwardKey, isTypingTarget } from '@/lib/
|
|
|
24
24
|
import { useDocumentTitle } from '@/lib/use-document-title';
|
|
25
25
|
import { format, useLocale } from '@/lib/use-locale';
|
|
26
26
|
import { cn, pad2 } from '@/lib/utils';
|
|
27
|
+
import { NoteMarkdown } from '../components/note-markdown';
|
|
27
28
|
import {
|
|
28
29
|
type PresenterState,
|
|
29
30
|
usePresenterChannel,
|
|
@@ -591,11 +592,11 @@ function SpeakerNotes({ note }: { note: string | undefined }) {
|
|
|
591
592
|
</div>
|
|
592
593
|
</div>
|
|
593
594
|
<div
|
|
594
|
-
className="min-h-0 flex-1 overflow-y-auto rounded-[6px] border border-border bg-card p-3 leading-relaxed
|
|
595
|
+
className="min-h-0 flex-1 overflow-y-auto rounded-[6px] border border-border bg-card p-3 leading-relaxed text-card-foreground"
|
|
595
596
|
style={{ fontSize: NOTES_FONT_SIZES[sizeIndex] }}
|
|
596
597
|
>
|
|
597
598
|
{note?.trim() ? (
|
|
598
|
-
note
|
|
599
|
+
<NoteMarkdown text={note} />
|
|
599
600
|
) : (
|
|
600
601
|
<span className="text-muted-foreground">
|
|
601
602
|
{t.presenter.noNotesPrefix}
|
package/src/locale/en.ts
CHANGED
|
@@ -513,7 +513,7 @@ export const en: Locale = {
|
|
|
513
513
|
notesDrawer: {
|
|
514
514
|
toggle: 'Notes',
|
|
515
515
|
pageLabel: 'page {n}/{total}',
|
|
516
|
-
placeholder: 'Write speaker notes for this slide…',
|
|
516
|
+
placeholder: 'Write speaker notes for this slide (Markdown supported)…',
|
|
517
517
|
statusSaving: 'Saving…',
|
|
518
518
|
statusSaved: 'Saved',
|
|
519
519
|
statusError: 'Save failed: {msg}',
|
package/src/locale/ja.ts
CHANGED
|
@@ -520,7 +520,7 @@ export const ja: Locale = {
|
|
|
520
520
|
notesDrawer: {
|
|
521
521
|
toggle: '発表者ノート',
|
|
522
522
|
pageLabel: '{n} / {total} ページ',
|
|
523
|
-
placeholder: '
|
|
523
|
+
placeholder: 'このスライドの発表者ノートを記入(Markdown 対応)…',
|
|
524
524
|
statusSaving: '保存中…',
|
|
525
525
|
statusSaved: '保存済み',
|
|
526
526
|
statusError: '保存に失敗しました: {msg}',
|
package/src/locale/zh-cn.ts
CHANGED
|
@@ -510,7 +510,7 @@ export const zhCN: Locale = {
|
|
|
510
510
|
notesDrawer: {
|
|
511
511
|
toggle: '演讲备注',
|
|
512
512
|
pageLabel: '第 {n} / {total} 页',
|
|
513
|
-
placeholder: '
|
|
513
|
+
placeholder: '为这一页撰写演讲备注(支持 Markdown)…',
|
|
514
514
|
statusSaving: '保存中…',
|
|
515
515
|
statusSaved: '已保存',
|
|
516
516
|
statusError: '保存失败:{msg}',
|
package/src/locale/zh-tw.ts
CHANGED
|
@@ -510,7 +510,7 @@ export const zhTW: Locale = {
|
|
|
510
510
|
notesDrawer: {
|
|
511
511
|
toggle: '講稿',
|
|
512
512
|
pageLabel: '第 {n} / {total} 頁',
|
|
513
|
-
placeholder: '
|
|
513
|
+
placeholder: '為這一頁撰寫演講備忘(支援 Markdown)…',
|
|
514
514
|
statusSaving: '儲存中…',
|
|
515
515
|
statusSaved: '已儲存',
|
|
516
516
|
statusError: '儲存失敗:{msg}',
|