ember-repl 7.1.0 → 7.1.2

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