@ember-marquetry/markdown 0.0.0-stage → 1.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/CHANGELOG.md +26 -0
- package/LICENSE.md +21 -0
- package/NOTICE +13 -0
- package/README.md +52 -2
- package/dist/blocks.d.ts +12 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +653 -0
- package/dist/index.js.map +1 -0
- package/dist/inline.d.ts +5 -0
- package/dist/stream.d.ts +21 -0
- package/dist/types.d.ts +63 -0
- package/dist/url.d.ts +7 -0
- package/package.json +44 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @ember-marquetry/markdown
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 8f2790b: The first release of Marquetry: generative UI for Ember.
|
|
8
|
+
|
|
9
|
+
- `core`: the spec format, the JSONL patch stream, expressions, actions, the catalog, agent events, chat threads and stream replay.
|
|
10
|
+
- `ember`: the `<Render>` component and the `Generation` state machine.
|
|
11
|
+
- `joinery`: a catalog of 69 Joinery components, with layout templates and the chart, data table and code block add-ons. The `/a2ui` subpath is the A2UI v0.9.1 basic catalog on Joinery components, for the specs of `a2ui`.
|
|
12
|
+
- `chat`: a chat thread on Joinery components, with streamed markdown, agent surfaces, tool calls, approvals and MCP Apps.
|
|
13
|
+
- `formwright`: forms with validation from a JSON Schema, field rules and named validators.
|
|
14
|
+
- `inspector`: a dev panel for `<Render>` that shows the spec, the patches with their line numbers, the state and the problems.
|
|
15
|
+
- `ai-sdk`, `ag-ui`, `a2ui` and `sse`: adapters and chat transports for the AI SDK, AG-UI 1.0, A2UI v0.9.1 and plain JSONL or SSE endpoints.
|
|
16
|
+
- `markdown`: a streamed markdown parser that makes no HTML.
|
|
17
|
+
- `mcp-apps`: a host for MCP Apps in a sandbox frame on a second origin.
|
|
18
|
+
- `eslint-plugin`, `skills`, `test-support` and the `ember-marquetry` CLI: tools for catalog authors and app developers.
|
|
19
|
+
|
|
20
|
+
Safety defaults in 1.0:
|
|
21
|
+
|
|
22
|
+
- `joinery`: a URL that the browser loads with no click (the `src` of `Image` and `Avatar`, the `image` of `Attachment`, and the `url` of the A2UI `Image`, `Video` and `AudioPlayer`) must be relative, unless `urls.mediaHosts` lists its host. `isSafeMediaUrl` is the check. `urls.hosts` applies only to links.
|
|
23
|
+
- `markdown` and `chat`: an image must pass `isSafeImageUrl` (`<Chat @isSafeImageUrl>`, `<Markdown @isSafeImageUrl>`). The default, `isRelativeUrl`, accepts only a relative URL. A block of more than 20,000 characters is plain text.
|
|
24
|
+
- `chat`: `<McpApp>` and `McpAppsConfig` have `approveDomain`. Without it, the app gets no domain that it declares in its CSP. An app cannot call a tool that needs the approval of the user (`@needsApproval`).
|
|
25
|
+
- `mcp-apps`: the proxy puts the CSP meta at offset 0 of the app HTML, and gives its own page a `frame-src` with only the approved frame domains.
|
|
26
|
+
- `ai-sdk` and `ag-ui`: a problem in one item is a `data` event named `stream-error`, and a value that the reader does not convert is a `data` event named `unconverted`. `error` is only for a failed run.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Marquetry
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Marquetry is an original design. Two projects gave it ideas and formats, and Marquetry copies
|
|
5
|
+
no code from them:
|
|
6
|
+
|
|
7
|
+
- json-render (Vercel, Apache 2.0): the idea of a catalog that limits a model, a flat element
|
|
8
|
+
map, and a spec that streams as JSON Lines of RFC 6902 patches.
|
|
9
|
+
- A2UI (Google, Apache 2.0): the v0.9 message format that @ember-marquetry/a2ui reads.
|
|
10
|
+
|
|
11
|
+
@ember-marquetry/ag-ui reads the event format of the AG-UI protocol, and
|
|
12
|
+
@ember-marquetry/ai-sdk reads the UI message stream format of the Vercel AI SDK. Marquetry
|
|
13
|
+
depends on neither package.
|
package/README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-marquetry/markdown
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A markdown parser for streamed model text. It gives a tree of blocks with no HTML, and it
|
|
4
|
+
parses again only the last block while the text streams. The chat package of
|
|
5
|
+
[Marquetry](https://joegaudet.com/ember-marquetry/) renders the tree with Joinery components.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @ember-marquetry/markdown
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createMarkdownStream, parseMarkdown } from '@ember-marquetry/markdown'
|
|
13
|
+
|
|
14
|
+
parseMarkdown('# Hello\n\nSome **bold** text.')
|
|
15
|
+
|
|
16
|
+
const stream = createMarkdownStream()
|
|
17
|
+
for await (const chunk of text) {
|
|
18
|
+
const { blocks } = stream.push(chunk) // a block that did not change keeps its identity
|
|
19
|
+
}
|
|
20
|
+
stream.end()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## What it reads
|
|
24
|
+
|
|
25
|
+
- Blocks: paragraphs, ATX and setext headings, fenced code (`open` while the closing fence did
|
|
26
|
+
not arrive), bullet and ordered lists (tight or loose, nested), block quotes, rules, and GFM
|
|
27
|
+
tables with alignment.
|
|
28
|
+
- Inline: strong, emphasis, strikethrough, code spans, links, images, autolinks
|
|
29
|
+
(`<https://...>` and bare `https://` URLs), backslash escapes and hard breaks.
|
|
30
|
+
|
|
31
|
+
It does not read indented code blocks, link reference definitions, footnotes or HTML. HTML
|
|
32
|
+
stays text.
|
|
33
|
+
|
|
34
|
+
## Safety
|
|
35
|
+
|
|
36
|
+
- The tree holds no HTML. A renderer makes each node from data.
|
|
37
|
+
- A link or an image with a URL that is not safe becomes its text. The default check,
|
|
38
|
+
`isSafeUrl`, accepts `http:`, `https:`, `mailto:`, `tel:` and relative URLs, and refuses
|
|
39
|
+
every other scheme. Pass `{ isSafeUrl }` to use your own check.
|
|
40
|
+
- An image must also pass `isSafeImageUrl`. The default, `isRelativeUrl`, accepts only a relative
|
|
41
|
+
URL, because the browser loads an image with no click, and the URL can send data to its host.
|
|
42
|
+
Pass `{ isSafeImageUrl }` to permit some hosts.
|
|
43
|
+
- An image is a node with `src` and `alt`. The renderer decides if it shows images.
|
|
44
|
+
- A block of more than 20,000 characters is plain text, and emphasis or links nested more than
|
|
45
|
+
16 levels deep are text. Each scanner reads a block in one pass, so a long reply cannot freeze
|
|
46
|
+
the tab.
|
|
47
|
+
|
|
48
|
+
## Streams
|
|
49
|
+
|
|
50
|
+
`createMarkdownStream()` parses the text again only after the last final block. A block is
|
|
51
|
+
final when a later block starts in the complete lines, because later text can only change the
|
|
52
|
+
last block. A partial line never makes a block final: `#` is a heading, but `#tag` is text.
|
|
53
|
+
A test checks this rule against `parseMarkdown` after each character of many random documents.
|
package/dist/blocks.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Block, MarkdownOptions } from './types';
|
|
2
|
+
/** The blocks of some lines, and the index of the first line of each block. */
|
|
3
|
+
export interface Parsed {
|
|
4
|
+
blocks: Block[];
|
|
5
|
+
starts: number[];
|
|
6
|
+
}
|
|
7
|
+
/** Parses lines to blocks. */
|
|
8
|
+
export declare function parseLines(lines: string[], options?: MarkdownOptions, depth?: number): Parsed;
|
|
9
|
+
/** Splits text into lines, and removes the carriage return of a CRLF line end. */
|
|
10
|
+
export declare function splitLines(text: string): string[];
|
|
11
|
+
/** Parses markdown to a tree of blocks. The tree holds no HTML. */
|
|
12
|
+
export declare function parseMarkdown(text: string, options?: MarkdownOptions): Block[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { parseLines, parseMarkdown } from './blocks';
|
|
2
|
+
export { parseInline } from './inline';
|
|
3
|
+
export { createMarkdownStream, type MarkdownSnapshot, type MarkdownStream } from './stream';
|
|
4
|
+
export type { Align, Block, Inline, MarkdownOptions } from './types';
|
|
5
|
+
export { isRelativeUrl, isSafeUrl } from './url';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
// src/url.ts
|
|
2
|
+
var SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
|
|
3
|
+
function cleaned(url) {
|
|
4
|
+
let start = 0;
|
|
5
|
+
while (start < url.length && url.charCodeAt(start) <= 32) start++;
|
|
6
|
+
let out = "";
|
|
7
|
+
for (const char of url.slice(start)) {
|
|
8
|
+
if (char !== " " && char !== "\n" && char !== "\r") out += char;
|
|
9
|
+
}
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
function isSafeUrl(url) {
|
|
13
|
+
const value = cleaned(url);
|
|
14
|
+
const colon = value.indexOf(":");
|
|
15
|
+
if (colon === -1) return true;
|
|
16
|
+
if (value.startsWith("#")) return true;
|
|
17
|
+
const separator = value.search(/[/?]/);
|
|
18
|
+
if (separator !== -1 && separator < colon) return true;
|
|
19
|
+
return SCHEMES.has(value.slice(0, colon).toLowerCase());
|
|
20
|
+
}
|
|
21
|
+
function isRelativeUrl(url) {
|
|
22
|
+
const value = cleaned(url);
|
|
23
|
+
if (value === "" || value.startsWith("//") || value.includes("\\")) return false;
|
|
24
|
+
const colon = value.indexOf(":");
|
|
25
|
+
const separator = value.search(/[/?#]/);
|
|
26
|
+
return colon === -1 || separator !== -1 && separator < colon;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/inline.ts
|
|
30
|
+
var PUNCTUATION = /[!-/:-@[-`{-~]/;
|
|
31
|
+
var ALPHANUMERIC = /[\p{L}\p{N}]/u;
|
|
32
|
+
var AUTOLINK = /^<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^\s<>]*)>/;
|
|
33
|
+
var BARE_URL = /^https?:\/\/[^\s<]+/;
|
|
34
|
+
function pushText(out, text) {
|
|
35
|
+
if (text === "") return;
|
|
36
|
+
const last = out.at(-1);
|
|
37
|
+
if (last?.type === "text") last.text += text;
|
|
38
|
+
else out.push({ type: "text", text });
|
|
39
|
+
}
|
|
40
|
+
function pushAll(out, nodes) {
|
|
41
|
+
for (const node of nodes) {
|
|
42
|
+
if (node.type === "text") pushText(out, node.text);
|
|
43
|
+
else out.push(node);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function plainText(nodes) {
|
|
47
|
+
return nodes.map((node) => {
|
|
48
|
+
if (node.type === "text" || node.type === "code") return node.text;
|
|
49
|
+
if (node.type === "image") return node.alt;
|
|
50
|
+
if (node.type === "break") return "\n";
|
|
51
|
+
return plainText(node.children);
|
|
52
|
+
}).join("");
|
|
53
|
+
}
|
|
54
|
+
function runLength(source, at, char) {
|
|
55
|
+
let end = at;
|
|
56
|
+
while (source[end] === char) end++;
|
|
57
|
+
return end - at;
|
|
58
|
+
}
|
|
59
|
+
function firstFrom(list, min) {
|
|
60
|
+
if (!list) return void 0;
|
|
61
|
+
let low = 0;
|
|
62
|
+
let high = list.length;
|
|
63
|
+
while (low < high) {
|
|
64
|
+
const middle = low + high >> 1;
|
|
65
|
+
if (list[middle] < min) low = middle + 1;
|
|
66
|
+
else high = middle;
|
|
67
|
+
}
|
|
68
|
+
return list[low];
|
|
69
|
+
}
|
|
70
|
+
var Tables = class {
|
|
71
|
+
constructor(source) {
|
|
72
|
+
this.source = source;
|
|
73
|
+
const length = source.length;
|
|
74
|
+
for (let at = 0; at < length; ) {
|
|
75
|
+
if (source[at] !== "`") {
|
|
76
|
+
at++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const run = runLength(source, at, "`");
|
|
80
|
+
let list = this.#runs.get(run);
|
|
81
|
+
if (!list) this.#runs.set(run, list = []);
|
|
82
|
+
list.push(at);
|
|
83
|
+
at += run;
|
|
84
|
+
}
|
|
85
|
+
this.#onWalk = new Uint8Array(length + 1);
|
|
86
|
+
const open = [];
|
|
87
|
+
for (let at = 0; at < length; ) {
|
|
88
|
+
this.#onWalk[at] = 1;
|
|
89
|
+
const char = source[at];
|
|
90
|
+
if (char === "\\") {
|
|
91
|
+
at += 2;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (char === "`") {
|
|
95
|
+
const span = this.codeSpanEnd(at);
|
|
96
|
+
at = span ? span.end + span.length : at + runLength(source, at, "`");
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (char === "[") open.push(at);
|
|
100
|
+
else if (char === "]" && open.length > 0) this.#brackets.set(open.pop(), at);
|
|
101
|
+
else if ((char === "*" || char === "_" || char === "~") && !(this.#onWalk[at - 1] && source[at - 1] === char)) {
|
|
102
|
+
const run = runLength(source, at, char);
|
|
103
|
+
const before = source[at - 1] ?? " ";
|
|
104
|
+
const after = source[at + run] ?? " ";
|
|
105
|
+
if (!/\s/.test(before) && (char !== "_" || !ALPHANUMERIC.test(after))) {
|
|
106
|
+
const key = char + run;
|
|
107
|
+
let list = this.#closers.get(key);
|
|
108
|
+
if (!list) this.#closers.set(key, list = []);
|
|
109
|
+
list.push(at);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
at++;
|
|
113
|
+
}
|
|
114
|
+
const parens = [];
|
|
115
|
+
for (let at = 0; at < length; at++) {
|
|
116
|
+
const char = source[at];
|
|
117
|
+
if (char === "\\" && PUNCTUATION.test(source[at + 1] ?? "")) at++;
|
|
118
|
+
else if (char === "(") parens.push(at);
|
|
119
|
+
else if (char === ")" && parens.length > 0) this.#parens.set(parens.pop(), at);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
source;
|
|
123
|
+
/** For each length, the start of each backtick run of that length. */
|
|
124
|
+
#runs = /* @__PURE__ */ new Map();
|
|
125
|
+
/** The positions that the scan from the start reaches: escapes and code spans are skipped. */
|
|
126
|
+
#onWalk;
|
|
127
|
+
/** "[" to its "]". */
|
|
128
|
+
#brackets = /* @__PURE__ */ new Map();
|
|
129
|
+
/** `char + length` to each run that can close emphasis. */
|
|
130
|
+
#closers = /* @__PURE__ */ new Map();
|
|
131
|
+
/** "(" to its ")", in a link destination. */
|
|
132
|
+
#parens = /* @__PURE__ */ new Map();
|
|
133
|
+
#next = /* @__PURE__ */ new Map();
|
|
134
|
+
/** The end of a code span that starts at `at`, or undefined. */
|
|
135
|
+
codeSpanEnd(at) {
|
|
136
|
+
const length = runLength(this.source, at, "`");
|
|
137
|
+
const end = firstFrom(this.#runs.get(length), at + length);
|
|
138
|
+
return end === void 0 ? void 0 : { end, length };
|
|
139
|
+
}
|
|
140
|
+
/** The index of the "]" that closes the "[" at `at`, or -1. */
|
|
141
|
+
closingBracket(at) {
|
|
142
|
+
return this.#onWalk[at] && this.#brackets.get(at) || -1;
|
|
143
|
+
}
|
|
144
|
+
/** The index of the delimiter run that closes `marker`, from `from`, or -1. */
|
|
145
|
+
closingDelimiter(from, marker) {
|
|
146
|
+
if (!this.#onWalk[from]) return -1;
|
|
147
|
+
return firstFrom(this.#closers.get(marker[0] + marker.length), from + 1) ?? -1;
|
|
148
|
+
}
|
|
149
|
+
/** The ")" that closes the "(" at `at`, or -1. */
|
|
150
|
+
closingParen(at) {
|
|
151
|
+
return this.#parens.get(at) ?? -1;
|
|
152
|
+
}
|
|
153
|
+
/** The first index from `from` where `test` is true for the character, or the length. */
|
|
154
|
+
next(name, test, from) {
|
|
155
|
+
let table = this.#next.get(name);
|
|
156
|
+
if (!table) {
|
|
157
|
+
const source = this.source;
|
|
158
|
+
table = new Int32Array(source.length + 1);
|
|
159
|
+
table[source.length] = source.length;
|
|
160
|
+
for (let at = source.length - 1; at >= 0; at--) {
|
|
161
|
+
table[at] = test(source[at]) ? at : table[at + 1];
|
|
162
|
+
}
|
|
163
|
+
this.#next.set(name, table);
|
|
164
|
+
}
|
|
165
|
+
return from >= this.source.length ? this.source.length : table[from];
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var isSpace = (char) => /\s/.test(char);
|
|
169
|
+
var notBlank = (char) => char !== " " && char !== "\n";
|
|
170
|
+
function indexOf(tables, char, from) {
|
|
171
|
+
const at = tables.next(char, (c) => c === char, from);
|
|
172
|
+
return at === tables.source.length ? -1 : at;
|
|
173
|
+
}
|
|
174
|
+
function destination(tables, at) {
|
|
175
|
+
const source = tables.source;
|
|
176
|
+
if (source[at] !== "(") return void 0;
|
|
177
|
+
let index = tables.next("blank", notBlank, at + 1);
|
|
178
|
+
let url;
|
|
179
|
+
if (source[index] === "<") {
|
|
180
|
+
const close = indexOf(tables, ">", index);
|
|
181
|
+
if (close === -1) return void 0;
|
|
182
|
+
const line = indexOf(tables, "\n", index);
|
|
183
|
+
if (line !== -1 && line < close) return void 0;
|
|
184
|
+
const from = index + 1;
|
|
185
|
+
url = () => source.slice(from, close);
|
|
186
|
+
index = close + 1;
|
|
187
|
+
} else {
|
|
188
|
+
const paren = tables.closingParen(at);
|
|
189
|
+
const space = tables.next("space", isSpace, index);
|
|
190
|
+
const from = index;
|
|
191
|
+
const end = paren === -1 ? space : Math.min(paren, space);
|
|
192
|
+
url = () => source.slice(from, end).replace(/\\([!-/:-@[-`{-~])/g, "$1");
|
|
193
|
+
index = end;
|
|
194
|
+
}
|
|
195
|
+
index = tables.next("blank", notBlank, index);
|
|
196
|
+
const quote = source[index];
|
|
197
|
+
if (quote === '"' || quote === "'" || quote === "(") {
|
|
198
|
+
const close = indexOf(tables, quote === "(" ? ")" : quote, index + 1);
|
|
199
|
+
if (close === -1) return void 0;
|
|
200
|
+
index = tables.next("blank", notBlank, close + 1);
|
|
201
|
+
}
|
|
202
|
+
return source[index] === ")" ? { url: url(), end: index + 1 } : void 0;
|
|
203
|
+
}
|
|
204
|
+
var MAX_DEPTH = 16;
|
|
205
|
+
var MAX_INLINE_LENGTH = 2e4;
|
|
206
|
+
var AUTOLINK_AT = new RegExp(AUTOLINK.source.slice(1), "y");
|
|
207
|
+
var BARE_URL_AT = new RegExp(BARE_URL.source.slice(1), "y");
|
|
208
|
+
function parse(source, checks, depth) {
|
|
209
|
+
const check = checks.link;
|
|
210
|
+
if (depth > MAX_DEPTH) return source === "" ? [] : [{ type: "text", text: source }];
|
|
211
|
+
const tables = new Tables(source);
|
|
212
|
+
const out = [];
|
|
213
|
+
let index = 0;
|
|
214
|
+
while (index < source.length) {
|
|
215
|
+
const char = source[index];
|
|
216
|
+
const next = source[index + 1] ?? "";
|
|
217
|
+
if (char === "\\") {
|
|
218
|
+
if (next === "\n") {
|
|
219
|
+
out.push({ type: "break" });
|
|
220
|
+
index += 2;
|
|
221
|
+
} else if (PUNCTUATION.test(next)) {
|
|
222
|
+
pushText(out, next);
|
|
223
|
+
index += 2;
|
|
224
|
+
} else {
|
|
225
|
+
pushText(out, char);
|
|
226
|
+
index++;
|
|
227
|
+
}
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (char === "\n") {
|
|
231
|
+
const last = out.at(-1);
|
|
232
|
+
if (last?.type === "text" && / {2,}$/.test(last.text)) {
|
|
233
|
+
last.text = last.text.replace(/ +$/, "");
|
|
234
|
+
out.push({ type: "break" });
|
|
235
|
+
} else {
|
|
236
|
+
if (last?.type === "text") last.text = last.text.replace(/ +$/, "");
|
|
237
|
+
pushText(out, "\n");
|
|
238
|
+
}
|
|
239
|
+
index++;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (char === "`") {
|
|
243
|
+
const span = tables.codeSpanEnd(index);
|
|
244
|
+
if (!span) {
|
|
245
|
+
const run = runLength(source, index, "`");
|
|
246
|
+
pushText(out, "`".repeat(run));
|
|
247
|
+
index += run;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
let text = source.slice(index + span.length, span.end).replace(/\n/g, " ");
|
|
251
|
+
if (text.length > 2 && text.startsWith(" ") && text.endsWith(" ") && text.trim() !== "") {
|
|
252
|
+
text = text.slice(1, -1);
|
|
253
|
+
}
|
|
254
|
+
out.push({ type: "code", text });
|
|
255
|
+
index = span.end + span.length;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (char === "[" || char === "!" && next === "[") {
|
|
259
|
+
const image = char === "!";
|
|
260
|
+
const open = image ? index + 1 : index;
|
|
261
|
+
const close = tables.closingBracket(open);
|
|
262
|
+
const target = close === -1 ? void 0 : destination(tables, close + 1);
|
|
263
|
+
if (target) {
|
|
264
|
+
const label = parse(source.slice(open + 1, close), checks, depth + 1);
|
|
265
|
+
if (image) {
|
|
266
|
+
const alt = plainText(label);
|
|
267
|
+
if (check(target.url) && checks.image(target.url)) {
|
|
268
|
+
out.push({ type: "image", src: target.url, alt });
|
|
269
|
+
} else pushText(out, alt);
|
|
270
|
+
} else if (check(target.url)) {
|
|
271
|
+
out.push({ type: "link", href: target.url, children: label });
|
|
272
|
+
} else {
|
|
273
|
+
pushAll(out, label);
|
|
274
|
+
}
|
|
275
|
+
index = target.end;
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
pushText(out, char);
|
|
279
|
+
index++;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (char === "<") {
|
|
283
|
+
AUTOLINK_AT.lastIndex = index;
|
|
284
|
+
const match = AUTOLINK_AT.exec(source);
|
|
285
|
+
if (match && check(match[1])) {
|
|
286
|
+
out.push({ type: "link", href: match[1], children: [{ type: "text", text: match[1] }] });
|
|
287
|
+
index += match[0].length;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (char === "h" && !ALPHANUMERIC.test(source[index - 1] ?? " ")) {
|
|
292
|
+
BARE_URL_AT.lastIndex = index;
|
|
293
|
+
const match = BARE_URL_AT.exec(source);
|
|
294
|
+
if (match) {
|
|
295
|
+
let url = match[0].replace(/[.,:;!?'"]+$/, "");
|
|
296
|
+
const opens = url.match(/\(/g)?.length ?? 0;
|
|
297
|
+
let closes = url.match(/\)/g)?.length ?? 0;
|
|
298
|
+
while (url.endsWith(")") && opens < closes) {
|
|
299
|
+
url = url.slice(0, -1);
|
|
300
|
+
closes--;
|
|
301
|
+
}
|
|
302
|
+
if (check(url))
|
|
303
|
+
out.push({ type: "link", href: url, children: [{ type: "text", text: url }] });
|
|
304
|
+
else pushText(out, url);
|
|
305
|
+
index += url.length;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (char === "*" || char === "_" || char === "~" && next === "~") {
|
|
310
|
+
const run = runLength(source, index, char);
|
|
311
|
+
const marker = char === "~" ? "~~" : char.repeat(run >= 2 ? 2 : 1);
|
|
312
|
+
const after = source[index + marker.length] ?? "";
|
|
313
|
+
const before = source[index - 1] ?? " ";
|
|
314
|
+
const opens = run === marker.length && after !== "" && !/\s/.test(after) && (char !== "_" || !ALPHANUMERIC.test(before));
|
|
315
|
+
const close = opens ? tables.closingDelimiter(index + marker.length, marker) : -1;
|
|
316
|
+
if (close !== -1) {
|
|
317
|
+
const type = char === "~" ? "delete" : marker.length === 2 ? "strong" : "emphasis";
|
|
318
|
+
out.push({
|
|
319
|
+
type,
|
|
320
|
+
children: parse(source.slice(index + marker.length, close), checks, depth + 1)
|
|
321
|
+
});
|
|
322
|
+
index = close + marker.length;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
pushText(out, char.repeat(run));
|
|
326
|
+
index += run;
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
pushText(out, char);
|
|
330
|
+
index++;
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
function parseInline(source, options = {}) {
|
|
335
|
+
if (source.length > MAX_INLINE_LENGTH) return [{ type: "text", text: source }];
|
|
336
|
+
const checks = {
|
|
337
|
+
link: options.isSafeUrl ?? isSafeUrl,
|
|
338
|
+
image: options.isSafeImageUrl ?? isRelativeUrl
|
|
339
|
+
};
|
|
340
|
+
return parse(source, checks, 0);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/blocks.ts
|
|
344
|
+
var FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/;
|
|
345
|
+
var ATX = /^ {0,3}(#{1,6})(?:[ \t]|$)/;
|
|
346
|
+
var RULE = /^ {0,3}(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
347
|
+
var SETEXT = /^ {0,3}(=+|-+)[ \t]*$/;
|
|
348
|
+
var QUOTE = /^ {0,3}> ?/;
|
|
349
|
+
var LIST = /^( {0,3})([-*+]|(\d{1,9})([.)]))(?:([ \t]+)(.*))?$/;
|
|
350
|
+
var DELIMITER_CELL = /^:?-+:?$/;
|
|
351
|
+
var isBlank = (line) => line.trim() === "";
|
|
352
|
+
var MAX_DEPTH2 = 32;
|
|
353
|
+
function atx(line) {
|
|
354
|
+
const match = ATX.exec(line);
|
|
355
|
+
if (!match) return void 0;
|
|
356
|
+
let text = line.slice(match[0].length - (match[0].endsWith("#") ? 0 : 1)).replace(/[ \t]+$/, "");
|
|
357
|
+
const closing = /[ \t]#+$/.exec(text);
|
|
358
|
+
if (closing) text = text.slice(0, closing.index);
|
|
359
|
+
return { level: match[1].length, text: text.trim() };
|
|
360
|
+
}
|
|
361
|
+
function indentOf(line) {
|
|
362
|
+
return line.length - line.trimStart().length;
|
|
363
|
+
}
|
|
364
|
+
function listMarker(line) {
|
|
365
|
+
const match = LIST.exec(line);
|
|
366
|
+
if (!match) return void 0;
|
|
367
|
+
const indent = match[1].length;
|
|
368
|
+
const marker = match[2];
|
|
369
|
+
const ordered = match[3] !== void 0;
|
|
370
|
+
const spaces = match[5] ?? "";
|
|
371
|
+
const rest = match[6] ?? "";
|
|
372
|
+
const empty = rest.trim() === "";
|
|
373
|
+
const gap = empty ? 1 : spaces.length > 4 ? 1 : spaces.length;
|
|
374
|
+
return {
|
|
375
|
+
indent,
|
|
376
|
+
kind: ordered ? match[4] : marker,
|
|
377
|
+
ordered,
|
|
378
|
+
start: ordered ? Number(match[3]) : 1,
|
|
379
|
+
content: indent + marker.length + gap,
|
|
380
|
+
first: empty ? "" : spaces.length > 4 ? spaces.slice(1) + rest : rest
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function fenceOf(line) {
|
|
384
|
+
const match = FENCE.exec(line);
|
|
385
|
+
if (!match) return void 0;
|
|
386
|
+
const info = match[3].trim();
|
|
387
|
+
if (match[2][0] === "`" && info.includes("`")) return void 0;
|
|
388
|
+
return { indent: match[1].length, char: match[2][0], length: match[2].length, info };
|
|
389
|
+
}
|
|
390
|
+
function interrupts(line) {
|
|
391
|
+
if (fenceOf(line) || ATX.test(line) || RULE.test(line) || QUOTE.test(line)) return true;
|
|
392
|
+
const marker = listMarker(line);
|
|
393
|
+
return marker !== void 0 && marker.first !== "" && (!marker.ordered || marker.start === 1);
|
|
394
|
+
}
|
|
395
|
+
function cells(line) {
|
|
396
|
+
let text = line.trim();
|
|
397
|
+
if (text.startsWith("|")) text = text.slice(1);
|
|
398
|
+
if (text.endsWith("|") && !text.endsWith("\\|")) text = text.slice(0, -1);
|
|
399
|
+
const out = [];
|
|
400
|
+
let cell = "";
|
|
401
|
+
for (let index = 0; index < text.length; index++) {
|
|
402
|
+
const char = text[index];
|
|
403
|
+
if (char === "\\" && text[index + 1] === "|") {
|
|
404
|
+
cell += "\\|";
|
|
405
|
+
index++;
|
|
406
|
+
} else if (char === "|") {
|
|
407
|
+
out.push(cell.trim());
|
|
408
|
+
cell = "";
|
|
409
|
+
} else {
|
|
410
|
+
cell += char;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
out.push(cell.trim());
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
function delimiterRow(line, count) {
|
|
417
|
+
if (line === void 0 || !line.includes("-")) return void 0;
|
|
418
|
+
const row = cells(line);
|
|
419
|
+
if (row.length !== count || !row.every((cell) => DELIMITER_CELL.test(cell))) return void 0;
|
|
420
|
+
return row.map((cell) => {
|
|
421
|
+
const start = cell.startsWith(":");
|
|
422
|
+
const end = cell.endsWith(":");
|
|
423
|
+
return start && end ? "center" : end ? "end" : start ? "start" : null;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function paragraphText(lines) {
|
|
427
|
+
return lines.map((line) => line.trimStart()).join("\n").trimEnd();
|
|
428
|
+
}
|
|
429
|
+
function parseLines(lines, options = {}, depth = 0) {
|
|
430
|
+
const blocks = [];
|
|
431
|
+
const starts = [];
|
|
432
|
+
const inline = (text) => parseInline(text, options);
|
|
433
|
+
if (depth > MAX_DEPTH2) {
|
|
434
|
+
const text = paragraphText(lines.filter((line) => !isBlank(line)));
|
|
435
|
+
return text === "" ? { blocks, starts } : { blocks: [{ type: "paragraph", children: inline(text) }], starts: [0] };
|
|
436
|
+
}
|
|
437
|
+
let index = 0;
|
|
438
|
+
const add = (block, start) => {
|
|
439
|
+
blocks.push(block);
|
|
440
|
+
starts.push(start);
|
|
441
|
+
};
|
|
442
|
+
while (index < lines.length) {
|
|
443
|
+
const line = lines[index];
|
|
444
|
+
const start = index;
|
|
445
|
+
if (isBlank(line)) {
|
|
446
|
+
index++;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const fence = fenceOf(line);
|
|
450
|
+
if (fence) {
|
|
451
|
+
const close = new RegExp(`^ {0,3}\\${fence.char}{${fence.length},}[ \\t]*$`);
|
|
452
|
+
const body = [];
|
|
453
|
+
index++;
|
|
454
|
+
let open = true;
|
|
455
|
+
while (index < lines.length) {
|
|
456
|
+
const current = lines[index];
|
|
457
|
+
index++;
|
|
458
|
+
if (close.test(current)) {
|
|
459
|
+
open = false;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
const strip = Math.min(fence.indent, indentOf(current));
|
|
463
|
+
body.push(current.slice(strip));
|
|
464
|
+
}
|
|
465
|
+
const lang = fence.info.split(/\s+/)[0];
|
|
466
|
+
const block = { type: "code", text: body.join("\n"), open };
|
|
467
|
+
add(lang ? { type: "code", lang, text: block.text, open } : block, start);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const heading = atx(line);
|
|
471
|
+
if (heading) {
|
|
472
|
+
const level2 = heading.level;
|
|
473
|
+
add({ type: "heading", level: level2, children: inline(heading.text) }, start);
|
|
474
|
+
index++;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (RULE.test(line)) {
|
|
478
|
+
add({ type: "rule" }, start);
|
|
479
|
+
index++;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
if (QUOTE.test(line)) {
|
|
483
|
+
const inner = [];
|
|
484
|
+
let lazy = false;
|
|
485
|
+
while (index < lines.length) {
|
|
486
|
+
const current = lines[index];
|
|
487
|
+
if (QUOTE.test(current)) {
|
|
488
|
+
const stripped = current.replace(QUOTE, "");
|
|
489
|
+
inner.push(stripped);
|
|
490
|
+
lazy = !isBlank(stripped) && !fenceOf(stripped);
|
|
491
|
+
} else if (lazy && !isBlank(current) && !interrupts(current)) {
|
|
492
|
+
inner.push(current);
|
|
493
|
+
} else {
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
index++;
|
|
497
|
+
}
|
|
498
|
+
add({ type: "blockquote", children: parseLines(inner, options, depth + 1).blocks }, start);
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const marker = listMarker(line);
|
|
502
|
+
if (marker) {
|
|
503
|
+
const items = [];
|
|
504
|
+
let loose = false;
|
|
505
|
+
let item = [marker.first];
|
|
506
|
+
let content = marker.content;
|
|
507
|
+
let previousBlank = false;
|
|
508
|
+
let previousText = marker.first !== "";
|
|
509
|
+
const finish = () => {
|
|
510
|
+
while (item.length > 1 && isBlank(item.at(-1))) item.pop();
|
|
511
|
+
const parsed = parseLines(item, options, depth + 1);
|
|
512
|
+
if (parsed.starts.some((first, position) => position > 0 && isBlank(item[first - 1] ?? ""))) {
|
|
513
|
+
loose = true;
|
|
514
|
+
}
|
|
515
|
+
items.push(parsed.blocks);
|
|
516
|
+
};
|
|
517
|
+
index++;
|
|
518
|
+
while (index < lines.length) {
|
|
519
|
+
const current = lines[index];
|
|
520
|
+
if (isBlank(current)) {
|
|
521
|
+
item.push("");
|
|
522
|
+
previousBlank = true;
|
|
523
|
+
previousText = false;
|
|
524
|
+
index++;
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
if (indentOf(current) >= content) {
|
|
528
|
+
item.push(current.slice(content));
|
|
529
|
+
} else {
|
|
530
|
+
const sibling = listMarker(current);
|
|
531
|
+
if (sibling && sibling.kind === marker.kind && sibling.indent < content) {
|
|
532
|
+
finish();
|
|
533
|
+
if (previousBlank) loose = true;
|
|
534
|
+
item = [sibling.first];
|
|
535
|
+
content = sibling.content;
|
|
536
|
+
previousText = sibling.first !== "";
|
|
537
|
+
previousBlank = false;
|
|
538
|
+
index++;
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
const lazy = previousText && !interrupts(current);
|
|
542
|
+
if (!lazy) break;
|
|
543
|
+
item.push(current.trim());
|
|
544
|
+
}
|
|
545
|
+
previousBlank = false;
|
|
546
|
+
previousText = true;
|
|
547
|
+
index++;
|
|
548
|
+
}
|
|
549
|
+
finish();
|
|
550
|
+
const list = marker.ordered ? { type: "list", ordered: true, start: marker.start, tight: !loose, items } : { type: "list", ordered: false, tight: !loose, items };
|
|
551
|
+
add(list, start);
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
if (line.includes("|")) {
|
|
555
|
+
const head = cells(line);
|
|
556
|
+
const align = delimiterRow(lines[index + 1], head.length);
|
|
557
|
+
if (align) {
|
|
558
|
+
const rows = [];
|
|
559
|
+
index += 2;
|
|
560
|
+
while (index < lines.length && !isBlank(lines[index]) && !interrupts(lines[index])) {
|
|
561
|
+
const row = cells(lines[index]);
|
|
562
|
+
rows.push(head.map((_, column) => inline(row[column] ?? "")));
|
|
563
|
+
index++;
|
|
564
|
+
}
|
|
565
|
+
add({ type: "table", align, head: head.map((cell) => inline(cell)), rows }, start);
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const paragraph = [line];
|
|
570
|
+
index++;
|
|
571
|
+
let level;
|
|
572
|
+
while (index < lines.length) {
|
|
573
|
+
const current = lines[index];
|
|
574
|
+
const setext = SETEXT.exec(current);
|
|
575
|
+
if (setext) {
|
|
576
|
+
level = setext[1][0] === "=" ? 1 : 2;
|
|
577
|
+
index++;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
if (isBlank(current) || interrupts(current)) break;
|
|
581
|
+
paragraph.push(current);
|
|
582
|
+
index++;
|
|
583
|
+
}
|
|
584
|
+
const children = inline(paragraphText(paragraph));
|
|
585
|
+
add(level ? { type: "heading", level, children } : { type: "paragraph", children }, start);
|
|
586
|
+
}
|
|
587
|
+
return { blocks, starts };
|
|
588
|
+
}
|
|
589
|
+
function splitLines(text) {
|
|
590
|
+
return text.split("\n").map((line) => line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
591
|
+
}
|
|
592
|
+
function parseMarkdown(text, options = {}) {
|
|
593
|
+
return parseLines(splitLines(text), options).blocks;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// src/stream.ts
|
|
597
|
+
function equal(a, b) {
|
|
598
|
+
if (a === b) return true;
|
|
599
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
600
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
601
|
+
const keys = Object.keys(a);
|
|
602
|
+
if (keys.length !== Object.keys(b).length) return false;
|
|
603
|
+
return keys.every(
|
|
604
|
+
(key) => equal(a[key], b[key])
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
function createMarkdownStream(options = {}) {
|
|
608
|
+
const committed = [];
|
|
609
|
+
let pending = "";
|
|
610
|
+
let last = [];
|
|
611
|
+
let done = false;
|
|
612
|
+
const snapshot = () => ({ blocks: [...committed, ...last], done });
|
|
613
|
+
function commit() {
|
|
614
|
+
const complete = pending.lastIndexOf("\n") + 1;
|
|
615
|
+
if (complete === 0) return;
|
|
616
|
+
const raw = pending.slice(0, complete).split("\n");
|
|
617
|
+
const { blocks, starts } = parseLines(splitLines(pending.slice(0, complete)), options);
|
|
618
|
+
if (blocks.length < 2) return;
|
|
619
|
+
committed.push(
|
|
620
|
+
...blocks.slice(0, -1).map((block, index) => equal(block, last[index]) ? last[index] : block)
|
|
621
|
+
);
|
|
622
|
+
let offset = 0;
|
|
623
|
+
for (let line = 0; line < starts.at(-1); line++) offset += raw[line].length + 1;
|
|
624
|
+
pending = pending.slice(offset);
|
|
625
|
+
last = last.slice(blocks.length - 1);
|
|
626
|
+
}
|
|
627
|
+
function parse2() {
|
|
628
|
+
commit();
|
|
629
|
+
const previous = last;
|
|
630
|
+
last = parseLines(splitLines(pending), options).blocks.map(
|
|
631
|
+
(block, index) => equal(block, previous[index]) ? previous[index] : block
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
return {
|
|
635
|
+
get pending() {
|
|
636
|
+
return pending;
|
|
637
|
+
},
|
|
638
|
+
push(chunk) {
|
|
639
|
+
if (done) return snapshot();
|
|
640
|
+
pending += chunk;
|
|
641
|
+
parse2();
|
|
642
|
+
return snapshot();
|
|
643
|
+
},
|
|
644
|
+
end() {
|
|
645
|
+
done = true;
|
|
646
|
+
return snapshot();
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export { createMarkdownStream, isRelativeUrl, isSafeUrl, parseInline, parseLines, parseMarkdown };
|
|
652
|
+
//# sourceMappingURL=index.js.map
|
|
653
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/url.ts","../src/inline.ts","../src/blocks.ts","../src/stream.ts"],"names":["MAX_DEPTH","level","parse"],"mappings":";AAAA,IAAM,OAAA,uBAAc,GAAA,CAAI,CAAC,QAAQ,OAAA,EAAS,QAAA,EAAU,KAAK,CAAC,CAAA;AAG1D,SAAS,QAAQ,GAAA,EAAqB;AACpC,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,OAAO,QAAQ,GAAA,CAAI,MAAA,IAAU,IAAI,UAAA,CAAW,KAAK,KAAK,EAAA,EAAM,KAAA,EAAA;AAC5D,EAAA,IAAI,GAAA,GAAM,EAAA;AACV,EAAA,KAAA,MAAW,IAAA,IAAQ,GAAA,CAAI,KAAA,CAAM,KAAK,CAAA,EAAG;AACnC,IAAA,IAAI,SAAS,GAAA,IAAQ,IAAA,KAAS,IAAA,IAAQ,IAAA,KAAS,MAAM,GAAA,IAAO,IAAA;AAAA,EAC9D;AACA,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,UAAU,GAAA,EAAsB;AAC9C,EAAA,MAAM,KAAA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mailto', 'tel'])\n\n/** The URL as a browser reads its scheme: no leading control characters or spaces, no tabs or line ends. */\nfunction cleaned(url: string): string {\n let start = 0\n while (start < url.length && url.charCodeAt(start) <= 0x20) start++\n let out = ''\n for (const char of url.slice(start)) {\n if (char !== '\\t' && char !== '\\n' && char !== '\\r') out += char\n }\n return out\n}\n\n/** True for an `http:`, `https:`, `mailto:` or `tel:` URL, and for a relative URL. */\nexport function isSafeUrl(url: string): boolean {\n const value = cleaned(url)\n const colon = value.indexOf(':')\n if (colon === -1) return true\n if (value.startsWith('#')) return true\n const separator = value.search(/[/?]/)\n // A colon after the first \"/\" or \"?\" is part of the path or the query. Before it, the text is\n // a scheme, and an unknown scheme is refused, also when a browser would read it as a path.\n if (separator !== -1 && separator < colon) return true\n return SCHEMES.has(value.slice(0, colon).toLowerCase())\n}\n\n/**\n * True for a relative URL with no scheme and no host: a path, a query or a fragment. The default\n * check for an image, because the browser loads an image with no click.\n */\nexport function isRelativeUrl(url: string): boolean {\n const value = cleaned(url)\n // A browser reads \"\\\" as \"/\", so \"/\\host\" and \"\\\\host\" go to a host.\n if (value === '' || value.startsWith('//') || value.includes('\\\\')) return false\n const colon = value.indexOf(':')\n const separator = value.search(/[/?#]/)\n return colon === -1 || (separator !== -1 && separator < colon)\n}\n","import type { Inline, MarkdownOptions } from './types'\nimport { isRelativeUrl, isSafeUrl } from './url'\n\nconst PUNCTUATION = /[!-/:-@[-`{-~]/\nconst ALPHANUMERIC = /[\\p{L}\\p{N}]/u\nconst AUTOLINK = /^<([a-zA-Z][a-zA-Z0-9+.-]{1,31}:[^\\s<>]*)>/\nconst BARE_URL = /^https?:\\/\\/[^\\s<]+/\n\ntype Check = (url: string) => boolean\ninterface Checks {\n link: Check\n image: Check\n}\n\n/** Adds text, and joins it to the text node before it. */\nfunction pushText(out: Inline[], text: string): void {\n if (text === '') return\n const last = out.at(-1)\n if (last?.type === 'text') last.text += text\n else out.push({ type: 'text', text })\n}\n\nfunction pushAll(out: Inline[], nodes: Inline[]): void {\n for (const node of nodes) {\n if (node.type === 'text') pushText(out, node.text)\n else out.push(node)\n }\n}\n\n/** The text of a list of nodes, with no markup. */\nfunction plainText(nodes: Inline[]): string {\n return nodes\n .map(node => {\n if (node.type === 'text' || node.type === 'code') return node.text\n if (node.type === 'image') return node.alt\n if (node.type === 'break') return '\\n'\n return plainText(node.children)\n })\n .join('')\n}\n\nfunction runLength(source: string, at: number, char: string): number {\n let end = at\n while (source[end] === char) end++\n return end - at\n}\n\n/** The first item of a sorted list that is at least `min`, or undefined. */\nfunction firstFrom(list: readonly number[] | undefined, min: number): number | undefined {\n if (!list) return undefined\n let low = 0\n let high = list.length\n while (low < high) {\n const middle = (low + high) >> 1\n if (list[middle]! < min) low = middle + 1\n else high = middle\n }\n return list[low]\n}\n\n/**\n * The matches of one source, found in one pass, so that each look-up is fast. Without them, a\n * search from each opener to the end of the text is quadratic, and a long reply freezes the tab.\n */\nclass Tables {\n /** For each length, the start of each backtick run of that length. */\n readonly #runs = new Map<number, number[]>()\n /** The positions that the scan from the start reaches: escapes and code spans are skipped. */\n readonly #onWalk: Uint8Array\n /** \"[\" to its \"]\". */\n readonly #brackets = new Map<number, number>()\n /** `char + length` to each run that can close emphasis. */\n readonly #closers = new Map<string, number[]>()\n /** \"(\" to its \")\", in a link destination. */\n readonly #parens = new Map<number, number>()\n readonly #next = new Map<string, Int32Array>()\n\n constructor(readonly source: string) {\n const length = source.length\n for (let at = 0; at < length;) {\n if (source[at] !== '`') {\n at++\n continue\n }\n const run = runLength(source, at, '`')\n let list = this.#runs.get(run)\n if (!list) this.#runs.set(run, (list = []))\n list.push(at)\n at += run\n }\n\n this.#onWalk = new Uint8Array(length + 1)\n const open: number[] = []\n for (let at = 0; at < length;) {\n this.#onWalk[at] = 1\n const char = source[at]!\n if (char === '\\\\') {\n at += 2\n continue\n }\n if (char === '`') {\n const span = this.codeSpanEnd(at)\n at = span ? span.end + span.length : at + runLength(source, at, '`')\n continue\n }\n if (char === '[') open.push(at)\n else if (char === ']' && open.length > 0) this.#brackets.set(open.pop()!, at)\n else if (\n (char === '*' || char === '_' || char === '~') &&\n !(this.#onWalk[at - 1] && source[at - 1] === char)\n ) {\n const run = runLength(source, at, char)\n const before = source[at - 1] ?? ' '\n const after = source[at + run] ?? ' '\n if (!/\\s/.test(before) && (char !== '_' || !ALPHANUMERIC.test(after))) {\n const key = char + run\n let list = this.#closers.get(key)\n if (!list) this.#closers.set(key, (list = []))\n list.push(at)\n }\n }\n at++\n }\n\n const parens: number[] = []\n for (let at = 0; at < length; at++) {\n const char = source[at]\n if (char === '\\\\' && PUNCTUATION.test(source[at + 1] ?? '')) at++\n else if (char === '(') parens.push(at)\n else if (char === ')' && parens.length > 0) this.#parens.set(parens.pop()!, at)\n }\n }\n\n /** The end of a code span that starts at `at`, or undefined. */\n codeSpanEnd(at: number): { end: number; length: number } | undefined {\n const length = runLength(this.source, at, '`')\n const end = firstFrom(this.#runs.get(length), at + length)\n return end === undefined ? undefined : { end, length }\n }\n\n /** The index of the \"]\" that closes the \"[\" at `at`, or -1. */\n closingBracket(at: number): number {\n return (this.#onWalk[at] && this.#brackets.get(at)) || -1\n }\n\n /** The index of the delimiter run that closes `marker`, from `from`, or -1. */\n closingDelimiter(from: number, marker: string): number {\n if (!this.#onWalk[from]) return -1\n return firstFrom(this.#closers.get(marker[0]! + marker.length), from + 1) ?? -1\n }\n\n /** The \")\" that closes the \"(\" at `at`, or -1. */\n closingParen(at: number): number {\n return this.#parens.get(at) ?? -1\n }\n\n /** The first index from `from` where `test` is true for the character, or the length. */\n next(name: string, test: (char: string) => boolean, from: number): number {\n let table = this.#next.get(name)\n if (!table) {\n const source = this.source\n table = new Int32Array(source.length + 1)\n table[source.length] = source.length\n for (let at = source.length - 1; at >= 0; at--) {\n table[at] = test(source[at]!) ? at : table[at + 1]!\n }\n this.#next.set(name, table)\n }\n return from >= this.source.length ? this.source.length : table[from]!\n }\n}\n\nconst isSpace = (char: string) => /\\s/.test(char)\nconst notBlank = (char: string) => char !== ' ' && char !== '\\n'\n\n/** The index of `char` from `from`, or -1. */\nfunction indexOf(tables: Tables, char: string, from: number): number {\n const at = tables.next(char, c => c === char, from)\n return at === tables.source.length ? -1 : at\n}\n\n/** Reads `(url \"title\")` at `at`. Gives the URL and the index after \")\". */\nfunction destination(tables: Tables, at: number): { url: string; end: number } | undefined {\n const source = tables.source\n if (source[at] !== '(') return undefined\n let index = tables.next('blank', notBlank, at + 1)\n // The URL is read only when the destination is complete: a slice for each failed opener is\n // quadratic.\n let url: () => string\n if (source[index] === '<') {\n const close = indexOf(tables, '>', index)\n if (close === -1) return undefined\n const line = indexOf(tables, '\\n', index)\n if (line !== -1 && line < close) return undefined\n const from = index + 1\n url = () => source.slice(from, close)\n index = close + 1\n } else {\n const paren = tables.closingParen(at)\n const space = tables.next('space', isSpace, index)\n const from = index\n const end = paren === -1 ? space : Math.min(paren, space)\n url = () => source.slice(from, end).replace(/\\\\([!-/:-@[-`{-~])/g, '$1')\n index = end\n }\n index = tables.next('blank', notBlank, index)\n const quote = source[index]\n if (quote === '\"' || quote === \"'\" || quote === '(') {\n const close = indexOf(tables, quote === '(' ? ')' : quote, index + 1)\n if (close === -1) return undefined\n index = tables.next('blank', notBlank, close + 1)\n }\n return source[index] === ')' ? { url: url(), end: index + 1 } : undefined\n}\n\n/** Nested emphasis and links deeper than this are text. The limit keeps the cost linear. */\nconst MAX_DEPTH = 16\n\n/** A block with more characters shows as plain text. */\nexport const MAX_INLINE_LENGTH = 20_000\n\nconst AUTOLINK_AT = new RegExp(AUTOLINK.source.slice(1), 'y')\nconst BARE_URL_AT = new RegExp(BARE_URL.source.slice(1), 'y')\n\nfunction parse(source: string, checks: Checks, depth: number): Inline[] {\n const check = checks.link\n if (depth > MAX_DEPTH) return source === '' ? [] : [{ type: 'text', text: source }]\n const tables = new Tables(source)\n const out: Inline[] = []\n let index = 0\n\n while (index < source.length) {\n const char = source[index]!\n const next = source[index + 1] ?? ''\n\n if (char === '\\\\') {\n if (next === '\\n') {\n out.push({ type: 'break' })\n index += 2\n } else if (PUNCTUATION.test(next)) {\n pushText(out, next)\n index += 2\n } else {\n pushText(out, char)\n index++\n }\n continue\n }\n\n if (char === '\\n') {\n const last = out.at(-1)\n if (last?.type === 'text' && / {2,}$/.test(last.text)) {\n last.text = last.text.replace(/ +$/, '')\n out.push({ type: 'break' })\n } else {\n if (last?.type === 'text') last.text = last.text.replace(/ +$/, '')\n pushText(out, '\\n')\n }\n index++\n continue\n }\n\n if (char === '`') {\n const span = tables.codeSpanEnd(index)\n if (!span) {\n const run = runLength(source, index, '`')\n pushText(out, '`'.repeat(run))\n index += run\n continue\n }\n let text = source.slice(index + span.length, span.end).replace(/\\n/g, ' ')\n if (text.length > 2 && text.startsWith(' ') && text.endsWith(' ') && text.trim() !== '') {\n text = text.slice(1, -1)\n }\n out.push({ type: 'code', text })\n index = span.end + span.length\n continue\n }\n\n if (char === '[' || (char === '!' && next === '[')) {\n const image = char === '!'\n const open = image ? index + 1 : index\n const close = tables.closingBracket(open)\n const target = close === -1 ? undefined : destination(tables, close + 1)\n if (target) {\n const label = parse(source.slice(open + 1, close), checks, depth + 1)\n if (image) {\n const alt = plainText(label)\n if (check(target.url) && checks.image(target.url)) {\n out.push({ type: 'image', src: target.url, alt })\n } else pushText(out, alt)\n } else if (check(target.url)) {\n out.push({ type: 'link', href: target.url, children: label })\n } else {\n pushAll(out, label)\n }\n index = target.end\n continue\n }\n pushText(out, char)\n index++\n continue\n }\n\n if (char === '<') {\n AUTOLINK_AT.lastIndex = index\n const match = AUTOLINK_AT.exec(source)\n if (match && check(match[1]!)) {\n out.push({ type: 'link', href: match[1]!, children: [{ type: 'text', text: match[1]! }] })\n index += match[0].length\n continue\n }\n }\n\n if (char === 'h' && !ALPHANUMERIC.test(source[index - 1] ?? ' ')) {\n BARE_URL_AT.lastIndex = index\n const match = BARE_URL_AT.exec(source)\n if (match) {\n let url = match[0].replace(/[.,:;!?'\"]+$/, '')\n const opens = url.match(/\\(/g)?.length ?? 0\n let closes = url.match(/\\)/g)?.length ?? 0\n while (url.endsWith(')') && opens < closes) {\n url = url.slice(0, -1)\n closes--\n }\n // A URL that the check refuses stays text, so the next \"h\" does not read it again.\n if (check(url))\n out.push({ type: 'link', href: url, children: [{ type: 'text', text: url }] })\n else pushText(out, url)\n index += url.length\n continue\n }\n }\n\n if (char === '*' || char === '_' || (char === '~' && next === '~')) {\n const run = runLength(source, index, char)\n const marker = char === '~' ? '~~' : char.repeat(run >= 2 ? 2 : 1)\n const after = source[index + marker.length] ?? ''\n const before = source[index - 1] ?? ' '\n const opens =\n run === marker.length &&\n after !== '' &&\n !/\\s/.test(after) &&\n (char !== '_' || !ALPHANUMERIC.test(before))\n const close = opens ? tables.closingDelimiter(index + marker.length, marker) : -1\n if (close !== -1) {\n const type = char === '~' ? 'delete' : marker.length === 2 ? 'strong' : 'emphasis'\n out.push({\n type,\n children: parse(source.slice(index + marker.length, close), checks, depth + 1),\n })\n index = close + marker.length\n continue\n }\n pushText(out, char.repeat(run))\n index += run\n continue\n }\n\n pushText(out, char)\n index++\n }\n return out\n}\n\n/** Parses the inline markdown of one block. HTML stays text. */\nexport function parseInline(source: string, options: MarkdownOptions = {}): Inline[] {\n if (source.length > MAX_INLINE_LENGTH) return [{ type: 'text', text: source }]\n const checks = {\n link: options.isSafeUrl ?? isSafeUrl,\n image: options.isSafeImageUrl ?? isRelativeUrl,\n }\n return parse(source, checks, 0)\n}\n","import { parseInline } from './inline'\nimport type { Align, Block, Inline, MarkdownOptions } from './types'\n\nconst FENCE = /^( {0,3})(`{3,}|~{3,})(.*)$/\nconst ATX = /^ {0,3}(#{1,6})(?:[ \\t]|$)/\nconst RULE = /^ {0,3}(?:(?:\\*[ \\t]*){3,}|(?:-[ \\t]*){3,}|(?:_[ \\t]*){3,})$/\nconst SETEXT = /^ {0,3}(=+|-+)[ \\t]*$/\nconst QUOTE = /^ {0,3}> ?/\nconst LIST = /^( {0,3})([-*+]|(\\d{1,9})([.)]))(?:([ \\t]+)(.*))?$/\nconst DELIMITER_CELL = /^:?-+:?$/\n\n/** The blocks of some lines, and the index of the first line of each block. */\nexport interface Parsed {\n blocks: Block[]\n starts: number[]\n}\n\ninterface ListMarker {\n indent: number\n /** `-`, `*`, `+`, `.` or `)`. Two items of one list have the same kind. */\n kind: string\n ordered: boolean\n start: number\n /** The column where the content of the item starts. */\n content: number\n /** The first line of content. */\n first: string\n}\n\nconst isBlank = (line: string) => line.trim() === ''\n\n/** Block quotes and lists nested deeper than this are a paragraph. The limit keeps the stack. */\nconst MAX_DEPTH = 32\n\n/**\n * The text of an ATX heading, or undefined. The text has no closing \"#\" sequence. A regular\n * expression with a lazy group is quadratic on a long line of spaces, so this is a loop.\n */\nfunction atx(line: string): { level: number; text: string } | undefined {\n const match = ATX.exec(line)\n if (!match) return undefined\n let text = line.slice(match[0].length - (match[0].endsWith('#') ? 0 : 1)).replace(/[ \\t]+$/, '')\n const closing = /[ \\t]#+$/.exec(text)\n if (closing) text = text.slice(0, closing.index)\n return { level: match[1]!.length, text: text.trim() }\n}\n\nfunction indentOf(line: string): number {\n return line.length - line.trimStart().length\n}\n\nfunction listMarker(line: string): ListMarker | undefined {\n const match = LIST.exec(line)\n if (!match) return undefined\n const indent = match[1]!.length\n const marker = match[2]!\n const ordered = match[3] !== undefined\n const spaces = match[5] ?? ''\n const rest = match[6] ?? ''\n const empty = rest.trim() === ''\n // More than four spaces after the marker start an indented line in the item; one space counts.\n const gap = empty ? 1 : spaces.length > 4 ? 1 : spaces.length\n return {\n indent,\n kind: ordered ? match[4]! : marker,\n ordered,\n start: ordered ? Number(match[3]) : 1,\n content: indent + marker.length + gap,\n first: empty ? '' : spaces.length > 4 ? spaces.slice(1) + rest : rest,\n }\n}\n\nfunction fenceOf(line: string) {\n const match = FENCE.exec(line)\n if (!match) return undefined\n const info = match[3]!.trim()\n // The info string of a backtick fence cannot hold a backtick.\n if (match[2]![0] === '`' && info.includes('`')) return undefined\n return { indent: match[1]!.length, char: match[2]![0]!, length: match[2]!.length, info }\n}\n\n/** True when the line starts a block that ends a paragraph. */\nfunction interrupts(line: string): boolean {\n if (fenceOf(line) || ATX.test(line) || RULE.test(line) || QUOTE.test(line)) return true\n const marker = listMarker(line)\n // An empty item, or an ordered item that does not start at 1, cannot end a paragraph.\n return marker !== undefined && marker.first !== '' && (!marker.ordered || marker.start === 1)\n}\n\n/** The cells of a table row. An escaped pipe stays in the cell, and the inline parser reads it. */\nfunction cells(line: string): string[] {\n let text = line.trim()\n if (text.startsWith('|')) text = text.slice(1)\n if (text.endsWith('|') && !text.endsWith('\\\\|')) text = text.slice(0, -1)\n const out: string[] = []\n let cell = ''\n for (let index = 0; index < text.length; index++) {\n const char = text[index]\n if (char === '\\\\' && text[index + 1] === '|') {\n cell += '\\\\|'\n index++\n } else if (char === '|') {\n out.push(cell.trim())\n cell = ''\n } else {\n cell += char\n }\n }\n out.push(cell.trim())\n return out\n}\n\nfunction delimiterRow(line: string | undefined, count: number): Align[] | undefined {\n if (line === undefined || !line.includes('-')) return undefined\n const row = cells(line)\n if (row.length !== count || !row.every(cell => DELIMITER_CELL.test(cell))) return undefined\n return row.map(cell => {\n const start = cell.startsWith(':')\n const end = cell.endsWith(':')\n return start && end ? 'center' : end ? 'end' : start ? 'start' : null\n })\n}\n\nfunction paragraphText(lines: string[]): string {\n return lines\n .map(line => line.trimStart())\n .join('\\n')\n .trimEnd()\n}\n\n/** Parses lines to blocks. */\nexport function parseLines(lines: string[], options: MarkdownOptions = {}, depth = 0): Parsed {\n const blocks: Block[] = []\n const starts: number[] = []\n const inline = (text: string): Inline[] => parseInline(text, options)\n if (depth > MAX_DEPTH) {\n const text = paragraphText(lines.filter(line => !isBlank(line)))\n return text === ''\n ? { blocks, starts }\n : { blocks: [{ type: 'paragraph', children: inline(text) }], starts: [0] }\n }\n let index = 0\n\n const add = (block: Block, start: number) => {\n blocks.push(block)\n starts.push(start)\n }\n\n while (index < lines.length) {\n const line = lines[index]!\n const start = index\n\n if (isBlank(line)) {\n index++\n continue\n }\n\n const fence = fenceOf(line)\n if (fence) {\n const close = new RegExp(`^ {0,3}\\\\${fence.char}{${fence.length},}[ \\\\t]*$`)\n const body: string[] = []\n index++\n let open = true\n while (index < lines.length) {\n const current = lines[index]!\n index++\n if (close.test(current)) {\n open = false\n break\n }\n const strip = Math.min(fence.indent, indentOf(current))\n body.push(current.slice(strip))\n }\n const lang = fence.info.split(/\\s+/)[0]\n const block: Block = { type: 'code', text: body.join('\\n'), open }\n add(lang ? { type: 'code', lang, text: block.text, open } : block, start)\n continue\n }\n\n const heading = atx(line)\n if (heading) {\n const level = heading.level as 1 | 2 | 3 | 4 | 5 | 6\n add({ type: 'heading', level, children: inline(heading.text) }, start)\n index++\n continue\n }\n\n if (RULE.test(line)) {\n add({ type: 'rule' }, start)\n index++\n continue\n }\n\n if (QUOTE.test(line)) {\n const inner: string[] = []\n let lazy = false\n while (index < lines.length) {\n const current = lines[index]!\n if (QUOTE.test(current)) {\n const stripped = current.replace(QUOTE, '')\n inner.push(stripped)\n lazy = !isBlank(stripped) && !fenceOf(stripped)\n } else if (lazy && !isBlank(current) && !interrupts(current)) {\n inner.push(current)\n } else {\n break\n }\n index++\n }\n add({ type: 'blockquote', children: parseLines(inner, options, depth + 1).blocks }, start)\n continue\n }\n\n const marker = listMarker(line)\n if (marker) {\n const items: Block[][] = []\n let loose = false\n let item: string[] = [marker.first]\n let content = marker.content\n let previousBlank = false\n let previousText = marker.first !== ''\n\n const finish = () => {\n // Blank lines at the end belong to the list, not to the item.\n while (item.length > 1 && isBlank(item.at(-1)!)) item.pop()\n const parsed = parseLines(item, options, depth + 1)\n if (\n parsed.starts.some((first, position) => position > 0 && isBlank(item[first - 1] ?? ''))\n ) {\n loose = true\n }\n items.push(parsed.blocks)\n }\n\n index++\n while (index < lines.length) {\n const current = lines[index]!\n if (isBlank(current)) {\n item.push('')\n previousBlank = true\n previousText = false\n index++\n continue\n }\n if (indentOf(current) >= content) {\n item.push(current.slice(content))\n } else {\n const sibling = listMarker(current)\n if (sibling && sibling.kind === marker.kind && sibling.indent < content) {\n finish()\n if (previousBlank) loose = true\n item = [sibling.first]\n content = sibling.content\n previousText = sibling.first !== ''\n previousBlank = false\n index++\n continue\n }\n // A line that cannot end a paragraph continues the paragraph of the item.\n const lazy = previousText && !interrupts(current)\n if (!lazy) break\n item.push(current.trim())\n }\n previousBlank = false\n previousText = true\n index++\n }\n finish()\n const list: Block = marker.ordered\n ? { type: 'list', ordered: true, start: marker.start, tight: !loose, items }\n : { type: 'list', ordered: false, tight: !loose, items }\n add(list, start)\n continue\n }\n\n if (line.includes('|')) {\n const head = cells(line)\n const align = delimiterRow(lines[index + 1], head.length)\n if (align) {\n const rows: Inline[][][] = []\n index += 2\n // As in GFM, the rows end at a blank line or at the start of another block. A row with no\n // pipe is a row too, so a later chunk of the line cannot move it out of the table.\n while (index < lines.length && !isBlank(lines[index]!) && !interrupts(lines[index]!)) {\n const row = cells(lines[index]!)\n rows.push(head.map((_, column) => inline(row[column] ?? '')))\n index++\n }\n add({ type: 'table', align, head: head.map(cell => inline(cell)), rows }, start)\n continue\n }\n }\n\n const paragraph = [line]\n index++\n let level: 1 | 2 | undefined\n while (index < lines.length) {\n const current = lines[index]!\n const setext = SETEXT.exec(current)\n if (setext) {\n level = setext[1]![0] === '=' ? 1 : 2\n index++\n break\n }\n if (isBlank(current) || interrupts(current)) break\n paragraph.push(current)\n index++\n }\n const children = inline(paragraphText(paragraph))\n add(level ? { type: 'heading', level, children } : { type: 'paragraph', children }, start)\n }\n\n return { blocks, starts }\n}\n\n/** Splits text into lines, and removes the carriage return of a CRLF line end. */\nexport function splitLines(text: string): string[] {\n return text.split('\\n').map(line => (line.endsWith('\\r') ? line.slice(0, -1) : line))\n}\n\n/** Parses markdown to a tree of blocks. The tree holds no HTML. */\nexport function parseMarkdown(text: string, options: MarkdownOptions = {}): Block[] {\n return parseLines(splitLines(text), options).blocks\n}\n","import { parseLines, splitLines } from './blocks'\nimport type { Block, MarkdownOptions } from './types'\n\nexport interface MarkdownSnapshot {\n /** The blocks so far. A block that did not change keeps its identity. */\n blocks: Block[]\n done: boolean\n}\n\nexport interface MarkdownStream {\n push(chunk: string): MarkdownSnapshot\n end(): MarkdownSnapshot\n /** The text after the last committed block. Only this text is parsed again. */\n readonly pending: string\n}\n\nfunction equal(a: unknown, b: unknown): boolean {\n if (a === b) return true\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return false\n if (Array.isArray(a) !== Array.isArray(b)) return false\n const keys = Object.keys(a)\n if (keys.length !== Object.keys(b).length) return false\n return keys.every(key =>\n equal((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key]),\n )\n}\n\n/**\n * Parses markdown while it streams.\n *\n * Only complete lines decide which blocks are final: a partial line can change how the lines\n * before it parse (`#` is a heading, `#tag` is text). In the complete lines, each block before\n * the last one is final, because later text can only change the last block. Each push parses\n * again only the text after the final blocks.\n */\nexport function createMarkdownStream(options: MarkdownOptions = {}): MarkdownStream {\n const committed: Block[] = []\n let pending = ''\n let last: Block[] = []\n let done = false\n\n const snapshot = (): MarkdownSnapshot => ({ blocks: [...committed, ...last], done })\n\n function commit() {\n const complete = pending.lastIndexOf('\\n') + 1\n if (complete === 0) return\n const raw = pending.slice(0, complete).split('\\n')\n const { blocks, starts } = parseLines(splitLines(pending.slice(0, complete)), options)\n if (blocks.length < 2) return\n // A block that did not change keeps the identity that the last snapshot gave it.\n committed.push(\n ...blocks\n .slice(0, -1)\n .map((block, index) => (equal(block, last[index]) ? last[index]! : block)),\n )\n // The offset of the first line of the last block, in the raw text.\n let offset = 0\n for (let line = 0; line < starts.at(-1)!; line++) offset += raw[line]!.length + 1\n pending = pending.slice(offset)\n last = last.slice(blocks.length - 1)\n }\n\n function parse() {\n commit()\n const previous = last\n last = parseLines(splitLines(pending), options).blocks.map((block, index) =>\n equal(block, previous[index]) ? previous[index]! : block,\n )\n }\n\n return {\n get pending() {\n return pending\n },\n push(chunk) {\n if (done) return snapshot()\n pending += chunk\n parse()\n return snapshot()\n },\n end() {\n done = true\n return snapshot()\n },\n }\n}\n"]}
|
package/dist/inline.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Inline, MarkdownOptions } from './types';
|
|
2
|
+
/** A block with more characters shows as plain text. */
|
|
3
|
+
export declare const MAX_INLINE_LENGTH = 20000;
|
|
4
|
+
/** Parses the inline markdown of one block. HTML stays text. */
|
|
5
|
+
export declare function parseInline(source: string, options?: MarkdownOptions): Inline[];
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Block, MarkdownOptions } from './types';
|
|
2
|
+
export interface MarkdownSnapshot {
|
|
3
|
+
/** The blocks so far. A block that did not change keeps its identity. */
|
|
4
|
+
blocks: Block[];
|
|
5
|
+
done: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface MarkdownStream {
|
|
8
|
+
push(chunk: string): MarkdownSnapshot;
|
|
9
|
+
end(): MarkdownSnapshot;
|
|
10
|
+
/** The text after the last committed block. Only this text is parsed again. */
|
|
11
|
+
readonly pending: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parses markdown while it streams.
|
|
15
|
+
*
|
|
16
|
+
* Only complete lines decide which blocks are final: a partial line can change how the lines
|
|
17
|
+
* before it parse (`#` is a heading, `#tag` is text). In the complete lines, each block before
|
|
18
|
+
* the last one is final, because later text can only change the last block. Each push parses
|
|
19
|
+
* again only the text after the final blocks.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createMarkdownStream(options?: MarkdownOptions): MarkdownStream;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** A part of a line of text. */
|
|
2
|
+
export type Inline = {
|
|
3
|
+
type: 'text';
|
|
4
|
+
text: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'strong' | 'emphasis' | 'delete';
|
|
7
|
+
children: Inline[];
|
|
8
|
+
} | {
|
|
9
|
+
type: 'code';
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'link';
|
|
13
|
+
href: string;
|
|
14
|
+
children: Inline[];
|
|
15
|
+
} | {
|
|
16
|
+
type: 'image';
|
|
17
|
+
src: string;
|
|
18
|
+
alt: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'break';
|
|
21
|
+
};
|
|
22
|
+
export type Align = 'start' | 'center' | 'end' | null;
|
|
23
|
+
/** A block of a document. The tree holds no HTML. */
|
|
24
|
+
export type Block = {
|
|
25
|
+
type: 'paragraph';
|
|
26
|
+
children: Inline[];
|
|
27
|
+
} | {
|
|
28
|
+
type: 'heading';
|
|
29
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
30
|
+
children: Inline[];
|
|
31
|
+
}
|
|
32
|
+
/** `open` is true while the closing fence did not arrive. */
|
|
33
|
+
| {
|
|
34
|
+
type: 'code';
|
|
35
|
+
lang?: string;
|
|
36
|
+
text: string;
|
|
37
|
+
open: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'list';
|
|
40
|
+
ordered: boolean;
|
|
41
|
+
start?: number;
|
|
42
|
+
tight: boolean;
|
|
43
|
+
items: Block[][];
|
|
44
|
+
} | {
|
|
45
|
+
type: 'blockquote';
|
|
46
|
+
children: Block[];
|
|
47
|
+
} | {
|
|
48
|
+
type: 'rule';
|
|
49
|
+
} | {
|
|
50
|
+
type: 'table';
|
|
51
|
+
align: Align[];
|
|
52
|
+
head: Inline[][];
|
|
53
|
+
rows: Inline[][][];
|
|
54
|
+
};
|
|
55
|
+
export interface MarkdownOptions {
|
|
56
|
+
/** Says if a link or an image can use a URL. Default: `isSafeUrl`. */
|
|
57
|
+
isSafeUrl?: (url: string) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Says if an image can use a URL. An image must pass `isSafeUrl` too. Default: `isRelativeUrl`,
|
|
60
|
+
* because the browser loads an image with no click.
|
|
61
|
+
*/
|
|
62
|
+
isSafeImageUrl?: (url: string) => boolean;
|
|
63
|
+
}
|
package/dist/url.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** True for an `http:`, `https:`, `mailto:` or `tel:` URL, and for a relative URL. */
|
|
2
|
+
export declare function isSafeUrl(url: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* True for a relative URL with no scheme and no host: a path, a query or a fragment. The default
|
|
5
|
+
* check for an image, because the browser loads an image with no click.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isRelativeUrl(url: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-marquetry/markdown",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A streamed markdown parser for Marquetry chat: markdown to a safe tree, with no HTML.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown",
|
|
7
|
+
"streaming",
|
|
8
|
+
"llm",
|
|
9
|
+
"generative-ui",
|
|
10
|
+
"ember"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Joe Gaudet joe@joegaudet.com",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/joegaudet/ember-marquetry.git",
|
|
17
|
+
"directory": "packages/markdown"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://joegaudet.com/ember-marquetry/",
|
|
20
|
+
"bugs": "https://github.com/joegaudet/ember-marquetry/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE.md",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22.12.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup"
|
|
46
|
+
}
|
|
6
47
|
}
|