markemental 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/index.cjs +1034 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +708 -0
- package/dist/index.d.ts +708 -0
- package/dist/index.js +1025 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/sources/line-source.ts
|
|
4
|
+
function createLineSource() {
|
|
5
|
+
let buffer = "";
|
|
6
|
+
let closed = false;
|
|
7
|
+
return {
|
|
8
|
+
push(chunk) {
|
|
9
|
+
if (closed) throw new Error("push after close");
|
|
10
|
+
buffer += chunk;
|
|
11
|
+
},
|
|
12
|
+
readLines() {
|
|
13
|
+
const lines = [];
|
|
14
|
+
let at = buffer.indexOf("\n");
|
|
15
|
+
while (at !== -1) {
|
|
16
|
+
lines.push(buffer.slice(0, at).replace(/\r$/, ""));
|
|
17
|
+
buffer = buffer.slice(at + 1);
|
|
18
|
+
at = buffer.indexOf("\n");
|
|
19
|
+
}
|
|
20
|
+
return lines;
|
|
21
|
+
},
|
|
22
|
+
close() {
|
|
23
|
+
closed = true;
|
|
24
|
+
if (buffer === "") return [];
|
|
25
|
+
const rest = buffer.replace(/\r$/, "");
|
|
26
|
+
buffer = "";
|
|
27
|
+
return [rest];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/core/pipelines/markdown-pipeline.ts
|
|
33
|
+
function createMarkdownPipeline(renderer) {
|
|
34
|
+
const source = createLineSource();
|
|
35
|
+
function feed(lines) {
|
|
36
|
+
for (const line of lines) renderer.writeLine(line);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
async push(chunk) {
|
|
40
|
+
source.push(await chunk);
|
|
41
|
+
feed(source.readLines());
|
|
42
|
+
},
|
|
43
|
+
async flush() {
|
|
44
|
+
feed(source.close());
|
|
45
|
+
await renderer.flush();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/renderers/parser/blocks.ts
|
|
51
|
+
var HEADING_RE = /^(#{1,6})(?:\s+(.*))?\s*$/;
|
|
52
|
+
var RULE_RE = /^(?:\*\s*){3,}$|^(?:-\s*){3,}$|^(?:_\s*){3,}$/;
|
|
53
|
+
var FENCE_RE = /^(`{3,}|~{3,})\s*([^`]*)$/;
|
|
54
|
+
var QUOTE_RE = /^>\s?(.*)$/;
|
|
55
|
+
var BULLET_RE = /^\s*[-*+]\s+(.*)$/;
|
|
56
|
+
var ORDERED_RE = /^\s*\d+[.)]\s+(.*)$/;
|
|
57
|
+
var TABLE_DELIM_CELL_RE = /^:?-{1,}:?$/;
|
|
58
|
+
var LEADING_WS_RE = /^\s*/;
|
|
59
|
+
function isBlankLine(line) {
|
|
60
|
+
return line.trim() === "";
|
|
61
|
+
}
|
|
62
|
+
function matchFence(line) {
|
|
63
|
+
const match = FENCE_RE.exec(line.trim());
|
|
64
|
+
if (!match || !match[1]) return null;
|
|
65
|
+
const run = match[1];
|
|
66
|
+
return {
|
|
67
|
+
marker: run[0],
|
|
68
|
+
length: run.length,
|
|
69
|
+
language: (match[2] ?? "").trim() || void 0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function fenceCloses(open, line) {
|
|
73
|
+
const match = matchFence(line);
|
|
74
|
+
return match !== null && match.marker === open.marker && match.length >= open.length;
|
|
75
|
+
}
|
|
76
|
+
function matchHeading(line) {
|
|
77
|
+
const match = HEADING_RE.exec(line);
|
|
78
|
+
if (!match || !match[1]) return null;
|
|
79
|
+
return {
|
|
80
|
+
level: Math.min(6, match[1].length),
|
|
81
|
+
text: (match[2] ?? "").replace(/\s+#+\s*$/, "").trim()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function isRuleLine(line) {
|
|
85
|
+
return RULE_RE.test(line.trim());
|
|
86
|
+
}
|
|
87
|
+
function matchQuote(line) {
|
|
88
|
+
const match = QUOTE_RE.exec(line);
|
|
89
|
+
if (!match) return null;
|
|
90
|
+
return { text: match[1] ?? "" };
|
|
91
|
+
}
|
|
92
|
+
function matchListItem(line) {
|
|
93
|
+
const bullet = BULLET_RE.exec(line);
|
|
94
|
+
const ordered = ORDERED_RE.exec(line);
|
|
95
|
+
if (!bullet && !ordered) return null;
|
|
96
|
+
return {
|
|
97
|
+
ordered: !bullet,
|
|
98
|
+
indent: LEADING_WS_RE.exec(line)?.[0].length ?? 0,
|
|
99
|
+
text: bullet?.[1] ?? ordered?.[1] ?? ""
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function isTableDelimiter(line) {
|
|
103
|
+
if (!line.includes("|") && !line.includes("-")) return false;
|
|
104
|
+
const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|");
|
|
105
|
+
return cells.length > 0 && cells.every((cell) => TABLE_DELIM_CELL_RE.test(cell.trim()));
|
|
106
|
+
}
|
|
107
|
+
function hasOpenFence(lines) {
|
|
108
|
+
let open = null;
|
|
109
|
+
for (const line of lines) {
|
|
110
|
+
if (open === null) {
|
|
111
|
+
open = matchFence(line);
|
|
112
|
+
} else if (fenceCloses(open, line)) {
|
|
113
|
+
open = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return open !== null;
|
|
117
|
+
}
|
|
118
|
+
function makeBlock(block, sourceLineCount) {
|
|
119
|
+
return { ...block, sourceLineCount };
|
|
120
|
+
}
|
|
121
|
+
function splitBlocks(lines) {
|
|
122
|
+
const blocks = [];
|
|
123
|
+
let i = 0;
|
|
124
|
+
while (i < lines.length) {
|
|
125
|
+
const line = lines[i];
|
|
126
|
+
if (isBlankLine(line)) {
|
|
127
|
+
i++;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const fence = matchFence(line);
|
|
131
|
+
if (fence) {
|
|
132
|
+
const content = [];
|
|
133
|
+
let j2 = i + 1;
|
|
134
|
+
while (j2 < lines.length && !fenceCloses(fence, lines[j2])) {
|
|
135
|
+
content.push(lines[j2]);
|
|
136
|
+
j2++;
|
|
137
|
+
}
|
|
138
|
+
const closed = j2 < lines.length;
|
|
139
|
+
blocks.push(makeBlock({ kind: "fence", lines: content, language: fence.language }, j2 - i + (closed ? 1 : 0)));
|
|
140
|
+
i = j2 + (closed ? 1 : 0);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const heading = matchHeading(line);
|
|
144
|
+
if (heading) {
|
|
145
|
+
blocks.push(makeBlock({ kind: "heading", lines: [heading.text], level: heading.level }, 1));
|
|
146
|
+
i++;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (isRuleLine(line)) {
|
|
150
|
+
blocks.push(makeBlock({ kind: "rule", lines: [] }, 1));
|
|
151
|
+
i++;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const quote = matchQuote(line);
|
|
155
|
+
if (quote) {
|
|
156
|
+
const quoted = [quote.text];
|
|
157
|
+
let j2 = i + 1;
|
|
158
|
+
while (j2 < lines.length) {
|
|
159
|
+
const next = matchQuote(lines[j2]);
|
|
160
|
+
if (!next) break;
|
|
161
|
+
quoted.push(next.text);
|
|
162
|
+
j2++;
|
|
163
|
+
}
|
|
164
|
+
blocks.push(makeBlock({ kind: "quote", lines: quoted }, j2 - i));
|
|
165
|
+
i = j2;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const paragraph = [line];
|
|
169
|
+
let j = i + 1;
|
|
170
|
+
while (j < lines.length) {
|
|
171
|
+
const next = lines[j];
|
|
172
|
+
if (isBlankLine(next) || matchFence(next) !== null || matchHeading(next) !== null || isRuleLine(next) || matchQuote(next) !== null) {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
paragraph.push(next);
|
|
176
|
+
j++;
|
|
177
|
+
}
|
|
178
|
+
blocks.push(makeBlock({ kind: "paragraph", lines: paragraph }, j - i));
|
|
179
|
+
i = j;
|
|
180
|
+
}
|
|
181
|
+
return blocks;
|
|
182
|
+
}
|
|
183
|
+
function splitTableRow(line) {
|
|
184
|
+
return line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim());
|
|
185
|
+
}
|
|
186
|
+
function parseTableAlignment(cell) {
|
|
187
|
+
const left = cell.startsWith(":");
|
|
188
|
+
const right = cell.endsWith(":");
|
|
189
|
+
if (left && right) return "center";
|
|
190
|
+
if (right) return "right";
|
|
191
|
+
if (left) return "left";
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/renderers/renderer-state.ts
|
|
196
|
+
var CommonMarkState = class {
|
|
197
|
+
/**
|
|
198
|
+
* @param emit - Receives parse fragments in document order.
|
|
199
|
+
*/
|
|
200
|
+
constructor(_emit) {
|
|
201
|
+
this._emit = _emit;
|
|
202
|
+
}
|
|
203
|
+
_emit;
|
|
204
|
+
_pending = [];
|
|
205
|
+
_fence = null;
|
|
206
|
+
_quote = null;
|
|
207
|
+
_lists = [];
|
|
208
|
+
/**
|
|
209
|
+
* Feed one source line; completed fragments emit to the handler.
|
|
210
|
+
*
|
|
211
|
+
* @param line - Next source line, without its line break.
|
|
212
|
+
*/
|
|
213
|
+
addLine(line) {
|
|
214
|
+
if (this._consumeFence(line)) return;
|
|
215
|
+
if (this._consumeLists(line)) return;
|
|
216
|
+
if (this._consumeQuote(line)) return;
|
|
217
|
+
this._classify(line);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Close every open context and emit the trailing remainder.
|
|
221
|
+
*/
|
|
222
|
+
flush() {
|
|
223
|
+
this._closeLists();
|
|
224
|
+
if (this._quote !== null) {
|
|
225
|
+
this._pending.push(...this._quote);
|
|
226
|
+
this._quote = null;
|
|
227
|
+
}
|
|
228
|
+
if (this._fence !== null) {
|
|
229
|
+
this._pending.push(this._fence.openLine, ...this._fence.content);
|
|
230
|
+
this._fence = null;
|
|
231
|
+
}
|
|
232
|
+
this._takeAll();
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Feed a line to the open fence, if any.
|
|
236
|
+
*
|
|
237
|
+
* @param line - Next source line.
|
|
238
|
+
* @returns True when the line was consumed.
|
|
239
|
+
*/
|
|
240
|
+
_consumeFence(line) {
|
|
241
|
+
if (this._fence === null) return false;
|
|
242
|
+
if (fenceCloses(this._fence, line)) {
|
|
243
|
+
this._pending.push(this._fence.openLine, ...this._fence.content, line);
|
|
244
|
+
this._fence = null;
|
|
245
|
+
this._takeComplete();
|
|
246
|
+
} else {
|
|
247
|
+
this._fence.content.push(line);
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Feed a line to the open lists, if any, closing and reprocessing when
|
|
253
|
+
* the line is not an item.
|
|
254
|
+
*
|
|
255
|
+
* @param line - Next source line.
|
|
256
|
+
* @returns True when the line was consumed or reprocessed.
|
|
257
|
+
*/
|
|
258
|
+
_consumeLists(line) {
|
|
259
|
+
if (this._lists.length === 0) return false;
|
|
260
|
+
const item = matchListItem(line);
|
|
261
|
+
if (item !== null) {
|
|
262
|
+
this._listItem(item);
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
this._closeLists();
|
|
266
|
+
this.addLine(line);
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Feed a line to the open quote, if any, dumping it back to pending when
|
|
271
|
+
* the line does not continue the quote.
|
|
272
|
+
*
|
|
273
|
+
* @param line - Next source line.
|
|
274
|
+
* @returns True when the line was consumed.
|
|
275
|
+
*/
|
|
276
|
+
_consumeQuote(line) {
|
|
277
|
+
if (this._quote === null) return false;
|
|
278
|
+
if (matchQuote(line) !== null) {
|
|
279
|
+
this._quote.push(line);
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
this._pending.push(...this._quote);
|
|
283
|
+
this._quote = null;
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Classify a line that continues no open context.
|
|
288
|
+
*
|
|
289
|
+
* @param line - Next source line.
|
|
290
|
+
*/
|
|
291
|
+
_classify(line) {
|
|
292
|
+
if (isBlankLine(line)) {
|
|
293
|
+
this._pending.push(line);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const fence = matchFence(line);
|
|
297
|
+
if (fence !== null) {
|
|
298
|
+
this._takeAll();
|
|
299
|
+
this._fence = { marker: fence.marker, length: fence.length, openLine: line, content: [] };
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (matchHeading(line) !== null || isRuleLine(line)) {
|
|
303
|
+
this._takeAll();
|
|
304
|
+
this._pending.push(line);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (matchQuote(line) !== null) {
|
|
308
|
+
this._takeAll();
|
|
309
|
+
this._quote = [line];
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const item = matchListItem(line);
|
|
313
|
+
if (item !== null) {
|
|
314
|
+
this._takeAll();
|
|
315
|
+
this._listItem(item);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (this._classifyPipe(line)) return;
|
|
319
|
+
this._pending.push(line);
|
|
320
|
+
this._takeComplete();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Classify a line that matches no CommonMark opener. The base parser has
|
|
324
|
+
* no pipe syntax, so this never consumes; {@link GFMState} overrides it
|
|
325
|
+
* to start table candidates.
|
|
326
|
+
*
|
|
327
|
+
* @param _line - Next source line.
|
|
328
|
+
* @returns Always false here.
|
|
329
|
+
*/
|
|
330
|
+
_classifyPipe(_line) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
_listItem(item) {
|
|
334
|
+
while (this._lists.length > 0 && item.indent < this._lists[this._lists.length - 1].indent) {
|
|
335
|
+
this._lists.pop();
|
|
336
|
+
this._emit({ kind: "listEnd" });
|
|
337
|
+
}
|
|
338
|
+
const top = this._lists[this._lists.length - 1];
|
|
339
|
+
if (top && top.indent === item.indent && top.ordered === item.ordered) {
|
|
340
|
+
this._emit({ kind: "listItem", text: item.text });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (top && top.indent === item.indent) {
|
|
344
|
+
this._lists.pop();
|
|
345
|
+
this._emit({ kind: "listEnd" });
|
|
346
|
+
}
|
|
347
|
+
this._emit({ kind: "listStart", ordered: item.ordered });
|
|
348
|
+
this._lists.push({ ordered: item.ordered, indent: item.indent });
|
|
349
|
+
this._emit({ kind: "listItem", text: item.text });
|
|
350
|
+
}
|
|
351
|
+
_closeLists() {
|
|
352
|
+
while (this._lists.length > 0) {
|
|
353
|
+
this._lists.pop();
|
|
354
|
+
this._emit({ kind: "listEnd" });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
_takeComplete() {
|
|
358
|
+
let start = 0;
|
|
359
|
+
let end = this._pending.length;
|
|
360
|
+
while (start < end && isBlankLine(this._pending[start])) start++;
|
|
361
|
+
while (end > start && isBlankLine(this._pending[end - 1])) end--;
|
|
362
|
+
const trimmed = this._pending.slice(start, end);
|
|
363
|
+
if (trimmed.length === 0) {
|
|
364
|
+
this._pending = [];
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (hasOpenFence(trimmed)) return;
|
|
368
|
+
const blocks = splitBlocks(trimmed);
|
|
369
|
+
const last = blocks[blocks.length - 1];
|
|
370
|
+
if (last === void 0) {
|
|
371
|
+
this._pending = [];
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
this._pending = trimmed.slice(trimmed.length - last.sourceLineCount);
|
|
375
|
+
for (const block of blocks.slice(0, -1)) this._emit({ kind: "block", block });
|
|
376
|
+
}
|
|
377
|
+
_takeAll() {
|
|
378
|
+
const blocks = splitBlocks(this._pending);
|
|
379
|
+
this._pending = [];
|
|
380
|
+
for (const block of blocks) this._emit({ kind: "block", block });
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
var GFMState = class extends CommonMarkState {
|
|
384
|
+
_tableOpen = false;
|
|
385
|
+
_candidate = null;
|
|
386
|
+
/**
|
|
387
|
+
* Feed one source line; completed fragments emit to the handler.
|
|
388
|
+
*
|
|
389
|
+
* @param line - Next source line, without its line break.
|
|
390
|
+
*/
|
|
391
|
+
addLine(line) {
|
|
392
|
+
if (this._consumeFence(line)) return;
|
|
393
|
+
if (this._consumeTable(line)) return;
|
|
394
|
+
if (this._consumeLists(line)) return;
|
|
395
|
+
if (this._consumeQuote(line)) return;
|
|
396
|
+
if (this._consumeCandidate(line)) return;
|
|
397
|
+
this._classify(line);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Close every open context and emit the trailing remainder.
|
|
401
|
+
*/
|
|
402
|
+
flush() {
|
|
403
|
+
if (this._candidate !== null) {
|
|
404
|
+
this._pending.push(this._candidate);
|
|
405
|
+
this._candidate = null;
|
|
406
|
+
}
|
|
407
|
+
if (this._tableOpen) {
|
|
408
|
+
this._emit({ kind: "tableEnd" });
|
|
409
|
+
this._tableOpen = false;
|
|
410
|
+
}
|
|
411
|
+
super.flush();
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Feed a line to the open table, if any, closing and reprocessing when
|
|
415
|
+
* the line is not a row.
|
|
416
|
+
*
|
|
417
|
+
* @param line - Next source line.
|
|
418
|
+
* @returns True when the line was consumed or reprocessed.
|
|
419
|
+
*/
|
|
420
|
+
_consumeTable(line) {
|
|
421
|
+
if (!this._tableOpen) return false;
|
|
422
|
+
if (!isBlankLine(line) && line.includes("|")) {
|
|
423
|
+
this._emit({ kind: "tableRow", line });
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
this._emit({ kind: "tableEnd" });
|
|
427
|
+
this._tableOpen = false;
|
|
428
|
+
this.addLine(line);
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Resolve a pending table header candidate against the next line.
|
|
433
|
+
*
|
|
434
|
+
* @param line - Next source line.
|
|
435
|
+
* @returns True when a table opened.
|
|
436
|
+
*/
|
|
437
|
+
_consumeCandidate(line) {
|
|
438
|
+
if (this._candidate === null) return false;
|
|
439
|
+
if (isTableDelimiter(line)) {
|
|
440
|
+
this._emit({ kind: "tableHead", headLine: this._candidate, delimLine: line });
|
|
441
|
+
this._candidate = null;
|
|
442
|
+
this._tableOpen = true;
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
this._pending.push(this._candidate);
|
|
446
|
+
this._candidate = null;
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Start a table header candidate on pipe lines.
|
|
451
|
+
*
|
|
452
|
+
* @param line - Next source line.
|
|
453
|
+
* @returns True when the line starts a candidate.
|
|
454
|
+
*/
|
|
455
|
+
_classifyPipe(line) {
|
|
456
|
+
if (!line.includes("|")) return false;
|
|
457
|
+
this._takeAll();
|
|
458
|
+
this._candidate = line;
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/renderers/parser/inline.ts
|
|
464
|
+
var ESCAPABLE_RE = /^[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]$/;
|
|
465
|
+
var AUTOLINK_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:[^<>\s]*$/;
|
|
466
|
+
var ALNUM_RE = /[A-Za-z0-9]/;
|
|
467
|
+
function tryParseLink(text, start) {
|
|
468
|
+
const labelEnd = text.indexOf("]", start + 1);
|
|
469
|
+
if (labelEnd === -1 || text[labelEnd + 1] !== "(") return null;
|
|
470
|
+
const label = text.slice(start + 1, labelEnd);
|
|
471
|
+
if (label.includes("[") || label.includes("\n")) return null;
|
|
472
|
+
const hrefEnd = text.indexOf(")", labelEnd + 2);
|
|
473
|
+
if (hrefEnd === -1) return null;
|
|
474
|
+
const inside = text.slice(labelEnd + 2, hrefEnd).trim();
|
|
475
|
+
if (inside === "") return null;
|
|
476
|
+
if (/\s/.test(inside) && !/^<?\S+>?\s+"[^"]*"$/.test(inside)) return null;
|
|
477
|
+
const href = inside.replace(/^<(.*)>$/, "$1").split(/\s+/)[0];
|
|
478
|
+
return { label, href, end: hrefEnd + 1 };
|
|
479
|
+
}
|
|
480
|
+
function matchEmphasis(text, i, gfm) {
|
|
481
|
+
if (gfm && text.startsWith("~~", i)) return { marker: "~~", tag: "del", underscore: false };
|
|
482
|
+
if (text.startsWith("**", i)) return { marker: "**", tag: "strong", underscore: false };
|
|
483
|
+
if (text.startsWith("__", i)) return { marker: "__", tag: "strong", underscore: true };
|
|
484
|
+
if (text[i] === "*") return { marker: "*", tag: "em", underscore: false };
|
|
485
|
+
if (text[i] === "_") {
|
|
486
|
+
if (i > 0 && ALNUM_RE.test(text[i - 1])) return null;
|
|
487
|
+
return { marker: "_", tag: "em", underscore: true };
|
|
488
|
+
}
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
function findEmphasisClose(text, from, token) {
|
|
492
|
+
let at = text.indexOf(token.marker, from);
|
|
493
|
+
while (at !== -1 && token.underscore) {
|
|
494
|
+
const next = text[at + token.marker.length];
|
|
495
|
+
if (next === void 0 || !ALNUM_RE.test(next)) return at;
|
|
496
|
+
at = text.indexOf(token.marker, at + 1);
|
|
497
|
+
}
|
|
498
|
+
return at;
|
|
499
|
+
}
|
|
500
|
+
function appendInline(parent, text, doc, gfm) {
|
|
501
|
+
let i = 0;
|
|
502
|
+
let literal = "";
|
|
503
|
+
const flushLiteral = () => {
|
|
504
|
+
if (literal !== "") {
|
|
505
|
+
parent.appendChild(doc.createTextNode(literal));
|
|
506
|
+
literal = "";
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
while (i < text.length) {
|
|
510
|
+
const ch = text[i];
|
|
511
|
+
if (ch === "\\" && i + 1 < text.length && ESCAPABLE_RE.test(text[i + 1])) {
|
|
512
|
+
literal += text[i + 1];
|
|
513
|
+
i += 2;
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (ch === "`") {
|
|
517
|
+
const run = /^`+/.exec(text.slice(i));
|
|
518
|
+
const close = text.indexOf(run[0], i + run[0].length);
|
|
519
|
+
if (close !== -1) {
|
|
520
|
+
flushLiteral();
|
|
521
|
+
const code = doc.createElement("code");
|
|
522
|
+
code.appendChild(doc.createTextNode(text.slice(i + run[0].length, close)));
|
|
523
|
+
parent.appendChild(code);
|
|
524
|
+
i = close + run[0].length;
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
literal += ch;
|
|
528
|
+
i++;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (ch === "!" && text[i + 1] === "[") {
|
|
532
|
+
const link = tryParseLink(text, i + 1);
|
|
533
|
+
if (link && link.href !== "") {
|
|
534
|
+
flushLiteral();
|
|
535
|
+
const img = doc.createElement("img");
|
|
536
|
+
img.setAttribute?.("src", link.href);
|
|
537
|
+
img.setAttribute?.("alt", link.label);
|
|
538
|
+
parent.appendChild(img);
|
|
539
|
+
i = link.end;
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (ch === "[") {
|
|
544
|
+
const link = tryParseLink(text, i);
|
|
545
|
+
if (link) {
|
|
546
|
+
flushLiteral();
|
|
547
|
+
const anchor = doc.createElement("a");
|
|
548
|
+
anchor.setAttribute?.("href", link.href);
|
|
549
|
+
appendInline(anchor, link.label, doc, gfm);
|
|
550
|
+
parent.appendChild(anchor);
|
|
551
|
+
i = link.end;
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
literal += ch;
|
|
555
|
+
i++;
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
if (ch === "<") {
|
|
559
|
+
const end = text.indexOf(">", i + 1);
|
|
560
|
+
if (end !== -1 && AUTOLINK_RE.test(text.slice(i + 1, end))) {
|
|
561
|
+
flushLiteral();
|
|
562
|
+
const href = text.slice(i + 1, end);
|
|
563
|
+
const anchor = doc.createElement("a");
|
|
564
|
+
anchor.setAttribute?.("href", href);
|
|
565
|
+
anchor.appendChild(doc.createTextNode(href));
|
|
566
|
+
parent.appendChild(anchor);
|
|
567
|
+
i = end + 1;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
literal += ch;
|
|
571
|
+
i++;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const token = matchEmphasis(text, i, gfm);
|
|
575
|
+
if (token) {
|
|
576
|
+
const close = findEmphasisClose(text, i + token.marker.length, token);
|
|
577
|
+
if (close !== -1 && close > i + token.marker.length) {
|
|
578
|
+
flushLiteral();
|
|
579
|
+
const el = doc.createElement(token.tag);
|
|
580
|
+
appendInline(el, text.slice(i + token.marker.length, close), doc, gfm);
|
|
581
|
+
parent.appendChild(el);
|
|
582
|
+
i = close + token.marker.length;
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
literal += token.marker;
|
|
586
|
+
i += token.marker.length;
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
literal += ch;
|
|
590
|
+
i++;
|
|
591
|
+
}
|
|
592
|
+
flushLiteral();
|
|
593
|
+
}
|
|
594
|
+
function splitHardBreak(line) {
|
|
595
|
+
const hardBreak = / {2,}$/.test(line);
|
|
596
|
+
return { text: hardBreak ? line.replace(/ {2,}$/, "") : line, hardBreak };
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// src/renderers/commonmark.ts
|
|
600
|
+
var CommonMarkRenderer = class {
|
|
601
|
+
/** Rendering options. */
|
|
602
|
+
options;
|
|
603
|
+
_target;
|
|
604
|
+
_doc;
|
|
605
|
+
_state;
|
|
606
|
+
_open = [];
|
|
607
|
+
/**
|
|
608
|
+
* @param target - Destination for rendered output, from
|
|
609
|
+
* `createRenderTarget`. Pass `requestAnimationFrame` there to batch
|
|
610
|
+
* writes on animation frames, or nothing for synchronous writes.
|
|
611
|
+
* @param doc - Document used to create nodes.
|
|
612
|
+
* @param opts - CommonMark rendering options.
|
|
613
|
+
*/
|
|
614
|
+
constructor(target, doc, opts) {
|
|
615
|
+
this._target = target;
|
|
616
|
+
this._doc = doc;
|
|
617
|
+
this.options = opts;
|
|
618
|
+
this._state = this._createState((fragment) => this._applyFragment(fragment));
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Create the parser state. Overridden by `GFMRenderer` to parse
|
|
622
|
+
* tables.
|
|
623
|
+
*
|
|
624
|
+
* @param emit - Receives parse fragments in document order.
|
|
625
|
+
* @returns The state for this renderer.
|
|
626
|
+
*/
|
|
627
|
+
_createState(emit) {
|
|
628
|
+
return new CommonMarkState(emit);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Feed one source line; completed output is written to the target.
|
|
632
|
+
*
|
|
633
|
+
* @param line - Next source line, without its line break.
|
|
634
|
+
*/
|
|
635
|
+
writeLine(line) {
|
|
636
|
+
this._state.addLine(line);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Render the buffered remainder and settle the target.
|
|
640
|
+
*
|
|
641
|
+
* @returns A promise that resolves once all output has landed in the target.
|
|
642
|
+
*/
|
|
643
|
+
async flush() {
|
|
644
|
+
this._state.flush();
|
|
645
|
+
await this._target.flush();
|
|
646
|
+
}
|
|
647
|
+
_applyFragment(fragment) {
|
|
648
|
+
switch (fragment.kind) {
|
|
649
|
+
case "block": {
|
|
650
|
+
const node = this.renderBlock(fragment.block, this._doc);
|
|
651
|
+
if (node !== null) this._commit(node, null);
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
case "listStart": {
|
|
655
|
+
const top = this._open[this._open.length - 1];
|
|
656
|
+
const list = this._doc.createElement(fragment.ordered ? "ol" : "ul");
|
|
657
|
+
this._commit(list, top?.currentItem ?? null);
|
|
658
|
+
this._open.push({ node: list, currentItem: null });
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
case "listItem": {
|
|
662
|
+
const top = this._open[this._open.length - 1];
|
|
663
|
+
const item = this._doc.createElement("li");
|
|
664
|
+
appendInline(item, fragment.text, this._doc, this.inlineGfm());
|
|
665
|
+
this._commit(item, top.node);
|
|
666
|
+
top.currentItem = item;
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
case "listEnd":
|
|
670
|
+
this._open.pop();
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Append a node to the target (top level) or to its parent container,
|
|
676
|
+
* running the sanitizer first when one is set.
|
|
677
|
+
*
|
|
678
|
+
* @param node - Node to commit.
|
|
679
|
+
* @param parent - Parent container, or null to commit to the target.
|
|
680
|
+
*/
|
|
681
|
+
_commit(node, parent) {
|
|
682
|
+
const sanitizer = this.options.sanitizer;
|
|
683
|
+
const out = sanitizer === void 0 ? node : sanitizer(node);
|
|
684
|
+
if (parent === null) this._target.append(out);
|
|
685
|
+
else parent.appendChild(out);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Whether GFM-only inlines are enabled. Always false here; overridden by
|
|
689
|
+
* `GFMRenderer`.
|
|
690
|
+
*
|
|
691
|
+
* @returns False.
|
|
692
|
+
*/
|
|
693
|
+
inlineGfm() {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Render one block to a DOM-like node.
|
|
698
|
+
*
|
|
699
|
+
* @param block - Parsed block to render.
|
|
700
|
+
* @param doc - Document used to create nodes.
|
|
701
|
+
* @returns The rendered node, or `null` to emit nothing.
|
|
702
|
+
*/
|
|
703
|
+
renderBlock(block, doc) {
|
|
704
|
+
switch (block.kind) {
|
|
705
|
+
case "heading": {
|
|
706
|
+
const heading = doc.createElement(`h${block.level ?? 1}`);
|
|
707
|
+
this.appendLinesInline(heading, block.lines, doc, " ");
|
|
708
|
+
return heading;
|
|
709
|
+
}
|
|
710
|
+
case "paragraph":
|
|
711
|
+
return this.renderParagraph(block.lines, doc);
|
|
712
|
+
case "fence": {
|
|
713
|
+
const pre = doc.createElement("pre");
|
|
714
|
+
const code = doc.createElement("code");
|
|
715
|
+
if (block.language !== void 0) code.setAttribute?.("class", `language-${block.language}`);
|
|
716
|
+
const text = block.lines.join("\n");
|
|
717
|
+
code.appendChild(doc.createTextNode(text === "" ? "" : `${text}
|
|
718
|
+
`));
|
|
719
|
+
pre.appendChild(code);
|
|
720
|
+
return pre;
|
|
721
|
+
}
|
|
722
|
+
case "quote": {
|
|
723
|
+
const quote = doc.createElement("blockquote");
|
|
724
|
+
const body = doc.createElement("p");
|
|
725
|
+
this.appendLinesInline(body, block.lines, doc, " ");
|
|
726
|
+
quote.appendChild(body);
|
|
727
|
+
return quote;
|
|
728
|
+
}
|
|
729
|
+
case "rule":
|
|
730
|
+
return doc.createElement("hr");
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Render paragraph lines, honoring two-space hard breaks.
|
|
735
|
+
*
|
|
736
|
+
* @param lines - Raw paragraph lines.
|
|
737
|
+
* @param doc - Document used to create nodes.
|
|
738
|
+
* @returns The paragraph element.
|
|
739
|
+
*/
|
|
740
|
+
renderParagraph(lines, doc) {
|
|
741
|
+
const paragraph = doc.createElement("p");
|
|
742
|
+
lines.forEach((line, at) => {
|
|
743
|
+
const { text, hardBreak } = splitHardBreak(line);
|
|
744
|
+
appendInline(paragraph, text, doc, this.inlineGfm());
|
|
745
|
+
if (at < lines.length - 1) {
|
|
746
|
+
if (hardBreak) paragraph.appendChild(doc.createElement("br"));
|
|
747
|
+
else paragraph.appendChild(doc.createTextNode(" "));
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
return paragraph;
|
|
751
|
+
}
|
|
752
|
+
appendLinesInline(parent, lines, doc, join) {
|
|
753
|
+
lines.forEach((line, at) => {
|
|
754
|
+
if (at > 0) parent.appendChild(doc.createTextNode(join));
|
|
755
|
+
appendInline(parent, line, doc, this.inlineGfm());
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// src/renderers/gfm.ts
|
|
761
|
+
var GFMRenderer = class extends CommonMarkRenderer {
|
|
762
|
+
/** Rendering options. */
|
|
763
|
+
options;
|
|
764
|
+
_table = null;
|
|
765
|
+
/**
|
|
766
|
+
* @param target - Destination for rendered output, from
|
|
767
|
+
* `createRenderTarget`. Pass `requestAnimationFrame` there to batch
|
|
768
|
+
* writes on animation frames, or nothing for synchronous writes.
|
|
769
|
+
* @param doc - Document used to create nodes.
|
|
770
|
+
* @param opts - GFM rendering options.
|
|
771
|
+
*/
|
|
772
|
+
constructor(target, doc, opts) {
|
|
773
|
+
super(target, doc, opts);
|
|
774
|
+
this.options = opts;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* GFM-only inlines are enabled.
|
|
778
|
+
*
|
|
779
|
+
* @returns True.
|
|
780
|
+
*/
|
|
781
|
+
inlineGfm() {
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Create the GFM parser state.
|
|
786
|
+
*
|
|
787
|
+
* @param emit - Receives parse fragments in document order.
|
|
788
|
+
* @returns The state for this renderer.
|
|
789
|
+
*/
|
|
790
|
+
_createState(emit) {
|
|
791
|
+
return new GFMState(emit);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Apply a fragment, handling tables here and delegating the rest.
|
|
795
|
+
*
|
|
796
|
+
* @param fragment - Fragment to apply.
|
|
797
|
+
*/
|
|
798
|
+
_applyFragment(fragment) {
|
|
799
|
+
switch (fragment.kind) {
|
|
800
|
+
case "tableHead":
|
|
801
|
+
this._applyTableHead(fragment.headLine, fragment.delimLine);
|
|
802
|
+
break;
|
|
803
|
+
case "tableRow":
|
|
804
|
+
this._applyTableRow(fragment.line);
|
|
805
|
+
break;
|
|
806
|
+
case "tableEnd":
|
|
807
|
+
this._applyTableEnd();
|
|
808
|
+
break;
|
|
809
|
+
default:
|
|
810
|
+
super._applyFragment(fragment);
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Commit the table with its header; body rows stream in afterwards.
|
|
816
|
+
*
|
|
817
|
+
* @param headLine - Raw header row line.
|
|
818
|
+
* @param delimLine - Delimiter row line carrying column alignment.
|
|
819
|
+
*/
|
|
820
|
+
_applyTableHead(headLine, delimLine) {
|
|
821
|
+
const header = splitTableRow(headLine);
|
|
822
|
+
const aligns = splitTableRow(delimLine).map(parseTableAlignment);
|
|
823
|
+
const width = header.length;
|
|
824
|
+
const table = this._doc.createElement("table");
|
|
825
|
+
const head = this._doc.createElement("thead");
|
|
826
|
+
const headRow = this._doc.createElement("tr");
|
|
827
|
+
for (let col = 0; col < width; col++) {
|
|
828
|
+
const cell = this._doc.createElement("th");
|
|
829
|
+
const align = aligns[col] ?? null;
|
|
830
|
+
if (align !== null) cell.setAttribute?.("align", align);
|
|
831
|
+
appendInline(cell, header[col] ?? "", this._doc, true);
|
|
832
|
+
headRow.appendChild(cell);
|
|
833
|
+
}
|
|
834
|
+
head.appendChild(headRow);
|
|
835
|
+
table.appendChild(head);
|
|
836
|
+
const body = this._doc.createElement("tbody");
|
|
837
|
+
table.appendChild(body);
|
|
838
|
+
this._commit(table, null);
|
|
839
|
+
this._table = { body, aligns, width };
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Append one body row to the open table.
|
|
843
|
+
*
|
|
844
|
+
* @param line - Raw body row line.
|
|
845
|
+
*/
|
|
846
|
+
_applyTableRow(line) {
|
|
847
|
+
const table = this._table;
|
|
848
|
+
if (table === null) return;
|
|
849
|
+
const cells = splitTableRow(line);
|
|
850
|
+
const row = this._doc.createElement("tr");
|
|
851
|
+
for (let col = 0; col < table.width; col++) {
|
|
852
|
+
const cell = this._doc.createElement("td");
|
|
853
|
+
const align = table.aligns[col] ?? null;
|
|
854
|
+
if (align !== null) cell.setAttribute?.("align", align);
|
|
855
|
+
appendInline(cell, cells[col] ?? "", this._doc, true);
|
|
856
|
+
row.appendChild(cell);
|
|
857
|
+
}
|
|
858
|
+
for (let col = table.width; col < cells.length; col++) {
|
|
859
|
+
const cell = this._doc.createElement("td");
|
|
860
|
+
appendInline(cell, cells[col], this._doc, true);
|
|
861
|
+
row.appendChild(cell);
|
|
862
|
+
}
|
|
863
|
+
this._commit(row, table.body);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Close the open table.
|
|
867
|
+
*/
|
|
868
|
+
_applyTableEnd() {
|
|
869
|
+
this._table = null;
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// src/targets/animated-dom-target.ts
|
|
874
|
+
var AnimatedDOMTarget = class {
|
|
875
|
+
_targetNode;
|
|
876
|
+
_raf;
|
|
877
|
+
_queue = [];
|
|
878
|
+
_scheduled = false;
|
|
879
|
+
_flushResolvers = [];
|
|
880
|
+
/**
|
|
881
|
+
* @param targetNode - Container node receiving rendered output.
|
|
882
|
+
* @param raf - Frame scheduler used to batch writes.
|
|
883
|
+
*/
|
|
884
|
+
constructor(targetNode, raf) {
|
|
885
|
+
this._targetNode = targetNode;
|
|
886
|
+
this._raf = raf;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Queue a rendered node for the next frame.
|
|
890
|
+
*
|
|
891
|
+
* @param node - Node to attach.
|
|
892
|
+
*/
|
|
893
|
+
append(node) {
|
|
894
|
+
this._queue.push(node);
|
|
895
|
+
if (!this._scheduled) {
|
|
896
|
+
this._scheduled = true;
|
|
897
|
+
this._raf(() => {
|
|
898
|
+
this._scheduled = false;
|
|
899
|
+
const batch = this._queue;
|
|
900
|
+
this._queue = [];
|
|
901
|
+
for (const queued of batch) this._targetNode.appendChild(queued);
|
|
902
|
+
const resolvers = this._flushResolvers;
|
|
903
|
+
this._flushResolvers = [];
|
|
904
|
+
for (const resolve of resolvers) resolve();
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Wait until every queued node has been attached.
|
|
910
|
+
*
|
|
911
|
+
* @returns A promise that resolves after the next frame carrying nodes.
|
|
912
|
+
*/
|
|
913
|
+
flush() {
|
|
914
|
+
if (!this._scheduled && this._queue.length === 0) return Promise.resolve();
|
|
915
|
+
return new Promise((resolve) => {
|
|
916
|
+
this._flushResolvers.push(resolve);
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// src/targets/dom-target.ts
|
|
922
|
+
var DOMTarget = class {
|
|
923
|
+
_targetNode;
|
|
924
|
+
/**
|
|
925
|
+
* @param targetNode - Container node receiving rendered output.
|
|
926
|
+
*/
|
|
927
|
+
constructor(targetNode) {
|
|
928
|
+
this._targetNode = targetNode;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Append a rendered node immediately.
|
|
932
|
+
*
|
|
933
|
+
* @param node - Node to attach.
|
|
934
|
+
*/
|
|
935
|
+
append(node) {
|
|
936
|
+
this._targetNode.appendChild(node);
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Resolve immediately: synchronous targets hold every node already.
|
|
940
|
+
*
|
|
941
|
+
* @returns A resolved promise.
|
|
942
|
+
*/
|
|
943
|
+
flush() {
|
|
944
|
+
return Promise.resolve();
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
// src/targets/render-target.ts
|
|
949
|
+
function createRenderTarget(targetNode, raf) {
|
|
950
|
+
return raf === void 0 ? new DOMTarget(targetNode) : new AnimatedDOMTarget(targetNode, raf);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// src/core/pipelines/gfm-pipeline.ts
|
|
954
|
+
function createGFMPipeline(target, dom, opts, raf) {
|
|
955
|
+
return new GFMPipeline(target, dom, opts, raf);
|
|
956
|
+
}
|
|
957
|
+
var GFMPipeline = class {
|
|
958
|
+
_engine;
|
|
959
|
+
/**
|
|
960
|
+
* @param target - Container node receiving rendered output.
|
|
961
|
+
* @param dom - Document used to create nodes.
|
|
962
|
+
* @param opts - GFM rendering options.
|
|
963
|
+
* @param raf - Optional frame scheduler for batched DOM writes.
|
|
964
|
+
*/
|
|
965
|
+
constructor(target, dom, opts, raf) {
|
|
966
|
+
this._engine = createMarkdownPipeline(
|
|
967
|
+
new GFMRenderer(createRenderTarget(target, raf), dom, opts)
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Push a chunk of markdown into the pipeline.
|
|
972
|
+
*
|
|
973
|
+
* @param chunk - Markdown text, or a promise resolving to markdown text.
|
|
974
|
+
* @returns A promise that resolves once the chunk has been consumed.
|
|
975
|
+
*/
|
|
976
|
+
push(chunk) {
|
|
977
|
+
return this._engine.push(chunk);
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Render any buffered remainder.
|
|
981
|
+
*
|
|
982
|
+
* @returns A promise that resolves once all output has been flushed.
|
|
983
|
+
*/
|
|
984
|
+
flush() {
|
|
985
|
+
return this._engine.flush();
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
// src/core/pipelines/commonmark-pipeline.ts
|
|
990
|
+
function createCommonMarkPipeline(target, dom, opts, raf) {
|
|
991
|
+
return new CommonMarkPipeline(target, dom, opts, raf);
|
|
992
|
+
}
|
|
993
|
+
var CommonMarkPipeline = class {
|
|
994
|
+
_engine;
|
|
995
|
+
/**
|
|
996
|
+
* @param target - Container node receiving rendered output.
|
|
997
|
+
* @param dom - Document used to create nodes.
|
|
998
|
+
* @param opts - CommonMark rendering options.
|
|
999
|
+
* @param raf - Optional frame scheduler for batched DOM writes.
|
|
1000
|
+
*/
|
|
1001
|
+
constructor(target, dom, opts, raf) {
|
|
1002
|
+
this._engine = createMarkdownPipeline(
|
|
1003
|
+
new CommonMarkRenderer(createRenderTarget(target, raf), dom, opts)
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Push a chunk of markdown into the pipeline.
|
|
1008
|
+
*
|
|
1009
|
+
* @param chunk - Markdown text, or a promise resolving to markdown text.
|
|
1010
|
+
* @returns A promise that resolves once the chunk has been consumed.
|
|
1011
|
+
*/
|
|
1012
|
+
push(chunk) {
|
|
1013
|
+
return this._engine.push(chunk);
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Render any buffered remainder.
|
|
1017
|
+
*
|
|
1018
|
+
* @returns A promise that resolves once all output has been flushed.
|
|
1019
|
+
*/
|
|
1020
|
+
flush() {
|
|
1021
|
+
return this._engine.flush();
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
exports.CommonMarkPipeline = CommonMarkPipeline;
|
|
1026
|
+
exports.CommonMarkRenderer = CommonMarkRenderer;
|
|
1027
|
+
exports.GFMPipeline = GFMPipeline;
|
|
1028
|
+
exports.GFMRenderer = GFMRenderer;
|
|
1029
|
+
exports.createCommonMarkPipeline = createCommonMarkPipeline;
|
|
1030
|
+
exports.createGFMPipeline = createGFMPipeline;
|
|
1031
|
+
exports.createMarkdownPipeline = createMarkdownPipeline;
|
|
1032
|
+
exports.createRenderTarget = createRenderTarget;
|
|
1033
|
+
//# sourceMappingURL=index.cjs.map
|
|
1034
|
+
//# sourceMappingURL=index.cjs.map
|