ember-repl 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +2 -404
  3. package/config/.try.mjs +87 -0
  4. package/config/addon-main.cjs +7 -0
  5. package/config/attw.json +7 -0
  6. package/config/babel.publish.config.cjs +29 -0
  7. package/config/ember-cli-update.json +21 -0
  8. package/config/rollup.config.mjs +44 -0
  9. package/config/testem.cjs +35 -0
  10. package/config/tsconfig.publish.json +18 -0
  11. package/config/vite.config.mjs +36 -0
  12. package/declarations/compile/Compiled.d.ts +7 -0
  13. package/declarations/compile/Compiled.d.ts.map +1 -0
  14. package/declarations/compile/compile.d.ts +17 -0
  15. package/declarations/compile/compile.d.ts.map +1 -0
  16. package/declarations/compile/state.d.ts +43 -0
  17. package/declarations/compile/state.d.ts.map +1 -0
  18. package/declarations/compile/types.d.ts +5 -12
  19. package/declarations/compile/types.d.ts.map +1 -1
  20. package/declarations/index.d.ts +6 -2
  21. package/declarations/index.d.ts.map +1 -1
  22. package/declarations/services/compiler.d.ts +94 -0
  23. package/declarations/services/compiler.d.ts.map +1 -0
  24. package/declarations/services/known-modules.d.ts +7 -0
  25. package/declarations/services/known-modules.d.ts.map +1 -0
  26. package/declarations/setup.d.ts +7 -0
  27. package/declarations/setup.d.ts.map +1 -0
  28. package/declarations/test-support.d.ts +20 -0
  29. package/declarations/test-support.d.ts.map +1 -0
  30. package/dist/_commonjsHelpers-BAGoDD49.js +37 -0
  31. package/dist/_commonjsHelpers-BAGoDD49.js.map +1 -0
  32. package/dist/babel-8wMrbxkT.js +110427 -0
  33. package/dist/babel-8wMrbxkT.js.map +1 -0
  34. package/dist/blank-line-Bzg2Qt4K.js +482 -0
  35. package/dist/blank-line-Bzg2Qt4K.js.map +1 -0
  36. package/dist/compile/Compiled.js +26 -0
  37. package/dist/compile/Compiled.js.map +1 -0
  38. package/dist/compile/compile.js +62 -0
  39. package/dist/compile/compile.js.map +1 -0
  40. package/dist/compile/state.js +75 -0
  41. package/dist/compile/state.js.map +1 -0
  42. package/dist/compile/utils.js +213 -2
  43. package/dist/compile/utils.js.map +1 -1
  44. package/dist/default-CoqAuVeH.js +4 -0
  45. package/dist/default-CoqAuVeH.js.map +1 -0
  46. package/dist/index-BTx1k6gT.js +323 -0
  47. package/dist/index-BTx1k6gT.js.map +1 -0
  48. package/dist/index-Bxzjtr16.js +87 -0
  49. package/dist/index-Bxzjtr16.js.map +1 -0
  50. package/dist/index-C371bO_b.js +1553 -0
  51. package/dist/index-C371bO_b.js.map +1 -0
  52. package/dist/index-C4AyeeIa.js +5721 -0
  53. package/dist/index-C4AyeeIa.js.map +1 -0
  54. package/dist/index-C8S2G0FH.js +1953 -0
  55. package/dist/index-C8S2G0FH.js.map +1 -0
  56. package/dist/index-CCcIVEUK.js +409 -0
  57. package/dist/index-CCcIVEUK.js.map +1 -0
  58. package/dist/index-CDSIcg03.js +9070 -0
  59. package/dist/index-CDSIcg03.js.map +1 -0
  60. package/dist/index-D8szzCn3.js +2 -0
  61. package/dist/index-D8szzCn3.js.map +1 -0
  62. package/dist/index-DBBNT106.js +2644 -0
  63. package/dist/index-DBBNT106.js.map +1 -0
  64. package/dist/index-DP_Su7Zc.js +362 -0
  65. package/dist/index-DP_Su7Zc.js.map +1 -0
  66. package/dist/index-DejgrVqh.js +11299 -0
  67. package/dist/index-DejgrVqh.js.map +1 -0
  68. package/dist/index-Dr5iYoKt.js +1551 -0
  69. package/dist/index-Dr5iYoKt.js.map +1 -0
  70. package/dist/index-DxolpiGq.js +3336 -0
  71. package/dist/index-DxolpiGq.js.map +1 -0
  72. package/dist/index-ZyJlPFQY.js +249 -0
  73. package/dist/index-ZyJlPFQY.js.map +1 -0
  74. package/dist/index-k6CfLgeq.js +26 -0
  75. package/dist/index-k6CfLgeq.js.map +1 -0
  76. package/dist/index.js +4 -1
  77. package/dist/index.js.map +1 -1
  78. package/dist/services/compiler.js +329 -0
  79. package/dist/services/compiler.js.map +1 -0
  80. package/dist/services/known-modules.js +123 -0
  81. package/dist/services/known-modules.js.map +1 -0
  82. package/dist/setup.js +15 -0
  83. package/dist/setup.js.map +1 -0
  84. package/dist/test-support.js +33 -0
  85. package/dist/test-support.js.map +1 -0
  86. package/package.json +117 -138
  87. package/src/compile/Compiled.ts +45 -0
  88. package/src/compile/compile.ts +89 -0
  89. package/src/compile/state.ts +88 -0
  90. package/src/compile/types.ts +14 -13
  91. package/src/index.ts +6 -2
  92. package/src/services/compiler.ts +401 -0
  93. package/src/services/known-modules.ts +130 -0
  94. package/src/setup.ts +26 -0
  95. package/src/test-support.ts +64 -0
  96. package/addon-main.cjs +0 -5
  97. package/declarations/__PRIVATE__.d.ts +0 -2
  98. package/declarations/__PRIVATE__.d.ts.map +0 -1
  99. package/declarations/compile/formats/gjs/babel.d.ts +0 -7
  100. package/declarations/compile/formats/gjs/babel.d.ts.map +0 -1
  101. package/declarations/compile/formats/gjs/eval.d.ts +0 -8
  102. package/declarations/compile/formats/gjs/eval.d.ts.map +0 -1
  103. package/declarations/compile/formats/gjs/index.d.ts +0 -24
  104. package/declarations/compile/formats/gjs/index.d.ts.map +0 -1
  105. package/declarations/compile/formats/gjs/known-modules.d.ts +0 -48
  106. package/declarations/compile/formats/gjs/known-modules.d.ts.map +0 -1
  107. package/declarations/compile/formats/hbs.d.ts +0 -17
  108. package/declarations/compile/formats/hbs.d.ts.map +0 -1
  109. package/declarations/compile/formats/markdown.d.ts +0 -22
  110. package/declarations/compile/formats/markdown.d.ts.map +0 -1
  111. package/declarations/compile/formats.d.ts +0 -17
  112. package/declarations/compile/formats.d.ts.map +0 -1
  113. package/declarations/compile/index.d.ts +0 -80
  114. package/declarations/compile/index.d.ts.map +0 -1
  115. package/declarations/test-support/index.d.ts +0 -2
  116. package/declarations/test-support/index.d.ts.map +0 -1
  117. package/dist/__PRIVATE__.js +0 -2
  118. package/dist/__PRIVATE__.js.map +0 -1
  119. package/dist/compile/formats/gjs/babel.js +0 -2
  120. package/dist/compile/formats/gjs/babel.js.map +0 -1
  121. package/dist/compile/formats/gjs/eval.js +0 -19
  122. package/dist/compile/formats/gjs/eval.js.map +0 -1
  123. package/dist/compile/formats/gjs/index.js +0 -122
  124. package/dist/compile/formats/gjs/index.js.map +0 -1
  125. package/dist/compile/formats/gjs/known-modules.js +0 -52
  126. package/dist/compile/formats/gjs/known-modules.js.map +0 -1
  127. package/dist/compile/formats/hbs.js +0 -93
  128. package/dist/compile/formats/hbs.js.map +0 -1
  129. package/dist/compile/formats/markdown.js +0 -266
  130. package/dist/compile/formats/markdown.js.map +0 -1
  131. package/dist/compile/formats.js +0 -173
  132. package/dist/compile/formats.js.map +0 -1
  133. package/dist/compile/index.js +0 -113
  134. package/dist/compile/index.js.map +0 -1
  135. package/dist/test-support/index.js +0 -8
  136. package/dist/test-support/index.js.map +0 -1
  137. package/src/__PRIVATE__.ts +0 -1
  138. package/src/compile/formats/gjs/babel.ts +0 -7
  139. package/src/compile/formats/gjs/eval.ts +0 -29
  140. package/src/compile/formats/gjs/index.ts +0 -153
  141. package/src/compile/formats/gjs/known-modules.ts +0 -49
  142. package/src/compile/formats/hbs.ts +0 -100
  143. package/src/compile/formats/markdown.ts +0 -345
  144. package/src/compile/formats.ts +0 -178
  145. package/src/compile/index.ts +0 -219
  146. package/src/test-support/index.ts +0 -5
@@ -0,0 +1,1953 @@
1
+ import { p as pointStart, a as pointEnd, s as structuredClone, b as position } from './index-DP_Su7Zc.js';
2
+ import { b as asciiAlphanumeric } from './index-ZyJlPFQY.js';
3
+ import { v as visit } from './index-CCcIVEUK.js';
4
+
5
+ /**
6
+ * Normalize a URL.
7
+ *
8
+ * Encode unsafe characters with percent-encoding, skipping already encoded
9
+ * sequences.
10
+ *
11
+ * @param {string} value
12
+ * URI to normalize.
13
+ * @returns {string}
14
+ * Normalized URI.
15
+ */
16
+ function normalizeUri(value) {
17
+ /** @type {Array<string>} */
18
+ const result = [];
19
+ let index = -1;
20
+ let start = 0;
21
+ let skip = 0;
22
+ while (++index < value.length) {
23
+ const code = value.charCodeAt(index);
24
+ /** @type {string} */
25
+ let replace = '';
26
+
27
+ // A correct percent encoded value.
28
+ if (code === 37 && asciiAlphanumeric(value.charCodeAt(index + 1)) && asciiAlphanumeric(value.charCodeAt(index + 2))) {
29
+ skip = 2;
30
+ }
31
+ // ASCII.
32
+ else if (code < 128) {
33
+ if (!/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(code))) {
34
+ replace = String.fromCharCode(code);
35
+ }
36
+ }
37
+ // Astral.
38
+ else if (code > 55_295 && code < 57_344) {
39
+ const next = value.charCodeAt(index + 1);
40
+
41
+ // A correct surrogate pair.
42
+ if (code < 56_320 && next > 56_319 && next < 57_344) {
43
+ replace = String.fromCharCode(code, next);
44
+ skip = 1;
45
+ }
46
+ // Lone surrogate.
47
+ else {
48
+ replace = "\uFFFD";
49
+ }
50
+ }
51
+ // Unicode.
52
+ else {
53
+ replace = String.fromCharCode(code);
54
+ }
55
+ if (replace) {
56
+ result.push(value.slice(start, index), encodeURIComponent(replace));
57
+ start = index + skip + 1;
58
+ replace = '';
59
+ }
60
+ if (skip) {
61
+ index += skip;
62
+ skip = 0;
63
+ }
64
+ }
65
+ return result.join('') + value.slice(start);
66
+ }
67
+
68
+ /**
69
+ * @typedef {import('hast').Element} Element
70
+ * @typedef {import('mdast').Blockquote} Blockquote
71
+ * @typedef {import('../state.js').State} State
72
+ */
73
+
74
+
75
+ /**
76
+ * Turn an mdast `blockquote` node into hast.
77
+ *
78
+ * @param {State} state
79
+ * Info passed around.
80
+ * @param {Blockquote} node
81
+ * mdast node.
82
+ * @returns {Element}
83
+ * hast node.
84
+ */
85
+ function blockquote(state, node) {
86
+ /** @type {Element} */
87
+ const result = {
88
+ type: 'element',
89
+ tagName: 'blockquote',
90
+ properties: {},
91
+ children: state.wrap(state.all(node), true)
92
+ };
93
+ state.patch(node, result);
94
+ return state.applyData(node, result);
95
+ }
96
+
97
+ /**
98
+ * @typedef {import('hast').Element} Element
99
+ * @typedef {import('hast').Text} Text
100
+ * @typedef {import('mdast').Break} Break
101
+ * @typedef {import('../state.js').State} State
102
+ */
103
+
104
+
105
+ /**
106
+ * Turn an mdast `break` node into hast.
107
+ *
108
+ * @param {State} state
109
+ * Info passed around.
110
+ * @param {Break} node
111
+ * mdast node.
112
+ * @returns {Array<Element | Text>}
113
+ * hast element content.
114
+ */
115
+ function hardBreak(state, node) {
116
+ /** @type {Element} */
117
+ const result = {
118
+ type: 'element',
119
+ tagName: 'br',
120
+ properties: {},
121
+ children: []
122
+ };
123
+ state.patch(node, result);
124
+ return [state.applyData(node, result), {
125
+ type: 'text',
126
+ value: '\n'
127
+ }];
128
+ }
129
+
130
+ /**
131
+ * @typedef {import('hast').Element} Element
132
+ * @typedef {import('hast').Properties} Properties
133
+ * @typedef {import('mdast').Code} Code
134
+ * @typedef {import('../state.js').State} State
135
+ */
136
+
137
+
138
+ /**
139
+ * Turn an mdast `code` node into hast.
140
+ *
141
+ * @param {State} state
142
+ * Info passed around.
143
+ * @param {Code} node
144
+ * mdast node.
145
+ * @returns {Element}
146
+ * hast node.
147
+ */
148
+ function code(state, node) {
149
+ const value = node.value ? node.value + '\n' : '';
150
+ /** @type {Properties} */
151
+ const properties = {};
152
+ if (node.lang) {
153
+ properties.className = ['language-' + node.lang];
154
+ }
155
+
156
+ // Create `<code>`.
157
+ /** @type {Element} */
158
+ let result = {
159
+ type: 'element',
160
+ tagName: 'code',
161
+ properties,
162
+ children: [{
163
+ type: 'text',
164
+ value
165
+ }]
166
+ };
167
+ if (node.meta) {
168
+ result.data = {
169
+ meta: node.meta
170
+ };
171
+ }
172
+ state.patch(node, result);
173
+ result = state.applyData(node, result);
174
+
175
+ // Create `<pre>`.
176
+ result = {
177
+ type: 'element',
178
+ tagName: 'pre',
179
+ properties: {},
180
+ children: [result]
181
+ };
182
+ state.patch(node, result);
183
+ return result;
184
+ }
185
+
186
+ /**
187
+ * @typedef {import('hast').Element} Element
188
+ * @typedef {import('mdast').Delete} Delete
189
+ * @typedef {import('../state.js').State} State
190
+ */
191
+
192
+
193
+ /**
194
+ * Turn an mdast `delete` node into hast.
195
+ *
196
+ * @param {State} state
197
+ * Info passed around.
198
+ * @param {Delete} node
199
+ * mdast node.
200
+ * @returns {Element}
201
+ * hast node.
202
+ */
203
+ function strikethrough(state, node) {
204
+ /** @type {Element} */
205
+ const result = {
206
+ type: 'element',
207
+ tagName: 'del',
208
+ properties: {},
209
+ children: state.all(node)
210
+ };
211
+ state.patch(node, result);
212
+ return state.applyData(node, result);
213
+ }
214
+
215
+ /**
216
+ * @typedef {import('hast').Element} Element
217
+ * @typedef {import('mdast').Emphasis} Emphasis
218
+ * @typedef {import('../state.js').State} State
219
+ */
220
+
221
+
222
+ /**
223
+ * Turn an mdast `emphasis` node into hast.
224
+ *
225
+ * @param {State} state
226
+ * Info passed around.
227
+ * @param {Emphasis} node
228
+ * mdast node.
229
+ * @returns {Element}
230
+ * hast node.
231
+ */
232
+ function emphasis(state, node) {
233
+ /** @type {Element} */
234
+ const result = {
235
+ type: 'element',
236
+ tagName: 'em',
237
+ properties: {},
238
+ children: state.all(node)
239
+ };
240
+ state.patch(node, result);
241
+ return state.applyData(node, result);
242
+ }
243
+
244
+ /**
245
+ * @typedef {import('hast').Element} Element
246
+ * @typedef {import('mdast').FootnoteReference} FootnoteReference
247
+ * @typedef {import('../state.js').State} State
248
+ */
249
+
250
+
251
+ /**
252
+ * Turn an mdast `footnoteReference` node into hast.
253
+ *
254
+ * @param {State} state
255
+ * Info passed around.
256
+ * @param {FootnoteReference} node
257
+ * mdast node.
258
+ * @returns {Element}
259
+ * hast node.
260
+ */
261
+ function footnoteReference(state, node) {
262
+ const clobberPrefix = typeof state.options.clobberPrefix === 'string' ? state.options.clobberPrefix : 'user-content-';
263
+ const id = String(node.identifier).toUpperCase();
264
+ const safeId = normalizeUri(id.toLowerCase());
265
+ const index = state.footnoteOrder.indexOf(id);
266
+ /** @type {number} */
267
+ let counter;
268
+ let reuseCounter = state.footnoteCounts.get(id);
269
+ if (reuseCounter === undefined) {
270
+ reuseCounter = 0;
271
+ state.footnoteOrder.push(id);
272
+ counter = state.footnoteOrder.length;
273
+ } else {
274
+ counter = index + 1;
275
+ }
276
+ reuseCounter += 1;
277
+ state.footnoteCounts.set(id, reuseCounter);
278
+
279
+ /** @type {Element} */
280
+ const link = {
281
+ type: 'element',
282
+ tagName: 'a',
283
+ properties: {
284
+ href: '#' + clobberPrefix + 'fn-' + safeId,
285
+ id: clobberPrefix + 'fnref-' + safeId + (reuseCounter > 1 ? '-' + reuseCounter : ''),
286
+ dataFootnoteRef: true,
287
+ ariaDescribedBy: ['footnote-label']
288
+ },
289
+ children: [{
290
+ type: 'text',
291
+ value: String(counter)
292
+ }]
293
+ };
294
+ state.patch(node, link);
295
+
296
+ /** @type {Element} */
297
+ const sup = {
298
+ type: 'element',
299
+ tagName: 'sup',
300
+ properties: {},
301
+ children: [link]
302
+ };
303
+ state.patch(node, sup);
304
+ return state.applyData(node, sup);
305
+ }
306
+
307
+ /**
308
+ * @typedef {import('hast').Element} Element
309
+ * @typedef {import('mdast').Heading} Heading
310
+ * @typedef {import('../state.js').State} State
311
+ */
312
+
313
+
314
+ /**
315
+ * Turn an mdast `heading` node into hast.
316
+ *
317
+ * @param {State} state
318
+ * Info passed around.
319
+ * @param {Heading} node
320
+ * mdast node.
321
+ * @returns {Element}
322
+ * hast node.
323
+ */
324
+ function heading(state, node) {
325
+ /** @type {Element} */
326
+ const result = {
327
+ type: 'element',
328
+ tagName: 'h' + node.depth,
329
+ properties: {},
330
+ children: state.all(node)
331
+ };
332
+ state.patch(node, result);
333
+ return state.applyData(node, result);
334
+ }
335
+
336
+ /**
337
+ * @typedef {import('hast').Element} Element
338
+ * @typedef {import('mdast').Html} Html
339
+ * @typedef {import('../state.js').State} State
340
+ * @typedef {import('../../index.js').Raw} Raw
341
+ */
342
+
343
+
344
+ /**
345
+ * Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
346
+ * nothing).
347
+ *
348
+ * @param {State} state
349
+ * Info passed around.
350
+ * @param {Html} node
351
+ * mdast node.
352
+ * @returns {Element | Raw | undefined}
353
+ * hast node.
354
+ */
355
+ function html(state, node) {
356
+ if (state.options.allowDangerousHtml) {
357
+ /** @type {Raw} */
358
+ const result = {
359
+ type: 'raw',
360
+ value: node.value
361
+ };
362
+ state.patch(node, result);
363
+ return state.applyData(node, result);
364
+ }
365
+ return undefined;
366
+ }
367
+
368
+ /**
369
+ * @typedef {import('hast').ElementContent} ElementContent
370
+ *
371
+ * @typedef {import('mdast').Nodes} Nodes
372
+ * @typedef {import('mdast').Reference} Reference
373
+ *
374
+ * @typedef {import('./state.js').State} State
375
+ */
376
+
377
+
378
+ /**
379
+ * Return the content of a reference without definition as plain text.
380
+ *
381
+ * @param {State} state
382
+ * Info passed around.
383
+ * @param {Extract<Nodes, Reference>} node
384
+ * Reference node (image, link).
385
+ * @returns {Array<ElementContent>}
386
+ * hast content.
387
+ */
388
+ function revert(state, node) {
389
+ const subtype = node.referenceType;
390
+ let suffix = ']';
391
+ if (subtype === 'collapsed') {
392
+ suffix += '[]';
393
+ } else if (subtype === 'full') {
394
+ suffix += '[' + (node.label || node.identifier) + ']';
395
+ }
396
+ if (node.type === 'imageReference') {
397
+ return [{
398
+ type: 'text',
399
+ value: '![' + node.alt + suffix
400
+ }];
401
+ }
402
+ const contents = state.all(node);
403
+ const head = contents[0];
404
+ if (head && head.type === 'text') {
405
+ head.value = '[' + head.value;
406
+ } else {
407
+ contents.unshift({
408
+ type: 'text',
409
+ value: '['
410
+ });
411
+ }
412
+ const tail = contents[contents.length - 1];
413
+ if (tail && tail.type === 'text') {
414
+ tail.value += suffix;
415
+ } else {
416
+ contents.push({
417
+ type: 'text',
418
+ value: suffix
419
+ });
420
+ }
421
+ return contents;
422
+ }
423
+
424
+ /**
425
+ * @typedef {import('hast').Element} Element
426
+ * @typedef {import('hast').ElementContent} ElementContent
427
+ * @typedef {import('hast').Properties} Properties
428
+ * @typedef {import('mdast').ImageReference} ImageReference
429
+ * @typedef {import('../state.js').State} State
430
+ */
431
+
432
+
433
+ /**
434
+ * Turn an mdast `imageReference` node into hast.
435
+ *
436
+ * @param {State} state
437
+ * Info passed around.
438
+ * @param {ImageReference} node
439
+ * mdast node.
440
+ * @returns {Array<ElementContent> | ElementContent}
441
+ * hast node.
442
+ */
443
+ function imageReference(state, node) {
444
+ const id = String(node.identifier).toUpperCase();
445
+ const definition = state.definitionById.get(id);
446
+ if (!definition) {
447
+ return revert(state, node);
448
+ }
449
+
450
+ /** @type {Properties} */
451
+ const properties = {
452
+ src: normalizeUri(definition.url || ''),
453
+ alt: node.alt
454
+ };
455
+ if (definition.title !== null && definition.title !== undefined) {
456
+ properties.title = definition.title;
457
+ }
458
+
459
+ /** @type {Element} */
460
+ const result = {
461
+ type: 'element',
462
+ tagName: 'img',
463
+ properties,
464
+ children: []
465
+ };
466
+ state.patch(node, result);
467
+ return state.applyData(node, result);
468
+ }
469
+
470
+ /**
471
+ * @typedef {import('hast').Element} Element
472
+ * @typedef {import('hast').Properties} Properties
473
+ * @typedef {import('mdast').Image} Image
474
+ * @typedef {import('../state.js').State} State
475
+ */
476
+
477
+
478
+ /**
479
+ * Turn an mdast `image` node into hast.
480
+ *
481
+ * @param {State} state
482
+ * Info passed around.
483
+ * @param {Image} node
484
+ * mdast node.
485
+ * @returns {Element}
486
+ * hast node.
487
+ */
488
+ function image(state, node) {
489
+ /** @type {Properties} */
490
+ const properties = {
491
+ src: normalizeUri(node.url)
492
+ };
493
+ if (node.alt !== null && node.alt !== undefined) {
494
+ properties.alt = node.alt;
495
+ }
496
+ if (node.title !== null && node.title !== undefined) {
497
+ properties.title = node.title;
498
+ }
499
+
500
+ /** @type {Element} */
501
+ const result = {
502
+ type: 'element',
503
+ tagName: 'img',
504
+ properties,
505
+ children: []
506
+ };
507
+ state.patch(node, result);
508
+ return state.applyData(node, result);
509
+ }
510
+
511
+ /**
512
+ * @typedef {import('hast').Element} Element
513
+ * @typedef {import('hast').Text} Text
514
+ * @typedef {import('mdast').InlineCode} InlineCode
515
+ * @typedef {import('../state.js').State} State
516
+ */
517
+
518
+
519
+ /**
520
+ * Turn an mdast `inlineCode` node into hast.
521
+ *
522
+ * @param {State} state
523
+ * Info passed around.
524
+ * @param {InlineCode} node
525
+ * mdast node.
526
+ * @returns {Element}
527
+ * hast node.
528
+ */
529
+ function inlineCode(state, node) {
530
+ /** @type {Text} */
531
+ const text = {
532
+ type: 'text',
533
+ value: node.value.replace(/\r?\n|\r/g, ' ')
534
+ };
535
+ state.patch(node, text);
536
+
537
+ /** @type {Element} */
538
+ const result = {
539
+ type: 'element',
540
+ tagName: 'code',
541
+ properties: {},
542
+ children: [text]
543
+ };
544
+ state.patch(node, result);
545
+ return state.applyData(node, result);
546
+ }
547
+
548
+ /**
549
+ * @typedef {import('hast').Element} Element
550
+ * @typedef {import('hast').ElementContent} ElementContent
551
+ * @typedef {import('hast').Properties} Properties
552
+ * @typedef {import('mdast').LinkReference} LinkReference
553
+ * @typedef {import('../state.js').State} State
554
+ */
555
+
556
+
557
+ /**
558
+ * Turn an mdast `linkReference` node into hast.
559
+ *
560
+ * @param {State} state
561
+ * Info passed around.
562
+ * @param {LinkReference} node
563
+ * mdast node.
564
+ * @returns {Array<ElementContent> | ElementContent}
565
+ * hast node.
566
+ */
567
+ function linkReference(state, node) {
568
+ const id = String(node.identifier).toUpperCase();
569
+ const definition = state.definitionById.get(id);
570
+ if (!definition) {
571
+ return revert(state, node);
572
+ }
573
+
574
+ /** @type {Properties} */
575
+ const properties = {
576
+ href: normalizeUri(definition.url || '')
577
+ };
578
+ if (definition.title !== null && definition.title !== undefined) {
579
+ properties.title = definition.title;
580
+ }
581
+
582
+ /** @type {Element} */
583
+ const result = {
584
+ type: 'element',
585
+ tagName: 'a',
586
+ properties,
587
+ children: state.all(node)
588
+ };
589
+ state.patch(node, result);
590
+ return state.applyData(node, result);
591
+ }
592
+
593
+ /**
594
+ * @typedef {import('hast').Element} Element
595
+ * @typedef {import('hast').Properties} Properties
596
+ * @typedef {import('mdast').Link} Link
597
+ * @typedef {import('../state.js').State} State
598
+ */
599
+
600
+
601
+ /**
602
+ * Turn an mdast `link` node into hast.
603
+ *
604
+ * @param {State} state
605
+ * Info passed around.
606
+ * @param {Link} node
607
+ * mdast node.
608
+ * @returns {Element}
609
+ * hast node.
610
+ */
611
+ function link(state, node) {
612
+ /** @type {Properties} */
613
+ const properties = {
614
+ href: normalizeUri(node.url)
615
+ };
616
+ if (node.title !== null && node.title !== undefined) {
617
+ properties.title = node.title;
618
+ }
619
+
620
+ /** @type {Element} */
621
+ const result = {
622
+ type: 'element',
623
+ tagName: 'a',
624
+ properties,
625
+ children: state.all(node)
626
+ };
627
+ state.patch(node, result);
628
+ return state.applyData(node, result);
629
+ }
630
+
631
+ /**
632
+ * @typedef {import('hast').Element} Element
633
+ * @typedef {import('hast').ElementContent} ElementContent
634
+ * @typedef {import('hast').Properties} Properties
635
+ * @typedef {import('mdast').ListItem} ListItem
636
+ * @typedef {import('mdast').Parents} Parents
637
+ * @typedef {import('../state.js').State} State
638
+ */
639
+
640
+
641
+ /**
642
+ * Turn an mdast `listItem` node into hast.
643
+ *
644
+ * @param {State} state
645
+ * Info passed around.
646
+ * @param {ListItem} node
647
+ * mdast node.
648
+ * @param {Parents | undefined} parent
649
+ * Parent of `node`.
650
+ * @returns {Element}
651
+ * hast node.
652
+ */
653
+ function listItem(state, node, parent) {
654
+ const results = state.all(node);
655
+ const loose = parent ? listLoose(parent) : listItemLoose(node);
656
+ /** @type {Properties} */
657
+ const properties = {};
658
+ /** @type {Array<ElementContent>} */
659
+ const children = [];
660
+ if (typeof node.checked === 'boolean') {
661
+ const head = results[0];
662
+ /** @type {Element} */
663
+ let paragraph;
664
+ if (head && head.type === 'element' && head.tagName === 'p') {
665
+ paragraph = head;
666
+ } else {
667
+ paragraph = {
668
+ type: 'element',
669
+ tagName: 'p',
670
+ properties: {},
671
+ children: []
672
+ };
673
+ results.unshift(paragraph);
674
+ }
675
+ if (paragraph.children.length > 0) {
676
+ paragraph.children.unshift({
677
+ type: 'text',
678
+ value: ' '
679
+ });
680
+ }
681
+ paragraph.children.unshift({
682
+ type: 'element',
683
+ tagName: 'input',
684
+ properties: {
685
+ type: 'checkbox',
686
+ checked: node.checked,
687
+ disabled: true
688
+ },
689
+ children: []
690
+ });
691
+
692
+ // According to github-markdown-css, this class hides bullet.
693
+ // See: <https://github.com/sindresorhus/github-markdown-css>.
694
+ properties.className = ['task-list-item'];
695
+ }
696
+ let index = -1;
697
+ while (++index < results.length) {
698
+ const child = results[index];
699
+
700
+ // Add eols before nodes, except if this is a loose, first paragraph.
701
+ if (loose || index !== 0 || child.type !== 'element' || child.tagName !== 'p') {
702
+ children.push({
703
+ type: 'text',
704
+ value: '\n'
705
+ });
706
+ }
707
+ if (child.type === 'element' && child.tagName === 'p' && !loose) {
708
+ children.push(...child.children);
709
+ } else {
710
+ children.push(child);
711
+ }
712
+ }
713
+ const tail = results[results.length - 1];
714
+
715
+ // Add a final eol.
716
+ if (tail && (loose || tail.type !== 'element' || tail.tagName !== 'p')) {
717
+ children.push({
718
+ type: 'text',
719
+ value: '\n'
720
+ });
721
+ }
722
+
723
+ /** @type {Element} */
724
+ const result = {
725
+ type: 'element',
726
+ tagName: 'li',
727
+ properties,
728
+ children
729
+ };
730
+ state.patch(node, result);
731
+ return state.applyData(node, result);
732
+ }
733
+
734
+ /**
735
+ * @param {Parents} node
736
+ * @return {Boolean}
737
+ */
738
+ function listLoose(node) {
739
+ let loose = false;
740
+ if (node.type === 'list') {
741
+ loose = node.spread || false;
742
+ const children = node.children;
743
+ let index = -1;
744
+ while (!loose && ++index < children.length) {
745
+ loose = listItemLoose(children[index]);
746
+ }
747
+ }
748
+ return loose;
749
+ }
750
+
751
+ /**
752
+ * @param {ListItem} node
753
+ * @return {Boolean}
754
+ */
755
+ function listItemLoose(node) {
756
+ const spread = node.spread;
757
+ return spread === null || spread === undefined ? node.children.length > 1 : spread;
758
+ }
759
+
760
+ /**
761
+ * @typedef {import('hast').Element} Element
762
+ * @typedef {import('hast').Properties} Properties
763
+ * @typedef {import('mdast').List} List
764
+ * @typedef {import('../state.js').State} State
765
+ */
766
+
767
+
768
+ /**
769
+ * Turn an mdast `list` node into hast.
770
+ *
771
+ * @param {State} state
772
+ * Info passed around.
773
+ * @param {List} node
774
+ * mdast node.
775
+ * @returns {Element}
776
+ * hast node.
777
+ */
778
+ function list(state, node) {
779
+ /** @type {Properties} */
780
+ const properties = {};
781
+ const results = state.all(node);
782
+ let index = -1;
783
+ if (typeof node.start === 'number' && node.start !== 1) {
784
+ properties.start = node.start;
785
+ }
786
+
787
+ // Like GitHub, add a class for custom styling.
788
+ while (++index < results.length) {
789
+ const child = results[index];
790
+ if (child.type === 'element' && child.tagName === 'li' && child.properties && Array.isArray(child.properties.className) && child.properties.className.includes('task-list-item')) {
791
+ properties.className = ['contains-task-list'];
792
+ break;
793
+ }
794
+ }
795
+
796
+ /** @type {Element} */
797
+ const result = {
798
+ type: 'element',
799
+ tagName: node.ordered ? 'ol' : 'ul',
800
+ properties,
801
+ children: state.wrap(results, true)
802
+ };
803
+ state.patch(node, result);
804
+ return state.applyData(node, result);
805
+ }
806
+
807
+ /**
808
+ * @typedef {import('hast').Element} Element
809
+ * @typedef {import('mdast').Paragraph} Paragraph
810
+ * @typedef {import('../state.js').State} State
811
+ */
812
+
813
+
814
+ /**
815
+ * Turn an mdast `paragraph` node into hast.
816
+ *
817
+ * @param {State} state
818
+ * Info passed around.
819
+ * @param {Paragraph} node
820
+ * mdast node.
821
+ * @returns {Element}
822
+ * hast node.
823
+ */
824
+ function paragraph(state, node) {
825
+ /** @type {Element} */
826
+ const result = {
827
+ type: 'element',
828
+ tagName: 'p',
829
+ properties: {},
830
+ children: state.all(node)
831
+ };
832
+ state.patch(node, result);
833
+ return state.applyData(node, result);
834
+ }
835
+
836
+ /**
837
+ * @typedef {import('hast').Parents} HastParents
838
+ * @typedef {import('hast').Root} HastRoot
839
+ * @typedef {import('mdast').Root} MdastRoot
840
+ * @typedef {import('../state.js').State} State
841
+ */
842
+
843
+
844
+ /**
845
+ * Turn an mdast `root` node into hast.
846
+ *
847
+ * @param {State} state
848
+ * Info passed around.
849
+ * @param {MdastRoot} node
850
+ * mdast node.
851
+ * @returns {HastParents}
852
+ * hast node.
853
+ */
854
+ function root(state, node) {
855
+ /** @type {HastRoot} */
856
+ const result = {
857
+ type: 'root',
858
+ children: state.wrap(state.all(node))
859
+ };
860
+ state.patch(node, result);
861
+ return state.applyData(node, result);
862
+ }
863
+
864
+ /**
865
+ * @typedef {import('hast').Element} Element
866
+ * @typedef {import('mdast').Strong} Strong
867
+ * @typedef {import('../state.js').State} State
868
+ */
869
+
870
+
871
+ /**
872
+ * Turn an mdast `strong` node into hast.
873
+ *
874
+ * @param {State} state
875
+ * Info passed around.
876
+ * @param {Strong} node
877
+ * mdast node.
878
+ * @returns {Element}
879
+ * hast node.
880
+ */
881
+ function strong(state, node) {
882
+ /** @type {Element} */
883
+ const result = {
884
+ type: 'element',
885
+ tagName: 'strong',
886
+ properties: {},
887
+ children: state.all(node)
888
+ };
889
+ state.patch(node, result);
890
+ return state.applyData(node, result);
891
+ }
892
+
893
+ /**
894
+ * @typedef {import('hast').Element} Element
895
+ * @typedef {import('mdast').Table} Table
896
+ * @typedef {import('../state.js').State} State
897
+ */
898
+
899
+
900
+ /**
901
+ * Turn an mdast `table` node into hast.
902
+ *
903
+ * @param {State} state
904
+ * Info passed around.
905
+ * @param {Table} node
906
+ * mdast node.
907
+ * @returns {Element}
908
+ * hast node.
909
+ */
910
+ function table(state, node) {
911
+ const rows = state.all(node);
912
+ const firstRow = rows.shift();
913
+ /** @type {Array<Element>} */
914
+ const tableContent = [];
915
+ if (firstRow) {
916
+ /** @type {Element} */
917
+ const head = {
918
+ type: 'element',
919
+ tagName: 'thead',
920
+ properties: {},
921
+ children: state.wrap([firstRow], true)
922
+ };
923
+ state.patch(node.children[0], head);
924
+ tableContent.push(head);
925
+ }
926
+ if (rows.length > 0) {
927
+ /** @type {Element} */
928
+ const body = {
929
+ type: 'element',
930
+ tagName: 'tbody',
931
+ properties: {},
932
+ children: state.wrap(rows, true)
933
+ };
934
+ const start = pointStart(node.children[1]);
935
+ const end = pointEnd(node.children[node.children.length - 1]);
936
+ if (start && end) body.position = {
937
+ start,
938
+ end
939
+ };
940
+ tableContent.push(body);
941
+ }
942
+
943
+ /** @type {Element} */
944
+ const result = {
945
+ type: 'element',
946
+ tagName: 'table',
947
+ properties: {},
948
+ children: state.wrap(tableContent, true)
949
+ };
950
+ state.patch(node, result);
951
+ return state.applyData(node, result);
952
+ }
953
+
954
+ /**
955
+ * @typedef {import('hast').Element} Element
956
+ * @typedef {import('hast').ElementContent} ElementContent
957
+ * @typedef {import('hast').Properties} Properties
958
+ * @typedef {import('mdast').Parents} Parents
959
+ * @typedef {import('mdast').TableRow} TableRow
960
+ * @typedef {import('../state.js').State} State
961
+ */
962
+
963
+
964
+ /**
965
+ * Turn an mdast `tableRow` node into hast.
966
+ *
967
+ * @param {State} state
968
+ * Info passed around.
969
+ * @param {TableRow} node
970
+ * mdast node.
971
+ * @param {Parents | undefined} parent
972
+ * Parent of `node`.
973
+ * @returns {Element}
974
+ * hast node.
975
+ */
976
+ function tableRow(state, node, parent) {
977
+ const siblings = parent ? parent.children : undefined;
978
+ // Generate a body row when without parent.
979
+ const rowIndex = siblings ? siblings.indexOf(node) : 1;
980
+ const tagName = rowIndex === 0 ? 'th' : 'td';
981
+ // To do: option to use `style`?
982
+ const align = parent && parent.type === 'table' ? parent.align : undefined;
983
+ const length = align ? align.length : node.children.length;
984
+ let cellIndex = -1;
985
+ /** @type {Array<ElementContent>} */
986
+ const cells = [];
987
+ while (++cellIndex < length) {
988
+ // Note: can also be undefined.
989
+ const cell = node.children[cellIndex];
990
+ /** @type {Properties} */
991
+ const properties = {};
992
+ const alignValue = align ? align[cellIndex] : undefined;
993
+ if (alignValue) {
994
+ properties.align = alignValue;
995
+ }
996
+
997
+ /** @type {Element} */
998
+ let result = {
999
+ type: 'element',
1000
+ tagName,
1001
+ properties,
1002
+ children: []
1003
+ };
1004
+ if (cell) {
1005
+ result.children = state.all(cell);
1006
+ state.patch(cell, result);
1007
+ result = state.applyData(cell, result);
1008
+ }
1009
+ cells.push(result);
1010
+ }
1011
+
1012
+ /** @type {Element} */
1013
+ const result = {
1014
+ type: 'element',
1015
+ tagName: 'tr',
1016
+ properties: {},
1017
+ children: state.wrap(cells, true)
1018
+ };
1019
+ state.patch(node, result);
1020
+ return state.applyData(node, result);
1021
+ }
1022
+
1023
+ /**
1024
+ * @typedef {import('hast').Element} Element
1025
+ * @typedef {import('mdast').TableCell} TableCell
1026
+ * @typedef {import('../state.js').State} State
1027
+ */
1028
+
1029
+
1030
+ /**
1031
+ * Turn an mdast `tableCell` node into hast.
1032
+ *
1033
+ * @param {State} state
1034
+ * Info passed around.
1035
+ * @param {TableCell} node
1036
+ * mdast node.
1037
+ * @returns {Element}
1038
+ * hast node.
1039
+ */
1040
+ function tableCell(state, node) {
1041
+ // Note: this function is normally not called: see `table-row` for how rows
1042
+ // and their cells are compiled.
1043
+ /** @type {Element} */
1044
+ const result = {
1045
+ type: 'element',
1046
+ tagName: 'td',
1047
+ // Assume body cell.
1048
+ properties: {},
1049
+ children: state.all(node)
1050
+ };
1051
+ state.patch(node, result);
1052
+ return state.applyData(node, result);
1053
+ }
1054
+
1055
+ const tab = 9; /* `\t` */
1056
+ const space = 32; /* ` ` */
1057
+
1058
+ /**
1059
+ * Remove initial and final spaces and tabs at the line breaks in `value`.
1060
+ * Does not trim initial and final spaces and tabs of the value itself.
1061
+ *
1062
+ * @param {string} value
1063
+ * Value to trim.
1064
+ * @returns {string}
1065
+ * Trimmed value.
1066
+ */
1067
+ function trimLines(value) {
1068
+ const source = String(value);
1069
+ const search = /\r?\n|\r/g;
1070
+ let match = search.exec(source);
1071
+ let last = 0;
1072
+ /** @type {Array<string>} */
1073
+ const lines = [];
1074
+ while (match) {
1075
+ lines.push(trimLine(source.slice(last, match.index), last > 0, true), match[0]);
1076
+ last = match.index + match[0].length;
1077
+ match = search.exec(source);
1078
+ }
1079
+ lines.push(trimLine(source.slice(last), last > 0, false));
1080
+ return lines.join('');
1081
+ }
1082
+
1083
+ /**
1084
+ * @param {string} value
1085
+ * Line to trim.
1086
+ * @param {boolean} start
1087
+ * Whether to trim the start of the line.
1088
+ * @param {boolean} end
1089
+ * Whether to trim the end of the line.
1090
+ * @returns {string}
1091
+ * Trimmed line.
1092
+ */
1093
+ function trimLine(value, start, end) {
1094
+ let startIndex = 0;
1095
+ let endIndex = value.length;
1096
+ if (start) {
1097
+ let code = value.codePointAt(startIndex);
1098
+ while (code === tab || code === space) {
1099
+ startIndex++;
1100
+ code = value.codePointAt(startIndex);
1101
+ }
1102
+ }
1103
+ if (end) {
1104
+ let code = value.codePointAt(endIndex - 1);
1105
+ while (code === tab || code === space) {
1106
+ endIndex--;
1107
+ code = value.codePointAt(endIndex - 1);
1108
+ }
1109
+ }
1110
+ return endIndex > startIndex ? value.slice(startIndex, endIndex) : '';
1111
+ }
1112
+
1113
+ /**
1114
+ * @typedef {import('hast').Element} HastElement
1115
+ * @typedef {import('hast').Text} HastText
1116
+ * @typedef {import('mdast').Text} MdastText
1117
+ * @typedef {import('../state.js').State} State
1118
+ */
1119
+
1120
+
1121
+ /**
1122
+ * Turn an mdast `text` node into hast.
1123
+ *
1124
+ * @param {State} state
1125
+ * Info passed around.
1126
+ * @param {MdastText} node
1127
+ * mdast node.
1128
+ * @returns {HastElement | HastText}
1129
+ * hast node.
1130
+ */
1131
+ function text(state, node) {
1132
+ /** @type {HastText} */
1133
+ const result = {
1134
+ type: 'text',
1135
+ value: trimLines(String(node.value))
1136
+ };
1137
+ state.patch(node, result);
1138
+ return state.applyData(node, result);
1139
+ }
1140
+
1141
+ /**
1142
+ * @typedef {import('hast').Element} Element
1143
+ * @typedef {import('mdast').ThematicBreak} ThematicBreak
1144
+ * @typedef {import('../state.js').State} State
1145
+ */
1146
+
1147
+
1148
+ /**
1149
+ * Turn an mdast `thematicBreak` node into hast.
1150
+ *
1151
+ * @param {State} state
1152
+ * Info passed around.
1153
+ * @param {ThematicBreak} node
1154
+ * mdast node.
1155
+ * @returns {Element}
1156
+ * hast node.
1157
+ */
1158
+ function thematicBreak(state, node) {
1159
+ /** @type {Element} */
1160
+ const result = {
1161
+ type: 'element',
1162
+ tagName: 'hr',
1163
+ properties: {},
1164
+ children: []
1165
+ };
1166
+ state.patch(node, result);
1167
+ return state.applyData(node, result);
1168
+ }
1169
+
1170
+ /**
1171
+ * Default handlers for nodes.
1172
+ *
1173
+ * @satisfies {import('../state.js').Handlers}
1174
+ */
1175
+ const handlers = {
1176
+ blockquote,
1177
+ break: hardBreak,
1178
+ code,
1179
+ delete: strikethrough,
1180
+ emphasis,
1181
+ footnoteReference,
1182
+ heading,
1183
+ html,
1184
+ imageReference,
1185
+ image,
1186
+ inlineCode,
1187
+ linkReference,
1188
+ link,
1189
+ listItem,
1190
+ list,
1191
+ paragraph,
1192
+ // @ts-expect-error: root is different, but hard to type.
1193
+ root,
1194
+ strong,
1195
+ table,
1196
+ tableCell,
1197
+ tableRow,
1198
+ text,
1199
+ thematicBreak,
1200
+ toml: ignore,
1201
+ yaml: ignore,
1202
+ definition: ignore,
1203
+ footnoteDefinition: ignore
1204
+ };
1205
+
1206
+ // Return nothing for nodes that are ignored.
1207
+ function ignore() {
1208
+ return undefined;
1209
+ }
1210
+
1211
+ /**
1212
+ * @typedef {import('hast').Element} Element
1213
+ * @typedef {import('hast').ElementContent} ElementContent
1214
+ *
1215
+ * @typedef {import('./state.js').State} State
1216
+ */
1217
+
1218
+
1219
+ /**
1220
+ * Generate the default content that GitHub uses on backreferences.
1221
+ *
1222
+ * @param {number} _
1223
+ * Index of the definition in the order that they are first referenced,
1224
+ * 0-indexed.
1225
+ * @param {number} rereferenceIndex
1226
+ * Index of calls to the same definition, 0-indexed.
1227
+ * @returns {Array<ElementContent>}
1228
+ * Content.
1229
+ */
1230
+ function defaultFootnoteBackContent(_, rereferenceIndex) {
1231
+ /** @type {Array<ElementContent>} */
1232
+ const result = [{
1233
+ type: 'text',
1234
+ value: '↩'
1235
+ }];
1236
+ if (rereferenceIndex > 1) {
1237
+ result.push({
1238
+ type: 'element',
1239
+ tagName: 'sup',
1240
+ properties: {},
1241
+ children: [{
1242
+ type: 'text',
1243
+ value: String(rereferenceIndex)
1244
+ }]
1245
+ });
1246
+ }
1247
+ return result;
1248
+ }
1249
+
1250
+ /**
1251
+ * Generate the default label that GitHub uses on backreferences.
1252
+ *
1253
+ * @param {number} referenceIndex
1254
+ * Index of the definition in the order that they are first referenced,
1255
+ * 0-indexed.
1256
+ * @param {number} rereferenceIndex
1257
+ * Index of calls to the same definition, 0-indexed.
1258
+ * @returns {string}
1259
+ * Label.
1260
+ */
1261
+ function defaultFootnoteBackLabel(referenceIndex, rereferenceIndex) {
1262
+ return 'Back to reference ' + (referenceIndex + 1) + (rereferenceIndex > 1 ? '-' + rereferenceIndex : '');
1263
+ }
1264
+
1265
+ /**
1266
+ * Generate a hast footer for called footnote definitions.
1267
+ *
1268
+ * @param {State} state
1269
+ * Info passed around.
1270
+ * @returns {Element | undefined}
1271
+ * `section` element or `undefined`.
1272
+ */
1273
+ // eslint-disable-next-line complexity
1274
+ function footer(state) {
1275
+ const clobberPrefix = typeof state.options.clobberPrefix === 'string' ? state.options.clobberPrefix : 'user-content-';
1276
+ const footnoteBackContent = state.options.footnoteBackContent || defaultFootnoteBackContent;
1277
+ const footnoteBackLabel = state.options.footnoteBackLabel || defaultFootnoteBackLabel;
1278
+ const footnoteLabel = state.options.footnoteLabel || 'Footnotes';
1279
+ const footnoteLabelTagName = state.options.footnoteLabelTagName || 'h2';
1280
+ const footnoteLabelProperties = state.options.footnoteLabelProperties || {
1281
+ className: ['sr-only']
1282
+ };
1283
+ /** @type {Array<ElementContent>} */
1284
+ const listItems = [];
1285
+ let referenceIndex = -1;
1286
+ while (++referenceIndex < state.footnoteOrder.length) {
1287
+ const definition = state.footnoteById.get(state.footnoteOrder[referenceIndex]);
1288
+ if (!definition) {
1289
+ continue;
1290
+ }
1291
+ const content = state.all(definition);
1292
+ const id = String(definition.identifier).toUpperCase();
1293
+ const safeId = normalizeUri(id.toLowerCase());
1294
+ let rereferenceIndex = 0;
1295
+ /** @type {Array<ElementContent>} */
1296
+ const backReferences = [];
1297
+ const counts = state.footnoteCounts.get(id);
1298
+
1299
+ // eslint-disable-next-line no-unmodified-loop-condition
1300
+ while (counts !== undefined && ++rereferenceIndex <= counts) {
1301
+ if (backReferences.length > 0) {
1302
+ backReferences.push({
1303
+ type: 'text',
1304
+ value: ' '
1305
+ });
1306
+ }
1307
+ let children = typeof footnoteBackContent === 'string' ? footnoteBackContent : footnoteBackContent(referenceIndex, rereferenceIndex);
1308
+ if (typeof children === 'string') {
1309
+ children = {
1310
+ type: 'text',
1311
+ value: children
1312
+ };
1313
+ }
1314
+ backReferences.push({
1315
+ type: 'element',
1316
+ tagName: 'a',
1317
+ properties: {
1318
+ href: '#' + clobberPrefix + 'fnref-' + safeId + (rereferenceIndex > 1 ? '-' + rereferenceIndex : ''),
1319
+ dataFootnoteBackref: '',
1320
+ ariaLabel: typeof footnoteBackLabel === 'string' ? footnoteBackLabel : footnoteBackLabel(referenceIndex, rereferenceIndex),
1321
+ className: ['data-footnote-backref']
1322
+ },
1323
+ children: Array.isArray(children) ? children : [children]
1324
+ });
1325
+ }
1326
+ const tail = content[content.length - 1];
1327
+ if (tail && tail.type === 'element' && tail.tagName === 'p') {
1328
+ const tailTail = tail.children[tail.children.length - 1];
1329
+ if (tailTail && tailTail.type === 'text') {
1330
+ tailTail.value += ' ';
1331
+ } else {
1332
+ tail.children.push({
1333
+ type: 'text',
1334
+ value: ' '
1335
+ });
1336
+ }
1337
+ tail.children.push(...backReferences);
1338
+ } else {
1339
+ content.push(...backReferences);
1340
+ }
1341
+
1342
+ /** @type {Element} */
1343
+ const listItem = {
1344
+ type: 'element',
1345
+ tagName: 'li',
1346
+ properties: {
1347
+ id: clobberPrefix + 'fn-' + safeId
1348
+ },
1349
+ children: state.wrap(content, true)
1350
+ };
1351
+ state.patch(definition, listItem);
1352
+ listItems.push(listItem);
1353
+ }
1354
+ if (listItems.length === 0) {
1355
+ return;
1356
+ }
1357
+ return {
1358
+ type: 'element',
1359
+ tagName: 'section',
1360
+ properties: {
1361
+ dataFootnotes: true,
1362
+ className: ['footnotes']
1363
+ },
1364
+ children: [{
1365
+ type: 'element',
1366
+ tagName: footnoteLabelTagName,
1367
+ properties: {
1368
+ ...structuredClone(footnoteLabelProperties),
1369
+ id: 'footnote-label'
1370
+ },
1371
+ children: [{
1372
+ type: 'text',
1373
+ value: footnoteLabel
1374
+ }]
1375
+ }, {
1376
+ type: 'text',
1377
+ value: '\n'
1378
+ }, {
1379
+ type: 'element',
1380
+ tagName: 'ol',
1381
+ properties: {},
1382
+ children: state.wrap(listItems, true)
1383
+ }, {
1384
+ type: 'text',
1385
+ value: '\n'
1386
+ }]
1387
+ };
1388
+ }
1389
+
1390
+ /**
1391
+ * @typedef {import('hast').Element} HastElement
1392
+ * @typedef {import('hast').ElementContent} HastElementContent
1393
+ * @typedef {import('hast').Nodes} HastNodes
1394
+ * @typedef {import('hast').Properties} HastProperties
1395
+ * @typedef {import('hast').RootContent} HastRootContent
1396
+ * @typedef {import('hast').Text} HastText
1397
+ *
1398
+ * @typedef {import('mdast').Definition} MdastDefinition
1399
+ * @typedef {import('mdast').FootnoteDefinition} MdastFootnoteDefinition
1400
+ * @typedef {import('mdast').Nodes} MdastNodes
1401
+ * @typedef {import('mdast').Parents} MdastParents
1402
+ *
1403
+ * @typedef {import('vfile').VFile} VFile
1404
+ *
1405
+ * @typedef {import('./footer.js').FootnoteBackContentTemplate} FootnoteBackContentTemplate
1406
+ * @typedef {import('./footer.js').FootnoteBackLabelTemplate} FootnoteBackLabelTemplate
1407
+ */
1408
+
1409
+ const own = {}.hasOwnProperty;
1410
+
1411
+ /** @type {Options} */
1412
+ const emptyOptions = {};
1413
+
1414
+ /**
1415
+ * Create `state` from an mdast tree.
1416
+ *
1417
+ * @param {MdastNodes} tree
1418
+ * mdast node to transform.
1419
+ * @param {Options | null | undefined} [options]
1420
+ * Configuration (optional).
1421
+ * @returns {State}
1422
+ * `state` function.
1423
+ */
1424
+ function createState(tree, options) {
1425
+ const settings = options || emptyOptions;
1426
+ /** @type {Map<string, MdastDefinition>} */
1427
+ const definitionById = new Map();
1428
+ /** @type {Map<string, MdastFootnoteDefinition>} */
1429
+ const footnoteById = new Map();
1430
+ /** @type {Map<string, number>} */
1431
+ const footnoteCounts = new Map();
1432
+ /** @type {Handlers} */
1433
+ // @ts-expect-error: the root handler returns a root.
1434
+ // Hard to type.
1435
+ const handlers$1 = {
1436
+ ...handlers,
1437
+ ...settings.handlers
1438
+ };
1439
+
1440
+ /** @type {State} */
1441
+ const state = {
1442
+ all,
1443
+ applyData,
1444
+ definitionById,
1445
+ footnoteById,
1446
+ footnoteCounts,
1447
+ footnoteOrder: [],
1448
+ handlers: handlers$1,
1449
+ one,
1450
+ options: settings,
1451
+ patch,
1452
+ wrap
1453
+ };
1454
+ visit(tree, function (node) {
1455
+ if (node.type === 'definition' || node.type === 'footnoteDefinition') {
1456
+ const map = node.type === 'definition' ? definitionById : footnoteById;
1457
+ const id = String(node.identifier).toUpperCase();
1458
+
1459
+ // Mimick CM behavior of link definitions.
1460
+ // See: <https://github.com/syntax-tree/mdast-util-definitions/blob/9032189/lib/index.js#L20-L21>.
1461
+ if (!map.has(id)) {
1462
+ // @ts-expect-error: node type matches map.
1463
+ map.set(id, node);
1464
+ }
1465
+ }
1466
+ });
1467
+ return state;
1468
+
1469
+ /**
1470
+ * Transform an mdast node into a hast node.
1471
+ *
1472
+ * @param {MdastNodes} node
1473
+ * mdast node.
1474
+ * @param {MdastParents | undefined} [parent]
1475
+ * Parent of `node`.
1476
+ * @returns {Array<HastElementContent> | HastElementContent | undefined}
1477
+ * Resulting hast node.
1478
+ */
1479
+ function one(node, parent) {
1480
+ const type = node.type;
1481
+ const handle = state.handlers[type];
1482
+ if (own.call(state.handlers, type) && handle) {
1483
+ return handle(state, node, parent);
1484
+ }
1485
+ if (state.options.passThrough && state.options.passThrough.includes(type)) {
1486
+ if ('children' in node) {
1487
+ const {
1488
+ children,
1489
+ ...shallow
1490
+ } = node;
1491
+ const result = structuredClone(shallow);
1492
+ // @ts-expect-error: TS doesn’t understand…
1493
+ result.children = state.all(node);
1494
+ // @ts-expect-error: TS doesn’t understand…
1495
+ return result;
1496
+ }
1497
+
1498
+ // @ts-expect-error: it’s custom.
1499
+ return structuredClone(node);
1500
+ }
1501
+ const unknown = state.options.unknownHandler || defaultUnknownHandler;
1502
+ return unknown(state, node, parent);
1503
+ }
1504
+
1505
+ /**
1506
+ * Transform the children of an mdast node into hast nodes.
1507
+ *
1508
+ * @param {MdastNodes} parent
1509
+ * mdast node to compile
1510
+ * @returns {Array<HastElementContent>}
1511
+ * Resulting hast nodes.
1512
+ */
1513
+ function all(parent) {
1514
+ /** @type {Array<HastElementContent>} */
1515
+ const values = [];
1516
+ if ('children' in parent) {
1517
+ const nodes = parent.children;
1518
+ let index = -1;
1519
+ while (++index < nodes.length) {
1520
+ const result = state.one(nodes[index], parent);
1521
+
1522
+ // To do: see if we van clean this? Can we merge texts?
1523
+ if (result) {
1524
+ if (index && nodes[index - 1].type === 'break') {
1525
+ if (!Array.isArray(result) && result.type === 'text') {
1526
+ result.value = trimMarkdownSpaceStart(result.value);
1527
+ }
1528
+ if (!Array.isArray(result) && result.type === 'element') {
1529
+ const head = result.children[0];
1530
+ if (head && head.type === 'text') {
1531
+ head.value = trimMarkdownSpaceStart(head.value);
1532
+ }
1533
+ }
1534
+ }
1535
+ if (Array.isArray(result)) {
1536
+ values.push(...result);
1537
+ } else {
1538
+ values.push(result);
1539
+ }
1540
+ }
1541
+ }
1542
+ }
1543
+ return values;
1544
+ }
1545
+ }
1546
+
1547
+ /**
1548
+ * Copy a node’s positional info.
1549
+ *
1550
+ * @param {MdastNodes} from
1551
+ * mdast node to copy from.
1552
+ * @param {HastNodes} to
1553
+ * hast node to copy into.
1554
+ * @returns {undefined}
1555
+ * Nothing.
1556
+ */
1557
+ function patch(from, to) {
1558
+ if (from.position) to.position = position(from);
1559
+ }
1560
+
1561
+ /**
1562
+ * Honor the `data` of `from` and maybe generate an element instead of `to`.
1563
+ *
1564
+ * @template {HastNodes} Type
1565
+ * Node type.
1566
+ * @param {MdastNodes} from
1567
+ * mdast node to use data from.
1568
+ * @param {Type} to
1569
+ * hast node to change.
1570
+ * @returns {HastElement | Type}
1571
+ * Nothing.
1572
+ */
1573
+ function applyData(from, to) {
1574
+ /** @type {HastElement | Type} */
1575
+ let result = to;
1576
+
1577
+ // Handle `data.hName`, `data.hProperties, `data.hChildren`.
1578
+ if (from && from.data) {
1579
+ const hName = from.data.hName;
1580
+ const hChildren = from.data.hChildren;
1581
+ const hProperties = from.data.hProperties;
1582
+ if (typeof hName === 'string') {
1583
+ // Transforming the node resulted in an element with a different name
1584
+ // than wanted:
1585
+ if (result.type === 'element') {
1586
+ result.tagName = hName;
1587
+ }
1588
+ // Transforming the node resulted in a non-element, which happens for
1589
+ // raw, text, and root nodes (unless custom handlers are passed).
1590
+ // The intent of `hName` is to create an element, but likely also to keep
1591
+ // the content around (otherwise: pass `hChildren`).
1592
+ else {
1593
+ /** @type {Array<HastElementContent>} */
1594
+ // @ts-expect-error: assume no doctypes in `root`.
1595
+ const children = 'children' in result ? result.children : [result];
1596
+ result = {
1597
+ type: 'element',
1598
+ tagName: hName,
1599
+ properties: {},
1600
+ children
1601
+ };
1602
+ }
1603
+ }
1604
+ if (result.type === 'element' && hProperties) {
1605
+ Object.assign(result.properties, structuredClone(hProperties));
1606
+ }
1607
+ if ('children' in result && result.children && hChildren !== null && hChildren !== undefined) {
1608
+ result.children = hChildren;
1609
+ }
1610
+ }
1611
+ return result;
1612
+ }
1613
+
1614
+ /**
1615
+ * Transform an unknown node.
1616
+ *
1617
+ * @param {State} state
1618
+ * Info passed around.
1619
+ * @param {MdastNodes} node
1620
+ * Unknown mdast node.
1621
+ * @returns {HastElement | HastText}
1622
+ * Resulting hast node.
1623
+ */
1624
+ function defaultUnknownHandler(state, node) {
1625
+ const data = node.data || {};
1626
+ /** @type {HastElement | HastText} */
1627
+ const result = 'value' in node && !(own.call(data, 'hProperties') || own.call(data, 'hChildren')) ? {
1628
+ type: 'text',
1629
+ value: node.value
1630
+ } : {
1631
+ type: 'element',
1632
+ tagName: 'div',
1633
+ properties: {},
1634
+ children: state.all(node)
1635
+ };
1636
+ state.patch(node, result);
1637
+ return state.applyData(node, result);
1638
+ }
1639
+
1640
+ /**
1641
+ * Wrap `nodes` with line endings between each node.
1642
+ *
1643
+ * @template {HastRootContent} Type
1644
+ * Node type.
1645
+ * @param {Array<Type>} nodes
1646
+ * List of nodes to wrap.
1647
+ * @param {boolean | undefined} [loose=false]
1648
+ * Whether to add line endings at start and end (default: `false`).
1649
+ * @returns {Array<HastText | Type>}
1650
+ * Wrapped nodes.
1651
+ */
1652
+ function wrap(nodes, loose) {
1653
+ /** @type {Array<HastText | Type>} */
1654
+ const result = [];
1655
+ let index = -1;
1656
+ if (loose) {
1657
+ result.push({
1658
+ type: 'text',
1659
+ value: '\n'
1660
+ });
1661
+ }
1662
+ while (++index < nodes.length) {
1663
+ if (index) result.push({
1664
+ type: 'text',
1665
+ value: '\n'
1666
+ });
1667
+ result.push(nodes[index]);
1668
+ }
1669
+ if (loose && nodes.length > 0) {
1670
+ result.push({
1671
+ type: 'text',
1672
+ value: '\n'
1673
+ });
1674
+ }
1675
+ return result;
1676
+ }
1677
+
1678
+ /**
1679
+ * Trim spaces and tabs at the start of `value`.
1680
+ *
1681
+ * @param {string} value
1682
+ * Value to trim.
1683
+ * @returns {string}
1684
+ * Result.
1685
+ */
1686
+ function trimMarkdownSpaceStart(value) {
1687
+ let index = 0;
1688
+ let code = value.charCodeAt(index);
1689
+ while (code === 9 || code === 32) {
1690
+ index++;
1691
+ code = value.charCodeAt(index);
1692
+ }
1693
+ return value.slice(index);
1694
+ }
1695
+
1696
+ /**
1697
+ * @typedef {import('hast').Nodes} HastNodes
1698
+ * @typedef {import('mdast').Nodes} MdastNodes
1699
+ * @typedef {import('./state.js').Options} Options
1700
+ */
1701
+
1702
+
1703
+ /**
1704
+ * Transform mdast to hast.
1705
+ *
1706
+ * ##### Notes
1707
+ *
1708
+ * ###### HTML
1709
+ *
1710
+ * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
1711
+ * as semistandard `raw` nodes.
1712
+ * Most utilities ignore `raw` nodes but two notable ones don’t:
1713
+ *
1714
+ * * `hast-util-to-html` also has an option `allowDangerousHtml` which will
1715
+ * output the raw HTML.
1716
+ * This is typically discouraged as noted by the option name but is useful
1717
+ * if you completely trust authors
1718
+ * * `hast-util-raw` can handle the raw embedded HTML strings by parsing them
1719
+ * into standard hast nodes (`element`, `text`, etc).
1720
+ * This is a heavy task as it needs a full HTML parser, but it is the only
1721
+ * way to support untrusted content
1722
+ *
1723
+ * ###### Footnotes
1724
+ *
1725
+ * Many options supported here relate to footnotes.
1726
+ * Footnotes are not specified by CommonMark, which we follow by default.
1727
+ * They are supported by GitHub, so footnotes can be enabled in markdown with
1728
+ * `mdast-util-gfm`.
1729
+ *
1730
+ * The options `footnoteBackLabel` and `footnoteLabel` define natural language
1731
+ * that explains footnotes, which is hidden for sighted users but shown to
1732
+ * assistive technology.
1733
+ * When your page is not in English, you must define translated values.
1734
+ *
1735
+ * Back references use ARIA attributes, but the section label itself uses a
1736
+ * heading that is hidden with an `sr-only` class.
1737
+ * To show it to sighted users, define different attributes in
1738
+ * `footnoteLabelProperties`.
1739
+ *
1740
+ * ###### Clobbering
1741
+ *
1742
+ * Footnotes introduces a problem, as it links footnote calls to footnote
1743
+ * definitions on the page through `id` attributes generated from user content,
1744
+ * which results in DOM clobbering.
1745
+ *
1746
+ * DOM clobbering is this:
1747
+ *
1748
+ * ```html
1749
+ * <p id=x></p>
1750
+ * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
1751
+ * ```
1752
+ *
1753
+ * Elements by their ID are made available by browsers on the `window` object,
1754
+ * which is a security risk.
1755
+ * Using a prefix solves this problem.
1756
+ *
1757
+ * More information on how to handle clobbering and the prefix is explained in
1758
+ * Example: headings (DOM clobbering) in `rehype-sanitize`.
1759
+ *
1760
+ * ###### Unknown nodes
1761
+ *
1762
+ * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
1763
+ * The default behavior for unknown nodes is:
1764
+ *
1765
+ * * when the node has a `value` (and doesn’t have `data.hName`,
1766
+ * `data.hProperties`, or `data.hChildren`, see later), create a hast `text`
1767
+ * node
1768
+ * * otherwise, create a `<div>` element (which could be changed with
1769
+ * `data.hName`), with its children mapped from mdast to hast as well
1770
+ *
1771
+ * This behavior can be changed by passing an `unknownHandler`.
1772
+ *
1773
+ * @param {MdastNodes} tree
1774
+ * mdast tree.
1775
+ * @param {Options | null | undefined} [options]
1776
+ * Configuration (optional).
1777
+ * @returns {HastNodes}
1778
+ * hast tree.
1779
+ */
1780
+ function toHast(tree, options) {
1781
+ const state = createState(tree, options);
1782
+ const node = state.one(tree, undefined);
1783
+ const foot = footer(state);
1784
+ /** @type {HastNodes} */
1785
+ const result = Array.isArray(node) ? {
1786
+ type: 'root',
1787
+ children: node
1788
+ } : node || {
1789
+ type: 'root',
1790
+ children: []
1791
+ };
1792
+ if (foot) {
1793
+ result.children.push({
1794
+ type: 'text',
1795
+ value: '\n'
1796
+ }, foot);
1797
+ }
1798
+ return result;
1799
+ }
1800
+
1801
+ /**
1802
+ * @import {Root as HastRoot} from 'hast'
1803
+ * @import {Root as MdastRoot} from 'mdast'
1804
+ * @import {Options as ToHastOptions} from 'mdast-util-to-hast'
1805
+ * @import {Processor} from 'unified'
1806
+ * @import {VFile} from 'vfile'
1807
+ */
1808
+
1809
+
1810
+ /**
1811
+ * Turn markdown into HTML.
1812
+ *
1813
+ * ##### Notes
1814
+ *
1815
+ * ###### Signature
1816
+ *
1817
+ * * if a processor is given,
1818
+ * runs the (rehype) plugins used on it with a hast tree,
1819
+ * then discards the result (*bridge mode*)
1820
+ * * otherwise,
1821
+ * returns a hast tree,
1822
+ * the plugins used after `remarkRehype` are rehype plugins (*mutate mode*)
1823
+ *
1824
+ * > 👉 **Note**:
1825
+ * > It’s highly unlikely that you want to pass a `processor`.
1826
+ *
1827
+ * ###### HTML
1828
+ *
1829
+ * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
1830
+ * as semistandard `raw` nodes.
1831
+ * Most plugins ignore `raw` nodes but two notable ones don’t:
1832
+ *
1833
+ * * `rehype-stringify` also has an option `allowDangerousHtml` which will
1834
+ * output the raw HTML.
1835
+ * This is typically discouraged as noted by the option name but is useful if
1836
+ * you completely trust authors
1837
+ * * `rehype-raw` can handle the raw embedded HTML strings by parsing them
1838
+ * into standard hast nodes (`element`, `text`, etc);
1839
+ * this is a heavy task as it needs a full HTML parser,
1840
+ * but it is the only way to support untrusted content
1841
+ *
1842
+ * ###### Footnotes
1843
+ *
1844
+ * Many options supported here relate to footnotes.
1845
+ * Footnotes are not specified by CommonMark,
1846
+ * which we follow by default.
1847
+ * They are supported by GitHub,
1848
+ * so footnotes can be enabled in markdown with `remark-gfm`.
1849
+ *
1850
+ * The options `footnoteBackLabel` and `footnoteLabel` define natural language
1851
+ * that explains footnotes,
1852
+ * which is hidden for sighted users but shown to assistive technology.
1853
+ * When your page is not in English,
1854
+ * you must define translated values.
1855
+ *
1856
+ * Back references use ARIA attributes,
1857
+ * but the section label itself uses a heading that is hidden with an
1858
+ * `sr-only` class.
1859
+ * To show it to sighted users,
1860
+ * define different attributes in `footnoteLabelProperties`.
1861
+ *
1862
+ * ###### Clobbering
1863
+ *
1864
+ * Footnotes introduces a problem,
1865
+ * as it links footnote calls to footnote definitions on the page through `id`
1866
+ * attributes generated from user content,
1867
+ * which results in DOM clobbering.
1868
+ *
1869
+ * DOM clobbering is this:
1870
+ *
1871
+ * ```html
1872
+ * <p id=x></p>
1873
+ * <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
1874
+ * ```
1875
+ *
1876
+ * Elements by their ID are made available by browsers on the `window` object,
1877
+ * which is a security risk.
1878
+ * Using a prefix solves this problem.
1879
+ *
1880
+ * More information on how to handle clobbering and the prefix is explained in
1881
+ * *Example: headings (DOM clobbering)* in `rehype-sanitize`.
1882
+ *
1883
+ * ###### Unknown nodes
1884
+ *
1885
+ * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`.
1886
+ * The default behavior for unknown nodes is:
1887
+ *
1888
+ * * when the node has a `value`
1889
+ * (and doesn’t have `data.hName`, `data.hProperties`, or `data.hChildren`,
1890
+ * see later),
1891
+ * create a hast `text` node
1892
+ * * otherwise,
1893
+ * create a `<div>` element (which could be changed with `data.hName`),
1894
+ * with its children mapped from mdast to hast as well
1895
+ *
1896
+ * This behavior can be changed by passing an `unknownHandler`.
1897
+ *
1898
+ * @overload
1899
+ * @param {Processor} processor
1900
+ * @param {Readonly<Options> | null | undefined} [options]
1901
+ * @returns {TransformBridge}
1902
+ *
1903
+ * @overload
1904
+ * @param {Readonly<Options> | null | undefined} [options]
1905
+ * @returns {TransformMutate}
1906
+ *
1907
+ * @overload
1908
+ * @param {Readonly<Options> | Processor | null | undefined} [destination]
1909
+ * @param {Readonly<Options> | null | undefined} [options]
1910
+ * @returns {TransformBridge | TransformMutate}
1911
+ *
1912
+ * @param {Readonly<Options> | Processor | null | undefined} [destination]
1913
+ * Processor or configuration (optional).
1914
+ * @param {Readonly<Options> | null | undefined} [options]
1915
+ * When a processor was given,
1916
+ * configuration (optional).
1917
+ * @returns {TransformBridge | TransformMutate}
1918
+ * Transform.
1919
+ */
1920
+ function remarkRehype(destination, options) {
1921
+ if (destination && 'run' in destination) {
1922
+ /**
1923
+ * @type {TransformBridge}
1924
+ */
1925
+ return async function (tree, file) {
1926
+ // Cast because root in -> root out.
1927
+ const hastTree = /** @type {HastRoot} */
1928
+ toHast(tree, {
1929
+ file,
1930
+ ...options
1931
+ });
1932
+ await destination.run(hastTree, file);
1933
+ };
1934
+ }
1935
+
1936
+ /**
1937
+ * @type {TransformMutate}
1938
+ */
1939
+ return function (tree, file) {
1940
+ // Cast because root in -> root out.
1941
+ // To do: in the future, disallow ` || options` fallback.
1942
+ // With `unified-engine`, `destination` can be `undefined` but
1943
+ // `options` will be the file set.
1944
+ // We should not pass that as `options`.
1945
+ return /** @type {HastRoot} */toHast(tree, {
1946
+ file,
1947
+ ...(destination || options)
1948
+ });
1949
+ };
1950
+ }
1951
+
1952
+ export { remarkRehype as default, defaultFootnoteBackContent, defaultFootnoteBackLabel, handlers as defaultHandlers };
1953
+ //# sourceMappingURL=index-C8S2G0FH.js.map