@harbour-enterprises/superdoc 0.28.0-next.1 → 0.28.0-next.11

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.
Files changed (99) hide show
  1. package/dist/chunks/{PdfViewer-9z5hlRyt.es.js → PdfViewer-CLpN99Rl.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-Jb55JUCS.cjs → PdfViewer-CvsrAT4c.cjs} +1 -1
  3. package/dist/chunks/default-BS6z0SoE-BS6z0SoE.es.js +5 -0
  4. package/dist/chunks/default-BS6z0SoE-Gl4f7Y7J.cjs +4 -0
  5. package/dist/chunks/index-CHAKf7mX-C5aFF6Zl.es.js +2213 -0
  6. package/dist/chunks/index-CHAKf7mX-Dx-DOGGJ.cjs +2213 -0
  7. package/dist/chunks/{index-DqP-8_tO.es.js → index-CNPV5EVY.es.js} +2 -2
  8. package/dist/chunks/index-CSaZZzfe-BzemjgYL.cjs +264 -0
  9. package/dist/chunks/index-CSaZZzfe-CSaZZzfe.es.js +265 -0
  10. package/dist/chunks/index-C_x_N6Uh-DJn8hIEt.es.js +2200 -0
  11. package/dist/chunks/index-C_x_N6Uh-Db3CUJMX.cjs +2200 -0
  12. package/dist/chunks/index-Cd3D_8gF-CFhMnajQ.es.js +862 -0
  13. package/dist/chunks/index-Cd3D_8gF-DKJ_wTu_.cjs +861 -0
  14. package/dist/chunks/index-CvBqQJbG-CvBqQJbG.es.js +878 -0
  15. package/dist/chunks/index-CvBqQJbG-Dwm0THD7.cjs +877 -0
  16. package/dist/chunks/index-DL9bff78-8izww2lB.es.js +845 -0
  17. package/dist/chunks/index-DL9bff78-Cf4UBVvQ.cjs +845 -0
  18. package/dist/chunks/index-DRCvimau-Cw339678.es.js +9876 -0
  19. package/dist/chunks/index-DRCvimau-H4Ck3S9a.cjs +9876 -0
  20. package/dist/chunks/index-D_sWOSiG-BtDZzJ6I.cjs +588 -0
  21. package/dist/chunks/index-D_sWOSiG-DE96TaT5.es.js +588 -0
  22. package/dist/chunks/{index-D0UvyM8m.cjs → index-sLveeSfi.cjs} +2 -2
  23. package/dist/chunks/{super-editor.es-BBJIKdhr.es.js → super-editor.es-0SXIzzbj.es.js} +1846 -1655
  24. package/dist/chunks/{super-editor.es-Ca5D3ZTW.cjs → super-editor.es-Dy32MdYk.cjs} +1845 -1654
  25. package/dist/core/types/index.d.ts +2 -1
  26. package/dist/core/types/index.d.ts.map +1 -1
  27. package/dist/images/altText_add.svg +3 -0
  28. package/dist/images/altText_disclaimer.svg +3 -0
  29. package/dist/images/altText_done.svg +3 -0
  30. package/dist/images/altText_spinner.svg +30 -0
  31. package/dist/images/altText_warning.svg +3 -0
  32. package/dist/images/annotation-check.svg +11 -0
  33. package/dist/images/annotation-comment.svg +16 -0
  34. package/dist/images/annotation-help.svg +26 -0
  35. package/dist/images/annotation-insert.svg +10 -0
  36. package/dist/images/annotation-key.svg +11 -0
  37. package/dist/images/annotation-newparagraph.svg +11 -0
  38. package/dist/images/annotation-noicon.svg +7 -0
  39. package/dist/images/annotation-note.svg +42 -0
  40. package/dist/images/annotation-paperclip.svg +6 -0
  41. package/dist/images/annotation-paragraph.svg +16 -0
  42. package/dist/images/annotation-pushpin.svg +7 -0
  43. package/dist/images/cursor-editorFreeHighlight.svg +6 -0
  44. package/dist/images/cursor-editorFreeText.svg +3 -0
  45. package/dist/images/cursor-editorInk.svg +4 -0
  46. package/dist/images/cursor-editorTextHighlight.svg +8 -0
  47. package/dist/images/editor-toolbar-delete.svg +5 -0
  48. package/dist/images/loading-icon.gif +0 -0
  49. package/dist/images/messageBar_closingButton.svg +3 -0
  50. package/dist/images/messageBar_warning.svg +3 -0
  51. package/dist/images/toolbarButton-editorHighlight.svg +6 -0
  52. package/dist/images/toolbarButton-menuArrow.svg +3 -0
  53. package/dist/stores/comments-store.d.ts +1 -1
  54. package/dist/super-editor/ai-writer.es.js +2 -2
  55. package/dist/super-editor/chunks/{converter-AR-76siZ.js → converter-DMwo26F4.js} +1299 -1211
  56. package/dist/super-editor/chunks/default-BS6z0SoE.js +5 -0
  57. package/dist/super-editor/chunks/{docx-zipper-DVb-VGgt.js → docx-zipper-CuoYR_fZ.js} +1 -1
  58. package/dist/super-editor/chunks/{editor-mK_uimq6.js → editor-BQ9mPcm5.js} +202 -104
  59. package/dist/super-editor/chunks/index-CHAKf7mX.js +2213 -0
  60. package/dist/super-editor/chunks/index-CSaZZzfe.js +265 -0
  61. package/dist/super-editor/chunks/index-C_x_N6Uh.js +2200 -0
  62. package/dist/super-editor/chunks/index-Cd3D_8gF.js +862 -0
  63. package/dist/super-editor/chunks/index-CvBqQJbG.js +878 -0
  64. package/dist/super-editor/chunks/index-DL9bff78.js +845 -0
  65. package/dist/super-editor/chunks/index-DRCvimau.js +9876 -0
  66. package/dist/super-editor/chunks/index-D_sWOSiG.js +588 -0
  67. package/dist/super-editor/chunks/{toolbar-ByoNwr7x.js → toolbar-D59d-aMm.js} +2 -2
  68. package/dist/super-editor/converter.es.js +1 -1
  69. package/dist/super-editor/docx-zipper.es.js +2 -2
  70. package/dist/super-editor/editor.es.js +3 -3
  71. package/dist/super-editor/file-zipper.es.js +1 -1
  72. package/dist/super-editor/super-editor/src/core/Editor.d.ts +7 -1
  73. package/dist/super-editor/super-editor/src/core/commands/decreaseListIndent.d.ts +1 -1
  74. package/dist/super-editor/super-editor/src/core/commands/increaseListIndent.d.ts +1 -1
  75. package/dist/super-editor/super-editor/src/core/commands/list-helpers/list-indent-helpers.d.ts +3 -0
  76. package/dist/super-editor/super-editor/src/core/super-converter/exporter.d.ts +6 -0
  77. package/dist/super-editor/super-editor/src/core/super-converter/v2/importer/docxImporter.d.ts +1 -0
  78. package/dist/super-editor/super-editor/src/core/super-converter/v2/importer/types/index.d.ts +1 -0
  79. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/sdt/helpers/translate-structured-content.d.ts +2 -2
  80. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/t/index.d.ts +1 -0
  81. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/w/t/t-translator.d.ts +7 -0
  82. package/dist/super-editor/super-editor/src/core/super-converter/v3/node-translator/node-translator.d.ts +2 -1
  83. package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content-block.d.ts +8 -6
  84. package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content.d.ts +8 -1
  85. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentBlockTags.d.ts +11 -4
  86. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentInlineTags.d.ts +11 -4
  87. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTablesById.d.ts +8 -4
  88. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTags.d.ts +11 -4
  89. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTagsById.d.ts +12 -5
  90. package/dist/super-editor/super-editor/src/extensions/track-changes/permission-helpers.d.ts +2 -1
  91. package/dist/super-editor/super-editor.es.js +22 -22
  92. package/dist/super-editor/toolbar.es.js +2 -2
  93. package/dist/super-editor.cjs +1 -1
  94. package/dist/super-editor.es.js +1 -1
  95. package/dist/superdoc.cjs +2 -2
  96. package/dist/superdoc.es.js +2 -2
  97. package/dist/superdoc.umd.js +26057 -8172
  98. package/dist/superdoc.umd.js.map +1 -1
  99. package/package.json +1 -1
@@ -0,0 +1,2213 @@
1
+ import { u as unicodeWhitespace, b as unicodePunctuation, h as handle, c as asciiAlphanumeric, d as asciiAlpha, m as markdownLineEndingOrSpace, g as asciiControl, i as markdownSpace, j as markdownLineEnding, k as classifyCharacter } from "./index-Cd3D_8gF.js";
2
+ import { o as ok } from "./default-BS6z0SoE.js";
3
+ import { c as convert, a as visitParents } from "./index-CSaZZzfe.js";
4
+ function ccount(value, character) {
5
+ const source = String(value);
6
+ if (typeof character !== "string") {
7
+ throw new TypeError("Expected character");
8
+ }
9
+ let count = 0;
10
+ let index = source.indexOf(character);
11
+ while (index !== -1) {
12
+ count++;
13
+ index = source.indexOf(character, index + character.length);
14
+ }
15
+ return count;
16
+ }
17
+ function escapeStringRegexp(string) {
18
+ if (typeof string !== "string") {
19
+ throw new TypeError("Expected a string");
20
+ }
21
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
22
+ }
23
+ function findAndReplace(tree, list, options) {
24
+ const settings = options || {};
25
+ const ignored = convert(settings.ignore || []);
26
+ const pairs = toPairs(list);
27
+ let pairIndex = -1;
28
+ while (++pairIndex < pairs.length) {
29
+ visitParents(tree, "text", visitor);
30
+ }
31
+ function visitor(node, parents) {
32
+ let index = -1;
33
+ let grandparent;
34
+ while (++index < parents.length) {
35
+ const parent = parents[index];
36
+ const siblings = grandparent ? grandparent.children : void 0;
37
+ if (ignored(
38
+ parent,
39
+ siblings ? siblings.indexOf(parent) : void 0,
40
+ grandparent
41
+ )) {
42
+ return;
43
+ }
44
+ grandparent = parent;
45
+ }
46
+ if (grandparent) {
47
+ return handler(node, parents);
48
+ }
49
+ }
50
+ function handler(node, parents) {
51
+ const parent = parents[parents.length - 1];
52
+ const find = pairs[pairIndex][0];
53
+ const replace2 = pairs[pairIndex][1];
54
+ let start = 0;
55
+ const siblings = parent.children;
56
+ const index = siblings.indexOf(node);
57
+ let change = false;
58
+ let nodes = [];
59
+ find.lastIndex = 0;
60
+ let match = find.exec(node.value);
61
+ while (match) {
62
+ const position = match.index;
63
+ const matchObject = {
64
+ index: match.index,
65
+ input: match.input,
66
+ stack: [...parents, node]
67
+ };
68
+ let value = replace2(...match, matchObject);
69
+ if (typeof value === "string") {
70
+ value = value.length > 0 ? { type: "text", value } : void 0;
71
+ }
72
+ if (value === false) {
73
+ find.lastIndex = position + 1;
74
+ } else {
75
+ if (start !== position) {
76
+ nodes.push({
77
+ type: "text",
78
+ value: node.value.slice(start, position)
79
+ });
80
+ }
81
+ if (Array.isArray(value)) {
82
+ nodes.push(...value);
83
+ } else if (value) {
84
+ nodes.push(value);
85
+ }
86
+ start = position + match[0].length;
87
+ change = true;
88
+ }
89
+ if (!find.global) {
90
+ break;
91
+ }
92
+ match = find.exec(node.value);
93
+ }
94
+ if (change) {
95
+ if (start < node.value.length) {
96
+ nodes.push({ type: "text", value: node.value.slice(start) });
97
+ }
98
+ parent.children.splice(index, 1, ...nodes);
99
+ } else {
100
+ nodes = [node];
101
+ }
102
+ return index + nodes.length;
103
+ }
104
+ }
105
+ function toPairs(tupleOrList) {
106
+ const result = [];
107
+ if (!Array.isArray(tupleOrList)) {
108
+ throw new TypeError("Expected find and replace tuple or list of tuples");
109
+ }
110
+ const list = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
111
+ let index = -1;
112
+ while (++index < list.length) {
113
+ const tuple = list[index];
114
+ result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
115
+ }
116
+ return result;
117
+ }
118
+ function toExpression(find) {
119
+ return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find;
120
+ }
121
+ function toFunction(replace2) {
122
+ return typeof replace2 === "function" ? replace2 : function() {
123
+ return replace2;
124
+ };
125
+ }
126
+ const inConstruct = "phrasing";
127
+ const notInConstruct = ["autolink", "link", "image", "label"];
128
+ function gfmAutolinkLiteralFromMarkdown() {
129
+ return {
130
+ transforms: [transformGfmAutolinkLiterals],
131
+ enter: {
132
+ literalAutolink: enterLiteralAutolink,
133
+ literalAutolinkEmail: enterLiteralAutolinkValue,
134
+ literalAutolinkHttp: enterLiteralAutolinkValue,
135
+ literalAutolinkWww: enterLiteralAutolinkValue
136
+ },
137
+ exit: {
138
+ literalAutolink: exitLiteralAutolink,
139
+ literalAutolinkEmail: exitLiteralAutolinkEmail,
140
+ literalAutolinkHttp: exitLiteralAutolinkHttp,
141
+ literalAutolinkWww: exitLiteralAutolinkWww
142
+ }
143
+ };
144
+ }
145
+ function gfmAutolinkLiteralToMarkdown() {
146
+ return {
147
+ unsafe: [
148
+ {
149
+ character: "@",
150
+ before: "[+\\-.\\w]",
151
+ after: "[\\-.\\w]",
152
+ inConstruct,
153
+ notInConstruct
154
+ },
155
+ {
156
+ character: ".",
157
+ before: "[Ww]",
158
+ after: "[\\-.\\w]",
159
+ inConstruct,
160
+ notInConstruct
161
+ },
162
+ {
163
+ character: ":",
164
+ before: "[ps]",
165
+ after: "\\/",
166
+ inConstruct,
167
+ notInConstruct
168
+ }
169
+ ]
170
+ };
171
+ }
172
+ function enterLiteralAutolink(token) {
173
+ this.enter({ type: "link", title: null, url: "", children: [] }, token);
174
+ }
175
+ function enterLiteralAutolinkValue(token) {
176
+ this.config.enter.autolinkProtocol.call(this, token);
177
+ }
178
+ function exitLiteralAutolinkHttp(token) {
179
+ this.config.exit.autolinkProtocol.call(this, token);
180
+ }
181
+ function exitLiteralAutolinkWww(token) {
182
+ this.config.exit.data.call(this, token);
183
+ const node = this.stack[this.stack.length - 1];
184
+ ok(node.type === "link");
185
+ node.url = "http://" + this.sliceSerialize(token);
186
+ }
187
+ function exitLiteralAutolinkEmail(token) {
188
+ this.config.exit.autolinkEmail.call(this, token);
189
+ }
190
+ function exitLiteralAutolink(token) {
191
+ this.exit(token);
192
+ }
193
+ function transformGfmAutolinkLiterals(tree) {
194
+ findAndReplace(
195
+ tree,
196
+ [
197
+ [/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
198
+ [/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail]
199
+ ],
200
+ { ignore: ["link", "linkReference"] }
201
+ );
202
+ }
203
+ function findUrl(_, protocol, domain2, path2, match) {
204
+ let prefix = "";
205
+ if (!previous(match)) {
206
+ return false;
207
+ }
208
+ if (/^w/i.test(protocol)) {
209
+ domain2 = protocol + domain2;
210
+ protocol = "";
211
+ prefix = "http://";
212
+ }
213
+ if (!isCorrectDomain(domain2)) {
214
+ return false;
215
+ }
216
+ const parts = splitUrl(domain2 + path2);
217
+ if (!parts[0]) return false;
218
+ const result = {
219
+ type: "link",
220
+ title: null,
221
+ url: prefix + protocol + parts[0],
222
+ children: [{ type: "text", value: protocol + parts[0] }]
223
+ };
224
+ if (parts[1]) {
225
+ return [result, { type: "text", value: parts[1] }];
226
+ }
227
+ return result;
228
+ }
229
+ function findEmail(_, atext, label, match) {
230
+ if (
231
+ // Not an expected previous character.
232
+ !previous(match, true) || // Label ends in not allowed character.
233
+ /[-\d_]$/.test(label)
234
+ ) {
235
+ return false;
236
+ }
237
+ return {
238
+ type: "link",
239
+ title: null,
240
+ url: "mailto:" + atext + "@" + label,
241
+ children: [{ type: "text", value: atext + "@" + label }]
242
+ };
243
+ }
244
+ function isCorrectDomain(domain2) {
245
+ const parts = domain2.split(".");
246
+ if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
247
+ return false;
248
+ }
249
+ return true;
250
+ }
251
+ function splitUrl(url) {
252
+ const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url);
253
+ if (!trailExec) {
254
+ return [url, void 0];
255
+ }
256
+ url = url.slice(0, trailExec.index);
257
+ let trail2 = trailExec[0];
258
+ let closingParenIndex = trail2.indexOf(")");
259
+ const openingParens = ccount(url, "(");
260
+ let closingParens = ccount(url, ")");
261
+ while (closingParenIndex !== -1 && openingParens > closingParens) {
262
+ url += trail2.slice(0, closingParenIndex + 1);
263
+ trail2 = trail2.slice(closingParenIndex + 1);
264
+ closingParenIndex = trail2.indexOf(")");
265
+ closingParens++;
266
+ }
267
+ return [url, trail2];
268
+ }
269
+ function previous(match, email) {
270
+ const code2 = match.input.charCodeAt(match.index - 1);
271
+ return (match.index === 0 || unicodeWhitespace(code2) || unicodePunctuation(code2)) && // If it’s an email, the previous character should not be a slash.
272
+ (!email || code2 !== 47);
273
+ }
274
+ function normalizeIdentifier(value) {
275
+ return value.replace(/[\t\n\r ]+/g, " ").replace(/^ | $/g, "").toLowerCase().toUpperCase();
276
+ }
277
+ footnoteReference.peek = footnoteReferencePeek;
278
+ function enterFootnoteCallString() {
279
+ this.buffer();
280
+ }
281
+ function enterFootnoteCall(token) {
282
+ this.enter({ type: "footnoteReference", identifier: "", label: "" }, token);
283
+ }
284
+ function enterFootnoteDefinitionLabelString() {
285
+ this.buffer();
286
+ }
287
+ function enterFootnoteDefinition(token) {
288
+ this.enter(
289
+ { type: "footnoteDefinition", identifier: "", label: "", children: [] },
290
+ token
291
+ );
292
+ }
293
+ function exitFootnoteCallString(token) {
294
+ const label = this.resume();
295
+ const node = this.stack[this.stack.length - 1];
296
+ ok(node.type === "footnoteReference");
297
+ node.identifier = normalizeIdentifier(
298
+ this.sliceSerialize(token)
299
+ ).toLowerCase();
300
+ node.label = label;
301
+ }
302
+ function exitFootnoteCall(token) {
303
+ this.exit(token);
304
+ }
305
+ function exitFootnoteDefinitionLabelString(token) {
306
+ const label = this.resume();
307
+ const node = this.stack[this.stack.length - 1];
308
+ ok(node.type === "footnoteDefinition");
309
+ node.identifier = normalizeIdentifier(
310
+ this.sliceSerialize(token)
311
+ ).toLowerCase();
312
+ node.label = label;
313
+ }
314
+ function exitFootnoteDefinition(token) {
315
+ this.exit(token);
316
+ }
317
+ function footnoteReferencePeek() {
318
+ return "[";
319
+ }
320
+ function footnoteReference(node, _, state, info) {
321
+ const tracker = state.createTracker(info);
322
+ let value = tracker.move("[^");
323
+ const exit2 = state.enter("footnoteReference");
324
+ const subexit = state.enter("reference");
325
+ value += tracker.move(
326
+ state.safe(state.associationId(node), { after: "]", before: value })
327
+ );
328
+ subexit();
329
+ exit2();
330
+ value += tracker.move("]");
331
+ return value;
332
+ }
333
+ function gfmFootnoteFromMarkdown() {
334
+ return {
335
+ enter: {
336
+ gfmFootnoteCallString: enterFootnoteCallString,
337
+ gfmFootnoteCall: enterFootnoteCall,
338
+ gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString,
339
+ gfmFootnoteDefinition: enterFootnoteDefinition
340
+ },
341
+ exit: {
342
+ gfmFootnoteCallString: exitFootnoteCallString,
343
+ gfmFootnoteCall: exitFootnoteCall,
344
+ gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
345
+ gfmFootnoteDefinition: exitFootnoteDefinition
346
+ }
347
+ };
348
+ }
349
+ function gfmFootnoteToMarkdown(options) {
350
+ let firstLineBlank = false;
351
+ if (options && options.firstLineBlank) {
352
+ firstLineBlank = true;
353
+ }
354
+ return {
355
+ handlers: { footnoteDefinition, footnoteReference },
356
+ // This is on by default already.
357
+ unsafe: [{ character: "[", inConstruct: ["label", "phrasing", "reference"] }]
358
+ };
359
+ function footnoteDefinition(node, _, state, info) {
360
+ const tracker = state.createTracker(info);
361
+ let value = tracker.move("[^");
362
+ const exit2 = state.enter("footnoteDefinition");
363
+ const subexit = state.enter("label");
364
+ value += tracker.move(
365
+ state.safe(state.associationId(node), { before: value, after: "]" })
366
+ );
367
+ subexit();
368
+ value += tracker.move("]:");
369
+ if (node.children && node.children.length > 0) {
370
+ tracker.shift(4);
371
+ value += tracker.move(
372
+ (firstLineBlank ? "\n" : " ") + state.indentLines(
373
+ state.containerFlow(node, tracker.current()),
374
+ firstLineBlank ? mapAll : mapExceptFirst
375
+ )
376
+ );
377
+ }
378
+ exit2();
379
+ return value;
380
+ }
381
+ }
382
+ function mapExceptFirst(line, index, blank) {
383
+ return index === 0 ? line : mapAll(line, index, blank);
384
+ }
385
+ function mapAll(line, index, blank) {
386
+ return (blank ? "" : " ") + line;
387
+ }
388
+ const constructsWithoutStrikethrough = [
389
+ "autolink",
390
+ "destinationLiteral",
391
+ "destinationRaw",
392
+ "reference",
393
+ "titleQuote",
394
+ "titleApostrophe"
395
+ ];
396
+ handleDelete.peek = peekDelete;
397
+ function gfmStrikethroughFromMarkdown() {
398
+ return {
399
+ canContainEols: ["delete"],
400
+ enter: { strikethrough: enterStrikethrough },
401
+ exit: { strikethrough: exitStrikethrough }
402
+ };
403
+ }
404
+ function gfmStrikethroughToMarkdown() {
405
+ return {
406
+ unsafe: [
407
+ {
408
+ character: "~",
409
+ inConstruct: "phrasing",
410
+ notInConstruct: constructsWithoutStrikethrough
411
+ }
412
+ ],
413
+ handlers: { delete: handleDelete }
414
+ };
415
+ }
416
+ function enterStrikethrough(token) {
417
+ this.enter({ type: "delete", children: [] }, token);
418
+ }
419
+ function exitStrikethrough(token) {
420
+ this.exit(token);
421
+ }
422
+ function handleDelete(node, _, state, info) {
423
+ const tracker = state.createTracker(info);
424
+ const exit2 = state.enter("strikethrough");
425
+ let value = tracker.move("~~");
426
+ value += state.containerPhrasing(node, {
427
+ ...tracker.current(),
428
+ before: value,
429
+ after: "~"
430
+ });
431
+ value += tracker.move("~~");
432
+ exit2();
433
+ return value;
434
+ }
435
+ function peekDelete() {
436
+ return "~";
437
+ }
438
+ function defaultStringLength(value) {
439
+ return value.length;
440
+ }
441
+ function markdownTable(table, options) {
442
+ const settings = options || {};
443
+ const align = (settings.align || []).concat();
444
+ const stringLength = settings.stringLength || defaultStringLength;
445
+ const alignments = [];
446
+ const cellMatrix = [];
447
+ const sizeMatrix = [];
448
+ const longestCellByColumn = [];
449
+ let mostCellsPerRow = 0;
450
+ let rowIndex = -1;
451
+ while (++rowIndex < table.length) {
452
+ const row2 = [];
453
+ const sizes2 = [];
454
+ let columnIndex2 = -1;
455
+ if (table[rowIndex].length > mostCellsPerRow) {
456
+ mostCellsPerRow = table[rowIndex].length;
457
+ }
458
+ while (++columnIndex2 < table[rowIndex].length) {
459
+ const cell = serialize(table[rowIndex][columnIndex2]);
460
+ if (settings.alignDelimiters !== false) {
461
+ const size = stringLength(cell);
462
+ sizes2[columnIndex2] = size;
463
+ if (longestCellByColumn[columnIndex2] === void 0 || size > longestCellByColumn[columnIndex2]) {
464
+ longestCellByColumn[columnIndex2] = size;
465
+ }
466
+ }
467
+ row2.push(cell);
468
+ }
469
+ cellMatrix[rowIndex] = row2;
470
+ sizeMatrix[rowIndex] = sizes2;
471
+ }
472
+ let columnIndex = -1;
473
+ if (typeof align === "object" && "length" in align) {
474
+ while (++columnIndex < mostCellsPerRow) {
475
+ alignments[columnIndex] = toAlignment(align[columnIndex]);
476
+ }
477
+ } else {
478
+ const code2 = toAlignment(align);
479
+ while (++columnIndex < mostCellsPerRow) {
480
+ alignments[columnIndex] = code2;
481
+ }
482
+ }
483
+ columnIndex = -1;
484
+ const row = [];
485
+ const sizes = [];
486
+ while (++columnIndex < mostCellsPerRow) {
487
+ const code2 = alignments[columnIndex];
488
+ let before = "";
489
+ let after = "";
490
+ if (code2 === 99) {
491
+ before = ":";
492
+ after = ":";
493
+ } else if (code2 === 108) {
494
+ before = ":";
495
+ } else if (code2 === 114) {
496
+ after = ":";
497
+ }
498
+ let size = settings.alignDelimiters === false ? 1 : Math.max(
499
+ 1,
500
+ longestCellByColumn[columnIndex] - before.length - after.length
501
+ );
502
+ const cell = before + "-".repeat(size) + after;
503
+ if (settings.alignDelimiters !== false) {
504
+ size = before.length + size + after.length;
505
+ if (size > longestCellByColumn[columnIndex]) {
506
+ longestCellByColumn[columnIndex] = size;
507
+ }
508
+ sizes[columnIndex] = size;
509
+ }
510
+ row[columnIndex] = cell;
511
+ }
512
+ cellMatrix.splice(1, 0, row);
513
+ sizeMatrix.splice(1, 0, sizes);
514
+ rowIndex = -1;
515
+ const lines = [];
516
+ while (++rowIndex < cellMatrix.length) {
517
+ const row2 = cellMatrix[rowIndex];
518
+ const sizes2 = sizeMatrix[rowIndex];
519
+ columnIndex = -1;
520
+ const line = [];
521
+ while (++columnIndex < mostCellsPerRow) {
522
+ const cell = row2[columnIndex] || "";
523
+ let before = "";
524
+ let after = "";
525
+ if (settings.alignDelimiters !== false) {
526
+ const size = longestCellByColumn[columnIndex] - (sizes2[columnIndex] || 0);
527
+ const code2 = alignments[columnIndex];
528
+ if (code2 === 114) {
529
+ before = " ".repeat(size);
530
+ } else if (code2 === 99) {
531
+ if (size % 2) {
532
+ before = " ".repeat(size / 2 + 0.5);
533
+ after = " ".repeat(size / 2 - 0.5);
534
+ } else {
535
+ before = " ".repeat(size / 2);
536
+ after = before;
537
+ }
538
+ } else {
539
+ after = " ".repeat(size);
540
+ }
541
+ }
542
+ if (settings.delimiterStart !== false && !columnIndex) {
543
+ line.push("|");
544
+ }
545
+ if (settings.padding !== false && // Don’t add the opening space if we’re not aligning and the cell is
546
+ // empty: there will be a closing space.
547
+ !(settings.alignDelimiters === false && cell === "") && (settings.delimiterStart !== false || columnIndex)) {
548
+ line.push(" ");
549
+ }
550
+ if (settings.alignDelimiters !== false) {
551
+ line.push(before);
552
+ }
553
+ line.push(cell);
554
+ if (settings.alignDelimiters !== false) {
555
+ line.push(after);
556
+ }
557
+ if (settings.padding !== false) {
558
+ line.push(" ");
559
+ }
560
+ if (settings.delimiterEnd !== false || columnIndex !== mostCellsPerRow - 1) {
561
+ line.push("|");
562
+ }
563
+ }
564
+ lines.push(
565
+ settings.delimiterEnd === false ? line.join("").replace(/ +$/, "") : line.join("")
566
+ );
567
+ }
568
+ return lines.join("\n");
569
+ }
570
+ function serialize(value) {
571
+ return value === null || value === void 0 ? "" : String(value);
572
+ }
573
+ function toAlignment(value) {
574
+ const code2 = typeof value === "string" ? value.codePointAt(0) : 0;
575
+ return code2 === 67 || code2 === 99 ? 99 : code2 === 76 || code2 === 108 ? 108 : code2 === 82 || code2 === 114 ? 114 : 0;
576
+ }
577
+ function gfmTableFromMarkdown() {
578
+ return {
579
+ enter: {
580
+ table: enterTable,
581
+ tableData: enterCell,
582
+ tableHeader: enterCell,
583
+ tableRow: enterRow
584
+ },
585
+ exit: {
586
+ codeText: exitCodeText,
587
+ table: exitTable,
588
+ tableData: exit,
589
+ tableHeader: exit,
590
+ tableRow: exit
591
+ }
592
+ };
593
+ }
594
+ function enterTable(token) {
595
+ const align = token._align;
596
+ this.enter(
597
+ {
598
+ type: "table",
599
+ align: align.map(function(d) {
600
+ return d === "none" ? null : d;
601
+ }),
602
+ children: []
603
+ },
604
+ token
605
+ );
606
+ this.data.inTable = true;
607
+ }
608
+ function exitTable(token) {
609
+ this.exit(token);
610
+ this.data.inTable = void 0;
611
+ }
612
+ function enterRow(token) {
613
+ this.enter({ type: "tableRow", children: [] }, token);
614
+ }
615
+ function exit(token) {
616
+ this.exit(token);
617
+ }
618
+ function enterCell(token) {
619
+ this.enter({ type: "tableCell", children: [] }, token);
620
+ }
621
+ function exitCodeText(token) {
622
+ let value = this.resume();
623
+ if (this.data.inTable) {
624
+ value = value.replace(/\\([\\|])/g, replace);
625
+ }
626
+ const node = this.stack[this.stack.length - 1];
627
+ ok(node.type === "inlineCode");
628
+ node.value = value;
629
+ this.exit(token);
630
+ }
631
+ function replace($0, $1) {
632
+ return $1 === "|" ? $1 : $0;
633
+ }
634
+ function gfmTableToMarkdown(options) {
635
+ const settings = options || {};
636
+ const padding = settings.tableCellPadding;
637
+ const alignDelimiters = settings.tablePipeAlign;
638
+ const stringLength = settings.stringLength;
639
+ const around = padding ? " " : "|";
640
+ return {
641
+ unsafe: [
642
+ { character: "\r", inConstruct: "tableCell" },
643
+ { character: "\n", inConstruct: "tableCell" },
644
+ // A pipe, when followed by a tab or space (padding), or a dash or colon
645
+ // (unpadded delimiter row), could result in a table.
646
+ { atBreak: true, character: "|", after: "[ :-]" },
647
+ // A pipe in a cell must be encoded.
648
+ { character: "|", inConstruct: "tableCell" },
649
+ // A colon must be followed by a dash, in which case it could start a
650
+ // delimiter row.
651
+ { atBreak: true, character: ":", after: "-" },
652
+ // A delimiter row can also start with a dash, when followed by more
653
+ // dashes, a colon, or a pipe.
654
+ // This is a stricter version than the built in check for lists, thematic
655
+ // breaks, and setex heading underlines though:
656
+ // <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
657
+ { atBreak: true, character: "-", after: "[:|-]" }
658
+ ],
659
+ handlers: {
660
+ inlineCode: inlineCodeWithTable,
661
+ table: handleTable,
662
+ tableCell: handleTableCell,
663
+ tableRow: handleTableRow
664
+ }
665
+ };
666
+ function handleTable(node, _, state, info) {
667
+ return serializeData(handleTableAsData(node, state, info), node.align);
668
+ }
669
+ function handleTableRow(node, _, state, info) {
670
+ const row = handleTableRowAsData(node, state, info);
671
+ const value = serializeData([row]);
672
+ return value.slice(0, value.indexOf("\n"));
673
+ }
674
+ function handleTableCell(node, _, state, info) {
675
+ const exit2 = state.enter("tableCell");
676
+ const subexit = state.enter("phrasing");
677
+ const value = state.containerPhrasing(node, {
678
+ ...info,
679
+ before: around,
680
+ after: around
681
+ });
682
+ subexit();
683
+ exit2();
684
+ return value;
685
+ }
686
+ function serializeData(matrix, align) {
687
+ return markdownTable(matrix, {
688
+ align,
689
+ // @ts-expect-error: `markdown-table` types should support `null`.
690
+ alignDelimiters,
691
+ // @ts-expect-error: `markdown-table` types should support `null`.
692
+ padding,
693
+ // @ts-expect-error: `markdown-table` types should support `null`.
694
+ stringLength
695
+ });
696
+ }
697
+ function handleTableAsData(node, state, info) {
698
+ const children = node.children;
699
+ let index = -1;
700
+ const result = [];
701
+ const subexit = state.enter("table");
702
+ while (++index < children.length) {
703
+ result[index] = handleTableRowAsData(children[index], state, info);
704
+ }
705
+ subexit();
706
+ return result;
707
+ }
708
+ function handleTableRowAsData(node, state, info) {
709
+ const children = node.children;
710
+ let index = -1;
711
+ const result = [];
712
+ const subexit = state.enter("tableRow");
713
+ while (++index < children.length) {
714
+ result[index] = handleTableCell(children[index], node, state, info);
715
+ }
716
+ subexit();
717
+ return result;
718
+ }
719
+ function inlineCodeWithTable(node, parent, state) {
720
+ let value = handle.inlineCode(node, parent, state);
721
+ if (state.stack.includes("tableCell")) {
722
+ value = value.replace(/\|/g, "\\$&");
723
+ }
724
+ return value;
725
+ }
726
+ }
727
+ function gfmTaskListItemFromMarkdown() {
728
+ return {
729
+ exit: {
730
+ taskListCheckValueChecked: exitCheck,
731
+ taskListCheckValueUnchecked: exitCheck,
732
+ paragraph: exitParagraphWithTaskListItem
733
+ }
734
+ };
735
+ }
736
+ function gfmTaskListItemToMarkdown() {
737
+ return {
738
+ unsafe: [{ atBreak: true, character: "-", after: "[:|-]" }],
739
+ handlers: { listItem: listItemWithTaskListItem }
740
+ };
741
+ }
742
+ function exitCheck(token) {
743
+ const node = this.stack[this.stack.length - 2];
744
+ ok(node.type === "listItem");
745
+ node.checked = token.type === "taskListCheckValueChecked";
746
+ }
747
+ function exitParagraphWithTaskListItem(token) {
748
+ const parent = this.stack[this.stack.length - 2];
749
+ if (parent && parent.type === "listItem" && typeof parent.checked === "boolean") {
750
+ const node = this.stack[this.stack.length - 1];
751
+ ok(node.type === "paragraph");
752
+ const head = node.children[0];
753
+ if (head && head.type === "text") {
754
+ const siblings = parent.children;
755
+ let index = -1;
756
+ let firstParaghraph;
757
+ while (++index < siblings.length) {
758
+ const sibling = siblings[index];
759
+ if (sibling.type === "paragraph") {
760
+ firstParaghraph = sibling;
761
+ break;
762
+ }
763
+ }
764
+ if (firstParaghraph === node) {
765
+ head.value = head.value.slice(1);
766
+ if (head.value.length === 0) {
767
+ node.children.shift();
768
+ } else if (node.position && head.position && typeof head.position.start.offset === "number") {
769
+ head.position.start.column++;
770
+ head.position.start.offset++;
771
+ node.position.start = Object.assign({}, head.position.start);
772
+ }
773
+ }
774
+ }
775
+ }
776
+ this.exit(token);
777
+ }
778
+ function listItemWithTaskListItem(node, parent, state, info) {
779
+ const head = node.children[0];
780
+ const checkable = typeof node.checked === "boolean" && head && head.type === "paragraph";
781
+ const checkbox = "[" + (node.checked ? "x" : " ") + "] ";
782
+ const tracker = state.createTracker(info);
783
+ if (checkable) {
784
+ tracker.move(checkbox);
785
+ }
786
+ let value = handle.listItem(node, parent, state, {
787
+ ...info,
788
+ ...tracker.current()
789
+ });
790
+ if (checkable) {
791
+ value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check);
792
+ }
793
+ return value;
794
+ function check($0) {
795
+ return $0 + checkbox;
796
+ }
797
+ }
798
+ function gfmFromMarkdown() {
799
+ return [
800
+ gfmAutolinkLiteralFromMarkdown(),
801
+ gfmFootnoteFromMarkdown(),
802
+ gfmStrikethroughFromMarkdown(),
803
+ gfmTableFromMarkdown(),
804
+ gfmTaskListItemFromMarkdown()
805
+ ];
806
+ }
807
+ function gfmToMarkdown(options) {
808
+ return {
809
+ extensions: [
810
+ gfmAutolinkLiteralToMarkdown(),
811
+ gfmFootnoteToMarkdown(options),
812
+ gfmStrikethroughToMarkdown(),
813
+ gfmTableToMarkdown(options),
814
+ gfmTaskListItemToMarkdown()
815
+ ]
816
+ };
817
+ }
818
+ function splice(list, start, remove, items) {
819
+ const end = list.length;
820
+ let chunkStart = 0;
821
+ let parameters;
822
+ if (start < 0) {
823
+ start = -start > end ? 0 : end + start;
824
+ } else {
825
+ start = start > end ? end : start;
826
+ }
827
+ remove = remove > 0 ? remove : 0;
828
+ if (items.length < 1e4) {
829
+ parameters = Array.from(items);
830
+ parameters.unshift(start, remove);
831
+ list.splice(...parameters);
832
+ } else {
833
+ if (remove) list.splice(start, remove);
834
+ while (chunkStart < items.length) {
835
+ parameters = items.slice(chunkStart, chunkStart + 1e4);
836
+ parameters.unshift(start, 0);
837
+ list.splice(...parameters);
838
+ chunkStart += 1e4;
839
+ start += 1e4;
840
+ }
841
+ }
842
+ }
843
+ const hasOwnProperty = {}.hasOwnProperty;
844
+ function combineExtensions(extensions) {
845
+ const all = {};
846
+ let index = -1;
847
+ while (++index < extensions.length) {
848
+ syntaxExtension(all, extensions[index]);
849
+ }
850
+ return all;
851
+ }
852
+ function syntaxExtension(all, extension) {
853
+ let hook;
854
+ for (hook in extension) {
855
+ const maybe = hasOwnProperty.call(all, hook) ? all[hook] : void 0;
856
+ const left = maybe || (all[hook] = {});
857
+ const right = extension[hook];
858
+ let code2;
859
+ if (right) {
860
+ for (code2 in right) {
861
+ if (!hasOwnProperty.call(left, code2)) left[code2] = [];
862
+ const value = right[code2];
863
+ constructs(
864
+ // @ts-expect-error Looks like a list.
865
+ left[code2],
866
+ Array.isArray(value) ? value : value ? [value] : []
867
+ );
868
+ }
869
+ }
870
+ }
871
+ }
872
+ function constructs(existing, list) {
873
+ let index = -1;
874
+ const before = [];
875
+ while (++index < list.length) {
876
+ (list[index].add === "after" ? existing : before).push(list[index]);
877
+ }
878
+ splice(existing, 0, 0, before);
879
+ }
880
+ const wwwPrefix = {
881
+ tokenize: tokenizeWwwPrefix,
882
+ partial: true
883
+ };
884
+ const domain = {
885
+ tokenize: tokenizeDomain,
886
+ partial: true
887
+ };
888
+ const path = {
889
+ tokenize: tokenizePath,
890
+ partial: true
891
+ };
892
+ const trail = {
893
+ tokenize: tokenizeTrail,
894
+ partial: true
895
+ };
896
+ const emailDomainDotTrail = {
897
+ tokenize: tokenizeEmailDomainDotTrail,
898
+ partial: true
899
+ };
900
+ const wwwAutolink = {
901
+ name: "wwwAutolink",
902
+ tokenize: tokenizeWwwAutolink,
903
+ previous: previousWww
904
+ };
905
+ const protocolAutolink = {
906
+ name: "protocolAutolink",
907
+ tokenize: tokenizeProtocolAutolink,
908
+ previous: previousProtocol
909
+ };
910
+ const emailAutolink = {
911
+ name: "emailAutolink",
912
+ tokenize: tokenizeEmailAutolink,
913
+ previous: previousEmail
914
+ };
915
+ const text = {};
916
+ function gfmAutolinkLiteral() {
917
+ return {
918
+ text
919
+ };
920
+ }
921
+ let code = 48;
922
+ while (code < 123) {
923
+ text[code] = emailAutolink;
924
+ code++;
925
+ if (code === 58) code = 65;
926
+ else if (code === 91) code = 97;
927
+ }
928
+ text[43] = emailAutolink;
929
+ text[45] = emailAutolink;
930
+ text[46] = emailAutolink;
931
+ text[95] = emailAutolink;
932
+ text[72] = [emailAutolink, protocolAutolink];
933
+ text[104] = [emailAutolink, protocolAutolink];
934
+ text[87] = [emailAutolink, wwwAutolink];
935
+ text[119] = [emailAutolink, wwwAutolink];
936
+ function tokenizeEmailAutolink(effects, ok2, nok) {
937
+ const self = this;
938
+ let dot;
939
+ let data;
940
+ return start;
941
+ function start(code2) {
942
+ if (!gfmAtext(code2) || !previousEmail.call(self, self.previous) || previousUnbalanced(self.events)) {
943
+ return nok(code2);
944
+ }
945
+ effects.enter("literalAutolink");
946
+ effects.enter("literalAutolinkEmail");
947
+ return atext(code2);
948
+ }
949
+ function atext(code2) {
950
+ if (gfmAtext(code2)) {
951
+ effects.consume(code2);
952
+ return atext;
953
+ }
954
+ if (code2 === 64) {
955
+ effects.consume(code2);
956
+ return emailDomain;
957
+ }
958
+ return nok(code2);
959
+ }
960
+ function emailDomain(code2) {
961
+ if (code2 === 46) {
962
+ return effects.check(emailDomainDotTrail, emailDomainAfter, emailDomainDot)(code2);
963
+ }
964
+ if (code2 === 45 || code2 === 95 || asciiAlphanumeric(code2)) {
965
+ data = true;
966
+ effects.consume(code2);
967
+ return emailDomain;
968
+ }
969
+ return emailDomainAfter(code2);
970
+ }
971
+ function emailDomainDot(code2) {
972
+ effects.consume(code2);
973
+ dot = true;
974
+ return emailDomain;
975
+ }
976
+ function emailDomainAfter(code2) {
977
+ if (data && dot && asciiAlpha(self.previous)) {
978
+ effects.exit("literalAutolinkEmail");
979
+ effects.exit("literalAutolink");
980
+ return ok2(code2);
981
+ }
982
+ return nok(code2);
983
+ }
984
+ }
985
+ function tokenizeWwwAutolink(effects, ok2, nok) {
986
+ const self = this;
987
+ return wwwStart;
988
+ function wwwStart(code2) {
989
+ if (code2 !== 87 && code2 !== 119 || !previousWww.call(self, self.previous) || previousUnbalanced(self.events)) {
990
+ return nok(code2);
991
+ }
992
+ effects.enter("literalAutolink");
993
+ effects.enter("literalAutolinkWww");
994
+ return effects.check(wwwPrefix, effects.attempt(domain, effects.attempt(path, wwwAfter), nok), nok)(code2);
995
+ }
996
+ function wwwAfter(code2) {
997
+ effects.exit("literalAutolinkWww");
998
+ effects.exit("literalAutolink");
999
+ return ok2(code2);
1000
+ }
1001
+ }
1002
+ function tokenizeProtocolAutolink(effects, ok2, nok) {
1003
+ const self = this;
1004
+ let buffer = "";
1005
+ let seen = false;
1006
+ return protocolStart;
1007
+ function protocolStart(code2) {
1008
+ if ((code2 === 72 || code2 === 104) && previousProtocol.call(self, self.previous) && !previousUnbalanced(self.events)) {
1009
+ effects.enter("literalAutolink");
1010
+ effects.enter("literalAutolinkHttp");
1011
+ buffer += String.fromCodePoint(code2);
1012
+ effects.consume(code2);
1013
+ return protocolPrefixInside;
1014
+ }
1015
+ return nok(code2);
1016
+ }
1017
+ function protocolPrefixInside(code2) {
1018
+ if (asciiAlpha(code2) && buffer.length < 5) {
1019
+ buffer += String.fromCodePoint(code2);
1020
+ effects.consume(code2);
1021
+ return protocolPrefixInside;
1022
+ }
1023
+ if (code2 === 58) {
1024
+ const protocol = buffer.toLowerCase();
1025
+ if (protocol === "http" || protocol === "https") {
1026
+ effects.consume(code2);
1027
+ return protocolSlashesInside;
1028
+ }
1029
+ }
1030
+ return nok(code2);
1031
+ }
1032
+ function protocolSlashesInside(code2) {
1033
+ if (code2 === 47) {
1034
+ effects.consume(code2);
1035
+ if (seen) {
1036
+ return afterProtocol;
1037
+ }
1038
+ seen = true;
1039
+ return protocolSlashesInside;
1040
+ }
1041
+ return nok(code2);
1042
+ }
1043
+ function afterProtocol(code2) {
1044
+ return code2 === null || asciiControl(code2) || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || unicodePunctuation(code2) ? nok(code2) : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code2);
1045
+ }
1046
+ function protocolAfter(code2) {
1047
+ effects.exit("literalAutolinkHttp");
1048
+ effects.exit("literalAutolink");
1049
+ return ok2(code2);
1050
+ }
1051
+ }
1052
+ function tokenizeWwwPrefix(effects, ok2, nok) {
1053
+ let size = 0;
1054
+ return wwwPrefixInside;
1055
+ function wwwPrefixInside(code2) {
1056
+ if ((code2 === 87 || code2 === 119) && size < 3) {
1057
+ size++;
1058
+ effects.consume(code2);
1059
+ return wwwPrefixInside;
1060
+ }
1061
+ if (code2 === 46 && size === 3) {
1062
+ effects.consume(code2);
1063
+ return wwwPrefixAfter;
1064
+ }
1065
+ return nok(code2);
1066
+ }
1067
+ function wwwPrefixAfter(code2) {
1068
+ return code2 === null ? nok(code2) : ok2(code2);
1069
+ }
1070
+ }
1071
+ function tokenizeDomain(effects, ok2, nok) {
1072
+ let underscoreInLastSegment;
1073
+ let underscoreInLastLastSegment;
1074
+ let seen;
1075
+ return domainInside;
1076
+ function domainInside(code2) {
1077
+ if (code2 === 46 || code2 === 95) {
1078
+ return effects.check(trail, domainAfter, domainAtPunctuation)(code2);
1079
+ }
1080
+ if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || code2 !== 45 && unicodePunctuation(code2)) {
1081
+ return domainAfter(code2);
1082
+ }
1083
+ seen = true;
1084
+ effects.consume(code2);
1085
+ return domainInside;
1086
+ }
1087
+ function domainAtPunctuation(code2) {
1088
+ if (code2 === 95) {
1089
+ underscoreInLastSegment = true;
1090
+ } else {
1091
+ underscoreInLastLastSegment = underscoreInLastSegment;
1092
+ underscoreInLastSegment = void 0;
1093
+ }
1094
+ effects.consume(code2);
1095
+ return domainInside;
1096
+ }
1097
+ function domainAfter(code2) {
1098
+ if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) {
1099
+ return nok(code2);
1100
+ }
1101
+ return ok2(code2);
1102
+ }
1103
+ }
1104
+ function tokenizePath(effects, ok2) {
1105
+ let sizeOpen = 0;
1106
+ let sizeClose = 0;
1107
+ return pathInside;
1108
+ function pathInside(code2) {
1109
+ if (code2 === 40) {
1110
+ sizeOpen++;
1111
+ effects.consume(code2);
1112
+ return pathInside;
1113
+ }
1114
+ if (code2 === 41 && sizeClose < sizeOpen) {
1115
+ return pathAtPunctuation(code2);
1116
+ }
1117
+ if (code2 === 33 || code2 === 34 || code2 === 38 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 60 || code2 === 63 || code2 === 93 || code2 === 95 || code2 === 126) {
1118
+ return effects.check(trail, ok2, pathAtPunctuation)(code2);
1119
+ }
1120
+ if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
1121
+ return ok2(code2);
1122
+ }
1123
+ effects.consume(code2);
1124
+ return pathInside;
1125
+ }
1126
+ function pathAtPunctuation(code2) {
1127
+ if (code2 === 41) {
1128
+ sizeClose++;
1129
+ }
1130
+ effects.consume(code2);
1131
+ return pathInside;
1132
+ }
1133
+ }
1134
+ function tokenizeTrail(effects, ok2, nok) {
1135
+ return trail2;
1136
+ function trail2(code2) {
1137
+ if (code2 === 33 || code2 === 34 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 63 || code2 === 95 || code2 === 126) {
1138
+ effects.consume(code2);
1139
+ return trail2;
1140
+ }
1141
+ if (code2 === 38) {
1142
+ effects.consume(code2);
1143
+ return trailCharacterReferenceStart;
1144
+ }
1145
+ if (code2 === 93) {
1146
+ effects.consume(code2);
1147
+ return trailBracketAfter;
1148
+ }
1149
+ if (
1150
+ // `<` is an end.
1151
+ code2 === 60 || // So is whitespace.
1152
+ code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)
1153
+ ) {
1154
+ return ok2(code2);
1155
+ }
1156
+ return nok(code2);
1157
+ }
1158
+ function trailBracketAfter(code2) {
1159
+ if (code2 === null || code2 === 40 || code2 === 91 || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
1160
+ return ok2(code2);
1161
+ }
1162
+ return trail2(code2);
1163
+ }
1164
+ function trailCharacterReferenceStart(code2) {
1165
+ return asciiAlpha(code2) ? trailCharacterReferenceInside(code2) : nok(code2);
1166
+ }
1167
+ function trailCharacterReferenceInside(code2) {
1168
+ if (code2 === 59) {
1169
+ effects.consume(code2);
1170
+ return trail2;
1171
+ }
1172
+ if (asciiAlpha(code2)) {
1173
+ effects.consume(code2);
1174
+ return trailCharacterReferenceInside;
1175
+ }
1176
+ return nok(code2);
1177
+ }
1178
+ }
1179
+ function tokenizeEmailDomainDotTrail(effects, ok2, nok) {
1180
+ return start;
1181
+ function start(code2) {
1182
+ effects.consume(code2);
1183
+ return after;
1184
+ }
1185
+ function after(code2) {
1186
+ return asciiAlphanumeric(code2) ? nok(code2) : ok2(code2);
1187
+ }
1188
+ }
1189
+ function previousWww(code2) {
1190
+ return code2 === null || code2 === 40 || code2 === 42 || code2 === 95 || code2 === 91 || code2 === 93 || code2 === 126 || markdownLineEndingOrSpace(code2);
1191
+ }
1192
+ function previousProtocol(code2) {
1193
+ return !asciiAlpha(code2);
1194
+ }
1195
+ function previousEmail(code2) {
1196
+ return !(code2 === 47 || gfmAtext(code2));
1197
+ }
1198
+ function gfmAtext(code2) {
1199
+ return code2 === 43 || code2 === 45 || code2 === 46 || code2 === 95 || asciiAlphanumeric(code2);
1200
+ }
1201
+ function previousUnbalanced(events) {
1202
+ let index = events.length;
1203
+ let result = false;
1204
+ while (index--) {
1205
+ const token = events[index][1];
1206
+ if ((token.type === "labelLink" || token.type === "labelImage") && !token._balanced) {
1207
+ result = true;
1208
+ break;
1209
+ }
1210
+ if (token._gfmAutolinkLiteralWalkedInto) {
1211
+ result = false;
1212
+ break;
1213
+ }
1214
+ }
1215
+ if (events.length > 0 && !result) {
1216
+ events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true;
1217
+ }
1218
+ return result;
1219
+ }
1220
+ function resolveAll(constructs2, events, context) {
1221
+ const called = [];
1222
+ let index = -1;
1223
+ while (++index < constructs2.length) {
1224
+ const resolve = constructs2[index].resolveAll;
1225
+ if (resolve && !called.includes(resolve)) {
1226
+ events = resolve(events, context);
1227
+ called.push(resolve);
1228
+ }
1229
+ }
1230
+ return events;
1231
+ }
1232
+ function factorySpace(effects, ok2, type, max) {
1233
+ const limit = max ? max - 1 : Number.POSITIVE_INFINITY;
1234
+ let size = 0;
1235
+ return start;
1236
+ function start(code2) {
1237
+ if (markdownSpace(code2)) {
1238
+ effects.enter(type);
1239
+ return prefix(code2);
1240
+ }
1241
+ return ok2(code2);
1242
+ }
1243
+ function prefix(code2) {
1244
+ if (markdownSpace(code2) && size++ < limit) {
1245
+ effects.consume(code2);
1246
+ return prefix;
1247
+ }
1248
+ effects.exit(type);
1249
+ return ok2(code2);
1250
+ }
1251
+ }
1252
+ const blankLine = {
1253
+ partial: true,
1254
+ tokenize: tokenizeBlankLine
1255
+ };
1256
+ function tokenizeBlankLine(effects, ok2, nok) {
1257
+ return start;
1258
+ function start(code2) {
1259
+ return markdownSpace(code2) ? factorySpace(effects, after, "linePrefix")(code2) : after(code2);
1260
+ }
1261
+ function after(code2) {
1262
+ return code2 === null || markdownLineEnding(code2) ? ok2(code2) : nok(code2);
1263
+ }
1264
+ }
1265
+ const indent = {
1266
+ tokenize: tokenizeIndent,
1267
+ partial: true
1268
+ };
1269
+ function gfmFootnote() {
1270
+ return {
1271
+ document: {
1272
+ [91]: {
1273
+ name: "gfmFootnoteDefinition",
1274
+ tokenize: tokenizeDefinitionStart,
1275
+ continuation: {
1276
+ tokenize: tokenizeDefinitionContinuation
1277
+ },
1278
+ exit: gfmFootnoteDefinitionEnd
1279
+ }
1280
+ },
1281
+ text: {
1282
+ [91]: {
1283
+ name: "gfmFootnoteCall",
1284
+ tokenize: tokenizeGfmFootnoteCall
1285
+ },
1286
+ [93]: {
1287
+ name: "gfmPotentialFootnoteCall",
1288
+ add: "after",
1289
+ tokenize: tokenizePotentialGfmFootnoteCall,
1290
+ resolveTo: resolveToPotentialGfmFootnoteCall
1291
+ }
1292
+ }
1293
+ };
1294
+ }
1295
+ function tokenizePotentialGfmFootnoteCall(effects, ok2, nok) {
1296
+ const self = this;
1297
+ let index = self.events.length;
1298
+ const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
1299
+ let labelStart;
1300
+ while (index--) {
1301
+ const token = self.events[index][1];
1302
+ if (token.type === "labelImage") {
1303
+ labelStart = token;
1304
+ break;
1305
+ }
1306
+ if (token.type === "gfmFootnoteCall" || token.type === "labelLink" || token.type === "label" || token.type === "image" || token.type === "link") {
1307
+ break;
1308
+ }
1309
+ }
1310
+ return start;
1311
+ function start(code2) {
1312
+ if (!labelStart || !labelStart._balanced) {
1313
+ return nok(code2);
1314
+ }
1315
+ const id = normalizeIdentifier(self.sliceSerialize({
1316
+ start: labelStart.end,
1317
+ end: self.now()
1318
+ }));
1319
+ if (id.codePointAt(0) !== 94 || !defined.includes(id.slice(1))) {
1320
+ return nok(code2);
1321
+ }
1322
+ effects.enter("gfmFootnoteCallLabelMarker");
1323
+ effects.consume(code2);
1324
+ effects.exit("gfmFootnoteCallLabelMarker");
1325
+ return ok2(code2);
1326
+ }
1327
+ }
1328
+ function resolveToPotentialGfmFootnoteCall(events, context) {
1329
+ let index = events.length;
1330
+ while (index--) {
1331
+ if (events[index][1].type === "labelImage" && events[index][0] === "enter") {
1332
+ events[index][1];
1333
+ break;
1334
+ }
1335
+ }
1336
+ events[index + 1][1].type = "data";
1337
+ events[index + 3][1].type = "gfmFootnoteCallLabelMarker";
1338
+ const call = {
1339
+ type: "gfmFootnoteCall",
1340
+ start: Object.assign({}, events[index + 3][1].start),
1341
+ end: Object.assign({}, events[events.length - 1][1].end)
1342
+ };
1343
+ const marker = {
1344
+ type: "gfmFootnoteCallMarker",
1345
+ start: Object.assign({}, events[index + 3][1].end),
1346
+ end: Object.assign({}, events[index + 3][1].end)
1347
+ };
1348
+ marker.end.column++;
1349
+ marker.end.offset++;
1350
+ marker.end._bufferIndex++;
1351
+ const string = {
1352
+ type: "gfmFootnoteCallString",
1353
+ start: Object.assign({}, marker.end),
1354
+ end: Object.assign({}, events[events.length - 1][1].start)
1355
+ };
1356
+ const chunk = {
1357
+ type: "chunkString",
1358
+ contentType: "string",
1359
+ start: Object.assign({}, string.start),
1360
+ end: Object.assign({}, string.end)
1361
+ };
1362
+ const replacement = [
1363
+ // Take the `labelImageMarker` (now `data`, the `!`)
1364
+ events[index + 1],
1365
+ events[index + 2],
1366
+ ["enter", call, context],
1367
+ // The `[`
1368
+ events[index + 3],
1369
+ events[index + 4],
1370
+ // The `^`.
1371
+ ["enter", marker, context],
1372
+ ["exit", marker, context],
1373
+ // Everything in between.
1374
+ ["enter", string, context],
1375
+ ["enter", chunk, context],
1376
+ ["exit", chunk, context],
1377
+ ["exit", string, context],
1378
+ // The ending (`]`, properly parsed and labelled).
1379
+ events[events.length - 2],
1380
+ events[events.length - 1],
1381
+ ["exit", call, context]
1382
+ ];
1383
+ events.splice(index, events.length - index + 1, ...replacement);
1384
+ return events;
1385
+ }
1386
+ function tokenizeGfmFootnoteCall(effects, ok2, nok) {
1387
+ const self = this;
1388
+ const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
1389
+ let size = 0;
1390
+ let data;
1391
+ return start;
1392
+ function start(code2) {
1393
+ effects.enter("gfmFootnoteCall");
1394
+ effects.enter("gfmFootnoteCallLabelMarker");
1395
+ effects.consume(code2);
1396
+ effects.exit("gfmFootnoteCallLabelMarker");
1397
+ return callStart;
1398
+ }
1399
+ function callStart(code2) {
1400
+ if (code2 !== 94) return nok(code2);
1401
+ effects.enter("gfmFootnoteCallMarker");
1402
+ effects.consume(code2);
1403
+ effects.exit("gfmFootnoteCallMarker");
1404
+ effects.enter("gfmFootnoteCallString");
1405
+ effects.enter("chunkString").contentType = "string";
1406
+ return callData;
1407
+ }
1408
+ function callData(code2) {
1409
+ if (
1410
+ // Too long.
1411
+ size > 999 || // Closing brace with nothing.
1412
+ code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
1413
+ // `\n` and `[` not being supported makes sense.
1414
+ code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
1415
+ ) {
1416
+ return nok(code2);
1417
+ }
1418
+ if (code2 === 93) {
1419
+ effects.exit("chunkString");
1420
+ const token = effects.exit("gfmFootnoteCallString");
1421
+ if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) {
1422
+ return nok(code2);
1423
+ }
1424
+ effects.enter("gfmFootnoteCallLabelMarker");
1425
+ effects.consume(code2);
1426
+ effects.exit("gfmFootnoteCallLabelMarker");
1427
+ effects.exit("gfmFootnoteCall");
1428
+ return ok2;
1429
+ }
1430
+ if (!markdownLineEndingOrSpace(code2)) {
1431
+ data = true;
1432
+ }
1433
+ size++;
1434
+ effects.consume(code2);
1435
+ return code2 === 92 ? callEscape : callData;
1436
+ }
1437
+ function callEscape(code2) {
1438
+ if (code2 === 91 || code2 === 92 || code2 === 93) {
1439
+ effects.consume(code2);
1440
+ size++;
1441
+ return callData;
1442
+ }
1443
+ return callData(code2);
1444
+ }
1445
+ }
1446
+ function tokenizeDefinitionStart(effects, ok2, nok) {
1447
+ const self = this;
1448
+ const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
1449
+ let identifier;
1450
+ let size = 0;
1451
+ let data;
1452
+ return start;
1453
+ function start(code2) {
1454
+ effects.enter("gfmFootnoteDefinition")._container = true;
1455
+ effects.enter("gfmFootnoteDefinitionLabel");
1456
+ effects.enter("gfmFootnoteDefinitionLabelMarker");
1457
+ effects.consume(code2);
1458
+ effects.exit("gfmFootnoteDefinitionLabelMarker");
1459
+ return labelAtMarker;
1460
+ }
1461
+ function labelAtMarker(code2) {
1462
+ if (code2 === 94) {
1463
+ effects.enter("gfmFootnoteDefinitionMarker");
1464
+ effects.consume(code2);
1465
+ effects.exit("gfmFootnoteDefinitionMarker");
1466
+ effects.enter("gfmFootnoteDefinitionLabelString");
1467
+ effects.enter("chunkString").contentType = "string";
1468
+ return labelInside;
1469
+ }
1470
+ return nok(code2);
1471
+ }
1472
+ function labelInside(code2) {
1473
+ if (
1474
+ // Too long.
1475
+ size > 999 || // Closing brace with nothing.
1476
+ code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
1477
+ // `\n` and `[` not being supported makes sense.
1478
+ code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
1479
+ ) {
1480
+ return nok(code2);
1481
+ }
1482
+ if (code2 === 93) {
1483
+ effects.exit("chunkString");
1484
+ const token = effects.exit("gfmFootnoteDefinitionLabelString");
1485
+ identifier = normalizeIdentifier(self.sliceSerialize(token));
1486
+ effects.enter("gfmFootnoteDefinitionLabelMarker");
1487
+ effects.consume(code2);
1488
+ effects.exit("gfmFootnoteDefinitionLabelMarker");
1489
+ effects.exit("gfmFootnoteDefinitionLabel");
1490
+ return labelAfter;
1491
+ }
1492
+ if (!markdownLineEndingOrSpace(code2)) {
1493
+ data = true;
1494
+ }
1495
+ size++;
1496
+ effects.consume(code2);
1497
+ return code2 === 92 ? labelEscape : labelInside;
1498
+ }
1499
+ function labelEscape(code2) {
1500
+ if (code2 === 91 || code2 === 92 || code2 === 93) {
1501
+ effects.consume(code2);
1502
+ size++;
1503
+ return labelInside;
1504
+ }
1505
+ return labelInside(code2);
1506
+ }
1507
+ function labelAfter(code2) {
1508
+ if (code2 === 58) {
1509
+ effects.enter("definitionMarker");
1510
+ effects.consume(code2);
1511
+ effects.exit("definitionMarker");
1512
+ if (!defined.includes(identifier)) {
1513
+ defined.push(identifier);
1514
+ }
1515
+ return factorySpace(effects, whitespaceAfter, "gfmFootnoteDefinitionWhitespace");
1516
+ }
1517
+ return nok(code2);
1518
+ }
1519
+ function whitespaceAfter(code2) {
1520
+ return ok2(code2);
1521
+ }
1522
+ }
1523
+ function tokenizeDefinitionContinuation(effects, ok2, nok) {
1524
+ return effects.check(blankLine, ok2, effects.attempt(indent, ok2, nok));
1525
+ }
1526
+ function gfmFootnoteDefinitionEnd(effects) {
1527
+ effects.exit("gfmFootnoteDefinition");
1528
+ }
1529
+ function tokenizeIndent(effects, ok2, nok) {
1530
+ const self = this;
1531
+ return factorySpace(effects, afterPrefix, "gfmFootnoteDefinitionIndent", 4 + 1);
1532
+ function afterPrefix(code2) {
1533
+ const tail = self.events[self.events.length - 1];
1534
+ return tail && tail[1].type === "gfmFootnoteDefinitionIndent" && tail[2].sliceSerialize(tail[1], true).length === 4 ? ok2(code2) : nok(code2);
1535
+ }
1536
+ }
1537
+ function gfmStrikethrough(options) {
1538
+ const options_ = options || {};
1539
+ let single = options_.singleTilde;
1540
+ const tokenizer = {
1541
+ name: "strikethrough",
1542
+ tokenize: tokenizeStrikethrough,
1543
+ resolveAll: resolveAllStrikethrough
1544
+ };
1545
+ if (single === null || single === void 0) {
1546
+ single = true;
1547
+ }
1548
+ return {
1549
+ text: {
1550
+ [126]: tokenizer
1551
+ },
1552
+ insideSpan: {
1553
+ null: [tokenizer]
1554
+ },
1555
+ attentionMarkers: {
1556
+ null: [126]
1557
+ }
1558
+ };
1559
+ function resolveAllStrikethrough(events, context) {
1560
+ let index = -1;
1561
+ while (++index < events.length) {
1562
+ if (events[index][0] === "enter" && events[index][1].type === "strikethroughSequenceTemporary" && events[index][1]._close) {
1563
+ let open = index;
1564
+ while (open--) {
1565
+ if (events[open][0] === "exit" && events[open][1].type === "strikethroughSequenceTemporary" && events[open][1]._open && // If the sizes are the same:
1566
+ events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) {
1567
+ events[index][1].type = "strikethroughSequence";
1568
+ events[open][1].type = "strikethroughSequence";
1569
+ const strikethrough = {
1570
+ type: "strikethrough",
1571
+ start: Object.assign({}, events[open][1].start),
1572
+ end: Object.assign({}, events[index][1].end)
1573
+ };
1574
+ const text2 = {
1575
+ type: "strikethroughText",
1576
+ start: Object.assign({}, events[open][1].end),
1577
+ end: Object.assign({}, events[index][1].start)
1578
+ };
1579
+ const nextEvents = [["enter", strikethrough, context], ["enter", events[open][1], context], ["exit", events[open][1], context], ["enter", text2, context]];
1580
+ const insideSpan = context.parser.constructs.insideSpan.null;
1581
+ if (insideSpan) {
1582
+ splice(nextEvents, nextEvents.length, 0, resolveAll(insideSpan, events.slice(open + 1, index), context));
1583
+ }
1584
+ splice(nextEvents, nextEvents.length, 0, [["exit", text2, context], ["enter", events[index][1], context], ["exit", events[index][1], context], ["exit", strikethrough, context]]);
1585
+ splice(events, open - 1, index - open + 3, nextEvents);
1586
+ index = open + nextEvents.length - 2;
1587
+ break;
1588
+ }
1589
+ }
1590
+ }
1591
+ }
1592
+ index = -1;
1593
+ while (++index < events.length) {
1594
+ if (events[index][1].type === "strikethroughSequenceTemporary") {
1595
+ events[index][1].type = "data";
1596
+ }
1597
+ }
1598
+ return events;
1599
+ }
1600
+ function tokenizeStrikethrough(effects, ok2, nok) {
1601
+ const previous2 = this.previous;
1602
+ const events = this.events;
1603
+ let size = 0;
1604
+ return start;
1605
+ function start(code2) {
1606
+ if (previous2 === 126 && events[events.length - 1][1].type !== "characterEscape") {
1607
+ return nok(code2);
1608
+ }
1609
+ effects.enter("strikethroughSequenceTemporary");
1610
+ return more(code2);
1611
+ }
1612
+ function more(code2) {
1613
+ const before = classifyCharacter(previous2);
1614
+ if (code2 === 126) {
1615
+ if (size > 1) return nok(code2);
1616
+ effects.consume(code2);
1617
+ size++;
1618
+ return more;
1619
+ }
1620
+ if (size < 2 && !single) return nok(code2);
1621
+ const token = effects.exit("strikethroughSequenceTemporary");
1622
+ const after = classifyCharacter(code2);
1623
+ token._open = !after || after === 2 && Boolean(before);
1624
+ token._close = !before || before === 2 && Boolean(after);
1625
+ return ok2(code2);
1626
+ }
1627
+ }
1628
+ }
1629
+ class EditMap {
1630
+ /**
1631
+ * Create a new edit map.
1632
+ */
1633
+ constructor() {
1634
+ this.map = [];
1635
+ }
1636
+ /**
1637
+ * Create an edit: a remove and/or add at a certain place.
1638
+ *
1639
+ * @param {number} index
1640
+ * @param {number} remove
1641
+ * @param {Array<Event>} add
1642
+ * @returns {undefined}
1643
+ */
1644
+ add(index, remove, add) {
1645
+ addImplementation(this, index, remove, add);
1646
+ }
1647
+ // To do: add this when moving to `micromark`.
1648
+ // /**
1649
+ // * Create an edit: but insert `add` before existing additions.
1650
+ // *
1651
+ // * @param {number} index
1652
+ // * @param {number} remove
1653
+ // * @param {Array<Event>} add
1654
+ // * @returns {undefined}
1655
+ // */
1656
+ // addBefore(index, remove, add) {
1657
+ // addImplementation(this, index, remove, add, true)
1658
+ // }
1659
+ /**
1660
+ * Done, change the events.
1661
+ *
1662
+ * @param {Array<Event>} events
1663
+ * @returns {undefined}
1664
+ */
1665
+ consume(events) {
1666
+ this.map.sort(function(a, b) {
1667
+ return a[0] - b[0];
1668
+ });
1669
+ if (this.map.length === 0) {
1670
+ return;
1671
+ }
1672
+ let index = this.map.length;
1673
+ const vecs = [];
1674
+ while (index > 0) {
1675
+ index -= 1;
1676
+ vecs.push(events.slice(this.map[index][0] + this.map[index][1]), this.map[index][2]);
1677
+ events.length = this.map[index][0];
1678
+ }
1679
+ vecs.push(events.slice());
1680
+ events.length = 0;
1681
+ let slice = vecs.pop();
1682
+ while (slice) {
1683
+ for (const element of slice) {
1684
+ events.push(element);
1685
+ }
1686
+ slice = vecs.pop();
1687
+ }
1688
+ this.map.length = 0;
1689
+ }
1690
+ }
1691
+ function addImplementation(editMap, at, remove, add) {
1692
+ let index = 0;
1693
+ if (remove === 0 && add.length === 0) {
1694
+ return;
1695
+ }
1696
+ while (index < editMap.map.length) {
1697
+ if (editMap.map[index][0] === at) {
1698
+ editMap.map[index][1] += remove;
1699
+ editMap.map[index][2].push(...add);
1700
+ return;
1701
+ }
1702
+ index += 1;
1703
+ }
1704
+ editMap.map.push([at, remove, add]);
1705
+ }
1706
+ function gfmTableAlign(events, index) {
1707
+ let inDelimiterRow = false;
1708
+ const align = [];
1709
+ while (index < events.length) {
1710
+ const event = events[index];
1711
+ if (inDelimiterRow) {
1712
+ if (event[0] === "enter") {
1713
+ if (event[1].type === "tableContent") {
1714
+ align.push(events[index + 1][1].type === "tableDelimiterMarker" ? "left" : "none");
1715
+ }
1716
+ } else if (event[1].type === "tableContent") {
1717
+ if (events[index - 1][1].type === "tableDelimiterMarker") {
1718
+ const alignIndex = align.length - 1;
1719
+ align[alignIndex] = align[alignIndex] === "left" ? "center" : "right";
1720
+ }
1721
+ } else if (event[1].type === "tableDelimiterRow") {
1722
+ break;
1723
+ }
1724
+ } else if (event[0] === "enter" && event[1].type === "tableDelimiterRow") {
1725
+ inDelimiterRow = true;
1726
+ }
1727
+ index += 1;
1728
+ }
1729
+ return align;
1730
+ }
1731
+ function gfmTable() {
1732
+ return {
1733
+ flow: {
1734
+ null: {
1735
+ name: "table",
1736
+ tokenize: tokenizeTable,
1737
+ resolveAll: resolveTable
1738
+ }
1739
+ }
1740
+ };
1741
+ }
1742
+ function tokenizeTable(effects, ok2, nok) {
1743
+ const self = this;
1744
+ let size = 0;
1745
+ let sizeB = 0;
1746
+ let seen;
1747
+ return start;
1748
+ function start(code2) {
1749
+ let index = self.events.length - 1;
1750
+ while (index > -1) {
1751
+ const type = self.events[index][1].type;
1752
+ if (type === "lineEnding" || // Note: markdown-rs uses `whitespace` instead of `linePrefix`
1753
+ type === "linePrefix") index--;
1754
+ else break;
1755
+ }
1756
+ const tail = index > -1 ? self.events[index][1].type : null;
1757
+ const next = tail === "tableHead" || tail === "tableRow" ? bodyRowStart : headRowBefore;
1758
+ if (next === bodyRowStart && self.parser.lazy[self.now().line]) {
1759
+ return nok(code2);
1760
+ }
1761
+ return next(code2);
1762
+ }
1763
+ function headRowBefore(code2) {
1764
+ effects.enter("tableHead");
1765
+ effects.enter("tableRow");
1766
+ return headRowStart(code2);
1767
+ }
1768
+ function headRowStart(code2) {
1769
+ if (code2 === 124) {
1770
+ return headRowBreak(code2);
1771
+ }
1772
+ seen = true;
1773
+ sizeB += 1;
1774
+ return headRowBreak(code2);
1775
+ }
1776
+ function headRowBreak(code2) {
1777
+ if (code2 === null) {
1778
+ return nok(code2);
1779
+ }
1780
+ if (markdownLineEnding(code2)) {
1781
+ if (sizeB > 1) {
1782
+ sizeB = 0;
1783
+ self.interrupt = true;
1784
+ effects.exit("tableRow");
1785
+ effects.enter("lineEnding");
1786
+ effects.consume(code2);
1787
+ effects.exit("lineEnding");
1788
+ return headDelimiterStart;
1789
+ }
1790
+ return nok(code2);
1791
+ }
1792
+ if (markdownSpace(code2)) {
1793
+ return factorySpace(effects, headRowBreak, "whitespace")(code2);
1794
+ }
1795
+ sizeB += 1;
1796
+ if (seen) {
1797
+ seen = false;
1798
+ size += 1;
1799
+ }
1800
+ if (code2 === 124) {
1801
+ effects.enter("tableCellDivider");
1802
+ effects.consume(code2);
1803
+ effects.exit("tableCellDivider");
1804
+ seen = true;
1805
+ return headRowBreak;
1806
+ }
1807
+ effects.enter("data");
1808
+ return headRowData(code2);
1809
+ }
1810
+ function headRowData(code2) {
1811
+ if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
1812
+ effects.exit("data");
1813
+ return headRowBreak(code2);
1814
+ }
1815
+ effects.consume(code2);
1816
+ return code2 === 92 ? headRowEscape : headRowData;
1817
+ }
1818
+ function headRowEscape(code2) {
1819
+ if (code2 === 92 || code2 === 124) {
1820
+ effects.consume(code2);
1821
+ return headRowData;
1822
+ }
1823
+ return headRowData(code2);
1824
+ }
1825
+ function headDelimiterStart(code2) {
1826
+ self.interrupt = false;
1827
+ if (self.parser.lazy[self.now().line]) {
1828
+ return nok(code2);
1829
+ }
1830
+ effects.enter("tableDelimiterRow");
1831
+ seen = false;
1832
+ if (markdownSpace(code2)) {
1833
+ return factorySpace(effects, headDelimiterBefore, "linePrefix", self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4)(code2);
1834
+ }
1835
+ return headDelimiterBefore(code2);
1836
+ }
1837
+ function headDelimiterBefore(code2) {
1838
+ if (code2 === 45 || code2 === 58) {
1839
+ return headDelimiterValueBefore(code2);
1840
+ }
1841
+ if (code2 === 124) {
1842
+ seen = true;
1843
+ effects.enter("tableCellDivider");
1844
+ effects.consume(code2);
1845
+ effects.exit("tableCellDivider");
1846
+ return headDelimiterCellBefore;
1847
+ }
1848
+ return headDelimiterNok(code2);
1849
+ }
1850
+ function headDelimiterCellBefore(code2) {
1851
+ if (markdownSpace(code2)) {
1852
+ return factorySpace(effects, headDelimiterValueBefore, "whitespace")(code2);
1853
+ }
1854
+ return headDelimiterValueBefore(code2);
1855
+ }
1856
+ function headDelimiterValueBefore(code2) {
1857
+ if (code2 === 58) {
1858
+ sizeB += 1;
1859
+ seen = true;
1860
+ effects.enter("tableDelimiterMarker");
1861
+ effects.consume(code2);
1862
+ effects.exit("tableDelimiterMarker");
1863
+ return headDelimiterLeftAlignmentAfter;
1864
+ }
1865
+ if (code2 === 45) {
1866
+ sizeB += 1;
1867
+ return headDelimiterLeftAlignmentAfter(code2);
1868
+ }
1869
+ if (code2 === null || markdownLineEnding(code2)) {
1870
+ return headDelimiterCellAfter(code2);
1871
+ }
1872
+ return headDelimiterNok(code2);
1873
+ }
1874
+ function headDelimiterLeftAlignmentAfter(code2) {
1875
+ if (code2 === 45) {
1876
+ effects.enter("tableDelimiterFiller");
1877
+ return headDelimiterFiller(code2);
1878
+ }
1879
+ return headDelimiterNok(code2);
1880
+ }
1881
+ function headDelimiterFiller(code2) {
1882
+ if (code2 === 45) {
1883
+ effects.consume(code2);
1884
+ return headDelimiterFiller;
1885
+ }
1886
+ if (code2 === 58) {
1887
+ seen = true;
1888
+ effects.exit("tableDelimiterFiller");
1889
+ effects.enter("tableDelimiterMarker");
1890
+ effects.consume(code2);
1891
+ effects.exit("tableDelimiterMarker");
1892
+ return headDelimiterRightAlignmentAfter;
1893
+ }
1894
+ effects.exit("tableDelimiterFiller");
1895
+ return headDelimiterRightAlignmentAfter(code2);
1896
+ }
1897
+ function headDelimiterRightAlignmentAfter(code2) {
1898
+ if (markdownSpace(code2)) {
1899
+ return factorySpace(effects, headDelimiterCellAfter, "whitespace")(code2);
1900
+ }
1901
+ return headDelimiterCellAfter(code2);
1902
+ }
1903
+ function headDelimiterCellAfter(code2) {
1904
+ if (code2 === 124) {
1905
+ return headDelimiterBefore(code2);
1906
+ }
1907
+ if (code2 === null || markdownLineEnding(code2)) {
1908
+ if (!seen || size !== sizeB) {
1909
+ return headDelimiterNok(code2);
1910
+ }
1911
+ effects.exit("tableDelimiterRow");
1912
+ effects.exit("tableHead");
1913
+ return ok2(code2);
1914
+ }
1915
+ return headDelimiterNok(code2);
1916
+ }
1917
+ function headDelimiterNok(code2) {
1918
+ return nok(code2);
1919
+ }
1920
+ function bodyRowStart(code2) {
1921
+ effects.enter("tableRow");
1922
+ return bodyRowBreak(code2);
1923
+ }
1924
+ function bodyRowBreak(code2) {
1925
+ if (code2 === 124) {
1926
+ effects.enter("tableCellDivider");
1927
+ effects.consume(code2);
1928
+ effects.exit("tableCellDivider");
1929
+ return bodyRowBreak;
1930
+ }
1931
+ if (code2 === null || markdownLineEnding(code2)) {
1932
+ effects.exit("tableRow");
1933
+ return ok2(code2);
1934
+ }
1935
+ if (markdownSpace(code2)) {
1936
+ return factorySpace(effects, bodyRowBreak, "whitespace")(code2);
1937
+ }
1938
+ effects.enter("data");
1939
+ return bodyRowData(code2);
1940
+ }
1941
+ function bodyRowData(code2) {
1942
+ if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
1943
+ effects.exit("data");
1944
+ return bodyRowBreak(code2);
1945
+ }
1946
+ effects.consume(code2);
1947
+ return code2 === 92 ? bodyRowEscape : bodyRowData;
1948
+ }
1949
+ function bodyRowEscape(code2) {
1950
+ if (code2 === 92 || code2 === 124) {
1951
+ effects.consume(code2);
1952
+ return bodyRowData;
1953
+ }
1954
+ return bodyRowData(code2);
1955
+ }
1956
+ }
1957
+ function resolveTable(events, context) {
1958
+ let index = -1;
1959
+ let inFirstCellAwaitingPipe = true;
1960
+ let rowKind = 0;
1961
+ let lastCell = [0, 0, 0, 0];
1962
+ let cell = [0, 0, 0, 0];
1963
+ let afterHeadAwaitingFirstBodyRow = false;
1964
+ let lastTableEnd = 0;
1965
+ let currentTable;
1966
+ let currentBody;
1967
+ let currentCell;
1968
+ const map = new EditMap();
1969
+ while (++index < events.length) {
1970
+ const event = events[index];
1971
+ const token = event[1];
1972
+ if (event[0] === "enter") {
1973
+ if (token.type === "tableHead") {
1974
+ afterHeadAwaitingFirstBodyRow = false;
1975
+ if (lastTableEnd !== 0) {
1976
+ flushTableEnd(map, context, lastTableEnd, currentTable, currentBody);
1977
+ currentBody = void 0;
1978
+ lastTableEnd = 0;
1979
+ }
1980
+ currentTable = {
1981
+ type: "table",
1982
+ start: Object.assign({}, token.start),
1983
+ // Note: correct end is set later.
1984
+ end: Object.assign({}, token.end)
1985
+ };
1986
+ map.add(index, 0, [["enter", currentTable, context]]);
1987
+ } else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
1988
+ inFirstCellAwaitingPipe = true;
1989
+ currentCell = void 0;
1990
+ lastCell = [0, 0, 0, 0];
1991
+ cell = [0, index + 1, 0, 0];
1992
+ if (afterHeadAwaitingFirstBodyRow) {
1993
+ afterHeadAwaitingFirstBodyRow = false;
1994
+ currentBody = {
1995
+ type: "tableBody",
1996
+ start: Object.assign({}, token.start),
1997
+ // Note: correct end is set later.
1998
+ end: Object.assign({}, token.end)
1999
+ };
2000
+ map.add(index, 0, [["enter", currentBody, context]]);
2001
+ }
2002
+ rowKind = token.type === "tableDelimiterRow" ? 2 : currentBody ? 3 : 1;
2003
+ } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
2004
+ inFirstCellAwaitingPipe = false;
2005
+ if (cell[2] === 0) {
2006
+ if (lastCell[1] !== 0) {
2007
+ cell[0] = cell[1];
2008
+ currentCell = flushCell(map, context, lastCell, rowKind, void 0, currentCell);
2009
+ lastCell = [0, 0, 0, 0];
2010
+ }
2011
+ cell[2] = index;
2012
+ }
2013
+ } else if (token.type === "tableCellDivider") {
2014
+ if (inFirstCellAwaitingPipe) {
2015
+ inFirstCellAwaitingPipe = false;
2016
+ } else {
2017
+ if (lastCell[1] !== 0) {
2018
+ cell[0] = cell[1];
2019
+ currentCell = flushCell(map, context, lastCell, rowKind, void 0, currentCell);
2020
+ }
2021
+ lastCell = cell;
2022
+ cell = [lastCell[1], index, 0, 0];
2023
+ }
2024
+ }
2025
+ } else if (token.type === "tableHead") {
2026
+ afterHeadAwaitingFirstBodyRow = true;
2027
+ lastTableEnd = index;
2028
+ } else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
2029
+ lastTableEnd = index;
2030
+ if (lastCell[1] !== 0) {
2031
+ cell[0] = cell[1];
2032
+ currentCell = flushCell(map, context, lastCell, rowKind, index, currentCell);
2033
+ } else if (cell[1] !== 0) {
2034
+ currentCell = flushCell(map, context, cell, rowKind, index, currentCell);
2035
+ }
2036
+ rowKind = 0;
2037
+ } else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
2038
+ cell[3] = index;
2039
+ }
2040
+ }
2041
+ if (lastTableEnd !== 0) {
2042
+ flushTableEnd(map, context, lastTableEnd, currentTable, currentBody);
2043
+ }
2044
+ map.consume(context.events);
2045
+ index = -1;
2046
+ while (++index < context.events.length) {
2047
+ const event = context.events[index];
2048
+ if (event[0] === "enter" && event[1].type === "table") {
2049
+ event[1]._align = gfmTableAlign(context.events, index);
2050
+ }
2051
+ }
2052
+ return events;
2053
+ }
2054
+ function flushCell(map, context, range, rowKind, rowEnd, previousCell) {
2055
+ const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData";
2056
+ const valueName = "tableContent";
2057
+ if (range[0] !== 0) {
2058
+ previousCell.end = Object.assign({}, getPoint(context.events, range[0]));
2059
+ map.add(range[0], 0, [["exit", previousCell, context]]);
2060
+ }
2061
+ const now = getPoint(context.events, range[1]);
2062
+ previousCell = {
2063
+ type: groupName,
2064
+ start: Object.assign({}, now),
2065
+ // Note: correct end is set later.
2066
+ end: Object.assign({}, now)
2067
+ };
2068
+ map.add(range[1], 0, [["enter", previousCell, context]]);
2069
+ if (range[2] !== 0) {
2070
+ const relatedStart = getPoint(context.events, range[2]);
2071
+ const relatedEnd = getPoint(context.events, range[3]);
2072
+ const valueToken = {
2073
+ type: valueName,
2074
+ start: Object.assign({}, relatedStart),
2075
+ end: Object.assign({}, relatedEnd)
2076
+ };
2077
+ map.add(range[2], 0, [["enter", valueToken, context]]);
2078
+ if (rowKind !== 2) {
2079
+ const start = context.events[range[2]];
2080
+ const end = context.events[range[3]];
2081
+ start[1].end = Object.assign({}, end[1].end);
2082
+ start[1].type = "chunkText";
2083
+ start[1].contentType = "text";
2084
+ if (range[3] > range[2] + 1) {
2085
+ const a = range[2] + 1;
2086
+ const b = range[3] - range[2] - 1;
2087
+ map.add(a, b, []);
2088
+ }
2089
+ }
2090
+ map.add(range[3] + 1, 0, [["exit", valueToken, context]]);
2091
+ }
2092
+ if (rowEnd !== void 0) {
2093
+ previousCell.end = Object.assign({}, getPoint(context.events, rowEnd));
2094
+ map.add(rowEnd, 0, [["exit", previousCell, context]]);
2095
+ previousCell = void 0;
2096
+ }
2097
+ return previousCell;
2098
+ }
2099
+ function flushTableEnd(map, context, index, table, tableBody) {
2100
+ const exits = [];
2101
+ const related = getPoint(context.events, index);
2102
+ if (tableBody) {
2103
+ tableBody.end = Object.assign({}, related);
2104
+ exits.push(["exit", tableBody, context]);
2105
+ }
2106
+ table.end = Object.assign({}, related);
2107
+ exits.push(["exit", table, context]);
2108
+ map.add(index + 1, 0, exits);
2109
+ }
2110
+ function getPoint(events, index) {
2111
+ const event = events[index];
2112
+ const side = event[0] === "enter" ? "start" : "end";
2113
+ return event[1][side];
2114
+ }
2115
+ const tasklistCheck = {
2116
+ name: "tasklistCheck",
2117
+ tokenize: tokenizeTasklistCheck
2118
+ };
2119
+ function gfmTaskListItem() {
2120
+ return {
2121
+ text: {
2122
+ [91]: tasklistCheck
2123
+ }
2124
+ };
2125
+ }
2126
+ function tokenizeTasklistCheck(effects, ok2, nok) {
2127
+ const self = this;
2128
+ return open;
2129
+ function open(code2) {
2130
+ if (
2131
+ // Exit if there’s stuff before.
2132
+ self.previous !== null || // Exit if not in the first content that is the first child of a list
2133
+ // item.
2134
+ !self._gfmTasklistFirstContentOfListItem
2135
+ ) {
2136
+ return nok(code2);
2137
+ }
2138
+ effects.enter("taskListCheck");
2139
+ effects.enter("taskListCheckMarker");
2140
+ effects.consume(code2);
2141
+ effects.exit("taskListCheckMarker");
2142
+ return inside;
2143
+ }
2144
+ function inside(code2) {
2145
+ if (markdownLineEndingOrSpace(code2)) {
2146
+ effects.enter("taskListCheckValueUnchecked");
2147
+ effects.consume(code2);
2148
+ effects.exit("taskListCheckValueUnchecked");
2149
+ return close;
2150
+ }
2151
+ if (code2 === 88 || code2 === 120) {
2152
+ effects.enter("taskListCheckValueChecked");
2153
+ effects.consume(code2);
2154
+ effects.exit("taskListCheckValueChecked");
2155
+ return close;
2156
+ }
2157
+ return nok(code2);
2158
+ }
2159
+ function close(code2) {
2160
+ if (code2 === 93) {
2161
+ effects.enter("taskListCheckMarker");
2162
+ effects.consume(code2);
2163
+ effects.exit("taskListCheckMarker");
2164
+ effects.exit("taskListCheck");
2165
+ return after;
2166
+ }
2167
+ return nok(code2);
2168
+ }
2169
+ function after(code2) {
2170
+ if (markdownLineEnding(code2)) {
2171
+ return ok2(code2);
2172
+ }
2173
+ if (markdownSpace(code2)) {
2174
+ return effects.check({
2175
+ tokenize: spaceThenNonSpace
2176
+ }, ok2, nok)(code2);
2177
+ }
2178
+ return nok(code2);
2179
+ }
2180
+ }
2181
+ function spaceThenNonSpace(effects, ok2, nok) {
2182
+ return factorySpace(effects, after, "whitespace");
2183
+ function after(code2) {
2184
+ return code2 === null ? nok(code2) : ok2(code2);
2185
+ }
2186
+ }
2187
+ function gfm(options) {
2188
+ return combineExtensions([
2189
+ gfmAutolinkLiteral(),
2190
+ gfmFootnote(),
2191
+ gfmStrikethrough(options),
2192
+ gfmTable(),
2193
+ gfmTaskListItem()
2194
+ ]);
2195
+ }
2196
+ const emptyOptions = {};
2197
+ function remarkGfm(options) {
2198
+ const self = (
2199
+ /** @type {Processor<Root>} */
2200
+ this
2201
+ );
2202
+ const settings = options || emptyOptions;
2203
+ const data = self.data();
2204
+ const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
2205
+ const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
2206
+ const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
2207
+ micromarkExtensions.push(gfm(settings));
2208
+ fromMarkdownExtensions.push(gfmFromMarkdown());
2209
+ toMarkdownExtensions.push(gfmToMarkdown(settings));
2210
+ }
2211
+ export {
2212
+ remarkGfm as default
2213
+ };