markdecl 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +45 -0
  2. package/README.md +11 -0
  3. package/dist/index.d.ts +95 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3368 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/src/ast/base.d.ts +7 -0
  8. package/dist/src/ast/base.d.ts.map +1 -0
  9. package/dist/src/ast/function.d.ts +9 -0
  10. package/dist/src/ast/function.d.ts.map +1 -0
  11. package/dist/src/ast/index.d.ts +18 -0
  12. package/dist/src/ast/index.d.ts.map +1 -0
  13. package/dist/src/ast/node.d.ts +23 -0
  14. package/dist/src/ast/node.d.ts.map +1 -0
  15. package/dist/src/ast/variable.d.ts +8 -0
  16. package/dist/src/ast/variable.d.ts.map +1 -0
  17. package/dist/src/formatter.d.ts +11 -0
  18. package/dist/src/formatter.d.ts.map +1 -0
  19. package/dist/src/functions/index.d.ts +11 -0
  20. package/dist/src/functions/index.d.ts.map +1 -0
  21. package/dist/src/parser.d.ts +4 -0
  22. package/dist/src/parser.d.ts.map +1 -0
  23. package/dist/src/renderers/html.d.ts +3 -0
  24. package/dist/src/renderers/html.d.ts.map +1 -0
  25. package/dist/src/renderers/index.d.ts +6 -0
  26. package/dist/src/renderers/index.d.ts.map +1 -0
  27. package/dist/src/schema-types/conditional.d.ts +13 -0
  28. package/dist/src/schema-types/conditional.d.ts.map +1 -0
  29. package/dist/src/schema.d.ts +36 -0
  30. package/dist/src/schema.d.ts.map +1 -0
  31. package/dist/src/tag.d.ts +10 -0
  32. package/dist/src/tag.d.ts.map +1 -0
  33. package/dist/src/tags/conditional.d.ts +5 -0
  34. package/dist/src/tags/conditional.d.ts.map +1 -0
  35. package/dist/src/tags/index.d.ts +9 -0
  36. package/dist/src/tags/index.d.ts.map +1 -0
  37. package/dist/src/tags/partial.d.ts +3 -0
  38. package/dist/src/tags/partial.d.ts.map +1 -0
  39. package/dist/src/tags/slot.d.ts +3 -0
  40. package/dist/src/tags/slot.d.ts.map +1 -0
  41. package/dist/src/tags/table.d.ts +3 -0
  42. package/dist/src/tags/table.d.ts.map +1 -0
  43. package/dist/src/tokenizer/index.d.ts +11 -0
  44. package/dist/src/tokenizer/index.d.ts.map +1 -0
  45. package/dist/src/tokenizer/plugins/annotations.d.ts +3 -0
  46. package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -0
  47. package/dist/src/tokenizer/plugins/comments.d.ts +3 -0
  48. package/dist/src/tokenizer/plugins/comments.d.ts.map +1 -0
  49. package/dist/src/tokenizer/plugins/frontmatter.d.ts +3 -0
  50. package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -0
  51. package/dist/src/transformer.d.ts +4 -0
  52. package/dist/src/transformer.d.ts.map +1 -0
  53. package/dist/src/transforms/index.d.ts +4 -0
  54. package/dist/src/transforms/index.d.ts.map +1 -0
  55. package/dist/src/transforms/table.d.ts +3 -0
  56. package/dist/src/transforms/table.d.ts.map +1 -0
  57. package/dist/src/types.d.ts +134 -0
  58. package/dist/src/types.d.ts.map +1 -0
  59. package/dist/src/utils.d.ts +9 -0
  60. package/dist/src/utils.d.ts.map +1 -0
  61. package/dist/src/validator.d.ts +28 -0
  62. package/dist/src/validator.d.ts.map +1 -0
  63. package/package.json +62 -0
package/dist/index.js ADDED
@@ -0,0 +1,3368 @@
1
+ import MarkdownIt from "markdown-it";
2
+ import MarkdownIt$1 from "markdown-it/lib/index.mjs";
3
+ function isAst(value) {
4
+ return !!value?.$$mdtype;
5
+ }
6
+ function isFunction(value) {
7
+ return !!(value?.$$mdtype === "Function");
8
+ }
9
+ function isVariable(value) {
10
+ return !!(value?.$$mdtype === "Variable");
11
+ }
12
+ function* getAstValues(value) {
13
+ if (value == null || typeof value !== "object") return;
14
+ if (Array.isArray(value)) for (const v of value) yield* getAstValues(v);
15
+ if (isAst(value)) yield value;
16
+ if (Object.getPrototypeOf(value) !== Object.prototype) return;
17
+ for (const v of Object.values(value)) yield* getAstValues(v);
18
+ }
19
+ function resolve$1(value, config = {}) {
20
+ if (value == null || typeof value !== "object") return value;
21
+ if (Array.isArray(value)) return value.map((item2) => resolve$1(item2, config));
22
+ if (isAst(value) && value?.resolve instanceof Function) return value.resolve(config);
23
+ if (Object.getPrototypeOf(value) !== Object.prototype) return value;
24
+ const output = {};
25
+ for (const [k, v] of Object.entries(value)) output[k] = resolve$1(v, config);
26
+ return output;
27
+ }
28
+ const base = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
29
+ __proto__: null,
30
+ getAstValues,
31
+ isAst,
32
+ isFunction,
33
+ isVariable,
34
+ resolve: resolve$1
35
+ }, Symbol.toStringTag, { value: "Module" }));
36
+ const _Tag = class _Tag {
37
+ constructor(name = "div", attributes = {}, children = []) {
38
+ this.$$mdtype = "Tag";
39
+ this.name = name;
40
+ this.attributes = attributes;
41
+ this.children = children;
42
+ }
43
+ };
44
+ _Tag.isTag = (tag) => {
45
+ return !!(tag?.$$mdtype === "Tag");
46
+ };
47
+ let Tag = _Tag;
48
+ class peg$SyntaxError extends SyntaxError {
49
+ constructor(message, expected, found, location) {
50
+ super(message);
51
+ this.expected = expected;
52
+ this.found = found;
53
+ this.location = location;
54
+ this.name = "SyntaxError";
55
+ }
56
+ format(sources) {
57
+ let str = "Error: " + this.message;
58
+ if (this.location) {
59
+ let src = null;
60
+ const st = sources.find((s3) => s3.source === this.location.source);
61
+ if (st) {
62
+ src = st.text.split(/\r\n|\n|\r/g);
63
+ }
64
+ const s2 = this.location.start;
65
+ const offset_s = this.location.source && typeof this.location.source.offset === "function" ? this.location.source.offset(s2) : s2;
66
+ const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
67
+ if (src) {
68
+ const e = this.location.end;
69
+ const filler = "".padEnd(offset_s.line.toString().length, " ");
70
+ const line = src[s2.line - 1];
71
+ const last = s2.line === e.line ? e.column : line.length + 1;
72
+ const hatLen = last - s2.column || 1;
73
+ str += "\n --> " + loc + "\n" + filler + " |\n" + offset_s.line + " | " + line + "\n" + filler + " | " + "".padEnd(s2.column - 1, " ") + "".padEnd(hatLen, "^");
74
+ } else {
75
+ str += "\n at " + loc;
76
+ }
77
+ }
78
+ return str;
79
+ }
80
+ static buildMessage(expected, found) {
81
+ function hex(ch) {
82
+ return ch.codePointAt(0).toString(16).toUpperCase();
83
+ }
84
+ const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode") ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu") : null;
85
+ function unicodeEscape(s2) {
86
+ if (nonPrintable) {
87
+ return s2.replace(nonPrintable, (ch) => "\\u{" + hex(ch) + "}");
88
+ }
89
+ return s2;
90
+ }
91
+ function literalEscape(s2) {
92
+ return unicodeEscape(
93
+ s2.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch))
94
+ );
95
+ }
96
+ function classEscape(s2) {
97
+ return unicodeEscape(
98
+ s2.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch))
99
+ );
100
+ }
101
+ const DESCRIBE_EXPECTATION_FNS = {
102
+ literal(expectation) {
103
+ return '"' + literalEscape(expectation.text) + '"';
104
+ },
105
+ class(expectation) {
106
+ const escapedParts = expectation.parts.map(
107
+ (part) => Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part)
108
+ );
109
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
110
+ },
111
+ any() {
112
+ return "any character";
113
+ },
114
+ end() {
115
+ return "end of input";
116
+ },
117
+ other(expectation) {
118
+ return expectation.description;
119
+ }
120
+ };
121
+ function describeExpectation(expectation) {
122
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
123
+ }
124
+ function describeExpected(expected2) {
125
+ const descriptions = expected2.map(describeExpectation);
126
+ descriptions.sort();
127
+ if (descriptions.length > 0) {
128
+ let j = 1;
129
+ for (let i = 1; i < descriptions.length; i++) {
130
+ if (descriptions[i - 1] !== descriptions[i]) {
131
+ descriptions[j] = descriptions[i];
132
+ j++;
133
+ }
134
+ }
135
+ descriptions.length = j;
136
+ }
137
+ switch (descriptions.length) {
138
+ case 1:
139
+ return descriptions[0];
140
+ case 2:
141
+ return descriptions[0] + " or " + descriptions[1];
142
+ default:
143
+ return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
144
+ }
145
+ }
146
+ function describeFound(found2) {
147
+ return found2 ? '"' + literalEscape(found2) + '"' : "end of input";
148
+ }
149
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
150
+ }
151
+ }
152
+ function peg$parse(input, options) {
153
+ options = options !== void 0 ? options : {};
154
+ const peg$FAILED = {};
155
+ const peg$source = options.grammarSource;
156
+ const peg$startRuleFunctions = {
157
+ Top: peg$parseTop
158
+ };
159
+ let peg$startRuleFunction = peg$parseTop;
160
+ const peg$c0 = "/";
161
+ const peg$c1 = "=";
162
+ const peg$c2 = "(";
163
+ const peg$c3 = ")";
164
+ const peg$c4 = ",";
165
+ const peg$c5 = ".";
166
+ const peg$c6 = "[";
167
+ const peg$c7 = "]";
168
+ const peg$c8 = "null";
169
+ const peg$c9 = "true";
170
+ const peg$c10 = "false";
171
+ const peg$c11 = "{";
172
+ const peg$c12 = "}";
173
+ const peg$c13 = ":";
174
+ const peg$c15 = '"';
175
+ const peg$c16 = "\\";
176
+ const peg$c17 = "n";
177
+ const peg$c18 = "r";
178
+ const peg$c19 = "t";
179
+ const peg$r0 = /^[$@]/;
180
+ const peg$r1 = /^[0-9]/;
181
+ const peg$r2 = /^[^\0-\x1F"\\]/;
182
+ const peg$r3 = /^["\\]/;
183
+ const peg$r4 = /^[a-zA-Z0-9_\-]/;
184
+ const peg$r5 = /^[ \n\t]/;
185
+ const peg$e0 = peg$literalExpectation("/", false);
186
+ const peg$e1 = peg$otherExpectation("tag name");
187
+ const peg$e2 = peg$literalExpectation("=", false);
188
+ const peg$e3 = peg$literalExpectation("(", false);
189
+ const peg$e4 = peg$literalExpectation(")", false);
190
+ const peg$e5 = peg$literalExpectation(",", false);
191
+ const peg$e6 = peg$otherExpectation("variable");
192
+ const peg$e7 = peg$classExpectation(["$", "@"], false, false, false);
193
+ const peg$e8 = peg$literalExpectation(".", false);
194
+ const peg$e9 = peg$literalExpectation("[", false);
195
+ const peg$e10 = peg$literalExpectation("]", false);
196
+ const peg$e11 = peg$otherExpectation("null");
197
+ const peg$e12 = peg$literalExpectation("null", false);
198
+ const peg$e13 = peg$otherExpectation("boolean");
199
+ const peg$e14 = peg$literalExpectation("true", false);
200
+ const peg$e15 = peg$literalExpectation("false", false);
201
+ const peg$e16 = peg$literalExpectation("{", false);
202
+ const peg$e17 = peg$literalExpectation("}", false);
203
+ const peg$e18 = peg$literalExpectation(":", false);
204
+ const peg$e19 = peg$otherExpectation("number");
205
+ const peg$e20 = peg$literalExpectation("-", false);
206
+ const peg$e21 = peg$classExpectation([["0", "9"]], false, false, false);
207
+ const peg$e22 = peg$otherExpectation("string");
208
+ const peg$e23 = peg$literalExpectation('"', false);
209
+ const peg$e24 = peg$classExpectation([["\0", ""], '"', "\\"], true, false, false);
210
+ const peg$e25 = peg$literalExpectation("\\", false);
211
+ const peg$e26 = peg$classExpectation(['"', "\\"], false, false, false);
212
+ const peg$e27 = peg$literalExpectation("n", false);
213
+ const peg$e28 = peg$literalExpectation("r", false);
214
+ const peg$e29 = peg$literalExpectation("t", false);
215
+ const peg$e30 = peg$otherExpectation("identifier");
216
+ const peg$e31 = peg$classExpectation(
217
+ [["a", "z"], ["A", "Z"], ["0", "9"], "_", "-"],
218
+ false,
219
+ false,
220
+ false
221
+ );
222
+ const peg$e32 = peg$otherExpectation("whitespace");
223
+ const peg$e33 = peg$classExpectation([" ", "\n", " "], false, false, false);
224
+ function peg$f0(variable) {
225
+ return { type: "variable", meta: { variable } };
226
+ }
227
+ function peg$f1(attributes) {
228
+ return { type: "annotation", meta: { attributes } };
229
+ }
230
+ function peg$f2(tag, value) {
231
+ return value;
232
+ }
233
+ function peg$f3(tag, primary, attributes, close) {
234
+ if (primary) {
235
+ attributes = attributes || [];
236
+ attributes.unshift({ type: "attribute", name: "primary", value: primary });
237
+ }
238
+ const [type, nesting] = close ? ["tag", 0] : ["tag_open", 1];
239
+ return { type, nesting, meta: { tag, attributes } };
240
+ }
241
+ function peg$f4(tag) {
242
+ return { type: "tag_close", nesting: -1, meta: { tag } };
243
+ }
244
+ function peg$f5(head, tail) {
245
+ return !head ? [] : [head, ...tail];
246
+ }
247
+ function peg$f6(item2) {
248
+ return item2;
249
+ }
250
+ function peg$f7(attribute) {
251
+ return attribute;
252
+ }
253
+ function peg$f8(name, value) {
254
+ return { type: "attribute", name, value };
255
+ }
256
+ function peg$f9(name, head, tail) {
257
+ return head ? [head, ...tail] : [];
258
+ }
259
+ function peg$f10(name, params) {
260
+ let parameters = {};
261
+ for (let [index, { name: name2, value }] of params.entries()) parameters[name2 || index] = value;
262
+ return new Function3(name, parameters);
263
+ }
264
+ function peg$f11(name) {
265
+ return name;
266
+ }
267
+ function peg$f12(name, value) {
268
+ return { name, value };
269
+ }
270
+ function peg$f13(value) {
271
+ return value;
272
+ }
273
+ function peg$f14(prefix, head, tail) {
274
+ if (prefix === "@") return [head, ...tail];
275
+ return new Variable2([head, ...tail]);
276
+ }
277
+ function peg$f15(name) {
278
+ return name;
279
+ }
280
+ function peg$f16(value) {
281
+ return value;
282
+ }
283
+ function peg$f17() {
284
+ return null;
285
+ }
286
+ function peg$f18() {
287
+ return true;
288
+ }
289
+ function peg$f19() {
290
+ return false;
291
+ }
292
+ function peg$f20(head, tail) {
293
+ return [head, ...tail];
294
+ }
295
+ function peg$f21(value) {
296
+ return value || [];
297
+ }
298
+ function peg$f22(value) {
299
+ return value;
300
+ }
301
+ function peg$f23(head, tail) {
302
+ return Object.assign(head, ...tail);
303
+ }
304
+ function peg$f24(value) {
305
+ return value || {};
306
+ }
307
+ function peg$f25(item2) {
308
+ return item2;
309
+ }
310
+ function peg$f26(key, value) {
311
+ return key === "$$mdtype" ? {} : { [key]: value };
312
+ }
313
+ function peg$f27() {
314
+ return parseFloat(text2());
315
+ }
316
+ function peg$f28(value) {
317
+ return value.join("");
318
+ }
319
+ function peg$f29() {
320
+ return "\n";
321
+ }
322
+ function peg$f30() {
323
+ return "\r";
324
+ }
325
+ function peg$f31() {
326
+ return " ";
327
+ }
328
+ function peg$f32(sequence) {
329
+ return sequence;
330
+ }
331
+ let peg$currPos = options.peg$currPos | 0;
332
+ let peg$savedPos = peg$currPos;
333
+ const peg$posDetailsCache = [{ line: 1, column: 1 }];
334
+ let peg$maxFailPos = peg$currPos;
335
+ let peg$maxFailExpected = options.peg$maxFailExpected || [];
336
+ let peg$silentFails = options.peg$silentFails | 0;
337
+ let peg$result;
338
+ if (options.startRule) {
339
+ if (!(options.startRule in peg$startRuleFunctions)) {
340
+ throw new Error(`Can't start parsing from rule "` + options.startRule + '".');
341
+ }
342
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
343
+ }
344
+ function text2() {
345
+ return input.substring(peg$savedPos, peg$currPos);
346
+ }
347
+ function peg$getUnicode(pos = peg$currPos) {
348
+ const cp = input.codePointAt(pos);
349
+ if (cp === void 0) {
350
+ return "";
351
+ }
352
+ return String.fromCodePoint(cp);
353
+ }
354
+ function peg$literalExpectation(text3, ignoreCase) {
355
+ return { type: "literal", text: text3, ignoreCase };
356
+ }
357
+ function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
358
+ return { type: "class", parts, inverted, ignoreCase, unicode };
359
+ }
360
+ function peg$endExpectation() {
361
+ return { type: "end" };
362
+ }
363
+ function peg$otherExpectation(description) {
364
+ return { type: "other", description };
365
+ }
366
+ function peg$computePosDetails(pos) {
367
+ let details = peg$posDetailsCache[pos];
368
+ let p;
369
+ if (details) {
370
+ return details;
371
+ } else {
372
+ if (pos >= peg$posDetailsCache.length) {
373
+ p = peg$posDetailsCache.length - 1;
374
+ } else {
375
+ p = pos;
376
+ while (!peg$posDetailsCache[--p]) {
377
+ }
378
+ }
379
+ details = peg$posDetailsCache[p];
380
+ details = {
381
+ line: details.line,
382
+ column: details.column
383
+ };
384
+ while (p < pos) {
385
+ if (input.charCodeAt(p) === 10) {
386
+ details.line++;
387
+ details.column = 1;
388
+ } else {
389
+ details.column++;
390
+ }
391
+ p++;
392
+ }
393
+ peg$posDetailsCache[pos] = details;
394
+ return details;
395
+ }
396
+ }
397
+ function peg$computeLocation(startPos, endPos, offset) {
398
+ const startPosDetails = peg$computePosDetails(startPos);
399
+ const endPosDetails = peg$computePosDetails(endPos);
400
+ const res = {
401
+ source: peg$source,
402
+ start: {
403
+ offset: startPos,
404
+ line: startPosDetails.line,
405
+ column: startPosDetails.column
406
+ },
407
+ end: {
408
+ offset: endPos,
409
+ line: endPosDetails.line,
410
+ column: endPosDetails.column
411
+ }
412
+ };
413
+ return res;
414
+ }
415
+ function peg$fail(expected) {
416
+ if (peg$currPos < peg$maxFailPos) {
417
+ return;
418
+ }
419
+ if (peg$currPos > peg$maxFailPos) {
420
+ peg$maxFailPos = peg$currPos;
421
+ peg$maxFailExpected = [];
422
+ }
423
+ peg$maxFailExpected.push(expected);
424
+ }
425
+ function peg$buildStructuredError(expected, found, location) {
426
+ return new peg$SyntaxError(
427
+ peg$SyntaxError.buildMessage(expected, found),
428
+ expected,
429
+ found,
430
+ location
431
+ );
432
+ }
433
+ function peg$parseTop() {
434
+ let s0;
435
+ s0 = peg$parseTopLevelValue();
436
+ if (s0 === peg$FAILED) {
437
+ s0 = peg$parseAnnotation();
438
+ if (s0 === peg$FAILED) {
439
+ s0 = peg$parseTagOpen();
440
+ if (s0 === peg$FAILED) {
441
+ s0 = peg$parseTagClose();
442
+ }
443
+ }
444
+ }
445
+ return s0;
446
+ }
447
+ function peg$parseTopLevelValue() {
448
+ let s0, s1;
449
+ s0 = peg$currPos;
450
+ s1 = peg$parseVariable();
451
+ if (s1 === peg$FAILED) {
452
+ s1 = peg$parseFunction();
453
+ }
454
+ if (s1 !== peg$FAILED) {
455
+ peg$savedPos = s0;
456
+ s1 = peg$f0(s1);
457
+ }
458
+ s0 = s1;
459
+ return s0;
460
+ }
461
+ function peg$parseAnnotation() {
462
+ let s0, s1, s2, s3;
463
+ s0 = peg$currPos;
464
+ s1 = peg$parseTagAttributes();
465
+ if (s1 !== peg$FAILED) {
466
+ s2 = [];
467
+ s3 = peg$parse_();
468
+ while (s3 !== peg$FAILED) {
469
+ s2.push(s3);
470
+ s3 = peg$parse_();
471
+ }
472
+ peg$savedPos = s0;
473
+ s0 = peg$f1(s1);
474
+ } else {
475
+ peg$currPos = s0;
476
+ s0 = peg$FAILED;
477
+ }
478
+ return s0;
479
+ }
480
+ function peg$parseTagOpen() {
481
+ let s0, s1, s2, s3, s4, s5, s6;
482
+ s0 = peg$currPos;
483
+ s1 = peg$parseTagName();
484
+ if (s1 !== peg$FAILED) {
485
+ s2 = [];
486
+ s3 = peg$parse_();
487
+ while (s3 !== peg$FAILED) {
488
+ s2.push(s3);
489
+ s3 = peg$parse_();
490
+ }
491
+ s3 = peg$currPos;
492
+ s4 = peg$parseValue();
493
+ if (s4 !== peg$FAILED) {
494
+ s5 = peg$parse_();
495
+ if (s5 === peg$FAILED) {
496
+ s5 = null;
497
+ }
498
+ peg$savedPos = s3;
499
+ s3 = peg$f2(s1, s4);
500
+ } else {
501
+ peg$currPos = s3;
502
+ s3 = peg$FAILED;
503
+ }
504
+ if (s3 === peg$FAILED) {
505
+ s3 = null;
506
+ }
507
+ s4 = peg$parseTagAttributes();
508
+ if (s4 === peg$FAILED) {
509
+ s4 = null;
510
+ }
511
+ s5 = [];
512
+ s6 = peg$parse_();
513
+ while (s6 !== peg$FAILED) {
514
+ s5.push(s6);
515
+ s6 = peg$parse_();
516
+ }
517
+ if (input.charCodeAt(peg$currPos) === 47) {
518
+ s6 = peg$c0;
519
+ peg$currPos++;
520
+ } else {
521
+ s6 = peg$FAILED;
522
+ if (peg$silentFails === 0) {
523
+ peg$fail(peg$e0);
524
+ }
525
+ }
526
+ if (s6 === peg$FAILED) {
527
+ s6 = null;
528
+ }
529
+ peg$savedPos = s0;
530
+ s0 = peg$f3(s1, s3, s4, s6);
531
+ } else {
532
+ peg$currPos = s0;
533
+ s0 = peg$FAILED;
534
+ }
535
+ return s0;
536
+ }
537
+ function peg$parseTagClose() {
538
+ let s0, s1, s2;
539
+ s0 = peg$currPos;
540
+ if (input.charCodeAt(peg$currPos) === 47) {
541
+ s1 = peg$c0;
542
+ peg$currPos++;
543
+ } else {
544
+ s1 = peg$FAILED;
545
+ if (peg$silentFails === 0) {
546
+ peg$fail(peg$e0);
547
+ }
548
+ }
549
+ if (s1 !== peg$FAILED) {
550
+ s2 = peg$parseTagName();
551
+ if (s2 !== peg$FAILED) {
552
+ peg$savedPos = s0;
553
+ s0 = peg$f4(s2);
554
+ } else {
555
+ peg$currPos = s0;
556
+ s0 = peg$FAILED;
557
+ }
558
+ } else {
559
+ peg$currPos = s0;
560
+ s0 = peg$FAILED;
561
+ }
562
+ return s0;
563
+ }
564
+ function peg$parseTagName() {
565
+ let s0;
566
+ peg$silentFails++;
567
+ s0 = peg$parseIdentifier();
568
+ peg$silentFails--;
569
+ if (s0 === peg$FAILED) {
570
+ if (peg$silentFails === 0) {
571
+ peg$fail(peg$e1);
572
+ }
573
+ }
574
+ return s0;
575
+ }
576
+ function peg$parseTagAttributes() {
577
+ let s0, s1, s2, s3;
578
+ s0 = peg$currPos;
579
+ s1 = peg$parseTagAttributesItem();
580
+ if (s1 !== peg$FAILED) {
581
+ s2 = [];
582
+ s3 = peg$parseTagAttributesTail();
583
+ while (s3 !== peg$FAILED) {
584
+ s2.push(s3);
585
+ s3 = peg$parseTagAttributesTail();
586
+ }
587
+ peg$savedPos = s0;
588
+ s0 = peg$f5(s1, s2);
589
+ } else {
590
+ peg$currPos = s0;
591
+ s0 = peg$FAILED;
592
+ }
593
+ return s0;
594
+ }
595
+ function peg$parseTagAttributesTail() {
596
+ let s0, s1, s2;
597
+ s0 = peg$currPos;
598
+ s1 = [];
599
+ s2 = peg$parse_();
600
+ if (s2 !== peg$FAILED) {
601
+ while (s2 !== peg$FAILED) {
602
+ s1.push(s2);
603
+ s2 = peg$parse_();
604
+ }
605
+ } else {
606
+ s1 = peg$FAILED;
607
+ }
608
+ if (s1 !== peg$FAILED) {
609
+ s2 = peg$parseTagAttributesItem();
610
+ if (s2 !== peg$FAILED) {
611
+ peg$savedPos = s0;
612
+ s0 = peg$f6(s2);
613
+ } else {
614
+ peg$currPos = s0;
615
+ s0 = peg$FAILED;
616
+ }
617
+ } else {
618
+ peg$currPos = s0;
619
+ s0 = peg$FAILED;
620
+ }
621
+ return s0;
622
+ }
623
+ function peg$parseTagAttributesItem() {
624
+ let s0, s1;
625
+ s0 = peg$currPos;
626
+ s1 = peg$parseTagAttribute();
627
+ if (s1 !== peg$FAILED) {
628
+ peg$savedPos = s0;
629
+ s1 = peg$f7(s1);
630
+ }
631
+ s0 = s1;
632
+ return s0;
633
+ }
634
+ function peg$parseTagAttribute() {
635
+ let s0, s1, s2, s3;
636
+ s0 = peg$currPos;
637
+ s1 = peg$parseIdentifier();
638
+ if (s1 !== peg$FAILED) {
639
+ if (input.charCodeAt(peg$currPos) === 61) {
640
+ s2 = peg$c1;
641
+ peg$currPos++;
642
+ } else {
643
+ s2 = peg$FAILED;
644
+ if (peg$silentFails === 0) {
645
+ peg$fail(peg$e2);
646
+ }
647
+ }
648
+ if (s2 !== peg$FAILED) {
649
+ s3 = peg$parseValue();
650
+ if (s3 !== peg$FAILED) {
651
+ peg$savedPos = s0;
652
+ s0 = peg$f8(s1, s3);
653
+ } else {
654
+ peg$currPos = s0;
655
+ s0 = peg$FAILED;
656
+ }
657
+ } else {
658
+ peg$currPos = s0;
659
+ s0 = peg$FAILED;
660
+ }
661
+ } else {
662
+ peg$currPos = s0;
663
+ s0 = peg$FAILED;
664
+ }
665
+ return s0;
666
+ }
667
+ function peg$parseFunction() {
668
+ let s0, s1, s2, s3, s4, s5, s6, s7;
669
+ s0 = peg$currPos;
670
+ s1 = peg$parseIdentifier();
671
+ if (s1 !== peg$FAILED) {
672
+ if (input.charCodeAt(peg$currPos) === 40) {
673
+ s2 = peg$c2;
674
+ peg$currPos++;
675
+ } else {
676
+ s2 = peg$FAILED;
677
+ if (peg$silentFails === 0) {
678
+ peg$fail(peg$e3);
679
+ }
680
+ }
681
+ if (s2 !== peg$FAILED) {
682
+ s3 = [];
683
+ s4 = peg$parse_();
684
+ while (s4 !== peg$FAILED) {
685
+ s3.push(s4);
686
+ s4 = peg$parse_();
687
+ }
688
+ s4 = peg$currPos;
689
+ s5 = peg$parseFunctionParameter();
690
+ if (s5 === peg$FAILED) {
691
+ s5 = null;
692
+ }
693
+ s6 = [];
694
+ s7 = peg$parseFunctionParameterTail();
695
+ while (s7 !== peg$FAILED) {
696
+ s6.push(s7);
697
+ s7 = peg$parseFunctionParameterTail();
698
+ }
699
+ peg$savedPos = s4;
700
+ s4 = peg$f9(s1, s5, s6);
701
+ if (input.charCodeAt(peg$currPos) === 41) {
702
+ s5 = peg$c3;
703
+ peg$currPos++;
704
+ } else {
705
+ s5 = peg$FAILED;
706
+ if (peg$silentFails === 0) {
707
+ peg$fail(peg$e4);
708
+ }
709
+ }
710
+ if (s5 !== peg$FAILED) {
711
+ peg$savedPos = s0;
712
+ s0 = peg$f10(s1, s4);
713
+ } else {
714
+ peg$currPos = s0;
715
+ s0 = peg$FAILED;
716
+ }
717
+ } else {
718
+ peg$currPos = s0;
719
+ s0 = peg$FAILED;
720
+ }
721
+ } else {
722
+ peg$currPos = s0;
723
+ s0 = peg$FAILED;
724
+ }
725
+ return s0;
726
+ }
727
+ function peg$parseFunctionParameter() {
728
+ let s0, s1, s2, s3;
729
+ s0 = peg$currPos;
730
+ s1 = peg$currPos;
731
+ s2 = peg$parseIdentifier();
732
+ if (s2 !== peg$FAILED) {
733
+ if (input.charCodeAt(peg$currPos) === 61) {
734
+ s3 = peg$c1;
735
+ peg$currPos++;
736
+ } else {
737
+ s3 = peg$FAILED;
738
+ if (peg$silentFails === 0) {
739
+ peg$fail(peg$e2);
740
+ }
741
+ }
742
+ if (s3 !== peg$FAILED) {
743
+ peg$savedPos = s1;
744
+ s1 = peg$f11(s2);
745
+ } else {
746
+ peg$currPos = s1;
747
+ s1 = peg$FAILED;
748
+ }
749
+ } else {
750
+ peg$currPos = s1;
751
+ s1 = peg$FAILED;
752
+ }
753
+ if (s1 === peg$FAILED) {
754
+ s1 = null;
755
+ }
756
+ s2 = peg$parseValue();
757
+ if (s2 !== peg$FAILED) {
758
+ peg$savedPos = s0;
759
+ s0 = peg$f12(s1, s2);
760
+ } else {
761
+ peg$currPos = s0;
762
+ s0 = peg$FAILED;
763
+ }
764
+ return s0;
765
+ }
766
+ function peg$parseFunctionParameterTail() {
767
+ let s0, s1, s2, s3, s4;
768
+ s0 = peg$currPos;
769
+ s1 = [];
770
+ s2 = peg$parse_();
771
+ while (s2 !== peg$FAILED) {
772
+ s1.push(s2);
773
+ s2 = peg$parse_();
774
+ }
775
+ if (input.charCodeAt(peg$currPos) === 44) {
776
+ s2 = peg$c4;
777
+ peg$currPos++;
778
+ } else {
779
+ s2 = peg$FAILED;
780
+ if (peg$silentFails === 0) {
781
+ peg$fail(peg$e5);
782
+ }
783
+ }
784
+ if (s2 !== peg$FAILED) {
785
+ s3 = [];
786
+ s4 = peg$parse_();
787
+ while (s4 !== peg$FAILED) {
788
+ s3.push(s4);
789
+ s4 = peg$parse_();
790
+ }
791
+ s4 = peg$parseFunctionParameter();
792
+ if (s4 !== peg$FAILED) {
793
+ peg$savedPos = s0;
794
+ s0 = peg$f13(s4);
795
+ } else {
796
+ peg$currPos = s0;
797
+ s0 = peg$FAILED;
798
+ }
799
+ } else {
800
+ peg$currPos = s0;
801
+ s0 = peg$FAILED;
802
+ }
803
+ return s0;
804
+ }
805
+ function peg$parseTrailingComma() {
806
+ let s0, s1, s2;
807
+ s0 = peg$currPos;
808
+ s1 = [];
809
+ s2 = peg$parse_();
810
+ while (s2 !== peg$FAILED) {
811
+ s1.push(s2);
812
+ s2 = peg$parse_();
813
+ }
814
+ if (input.charCodeAt(peg$currPos) === 44) {
815
+ s2 = peg$c4;
816
+ peg$currPos++;
817
+ } else {
818
+ s2 = peg$FAILED;
819
+ if (peg$silentFails === 0) {
820
+ peg$fail(peg$e5);
821
+ }
822
+ }
823
+ if (s2 !== peg$FAILED) {
824
+ s1 = [s1, s2];
825
+ s0 = s1;
826
+ } else {
827
+ peg$currPos = s0;
828
+ s0 = peg$FAILED;
829
+ }
830
+ if (s0 === peg$FAILED) {
831
+ s0 = null;
832
+ }
833
+ return s0;
834
+ }
835
+ function peg$parseVariable() {
836
+ let s0, s1, s2, s3, s4;
837
+ peg$silentFails++;
838
+ s0 = peg$currPos;
839
+ s1 = input.charAt(peg$currPos);
840
+ if (peg$r0.test(s1)) {
841
+ peg$currPos++;
842
+ } else {
843
+ s1 = peg$FAILED;
844
+ if (peg$silentFails === 0) {
845
+ peg$fail(peg$e7);
846
+ }
847
+ }
848
+ if (s1 !== peg$FAILED) {
849
+ s2 = peg$parseIdentifier();
850
+ if (s2 !== peg$FAILED) {
851
+ s3 = [];
852
+ s4 = peg$parseVariableTail();
853
+ while (s4 !== peg$FAILED) {
854
+ s3.push(s4);
855
+ s4 = peg$parseVariableTail();
856
+ }
857
+ peg$savedPos = s0;
858
+ s0 = peg$f14(s1, s2, s3);
859
+ } else {
860
+ peg$currPos = s0;
861
+ s0 = peg$FAILED;
862
+ }
863
+ } else {
864
+ peg$currPos = s0;
865
+ s0 = peg$FAILED;
866
+ }
867
+ peg$silentFails--;
868
+ if (s0 === peg$FAILED) {
869
+ s1 = peg$FAILED;
870
+ if (peg$silentFails === 0) {
871
+ peg$fail(peg$e6);
872
+ }
873
+ }
874
+ return s0;
875
+ }
876
+ function peg$parseVariableTail() {
877
+ let s0, s1, s2, s3;
878
+ s0 = peg$currPos;
879
+ if (input.charCodeAt(peg$currPos) === 46) {
880
+ s1 = peg$c5;
881
+ peg$currPos++;
882
+ } else {
883
+ s1 = peg$FAILED;
884
+ if (peg$silentFails === 0) {
885
+ peg$fail(peg$e8);
886
+ }
887
+ }
888
+ if (s1 !== peg$FAILED) {
889
+ s2 = peg$parseIdentifier();
890
+ if (s2 !== peg$FAILED) {
891
+ peg$savedPos = s0;
892
+ s0 = peg$f15(s2);
893
+ } else {
894
+ peg$currPos = s0;
895
+ s0 = peg$FAILED;
896
+ }
897
+ } else {
898
+ peg$currPos = s0;
899
+ s0 = peg$FAILED;
900
+ }
901
+ if (s0 === peg$FAILED) {
902
+ s0 = peg$currPos;
903
+ if (input.charCodeAt(peg$currPos) === 91) {
904
+ s1 = peg$c6;
905
+ peg$currPos++;
906
+ } else {
907
+ s1 = peg$FAILED;
908
+ if (peg$silentFails === 0) {
909
+ peg$fail(peg$e9);
910
+ }
911
+ }
912
+ if (s1 !== peg$FAILED) {
913
+ s2 = peg$parseValueNumber();
914
+ if (s2 === peg$FAILED) {
915
+ s2 = peg$parseValueString();
916
+ }
917
+ if (s2 !== peg$FAILED) {
918
+ if (input.charCodeAt(peg$currPos) === 93) {
919
+ s3 = peg$c7;
920
+ peg$currPos++;
921
+ } else {
922
+ s3 = peg$FAILED;
923
+ if (peg$silentFails === 0) {
924
+ peg$fail(peg$e10);
925
+ }
926
+ }
927
+ if (s3 !== peg$FAILED) {
928
+ peg$savedPos = s0;
929
+ s0 = peg$f16(s2);
930
+ } else {
931
+ peg$currPos = s0;
932
+ s0 = peg$FAILED;
933
+ }
934
+ } else {
935
+ peg$currPos = s0;
936
+ s0 = peg$FAILED;
937
+ }
938
+ } else {
939
+ peg$currPos = s0;
940
+ s0 = peg$FAILED;
941
+ }
942
+ }
943
+ return s0;
944
+ }
945
+ function peg$parseValue() {
946
+ let s0;
947
+ s0 = peg$parseValueNull();
948
+ if (s0 === peg$FAILED) {
949
+ s0 = peg$parseValueBoolean();
950
+ if (s0 === peg$FAILED) {
951
+ s0 = peg$parseValueString();
952
+ if (s0 === peg$FAILED) {
953
+ s0 = peg$parseValueNumber();
954
+ if (s0 === peg$FAILED) {
955
+ s0 = peg$parseValueArray();
956
+ if (s0 === peg$FAILED) {
957
+ s0 = peg$parseValueHash();
958
+ if (s0 === peg$FAILED) {
959
+ s0 = peg$parseFunction();
960
+ if (s0 === peg$FAILED) {
961
+ s0 = peg$parseVariable();
962
+ }
963
+ }
964
+ }
965
+ }
966
+ }
967
+ }
968
+ }
969
+ return s0;
970
+ }
971
+ function peg$parseValueNull() {
972
+ let s0, s1;
973
+ peg$silentFails++;
974
+ s0 = peg$currPos;
975
+ if (input.substr(peg$currPos, 4) === peg$c8) {
976
+ s1 = peg$c8;
977
+ peg$currPos += 4;
978
+ } else {
979
+ s1 = peg$FAILED;
980
+ if (peg$silentFails === 0) {
981
+ peg$fail(peg$e12);
982
+ }
983
+ }
984
+ if (s1 !== peg$FAILED) {
985
+ peg$savedPos = s0;
986
+ s1 = peg$f17();
987
+ }
988
+ s0 = s1;
989
+ peg$silentFails--;
990
+ if (s0 === peg$FAILED) {
991
+ s1 = peg$FAILED;
992
+ if (peg$silentFails === 0) {
993
+ peg$fail(peg$e11);
994
+ }
995
+ }
996
+ return s0;
997
+ }
998
+ function peg$parseValueBoolean() {
999
+ let s0, s1;
1000
+ peg$silentFails++;
1001
+ s0 = peg$currPos;
1002
+ if (input.substr(peg$currPos, 4) === peg$c9) {
1003
+ s1 = peg$c9;
1004
+ peg$currPos += 4;
1005
+ } else {
1006
+ s1 = peg$FAILED;
1007
+ if (peg$silentFails === 0) {
1008
+ peg$fail(peg$e14);
1009
+ }
1010
+ }
1011
+ if (s1 !== peg$FAILED) {
1012
+ peg$savedPos = s0;
1013
+ s1 = peg$f18();
1014
+ }
1015
+ s0 = s1;
1016
+ if (s0 === peg$FAILED) {
1017
+ s0 = peg$currPos;
1018
+ if (input.substr(peg$currPos, 5) === peg$c10) {
1019
+ s1 = peg$c10;
1020
+ peg$currPos += 5;
1021
+ } else {
1022
+ s1 = peg$FAILED;
1023
+ if (peg$silentFails === 0) {
1024
+ peg$fail(peg$e15);
1025
+ }
1026
+ }
1027
+ if (s1 !== peg$FAILED) {
1028
+ peg$savedPos = s0;
1029
+ s1 = peg$f19();
1030
+ }
1031
+ s0 = s1;
1032
+ }
1033
+ peg$silentFails--;
1034
+ if (s0 === peg$FAILED) {
1035
+ s1 = peg$FAILED;
1036
+ if (peg$silentFails === 0) {
1037
+ peg$fail(peg$e13);
1038
+ }
1039
+ }
1040
+ return s0;
1041
+ }
1042
+ function peg$parseValueArray() {
1043
+ let s0, s1, s2, s3, s4, s5, s6;
1044
+ s0 = peg$currPos;
1045
+ if (input.charCodeAt(peg$currPos) === 91) {
1046
+ s1 = peg$c6;
1047
+ peg$currPos++;
1048
+ } else {
1049
+ s1 = peg$FAILED;
1050
+ if (peg$silentFails === 0) {
1051
+ peg$fail(peg$e9);
1052
+ }
1053
+ }
1054
+ if (s1 !== peg$FAILED) {
1055
+ s2 = [];
1056
+ s3 = peg$parse_();
1057
+ while (s3 !== peg$FAILED) {
1058
+ s2.push(s3);
1059
+ s3 = peg$parse_();
1060
+ }
1061
+ s3 = peg$currPos;
1062
+ s4 = peg$parseValue();
1063
+ if (s4 !== peg$FAILED) {
1064
+ s5 = [];
1065
+ s6 = peg$parseValueArrayTail();
1066
+ while (s6 !== peg$FAILED) {
1067
+ s5.push(s6);
1068
+ s6 = peg$parseValueArrayTail();
1069
+ }
1070
+ s6 = peg$parseTrailingComma();
1071
+ peg$savedPos = s3;
1072
+ s3 = peg$f20(s4, s5);
1073
+ } else {
1074
+ peg$currPos = s3;
1075
+ s3 = peg$FAILED;
1076
+ }
1077
+ if (s3 === peg$FAILED) {
1078
+ s3 = null;
1079
+ }
1080
+ s4 = [];
1081
+ s5 = peg$parse_();
1082
+ while (s5 !== peg$FAILED) {
1083
+ s4.push(s5);
1084
+ s5 = peg$parse_();
1085
+ }
1086
+ if (input.charCodeAt(peg$currPos) === 93) {
1087
+ s5 = peg$c7;
1088
+ peg$currPos++;
1089
+ } else {
1090
+ s5 = peg$FAILED;
1091
+ if (peg$silentFails === 0) {
1092
+ peg$fail(peg$e10);
1093
+ }
1094
+ }
1095
+ if (s5 !== peg$FAILED) {
1096
+ peg$savedPos = s0;
1097
+ s0 = peg$f21(s3);
1098
+ } else {
1099
+ peg$currPos = s0;
1100
+ s0 = peg$FAILED;
1101
+ }
1102
+ } else {
1103
+ peg$currPos = s0;
1104
+ s0 = peg$FAILED;
1105
+ }
1106
+ return s0;
1107
+ }
1108
+ function peg$parseValueArrayTail() {
1109
+ let s0, s1, s2, s3, s4;
1110
+ s0 = peg$currPos;
1111
+ s1 = [];
1112
+ s2 = peg$parse_();
1113
+ while (s2 !== peg$FAILED) {
1114
+ s1.push(s2);
1115
+ s2 = peg$parse_();
1116
+ }
1117
+ if (input.charCodeAt(peg$currPos) === 44) {
1118
+ s2 = peg$c4;
1119
+ peg$currPos++;
1120
+ } else {
1121
+ s2 = peg$FAILED;
1122
+ if (peg$silentFails === 0) {
1123
+ peg$fail(peg$e5);
1124
+ }
1125
+ }
1126
+ if (s2 !== peg$FAILED) {
1127
+ s3 = [];
1128
+ s4 = peg$parse_();
1129
+ while (s4 !== peg$FAILED) {
1130
+ s3.push(s4);
1131
+ s4 = peg$parse_();
1132
+ }
1133
+ s4 = peg$parseValue();
1134
+ if (s4 !== peg$FAILED) {
1135
+ peg$savedPos = s0;
1136
+ s0 = peg$f22(s4);
1137
+ } else {
1138
+ peg$currPos = s0;
1139
+ s0 = peg$FAILED;
1140
+ }
1141
+ } else {
1142
+ peg$currPos = s0;
1143
+ s0 = peg$FAILED;
1144
+ }
1145
+ return s0;
1146
+ }
1147
+ function peg$parseValueHash() {
1148
+ let s0, s1, s2, s3, s4, s5, s6;
1149
+ s0 = peg$currPos;
1150
+ if (input.charCodeAt(peg$currPos) === 123) {
1151
+ s1 = peg$c11;
1152
+ peg$currPos++;
1153
+ } else {
1154
+ s1 = peg$FAILED;
1155
+ if (peg$silentFails === 0) {
1156
+ peg$fail(peg$e16);
1157
+ }
1158
+ }
1159
+ if (s1 !== peg$FAILED) {
1160
+ s2 = [];
1161
+ s3 = peg$parse_();
1162
+ while (s3 !== peg$FAILED) {
1163
+ s2.push(s3);
1164
+ s3 = peg$parse_();
1165
+ }
1166
+ s3 = peg$currPos;
1167
+ s4 = peg$parseValueHashItem();
1168
+ if (s4 !== peg$FAILED) {
1169
+ s5 = [];
1170
+ s6 = peg$parseValueHashTail();
1171
+ while (s6 !== peg$FAILED) {
1172
+ s5.push(s6);
1173
+ s6 = peg$parseValueHashTail();
1174
+ }
1175
+ s6 = peg$parseTrailingComma();
1176
+ peg$savedPos = s3;
1177
+ s3 = peg$f23(s4, s5);
1178
+ } else {
1179
+ peg$currPos = s3;
1180
+ s3 = peg$FAILED;
1181
+ }
1182
+ if (s3 === peg$FAILED) {
1183
+ s3 = null;
1184
+ }
1185
+ s4 = [];
1186
+ s5 = peg$parse_();
1187
+ while (s5 !== peg$FAILED) {
1188
+ s4.push(s5);
1189
+ s5 = peg$parse_();
1190
+ }
1191
+ if (input.charCodeAt(peg$currPos) === 125) {
1192
+ s5 = peg$c12;
1193
+ peg$currPos++;
1194
+ } else {
1195
+ s5 = peg$FAILED;
1196
+ if (peg$silentFails === 0) {
1197
+ peg$fail(peg$e17);
1198
+ }
1199
+ }
1200
+ if (s5 !== peg$FAILED) {
1201
+ peg$savedPos = s0;
1202
+ s0 = peg$f24(s3);
1203
+ } else {
1204
+ peg$currPos = s0;
1205
+ s0 = peg$FAILED;
1206
+ }
1207
+ } else {
1208
+ peg$currPos = s0;
1209
+ s0 = peg$FAILED;
1210
+ }
1211
+ return s0;
1212
+ }
1213
+ function peg$parseValueHashTail() {
1214
+ let s0, s1, s2, s3, s4;
1215
+ s0 = peg$currPos;
1216
+ s1 = [];
1217
+ s2 = peg$parse_();
1218
+ while (s2 !== peg$FAILED) {
1219
+ s1.push(s2);
1220
+ s2 = peg$parse_();
1221
+ }
1222
+ if (input.charCodeAt(peg$currPos) === 44) {
1223
+ s2 = peg$c4;
1224
+ peg$currPos++;
1225
+ } else {
1226
+ s2 = peg$FAILED;
1227
+ if (peg$silentFails === 0) {
1228
+ peg$fail(peg$e5);
1229
+ }
1230
+ }
1231
+ if (s2 !== peg$FAILED) {
1232
+ s3 = [];
1233
+ s4 = peg$parse_();
1234
+ while (s4 !== peg$FAILED) {
1235
+ s3.push(s4);
1236
+ s4 = peg$parse_();
1237
+ }
1238
+ s4 = peg$parseValueHashItem();
1239
+ if (s4 !== peg$FAILED) {
1240
+ peg$savedPos = s0;
1241
+ s0 = peg$f25(s4);
1242
+ } else {
1243
+ peg$currPos = s0;
1244
+ s0 = peg$FAILED;
1245
+ }
1246
+ } else {
1247
+ peg$currPos = s0;
1248
+ s0 = peg$FAILED;
1249
+ }
1250
+ return s0;
1251
+ }
1252
+ function peg$parseValueHashItem() {
1253
+ let s0, s1, s2, s3, s4;
1254
+ s0 = peg$currPos;
1255
+ s1 = peg$parseIdentifier();
1256
+ if (s1 === peg$FAILED) {
1257
+ s1 = peg$parseValueString();
1258
+ }
1259
+ if (s1 !== peg$FAILED) {
1260
+ if (input.charCodeAt(peg$currPos) === 58) {
1261
+ s2 = peg$c13;
1262
+ peg$currPos++;
1263
+ } else {
1264
+ s2 = peg$FAILED;
1265
+ if (peg$silentFails === 0) {
1266
+ peg$fail(peg$e18);
1267
+ }
1268
+ }
1269
+ if (s2 !== peg$FAILED) {
1270
+ s3 = [];
1271
+ s4 = peg$parse_();
1272
+ while (s4 !== peg$FAILED) {
1273
+ s3.push(s4);
1274
+ s4 = peg$parse_();
1275
+ }
1276
+ s4 = peg$parseValue();
1277
+ if (s4 !== peg$FAILED) {
1278
+ peg$savedPos = s0;
1279
+ s0 = peg$f26(s1, s4);
1280
+ } else {
1281
+ peg$currPos = s0;
1282
+ s0 = peg$FAILED;
1283
+ }
1284
+ } else {
1285
+ peg$currPos = s0;
1286
+ s0 = peg$FAILED;
1287
+ }
1288
+ } else {
1289
+ peg$currPos = s0;
1290
+ s0 = peg$FAILED;
1291
+ }
1292
+ return s0;
1293
+ }
1294
+ function peg$parseValueNumber() {
1295
+ let s0, s2, s3, s4, s5, s6;
1296
+ peg$silentFails++;
1297
+ s0 = peg$currPos;
1298
+ if (input.charCodeAt(peg$currPos) === 45) {
1299
+ peg$currPos++;
1300
+ } else {
1301
+ if (peg$silentFails === 0) {
1302
+ peg$fail(peg$e20);
1303
+ }
1304
+ }
1305
+ s2 = [];
1306
+ s3 = input.charAt(peg$currPos);
1307
+ if (peg$r1.test(s3)) {
1308
+ peg$currPos++;
1309
+ } else {
1310
+ s3 = peg$FAILED;
1311
+ if (peg$silentFails === 0) {
1312
+ peg$fail(peg$e21);
1313
+ }
1314
+ }
1315
+ if (s3 !== peg$FAILED) {
1316
+ while (s3 !== peg$FAILED) {
1317
+ s2.push(s3);
1318
+ s3 = input.charAt(peg$currPos);
1319
+ if (peg$r1.test(s3)) {
1320
+ peg$currPos++;
1321
+ } else {
1322
+ s3 = peg$FAILED;
1323
+ if (peg$silentFails === 0) {
1324
+ peg$fail(peg$e21);
1325
+ }
1326
+ }
1327
+ }
1328
+ } else {
1329
+ s2 = peg$FAILED;
1330
+ }
1331
+ if (s2 !== peg$FAILED) {
1332
+ s3 = peg$currPos;
1333
+ if (input.charCodeAt(peg$currPos) === 46) {
1334
+ s4 = peg$c5;
1335
+ peg$currPos++;
1336
+ } else {
1337
+ s4 = peg$FAILED;
1338
+ if (peg$silentFails === 0) {
1339
+ peg$fail(peg$e8);
1340
+ }
1341
+ }
1342
+ if (s4 !== peg$FAILED) {
1343
+ s5 = [];
1344
+ s6 = input.charAt(peg$currPos);
1345
+ if (peg$r1.test(s6)) {
1346
+ peg$currPos++;
1347
+ } else {
1348
+ s6 = peg$FAILED;
1349
+ if (peg$silentFails === 0) {
1350
+ peg$fail(peg$e21);
1351
+ }
1352
+ }
1353
+ if (s6 !== peg$FAILED) {
1354
+ while (s6 !== peg$FAILED) {
1355
+ s5.push(s6);
1356
+ s6 = input.charAt(peg$currPos);
1357
+ if (peg$r1.test(s6)) {
1358
+ peg$currPos++;
1359
+ } else {
1360
+ s6 = peg$FAILED;
1361
+ if (peg$silentFails === 0) {
1362
+ peg$fail(peg$e21);
1363
+ }
1364
+ }
1365
+ }
1366
+ } else {
1367
+ s5 = peg$FAILED;
1368
+ }
1369
+ if (s5 !== peg$FAILED) {
1370
+ s4 = [s4, s5];
1371
+ s3 = s4;
1372
+ } else {
1373
+ peg$currPos = s3;
1374
+ s3 = peg$FAILED;
1375
+ }
1376
+ } else {
1377
+ peg$currPos = s3;
1378
+ s3 = peg$FAILED;
1379
+ }
1380
+ if (s3 === peg$FAILED) {
1381
+ s3 = null;
1382
+ }
1383
+ peg$savedPos = s0;
1384
+ s0 = peg$f27();
1385
+ } else {
1386
+ peg$currPos = s0;
1387
+ s0 = peg$FAILED;
1388
+ }
1389
+ peg$silentFails--;
1390
+ if (s0 === peg$FAILED) {
1391
+ if (peg$silentFails === 0) {
1392
+ peg$fail(peg$e19);
1393
+ }
1394
+ }
1395
+ return s0;
1396
+ }
1397
+ function peg$parseValueString() {
1398
+ let s0, s1, s2, s3;
1399
+ peg$silentFails++;
1400
+ s0 = peg$currPos;
1401
+ if (input.charCodeAt(peg$currPos) === 34) {
1402
+ s1 = peg$c15;
1403
+ peg$currPos++;
1404
+ } else {
1405
+ s1 = peg$FAILED;
1406
+ if (peg$silentFails === 0) {
1407
+ peg$fail(peg$e23);
1408
+ }
1409
+ }
1410
+ if (s1 !== peg$FAILED) {
1411
+ s2 = [];
1412
+ s3 = peg$parseValueStringChars();
1413
+ while (s3 !== peg$FAILED) {
1414
+ s2.push(s3);
1415
+ s3 = peg$parseValueStringChars();
1416
+ }
1417
+ if (input.charCodeAt(peg$currPos) === 34) {
1418
+ s3 = peg$c15;
1419
+ peg$currPos++;
1420
+ } else {
1421
+ s3 = peg$FAILED;
1422
+ if (peg$silentFails === 0) {
1423
+ peg$fail(peg$e23);
1424
+ }
1425
+ }
1426
+ if (s3 !== peg$FAILED) {
1427
+ peg$savedPos = s0;
1428
+ s0 = peg$f28(s2);
1429
+ } else {
1430
+ peg$currPos = s0;
1431
+ s0 = peg$FAILED;
1432
+ }
1433
+ } else {
1434
+ peg$currPos = s0;
1435
+ s0 = peg$FAILED;
1436
+ }
1437
+ peg$silentFails--;
1438
+ if (s0 === peg$FAILED) {
1439
+ s1 = peg$FAILED;
1440
+ if (peg$silentFails === 0) {
1441
+ peg$fail(peg$e22);
1442
+ }
1443
+ }
1444
+ return s0;
1445
+ }
1446
+ function peg$parseValueStringChars() {
1447
+ let s0;
1448
+ s0 = input.charAt(peg$currPos);
1449
+ if (peg$r2.test(s0)) {
1450
+ peg$currPos++;
1451
+ } else {
1452
+ s0 = peg$FAILED;
1453
+ if (peg$silentFails === 0) {
1454
+ peg$fail(peg$e24);
1455
+ }
1456
+ }
1457
+ if (s0 === peg$FAILED) {
1458
+ s0 = peg$parseValueStringEscapes();
1459
+ }
1460
+ return s0;
1461
+ }
1462
+ function peg$parseValueStringEscapes() {
1463
+ let s0, s1, s2, s3;
1464
+ s0 = peg$currPos;
1465
+ if (input.charCodeAt(peg$currPos) === 92) {
1466
+ s1 = peg$c16;
1467
+ peg$currPos++;
1468
+ } else {
1469
+ s1 = peg$FAILED;
1470
+ if (peg$silentFails === 0) {
1471
+ peg$fail(peg$e25);
1472
+ }
1473
+ }
1474
+ if (s1 !== peg$FAILED) {
1475
+ s2 = input.charAt(peg$currPos);
1476
+ if (peg$r3.test(s2)) {
1477
+ peg$currPos++;
1478
+ } else {
1479
+ s2 = peg$FAILED;
1480
+ if (peg$silentFails === 0) {
1481
+ peg$fail(peg$e26);
1482
+ }
1483
+ }
1484
+ if (s2 === peg$FAILED) {
1485
+ s2 = peg$currPos;
1486
+ if (input.charCodeAt(peg$currPos) === 110) {
1487
+ s3 = peg$c17;
1488
+ peg$currPos++;
1489
+ } else {
1490
+ s3 = peg$FAILED;
1491
+ if (peg$silentFails === 0) {
1492
+ peg$fail(peg$e27);
1493
+ }
1494
+ }
1495
+ if (s3 !== peg$FAILED) {
1496
+ peg$savedPos = s2;
1497
+ s3 = peg$f29();
1498
+ }
1499
+ s2 = s3;
1500
+ if (s2 === peg$FAILED) {
1501
+ s2 = peg$currPos;
1502
+ if (input.charCodeAt(peg$currPos) === 114) {
1503
+ s3 = peg$c18;
1504
+ peg$currPos++;
1505
+ } else {
1506
+ s3 = peg$FAILED;
1507
+ if (peg$silentFails === 0) {
1508
+ peg$fail(peg$e28);
1509
+ }
1510
+ }
1511
+ if (s3 !== peg$FAILED) {
1512
+ peg$savedPos = s2;
1513
+ s3 = peg$f30();
1514
+ }
1515
+ s2 = s3;
1516
+ if (s2 === peg$FAILED) {
1517
+ s2 = peg$currPos;
1518
+ if (input.charCodeAt(peg$currPos) === 116) {
1519
+ s3 = peg$c19;
1520
+ peg$currPos++;
1521
+ } else {
1522
+ s3 = peg$FAILED;
1523
+ if (peg$silentFails === 0) {
1524
+ peg$fail(peg$e29);
1525
+ }
1526
+ }
1527
+ if (s3 !== peg$FAILED) {
1528
+ peg$savedPos = s2;
1529
+ s3 = peg$f31();
1530
+ }
1531
+ s2 = s3;
1532
+ }
1533
+ }
1534
+ }
1535
+ if (s2 !== peg$FAILED) {
1536
+ peg$savedPos = s0;
1537
+ s0 = peg$f32(s2);
1538
+ } else {
1539
+ peg$currPos = s0;
1540
+ s0 = peg$FAILED;
1541
+ }
1542
+ } else {
1543
+ peg$currPos = s0;
1544
+ s0 = peg$FAILED;
1545
+ }
1546
+ return s0;
1547
+ }
1548
+ function peg$parseIdentifier() {
1549
+ let s0, s1, s2;
1550
+ peg$silentFails++;
1551
+ s0 = peg$currPos;
1552
+ s1 = [];
1553
+ s2 = input.charAt(peg$currPos);
1554
+ if (peg$r4.test(s2)) {
1555
+ peg$currPos++;
1556
+ } else {
1557
+ s2 = peg$FAILED;
1558
+ if (peg$silentFails === 0) {
1559
+ peg$fail(peg$e31);
1560
+ }
1561
+ }
1562
+ if (s2 !== peg$FAILED) {
1563
+ while (s2 !== peg$FAILED) {
1564
+ s1.push(s2);
1565
+ s2 = input.charAt(peg$currPos);
1566
+ if (peg$r4.test(s2)) {
1567
+ peg$currPos++;
1568
+ } else {
1569
+ s2 = peg$FAILED;
1570
+ if (peg$silentFails === 0) {
1571
+ peg$fail(peg$e31);
1572
+ }
1573
+ }
1574
+ }
1575
+ } else {
1576
+ s1 = peg$FAILED;
1577
+ }
1578
+ if (s1 !== peg$FAILED) {
1579
+ s0 = input.substring(s0, peg$currPos);
1580
+ } else {
1581
+ s0 = s1;
1582
+ }
1583
+ peg$silentFails--;
1584
+ if (s0 === peg$FAILED) {
1585
+ s1 = peg$FAILED;
1586
+ if (peg$silentFails === 0) {
1587
+ peg$fail(peg$e30);
1588
+ }
1589
+ }
1590
+ return s0;
1591
+ }
1592
+ function peg$parse_() {
1593
+ let s0;
1594
+ peg$silentFails++;
1595
+ s0 = input.charAt(peg$currPos);
1596
+ if (peg$r5.test(s0)) {
1597
+ peg$currPos++;
1598
+ } else {
1599
+ s0 = peg$FAILED;
1600
+ if (peg$silentFails === 0) {
1601
+ peg$fail(peg$e33);
1602
+ }
1603
+ }
1604
+ peg$silentFails--;
1605
+ if (s0 === peg$FAILED) {
1606
+ if (peg$silentFails === 0) {
1607
+ peg$fail(peg$e32);
1608
+ }
1609
+ }
1610
+ return s0;
1611
+ }
1612
+ const { Variable: Variable2, Function: Function3 } = options;
1613
+ peg$result = peg$startRuleFunction();
1614
+ const peg$success = peg$result !== peg$FAILED && peg$currPos === input.length;
1615
+ function peg$throw() {
1616
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1617
+ peg$fail(peg$endExpectation());
1618
+ }
1619
+ throw peg$buildStructuredError(
1620
+ peg$maxFailExpected,
1621
+ peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null,
1622
+ peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
1623
+ );
1624
+ }
1625
+ if (options.peg$library) {
1626
+ return (
1627
+ /** @type {any} */
1628
+ {
1629
+ peg$result,
1630
+ peg$currPos,
1631
+ peg$FAILED,
1632
+ peg$maxFailExpected,
1633
+ peg$maxFailPos,
1634
+ peg$success,
1635
+ peg$throw: peg$success ? void 0 : peg$throw
1636
+ }
1637
+ );
1638
+ }
1639
+ if (peg$success) {
1640
+ return peg$result;
1641
+ } else {
1642
+ peg$throw();
1643
+ }
1644
+ }
1645
+ class Variable {
1646
+ constructor(path = []) {
1647
+ this.$$mdtype = "Variable";
1648
+ this.path = path;
1649
+ }
1650
+ resolve({ variables } = {}) {
1651
+ return variables instanceof Function ? variables(this.path) : this.path.reduce((obj = {}, key) => obj[key], variables);
1652
+ }
1653
+ }
1654
+ let Function$1 = class Function2 {
1655
+ constructor(name, parameters) {
1656
+ this.$$mdtype = "Function";
1657
+ this.name = name;
1658
+ this.parameters = parameters;
1659
+ }
1660
+ resolve(config = {}) {
1661
+ const fn = config?.functions?.[this.name];
1662
+ if (!fn) return null;
1663
+ const parameters = resolve$1(this.parameters, config);
1664
+ return fn.transform?.(parameters, config);
1665
+ }
1666
+ };
1667
+ const OPEN$1 = "{%";
1668
+ const CLOSE$1 = "%}";
1669
+ const IDENTIFIER_REGEX = /^[a-zA-Z0-9_-]+$/;
1670
+ function isIdentifier(s2) {
1671
+ return typeof s2 === "string" && IDENTIFIER_REGEX.test(s2);
1672
+ }
1673
+ function isPromise(a) {
1674
+ return a && typeof a === "object" && typeof a.then === "function";
1675
+ }
1676
+ function findTagEnd(content, start = 0) {
1677
+ let state = 0;
1678
+ for (let pos = start; pos < content.length; pos++) {
1679
+ const char = content[pos];
1680
+ switch (state) {
1681
+ case 1:
1682
+ switch (char) {
1683
+ case '"':
1684
+ state = 0;
1685
+ break;
1686
+ case "\\":
1687
+ state = 2;
1688
+ break;
1689
+ }
1690
+ break;
1691
+ case 2:
1692
+ state = 1;
1693
+ break;
1694
+ case 0:
1695
+ if (char === '"') state = 1;
1696
+ else if (content.startsWith(CLOSE$1, pos)) return pos;
1697
+ }
1698
+ }
1699
+ return null;
1700
+ }
1701
+ function parseTag(content, line, contentStart) {
1702
+ try {
1703
+ return peg$parse(content, { Variable, Function: Function$1 });
1704
+ } catch (error2) {
1705
+ if (!(error2 instanceof peg$SyntaxError)) throw error2;
1706
+ const {
1707
+ message,
1708
+ location: { start, end }
1709
+ } = error2;
1710
+ const location = {
1711
+ start: { line, character: start.offset + contentStart },
1712
+ end: { line: line + 1, character: end.offset + contentStart }
1713
+ };
1714
+ return { type: "error", meta: { error: { message, location } } };
1715
+ }
1716
+ }
1717
+ function parseTags(content, firstLine = 0) {
1718
+ let line = firstLine + 1;
1719
+ const output = [];
1720
+ let start = 0;
1721
+ for (let pos = 0; pos < content.length; pos++) {
1722
+ if (content[pos] === "\n") {
1723
+ line++;
1724
+ continue;
1725
+ }
1726
+ if (!content.startsWith(OPEN$1, pos)) continue;
1727
+ const end = findTagEnd(content, pos);
1728
+ if (end == null) {
1729
+ pos = pos + OPEN$1.length;
1730
+ continue;
1731
+ }
1732
+ const text2 = content.slice(pos, end + CLOSE$1.length);
1733
+ const inner = content.slice(pos + OPEN$1.length, end);
1734
+ const lineStart = content.lastIndexOf("\n", pos);
1735
+ const lineEnd = content.indexOf("\n", end);
1736
+ const lineContent = content.slice(lineStart, lineEnd);
1737
+ const tag = parseTag(inner.trim(), line, pos - lineStart);
1738
+ const precedingTextEnd = lineContent.trim() === text2 ? lineStart : pos;
1739
+ const precedingText = content.slice(start, precedingTextEnd);
1740
+ output.push({
1741
+ type: "text",
1742
+ start,
1743
+ end: pos - 1,
1744
+ content: precedingText
1745
+ });
1746
+ output.push({
1747
+ map: [line, line + 1],
1748
+ position: {
1749
+ start: pos - lineStart,
1750
+ end: pos - lineStart + text2.length
1751
+ },
1752
+ start: pos,
1753
+ end: pos + text2.length - 1,
1754
+ info: text2,
1755
+ ...tag
1756
+ });
1757
+ start = end + CLOSE$1.length;
1758
+ pos = start - 1;
1759
+ }
1760
+ output.push({
1761
+ type: "text",
1762
+ start,
1763
+ end: content.length - 1,
1764
+ content: content.slice(start)
1765
+ });
1766
+ return output;
1767
+ }
1768
+ const transformer = {
1769
+ findSchema(node2, { nodes: nodes2 = {}, tags: tags2 = {} } = {}) {
1770
+ return node2.tag ? tags2[node2.tag] : nodes2[node2.type];
1771
+ },
1772
+ attributes(node2, config = {}) {
1773
+ const schema = this.findSchema(node2, config) ?? {};
1774
+ const output = {};
1775
+ const attrs = { ...schema.attributes };
1776
+ for (const [key, attr] of Object.entries(attrs)) {
1777
+ if (attr.render == false) continue;
1778
+ const name = typeof attr.render === "string" ? attr.render : key;
1779
+ let value = node2.attributes[key];
1780
+ if (typeof attr.type === "function") {
1781
+ const instance = new attr.type();
1782
+ if (instance.transform) {
1783
+ value = instance.transform(value, config);
1784
+ }
1785
+ }
1786
+ value = value === void 0 ? attr.default : value;
1787
+ if (value === void 0) continue;
1788
+ output[name] = value;
1789
+ }
1790
+ if (schema.slots) {
1791
+ for (const [key, slot2] of Object.entries(schema.slots)) {
1792
+ if (slot2.render === false) continue;
1793
+ const name = typeof slot2.render === "string" ? slot2.render : key;
1794
+ if (node2.slots[key]) output[name] = this.node(node2.slots[key], config);
1795
+ }
1796
+ }
1797
+ return output;
1798
+ },
1799
+ children(node2, config = {}) {
1800
+ const children = node2.children.flatMap(
1801
+ (child) => this.node(child, config)
1802
+ );
1803
+ if (children.some(isPromise)) {
1804
+ return Promise.all(children);
1805
+ }
1806
+ return children;
1807
+ },
1808
+ node(node2, config = {}) {
1809
+ const schema = this.findSchema(node2, config) ?? {};
1810
+ if (schema && schema.transform instanceof Function) return schema.transform(node2, config);
1811
+ const children = this.children(node2, config);
1812
+ if (!schema || !schema.render) return children;
1813
+ const attributes = this.attributes(node2, config);
1814
+ if (isPromise(attributes) || isPromise(children)) {
1815
+ return Promise.all([attributes, children]).then(
1816
+ (values) => new Tag(schema.render, ...values)
1817
+ );
1818
+ }
1819
+ return new Tag(schema.render, attributes, children);
1820
+ }
1821
+ };
1822
+ class Node {
1823
+ constructor(type = "node", attributes = {}, children = [], tag) {
1824
+ this.$$mdtype = "Node";
1825
+ this.errors = [];
1826
+ this.lines = [];
1827
+ this.inline = false;
1828
+ this.attributes = attributes;
1829
+ this.children = children;
1830
+ this.type = type;
1831
+ this.tag = tag;
1832
+ this.annotations = [];
1833
+ this.slots = {};
1834
+ }
1835
+ *walk() {
1836
+ for (const child of [...Object.values(this.slots), ...this.children]) {
1837
+ yield child;
1838
+ yield* child.walk();
1839
+ }
1840
+ }
1841
+ push(node2) {
1842
+ this.children.push(node2);
1843
+ }
1844
+ resolve(config = {}) {
1845
+ return Object.assign(new Node(), this, {
1846
+ children: this.children.map((child) => child.resolve(config)),
1847
+ attributes: resolve$1(this.attributes, config),
1848
+ slots: Object.fromEntries(
1849
+ Object.entries(this.slots).map(([name, slot2]) => [name, slot2.resolve(config)])
1850
+ )
1851
+ });
1852
+ }
1853
+ findSchema(config = {}) {
1854
+ return transformer.findSchema(this, config);
1855
+ }
1856
+ transformAttributes(config = {}) {
1857
+ return transformer.attributes(this, config);
1858
+ }
1859
+ transformChildren(config) {
1860
+ return transformer.children(this, config);
1861
+ }
1862
+ transform(config) {
1863
+ return transformer.node(this, config);
1864
+ }
1865
+ }
1866
+ const AstTypes = {
1867
+ Function: Function$1,
1868
+ Node,
1869
+ Variable
1870
+ };
1871
+ function reviver(_, value) {
1872
+ if (!value) return value;
1873
+ const klass = AstTypes[value.$$mdtype];
1874
+ return klass ? Object.assign(new klass(), value) : value;
1875
+ }
1876
+ function fromJSON(text2) {
1877
+ return JSON.parse(text2, reviver);
1878
+ }
1879
+ const Ast = {
1880
+ ...AstTypes,
1881
+ ...base,
1882
+ fromJSON
1883
+ };
1884
+ const SPACE = " ";
1885
+ const SEP = ", ";
1886
+ const NL = "\n";
1887
+ const OL = ".";
1888
+ const UL = "-";
1889
+ const MAX_TAG_OPENING_WIDTH = 80;
1890
+ const WRAPPING_TYPES = ["strong", "em", "s"];
1891
+ const max = (a, b) => Math.max(a, b);
1892
+ const increment = (o, n = 2) => ({
1893
+ ...o,
1894
+ indent: (o.indent || 0) + n
1895
+ });
1896
+ function* formatChildren(a, options) {
1897
+ for (const child of a.children) {
1898
+ yield* formatValue(child, options);
1899
+ }
1900
+ }
1901
+ function* formatInline(g) {
1902
+ yield [...g].join("").trim();
1903
+ }
1904
+ function* formatTableRow(items) {
1905
+ yield `| ${items.join(" | ")} |`;
1906
+ }
1907
+ function formatScalar(v) {
1908
+ if (v === void 0) {
1909
+ return void 0;
1910
+ }
1911
+ if (Ast.isAst(v)) {
1912
+ return format(v);
1913
+ }
1914
+ if (v === null) {
1915
+ return "null";
1916
+ }
1917
+ if (Array.isArray(v)) {
1918
+ return "[" + v.map(formatScalar).join(SEP) + "]";
1919
+ }
1920
+ if (typeof v === "object") {
1921
+ return "{" + Object.entries(v).map(([key, value]) => `${isIdentifier(key) ? key : `"${key}"`}: ${formatScalar(value)}`).join(SEP) + "}";
1922
+ }
1923
+ return JSON.stringify(v);
1924
+ }
1925
+ function formatAnnotationValue(a) {
1926
+ const formattedValue = formatScalar(a.value);
1927
+ if (formattedValue === void 0) return void 0;
1928
+ if (a.name === "primary") return formattedValue;
1929
+ return `${a.name}=${formattedValue}`;
1930
+ }
1931
+ function* formatAttributes(n) {
1932
+ for (const [key, value] of Object.entries(n.attributes)) {
1933
+ yield formatAnnotationValue({ name: key, value });
1934
+ }
1935
+ }
1936
+ function* formatAnnotations(n) {
1937
+ if (n.annotations.length) {
1938
+ yield OPEN$1 + SPACE;
1939
+ yield n.annotations.map(formatAnnotationValue).join(SPACE);
1940
+ yield SPACE + CLOSE$1;
1941
+ }
1942
+ }
1943
+ function* formatVariable(v) {
1944
+ yield "$";
1945
+ yield v.path.map((p, i) => {
1946
+ if (i === 0) return p;
1947
+ if (isIdentifier(p)) return "." + p;
1948
+ if (typeof p === "number") return `[${p}]`;
1949
+ return `["${p}"]`;
1950
+ }).join("");
1951
+ }
1952
+ function* formatFunction(f) {
1953
+ yield f.name;
1954
+ yield "(";
1955
+ yield Object.values(f.parameters).map(formatScalar).join(SEP);
1956
+ yield ")";
1957
+ }
1958
+ function* trimStart(g) {
1959
+ let n;
1960
+ do {
1961
+ const { value, done } = g.next();
1962
+ if (done) return;
1963
+ n = value.trimStart();
1964
+ } while (!n.length);
1965
+ yield n;
1966
+ yield* g;
1967
+ }
1968
+ function* escapeMarkdownCharacters(s2, characters) {
1969
+ yield s2.replace(characters, "\\$&").replace(new RegExp(" ", "g"), "&nbsp;");
1970
+ }
1971
+ function* formatNode(n, o = {}) {
1972
+ const no = { ...o, parent: n };
1973
+ const indent = SPACE.repeat(no.indent || 0);
1974
+ switch (n.type) {
1975
+ case "document": {
1976
+ if (n.attributes.frontmatter && n.attributes.frontmatter.length) {
1977
+ yield "---" + NL + n.attributes.frontmatter + NL + "---" + NL + NL;
1978
+ }
1979
+ yield* trimStart(formatChildren(n, no));
1980
+ break;
1981
+ }
1982
+ case "heading": {
1983
+ yield NL;
1984
+ yield indent;
1985
+ yield "#".repeat(n.attributes.level || 1);
1986
+ yield SPACE;
1987
+ yield* trimStart(formatChildren(n, no));
1988
+ yield* formatAnnotations(n);
1989
+ yield NL;
1990
+ break;
1991
+ }
1992
+ case "paragraph": {
1993
+ yield NL;
1994
+ yield* formatChildren(n, no);
1995
+ yield* formatAnnotations(n);
1996
+ yield NL;
1997
+ break;
1998
+ }
1999
+ case "inline": {
2000
+ yield indent;
2001
+ yield* formatChildren(n, no);
2002
+ break;
2003
+ }
2004
+ case "image": {
2005
+ yield "!";
2006
+ yield "[";
2007
+ yield* formatValue(n.attributes.alt, no);
2008
+ yield "]";
2009
+ yield "(";
2010
+ yield* typeof n.attributes.src === "string" ? escapeMarkdownCharacters(n.attributes.src, /[()]/g) : formatValue(n.attributes.src, no);
2011
+ if (n.attributes.title) {
2012
+ yield SPACE + `"${n.attributes.title}"`;
2013
+ }
2014
+ yield ")";
2015
+ break;
2016
+ }
2017
+ case "link": {
2018
+ const children = [...formatChildren(n, no)].join("");
2019
+ if (children === n.attributes.href && !n.attributes.title) {
2020
+ yield `<${n.attributes.href}>`;
2021
+ break;
2022
+ }
2023
+ yield "[";
2024
+ yield children;
2025
+ yield "]";
2026
+ yield "(";
2027
+ yield* typeof n.attributes.href === "string" ? escapeMarkdownCharacters(n.attributes.href, /[()]/g) : formatValue(n.attributes.href, no);
2028
+ if (n.attributes.title) {
2029
+ yield SPACE + `"${n.attributes.title}"`;
2030
+ }
2031
+ yield ")";
2032
+ break;
2033
+ }
2034
+ case "text": {
2035
+ const { content } = n.attributes;
2036
+ if (Ast.isAst(content)) {
2037
+ yield OPEN$1 + SPACE;
2038
+ yield* formatValue(content, no);
2039
+ yield SPACE + CLOSE$1;
2040
+ } else {
2041
+ if (o.parent && WRAPPING_TYPES.includes(o.parent.type)) {
2042
+ yield* escapeMarkdownCharacters(content, /[*_~]/g);
2043
+ } else {
2044
+ yield* escapeMarkdownCharacters(content, /^\*|#+\s|^>/);
2045
+ }
2046
+ }
2047
+ break;
2048
+ }
2049
+ case "blockquote": {
2050
+ const prefix = ">" + SPACE;
2051
+ yield n.children.map((child) => format(child, no).trimStart()).map((d) => NL + indent + prefix + d).join(indent + prefix);
2052
+ break;
2053
+ }
2054
+ case "hr": {
2055
+ yield NL;
2056
+ yield indent;
2057
+ yield "---";
2058
+ yield NL;
2059
+ break;
2060
+ }
2061
+ case "fence": {
2062
+ yield NL;
2063
+ yield indent;
2064
+ const innerFence = n.attributes.content.match(/`{3,}/g) || [];
2065
+ const innerFenceLength = innerFence.map((s2) => s2.length).reduce(max, 0);
2066
+ const boundary = "`".repeat(innerFenceLength ? innerFenceLength + 1 : 3);
2067
+ const needsNlBeforeEndBoundary = !n.attributes.content.endsWith(NL);
2068
+ yield boundary;
2069
+ if (n.attributes.language) yield n.attributes.language;
2070
+ if (n.annotations.length) yield SPACE;
2071
+ yield* formatAnnotations(n);
2072
+ yield NL;
2073
+ yield indent;
2074
+ yield n.attributes.content.split(NL).join(NL + indent);
2075
+ if (needsNlBeforeEndBoundary) {
2076
+ yield NL;
2077
+ }
2078
+ yield boundary;
2079
+ yield NL;
2080
+ break;
2081
+ }
2082
+ case "tag": {
2083
+ if (!n.inline) {
2084
+ yield NL;
2085
+ yield indent;
2086
+ }
2087
+ const open = OPEN$1 + SPACE;
2088
+ const attributes = [...formatAttributes(n)].filter((v) => v !== void 0);
2089
+ const tag = [open + n.tag, ...attributes];
2090
+ const inlineTag = tag.join(SPACE);
2091
+ const isLongTagOpening = inlineTag.length + open.length * 2 > (o.maxTagOpeningWidth || MAX_TAG_OPENING_WIDTH);
2092
+ yield (!n.inline && isLongTagOpening ? tag.join(NL + SPACE.repeat(open.length) + indent) : inlineTag) + SPACE + (n.children.length ? "" : "/") + CLOSE$1;
2093
+ if (n.children.length) {
2094
+ yield* formatChildren(n, no.allowIndentation ? increment(no) : no);
2095
+ if (!n.inline) {
2096
+ yield indent;
2097
+ }
2098
+ yield OPEN$1 + SPACE + "/" + n.tag + SPACE + CLOSE$1;
2099
+ }
2100
+ if (!n.inline) {
2101
+ yield NL;
2102
+ }
2103
+ break;
2104
+ }
2105
+ case "list": {
2106
+ const isLoose = n.children.some((n2) => n2.children.some((c) => c.type === "paragraph"));
2107
+ for (let i = 0; i < n.children.length; i++) {
2108
+ const prefix = (() => {
2109
+ if (!n.attributes.ordered) return n.attributes.marker ?? UL;
2110
+ let number = "1";
2111
+ const startNumber = n.attributes.start ?? 1;
2112
+ if (i === 0) number = startNumber.toString();
2113
+ if (o.orderedListMode === "increment") {
2114
+ number = (parseInt(startNumber) + i).toString();
2115
+ }
2116
+ return `${number}${n.attributes.marker ?? OL}`;
2117
+ })();
2118
+ let d = format(n.children[i], increment(no, prefix.length + 1));
2119
+ if (!isLoose || i === n.children.length - 1) {
2120
+ d = d.trim();
2121
+ }
2122
+ yield NL + indent + prefix + " " + d;
2123
+ }
2124
+ yield NL;
2125
+ break;
2126
+ }
2127
+ case "item": {
2128
+ for (let i = 0; i < n.children.length; i++) {
2129
+ yield* formatValue(n.children[i], no);
2130
+ if (i === 0) yield* formatAnnotations(n);
2131
+ }
2132
+ break;
2133
+ }
2134
+ case "strong": {
2135
+ yield n.attributes.marker ?? "**";
2136
+ yield* formatInline(formatChildren(n, no));
2137
+ yield n.attributes.marker ?? "**";
2138
+ break;
2139
+ }
2140
+ case "em": {
2141
+ yield n.attributes.marker ?? "*";
2142
+ yield* formatInline(formatChildren(n, no));
2143
+ yield n.attributes.marker ?? "*";
2144
+ break;
2145
+ }
2146
+ case "code": {
2147
+ yield "`";
2148
+ yield* formatInline(formatValue(n.attributes.content, no));
2149
+ yield "`";
2150
+ break;
2151
+ }
2152
+ case "s": {
2153
+ yield "~~";
2154
+ yield* formatInline(formatChildren(n, no));
2155
+ yield "~~";
2156
+ break;
2157
+ }
2158
+ case "hardbreak": {
2159
+ yield "\\" + NL;
2160
+ yield indent;
2161
+ break;
2162
+ }
2163
+ case "softbreak": {
2164
+ yield NL;
2165
+ yield indent;
2166
+ break;
2167
+ }
2168
+ case "table": {
2169
+ const table2 = [...formatChildren(n, increment(no))];
2170
+ if (o.parent && o.parent.type === "tag" && o.parent.tag === "table") {
2171
+ for (let i = 0; i < table2.length; i++) {
2172
+ const row = table2[i];
2173
+ if (typeof row === "string") {
2174
+ if (row.trim().length) {
2175
+ yield NL;
2176
+ yield row;
2177
+ }
2178
+ } else {
2179
+ if (i !== 0) {
2180
+ yield NL;
2181
+ yield indent + "---";
2182
+ }
2183
+ for (const d of row) {
2184
+ yield NL + indent + UL + " " + d;
2185
+ }
2186
+ }
2187
+ }
2188
+ yield NL;
2189
+ } else {
2190
+ const widths = [];
2191
+ for (const row of table2) {
2192
+ for (let i = 0; i < row.length; i++) {
2193
+ widths[i] = widths[i] ? Math.max(widths[i], row[i].length) : row[i].length;
2194
+ }
2195
+ }
2196
+ const [head, ...rows] = table2;
2197
+ yield NL;
2198
+ yield* formatTableRow(head.map((cell, i) => cell + SPACE.repeat(widths[i] - cell.length)));
2199
+ yield NL;
2200
+ yield* formatTableRow(head.map((cell, i) => "-".repeat(widths[i])));
2201
+ yield NL;
2202
+ for (const row of rows) {
2203
+ yield* formatTableRow(row.map((cell, i) => cell + SPACE.repeat(widths[i] - cell.length)));
2204
+ yield NL;
2205
+ }
2206
+ }
2207
+ break;
2208
+ }
2209
+ case "thead": {
2210
+ const [head] = [...formatChildren(n, no)];
2211
+ yield head || [];
2212
+ break;
2213
+ }
2214
+ case "tr": {
2215
+ yield [...formatChildren(n, no)];
2216
+ break;
2217
+ }
2218
+ case "td":
2219
+ case "th": {
2220
+ yield [...formatChildren(n, no), ...formatAnnotations(n)].join("").trim();
2221
+ break;
2222
+ }
2223
+ case "tbody": {
2224
+ yield* formatChildren(n, no);
2225
+ break;
2226
+ }
2227
+ case "comment": {
2228
+ yield "<!-- " + n.attributes.content + " -->\n";
2229
+ break;
2230
+ }
2231
+ }
2232
+ }
2233
+ function* formatValue(v, o = {}) {
2234
+ switch (typeof v) {
2235
+ case "undefined":
2236
+ break;
2237
+ case "boolean":
2238
+ case "number":
2239
+ case "string": {
2240
+ yield v.toString();
2241
+ break;
2242
+ }
2243
+ case "object": {
2244
+ if (v === null) break;
2245
+ if (Array.isArray(v)) {
2246
+ for (const n of v) yield* formatValue(n, o);
2247
+ break;
2248
+ }
2249
+ switch (v.$$mdtype) {
2250
+ case "Function": {
2251
+ yield* formatFunction(v);
2252
+ break;
2253
+ }
2254
+ case "Node":
2255
+ yield* formatNode(v, o);
2256
+ break;
2257
+ case "Variable": {
2258
+ yield* formatVariable(v);
2259
+ break;
2260
+ }
2261
+ default:
2262
+ throw new Error(`Unimplemented: "${v.$$mdtype}"`);
2263
+ }
2264
+ break;
2265
+ }
2266
+ }
2267
+ }
2268
+ function format(v, options) {
2269
+ let doc = "";
2270
+ for (const s2 of formatValue(v, options)) doc += s2;
2271
+ return doc.trimStart();
2272
+ }
2273
+ class ConditionalAttributeType {
2274
+ validate(value, _config, key) {
2275
+ if (typeof value === "boolean" || value === null || value === void 0 || typeof value === "object") {
2276
+ return [];
2277
+ }
2278
+ return [
2279
+ {
2280
+ id: "attribute-type-invalid",
2281
+ level: "error",
2282
+ message: `Attribute '${key}' must be type 'boolean | object' (null or undefined are also allowed)`
2283
+ }
2284
+ ];
2285
+ }
2286
+ }
2287
+ function truthy(value) {
2288
+ return value !== false && value !== void 0 && value !== null;
2289
+ }
2290
+ function renderConditions(node2) {
2291
+ const conditions = [{ condition: node2.attributes.primary, children: [] }];
2292
+ for (const child of node2.children) {
2293
+ if (child.type === "tag" && child.tag === "else")
2294
+ conditions.push({
2295
+ condition: "primary" in child.attributes ? child.attributes.primary : true,
2296
+ children: []
2297
+ });
2298
+ else conditions[conditions.length - 1].children.push(child);
2299
+ }
2300
+ return conditions;
2301
+ }
2302
+ const tagIf = {
2303
+ attributes: {
2304
+ primary: { type: ConditionalAttributeType, render: false }
2305
+ },
2306
+ transform(node2, config) {
2307
+ const conditions = renderConditions(node2);
2308
+ for (const { condition, children } of conditions)
2309
+ if (truthy(condition)) {
2310
+ const nodes2 = children.flatMap(
2311
+ (child) => child.transform(config)
2312
+ );
2313
+ if (nodes2.some(isPromise)) {
2314
+ return Promise.all(nodes2).then((nodes22) => nodes22.flat());
2315
+ }
2316
+ return nodes2;
2317
+ }
2318
+ return [];
2319
+ }
2320
+ };
2321
+ const tagElse = {
2322
+ selfClosing: true,
2323
+ attributes: {
2324
+ primary: { type: ConditionalAttributeType, render: false }
2325
+ }
2326
+ };
2327
+ const and = {
2328
+ transform(parameters) {
2329
+ return Object.values(parameters).every((x) => truthy(x));
2330
+ }
2331
+ };
2332
+ const or = {
2333
+ transform(parameters) {
2334
+ return Object.values(parameters).find((x) => truthy(x)) !== void 0;
2335
+ }
2336
+ };
2337
+ const not = {
2338
+ parameters: {
2339
+ 0: { required: true }
2340
+ },
2341
+ transform(parameters) {
2342
+ return !truthy(parameters[0]);
2343
+ }
2344
+ };
2345
+ const equals = {
2346
+ transform(parameters) {
2347
+ const values = Object.values(parameters);
2348
+ return values.every((v) => v === values[0]);
2349
+ }
2350
+ };
2351
+ const debug = {
2352
+ transform(parameters) {
2353
+ return JSON.stringify(parameters[0], null, 2);
2354
+ }
2355
+ };
2356
+ const defaultFn = {
2357
+ transform(parameters) {
2358
+ return parameters[0] === void 0 ? parameters[1] : parameters[0];
2359
+ }
2360
+ };
2361
+ const functions = { and, or, not, equals, default: defaultFn, debug };
2362
+ function convertToRow(node2, cellType = "td") {
2363
+ node2.type = "tr";
2364
+ node2.attributes = {};
2365
+ for (const cell of node2.children) cell.type = cellType;
2366
+ return node2;
2367
+ }
2368
+ function transform$1(document2) {
2369
+ for (const node2 of document2.walk()) {
2370
+ if (node2.type !== "tag" || node2.tag !== "table") continue;
2371
+ const [first, ...rest] = node2.children;
2372
+ if (!first || first.type === "table") continue;
2373
+ const table2 = new Ast.Node("table", node2.attributes, [
2374
+ new Ast.Node("thead"),
2375
+ new Ast.Node("tbody")
2376
+ ]);
2377
+ const [thead2, tbody2] = table2.children;
2378
+ if (first.type === "list") thead2.push(convertToRow(first, "th"));
2379
+ for (const row of rest) {
2380
+ if (row.type === "list") convertToRow(row);
2381
+ else if (row.type === "tag" && row.tag === "if") {
2382
+ const children = [];
2383
+ for (const child of row.children) {
2384
+ if (child.type === "hr") continue;
2385
+ if (child.type === "list") convertToRow(child);
2386
+ children.push(child);
2387
+ }
2388
+ row.children = children;
2389
+ } else continue;
2390
+ tbody2.push(row);
2391
+ }
2392
+ node2.children = [table2];
2393
+ }
2394
+ }
2395
+ const transforms = [transform$1];
2396
+ const mappings = {
2397
+ ordered_list: "list",
2398
+ bullet_list: "list",
2399
+ code_inline: "code",
2400
+ list_item: "item",
2401
+ variable: "text"
2402
+ };
2403
+ function annotate(node2, attributes) {
2404
+ for (const attribute of attributes) {
2405
+ node2.annotations.push(attribute);
2406
+ const { name, value, type } = attribute;
2407
+ if (type === "attribute") {
2408
+ if (node2.attributes[name] !== void 0)
2409
+ node2.errors.push({
2410
+ id: "duplicate-attribute",
2411
+ level: "warning",
2412
+ message: `Attribute '${name}' already set`
2413
+ });
2414
+ node2.attributes[name] = value;
2415
+ }
2416
+ }
2417
+ }
2418
+ function handleAttrs(token, type) {
2419
+ switch (type) {
2420
+ case "heading":
2421
+ return { level: Number((token.tag || "").replace("h", "")) };
2422
+ case "list": {
2423
+ const attrs = token.attrs ? Object.fromEntries(token.attrs) : void 0;
2424
+ const ordered = token.type.startsWith("ordered");
2425
+ return ordered && attrs?.start ? { ordered: true, start: attrs.start, marker: token.markup || "" } : { ordered, marker: token.markup || "" };
2426
+ }
2427
+ case "link": {
2428
+ const attrs = Object.fromEntries(token.attrs || []);
2429
+ return attrs.title ? { href: attrs.href, title: attrs.title } : { href: attrs.href };
2430
+ }
2431
+ case "image": {
2432
+ const attrs = Object.fromEntries(token.attrs || []);
2433
+ return attrs.title ? { alt: token.content || "", src: attrs.src, title: attrs.title } : { alt: token.content || "", src: attrs.src };
2434
+ }
2435
+ case "em":
2436
+ case "strong":
2437
+ return { marker: token.markup };
2438
+ case "text":
2439
+ case "code":
2440
+ case "comment":
2441
+ return { content: (token.meta || {}).variable || token.content || "" };
2442
+ case "fence": {
2443
+ const [language] = (token.info || "").split(" ", 1);
2444
+ return language === "" || language === OPEN$1 ? { content: token.content || "" } : { content: token.content || "", language };
2445
+ }
2446
+ case "td":
2447
+ case "th": {
2448
+ if (token.attrs) {
2449
+ const attrs = Object.fromEntries(token.attrs);
2450
+ let align;
2451
+ if (attrs.style) {
2452
+ if (attrs.style.includes("left")) {
2453
+ align = "left";
2454
+ } else if (attrs.style.includes("center")) {
2455
+ align = "center";
2456
+ } else if (attrs.style.includes("right")) {
2457
+ align = "right";
2458
+ }
2459
+ }
2460
+ if (align) {
2461
+ return { align };
2462
+ }
2463
+ }
2464
+ return {};
2465
+ }
2466
+ default:
2467
+ return {};
2468
+ }
2469
+ }
2470
+ function handleToken(token, nodes2, file, handleSlots, addLocation, inlineParent) {
2471
+ if (token.type === "frontmatter") {
2472
+ nodes2[0].attributes.frontmatter = token.content;
2473
+ return;
2474
+ }
2475
+ if (token.hidden || token.type === "text" && (token.content || "") === "") return;
2476
+ const errors = token.errors || [];
2477
+ const parent = nodes2[nodes2.length - 1];
2478
+ const { tag, attributes, error: error2 } = token.meta || {};
2479
+ if (token.type === "annotation") {
2480
+ if (inlineParent) return annotate(inlineParent, attributes);
2481
+ return parent.errors.push({
2482
+ id: "no-inline-annotations",
2483
+ level: "error",
2484
+ message: `Can't apply inline annotations to '${parent.type}'`
2485
+ });
2486
+ }
2487
+ let typeName = token.type.replace(/_(open|close)$/, "");
2488
+ if (mappings[typeName]) typeName = mappings[typeName];
2489
+ if (typeName === "error") {
2490
+ const { message, location } = error2;
2491
+ errors.push({ id: "parse-error", level: "critical", message, location });
2492
+ }
2493
+ if ((token.nesting || 0) < 0) {
2494
+ if (parent.type === typeName && parent.tag === tag) {
2495
+ if (parent.lines && token.map) parent.lines.push(...token.map);
2496
+ return nodes2.pop();
2497
+ }
2498
+ errors.push({
2499
+ id: "missing-opening",
2500
+ level: "critical",
2501
+ message: `Node '${typeName}' is missing opening`
2502
+ });
2503
+ }
2504
+ const attrs = handleAttrs(token, typeName);
2505
+ const node2 = new Node(typeName, attrs, void 0, tag || void 0);
2506
+ const { position = {} } = token;
2507
+ node2.errors = errors;
2508
+ if (addLocation !== false) {
2509
+ node2.lines = token.map || parent.lines || [];
2510
+ node2.location = {
2511
+ file,
2512
+ start: {
2513
+ line: node2.lines[0],
2514
+ character: position.start
2515
+ },
2516
+ end: {
2517
+ line: node2.lines[1],
2518
+ character: position.end
2519
+ }
2520
+ };
2521
+ }
2522
+ if (inlineParent) node2.inline = true;
2523
+ if (attributes && ["tag", "fence", "image"].includes(typeName)) annotate(node2, attributes);
2524
+ if (handleSlots && tag === "slot" && typeof node2.attributes.primary === "string")
2525
+ parent.slots[node2.attributes.primary] = node2;
2526
+ else parent.push(node2);
2527
+ if ((token.nesting || 0) > 0) nodes2.push(node2);
2528
+ if (!Array.isArray(token.children)) return;
2529
+ if (node2.type === "inline") inlineParent = parent;
2530
+ nodes2.push(node2);
2531
+ const isLeafNode = typeName === "image";
2532
+ if (!isLeafNode) {
2533
+ for (const child of token.children)
2534
+ handleToken(child, nodes2, file, handleSlots, addLocation, inlineParent);
2535
+ }
2536
+ nodes2.pop();
2537
+ }
2538
+ function parser(tokens, args) {
2539
+ const doc = new Node("document");
2540
+ const nodes2 = [doc];
2541
+ if (typeof args === "string") args = { file: args };
2542
+ for (const token of tokens) handleToken(token, nodes2, args?.file, args?.slots, args?.location);
2543
+ if (nodes2.length > 1)
2544
+ for (const node2 of nodes2.slice(1))
2545
+ node2.errors.push({
2546
+ id: "missing-closing",
2547
+ level: "critical",
2548
+ message: `Node '${node2.tag || node2.type}' is missing closing`
2549
+ });
2550
+ for (const transform2 of transforms) transform2(doc);
2551
+ return doc;
2552
+ }
2553
+ const document = {
2554
+ render: "article",
2555
+ children: [
2556
+ "heading",
2557
+ "paragraph",
2558
+ "image",
2559
+ "table",
2560
+ "tag",
2561
+ "fence",
2562
+ "blockquote",
2563
+ "comment",
2564
+ "list",
2565
+ "hr"
2566
+ ],
2567
+ attributes: {
2568
+ frontmatter: { render: false }
2569
+ }
2570
+ };
2571
+ const heading = {
2572
+ children: ["inline"],
2573
+ attributes: {
2574
+ level: { type: Number, render: false, required: true }
2575
+ },
2576
+ transform(node2, config) {
2577
+ return new Tag(
2578
+ `h${node2.attributes["level"]}`,
2579
+ node2.transformAttributes(config),
2580
+ node2.transformChildren(config)
2581
+ );
2582
+ }
2583
+ };
2584
+ const paragraph = {
2585
+ render: "p",
2586
+ children: ["inline"]
2587
+ };
2588
+ const image = {
2589
+ render: "img",
2590
+ attributes: {
2591
+ src: { type: String, required: true },
2592
+ alt: { type: String },
2593
+ title: { type: String }
2594
+ // width/height attributes will need to be to be implemented as an extension to markdown-it
2595
+ }
2596
+ };
2597
+ const fence$1 = {
2598
+ render: "pre",
2599
+ attributes: {
2600
+ content: { type: String, render: false, required: true },
2601
+ language: { type: String, render: "data-language" },
2602
+ process: { type: Boolean, render: false, default: true }
2603
+ },
2604
+ transform(node2, config) {
2605
+ const attributes = node2.transformAttributes(config);
2606
+ const children = node2.children.length ? node2.transformChildren(config) : [node2.attributes.content];
2607
+ return new Tag("pre", attributes, children);
2608
+ }
2609
+ };
2610
+ const blockquote = {
2611
+ render: "blockquote",
2612
+ children: ["heading", "paragraph", "image", "table", "tag", "fence", "blockquote", "list", "hr"]
2613
+ };
2614
+ const item = {
2615
+ render: "li",
2616
+ children: [
2617
+ "inline",
2618
+ "heading",
2619
+ "paragraph",
2620
+ "image",
2621
+ "table",
2622
+ "tag",
2623
+ "fence",
2624
+ "blockquote",
2625
+ "list",
2626
+ "hr"
2627
+ ]
2628
+ };
2629
+ const list = {
2630
+ children: ["item"],
2631
+ attributes: {
2632
+ ordered: { type: Boolean, render: false, required: true },
2633
+ start: { type: Number },
2634
+ marker: { type: String, render: false }
2635
+ },
2636
+ transform(node2, config) {
2637
+ return new Tag(
2638
+ node2.attributes.ordered ? "ol" : "ul",
2639
+ node2.transformAttributes(config),
2640
+ node2.transformChildren(config)
2641
+ );
2642
+ }
2643
+ };
2644
+ const hr = {
2645
+ render: "hr"
2646
+ };
2647
+ const table$1 = {
2648
+ render: "table"
2649
+ };
2650
+ const td = {
2651
+ render: "td",
2652
+ children: [
2653
+ "inline",
2654
+ "heading",
2655
+ "paragraph",
2656
+ "image",
2657
+ "table",
2658
+ "tag",
2659
+ "fence",
2660
+ "blockquote",
2661
+ "list",
2662
+ "hr"
2663
+ ],
2664
+ attributes: {
2665
+ align: { type: String },
2666
+ colspan: { type: Number, render: "colSpan" },
2667
+ rowspan: { type: Number, render: "rowSpan" }
2668
+ }
2669
+ };
2670
+ const th = {
2671
+ render: "th",
2672
+ attributes: {
2673
+ width: { type: String },
2674
+ align: { type: String },
2675
+ colspan: { type: Number, render: "colSpan" },
2676
+ rowspan: { type: Number, render: "rowSpan" }
2677
+ }
2678
+ };
2679
+ const tr = {
2680
+ render: "tr",
2681
+ children: ["th", "td"]
2682
+ };
2683
+ const tbody = {
2684
+ render: "tbody",
2685
+ children: ["tr", "tag"]
2686
+ };
2687
+ const thead = {
2688
+ render: "thead",
2689
+ children: ["tr"]
2690
+ };
2691
+ const strong = {
2692
+ render: "strong",
2693
+ children: ["em", "s", "link", "code", "text", "tag"],
2694
+ attributes: {
2695
+ marker: { type: String, render: false }
2696
+ }
2697
+ };
2698
+ const em = {
2699
+ render: "em",
2700
+ children: ["strong", "s", "link", "code", "text", "tag"],
2701
+ attributes: {
2702
+ marker: { type: String, render: false }
2703
+ }
2704
+ };
2705
+ const s = {
2706
+ render: "s",
2707
+ children: ["strong", "em", "link", "code", "text", "tag"]
2708
+ };
2709
+ const inline$2 = {
2710
+ children: [
2711
+ "strong",
2712
+ "em",
2713
+ "s",
2714
+ "code",
2715
+ "text",
2716
+ "tag",
2717
+ "link",
2718
+ "image",
2719
+ "hardbreak",
2720
+ "softbreak",
2721
+ "comment"
2722
+ ]
2723
+ };
2724
+ const link = {
2725
+ render: "a",
2726
+ children: ["strong", "em", "s", "code", "text", "tag"],
2727
+ attributes: {
2728
+ href: { type: String, required: true },
2729
+ title: { type: String }
2730
+ }
2731
+ };
2732
+ const code = {
2733
+ render: "code",
2734
+ attributes: {
2735
+ content: { type: String, render: false, required: true }
2736
+ },
2737
+ transform(node2, config) {
2738
+ const attributes = node2.transformAttributes(config);
2739
+ return new Tag("code", attributes, [node2.attributes.content]);
2740
+ }
2741
+ };
2742
+ const text = {
2743
+ attributes: {
2744
+ content: { type: String, required: true }
2745
+ },
2746
+ transform(node2) {
2747
+ return node2.attributes.content;
2748
+ }
2749
+ };
2750
+ const hardbreak = {
2751
+ render: "br"
2752
+ };
2753
+ const softbreak = {
2754
+ transform() {
2755
+ return " ";
2756
+ }
2757
+ };
2758
+ const comment = {
2759
+ attributes: {
2760
+ content: { type: String, required: true }
2761
+ }
2762
+ };
2763
+ const error = {};
2764
+ const node = {};
2765
+ const nodes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2766
+ __proto__: null,
2767
+ blockquote,
2768
+ code,
2769
+ comment,
2770
+ document,
2771
+ em,
2772
+ error,
2773
+ fence: fence$1,
2774
+ hardbreak,
2775
+ heading,
2776
+ hr,
2777
+ image,
2778
+ inline: inline$2,
2779
+ item,
2780
+ link,
2781
+ list,
2782
+ node,
2783
+ paragraph,
2784
+ s,
2785
+ softbreak,
2786
+ strong,
2787
+ table: table$1,
2788
+ tbody,
2789
+ td,
2790
+ text,
2791
+ th,
2792
+ thead,
2793
+ tr
2794
+ }, Symbol.toStringTag, { value: "Module" }));
2795
+ const { escapeHtml } = MarkdownIt().utils;
2796
+ const voidElements = /* @__PURE__ */ new Set([
2797
+ "area",
2798
+ "base",
2799
+ "br",
2800
+ "col",
2801
+ "embed",
2802
+ "hr",
2803
+ "img",
2804
+ "input",
2805
+ "link",
2806
+ "meta",
2807
+ "param",
2808
+ "source",
2809
+ "track",
2810
+ "wbr"
2811
+ ]);
2812
+ function render(node2) {
2813
+ if (typeof node2 === "string" || typeof node2 === "number") return escapeHtml(String(node2));
2814
+ if (Array.isArray(node2)) return node2.map(render).join("");
2815
+ if (node2 === null || typeof node2 !== "object" || !Tag.isTag(node2)) return "";
2816
+ const { name, attributes, children = [] } = node2;
2817
+ if (!name) return render(children);
2818
+ let output = `<${name}`;
2819
+ for (const [k, v] of Object.entries(attributes ?? {}))
2820
+ output += ` ${k.toLowerCase()}="${escapeHtml(String(v))}"`;
2821
+ output += ">";
2822
+ if (voidElements.has(name)) return output;
2823
+ if (children.length) output += render(children);
2824
+ output += `</${name}>`;
2825
+ return output;
2826
+ }
2827
+ const renderers = { html: render };
2828
+ class PartialFile {
2829
+ validate(file, config) {
2830
+ const { partials = {} } = config;
2831
+ const partial2 = partials[file];
2832
+ if (!partial2)
2833
+ return [
2834
+ {
2835
+ id: "attribute-value-invalid",
2836
+ level: "error",
2837
+ message: `Partial \`${file}\` not found. The 'file' attribute must be set in \`config.partials\``
2838
+ }
2839
+ ];
2840
+ return [];
2841
+ }
2842
+ }
2843
+ const partial = {
2844
+ inline: false,
2845
+ selfClosing: true,
2846
+ attributes: {
2847
+ file: { type: PartialFile, render: false, required: true },
2848
+ variables: { type: Object, render: false }
2849
+ },
2850
+ transform(node2, config) {
2851
+ const { partials = {} } = config;
2852
+ const { file, variables } = node2.attributes;
2853
+ const partial2 = partials[file];
2854
+ if (!partial2) return null;
2855
+ const scopedConfig = {
2856
+ ...config,
2857
+ variables: {
2858
+ ...config.variables,
2859
+ ...variables,
2860
+ ["$$partial:filename"]: file
2861
+ }
2862
+ };
2863
+ const transformChildren = (part) => part.resolve(scopedConfig).transformChildren(scopedConfig);
2864
+ return Array.isArray(partial2) ? partial2.flatMap(transformChildren) : transformChildren(partial2);
2865
+ }
2866
+ };
2867
+ const table = {
2868
+ children: ["table"],
2869
+ inline: false
2870
+ };
2871
+ const slot = {
2872
+ attributes: {
2873
+ primary: { type: String, required: true }
2874
+ }
2875
+ };
2876
+ const tags = {
2877
+ else: tagElse,
2878
+ if: tagIf,
2879
+ partial,
2880
+ slot,
2881
+ table
2882
+ };
2883
+ function createToken(state, content, contentStart) {
2884
+ try {
2885
+ const { type, meta, nesting = 0 } = peg$parse(content, { Variable, Function: Function$1 });
2886
+ const token = state.push(type, "", nesting);
2887
+ token.info = content;
2888
+ token.meta = meta;
2889
+ if ("delimiters" in state && !state.delimiters) {
2890
+ state.delimiters = [];
2891
+ }
2892
+ return token;
2893
+ } catch (error2) {
2894
+ if (!(error2 instanceof peg$SyntaxError)) throw error2;
2895
+ const {
2896
+ message,
2897
+ location: { start, end }
2898
+ } = error2;
2899
+ const location = contentStart ? {
2900
+ start: { offset: start.offset + contentStart },
2901
+ end: { offset: end.offset + contentStart }
2902
+ } : null;
2903
+ const token = state.push("error", "", 0);
2904
+ token.meta = { error: { message, location } };
2905
+ return token;
2906
+ }
2907
+ }
2908
+ function block$2(state, startLine, endLine, silent) {
2909
+ const start = state.bMarks[startLine] + state.tShift[startLine];
2910
+ const finish = state.eMarks[startLine];
2911
+ if (!state.src.startsWith(OPEN$1, start)) return false;
2912
+ const tagEnd = findTagEnd(state.src, start);
2913
+ const lastPossible = state.src.slice(0, finish).trim().length;
2914
+ if (!tagEnd || tagEnd < lastPossible - CLOSE$1.length) return false;
2915
+ const contentStart = start + OPEN$1.length;
2916
+ const content = state.src.slice(contentStart, tagEnd).trim();
2917
+ const lines = state.src.slice(start, tagEnd + CLOSE$1.length).split("\n").length;
2918
+ if (content[0] === "$") return false;
2919
+ if (silent) return true;
2920
+ const token = createToken(state, content, contentStart);
2921
+ token.map = [startLine, startLine + lines];
2922
+ state.line += lines;
2923
+ return true;
2924
+ }
2925
+ function inline$1(state, silent) {
2926
+ if (!state.src.startsWith(OPEN$1, state.pos)) return false;
2927
+ const tagEnd = findTagEnd(state.src, state.pos);
2928
+ if (!tagEnd) return false;
2929
+ const content = state.src.slice(state.pos + OPEN$1.length, tagEnd);
2930
+ if (!silent) createToken(state, content.trim());
2931
+ state.pos = tagEnd + CLOSE$1.length;
2932
+ return true;
2933
+ }
2934
+ function core(state) {
2935
+ let token;
2936
+ for (token of state.tokens) {
2937
+ if (token.type !== "fence") continue;
2938
+ const info = token.info || "";
2939
+ if (info.includes(OPEN$1)) {
2940
+ const start = info.indexOf(OPEN$1);
2941
+ const end = findTagEnd(info, start);
2942
+ if (end == null) continue;
2943
+ const content = info.slice(start + OPEN$1.length, end);
2944
+ try {
2945
+ const { meta } = peg$parse(content.trim(), { Variable, Function: Function$1 });
2946
+ token.meta = meta;
2947
+ } catch (error2) {
2948
+ if (!(error2 instanceof peg$SyntaxError)) throw error2;
2949
+ if (!token.errors) token.errors = [];
2950
+ token.errors.push({
2951
+ id: "fence-tag-error",
2952
+ level: "error",
2953
+ message: `Syntax error in fence tag: ${error2.message}`
2954
+ });
2955
+ }
2956
+ }
2957
+ if (token?.meta?.attributes?.find(
2958
+ (attr) => attr.name === "process" && !attr.value
2959
+ ))
2960
+ continue;
2961
+ token.children = parseTags(token.content || "", token.map?.[0] || 0);
2962
+ }
2963
+ }
2964
+ function plugin$2(md) {
2965
+ md.block.ruler.before("paragraph", "annotations", block$2, {
2966
+ alt: ["paragraph", "blockquote"]
2967
+ });
2968
+ md.inline.ruler.push("containers", inline$1);
2969
+ md.core.ruler.push("annotations", core);
2970
+ }
2971
+ const fence = "---";
2972
+ function getLine(state, n) {
2973
+ return state.src.slice(state.bMarks[n], state.eMarks[n]).trim();
2974
+ }
2975
+ function findClose(state, endLine) {
2976
+ for (let line = 1; line < endLine; line++) if (getLine(state, line) === fence) return line;
2977
+ }
2978
+ function block$1(state, startLine, endLine, silent) {
2979
+ if (startLine != 0 || getLine(state, 0) != fence) return false;
2980
+ const close = findClose(state, endLine);
2981
+ if (!close) return false;
2982
+ if (silent) return true;
2983
+ const token = state.push("frontmatter", "", 0);
2984
+ token.content = state.src.slice(state.eMarks[0], state.bMarks[close]).trim();
2985
+ token.map = [0, close];
2986
+ token.hidden = true;
2987
+ state.line = close + 1;
2988
+ return true;
2989
+ }
2990
+ function plugin$1(md) {
2991
+ md.block.ruler.before("hr", "frontmatter", block$1);
2992
+ }
2993
+ const OPEN = "<!--";
2994
+ const CLOSE = "-->";
2995
+ function block(state, startLine, endLine, silent) {
2996
+ const start = state.bMarks[startLine] + state.tShift[startLine];
2997
+ if (!state.src.startsWith(OPEN, start)) return false;
2998
+ const close = state.src.indexOf(CLOSE, start);
2999
+ if (close === -1) return false;
3000
+ if (silent) return true;
3001
+ const content = state.src.slice(start + OPEN.length, close);
3002
+ const lines = content.split("\n").length;
3003
+ const token = state.push("comment", "", 0);
3004
+ token.content = content.trim();
3005
+ token.map = [startLine, startLine + lines];
3006
+ state.line += lines;
3007
+ return true;
3008
+ }
3009
+ function inline(state, silent) {
3010
+ if (!state.src.startsWith(OPEN, state.pos)) return false;
3011
+ const close = state.src.indexOf(CLOSE, state.pos);
3012
+ if (close === -1) return false;
3013
+ if (silent) return true;
3014
+ const content = state.src.slice(state.pos + OPEN.length, close);
3015
+ const token = state.push("comment", "", 0);
3016
+ token.content = content.trim();
3017
+ state.pos = close + CLOSE.length;
3018
+ return true;
3019
+ }
3020
+ function plugin(md) {
3021
+ md.block.ruler.before("table", "comment", block, { alt: ["paragraph"] });
3022
+ md.inline.ruler.push("comment", inline);
3023
+ }
3024
+ class Tokenizer {
3025
+ constructor(config = {}) {
3026
+ this.parser = new MarkdownIt$1(config);
3027
+ this.parser.use(plugin$2, "annotations", {});
3028
+ this.parser.use(plugin$1, "frontmatter", {});
3029
+ this.parser.disable([
3030
+ "lheading",
3031
+ // Disable indented `code_block` support https://spec.commonmark.org/0.30/#indented-code-block
3032
+ "code"
3033
+ ]);
3034
+ if (config.allowComments) this.parser.use(plugin, "comments", {});
3035
+ }
3036
+ tokenize(content) {
3037
+ return this.parser.parse(content.toString(), {});
3038
+ }
3039
+ }
3040
+ const TypeMappings = {
3041
+ String,
3042
+ Number,
3043
+ Array,
3044
+ Object,
3045
+ Boolean
3046
+ };
3047
+ function validateType(type, value, config, key) {
3048
+ if (!type) return true;
3049
+ if (Ast.isFunction(value) && config.validation?.validateFunctions) {
3050
+ const schema = config.functions?.[value.name];
3051
+ return !schema?.returns ? true : Array.isArray(schema.returns) ? schema.returns.find((t) => t === type) !== void 0 : schema.returns === type;
3052
+ }
3053
+ if (Ast.isAst(value)) return true;
3054
+ if (Array.isArray(type)) return type.some((t) => validateType(t, value, config, key));
3055
+ if (typeof type === "string") type = TypeMappings[type];
3056
+ if (typeof type === "function") {
3057
+ const instance = new type();
3058
+ if (instance.validate) {
3059
+ return instance.validate(value, config, key);
3060
+ }
3061
+ }
3062
+ return value != null && value.constructor === type;
3063
+ }
3064
+ function typeToString(type) {
3065
+ if (typeof type === "string") return type;
3066
+ if (Array.isArray(type)) return type.map(typeToString).join(" | ");
3067
+ return type.name;
3068
+ }
3069
+ function validateFunction(fn, config) {
3070
+ const schema = config.functions?.[fn.name];
3071
+ const errors = [];
3072
+ if (!schema)
3073
+ return [
3074
+ {
3075
+ id: "function-undefined",
3076
+ level: "critical",
3077
+ message: `Undefined function: '${fn.name}'`
3078
+ }
3079
+ ];
3080
+ if (schema.validate) errors.push(...schema.validate(fn, config));
3081
+ if (schema.parameters) {
3082
+ for (const [key, value] of Object.entries(fn.parameters)) {
3083
+ const param = schema.parameters?.[key];
3084
+ if (!param) {
3085
+ errors.push({
3086
+ id: "parameter-undefined",
3087
+ level: "error",
3088
+ message: `Invalid parameter: '${key}'`
3089
+ });
3090
+ continue;
3091
+ }
3092
+ if (Ast.isAst(value) && !Ast.isFunction(value)) continue;
3093
+ if (param.type) {
3094
+ const valid = validateType(param.type, value, config, key);
3095
+ if (valid === false) {
3096
+ errors.push({
3097
+ id: "parameter-type-invalid",
3098
+ level: "error",
3099
+ message: `Parameter '${key}' of '${fn.name}' must be type of '${typeToString(param.type)}'`
3100
+ });
3101
+ } else if (Array.isArray(valid)) {
3102
+ errors.push(...valid);
3103
+ }
3104
+ }
3105
+ }
3106
+ }
3107
+ for (const [key, { required }] of Object.entries(schema.parameters ?? {}))
3108
+ if (required && fn.parameters[key] === void 0)
3109
+ errors.push({
3110
+ id: "parameter-missing-required",
3111
+ level: "error",
3112
+ message: `Missing required parameter: '${key}'`
3113
+ });
3114
+ return errors;
3115
+ }
3116
+ function displayMatches(matches, n) {
3117
+ if (matches.length <= n) return JSON.stringify(matches);
3118
+ const items = matches.slice(0, n).map((item2) => JSON.stringify(item2));
3119
+ return `[${items.join(",")}, ... ${matches.length - n} more]`;
3120
+ }
3121
+ function validator(node2, config) {
3122
+ const schema = node2.findSchema(config);
3123
+ const errors = [...node2.errors || []];
3124
+ if (!schema) {
3125
+ errors.push({
3126
+ id: node2.tag ? "tag-undefined" : "node-undefined",
3127
+ level: "critical",
3128
+ message: node2.tag ? `Undefined tag: '${node2.tag}'` : `Undefined node: '${node2.type}'`
3129
+ });
3130
+ return errors;
3131
+ }
3132
+ if (schema.inline != void 0 && node2.inline !== schema.inline)
3133
+ errors.push({
3134
+ id: "tag-placement-invalid",
3135
+ level: "critical",
3136
+ message: `'${node2.tag}' tag should be ${schema.inline ? "inline" : "block"}`
3137
+ });
3138
+ if (schema.selfClosing && node2.children.length > 0)
3139
+ errors.push({
3140
+ id: "tag-selfclosing-has-children",
3141
+ level: "critical",
3142
+ message: `'${node2.tag}' tag should be self-closing`
3143
+ });
3144
+ const attributes = {
3145
+ ...schema.attributes
3146
+ };
3147
+ for (const key of Object.keys(node2.slots)) {
3148
+ const slot2 = schema.slots?.[key];
3149
+ if (!slot2)
3150
+ errors.push({
3151
+ id: "slot-undefined",
3152
+ level: "error",
3153
+ message: `Invalid slot: '${key}'`
3154
+ });
3155
+ }
3156
+ for (let [key, value] of Object.entries(node2.attributes)) {
3157
+ const attrib = attributes[key];
3158
+ if (!attrib) {
3159
+ errors.push({
3160
+ id: "attribute-undefined",
3161
+ level: "error",
3162
+ message: `Invalid attribute: '${key}'`
3163
+ });
3164
+ continue;
3165
+ }
3166
+ let { type, matches, errorLevel } = attrib;
3167
+ if (Ast.isAst(value)) {
3168
+ if (Ast.isFunction(value) && config.validation?.validateFunctions)
3169
+ errors.push(...validateFunction(value, config));
3170
+ else if (Ast.isVariable(value) && config.variables) {
3171
+ let missing = false;
3172
+ let variables = config.variables;
3173
+ for (const key2 of value.path) {
3174
+ if (!Object.prototype.hasOwnProperty.call(variables, key2)) {
3175
+ missing = true;
3176
+ break;
3177
+ }
3178
+ variables = variables[key2];
3179
+ }
3180
+ if (missing) {
3181
+ errors.push({
3182
+ id: "variable-undefined",
3183
+ level: "error",
3184
+ message: `Undefined variable: '${value.path.join(".")}'`
3185
+ });
3186
+ }
3187
+ } else continue;
3188
+ }
3189
+ value = value;
3190
+ if (type) {
3191
+ const valid = validateType(type, value, config, key);
3192
+ if (valid === false) {
3193
+ errors.push({
3194
+ id: "attribute-type-invalid",
3195
+ level: errorLevel || "error",
3196
+ message: `Attribute '${key}' must be type of '${typeToString(type)}'`
3197
+ });
3198
+ }
3199
+ if (Array.isArray(valid)) {
3200
+ errors.push(...valid);
3201
+ }
3202
+ }
3203
+ if (typeof matches === "function") matches = matches(config);
3204
+ if (Array.isArray(matches) && !matches.includes(value))
3205
+ errors.push({
3206
+ id: "attribute-value-invalid",
3207
+ level: errorLevel || "error",
3208
+ message: `Attribute '${key}' must match one of ${displayMatches(
3209
+ matches,
3210
+ 8
3211
+ )}. Got '${value}' instead.`
3212
+ });
3213
+ if (matches instanceof RegExp && !matches.test(value))
3214
+ errors.push({
3215
+ id: "attribute-value-invalid",
3216
+ level: errorLevel || "error",
3217
+ message: `Attribute '${key}' must match ${matches}. Got '${value}' instead.`
3218
+ });
3219
+ if (typeof attrib.validate === "function") {
3220
+ const attribErrors = attrib.validate(value, config, key);
3221
+ if (Array.isArray(attribErrors)) errors.push(...attribErrors);
3222
+ }
3223
+ }
3224
+ for (const [key, { required }] of Object.entries(attributes))
3225
+ if (required && node2.attributes[key] === void 0)
3226
+ errors.push({
3227
+ id: "attribute-missing-required",
3228
+ level: "error",
3229
+ message: `Missing required attribute: '${key}'`
3230
+ });
3231
+ if (schema.slots) {
3232
+ for (const [key, { required }] of Object.entries(schema.slots))
3233
+ if (required && node2.slots[key] === void 0)
3234
+ errors.push({
3235
+ id: "slot-missing-required",
3236
+ level: "error",
3237
+ message: `Missing required slot: '${key}'`
3238
+ });
3239
+ }
3240
+ for (const { type } of node2.children) {
3241
+ if (schema.children && type !== "error" && !schema.children.includes(type))
3242
+ errors.push({
3243
+ id: "child-invalid",
3244
+ level: "warning",
3245
+ message: `Can't nest '${type}' in '${node2.tag || node2.type}'`
3246
+ });
3247
+ }
3248
+ if (schema.validate) {
3249
+ const schemaErrors = schema.validate(node2, config);
3250
+ if (isPromise(schemaErrors)) {
3251
+ return schemaErrors.then((e) => errors.concat(e));
3252
+ }
3253
+ errors.push(...schemaErrors);
3254
+ }
3255
+ return errors;
3256
+ }
3257
+ function* walkWithParents(node2, parents = []) {
3258
+ yield [node2, parents];
3259
+ for (const child of [...Object.values(node2.slots), ...node2.children])
3260
+ yield* walkWithParents(child, [...parents, node2]);
3261
+ }
3262
+ function validateTree(content, config) {
3263
+ const output = [...walkWithParents(content)].map(([node2, parents]) => {
3264
+ const { type, lines, location } = node2;
3265
+ const updatedConfig = {
3266
+ ...config,
3267
+ validation: { ...config.validation, parents }
3268
+ };
3269
+ const errors = validator(node2, updatedConfig);
3270
+ if (isPromise(errors)) {
3271
+ return errors.then((e) => e.map((error2) => ({ type, lines, location, error: error2 })));
3272
+ }
3273
+ return errors.map((error2) => ({ type, lines, location, error: error2 }));
3274
+ });
3275
+ if (output.some(isPromise)) {
3276
+ return Promise.all(output).then((o) => o.flat());
3277
+ }
3278
+ return output.flat();
3279
+ }
3280
+ const tokenizer = new Tokenizer();
3281
+ function mergeConfig(config = {}) {
3282
+ return {
3283
+ ...config,
3284
+ tags: {
3285
+ ...tags,
3286
+ ...config.tags
3287
+ },
3288
+ nodes: {
3289
+ ...nodes,
3290
+ ...config.nodes
3291
+ },
3292
+ functions: {
3293
+ ...functions,
3294
+ ...config.functions
3295
+ }
3296
+ };
3297
+ }
3298
+ function parse(content, args) {
3299
+ if (typeof content === "string") content = tokenizer.tokenize(content);
3300
+ return parser(content, args);
3301
+ }
3302
+ function resolve(content, config) {
3303
+ if (Array.isArray(content)) return content.flatMap((child) => child.resolve(config));
3304
+ return content.resolve(config);
3305
+ }
3306
+ function transform(nodes2, options) {
3307
+ const config = mergeConfig(options);
3308
+ const content = resolve(nodes2, config);
3309
+ if (Array.isArray(content)) return content.flatMap((child) => child.transform(config));
3310
+ return content.transform(config);
3311
+ }
3312
+ function validate(content, options) {
3313
+ const config = mergeConfig(options);
3314
+ return validateTree(content, config);
3315
+ }
3316
+ function createElement(name, attributes = {}, ...children) {
3317
+ return { name, attributes, children };
3318
+ }
3319
+ const _Markdoc = class _Markdoc {
3320
+ constructor(config) {
3321
+ this.parse = parse;
3322
+ this.resolve = (content) => resolve(content, this.config);
3323
+ this.transform = (content) => transform(content, this.config);
3324
+ this.validate = (content) => validate(content, this.config);
3325
+ this.config = config;
3326
+ }
3327
+ };
3328
+ _Markdoc.nodes = nodes;
3329
+ _Markdoc.tags = tags;
3330
+ _Markdoc.functions = functions;
3331
+ _Markdoc.renderers = renderers;
3332
+ _Markdoc.transforms = transforms;
3333
+ _Markdoc.Ast = Ast;
3334
+ _Markdoc.Tag = Tag;
3335
+ _Markdoc.Tokenizer = Tokenizer;
3336
+ _Markdoc.parseTags = parseTags;
3337
+ _Markdoc.transformer = transformer;
3338
+ _Markdoc.validator = validator;
3339
+ _Markdoc.parse = parse;
3340
+ _Markdoc.transform = transform;
3341
+ _Markdoc.validate = validate;
3342
+ _Markdoc.createElement = createElement;
3343
+ _Markdoc.truthy = truthy;
3344
+ _Markdoc.format = format;
3345
+ let Markdoc = _Markdoc;
3346
+ export {
3347
+ Ast,
3348
+ Node,
3349
+ Tag,
3350
+ Tokenizer,
3351
+ createElement,
3352
+ Markdoc as default,
3353
+ format,
3354
+ functions,
3355
+ nodes,
3356
+ parse,
3357
+ parseTags,
3358
+ renderers,
3359
+ resolve,
3360
+ tags,
3361
+ transform,
3362
+ transformer,
3363
+ transforms,
3364
+ truthy,
3365
+ validate,
3366
+ validator
3367
+ };
3368
+ //# sourceMappingURL=index.js.map