@aparte/plugin-marked 0.27.4 → 0.28.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/README.md +19 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/math.d.ts +35 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +228 -0
- package/dist/math.js.map +1 -0
- package/dist/scan.d.ts +82 -0
- package/dist/scan.d.ts.map +1 -0
- package/dist/streaming.d.ts +9 -3
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +23 -8
- package/dist/streaming.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,3 +33,22 @@ the blocks above it are not. Every block goes through the config's sanitizer. `r
|
|
|
33
33
|
dependency of this plugin, imported by the `/streaming` entry only.
|
|
34
34
|
|
|
35
35
|
> ESM-only. Part of the aparté monorepo.
|
|
36
|
+
|
|
37
|
+
## Maths
|
|
38
|
+
|
|
39
|
+
Install `@aparte/plugin-katex` and marked hands it every formula — `$…$`, `$$…$$`, `\(…\)`,
|
|
40
|
+
`\[…\]` — instead of reading the TeX as Markdown (`\,` and `a*b*c` mean something else to it). It
|
|
41
|
+
turns on by itself when a `math` renderer is registered; `MarkedProviderOptions.math` forces it
|
|
42
|
+
either way:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
setupMarkedProvider({ math: false }); // leave dollars as text, whatever is registered
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A single `$` follows Pandoc's rule, so `$5 and $10` stays text; a formula never crosses a blank
|
|
49
|
+
line, code wins over it, and escaped brackets such as `\[1\]` stay brackets. While a reply streams,
|
|
50
|
+
a formula is drawn as it arrives.
|
|
51
|
+
|
|
52
|
+
With maths on, rendering runs on a marked instance of the plugin's own, so an extension you added
|
|
53
|
+
to the global `marked` with `marked.use()` does not apply: pass your marked options to
|
|
54
|
+
`setupMarkedProvider(options)` instead.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import { type AparteConfig } from '@aparte/core';
|
|
2
2
|
import { type MarkedExtension } from 'marked';
|
|
3
|
+
/**
|
|
4
|
+
* Options for the marked providers: marked's own (a renderer, `gfm`/`breaks`, hooks),
|
|
5
|
+
* and whether maths is recognised.
|
|
6
|
+
*/
|
|
7
|
+
export interface MarkedProviderOptions extends MarkedExtension {
|
|
8
|
+
/**
|
|
9
|
+
* Recognise maths — `$…$`, `$$…$$`, `\(…\)`, `\[…\]` — and hand it to the `math`
|
|
10
|
+
* renderer (`@aparte/plugin-katex`) instead of reading it as Markdown. By default it
|
|
11
|
+
* is on exactly when a `math` renderer is registered on the config, so installing
|
|
12
|
+
* one is enough; `true` or `false` forces it.
|
|
13
|
+
*/
|
|
14
|
+
math?: boolean;
|
|
15
|
+
}
|
|
3
16
|
/**
|
|
4
17
|
* Register [marked](https://marked.js.org) as aparté's one-shot Markdown
|
|
5
18
|
* provider — the renderer used for finished / re-rendered message bubbles.
|
|
6
19
|
* (For token-by-token incremental rendering, add `@aparte/plugin-streaming-markdown`.)
|
|
7
20
|
*
|
|
21
|
+
* Maths is recognised as soon as a `math` renderer is registered
|
|
22
|
+
* (`@aparte/plugin-katex`); see {@link MarkedProviderOptions.math}.
|
|
23
|
+
*
|
|
8
24
|
* Call once at application startup.
|
|
9
25
|
*
|
|
10
26
|
* @param options Optional marked extension(s) — custom renderer, `gfm`/`breaks`
|
|
11
|
-
* flags, hooks, etc.
|
|
27
|
+
* flags, hooks, etc. — applied to a private marked instance; and `math`.
|
|
12
28
|
*
|
|
13
29
|
* @example
|
|
14
30
|
* import { setupMarkedProvider } from '@aparte/plugin-marked';
|
|
15
31
|
* setupMarkedProvider({ gfm: true, breaks: true });
|
|
16
32
|
*/
|
|
17
|
-
export declare function setupMarkedProvider(options?:
|
|
33
|
+
export declare function setupMarkedProvider(options?: MarkedProviderOptions, config?: AparteConfig): void;
|
|
18
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,YAAY,EAAC,MAAM,cAAc,CAAC;AACrE,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,YAAY,EAAC,MAAM,cAAc,CAAC;AACrE,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;AAG9D;;;GAGG;AACH,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC1D;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AA0BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,MAAM,GAAE,YAAiC,GAAG,IAAI,CAMpH"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { aparteGlobalConfig } from "@aparte/core";
|
|
2
2
|
import { Marked, marked } from "marked";
|
|
3
|
+
import { m as markedMath } from "./math.js";
|
|
4
|
+
function markedParsers(options, config) {
|
|
5
|
+
const { math, ...extension } = options ?? {};
|
|
6
|
+
const scoped = options !== void 0 && (math === void 0 || Object.keys(extension).length > 0);
|
|
7
|
+
const plain = scoped ? new Marked(extension) : marked;
|
|
8
|
+
let withMath;
|
|
9
|
+
return {
|
|
10
|
+
/** Whether maths is recognised right now — a renderer may be registered later. */
|
|
11
|
+
mathOn: () => math ?? config.hasCodeLanguageRenderer("math"),
|
|
12
|
+
plain,
|
|
13
|
+
finished: () => withMath ??= new Marked(extension, markedMath())
|
|
14
|
+
};
|
|
15
|
+
}
|
|
3
16
|
function setupMarkedProvider(options, config = aparteGlobalConfig) {
|
|
4
|
-
const
|
|
5
|
-
config.setMarkdownProvider((raw) =>
|
|
17
|
+
const parsers = markedParsers(options, config);
|
|
18
|
+
config.setMarkdownProvider((raw) => (parsers.mathOn() ? parsers.finished() : parsers.plain).parse(raw, { async: false }));
|
|
6
19
|
}
|
|
7
20
|
export {
|
|
8
21
|
setupMarkedProvider
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { aparteGlobalConfig , type AparteConfig} from '@aparte/core';\nimport { Marked, marked, type MarkedExtension } from 'marked';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { aparteGlobalConfig , type AparteConfig} from '@aparte/core';\nimport { Marked, marked, type MarkedExtension } from 'marked';\nimport { markedMath } from './math.js';\n\n/**\n * Options for the marked providers: marked's own (a renderer, `gfm`/`breaks`, hooks),\n * and whether maths is recognised.\n */\nexport interface MarkedProviderOptions extends MarkedExtension {\n /**\n * Recognise maths — `$…$`, `$$…$$`, `\\(…\\)`, `\\[…\\]` — and hand it to the `math`\n * renderer (`@aparte/plugin-katex`) instead of reading it as Markdown. By default it\n * is on exactly when a `math` renderer is registered on the config, so installing\n * one is enough; `true` or `false` forces it.\n */\n math?: boolean;\n}\n\n/**\n * The parsers a provider picks from on each render: plain Markdown, and Markdown that\n * recognises maths — made on first use, so a chat without maths never builds it.\n * (`/streaming` keeps a copy of this with a third parser, for the block still arriving.)\n *\n * With no options there is nothing to scope, so plain Markdown is the shared `marked`\n * singleton — one parser instead of one per chat. Options go to a PRIVATE instance,\n * not `marked.use()`: `marked` is module-level and `use()` mutates it cumulatively\n * with no undo, so a second chat set up with other options would have changed the first\n * chat's rendering.\n */\nfunction markedParsers(options: MarkedProviderOptions | undefined, config: AparteConfig) {\n const { math, ...extension } = options ?? {};\n const scoped = options !== undefined && (math === undefined || Object.keys(extension).length > 0);\n const plain = scoped ? new Marked(extension) : marked;\n let withMath: Marked | undefined;\n return {\n /** Whether maths is recognised right now — a renderer may be registered later. */\n mathOn: (): boolean => math ?? config.hasCodeLanguageRenderer('math'),\n plain,\n finished: (): Marked => (withMath ??= new Marked(extension, markedMath())),\n };\n}\n\n/**\n * Register [marked](https://marked.js.org) as aparté's one-shot Markdown\n * provider — the renderer used for finished / re-rendered message bubbles.\n * (For token-by-token incremental rendering, add `@aparte/plugin-streaming-markdown`.)\n *\n * Maths is recognised as soon as a `math` renderer is registered\n * (`@aparte/plugin-katex`); see {@link MarkedProviderOptions.math}.\n *\n * Call once at application startup.\n *\n * @param options Optional marked extension(s) — custom renderer, `gfm`/`breaks`\n * flags, hooks, etc. — applied to a private marked instance; and `math`.\n *\n * @example\n * import { setupMarkedProvider } from '@aparte/plugin-marked';\n * setupMarkedProvider({ gfm: true, breaks: true });\n */\nexport function setupMarkedProvider(options?: MarkedProviderOptions, config: AparteConfig = aparteGlobalConfig): void {\n const parsers = markedParsers(options, config);\n // aparté's markdown provider is synchronous `(raw) => string`; `async: false`\n // makes marked return a string rather than a Promise.\n config.setMarkdownProvider((raw) =>\n (parsers.mathOn() ? parsers.finished() : parsers.plain).parse(raw, { async: false }) as string);\n}\n"],"names":[],"mappings":";;;AA6BA,SAAS,cAAc,SAA4C,QAAsB;AACrF,QAAM,EAAE,MAAM,GAAG,UAAA,IAAc,WAAW,CAAA;AAC1C,QAAM,SAAS,YAAY,WAAc,SAAS,UAAa,OAAO,KAAK,SAAS,EAAE,SAAS;AAC/F,QAAM,QAAQ,SAAS,IAAI,OAAO,SAAS,IAAI;AAC/C,MAAI;AACJ,SAAO;AAAA;AAAA,IAEH,QAAQ,MAAe,QAAQ,OAAO,wBAAwB,MAAM;AAAA,IACpE;AAAA,IACA,UAAU,MAAe,aAAa,IAAI,OAAO,WAAW,YAAY;AAAA,EAAA;AAEhF;AAmBO,SAAS,oBAAoB,SAAiC,SAAuB,oBAA0B;AAClH,QAAM,UAAU,cAAc,SAAS,MAAM;AAG7C,SAAO,oBAAoB,CAAC,SACvB,QAAQ,OAAA,IAAW,QAAQ,SAAA,IAAa,QAAQ,OAAO,MAAM,KAAK,EAAE,OAAO,MAAA,CAAO,CAAW;AACtG;"}
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MarkedExtension } from 'marked';
|
|
2
|
+
/**
|
|
3
|
+
* Maths in Markdown, recognised before Markdown can touch it.
|
|
4
|
+
*
|
|
5
|
+
* marked reads TeX as Markdown: `\,` and `\\` are escapes to it, `a*b*c` is emphasis,
|
|
6
|
+
* `x_1 + y_2` is too. So maths has to be claimed by the tokenizer, ahead of escapes and
|
|
7
|
+
* emphasis — which is what a marked extension's tokenizer is — and written out as the
|
|
8
|
+
* placeholder every code-language renderer reads: `<code class="language-math
|
|
9
|
+
* math-inline">TeX</code>` inline, `<pre><code class="language-math math-display">`
|
|
10
|
+
* for a block. A renderer such as `@aparte/plugin-katex` draws it; with none, the TeX
|
|
11
|
+
* shows intact, as code.
|
|
12
|
+
*
|
|
13
|
+
* The delimiters: `$$…$$` and `\[…\]` for display maths (a block on its own lines, or
|
|
14
|
+
* inside a paragraph), `\(…\)` and `$…$` inline. A single `$` follows Pandoc's rule, so
|
|
15
|
+
* a price stays a price: the opening `$` has a character right after it, the closing one
|
|
16
|
+
* a character right before it and no digit right after it — `$5 and $10` is text. A
|
|
17
|
+
* backquote before the closer ends the attempt: code wins. So does a blank line, and a
|
|
18
|
+
* line opening a block TeX never starts a line with (a `~~~` fence, a heading, a quote,
|
|
19
|
+
* an HTML block, a rule; a list item after `$$ is the PID`).
|
|
20
|
+
*/
|
|
21
|
+
export interface MarkedMathOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Read a formula that has not closed yet as one still arriving, marked
|
|
24
|
+
* `data-aparte-open`, instead of as text — while nothing it cannot run into has come
|
|
25
|
+
* after it, since then it can never close. For the block a stream is still writing;
|
|
26
|
+
* never for finished text, where an unclosed `\(` is just a parenthesis.
|
|
27
|
+
*/
|
|
28
|
+
live?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The marked extension: maths as code-language placeholders. Internal: the providers in
|
|
32
|
+
* this package install it when a `math` renderer is registered.
|
|
33
|
+
*/
|
|
34
|
+
export declare function markedMath(options?: MarkedMathOptions): MarkedExtension;
|
|
35
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAqB,MAAM,QAAQ,CAAC;AAGjE;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,iBAAiB;IAC9B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAmBD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAgF3E"}
|
package/dist/math.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
const isSpace = (c) => c === void 0 || /\s/.test(c);
|
|
2
|
+
function blankLineAt(src, i) {
|
|
3
|
+
if (src[i] !== "\n") return false;
|
|
4
|
+
for (let j = i + 1; j < src.length; j++) {
|
|
5
|
+
if (src[j] === "\n") return true;
|
|
6
|
+
if (src[j] !== " " && src[j] !== " ") return false;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const BLOCK_LINE = /^ {0,3}(?:~~~|#{1,6}(?:[ \t]|$)|>|<(?:[/!?]|(?:address|article|aside|blockquote|details|dialog|div|dl|fieldset|figure|footer|form|h[1-6]|header|hr|li|main|nav|ol|p|pre|script|section|style|table|textarea|ul)(?=[\s/>]|$))|([-*_])(?:[ \t]*\1){2,}[ \t]*$)/i;
|
|
11
|
+
const LIST_LINE = /^ {0,3}(?:[-+*]|\d{1,9}[.)])[ \t]/;
|
|
12
|
+
function blockLineAt(src, i, listStops) {
|
|
13
|
+
const next = src.indexOf("\n", i + 1);
|
|
14
|
+
const line = src.slice(i + 1, next < 0 ? src.length : next);
|
|
15
|
+
return BLOCK_LINE.test(line) || listStops && LIST_LINE.test(line);
|
|
16
|
+
}
|
|
17
|
+
function scanBody(src, from, close) {
|
|
18
|
+
const eol = src.indexOf("\n", from);
|
|
19
|
+
const listStops = /\S/.test(src.slice(from, eol < 0 ? src.length : eol));
|
|
20
|
+
for (let i = from; i < src.length; i++) {
|
|
21
|
+
if (close !== "" && src.startsWith(close, i)) return { at: i, closed: true };
|
|
22
|
+
if (src[i] === "`" || src[i] === "\n" && (blankLineAt(src, i) || blockLineAt(src, i, listStops))) return { at: i, closed: false };
|
|
23
|
+
if (src[i] === "\\" && close !== "\\)" && close !== "\\]") i++;
|
|
24
|
+
}
|
|
25
|
+
return { at: src.length, closed: false };
|
|
26
|
+
}
|
|
27
|
+
function dollarCloser(src) {
|
|
28
|
+
if (src[0] !== "$" || isSpace(src[1]) || src[1] === "$") return -1;
|
|
29
|
+
let depth = 0;
|
|
30
|
+
for (let i = 1; i < src.length; i++) {
|
|
31
|
+
const c = src[i];
|
|
32
|
+
if (c === "\\") {
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (c === "`" || blankLineAt(src, i)) return -1;
|
|
37
|
+
if (c === "{") {
|
|
38
|
+
depth++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (c === "}") {
|
|
42
|
+
depth = Math.max(0, depth - 1);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (c !== "$" || depth > 0) continue;
|
|
46
|
+
if (isSpace(src[i - 1]) || /\d/.test(src[i + 1] ?? "")) return -1;
|
|
47
|
+
return i;
|
|
48
|
+
}
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
function closerAfter(src, from, close) {
|
|
52
|
+
const { at, closed } = scanBody(src, from, close);
|
|
53
|
+
return closed ? at : -1;
|
|
54
|
+
}
|
|
55
|
+
function openEnd(src, from, close) {
|
|
56
|
+
return scanBody(src, from, close).at;
|
|
57
|
+
}
|
|
58
|
+
function isEscapedBrackets(open, text, before) {
|
|
59
|
+
if (!open.startsWith("\\")) return false;
|
|
60
|
+
return /[\p{L}\p{N}]$/u.test(before) || /^\s*[\d.,]*\s*$/.test(text);
|
|
61
|
+
}
|
|
62
|
+
const PAIRS = [
|
|
63
|
+
{ open: "$$", close: "$$", display: true },
|
|
64
|
+
{ open: "\\[", close: "\\]", display: true },
|
|
65
|
+
{ open: "\\(", close: "\\)", display: false }
|
|
66
|
+
];
|
|
67
|
+
function mathSpans(src, open) {
|
|
68
|
+
const spans = [];
|
|
69
|
+
let openDollar = -1;
|
|
70
|
+
for (let i = 0; i < src.length; ) {
|
|
71
|
+
const c = src[i];
|
|
72
|
+
if (c === "`") {
|
|
73
|
+
const run = /^`+/.exec(src.slice(i))[0];
|
|
74
|
+
const close = src.indexOf(run, i + run.length);
|
|
75
|
+
i = close === -1 ? i + run.length : close + run.length;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
let end = -1;
|
|
79
|
+
const pair = PAIRS.find((p) => src.startsWith(p.open, i));
|
|
80
|
+
if (pair) {
|
|
81
|
+
const from = i + pair.open.length;
|
|
82
|
+
const close = closerAfter(src, from, pair.close);
|
|
83
|
+
if (close !== -1) end = close + pair.close.length;
|
|
84
|
+
else if (open) end = openEnd(src, from, pair.close);
|
|
85
|
+
} else if (c === "\\") {
|
|
86
|
+
i += 2;
|
|
87
|
+
continue;
|
|
88
|
+
} else if (c === "$") {
|
|
89
|
+
const close = dollarCloser(src.slice(i));
|
|
90
|
+
if (close !== -1) end = i + close + 1;
|
|
91
|
+
else if (openDollar < 0 && !isSpace(src[i + 1]) && src[i + 1] !== "$") openDollar = i;
|
|
92
|
+
}
|
|
93
|
+
if (end <= i) {
|
|
94
|
+
i++;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
spans.push([i, end]);
|
|
98
|
+
i = end;
|
|
99
|
+
}
|
|
100
|
+
return { spans, openDollar };
|
|
101
|
+
}
|
|
102
|
+
function maskMath(src) {
|
|
103
|
+
const { spans, openDollar } = mathSpans(src, true);
|
|
104
|
+
if (openDollar >= 0) {
|
|
105
|
+
const end = openEnd(src, openDollar + 1, "");
|
|
106
|
+
if (!spans.some(([a, b]) => a < end && b > openDollar)) {
|
|
107
|
+
for (let k = openDollar; k < end; k++) if (src[k] === "[") spans.push([k, k + 1]);
|
|
108
|
+
spans.sort((a, b) => a[0] - b[0]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const kept = [];
|
|
112
|
+
let out = "";
|
|
113
|
+
let at = 0;
|
|
114
|
+
for (const [start, end] of spans) {
|
|
115
|
+
out += src.slice(at, start) + `${kept.length}`;
|
|
116
|
+
kept.push(src.slice(start, end));
|
|
117
|
+
at = end;
|
|
118
|
+
}
|
|
119
|
+
out += src.slice(at);
|
|
120
|
+
return {
|
|
121
|
+
masked: out,
|
|
122
|
+
unmask: (s) => s.replace(/\uE000(\d+)\uE001/g, (_m, n) => kept[Number(n)] ?? "")
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function blankMath(src, masked) {
|
|
126
|
+
const offset = masked.length - src.length;
|
|
127
|
+
let reading = "";
|
|
128
|
+
for (let i = 0; i < src.length; i++) reading += masked[offset + i] === "+" ? src[i] : masked[offset + i];
|
|
129
|
+
reading = reading.replace(/\[a+\]/g, (run) => `\`${"a".repeat(run.length - 2)}\``);
|
|
130
|
+
const spans = mathSpans(reading, false).spans.filter(([start, end]) => !isEscapedBrackets(reading.slice(start, start + 2), reading.slice(start + 2, end - 2), reading.slice(0, start)));
|
|
131
|
+
let out = masked.slice(0, offset);
|
|
132
|
+
let at = 0;
|
|
133
|
+
for (const [start, end] of spans) {
|
|
134
|
+
out += masked.slice(offset + at, offset + start) + "a".repeat(end - start);
|
|
135
|
+
at = end;
|
|
136
|
+
}
|
|
137
|
+
return out + masked.slice(offset + at);
|
|
138
|
+
}
|
|
139
|
+
const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
140
|
+
function placeholder(token, block) {
|
|
141
|
+
const open = token.open ? " data-aparte-open" : "";
|
|
142
|
+
const kind = token.display ? "math-display" : "math-inline";
|
|
143
|
+
const code = `<code class="language-math ${kind}"${open}>${escapeHtml(token.text)}</code>`;
|
|
144
|
+
return block ? `<pre${open}>${code}</pre>
|
|
145
|
+
` : code;
|
|
146
|
+
}
|
|
147
|
+
function markedMath(options = {}) {
|
|
148
|
+
const live = options.live === true;
|
|
149
|
+
return {
|
|
150
|
+
// marked looks ahead for the `*`, `_` or `~` closing an emphasis or a strikethrough
|
|
151
|
+
// on a masked copy of the text; a formula left in it closes an italic opened before
|
|
152
|
+
// it (`*the optimum $x^*$*`). Its `emStrongMask` hook cannot hide one: it receives a
|
|
153
|
+
// copy where `\(` is already `++`, so the formulas are found on the real text here.
|
|
154
|
+
// marked's own tokenizer is reached through the instance's prototype, not imported:
|
|
155
|
+
// this module is the chunk both entries share, and it imports nothing from marked.
|
|
156
|
+
tokenizer: {
|
|
157
|
+
emStrong(src, maskedSrc, prevChar) {
|
|
158
|
+
return Object.getPrototypeOf(this).emStrong.call(this, src, blankMath(src, maskedSrc), prevChar);
|
|
159
|
+
},
|
|
160
|
+
del(src, maskedSrc, prevChar) {
|
|
161
|
+
return Object.getPrototypeOf(this).del.call(this, src, blankMath(src, maskedSrc), prevChar);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
extensions: [
|
|
165
|
+
{
|
|
166
|
+
name: "aparteMathBlock",
|
|
167
|
+
level: "block",
|
|
168
|
+
// Where a block may start inside this paragraph. marked hands `start` the
|
|
169
|
+
// source minus its first character, so only a real newline marks a line.
|
|
170
|
+
start(src) {
|
|
171
|
+
const stop = src.search(/\n[ \t]*\n/);
|
|
172
|
+
const m = /\n {0,3}(\$\$|\\\[)/.exec(stop < 0 ? src : src.slice(0, stop));
|
|
173
|
+
return m ? m.index + 1 : void 0;
|
|
174
|
+
},
|
|
175
|
+
tokenizer(src) {
|
|
176
|
+
const head = /^ {0,3}(\$\$|\\\[)/.exec(src);
|
|
177
|
+
if (!head) return void 0;
|
|
178
|
+
const pair = PAIRS.find((p) => p.open === head[1]);
|
|
179
|
+
const from = head[0].length;
|
|
180
|
+
const end = closerAfter(src, from, pair.close);
|
|
181
|
+
if (end === -1) {
|
|
182
|
+
if (!live || openEnd(src, from, pair.close) < src.length) return void 0;
|
|
183
|
+
return { type: "aparteMathBlock", raw: src, text: src.slice(from).trim(), display: true, open: true };
|
|
184
|
+
}
|
|
185
|
+
const text = src.slice(from, end).trim();
|
|
186
|
+
if (isEscapedBrackets(pair.open, text, "")) return void 0;
|
|
187
|
+
const rest = /^[ \t]*(\n|$)/.exec(src.slice(end + pair.close.length));
|
|
188
|
+
if (!rest) return void 0;
|
|
189
|
+
const raw = src.slice(0, end + pair.close.length + rest[0].length);
|
|
190
|
+
return { type: "aparteMathBlock", raw, text, display: true, open: false };
|
|
191
|
+
},
|
|
192
|
+
renderer: (token) => placeholder(token, true)
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "aparteMathInline",
|
|
196
|
+
level: "inline",
|
|
197
|
+
start(src) {
|
|
198
|
+
const i = src.search(/\$|\\[([]/);
|
|
199
|
+
return i === -1 ? void 0 : i;
|
|
200
|
+
},
|
|
201
|
+
tokenizer(src, tokens) {
|
|
202
|
+
for (const pair of PAIRS) {
|
|
203
|
+
if (!src.startsWith(pair.open)) continue;
|
|
204
|
+
const end2 = closerAfter(src, pair.open.length, pair.close);
|
|
205
|
+
if (end2 === -1) {
|
|
206
|
+
if (!live || pair.open !== "$$" && /[\p{L}\p{N}]$/u.test(tokens.at(-1)?.raw ?? "")) return void 0;
|
|
207
|
+
if (openEnd(src, pair.open.length, pair.close) < src.length) return void 0;
|
|
208
|
+
return { type: "aparteMathInline", raw: src, text: src.slice(pair.open.length), display: pair.display, open: true };
|
|
209
|
+
}
|
|
210
|
+
const text = src.slice(pair.open.length, end2);
|
|
211
|
+
if (isEscapedBrackets(pair.open, text, tokens.at(-1)?.raw ?? "")) return void 0;
|
|
212
|
+
const raw = src.slice(0, end2 + pair.close.length);
|
|
213
|
+
return { type: "aparteMathInline", raw, text, display: pair.display, open: false };
|
|
214
|
+
}
|
|
215
|
+
const end = dollarCloser(src);
|
|
216
|
+
if (end === -1) return void 0;
|
|
217
|
+
return { type: "aparteMathInline", raw: src.slice(0, end + 1), text: src.slice(1, end), display: false, open: false };
|
|
218
|
+
},
|
|
219
|
+
renderer: (token) => placeholder(token, false)
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
maskMath as a,
|
|
226
|
+
markedMath as m
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=math.js.map
|
package/dist/math.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sources":["../src/scan.ts","../src/math.ts"],"sourcesContent":["/**\n * Finding formulas in Markdown source: the scanners the maths tokenizer, its emphasis\n * mask and the streaming entry's `remend` mask share. Internal to the package.\n *\n * One rule set for all three, so what is maths to the tokenizer is exactly what the two\n * masks hide. A formula never crosses a blank line (Pandoc: maths lives inside one\n * paragraph), and code wins: a backquote before the closer ends the attempt. Nor does\n * it run into a line that opens a block TeX never starts a line with — a `~~~` fence,\n * a heading, a quote, an HTML block, a rule — or into a list item when the opener had\n * text after it (`$$ is the PID`): a `$$` alone on its line opens a display formula,\n * whose lines may start like one (`- x^2`).\n */\n\nconst isSpace = (c: string | undefined): boolean => c === undefined || /\\s/.test(c);\n\n/** A blank line at `i`: a newline, then only spaces or tabs up to the next one. */\nfunction blankLineAt(src: string, i: number): boolean {\n if (src[i] !== '\\n') return false;\n for (let j = i + 1; j < src.length; j++) {\n if (src[j] === '\\n') return true;\n if (src[j] !== ' ' && src[j] !== '\\t') return false;\n }\n return false;\n}\n\n/**\n * A line opening a block no formula runs into: a `~~~` fence, a heading, a quote, a rule,\n * an HTML block — only one that can interrupt a paragraph in CommonMark (a block tag, a\n * comment, a declaration), so a TeX line such as `<x, y> = 0` stays in its formula.\n */\nconst BLOCK_LINE = /^ {0,3}(?:~~~|#{1,6}(?:[ \\t]|$)|>|<(?:[/!?]|(?:address|article|aside|blockquote|details|dialog|div|dl|fieldset|figure|footer|form|h[1-6]|header|hr|li|main|nav|ol|p|pre|script|section|style|table|textarea|ul)(?=[\\s/>]|$))|([-*_])(?:[ \\t]*\\1){2,}[ \\t]*$)/i;\n/** A list item's line. */\nconst LIST_LINE = /^ {0,3}(?:[-+*]|\\d{1,9}[.)])[ \\t]/;\n\n/** Whether the newline at `i` starts a line a formula stops before. */\nfunction blockLineAt(src: string, i: number, listStops: boolean): boolean {\n const next = src.indexOf('\\n', i + 1);\n const line = src.slice(i + 1, next < 0 ? src.length : next);\n return BLOCK_LINE.test(line) || listStops && LIST_LINE.test(line);\n}\n\n/**\n * Scan the body of a formula from `from` for `close`, skipping TeX escapes (`\\$` inside\n * `$$…$$`): the closer's index, or where the scan gives up — at a backquote, a blank\n * line or a block's line — and `src.length` when it runs out of text first. An empty\n * `close` is never found.\n */\nfunction scanBody(src: string, from: number, close: string): { at: number; closed: boolean } {\n const eol = src.indexOf('\\n', from);\n const listStops = /\\S/.test(src.slice(from, eol < 0 ? src.length : eol));\n for (let i = from; i < src.length; i++) {\n if (close !== '' && src.startsWith(close, i)) return { at: i, closed: true };\n if (src[i] === '`' || src[i] === '\\n' && (blankLineAt(src, i) || blockLineAt(src, i, listStops))) return { at: i, closed: false };\n if (src[i] === '\\\\' && close !== '\\\\)' && close !== '\\\\]') i++;\n }\n return { at: src.length, closed: false };\n}\n\n/**\n * Index of the `$` closing a single-`$` formula that opens at 0, or -1 — Pandoc's rule,\n * which gives up rather than looking further: a `$` with a space before it ends the\n * attempt (`$a $b$` is text), and so does a closer with a digit after it (`$x$5`). A `$`\n * inside braces — `\\text{in $x$ units}` — is TeX, not the closer.\n */\nexport function dollarCloser(src: string): number {\n if (src[0] !== '$' || isSpace(src[1]) || src[1] === '$') return -1;\n let depth = 0;\n for (let i = 1; i < src.length; i++) {\n const c = src[i];\n if (c === '\\\\') { i++; continue; }\n if (c === '`' || blankLineAt(src, i)) return -1;\n if (c === '{') { depth++; continue; }\n if (c === '}') { depth = Math.max(0, depth - 1); continue; }\n if (c !== '$' || depth > 0) continue;\n if (isSpace(src[i - 1]) || /\\d/.test(src[i + 1] ?? '')) return -1;\n return i;\n }\n return -1;\n}\n\n/**\n * Index of `close` after `from`, skipping TeX escapes (`\\$` inside `$$…$$`), or -1 when\n * something a formula does not run into comes first: a backquote, a blank line, a\n * block's line.\n */\nexport function closerAfter(src: string, from: number, close: string): number {\n const { at, closed } = scanBody(src, from, close);\n return closed ? at : -1;\n}\n\n/**\n * Where a formula whose body starts at `from` and that `close` has not closed runs to:\n * where the scan for its closer gives up, by the same rule. Short of `src.length`, the\n * formula can never close — it has met something it does not run into.\n */\nexport function openEnd(src: string, from: number, close: string): number {\n return scanBody(src, from, close).at;\n}\n\n/**\n * Whether a `\\(…\\)` or `\\[…\\]` is a Markdown escape rather than maths: in Markdown those\n * are how a reply writes literal brackets — a citation `\\[1\\]`, an index `array\\[0\\]`. So\n * a pair that follows a letter or a digit, or holds nothing but a number, is left to\n * Markdown. A `$` or `$$` pair is never an escape.\n */\nexport function isEscapedBrackets(open: string, text: string, before: string): boolean {\n if (!open.startsWith('\\\\')) return false;\n return /[\\p{L}\\p{N}]$/u.test(before) || /^\\s*[\\d.,]*\\s*$/.test(text);\n}\n\n/** The delimiters a formula can open with, and what closes each. */\nexport const PAIRS: ReadonlyArray<{ open: string; close: string; display: boolean }> = [\n { open: '$$', close: '$$', display: true },\n { open: '\\\\[', close: '\\\\]', display: true },\n { open: '\\\\(', close: '\\\\)', display: false },\n];\n\n/**\n * The formulas in `src`, as `[start, end)` ranges. With `open`, a formula whose opener\n * has no closer yet runs to where the scan for its closer gives up, as one still\n * arriving; `openDollar` is where the first single `$` opens something nothing closes\n * yet (it may be a price), or -1.\n */\nexport function mathSpans(src: string, open: boolean): { spans: Array<[number, number]>; openDollar: number } {\n const spans: Array<[number, number]> = [];\n let openDollar = -1;\n for (let i = 0; i < src.length;) {\n const c = src[i]!;\n if (c === '`') {\n const run = /^`+/.exec(src.slice(i))![0];\n const close = src.indexOf(run, i + run.length);\n i = close === -1 ? i + run.length : close + run.length;\n continue;\n }\n let end = -1;\n const pair = PAIRS.find((p) => src.startsWith(p.open, i));\n if (pair) {\n const from = i + pair.open.length;\n const close = closerAfter(src, from, pair.close);\n if (close !== -1) end = close + pair.close.length;\n else if (open) end = openEnd(src, from, pair.close);\n } else if (c === '\\\\') {\n // A Markdown escape, as marked reads one where no formula opens: `\\$` is a\n // dollar, and `\\\\(` a backslash before a parenthesis.\n i += 2;\n continue;\n } else if (c === '$') {\n const close = dollarCloser(src.slice(i));\n if (close !== -1) end = i + close + 1;\n else if (openDollar < 0 && !isSpace(src[i + 1]) && src[i + 1] !== '$') openDollar = i;\n }\n if (end <= i) { i++; continue; }\n spans.push([i, end]);\n i = end;\n }\n return { spans, openDollar };\n}\n\n/**\n * Hide the maths in `src` from a text rewriter, and put it back afterwards.\n *\n * `remend` completes Markdown as it streams — it closes `**`, a backquote, a link — and\n * it reads TeX as Markdown too, so it \"completes\" `\\[ a+b` into a link and the `_` of\n * `x_1` into emphasis. Each formula is swapped for a private-use marker it cannot read,\n * the rewriter runs, and the formulas go back. Code spans are left as they are.\n *\n * An opener that will never close — `\\[ a` followed by a backquote — is text to the\n * tokenizer but stays hidden up to where it stops: remend ignores the backslash, and\n * would complete that `[` into a link whose tail marked then prints as text.\n */\nexport function maskMath(src: string): { masked: string; unmask: (s: string) => string } {\n const { spans, openDollar } = mathSpans(src, true);\n // A single `$` still open may be a formula on its way: `$[a, b` of an interval, whose\n // bracket remend would complete into a link — and its `links: false` does not stop it.\n // So each bracket after it is hidden, and only the brackets: a price (`$10/month`)\n // must not cost the rest of the paragraph its healing. A real link after the price\n // only loses its pending look until it is complete.\n if (openDollar >= 0) {\n const end = openEnd(src, openDollar + 1, '');\n if (!spans.some(([a, b]) => a < end && b > openDollar)) {\n for (let k = openDollar; k < end; k++) if (src[k] === '[') spans.push([k, k + 1]);\n spans.sort((a, b) => a[0] - b[0]);\n }\n }\n const kept: string[] = [];\n let out = '';\n let at = 0;\n for (const [start, end] of spans) {\n out += src.slice(at, start) + `\\uE000${kept.length}\\uE001`;\n kept.push(src.slice(start, end));\n at = end;\n }\n out += src.slice(at);\n return {\n masked: out,\n unmask: (s) => s.replace(/\\uE000(\\d+)\\uE001/g, (_m, n: string) => kept[Number(n)] ?? ''),\n };\n}\n\n/**\n * marked's masked copy of the text, with every formula in `src` blanked too, for its\n * emphasis and strikethrough scans: they look ahead for the closing `*`, `_` or `~` on\n * that copy, and a `*` inside `$x^*$` would otherwise close an italic opened before the\n * formula.\n *\n * `src` is the text from where the tokenizer stands; `masked` is marked's copy of the\n * whole text, of the same length, so `src` lines up with its tail — as marked's own\n * scans read it.\n */\nexport function blankMath(src: string, masked: string): string {\n const offset = masked.length - src.length;\n // marked's copy is no place to look for maths: every backslash escape is `++` in it,\n // `\\(` and `\\[` included. Read the real text, except where marked set a code span, a\n // link or a tag aside as `[aaa]` — read as code, since the tokenizer never looks for\n // a formula inside one.\n let reading = '';\n for (let i = 0; i < src.length; i++) reading += masked[offset + i] === '+' ? src[i]! : masked[offset + i]!;\n reading = reading.replace(/\\[a+\\]/g, (run) => `\\`${'a'.repeat(run.length - 2)}\\``);\n // Only the formulas the tokenizer will draw. Not one still open: the `**` remend adds\n // after `**Theorem \\(f` closes the bold around it, not inside it. Nor brackets the\n // tokenizer leaves escaped (`array\\[i*\\]`), which marked reads as it always has.\n const spans = mathSpans(reading, false).spans\n .filter(([start, end]) => !isEscapedBrackets(reading.slice(start, start + 2), reading.slice(start + 2, end - 2), reading.slice(0, start)));\n let out = masked.slice(0, offset);\n let at = 0;\n for (const [start, end] of spans) {\n out += masked.slice(offset + at, offset + start) + 'a'.repeat(end - start);\n at = end;\n }\n return out + masked.slice(offset + at);\n}\n","import type { MarkedExtension, Tokenizer, Tokens } from 'marked';\nimport { PAIRS, blankMath, closerAfter, dollarCloser, isEscapedBrackets, openEnd } from './scan.js';\n\n/**\n * Maths in Markdown, recognised before Markdown can touch it.\n *\n * marked reads TeX as Markdown: `\\,` and `\\\\` are escapes to it, `a*b*c` is emphasis,\n * `x_1 + y_2` is too. So maths has to be claimed by the tokenizer, ahead of escapes and\n * emphasis — which is what a marked extension's tokenizer is — and written out as the\n * placeholder every code-language renderer reads: `<code class=\"language-math\n * math-inline\">TeX</code>` inline, `<pre><code class=\"language-math math-display\">`\n * for a block. A renderer such as `@aparte/plugin-katex` draws it; with none, the TeX\n * shows intact, as code.\n *\n * The delimiters: `$$…$$` and `\\[…\\]` for display maths (a block on its own lines, or\n * inside a paragraph), `\\(…\\)` and `$…$` inline. A single `$` follows Pandoc's rule, so\n * a price stays a price: the opening `$` has a character right after it, the closing one\n * a character right before it and no digit right after it — `$5 and $10` is text. A\n * backquote before the closer ends the attempt: code wins. So does a blank line, and a\n * line opening a block TeX never starts a line with (a `~~~` fence, a heading, a quote,\n * an HTML block, a rule; a list item after `$$ is the PID`).\n */\n\nexport interface MarkedMathOptions {\n /**\n * Read a formula that has not closed yet as one still arriving, marked\n * `data-aparte-open`, instead of as text — while nothing it cannot run into has come\n * after it, since then it can never close. For the block a stream is still writing;\n * never for finished text, where an unclosed `\\(` is just a parenthesis.\n */\n live?: boolean;\n}\n\nconst escapeHtml = (s: string): string =>\n s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"');\n\n\ninterface MathToken extends Tokens.Generic {\n text: string;\n display: boolean;\n open: boolean;\n}\n\nfunction placeholder(token: MathToken, block: boolean): string {\n const open = token.open ? ' data-aparte-open' : '';\n const kind = token.display ? 'math-display' : 'math-inline';\n const code = `<code class=\"language-math ${kind}\"${open}>${escapeHtml(token.text)}</code>`;\n return block ? `<pre${open}>${code}</pre>\\n` : code;\n}\n\n/**\n * The marked extension: maths as code-language placeholders. Internal: the providers in\n * this package install it when a `math` renderer is registered.\n */\nexport function markedMath(options: MarkedMathOptions = {}): MarkedExtension {\n const live = options.live === true;\n return {\n // marked looks ahead for the `*`, `_` or `~` closing an emphasis or a strikethrough\n // on a masked copy of the text; a formula left in it closes an italic opened before\n // it (`*the optimum $x^*$*`). Its `emStrongMask` hook cannot hide one: it receives a\n // copy where `\\(` is already `++`, so the formulas are found on the real text here.\n // marked's own tokenizer is reached through the instance's prototype, not imported:\n // this module is the chunk both entries share, and it imports nothing from marked.\n tokenizer: {\n emStrong(src, maskedSrc, prevChar) {\n return (Object.getPrototypeOf(this) as Tokenizer).emStrong.call(this, src, blankMath(src, maskedSrc), prevChar);\n },\n del(src, maskedSrc, prevChar) {\n return (Object.getPrototypeOf(this) as Tokenizer).del.call(this, src, blankMath(src, maskedSrc), prevChar);\n },\n },\n extensions: [\n {\n name: 'aparteMathBlock',\n level: 'block',\n // Where a block may start inside this paragraph. marked hands `start` the\n // source minus its first character, so only a real newline marks a line.\n start(src: string) {\n const stop = src.search(/\\n[ \\t]*\\n/);\n const m = /\\n {0,3}(\\$\\$|\\\\\\[)/.exec(stop < 0 ? src : src.slice(0, stop));\n return m ? m.index + 1 : undefined;\n },\n tokenizer(src: string): MathToken | undefined {\n const head = /^ {0,3}(\\$\\$|\\\\\\[)/.exec(src);\n if (!head) return undefined;\n const pair = PAIRS.find((p) => p.open === head[1])!;\n const from = head[0].length;\n const end = closerAfter(src, from, pair.close);\n if (end === -1) {\n // Still arriving only while it runs to the end of what has come:\n // past a blank line, a backquote or a block's line it can never\n // close, and it is text — the paragraph it begins, as at the end.\n if (!live || openEnd(src, from, pair.close) < src.length) return undefined;\n return { type: 'aparteMathBlock', raw: src, text: src.slice(from).trim(), display: true, open: true };\n }\n const text = src.slice(from, end).trim();\n if (isEscapedBrackets(pair.open, text, '')) return undefined;\n // A block owns its last line: text after the closer makes it inline maths.\n const rest = /^[ \\t]*(\\n|$)/.exec(src.slice(end + pair.close.length));\n if (!rest) return undefined;\n const raw = src.slice(0, end + pair.close.length + rest[0].length);\n return { type: 'aparteMathBlock', raw, text, display: true, open: false };\n },\n renderer: (token) => placeholder(token as MathToken, true),\n },\n {\n name: 'aparteMathInline',\n level: 'inline',\n start(src: string) {\n const i = src.search(/\\$|\\\\[([]/);\n return i === -1 ? undefined : i;\n },\n tokenizer(src: string, tokens: Array<{ raw: string }>): MathToken | undefined {\n for (const pair of PAIRS) {\n if (!src.startsWith(pair.open)) continue;\n const end = closerAfter(src, pair.open.length, pair.close);\n if (end === -1) {\n if (!live || pair.open !== '$$' && /[\\p{L}\\p{N}]$/u.test(tokens.at(-1)?.raw ?? '')) return undefined;\n if (openEnd(src, pair.open.length, pair.close) < src.length) return undefined;\n return { type: 'aparteMathInline', raw: src, text: src.slice(pair.open.length), display: pair.display, open: true };\n }\n const text = src.slice(pair.open.length, end);\n if (isEscapedBrackets(pair.open, text, tokens.at(-1)?.raw ?? '')) return undefined;\n const raw = src.slice(0, end + pair.close.length);\n return { type: 'aparteMathInline', raw, text, display: pair.display, open: false };\n }\n const end = dollarCloser(src);\n if (end === -1) return undefined;\n return { type: 'aparteMathInline', raw: src.slice(0, end + 1), text: src.slice(1, end), display: false, open: false };\n },\n renderer: (token) => placeholder(token as MathToken, false),\n },\n ],\n };\n}\n"],"names":["end"],"mappings":"AAaA,MAAM,UAAU,CAAC,MAAmC,MAAM,UAAa,KAAK,KAAK,CAAC;AAGlF,SAAS,YAAY,KAAa,GAAoB;AAClD,MAAI,IAAI,CAAC,MAAM,KAAM,QAAO;AAC5B,WAAS,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACrC,QAAI,IAAI,CAAC,MAAM,KAAM,QAAO;AAC5B,QAAI,IAAI,CAAC,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IAAI,IAAI,OAAQ,QAAO;AACpE,qBAAO,EAAE,MAAM,oBAAoB,KAAK,KAAK,MAAM,IAAI,MAAM,KAAK,KAAK,MAAM,GAAG,SAAS,KAAK,SAAS,MAAM,KAAA;AAAA,YACjH;AACA,kBAAM,OAAO,IAAI,MAAM,KAAK,KAAK,QAAQA,IAAG;AAC5C,gBAAI,kBAAkB,KAAK,MAAM,MAAM,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,EAAG,QAAO;AACzE,kBAAM,MAAM,IAAI,MAAM,GAAGA,OAAM,KAAK,MAAM,MAAM;AAChD,mBAAO,EAAE,MAAM,oBAAoB,KAAK,MAAM,SAAS,KAAK,SAAS,MAAM,MAAA;AAAA,UAC/E;AACA,gBAAM,MAAM,aAAa,GAAG;AAC5B,cAAI,QAAQ,GAAI,QAAO;AACvB,iBAAO,EAAE,MAAM,oBAAoB,KAAK,IAAI,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,GAAG,GAAG,GAAG,SAAS,OAAO,MAAM,MAAA;AAAA,QAClH;AAAA,QACA,UAAU,CAAC,UAAU,YAAY,OAAoB,KAAK;AAAA,MAAA;AAAA,IAC9D;AAAA,EACJ;AAER;"}
|
package/dist/scan.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding formulas in Markdown source: the scanners the maths tokenizer, its emphasis
|
|
3
|
+
* mask and the streaming entry's `remend` mask share. Internal to the package.
|
|
4
|
+
*
|
|
5
|
+
* One rule set for all three, so what is maths to the tokenizer is exactly what the two
|
|
6
|
+
* masks hide. A formula never crosses a blank line (Pandoc: maths lives inside one
|
|
7
|
+
* paragraph), and code wins: a backquote before the closer ends the attempt. Nor does
|
|
8
|
+
* it run into a line that opens a block TeX never starts a line with — a `~~~` fence,
|
|
9
|
+
* a heading, a quote, an HTML block, a rule — or into a list item when the opener had
|
|
10
|
+
* text after it (`$$ is the PID`): a `$$` alone on its line opens a display formula,
|
|
11
|
+
* whose lines may start like one (`- x^2`).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Index of the `$` closing a single-`$` formula that opens at 0, or -1 — Pandoc's rule,
|
|
15
|
+
* which gives up rather than looking further: a `$` with a space before it ends the
|
|
16
|
+
* attempt (`$a $b$` is text), and so does a closer with a digit after it (`$x$5`). A `$`
|
|
17
|
+
* inside braces — `\text{in $x$ units}` — is TeX, not the closer.
|
|
18
|
+
*/
|
|
19
|
+
export declare function dollarCloser(src: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Index of `close` after `from`, skipping TeX escapes (`\$` inside `$$…$$`), or -1 when
|
|
22
|
+
* something a formula does not run into comes first: a backquote, a blank line, a
|
|
23
|
+
* block's line.
|
|
24
|
+
*/
|
|
25
|
+
export declare function closerAfter(src: string, from: number, close: string): number;
|
|
26
|
+
/**
|
|
27
|
+
* Where a formula whose body starts at `from` and that `close` has not closed runs to:
|
|
28
|
+
* where the scan for its closer gives up, by the same rule. Short of `src.length`, the
|
|
29
|
+
* formula can never close — it has met something it does not run into.
|
|
30
|
+
*/
|
|
31
|
+
export declare function openEnd(src: string, from: number, close: string): number;
|
|
32
|
+
/**
|
|
33
|
+
* Whether a `\(…\)` or `\[…\]` is a Markdown escape rather than maths: in Markdown those
|
|
34
|
+
* are how a reply writes literal brackets — a citation `\[1\]`, an index `array\[0\]`. So
|
|
35
|
+
* a pair that follows a letter or a digit, or holds nothing but a number, is left to
|
|
36
|
+
* Markdown. A `$` or `$$` pair is never an escape.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isEscapedBrackets(open: string, text: string, before: string): boolean;
|
|
39
|
+
/** The delimiters a formula can open with, and what closes each. */
|
|
40
|
+
export declare const PAIRS: ReadonlyArray<{
|
|
41
|
+
open: string;
|
|
42
|
+
close: string;
|
|
43
|
+
display: boolean;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* The formulas in `src`, as `[start, end)` ranges. With `open`, a formula whose opener
|
|
47
|
+
* has no closer yet runs to where the scan for its closer gives up, as one still
|
|
48
|
+
* arriving; `openDollar` is where the first single `$` opens something nothing closes
|
|
49
|
+
* yet (it may be a price), or -1.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mathSpans(src: string, open: boolean): {
|
|
52
|
+
spans: Array<[number, number]>;
|
|
53
|
+
openDollar: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Hide the maths in `src` from a text rewriter, and put it back afterwards.
|
|
57
|
+
*
|
|
58
|
+
* `remend` completes Markdown as it streams — it closes `**`, a backquote, a link — and
|
|
59
|
+
* it reads TeX as Markdown too, so it "completes" `\[ a+b` into a link and the `_` of
|
|
60
|
+
* `x_1` into emphasis. Each formula is swapped for a private-use marker it cannot read,
|
|
61
|
+
* the rewriter runs, and the formulas go back. Code spans are left as they are.
|
|
62
|
+
*
|
|
63
|
+
* An opener that will never close — `\[ a` followed by a backquote — is text to the
|
|
64
|
+
* tokenizer but stays hidden up to where it stops: remend ignores the backslash, and
|
|
65
|
+
* would complete that `[` into a link whose tail marked then prints as text.
|
|
66
|
+
*/
|
|
67
|
+
export declare function maskMath(src: string): {
|
|
68
|
+
masked: string;
|
|
69
|
+
unmask: (s: string) => string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* marked's masked copy of the text, with every formula in `src` blanked too, for its
|
|
73
|
+
* emphasis and strikethrough scans: they look ahead for the closing `*`, `_` or `~` on
|
|
74
|
+
* that copy, and a `*` inside `$x^*$` would otherwise close an italic opened before the
|
|
75
|
+
* formula.
|
|
76
|
+
*
|
|
77
|
+
* `src` is the text from where the tokenizer stands; `masked` is marked's copy of the
|
|
78
|
+
* whole text, of the same length, so `src` lines up with its tail — as marked's own
|
|
79
|
+
* scans read it.
|
|
80
|
+
*/
|
|
81
|
+
export declare function blankMath(src: string, masked: string): string;
|
|
82
|
+
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.d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@
|
|
|
1
1
|
import { type AparteConfig } from '@aparte/core';
|
|
2
|
-
import {
|
|
2
|
+
import type { MarkedProviderOptions } from './index.js';
|
|
3
|
+
export type { MarkedProviderOptions } from './index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Register [marked](https://marked.js.org) as aparté's Markdown renderer for a reply
|
|
5
6
|
* WHILE it streams and once it is finished — one parser on both sides, so a reply
|
|
@@ -18,13 +19,18 @@ import { type MarkedExtension } from 'marked';
|
|
|
18
19
|
*
|
|
19
20
|
* Call once at application startup.
|
|
20
21
|
*
|
|
22
|
+
* Maths is recognised as soon as a `math` renderer is registered (`@aparte/plugin-katex`),
|
|
23
|
+
* and a formula is drawn while it arrives: the parser reads an unclosed `$$`, `\[` or
|
|
24
|
+
* `\(` in the block being written as a formula still arriving. A single `$` is read
|
|
25
|
+
* only once it closes — until then it could be a price.
|
|
26
|
+
*
|
|
21
27
|
* @param options Optional marked extension(s), as for `setupMarkedProvider`: applied
|
|
22
|
-
* to a private marked instance, to the streaming and the finished render alike
|
|
28
|
+
* to a private marked instance, to the streaming and the finished render alike; and `math`.
|
|
23
29
|
* @param config The config to register on. Defaults to the global one.
|
|
24
30
|
*
|
|
25
31
|
* @example
|
|
26
32
|
* import { setupMarkedStreamingProvider } from '@aparte/plugin-marked/streaming';
|
|
27
33
|
* setupMarkedStreamingProvider({ gfm: true });
|
|
28
34
|
*/
|
|
29
|
-
export declare function setupMarkedStreamingProvider(options?:
|
|
35
|
+
export declare function setupMarkedStreamingProvider(options?: MarkedProviderOptions, config?: AparteConfig): void;
|
|
30
36
|
//# sourceMappingURL=streaming.d.ts.map
|
package/dist/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAwC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,YAAY,EAAwC,MAAM,cAAc,CAAC;AAK3G,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA8GxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,CAAC,EAAE,qBAAqB,EAAE,MAAM,GAAE,YAAiC,GAAG,IAAI,CAqB7H"}
|
package/dist/streaming.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { aparteGlobalConfig } from "@aparte/core";
|
|
2
2
|
import { Marked, marked } from "marked";
|
|
3
3
|
import remend from "remend";
|
|
4
|
+
import { m as markedMath, a as maskMath } from "./math.js";
|
|
4
5
|
const PENDING = "streamdown:";
|
|
5
6
|
const BARE_OPENER = /(^|[ \t])[*_~`]+$/;
|
|
6
|
-
function heal(raw) {
|
|
7
|
-
|
|
7
|
+
function heal(raw, math) {
|
|
8
|
+
const text = raw.replace(BARE_OPENER, "$1");
|
|
9
|
+
if (!math) return remend(text);
|
|
10
|
+
let { masked, unmask } = maskMath(text);
|
|
11
|
+
if (/$/.test(masked) && /[\s\\]$/.test(text)) ({ masked, unmask } = maskMath(text.replace(/[\s\\]+$/, "")));
|
|
12
|
+
return unmask(remend(masked, { katex: false }));
|
|
8
13
|
}
|
|
9
14
|
function blockNodes(html, healed, config) {
|
|
10
15
|
const template = document.createElement("template");
|
|
@@ -16,11 +21,11 @@ function blockNodes(html, healed, config) {
|
|
|
16
21
|
template.innerHTML = config.sanitizeHtml(template.innerHTML);
|
|
17
22
|
return Array.from(template.content.childNodes);
|
|
18
23
|
}
|
|
19
|
-
function createRenderer(target,
|
|
24
|
+
function createRenderer(target, parsers, config) {
|
|
20
25
|
let source = "";
|
|
21
26
|
let drawn = [];
|
|
22
27
|
const draw = (healLast) => {
|
|
23
|
-
const blocks =
|
|
28
|
+
const blocks = (healLast ? parsers.arriving : parsers.finished).lexer(source);
|
|
24
29
|
let from = 0;
|
|
25
30
|
while (from < blocks.length && from < drawn.length) {
|
|
26
31
|
const healed = healLast && from === blocks.length - 1;
|
|
@@ -33,7 +38,7 @@ function createRenderer(target, parser, config) {
|
|
|
33
38
|
for (let i = from; i < blocks.length; i++) {
|
|
34
39
|
const raw = blocks[i].raw;
|
|
35
40
|
const healed = healLast && i === blocks.length - 1;
|
|
36
|
-
const html =
|
|
41
|
+
const html = healed ? parsers.arriving.parse(heal(raw, parsers.math), { async: false }) : parsers.finished.parse(raw, { async: false });
|
|
37
42
|
const nodes = blockNodes(html, healed, config);
|
|
38
43
|
target.append(...nodes);
|
|
39
44
|
next.push({ raw, healed, nodes });
|
|
@@ -51,9 +56,19 @@ function createRenderer(target, parser, config) {
|
|
|
51
56
|
};
|
|
52
57
|
}
|
|
53
58
|
function setupMarkedStreamingProvider(options, config = aparteGlobalConfig) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
const { math, ...extension } = options ?? {};
|
|
60
|
+
const scoped = options !== void 0 && (math === void 0 || Object.keys(extension).length > 0);
|
|
61
|
+
const plain = scoped ? new Marked(extension) : marked;
|
|
62
|
+
let finished;
|
|
63
|
+
let arriving;
|
|
64
|
+
const mathOn = () => math ?? config.hasCodeLanguageRenderer("math");
|
|
65
|
+
const withMath = () => finished ??= new Marked(extension, markedMath());
|
|
66
|
+
const arrivingMath = () => arriving ??= new Marked(extension, markedMath({ live: true }));
|
|
67
|
+
config.setMarkdownProvider((raw) => (mathOn() ? withMath() : plain).parse(raw, { async: false }));
|
|
68
|
+
config.setStreamingMarkdownProvider((target) => {
|
|
69
|
+
const on = mathOn();
|
|
70
|
+
return createRenderer(target, on ? { finished: withMath(), arriving: arrivingMath(), math: true } : { finished: plain, arriving: plain, math: false }, config);
|
|
71
|
+
});
|
|
57
72
|
}
|
|
58
73
|
export {
|
|
59
74
|
setupMarkedStreamingProvider
|
package/dist/streaming.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sources":["../src/streaming.ts"],"sourcesContent":["import { aparteGlobalConfig, type AparteConfig, type AparteStreamingMarkdownRenderer } from '@aparte/core';\nimport { Marked, marked, type MarkedExtension } from 'marked';\nimport remend from 'remend';\n\n/*\n * What remend writes where a link or an image has no destination yet. Not a URL\n * anyone can follow: a pending link loses its `href`, so it reads as a link from its\n * first character without going anywhere, and a pending image is left out, since\n * there is nothing to show until its URL is complete.\n */\nconst PENDING = 'streamdown:';\n\n/*\n * A marker that opens and has nothing after it yet — `I am a **`. remend completes\n * `**scr` but has nothing to complete here, so the marker would show as typed until\n * the next chunk. After a space it can only open (a closer follows a character, not\n * a space), so holding it back never hides one that closes.\n */\nconst BARE_OPENER = /(^|[ \\t])[*_~`]+$/;\n\n/** The block being written, completed so that marked reads it as it will end. */\nfunction heal(raw: string): string {\n return remend(raw.replace(BARE_OPENER, '$1'));\n}\n\n/** One top-level Markdown block as it was last drawn. */\ninterface DrawnBlock {\n /** The block's source, which is what decides whether it has to be drawn again. */\n raw: string;\n /** Whether it was drawn completed by remend, as the block still being written is. */\n healed: boolean;\n /** The nodes it put in the target, in order. */\n nodes: ChildNode[];\n}\n\nfunction blockNodes(html: string, healed: boolean, config: AparteConfig): ChildNode[] {\n const template = document.createElement('template');\n template.innerHTML = html;\n if (healed) {\n for (const a of template.content.querySelectorAll(`a[href^=\"${PENDING}\"]`)) a.removeAttribute('href');\n for (const img of template.content.querySelectorAll(`img[src^=\"${PENDING}\"]`)) img.remove();\n }\n // Model-authored, like everything a Markdown provider returns: the config's own\n // sanitizer runs before any of it reaches the page, external links included.\n template.innerHTML = config.sanitizeHtml(template.innerHTML);\n return Array.from(template.content.childNodes);\n}\n\nfunction createRenderer(target: HTMLElement, parser: Marked, config: AparteConfig): AparteStreamingMarkdownRenderer {\n let source = '';\n let drawn: DrawnBlock[] = [];\n\n const draw = (healLast: boolean): void => {\n const blocks = parser.lexer(source);\n // The first block whose source moved; everything before it keeps its DOM.\n let from = 0;\n while (from < blocks.length && from < drawn.length) {\n const healed = healLast && from === blocks.length - 1;\n const old = drawn[from]!;\n if (old.raw !== blocks[from]!.raw || old.healed !== healed) break;\n from++;\n }\n for (const old of drawn.slice(from)) for (const node of old.nodes) node.remove();\n const next = drawn.slice(0, from);\n for (let i = from; i < blocks.length; i++) {\n const raw = blocks[i]!.raw;\n const healed = healLast && i === blocks.length - 1;\n const html = parser.parse(healed ? heal(raw) : raw, { async: false }) as string;\n const nodes = blockNodes(html, healed, config);\n target.append(...nodes);\n next.push({ raw, healed, nodes });\n }\n drawn = next;\n };\n\n return {\n write(chunk: string): void {\n source += chunk;\n draw(true);\n },\n end(): void {\n draw(false);\n },\n };\n}\n\n/**\n * Register [marked](https://marked.js.org) as aparté's Markdown renderer for a reply\n * WHILE it streams and once it is finished — one parser on both sides, so a reply\n * looks the same at its last chunk as when it settles.\n *\n * While a reply streams, the block being written is completed by Vercel's\n * [`remend`](https://www.npmjs.com/package/remend) before marked parses it:\n * `**bold` shows bold before its closing `**` arrives, and a link shows as a link\n * from its first character, clickable once its URL is complete. Blocks already\n * written are not drawn again, so a selection in them survives the stream. Every\n * block goes through the config's sanitizer before it reaches the page.\n *\n * It takes both of aparté's Markdown seams — `setMarkdownProvider` and\n * `setStreamingMarkdownProvider` — so it replaces `setupMarkedProvider` and\n * `@aparte/plugin-streaming-markdown` rather than going beside them.\n *\n * Call once at application startup.\n *\n * @param options Optional marked extension(s), as for `setupMarkedProvider`: applied\n * to a private marked instance, to the streaming and the finished render alike.\n * @param config The config to register on. Defaults to the global one.\n *\n * @example\n * import { setupMarkedStreamingProvider } from '@aparte/plugin-marked/streaming';\n * setupMarkedStreamingProvider({ gfm: true });\n */\nexport function setupMarkedStreamingProvider(options?: MarkedExtension, config: AparteConfig = aparteGlobalConfig): void {\n // Private instance when options are given, for the reason `setupMarkedProvider` gives.\n const parser = options ? new Marked(options) : marked;\n config.setMarkdownProvider((raw) => parser.parse(raw, { async: false }) as string);\n config.setStreamingMarkdownProvider((target) => createRenderer(target, parser as Marked, config));\n}\n"],"names":[],"mappings":";;;AAUA,MAAM,UAAU;AAQhB,MAAM,cAAc;AAGpB,SAAS,KAAK,KAAqB;AAC/B,SAAO,OAAO,IAAI,QAAQ,aAAa,IAAI,CAAC;AAChD;AAYA,SAAS,WAAW,MAAc,QAAiB,QAAmC;AAClF,QAAM,WAAW,SAAS,cAAc,UAAU;AAClD,WAAS,YAAY;AACrB,MAAI,QAAQ;AACR,eAAW,KAAK,SAAS,QAAQ,iBAAiB,YAAY,OAAO,IAAI,EAAG,GAAE,gBAAgB,MAAM;AACpG,eAAW,OAAO,SAAS,QAAQ,iBAAiB,aAAa,OAAO,IAAI,EAAG,KAAI,OAAA;AAAA,EACvF;AAGA,WAAS,YAAY,OAAO,aAAa,SAAS,SAAS;AAC3D,SAAO,MAAM,KAAK,SAAS,QAAQ,UAAU;AACjD;AAEA,SAAS,eAAe,QAAqB,QAAgB,QAAuD;AAChH,MAAI,SAAS;AACb,MAAI,QAAsB,CAAA;AAE1B,QAAM,OAAO,CAAC,aAA4B;AACtC,UAAM,SAAS,OAAO,MAAM,MAAM;AAElC,QAAI,OAAO;AACX,WAAO,OAAO,OAAO,UAAU,OAAO,MAAM,QAAQ;AAChD,YAAM,SAAS,YAAY,SAAS,OAAO,SAAS;AACpD,YAAM,MAAM,MAAM,IAAI;AACtB,UAAI,IAAI,QAAQ,OAAO,IAAI,EAAG,OAAO,IAAI,WAAW,OAAQ;AAC5D;AAAA,IACJ;AACA,eAAW,OAAO,MAAM,MAAM,IAAI,cAAc,QAAQ,IAAI,MAAO,MAAK,OAAA;AACxE,UAAM,OAAO,MAAM,MAAM,GAAG,IAAI;AAChC,aAAS,IAAI,MAAM,IAAI,OAAO,QAAQ,KAAK;AACvC,YAAM,MAAM,OAAO,CAAC,EAAG;AACvB,YAAM,SAAS,YAAY,MAAM,OAAO,SAAS;AACjD,YAAM,OAAO,OAAO,MAAM,SAAS,KAAK,GAAG,IAAI,KAAK,EAAE,OAAO,MAAA,CAAO;AACpE,YAAM,QAAQ,WAAW,MAAM,QAAQ,MAAM;AAC7C,aAAO,OAAO,GAAG,KAAK;AACtB,WAAK,KAAK,EAAE,KAAK,QAAQ,OAAO;AAAA,IACpC;AACA,YAAQ;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,MAAM,OAAqB;AACvB,gBAAU;AACV,WAAK,IAAI;AAAA,IACb;AAAA,IACA,MAAY;AACR,WAAK,KAAK;AAAA,IACd;AAAA,EAAA;AAER;AA4BO,SAAS,6BAA6B,SAA2B,SAAuB,oBAA0B;AAErH,QAAM,SAAS,UAAU,IAAI,OAAO,OAAO,IAAI;AAC/C,SAAO,oBAAoB,CAAC,QAAQ,OAAO,MAAM,KAAK,EAAE,OAAO,MAAA,CAAO,CAAW;AACjF,SAAO,6BAA6B,CAAC,WAAW,eAAe,QAAQ,QAAkB,MAAM,CAAC;AACpG;"}
|
|
1
|
+
{"version":3,"file":"streaming.js","sources":["../src/streaming.ts"],"sourcesContent":["import { aparteGlobalConfig, type AparteConfig, type AparteStreamingMarkdownRenderer } from '@aparte/core';\nimport { Marked, marked } from 'marked';\nimport remend from 'remend';\nimport { markedMath } from './math.js';\nimport { maskMath } from './scan.js';\nimport type { MarkedProviderOptions } from './index.js';\n\nexport type { MarkedProviderOptions } from './index.js';\n\n/*\n * What remend writes where a link or an image has no destination yet. Not a URL\n * anyone can follow: a pending link loses its `href`, so it reads as a link from its\n * first character without going anywhere, and a pending image is left out, since\n * there is nothing to show until its URL is complete.\n */\nconst PENDING = 'streamdown:';\n\n/*\n * A marker that opens and has nothing after it yet — `I am a **`. remend completes\n * `**scr` but has nothing to complete here, so the marker would show as typed until\n * the next chunk. After a space it can only open (a closer follows a character, not\n * a space), so holding it back never hides one that closes.\n */\nconst BARE_OPENER = /(^|[ \\t])[*_~`]+$/;\n\n/**\n * The block being written, completed so that marked reads it as it will end.\n *\n * With maths on, the formulas are hidden from remend first: it reads TeX as Markdown,\n * so it \"completed\" `\\[ a+b` into a link and the `_` of `x_1` into emphasis. A formula\n * still open is the parser's to handle, as one arriving.\n */\nfunction heal(raw: string, math: boolean): string {\n const text = raw.replace(BARE_OPENER, '$1');\n if (!math) return remend(text);\n let { masked, unmask } = maskMath(text);\n // A formula still arriving at the very end: a space or a lone `\\` (half of `\\)`) at its\n // tail is left out of this frame, or the closer remend appends would follow it — no\n // longer closing the emphasis around the formula, and drawn inside it.\n if (/$/.test(masked) && /[\\s\\\\]$/.test(text)) ({ masked, unmask } = maskMath(text.replace(/[\\s\\\\]+$/, '')));\n // A single `$` still open may be a formula on its way (`$[a, b]` of an interval):\n // completing its bracket into a link would draw a link that becomes maths a token later.\n return unmask(remend(masked, { katex: false }));\n}\n\n/** One top-level Markdown block as it was last drawn. */\ninterface DrawnBlock {\n /** The block's source, which is what decides whether it has to be drawn again. */\n raw: string;\n /** Whether it was drawn completed by remend, as the block still being written is. */\n healed: boolean;\n /** The nodes it put in the target, in order. */\n nodes: ChildNode[];\n}\n\nfunction blockNodes(html: string, healed: boolean, config: AparteConfig): ChildNode[] {\n const template = document.createElement('template');\n template.innerHTML = html;\n if (healed) {\n for (const a of template.content.querySelectorAll(`a[href^=\"${PENDING}\"]`)) a.removeAttribute('href');\n for (const img of template.content.querySelectorAll(`img[src^=\"${PENDING}\"]`)) img.remove();\n }\n // Model-authored, like everything a Markdown provider returns: the config's own\n // sanitizer runs before any of it reaches the page, external links included.\n template.innerHTML = config.sanitizeHtml(template.innerHTML);\n return Array.from(template.content.childNodes);\n}\n\n/** The parsers one streamed reply uses: one for the blocks it has finished, one for the block it is writing. */\ninterface ReplyParsers {\n finished: Marked;\n arriving: Marked;\n math: boolean;\n}\n\nfunction createRenderer(target: HTMLElement, parsers: ReplyParsers, config: AparteConfig): AparteStreamingMarkdownRenderer {\n let source = '';\n let drawn: DrawnBlock[] = [];\n\n const draw = (healLast: boolean): void => {\n // The arriving parser splits the blocks: it reads an unclosed `$$` as one block\n // running to the end, as an unclosed fence is.\n const blocks = (healLast ? parsers.arriving : parsers.finished).lexer(source);\n // The first block whose source moved; everything before it keeps its DOM.\n let from = 0;\n while (from < blocks.length && from < drawn.length) {\n const healed = healLast && from === blocks.length - 1;\n const old = drawn[from]!;\n if (old.raw !== blocks[from]!.raw || old.healed !== healed) break;\n from++;\n }\n for (const old of drawn.slice(from)) for (const node of old.nodes) node.remove();\n const next = drawn.slice(0, from);\n for (let i = from; i < blocks.length; i++) {\n const raw = blocks[i]!.raw;\n const healed = healLast && i === blocks.length - 1;\n const html = healed\n ? parsers.arriving.parse(heal(raw, parsers.math), { async: false }) as string\n : parsers.finished.parse(raw, { async: false }) as string;\n const nodes = blockNodes(html, healed, config);\n target.append(...nodes);\n next.push({ raw, healed, nodes });\n }\n drawn = next;\n };\n\n return {\n write(chunk: string): void {\n source += chunk;\n draw(true);\n },\n end(): void {\n draw(false);\n },\n };\n}\n\n/**\n * Register [marked](https://marked.js.org) as aparté's Markdown renderer for a reply\n * WHILE it streams and once it is finished — one parser on both sides, so a reply\n * looks the same at its last chunk as when it settles.\n *\n * While a reply streams, the block being written is completed by Vercel's\n * [`remend`](https://www.npmjs.com/package/remend) before marked parses it:\n * `**bold` shows bold before its closing `**` arrives, and a link shows as a link\n * from its first character, clickable once its URL is complete. Blocks already\n * written are not drawn again, so a selection in them survives the stream. Every\n * block goes through the config's sanitizer before it reaches the page.\n *\n * It takes both of aparté's Markdown seams — `setMarkdownProvider` and\n * `setStreamingMarkdownProvider` — so it replaces `setupMarkedProvider` and\n * `@aparte/plugin-streaming-markdown` rather than going beside them.\n *\n * Call once at application startup.\n *\n * Maths is recognised as soon as a `math` renderer is registered (`@aparte/plugin-katex`),\n * and a formula is drawn while it arrives: the parser reads an unclosed `$$`, `\\[` or\n * `\\(` in the block being written as a formula still arriving. A single `$` is read\n * only once it closes — until then it could be a price.\n *\n * @param options Optional marked extension(s), as for `setupMarkedProvider`: applied\n * to a private marked instance, to the streaming and the finished render alike; and `math`.\n * @param config The config to register on. Defaults to the global one.\n *\n * @example\n * import { setupMarkedStreamingProvider } from '@aparte/plugin-marked/streaming';\n * setupMarkedStreamingProvider({ gfm: true });\n */\nexport function setupMarkedStreamingProvider(options?: MarkedProviderOptions, config: AparteConfig = aparteGlobalConfig): void {\n // A private instance when options are given, for the reason `setupMarkedProvider`\n // gives; the parsers that recognise maths are made on first use.\n const { math, ...extension } = options ?? {};\n const scoped = options !== undefined && (math === undefined || Object.keys(extension).length > 0);\n const plain = scoped ? new Marked(extension) : marked;\n let finished: Marked | undefined;\n let arriving: Marked | undefined;\n const mathOn = (): boolean => math ?? config.hasCodeLanguageRenderer('math');\n const withMath = (): Marked => (finished ??= new Marked(extension, markedMath()));\n const arrivingMath = (): Marked => (arriving ??= new Marked(extension, markedMath({ live: true })));\n\n config.setMarkdownProvider((raw) => (mathOn() ? withMath() : plain).parse(raw, { async: false }) as string);\n // Decided once per reply, so a renderer registered mid-stream does not switch the\n // parser under blocks already drawn; the settle draws the reply again anyway.\n config.setStreamingMarkdownProvider((target) => {\n const on = mathOn();\n return createRenderer(target, on\n ? { finished: withMath(), arriving: arrivingMath(), math: true }\n : { finished: plain as Marked, arriving: plain as Marked, math: false }, config);\n });\n}\n"],"names":[],"mappings":";;;;AAeA,MAAM,UAAU;AAQhB,MAAM,cAAc;AASpB,SAAS,KAAK,KAAa,MAAuB;AAC9C,QAAM,OAAO,IAAI,QAAQ,aAAa,IAAI;AAC1C,MAAI,CAAC,KAAM,QAAO,OAAO,IAAI;AAC7B,MAAI,EAAE,QAAQ,WAAW,SAAS,IAAI;AAItC,MAAI,KAAK,KAAK,MAAM,KAAK,UAAU,KAAK,IAAI,EAAG,EAAC,EAAE,QAAQ,WAAW,SAAS,KAAK,QAAQ,YAAY,EAAE,CAAC;AAG1G,SAAO,OAAO,OAAO,QAAQ,EAAE,OAAO,MAAA,CAAO,CAAC;AAClD;AAYA,SAAS,WAAW,M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AAK,KAAK,EAAE,KAAK,QAAQ,OAAO;AAAA,IACpC;AACA,YAAQ;AAAA,EACZ;AAEA,SAAO;AAAA,IACH,MAAM,OAAqB;AACvB,gBAAU;AACV,WAAK,IAAI;AAAA,IACb;AAAA,IACA,MAAY;AACR,WAAK,KAAK;AAAA,IACd;AAAA,EAAA;AAER;AAiCO,SAAS,6BAA6B,SAAiC,SAAuB,oBAA0B;AAG3H,QAAM,EAAE,MAAM,GAAG,UAAA,IAAc,WAAW,CAAA;AAC1C,QAAM,SAAS,YAAY,WAAc,SAAS,UAAa,OAAO,KAAK,SAAS,EAAE,SAAS;AAC/F,QAAM,QAAQ,SAAS,IAAI,OAAO,SAAS,IAAI;AAC/C,MAAI;AACJ,MAAI;AACJ,QAAM,SAAS,MAAe,QAAQ,OAAO,wBAAwB,MAAM;AAC3E,QAAM,WAAW,MAAe,aAAa,IAAI,OAAO,WAAW,YAAY;AAC/E,QAAM,eAAe,MAAe,aAAa,IAAI,OAAO,WAAW,WAAW,EAAE,MAAM,KAAA,CAAM,CAAC;AAEjG,SAAO,oBAAoB,CAAC,SAAS,OAAA,IAAW,SAAA,IAAa,OAAO,MAAM,KAAK,EAAE,OAAO,MAAA,CAAO,CAAW;AAG1G,SAAO,6BAA6B,CAAC,WAAW;AAC5C,UAAM,KAAK,OAAA;AACX,WAAO,eAAe,QAAQ,KACxB,EAAE,UAAU,SAAA,GAAY,UAAU,gBAAgB,MAAM,SACxD,EAAE,UAAU,OAAiB,UAAU,OAAiB,MAAM,MAAA,GAAS,MAAM;AAAA,EACvF,CAAC;AACL;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aparte/plugin-marked",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"homepage": "https://apartejs.dev/plugins/marked/",
|
|
5
5
|
"description": "Markdown rendering for aparté via marked — register it as the one-shot Markdown provider.",
|
|
6
6
|
"type": "module",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"remend": "^1.4.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@aparte/core": ">=0.
|
|
37
|
+
"@aparte/core": ">=0.28.0 <1.0.0",
|
|
38
38
|
"marked": "^18.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"marked": "^18.0.0",
|
|
42
42
|
"typescript": "^5.4.0",
|
|
43
43
|
"vite": "^6.0.0",
|
|
44
|
-
"@aparte/core": "0.
|
|
44
|
+
"@aparte/core": "0.28.0"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|
|
47
47
|
"aparte",
|