Spaces:
Paused

Leon4gr45 commited on
Commit
867a9f1
·
verified ·
1 Parent(s): de1749b

Include updated package-lock.json (part 2)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. node_modules/math-intrinsics/constants/maxValue.js +5 -0
  2. node_modules/math-intrinsics/floor.d.ts +1 -0
  3. node_modules/math-intrinsics/floor.js +4 -0
  4. node_modules/math-intrinsics/isFinite.d.ts +3 -0
  5. node_modules/math-intrinsics/isFinite.js +12 -0
  6. node_modules/math-intrinsics/isInteger.d.ts +3 -0
  7. node_modules/math-intrinsics/isInteger.js +16 -0
  8. node_modules/math-intrinsics/isNaN.d.ts +1 -0
  9. node_modules/math-intrinsics/isNaN.js +6 -0
  10. node_modules/math-intrinsics/isNegativeZero.d.ts +3 -0
  11. node_modules/math-intrinsics/isNegativeZero.js +6 -0
  12. node_modules/math-intrinsics/max.d.ts +1 -0
  13. node_modules/math-intrinsics/max.js +4 -0
  14. node_modules/math-intrinsics/min.d.ts +1 -0
  15. node_modules/math-intrinsics/min.js +4 -0
  16. node_modules/math-intrinsics/mod.d.ts +3 -0
  17. node_modules/math-intrinsics/mod.js +9 -0
  18. node_modules/math-intrinsics/package.json +86 -0
  19. node_modules/math-intrinsics/pow.d.ts +1 -0
  20. node_modules/math-intrinsics/pow.js +4 -0
  21. node_modules/math-intrinsics/round.d.ts +1 -0
  22. node_modules/math-intrinsics/round.js +4 -0
  23. node_modules/math-intrinsics/sign.d.ts +3 -0
  24. node_modules/math-intrinsics/sign.js +11 -0
  25. node_modules/math-intrinsics/test/index.js +192 -0
  26. node_modules/math-intrinsics/tsconfig.json +3 -0
  27. node_modules/mdast-util-find-and-replace/index.d.ts +9 -0
  28. node_modules/mdast-util-find-and-replace/index.d.ts.map +1 -0
  29. node_modules/mdast-util-find-and-replace/index.js +11 -0
  30. node_modules/mdast-util-find-and-replace/lib/index.d.ts +79 -0
  31. node_modules/mdast-util-find-and-replace/lib/index.d.ts.map +1 -0
  32. node_modules/mdast-util-find-and-replace/lib/index.js +261 -0
  33. node_modules/mdast-util-find-and-replace/license +22 -0
  34. node_modules/mdast-util-find-and-replace/package.json +85 -0
  35. node_modules/mdast-util-find-and-replace/readme.md +368 -0
  36. node_modules/mdast-util-from-markdown/dev/index.d.ts +23 -0
  37. node_modules/mdast-util-from-markdown/dev/index.js +2 -0
  38. node_modules/mdast-util-from-markdown/dev/lib/index.d.ts +53 -0
  39. node_modules/mdast-util-from-markdown/dev/lib/index.d.ts.map +1 -0
  40. node_modules/mdast-util-from-markdown/dev/lib/index.js +1348 -0
  41. node_modules/mdast-util-from-markdown/dev/lib/types.d.ts +295 -0
  42. node_modules/mdast-util-from-markdown/dev/lib/types.js +2 -0
  43. node_modules/mdast-util-from-markdown/index.d.ts +23 -0
  44. node_modules/mdast-util-from-markdown/index.js +2 -0
  45. node_modules/mdast-util-from-markdown/lib/index.d.ts +53 -0
  46. node_modules/mdast-util-from-markdown/lib/index.d.ts.map +1 -0
  47. node_modules/mdast-util-from-markdown/lib/index.js +1177 -0
  48. node_modules/mdast-util-from-markdown/lib/types.d.ts +295 -0
  49. node_modules/mdast-util-from-markdown/lib/types.js +2 -0
  50. node_modules/mdast-util-from-markdown/license +22 -0
node_modules/math-intrinsics/constants/maxValue.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./maxValue')} */
4
+ // eslint-disable-next-line no-extra-parens
5
+ module.exports = /** @type {import('./maxValue')} */ (Number.MAX_VALUE) || 1.7976931348623157e+308;
node_modules/math-intrinsics/floor.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Math.floor;
node_modules/math-intrinsics/floor.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./floor')} */
4
+ module.exports = Math.floor;
node_modules/math-intrinsics/isFinite.d.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ declare function isFinite(x: unknown): x is number | bigint;
2
+
3
+ export = isFinite;
node_modules/math-intrinsics/isFinite.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var $isNaN = require('./isNaN');
4
+
5
+ /** @type {import('./isFinite')} */
6
+ module.exports = function isFinite(x) {
7
+ return (typeof x === 'number' || typeof x === 'bigint')
8
+ && !$isNaN(x)
9
+ && x !== Infinity
10
+ && x !== -Infinity;
11
+ };
12
+
node_modules/math-intrinsics/isInteger.d.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ declare function isInteger(argument: unknown): argument is number;
2
+
3
+ export = isInteger;
node_modules/math-intrinsics/isInteger.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var $abs = require('./abs');
4
+ var $floor = require('./floor');
5
+
6
+ var $isNaN = require('./isNaN');
7
+ var $isFinite = require('./isFinite');
8
+
9
+ /** @type {import('./isInteger')} */
10
+ module.exports = function isInteger(argument) {
11
+ if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {
12
+ return false;
13
+ }
14
+ var absValue = $abs(argument);
15
+ return $floor(absValue) === absValue;
16
+ };
node_modules/math-intrinsics/isNaN.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Number.isNaN;
node_modules/math-intrinsics/isNaN.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./isNaN')} */
4
+ module.exports = Number.isNaN || function isNaN(a) {
5
+ return a !== a;
6
+ };
node_modules/math-intrinsics/isNegativeZero.d.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ declare function isNegativeZero(x: unknown): boolean;
2
+
3
+ export = isNegativeZero;
node_modules/math-intrinsics/isNegativeZero.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./isNegativeZero')} */
4
+ module.exports = function isNegativeZero(x) {
5
+ return x === 0 && 1 / x === 1 / -0;
6
+ };
node_modules/math-intrinsics/max.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Math.max;
node_modules/math-intrinsics/max.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./max')} */
4
+ module.exports = Math.max;
node_modules/math-intrinsics/min.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Math.min;
node_modules/math-intrinsics/min.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./min')} */
4
+ module.exports = Math.min;
node_modules/math-intrinsics/mod.d.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ declare function mod(number: number, modulo: number): number;
2
+
3
+ export = mod;
node_modules/math-intrinsics/mod.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var $floor = require('./floor');
4
+
5
+ /** @type {import('./mod')} */
6
+ module.exports = function mod(number, modulo) {
7
+ var remain = number % modulo;
8
+ return $floor(remain >= 0 ? remain : remain + modulo);
9
+ };
node_modules/math-intrinsics/package.json ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "math-intrinsics",
3
+ "version": "1.1.0",
4
+ "description": "ES Math-related intrinsics and helpers, robustly cached.",
5
+ "main": false,
6
+ "exports": {
7
+ "./abs": "./abs.js",
8
+ "./floor": "./floor.js",
9
+ "./isFinite": "./isFinite.js",
10
+ "./isInteger": "./isInteger.js",
11
+ "./isNaN": "./isNaN.js",
12
+ "./isNegativeZero": "./isNegativeZero.js",
13
+ "./max": "./max.js",
14
+ "./min": "./min.js",
15
+ "./mod": "./mod.js",
16
+ "./pow": "./pow.js",
17
+ "./sign": "./sign.js",
18
+ "./round": "./round.js",
19
+ "./constants/maxArrayLength": "./constants/maxArrayLength.js",
20
+ "./constants/maxSafeInteger": "./constants/maxSafeInteger.js",
21
+ "./constants/maxValue": "./constants/maxValue.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "sideEffects": false,
25
+ "scripts": {
26
+ "prepack": "npmignore --auto --commentLines=autogenerated",
27
+ "prepublishOnly": "safe-publish-latest",
28
+ "prepublish": "not-in-publish || npm run prepublishOnly",
29
+ "pretest": "npm run lint",
30
+ "test": "npm run tests-only",
31
+ "tests-only": "nyc tape 'test/**/*.js'",
32
+ "posttest": "npx npm@'>= 10.2' audit --production",
33
+ "prelint": "evalmd README.md && eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)",
34
+ "lint": "eslint --ext=js,mjs .",
35
+ "postlint": "tsc && attw -P",
36
+ "version": "auto-changelog && git add CHANGELOG.md",
37
+ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/es-shims/math-intrinsics.git"
42
+ },
43
+ "author": "Jordan Harband <ljharb@gmail.com>",
44
+ "license": "MIT",
45
+ "bugs": {
46
+ "url": "https://github.com/es-shims/math-intrinsics/issues"
47
+ },
48
+ "homepage": "https://github.com/es-shims/math-intrinsics#readme",
49
+ "devDependencies": {
50
+ "@arethetypeswrong/cli": "^0.17.1",
51
+ "@ljharb/eslint-config": "^21.1.1",
52
+ "@ljharb/tsconfig": "^0.2.2",
53
+ "@types/for-each": "^0.3.3",
54
+ "@types/object-inspect": "^1.13.0",
55
+ "@types/tape": "^5.8.0",
56
+ "auto-changelog": "^2.5.0",
57
+ "eclint": "^2.8.1",
58
+ "es-value-fixtures": "^1.5.0",
59
+ "eslint": "^8.8.0",
60
+ "evalmd": "^0.0.19",
61
+ "for-each": "^0.3.3",
62
+ "in-publish": "^2.0.1",
63
+ "npmignore": "^0.3.1",
64
+ "nyc": "^10.3.2",
65
+ "object-inspect": "^1.13.3",
66
+ "safe-publish-latest": "^2.0.0",
67
+ "tape": "^5.9.0",
68
+ "typescript": "next"
69
+ },
70
+ "auto-changelog": {
71
+ "output": "CHANGELOG.md",
72
+ "template": "keepachangelog",
73
+ "unreleased": false,
74
+ "commitLimit": false,
75
+ "backfillLimit": false,
76
+ "hideCredit": true
77
+ },
78
+ "publishConfig": {
79
+ "ignore": [
80
+ ".github/workflows"
81
+ ]
82
+ },
83
+ "engines": {
84
+ "node": ">= 0.4"
85
+ }
86
+ }
node_modules/math-intrinsics/pow.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Math.pow;
node_modules/math-intrinsics/pow.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./pow')} */
4
+ module.exports = Math.pow;
node_modules/math-intrinsics/round.d.ts ADDED
@@ -0,0 +1 @@
 
 
1
+ export = Math.round;
node_modules/math-intrinsics/round.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /** @type {import('./round')} */
4
+ module.exports = Math.round;
node_modules/math-intrinsics/sign.d.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ declare function sign(x: number): number;
2
+
3
+ export = sign;
node_modules/math-intrinsics/sign.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var $isNaN = require('./isNaN');
4
+
5
+ /** @type {import('./sign')} */
6
+ module.exports = function sign(number) {
7
+ if ($isNaN(number) || number === 0) {
8
+ return number;
9
+ }
10
+ return number < 0 ? -1 : +1;
11
+ };
node_modules/math-intrinsics/test/index.js ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var test = require('tape');
4
+ var v = require('es-value-fixtures');
5
+ var forEach = require('for-each');
6
+ var inspect = require('object-inspect');
7
+
8
+ var abs = require('../abs');
9
+ var floor = require('../floor');
10
+ var isFinite = require('../isFinite');
11
+ var isInteger = require('../isInteger');
12
+ var isNaN = require('../isNaN');
13
+ var isNegativeZero = require('../isNegativeZero');
14
+ var max = require('../max');
15
+ var min = require('../min');
16
+ var mod = require('../mod');
17
+ var pow = require('../pow');
18
+ var round = require('../round');
19
+ var sign = require('../sign');
20
+
21
+ var maxArrayLength = require('../constants/maxArrayLength');
22
+ var maxSafeInteger = require('../constants/maxSafeInteger');
23
+ var maxValue = require('../constants/maxValue');
24
+
25
+ test('abs', function (t) {
26
+ t.equal(abs(-1), 1, 'abs(-1) === 1');
27
+ t.equal(abs(+1), 1, 'abs(+1) === 1');
28
+ t.equal(abs(+0), +0, 'abs(+0) === +0');
29
+ t.equal(abs(-0), +0, 'abs(-0) === +0');
30
+
31
+ t.end();
32
+ });
33
+
34
+ test('floor', function (t) {
35
+ t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
36
+ t.equal(floor(+1.1), 1, 'floor(+1.1) === 1');
37
+ t.equal(floor(+0), +0, 'floor(+0) === +0');
38
+ t.equal(floor(-0), -0, 'floor(-0) === -0');
39
+ t.equal(floor(-Infinity), -Infinity, 'floor(-Infinity) === -Infinity');
40
+ t.equal(floor(Number(Infinity)), Number(Infinity), 'floor(+Infinity) === +Infinity');
41
+ t.equal(floor(NaN), NaN, 'floor(NaN) === NaN');
42
+ t.equal(floor(0), +0, 'floor(0) === +0');
43
+ t.equal(floor(-0), -0, 'floor(-0) === -0');
44
+ t.equal(floor(1), 1, 'floor(1) === 1');
45
+ t.equal(floor(-1), -1, 'floor(-1) === -1');
46
+ t.equal(floor(1.1), 1, 'floor(1.1) === 1');
47
+ t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
48
+ t.equal(floor(maxValue), maxValue, 'floor(maxValue) === maxValue');
49
+ t.equal(floor(maxSafeInteger), maxSafeInteger, 'floor(maxSafeInteger) === maxSafeInteger');
50
+
51
+ t.end();
52
+ });
53
+
54
+ test('isFinite', function (t) {
55
+ t.equal(isFinite(0), true, 'isFinite(+0) === true');
56
+ t.equal(isFinite(-0), true, 'isFinite(-0) === true');
57
+ t.equal(isFinite(1), true, 'isFinite(1) === true');
58
+ t.equal(isFinite(Infinity), false, 'isFinite(Infinity) === false');
59
+ t.equal(isFinite(-Infinity), false, 'isFinite(-Infinity) === false');
60
+ t.equal(isFinite(NaN), false, 'isFinite(NaN) === false');
61
+
62
+ forEach(v.nonNumbers, function (nonNumber) {
63
+ t.equal(isFinite(nonNumber), false, 'isFinite(' + inspect(nonNumber) + ') === false');
64
+ });
65
+
66
+ t.end();
67
+ });
68
+
69
+ test('isInteger', function (t) {
70
+ forEach([].concat(
71
+ // @ts-expect-error TS sucks with concat
72
+ v.nonNumbers,
73
+ v.nonIntegerNumbers
74
+ ), function (nonInteger) {
75
+ t.equal(isInteger(nonInteger), false, 'isInteger(' + inspect(nonInteger) + ') === false');
76
+ });
77
+
78
+ t.end();
79
+ });
80
+
81
+ test('isNaN', function (t) {
82
+ forEach([].concat(
83
+ // @ts-expect-error TS sucks with concat
84
+ v.nonNumbers,
85
+ v.infinities,
86
+ v.zeroes,
87
+ v.integerNumbers
88
+ ), function (nonNaN) {
89
+ t.equal(isNaN(nonNaN), false, 'isNaN(' + inspect(nonNaN) + ') === false');
90
+ });
91
+
92
+ t.equal(isNaN(NaN), true, 'isNaN(NaN) === true');
93
+
94
+ t.end();
95
+ });
96
+
97
+ test('isNegativeZero', function (t) {
98
+ t.equal(isNegativeZero(-0), true, 'isNegativeZero(-0) === true');
99
+ t.equal(isNegativeZero(+0), false, 'isNegativeZero(+0) === false');
100
+ t.equal(isNegativeZero(1), false, 'isNegativeZero(1) === false');
101
+ t.equal(isNegativeZero(-1), false, 'isNegativeZero(-1) === false');
102
+ t.equal(isNegativeZero(NaN), false, 'isNegativeZero(NaN) === false');
103
+ t.equal(isNegativeZero(Infinity), false, 'isNegativeZero(Infinity) === false');
104
+ t.equal(isNegativeZero(-Infinity), false, 'isNegativeZero(-Infinity) === false');
105
+
106
+ forEach(v.nonNumbers, function (nonNumber) {
107
+ t.equal(isNegativeZero(nonNumber), false, 'isNegativeZero(' + inspect(nonNumber) + ') === false');
108
+ });
109
+
110
+ t.end();
111
+ });
112
+
113
+ test('max', function (t) {
114
+ t.equal(max(1, 2), 2, 'max(1, 2) === 2');
115
+ t.equal(max(1, 2, 3), 3, 'max(1, 2, 3) === 3');
116
+ t.equal(max(1, 2, 3, 4), 4, 'max(1, 2, 3, 4) === 4');
117
+ t.equal(max(1, 2, 3, 4, 5), 5, 'max(1, 2, 3, 4, 5) === 5');
118
+ t.equal(max(1, 2, 3, 4, 5, 6), 6, 'max(1, 2, 3, 4, 5, 6) === 6');
119
+ t.equal(max(1, 2, 3, 4, 5, 6, 7), 7, 'max(1, 2, 3, 4, 5, 6, 7) === 7');
120
+
121
+ t.end();
122
+ });
123
+
124
+ test('min', function (t) {
125
+ t.equal(min(1, 2), 1, 'min(1, 2) === 1');
126
+ t.equal(min(1, 2, 3), 1, 'min(1, 2, 3) === 1');
127
+ t.equal(min(1, 2, 3, 4), 1, 'min(1, 2, 3, 4) === 1');
128
+ t.equal(min(1, 2, 3, 4, 5), 1, 'min(1, 2, 3, 4, 5) === 1');
129
+ t.equal(min(1, 2, 3, 4, 5, 6), 1, 'min(1, 2, 3, 4, 5, 6) === 1');
130
+
131
+ t.end();
132
+ });
133
+
134
+ test('mod', function (t) {
135
+ t.equal(mod(1, 2), 1, 'mod(1, 2) === 1');
136
+ t.equal(mod(2, 2), 0, 'mod(2, 2) === 0');
137
+ t.equal(mod(3, 2), 1, 'mod(3, 2) === 1');
138
+ t.equal(mod(4, 2), 0, 'mod(4, 2) === 0');
139
+ t.equal(mod(5, 2), 1, 'mod(5, 2) === 1');
140
+ t.equal(mod(6, 2), 0, 'mod(6, 2) === 0');
141
+ t.equal(mod(7, 2), 1, 'mod(7, 2) === 1');
142
+ t.equal(mod(8, 2), 0, 'mod(8, 2) === 0');
143
+ t.equal(mod(9, 2), 1, 'mod(9, 2) === 1');
144
+ t.equal(mod(10, 2), 0, 'mod(10, 2) === 0');
145
+ t.equal(mod(11, 2), 1, 'mod(11, 2) === 1');
146
+
147
+ t.end();
148
+ });
149
+
150
+ test('pow', function (t) {
151
+ t.equal(pow(2, 2), 4, 'pow(2, 2) === 4');
152
+ t.equal(pow(2, 3), 8, 'pow(2, 3) === 8');
153
+ t.equal(pow(2, 4), 16, 'pow(2, 4) === 16');
154
+ t.equal(pow(2, 5), 32, 'pow(2, 5) === 32');
155
+ t.equal(pow(2, 6), 64, 'pow(2, 6) === 64');
156
+ t.equal(pow(2, 7), 128, 'pow(2, 7) === 128');
157
+ t.equal(pow(2, 8), 256, 'pow(2, 8) === 256');
158
+ t.equal(pow(2, 9), 512, 'pow(2, 9) === 512');
159
+ t.equal(pow(2, 10), 1024, 'pow(2, 10) === 1024');
160
+
161
+ t.end();
162
+ });
163
+
164
+ test('round', function (t) {
165
+ t.equal(round(1.1), 1, 'round(1.1) === 1');
166
+ t.equal(round(1.5), 2, 'round(1.5) === 2');
167
+ t.equal(round(1.9), 2, 'round(1.9) === 2');
168
+
169
+ t.end();
170
+ });
171
+
172
+ test('sign', function (t) {
173
+ t.equal(sign(-1), -1, 'sign(-1) === -1');
174
+ t.equal(sign(+1), +1, 'sign(+1) === +1');
175
+ t.equal(sign(+0), +0, 'sign(+0) === +0');
176
+ t.equal(sign(-0), -0, 'sign(-0) === -0');
177
+ t.equal(sign(NaN), NaN, 'sign(NaN) === NaN');
178
+ t.equal(sign(Infinity), +1, 'sign(Infinity) === +1');
179
+ t.equal(sign(-Infinity), -1, 'sign(-Infinity) === -1');
180
+ t.equal(sign(maxValue), +1, 'sign(maxValue) === +1');
181
+ t.equal(sign(maxSafeInteger), +1, 'sign(maxSafeInteger) === +1');
182
+
183
+ t.end();
184
+ });
185
+
186
+ test('constants', function (t) {
187
+ t.equal(typeof maxArrayLength, 'number', 'typeof maxArrayLength === "number"');
188
+ t.equal(typeof maxSafeInteger, 'number', 'typeof maxSafeInteger === "number"');
189
+ t.equal(typeof maxValue, 'number', 'typeof maxValue === "number"');
190
+
191
+ t.end();
192
+ });
node_modules/math-intrinsics/tsconfig.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "extends": "@ljharb/tsconfig",
3
+ }
node_modules/mdast-util-find-and-replace/index.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export { findAndReplace } from "./lib/index.js";
2
+ export type FindAndReplaceList = import("./lib/index.js").FindAndReplaceList;
3
+ export type FindAndReplaceTuple = import("./lib/index.js").FindAndReplaceTuple;
4
+ export type Find = import("./lib/index.js").Find;
5
+ export type Options = import("./lib/index.js").Options;
6
+ export type RegExpMatchObject = import("./lib/index.js").RegExpMatchObject;
7
+ export type ReplaceFunction = import("./lib/index.js").ReplaceFunction;
8
+ export type Replace = import("./lib/index.js").Replace;
9
+ //# sourceMappingURL=index.d.ts.map
node_modules/mdast-util-find-and-replace/index.d.ts.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";iCACa,OAAO,gBAAgB,EAAE,kBAAkB;kCAC3C,OAAO,gBAAgB,EAAE,mBAAmB;mBAC5C,OAAO,gBAAgB,EAAE,IAAI;sBAC7B,OAAO,gBAAgB,EAAE,OAAO;gCAChC,OAAO,gBAAgB,EAAE,iBAAiB;8BAC1C,OAAO,gBAAgB,EAAE,eAAe;sBACxC,OAAO,gBAAgB,EAAE,OAAO"}
node_modules/mdast-util-find-and-replace/index.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @typedef {import('./lib/index.js').FindAndReplaceList} FindAndReplaceList
3
+ * @typedef {import('./lib/index.js').FindAndReplaceTuple} FindAndReplaceTuple
4
+ * @typedef {import('./lib/index.js').Find} Find
5
+ * @typedef {import('./lib/index.js').Options} Options
6
+ * @typedef {import('./lib/index.js').RegExpMatchObject} RegExpMatchObject
7
+ * @typedef {import('./lib/index.js').ReplaceFunction} ReplaceFunction
8
+ * @typedef {import('./lib/index.js').Replace} Replace
9
+ */
10
+
11
+ export {findAndReplace} from './lib/index.js'
node_modules/mdast-util-find-and-replace/lib/index.d.ts ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Find patterns in a tree and replace them.
3
+ *
4
+ * The algorithm searches the tree in *preorder* for complete values in `Text`
5
+ * nodes.
6
+ * Partial matches are not supported.
7
+ *
8
+ * @param {Nodes} tree
9
+ * Tree to change.
10
+ * @param {FindAndReplaceList | FindAndReplaceTuple} list
11
+ * Patterns to find.
12
+ * @param {Options | null | undefined} [options]
13
+ * Configuration (when `find` is not `Find`).
14
+ * @returns {undefined}
15
+ * Nothing.
16
+ */
17
+ export function findAndReplace(tree: Nodes, list: FindAndReplaceList | FindAndReplaceTuple, options?: Options | null | undefined): undefined;
18
+ /**
19
+ * Info on the match.
20
+ */
21
+ export type RegExpMatchObject = {
22
+ /**
23
+ * The index of the search at which the result was found.
24
+ */
25
+ index: number;
26
+ /**
27
+ * A copy of the search string in the text node.
28
+ */
29
+ input: string;
30
+ /**
31
+ * All ancestors of the text node, where the last node is the text itself.
32
+ */
33
+ stack: [...Array<Parents>, Text];
34
+ };
35
+ /**
36
+ * Pattern to find.
37
+ *
38
+ * Strings are escaped and then turned into global expressions.
39
+ */
40
+ export type Find = RegExp | string;
41
+ /**
42
+ * Several find and replaces, in array form.
43
+ */
44
+ export type FindAndReplaceList = Array<FindAndReplaceTuple>;
45
+ /**
46
+ * Find and replace in tuple form.
47
+ */
48
+ export type FindAndReplaceTuple = [Find, Replace?];
49
+ /**
50
+ * Thing to replace with.
51
+ */
52
+ export type Replace = ReplaceFunction | string | null | undefined;
53
+ /**
54
+ * Callback called when a search matches.
55
+ */
56
+ export type ReplaceFunction = (...parameters: any[]) => Array<PhrasingContent> | PhrasingContent | string | false | null | undefined;
57
+ /**
58
+ * Normalized find and replace.
59
+ */
60
+ export type Pair = [RegExp, ReplaceFunction];
61
+ /**
62
+ * All find and replaced.
63
+ */
64
+ export type Pairs = Array<Pair>;
65
+ /**
66
+ * Configuration.
67
+ */
68
+ export type Options = {
69
+ /**
70
+ * Test for which nodes to ignore (optional).
71
+ */
72
+ ignore?: Test | null | undefined;
73
+ };
74
+ import type { Nodes } from 'mdast';
75
+ import type { Parents } from 'mdast';
76
+ import type { Text } from 'mdast';
77
+ import type { PhrasingContent } from 'mdast';
78
+ import type { Test } from 'unist-util-visit-parents';
79
+ //# sourceMappingURL=index.d.ts.map
node_modules/mdast-util-find-and-replace/lib/index.d.ts.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA6DA;;;;;;;;;;;;;;;GAeG;AACH,qCATW,KAAK,QAEL,kBAAkB,GAAG,mBAAmB,YAExC,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,SAAS,CA6HrB;;;;;;;;WA/La,MAAM;;;;WAEN,MAAM;;;;WAEN,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;;;;;;;mBAG1B,MAAM,GAAG,MAAM;;;;iCAKf,KAAK,CAAC,mBAAmB,CAAC;;;;kCAG1B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;;;;sBAGhB,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;8CAK1C,GAAG,EAAA,KAMJ,KAAK,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS;;;;mBAQ5E,CAAC,MAAM,EAAE,eAAe,CAAC;;;;oBAGzB,KAAK,CAAC,IAAI,CAAC;;;;;;;;aAKV,IAAI,GAAG,IAAI,GAAG,SAAS;;2BApDyB,OAAO;6BAAP,OAAO;0BAAP,OAAO;qCAAP,OAAO;0BACjB,0BAA0B"}
node_modules/mdast-util-find-and-replace/lib/index.js ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @import {Nodes, Parents, PhrasingContent, Root, Text} from 'mdast'
3
+ * @import {BuildVisitor, Test, VisitorResult} from 'unist-util-visit-parents'
4
+ */
5
+
6
+ /**
7
+ * @typedef RegExpMatchObject
8
+ * Info on the match.
9
+ * @property {number} index
10
+ * The index of the search at which the result was found.
11
+ * @property {string} input
12
+ * A copy of the search string in the text node.
13
+ * @property {[...Array<Parents>, Text]} stack
14
+ * All ancestors of the text node, where the last node is the text itself.
15
+ *
16
+ * @typedef {RegExp | string} Find
17
+ * Pattern to find.
18
+ *
19
+ * Strings are escaped and then turned into global expressions.
20
+ *
21
+ * @typedef {Array<FindAndReplaceTuple>} FindAndReplaceList
22
+ * Several find and replaces, in array form.
23
+ *
24
+ * @typedef {[Find, Replace?]} FindAndReplaceTuple
25
+ * Find and replace in tuple form.
26
+ *
27
+ * @typedef {ReplaceFunction | string | null | undefined} Replace
28
+ * Thing to replace with.
29
+ *
30
+ * @callback ReplaceFunction
31
+ * Callback called when a search matches.
32
+ * @param {...any} parameters
33
+ * The parameters are the result of corresponding search expression:
34
+ *
35
+ * * `value` (`string`) — whole match
36
+ * * `...capture` (`Array<string>`) — matches from regex capture groups
37
+ * * `match` (`RegExpMatchObject`) — info on the match
38
+ * @returns {Array<PhrasingContent> | PhrasingContent | string | false | null | undefined}
39
+ * Thing to replace with.
40
+ *
41
+ * * when `null`, `undefined`, `''`, remove the match
42
+ * * …or when `false`, do not replace at all
43
+ * * …or when `string`, replace with a text node of that value
44
+ * * …or when `Node` or `Array<Node>`, replace with those nodes
45
+ *
46
+ * @typedef {[RegExp, ReplaceFunction]} Pair
47
+ * Normalized find and replace.
48
+ *
49
+ * @typedef {Array<Pair>} Pairs
50
+ * All find and replaced.
51
+ *
52
+ * @typedef Options
53
+ * Configuration.
54
+ * @property {Test | null | undefined} [ignore]
55
+ * Test for which nodes to ignore (optional).
56
+ */
57
+
58
+ import escape from 'escape-string-regexp'
59
+ import {visitParents} from 'unist-util-visit-parents'
60
+ import {convert} from 'unist-util-is'
61
+
62
+ /**
63
+ * Find patterns in a tree and replace them.
64
+ *
65
+ * The algorithm searches the tree in *preorder* for complete values in `Text`
66
+ * nodes.
67
+ * Partial matches are not supported.
68
+ *
69
+ * @param {Nodes} tree
70
+ * Tree to change.
71
+ * @param {FindAndReplaceList | FindAndReplaceTuple} list
72
+ * Patterns to find.
73
+ * @param {Options | null | undefined} [options]
74
+ * Configuration (when `find` is not `Find`).
75
+ * @returns {undefined}
76
+ * Nothing.
77
+ */
78
+ export function findAndReplace(tree, list, options) {
79
+ const settings = options || {}
80
+ const ignored = convert(settings.ignore || [])
81
+ const pairs = toPairs(list)
82
+ let pairIndex = -1
83
+
84
+ while (++pairIndex < pairs.length) {
85
+ visitParents(tree, 'text', visitor)
86
+ }
87
+
88
+ /** @type {BuildVisitor<Root, 'text'>} */
89
+ function visitor(node, parents) {
90
+ let index = -1
91
+ /** @type {Parents | undefined} */
92
+ let grandparent
93
+
94
+ while (++index < parents.length) {
95
+ const parent = parents[index]
96
+ /** @type {Array<Nodes> | undefined} */
97
+ const siblings = grandparent ? grandparent.children : undefined
98
+
99
+ if (
100
+ ignored(
101
+ parent,
102
+ siblings ? siblings.indexOf(parent) : undefined,
103
+ grandparent
104
+ )
105
+ ) {
106
+ return
107
+ }
108
+
109
+ grandparent = parent
110
+ }
111
+
112
+ if (grandparent) {
113
+ return handler(node, parents)
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Handle a text node which is not in an ignored parent.
119
+ *
120
+ * @param {Text} node
121
+ * Text node.
122
+ * @param {Array<Parents>} parents
123
+ * Parents.
124
+ * @returns {VisitorResult}
125
+ * Result.
126
+ */
127
+ function handler(node, parents) {
128
+ const parent = parents[parents.length - 1]
129
+ const find = pairs[pairIndex][0]
130
+ const replace = pairs[pairIndex][1]
131
+ let start = 0
132
+ /** @type {Array<Nodes>} */
133
+ const siblings = parent.children
134
+ const index = siblings.indexOf(node)
135
+ let change = false
136
+ /** @type {Array<PhrasingContent>} */
137
+ let nodes = []
138
+
139
+ find.lastIndex = 0
140
+
141
+ let match = find.exec(node.value)
142
+
143
+ while (match) {
144
+ const position = match.index
145
+ /** @type {RegExpMatchObject} */
146
+ const matchObject = {
147
+ index: match.index,
148
+ input: match.input,
149
+ stack: [...parents, node]
150
+ }
151
+ let value = replace(...match, matchObject)
152
+
153
+ if (typeof value === 'string') {
154
+ value = value.length > 0 ? {type: 'text', value} : undefined
155
+ }
156
+
157
+ // It wasn’t a match after all.
158
+ if (value === false) {
159
+ // False acts as if there was no match.
160
+ // So we need to reset `lastIndex`, which currently being at the end of
161
+ // the current match, to the beginning.
162
+ find.lastIndex = position + 1
163
+ } else {
164
+ if (start !== position) {
165
+ nodes.push({
166
+ type: 'text',
167
+ value: node.value.slice(start, position)
168
+ })
169
+ }
170
+
171
+ if (Array.isArray(value)) {
172
+ nodes.push(...value)
173
+ } else if (value) {
174
+ nodes.push(value)
175
+ }
176
+
177
+ start = position + match[0].length
178
+ change = true
179
+ }
180
+
181
+ if (!find.global) {
182
+ break
183
+ }
184
+
185
+ match = find.exec(node.value)
186
+ }
187
+
188
+ if (change) {
189
+ if (start < node.value.length) {
190
+ nodes.push({type: 'text', value: node.value.slice(start)})
191
+ }
192
+
193
+ parent.children.splice(index, 1, ...nodes)
194
+ } else {
195
+ nodes = [node]
196
+ }
197
+
198
+ return index + nodes.length
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Turn a tuple or a list of tuples into pairs.
204
+ *
205
+ * @param {FindAndReplaceList | FindAndReplaceTuple} tupleOrList
206
+ * Schema.
207
+ * @returns {Pairs}
208
+ * Clean pairs.
209
+ */
210
+ function toPairs(tupleOrList) {
211
+ /** @type {Pairs} */
212
+ const result = []
213
+
214
+ if (!Array.isArray(tupleOrList)) {
215
+ throw new TypeError('Expected find and replace tuple or list of tuples')
216
+ }
217
+
218
+ /** @type {FindAndReplaceList} */
219
+ // @ts-expect-error: correct.
220
+ const list =
221
+ !tupleOrList[0] || Array.isArray(tupleOrList[0])
222
+ ? tupleOrList
223
+ : [tupleOrList]
224
+
225
+ let index = -1
226
+
227
+ while (++index < list.length) {
228
+ const tuple = list[index]
229
+ result.push([toExpression(tuple[0]), toFunction(tuple[1])])
230
+ }
231
+
232
+ return result
233
+ }
234
+
235
+ /**
236
+ * Turn a find into an expression.
237
+ *
238
+ * @param {Find} find
239
+ * Find.
240
+ * @returns {RegExp}
241
+ * Expression.
242
+ */
243
+ function toExpression(find) {
244
+ return typeof find === 'string' ? new RegExp(escape(find), 'g') : find
245
+ }
246
+
247
+ /**
248
+ * Turn a replace into a function.
249
+ *
250
+ * @param {Replace} replace
251
+ * Replace.
252
+ * @returns {ReplaceFunction}
253
+ * Function.
254
+ */
255
+ function toFunction(replace) {
256
+ return typeof replace === 'function'
257
+ ? replace
258
+ : function () {
259
+ return replace
260
+ }
261
+ }
node_modules/mdast-util-find-and-replace/license ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (The MIT License)
2
+
3
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/mdast-util-find-and-replace/package.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
3
+ "bugs": "https://github.com/syntax-tree/mdast-util-find-and-replace/issues",
4
+ "contributors": [
5
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
6
+ ],
7
+ "dependencies": {
8
+ "@types/mdast": "^4.0.0",
9
+ "escape-string-regexp": "^5.0.0",
10
+ "unist-util-is": "^6.0.0",
11
+ "unist-util-visit-parents": "^6.0.0"
12
+ },
13
+ "description": "mdast utility to find and replace text in a tree",
14
+ "devDependencies": {
15
+ "@types/node": "^22.0.0",
16
+ "c8": "^10.0.0",
17
+ "prettier": "^3.0.0",
18
+ "remark-cli": "^12.0.0",
19
+ "remark-preset-wooorm": "^10.0.0",
20
+ "type-coverage": "^2.0.0",
21
+ "typescript": "^5.0.0",
22
+ "unist-builder": "^4.0.0",
23
+ "xo": "^0.60.0"
24
+ },
25
+ "exports": "./index.js",
26
+ "files": [
27
+ "index.d.ts.map",
28
+ "index.d.ts",
29
+ "index.js",
30
+ "lib/"
31
+ ],
32
+ "funding": {
33
+ "type": "opencollective",
34
+ "url": "https://opencollective.com/unified"
35
+ },
36
+ "keywords": [
37
+ "find",
38
+ "markdown",
39
+ "mdast-util",
40
+ "mdast",
41
+ "unist",
42
+ "utility",
43
+ "util",
44
+ "replace"
45
+ ],
46
+ "license": "MIT",
47
+ "name": "mdast-util-find-and-replace",
48
+ "prettier": {
49
+ "bracketSpacing": false,
50
+ "semi": false,
51
+ "singleQuote": true,
52
+ "tabWidth": 2,
53
+ "trailingComma": "none",
54
+ "useTabs": false
55
+ },
56
+ "remarkConfig": {
57
+ "plugins": [
58
+ "remark-preset-wooorm"
59
+ ]
60
+ },
61
+ "repository": "syntax-tree/mdast-util-find-and-replace",
62
+ "scripts": {
63
+ "build": "tsc --build --clean && tsc --build && type-coverage",
64
+ "format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
65
+ "test-api": "node --conditions development test.js",
66
+ "test-coverage": "c8 --100 --reporter lcov -- npm run test-api",
67
+ "test": "npm run build && npm run format && npm run test-coverage"
68
+ },
69
+ "sideEffects": false,
70
+ "typeCoverage": {
71
+ "atLeast": 100,
72
+ "ignoreFiles": [
73
+ "lib/index.d.ts"
74
+ ],
75
+ "strict": true
76
+ },
77
+ "type": "module",
78
+ "version": "3.0.2",
79
+ "xo": {
80
+ "prettier": true,
81
+ "rules": {
82
+ "unicorn/prefer-at": "off"
83
+ }
84
+ }
85
+ }
node_modules/mdast-util-find-and-replace/readme.md ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # mdast-util-find-and-replace
2
+
3
+ [![Build][build-badge]][build]
4
+ [![Coverage][coverage-badge]][coverage]
5
+ [![Downloads][downloads-badge]][downloads]
6
+ [![Size][size-badge]][size]
7
+ [![Sponsors][sponsors-badge]][collective]
8
+ [![Backers][backers-badge]][collective]
9
+ [![Chat][chat-badge]][chat]
10
+
11
+ [mdast][] utility to find and replace things.
12
+
13
+ ## Contents
14
+
15
+ * [What is this?](#what-is-this)
16
+ * [When should I use this?](#when-should-i-use-this)
17
+ * [Install](#install)
18
+ * [Use](#use)
19
+ * [API](#api)
20
+ * [`findAndReplace(tree, list[, options])`](#findandreplacetree-list-options)
21
+ * [`Find`](#find)
22
+ * [`FindAndReplaceList`](#findandreplacelist)
23
+ * [`FindAndReplaceTuple`](#findandreplacetuple)
24
+ * [`Options`](#options)
25
+ * [`RegExpMatchObject`](#regexpmatchobject)
26
+ * [`Replace`](#replace)
27
+ * [`ReplaceFunction`](#replacefunction)
28
+ * [Types](#types)
29
+ * [Compatibility](#compatibility)
30
+ * [Security](#security)
31
+ * [Related](#related)
32
+ * [Contribute](#contribute)
33
+ * [License](#license)
34
+
35
+ ## What is this?
36
+
37
+ This package is a utility that lets you find patterns (`string`, `RegExp`) in
38
+ text and replace them with nodes.
39
+
40
+ ## When should I use this?
41
+
42
+ This utility is typically useful when you have regexes and want to modify mdast.
43
+ One example is when you have some form of “mentions” (such as
44
+ `/@([a-z][_a-z0-9])\b/gi`) and want to create links to persons from them.
45
+
46
+ A similar package, [`hast-util-find-and-replace`][hast-util-find-and-replace]
47
+ does the same but on [hast][].
48
+
49
+ ## Install
50
+
51
+ This package is [ESM only][esm].
52
+ In Node.js (version 16+), install with [npm][]:
53
+
54
+ ```sh
55
+ npm install mdast-util-find-and-replace
56
+ ```
57
+
58
+ In Deno with [`esm.sh`][esmsh]:
59
+
60
+ ```js
61
+ import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3'
62
+ ```
63
+
64
+ In browsers with [`esm.sh`][esmsh]:
65
+
66
+ ```html
67
+ <script type="module">
68
+ import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3?bundle'
69
+ </script>
70
+ ```
71
+
72
+ ## Use
73
+
74
+ ```js
75
+ import {findAndReplace} from 'mdast-util-find-and-replace'
76
+ import {u} from 'unist-builder'
77
+ import {inspect} from 'unist-util-inspect'
78
+
79
+ const tree = u('paragraph', [
80
+ u('text', 'Some '),
81
+ u('emphasis', [u('text', 'emphasis')]),
82
+ u('text', ' and '),
83
+ u('strong', [u('text', 'importance')]),
84
+ u('text', '.')
85
+ ])
86
+
87
+ findAndReplace(tree, [
88
+ [/and/gi, 'or'],
89
+ [/emphasis/gi, 'em'],
90
+ [/importance/gi, 'strong'],
91
+ [
92
+ /Some/g,
93
+ function ($0) {
94
+ return u('link', {url: '//example.com#' + $0}, [u('text', $0)])
95
+ }
96
+ ]
97
+ ])
98
+
99
+ console.log(inspect(tree))
100
+ ```
101
+
102
+ Yields:
103
+
104
+ ```txt
105
+ paragraph[8]
106
+ ├─0 link[1]
107
+ │ │ url: "//example.com#Some"
108
+ │ └─0 text "Some"
109
+ ├─1 text " "
110
+ ├─2 emphasis[1]
111
+ │ └─0 text "em"
112
+ ├─3 text " "
113
+ ├─4 text "or"
114
+ ├─5 text " "
115
+ ├─6 strong[1]
116
+ │ └─0 text "strong"
117
+ └─7 text "."
118
+ ```
119
+
120
+ ## API
121
+
122
+ This package exports the identifier [`findAndReplace`][api-find-and-replace].
123
+ There is no default export.
124
+
125
+ ### `findAndReplace(tree, list[, options])`
126
+
127
+ Find patterns in a tree and replace them.
128
+
129
+ The algorithm searches the tree in *[preorder][]* for complete values in
130
+ [`Text`][text] nodes.
131
+ Partial matches are not supported.
132
+
133
+ ###### Parameters
134
+
135
+ * `tree` ([`Node`][node])
136
+ — tree to change
137
+ * `list` ([`FindAndReplaceList`][api-find-and-replace-list] or
138
+ [`FindAndReplaceTuple`][api-find-and-replace-tuple])
139
+ — one or more find-and-replace pairs
140
+ * `options` ([`Options`][api-options])
141
+ — configuration
142
+
143
+ ###### Returns
144
+
145
+ Nothing (`undefined`).
146
+
147
+ ### `Find`
148
+
149
+ Pattern to find (TypeScript type).
150
+
151
+ Strings are escaped and then turned into global expressions.
152
+
153
+ ###### Type
154
+
155
+ ```ts
156
+ type Find = RegExp | string
157
+ ```
158
+
159
+ ### `FindAndReplaceList`
160
+
161
+ Several find and replaces, in array form (TypeScript type).
162
+
163
+ ###### Type
164
+
165
+ ```ts
166
+ type FindAndReplaceList = Array<FindAndReplaceTuple>
167
+ ```
168
+
169
+ See [`FindAndReplaceTuple`][api-find-and-replace-tuple].
170
+
171
+ ### `FindAndReplaceTuple`
172
+
173
+ Find and replace in tuple form (TypeScript type).
174
+
175
+ ###### Type
176
+
177
+ ```ts
178
+ type FindAndReplaceTuple = [Find, Replace?]
179
+ ```
180
+
181
+ See [`Find`][api-find] and [`Replace`][api-replace].
182
+
183
+ ### `Options`
184
+
185
+ Configuration (TypeScript type).
186
+
187
+ ###### Fields
188
+
189
+ * `ignore` ([`Test`][test], optional)
190
+ — test for which elements to ignore
191
+
192
+ ### `RegExpMatchObject`
193
+
194
+ Info on the match (TypeScript type).
195
+
196
+ ###### Fields
197
+
198
+ * `index` (`number`)
199
+ — the index of the search at which the result was found
200
+ * `input` (`string`)
201
+ — a copy of the search string in the text node
202
+ * `stack` ([`Array<Node>`][node])
203
+ — all ancestors of the text node, where the last node is the text itself
204
+
205
+ ### `Replace`
206
+
207
+ Thing to replace with (TypeScript type).
208
+
209
+ ###### Type
210
+
211
+ ```ts
212
+ type Replace = ReplaceFunction | string
213
+ ```
214
+
215
+ See [`ReplaceFunction`][api-replace-function].
216
+
217
+ ### `ReplaceFunction`
218
+
219
+ Callback called when a search matches (TypeScript type).
220
+
221
+ ###### Parameters
222
+
223
+ The parameters are the result of corresponding search expression:
224
+
225
+ * `value` (`string`)
226
+ — whole match
227
+ * `...capture` (`Array<string>`)
228
+ — matches from regex capture groups
229
+ * `match` ([`RegExpMatchObject`][api-regexp-match-object])
230
+ — info on the match
231
+
232
+ ###### Returns
233
+
234
+ Thing to replace with:
235
+
236
+ * when `null`, `undefined`, `''`, remove the match
237
+ * …or when `false`, do not replace at all
238
+ * …or when `string`, replace with a text node of that value
239
+ * …or when `Node` or `Array<Node>`, replace with those nodes
240
+
241
+ ## Types
242
+
243
+ This package is fully typed with [TypeScript][].
244
+ It exports the additional types [`Find`][api-find],
245
+ [`FindAndReplaceList`][api-find-and-replace-list],
246
+ [`FindAndReplaceTuple`][api-find-and-replace-tuple],
247
+ [`Options`][api-options],
248
+ [`RegExpMatchObject`][api-regexp-match-object],
249
+ [`Replace`][api-replace], and
250
+ [`ReplaceFunction`][api-replace-function].
251
+
252
+ ## Compatibility
253
+
254
+ Projects maintained by the unified collective are compatible with maintained
255
+ versions of Node.js.
256
+
257
+ When we cut a new major release, we drop support for unmaintained versions of
258
+ Node.
259
+ This means we try to keep the current release line,
260
+ `mdast-util-find-and-replace@^3`, compatible with Node.js 16.
261
+
262
+ ## Security
263
+
264
+ Use of `mdast-util-find-and-replace` does not involve [hast][] or user content
265
+ so there are no openings for [cross-site scripting (XSS)][xss] attacks.
266
+
267
+ ## Related
268
+
269
+ * [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace)
270
+ — find and replace in hast
271
+ * [`hast-util-select`](https://github.com/syntax-tree/hast-util-select)
272
+ — `querySelector`, `querySelectorAll`, and `matches`
273
+ * [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)
274
+ — select unist nodes with CSS-like selectors
275
+
276
+ ## Contribute
277
+
278
+ See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
279
+ ways to get started.
280
+ See [`support.md`][support] for ways to get help.
281
+
282
+ This project has a [code of conduct][coc].
283
+ By interacting with this repository, organisation, or community you agree to
284
+ abide by its terms.
285
+
286
+ ## License
287
+
288
+ [MIT][license] © [Titus Wormer][author]
289
+
290
+ <!-- Definition -->
291
+
292
+ [build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg
293
+
294
+ [build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions
295
+
296
+ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg
297
+
298
+ [coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace
299
+
300
+ [downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg
301
+
302
+ [downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace
303
+
304
+ [size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-find-and-replace
305
+
306
+ [size]: https://bundlejs.com/?q=mdast-util-find-and-replace
307
+
308
+ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
309
+
310
+ [backers-badge]: https://opencollective.com/unified/backers/badge.svg
311
+
312
+ [collective]: https://opencollective.com/unified
313
+
314
+ [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
315
+
316
+ [chat]: https://github.com/syntax-tree/unist/discussions
317
+
318
+ [npm]: https://docs.npmjs.com/cli/install
319
+
320
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
321
+
322
+ [esmsh]: https://esm.sh
323
+
324
+ [typescript]: https://www.typescriptlang.org
325
+
326
+ [license]: license
327
+
328
+ [author]: https://wooorm.com
329
+
330
+ [health]: https://github.com/syntax-tree/.github
331
+
332
+ [contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
333
+
334
+ [support]: https://github.com/syntax-tree/.github/blob/main/support.md
335
+
336
+ [coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
337
+
338
+ [hast]: https://github.com/syntax-tree/hast
339
+
340
+ [mdast]: https://github.com/syntax-tree/mdast
341
+
342
+ [node]: https://github.com/syntax-tree/mdast#nodes
343
+
344
+ [preorder]: https://github.com/syntax-tree/unist#preorder
345
+
346
+ [text]: https://github.com/syntax-tree/mdast#text
347
+
348
+ [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
349
+
350
+ [test]: https://github.com/syntax-tree/unist-util-is#api
351
+
352
+ [hast-util-find-and-replace]: https://github.com/syntax-tree/hast-util-find-and-replace
353
+
354
+ [api-find-and-replace]: #findandreplacetree-list-options
355
+
356
+ [api-options]: #options
357
+
358
+ [api-find]: #find
359
+
360
+ [api-replace]: #replace
361
+
362
+ [api-replace-function]: #replacefunction
363
+
364
+ [api-find-and-replace-list]: #findandreplacelist
365
+
366
+ [api-find-and-replace-tuple]: #findandreplacetuple
367
+
368
+ [api-regexp-match-object]: #regexpmatchobject
node_modules/mdast-util-from-markdown/dev/index.d.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type {Encoding, Token, Value} from 'micromark-util-types'
2
+ export type {
3
+ CompileContext,
4
+ CompileData,
5
+ Extension,
6
+ Handles,
7
+ Handle,
8
+ OnEnterError,
9
+ OnExitError,
10
+ Options,
11
+ Transform
12
+ } from './lib/types.js'
13
+ export {fromMarkdown} from './lib/index.js'
14
+
15
+ declare module 'micromark-util-types' {
16
+ interface TokenTypeMap {
17
+ listItem: 'listItem'
18
+ }
19
+
20
+ interface Token {
21
+ _spread?: boolean
22
+ }
23
+ }
node_modules/mdast-util-from-markdown/dev/index.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // Note: types exported from `index.d.ts`.
2
+ export {fromMarkdown} from './lib/index.js'
node_modules/mdast-util-from-markdown/dev/lib/index.d.ts ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Turn markdown into a syntax tree.
3
+ *
4
+ * @overload
5
+ * @param {Value} value
6
+ * @param {Encoding | null | undefined} [encoding]
7
+ * @param {Options | null | undefined} [options]
8
+ * @returns {Root}
9
+ *
10
+ * @overload
11
+ * @param {Value} value
12
+ * @param {Options | null | undefined} [options]
13
+ * @returns {Root}
14
+ *
15
+ * @param {Value} value
16
+ * Markdown to parse.
17
+ * @param {Encoding | Options | null | undefined} [encoding]
18
+ * Character encoding for when `value` is `Buffer`.
19
+ * @param {Options | null | undefined} [options]
20
+ * Configuration.
21
+ * @returns {Root}
22
+ * mdast tree.
23
+ */
24
+ export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root;
25
+ /**
26
+ * Turn markdown into a syntax tree.
27
+ *
28
+ * @overload
29
+ * @param {Value} value
30
+ * @param {Encoding | null | undefined} [encoding]
31
+ * @param {Options | null | undefined} [options]
32
+ * @returns {Root}
33
+ *
34
+ * @overload
35
+ * @param {Value} value
36
+ * @param {Options | null | undefined} [options]
37
+ * @returns {Root}
38
+ *
39
+ * @param {Value} value
40
+ * Markdown to parse.
41
+ * @param {Encoding | Options | null | undefined} [encoding]
42
+ * Character encoding for when `value` is `Buffer`.
43
+ * @param {Options | null | undefined} [options]
44
+ * Configuration.
45
+ * @returns {Root}
46
+ * mdast tree.
47
+ */
48
+ export function fromMarkdown(value: Value, options?: Options | null | undefined): Root;
49
+ import type { Value } from 'micromark-util-types';
50
+ import type { Encoding } from 'micromark-util-types';
51
+ import type { Options } from './types.js';
52
+ import type { Root } from 'mdast';
53
+ //# sourceMappingURL=index.d.ts.map
node_modules/mdast-util-from-markdown/dev/lib/index.d.ts.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwDG,oCACQ,KAAK,aACL,QAAQ,GAAG,IAAI,GAAG,SAAS,YAC3B,OAAO,GAAG,IAAI,GAAG,SAAS,GACxB,IAAI,CAEd;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCACQ,KAAK,YACL,OAAO,GAAG,IAAI,GAAG,SAAS,GACxB,IAAI,CAEd;2BAvCO,sBAAsB;8BAAtB,sBAAsB;6BAUtB,YAAY;0BAhBZ,OAAO"}
node_modules/mdast-util-from-markdown/dev/lib/index.js ADDED
@@ -0,0 +1,1348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @import {
3
+ * Break,
4
+ * Blockquote,
5
+ * Code,
6
+ * Definition,
7
+ * Emphasis,
8
+ * Heading,
9
+ * Html,
10
+ * Image,
11
+ * InlineCode,
12
+ * Link,
13
+ * ListItem,
14
+ * List,
15
+ * Nodes,
16
+ * Paragraph,
17
+ * PhrasingContent,
18
+ * ReferenceType,
19
+ * Root,
20
+ * Strong,
21
+ * Text,
22
+ * ThematicBreak
23
+ * } from 'mdast'
24
+ * @import {
25
+ * Encoding,
26
+ * Event,
27
+ * Token,
28
+ * Value
29
+ * } from 'micromark-util-types'
30
+ * @import {Point} from 'unist'
31
+ * @import {
32
+ * CompileContext,
33
+ * CompileData,
34
+ * Config,
35
+ * Extension,
36
+ * Handle,
37
+ * OnEnterError,
38
+ * Options
39
+ * } from './types.js'
40
+ */
41
+
42
+ import {ok as assert} from 'devlop'
43
+ import {toString} from 'mdast-util-to-string'
44
+ import {parse, postprocess, preprocess} from 'micromark'
45
+ import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
46
+ import {decodeString} from 'micromark-util-decode-string'
47
+ import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
48
+ import {codes, constants, types} from 'micromark-util-symbol'
49
+ import {decodeNamedCharacterReference} from 'decode-named-character-reference'
50
+ import {stringifyPosition} from 'unist-util-stringify-position'
51
+
52
+ const own = {}.hasOwnProperty
53
+
54
+ /**
55
+ * Turn markdown into a syntax tree.
56
+ *
57
+ * @overload
58
+ * @param {Value} value
59
+ * @param {Encoding | null | undefined} [encoding]
60
+ * @param {Options | null | undefined} [options]
61
+ * @returns {Root}
62
+ *
63
+ * @overload
64
+ * @param {Value} value
65
+ * @param {Options | null | undefined} [options]
66
+ * @returns {Root}
67
+ *
68
+ * @param {Value} value
69
+ * Markdown to parse.
70
+ * @param {Encoding | Options | null | undefined} [encoding]
71
+ * Character encoding for when `value` is `Buffer`.
72
+ * @param {Options | null | undefined} [options]
73
+ * Configuration.
74
+ * @returns {Root}
75
+ * mdast tree.
76
+ */
77
+ export function fromMarkdown(value, encoding, options) {
78
+ if (encoding && typeof encoding === 'object') {
79
+ options = encoding
80
+ encoding = undefined
81
+ }
82
+
83
+ return compiler(options)(
84
+ postprocess(
85
+ parse(options)
86
+ .document()
87
+ .write(preprocess()(value, encoding, true))
88
+ )
89
+ )
90
+ }
91
+
92
+ /**
93
+ * Note this compiler only understand complete buffering, not streaming.
94
+ *
95
+ * @param {Options | null | undefined} [options]
96
+ */
97
+ function compiler(options) {
98
+ /** @type {Config} */
99
+ const config = {
100
+ transforms: [],
101
+ canContainEols: ['emphasis', 'fragment', 'heading', 'paragraph', 'strong'],
102
+ enter: {
103
+ autolink: opener(link),
104
+ autolinkProtocol: onenterdata,
105
+ autolinkEmail: onenterdata,
106
+ atxHeading: opener(heading),
107
+ blockQuote: opener(blockQuote),
108
+ characterEscape: onenterdata,
109
+ characterReference: onenterdata,
110
+ codeFenced: opener(codeFlow),
111
+ codeFencedFenceInfo: buffer,
112
+ codeFencedFenceMeta: buffer,
113
+ codeIndented: opener(codeFlow, buffer),
114
+ codeText: opener(codeText, buffer),
115
+ codeTextData: onenterdata,
116
+ data: onenterdata,
117
+ codeFlowValue: onenterdata,
118
+ definition: opener(definition),
119
+ definitionDestinationString: buffer,
120
+ definitionLabelString: buffer,
121
+ definitionTitleString: buffer,
122
+ emphasis: opener(emphasis),
123
+ hardBreakEscape: opener(hardBreak),
124
+ hardBreakTrailing: opener(hardBreak),
125
+ htmlFlow: opener(html, buffer),
126
+ htmlFlowData: onenterdata,
127
+ htmlText: opener(html, buffer),
128
+ htmlTextData: onenterdata,
129
+ image: opener(image),
130
+ label: buffer,
131
+ link: opener(link),
132
+ listItem: opener(listItem),
133
+ listItemValue: onenterlistitemvalue,
134
+ listOrdered: opener(list, onenterlistordered),
135
+ listUnordered: opener(list),
136
+ paragraph: opener(paragraph),
137
+ reference: onenterreference,
138
+ referenceString: buffer,
139
+ resourceDestinationString: buffer,
140
+ resourceTitleString: buffer,
141
+ setextHeading: opener(heading),
142
+ strong: opener(strong),
143
+ thematicBreak: opener(thematicBreak)
144
+ },
145
+ exit: {
146
+ atxHeading: closer(),
147
+ atxHeadingSequence: onexitatxheadingsequence,
148
+ autolink: closer(),
149
+ autolinkEmail: onexitautolinkemail,
150
+ autolinkProtocol: onexitautolinkprotocol,
151
+ blockQuote: closer(),
152
+ characterEscapeValue: onexitdata,
153
+ characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
154
+ characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
155
+ characterReferenceValue: onexitcharacterreferencevalue,
156
+ characterReference: onexitcharacterreference,
157
+ codeFenced: closer(onexitcodefenced),
158
+ codeFencedFence: onexitcodefencedfence,
159
+ codeFencedFenceInfo: onexitcodefencedfenceinfo,
160
+ codeFencedFenceMeta: onexitcodefencedfencemeta,
161
+ codeFlowValue: onexitdata,
162
+ codeIndented: closer(onexitcodeindented),
163
+ codeText: closer(onexitcodetext),
164
+ codeTextData: onexitdata,
165
+ data: onexitdata,
166
+ definition: closer(),
167
+ definitionDestinationString: onexitdefinitiondestinationstring,
168
+ definitionLabelString: onexitdefinitionlabelstring,
169
+ definitionTitleString: onexitdefinitiontitlestring,
170
+ emphasis: closer(),
171
+ hardBreakEscape: closer(onexithardbreak),
172
+ hardBreakTrailing: closer(onexithardbreak),
173
+ htmlFlow: closer(onexithtmlflow),
174
+ htmlFlowData: onexitdata,
175
+ htmlText: closer(onexithtmltext),
176
+ htmlTextData: onexitdata,
177
+ image: closer(onexitimage),
178
+ label: onexitlabel,
179
+ labelText: onexitlabeltext,
180
+ lineEnding: onexitlineending,
181
+ link: closer(onexitlink),
182
+ listItem: closer(),
183
+ listOrdered: closer(),
184
+ listUnordered: closer(),
185
+ paragraph: closer(),
186
+ referenceString: onexitreferencestring,
187
+ resourceDestinationString: onexitresourcedestinationstring,
188
+ resourceTitleString: onexitresourcetitlestring,
189
+ resource: onexitresource,
190
+ setextHeading: closer(onexitsetextheading),
191
+ setextHeadingLineSequence: onexitsetextheadinglinesequence,
192
+ setextHeadingText: onexitsetextheadingtext,
193
+ strong: closer(),
194
+ thematicBreak: closer()
195
+ }
196
+ }
197
+
198
+ configure(config, (options || {}).mdastExtensions || [])
199
+
200
+ /** @type {CompileData} */
201
+ const data = {}
202
+
203
+ return compile
204
+
205
+ /**
206
+ * Turn micromark events into an mdast tree.
207
+ *
208
+ * @param {Array<Event>} events
209
+ * Events.
210
+ * @returns {Root}
211
+ * mdast tree.
212
+ */
213
+ function compile(events) {
214
+ /** @type {Root} */
215
+ let tree = {type: 'root', children: []}
216
+ /** @type {Omit<CompileContext, 'sliceSerialize'>} */
217
+ const context = {
218
+ stack: [tree],
219
+ tokenStack: [],
220
+ config,
221
+ enter,
222
+ exit,
223
+ buffer,
224
+ resume,
225
+ data
226
+ }
227
+ /** @type {Array<number>} */
228
+ const listStack = []
229
+ let index = -1
230
+
231
+ while (++index < events.length) {
232
+ // We preprocess lists to add `listItem` tokens, and to infer whether
233
+ // items the list itself are spread out.
234
+ if (
235
+ events[index][1].type === types.listOrdered ||
236
+ events[index][1].type === types.listUnordered
237
+ ) {
238
+ if (events[index][0] === 'enter') {
239
+ listStack.push(index)
240
+ } else {
241
+ const tail = listStack.pop()
242
+ assert(typeof tail === 'number', 'expected list to be open')
243
+ index = prepareList(events, tail, index)
244
+ }
245
+ }
246
+ }
247
+
248
+ index = -1
249
+
250
+ while (++index < events.length) {
251
+ const handler = config[events[index][0]]
252
+
253
+ if (own.call(handler, events[index][1].type)) {
254
+ handler[events[index][1].type].call(
255
+ Object.assign(
256
+ {sliceSerialize: events[index][2].sliceSerialize},
257
+ context
258
+ ),
259
+ events[index][1]
260
+ )
261
+ }
262
+ }
263
+
264
+ // Handle tokens still being open.
265
+ if (context.tokenStack.length > 0) {
266
+ const tail = context.tokenStack[context.tokenStack.length - 1]
267
+ const handler = tail[1] || defaultOnError
268
+ handler.call(context, undefined, tail[0])
269
+ }
270
+
271
+ // Figure out `root` position.
272
+ tree.position = {
273
+ start: point(
274
+ events.length > 0 ? events[0][1].start : {line: 1, column: 1, offset: 0}
275
+ ),
276
+ end: point(
277
+ events.length > 0
278
+ ? events[events.length - 2][1].end
279
+ : {line: 1, column: 1, offset: 0}
280
+ )
281
+ }
282
+
283
+ // Call transforms.
284
+ index = -1
285
+ while (++index < config.transforms.length) {
286
+ tree = config.transforms[index](tree) || tree
287
+ }
288
+
289
+ return tree
290
+ }
291
+
292
+ /**
293
+ * @param {Array<Event>} events
294
+ * @param {number} start
295
+ * @param {number} length
296
+ * @returns {number}
297
+ */
298
+ function prepareList(events, start, length) {
299
+ let index = start - 1
300
+ let containerBalance = -1
301
+ let listSpread = false
302
+ /** @type {Token | undefined} */
303
+ let listItem
304
+ /** @type {number | undefined} */
305
+ let lineIndex
306
+ /** @type {number | undefined} */
307
+ let firstBlankLineIndex
308
+ /** @type {boolean | undefined} */
309
+ let atMarker
310
+
311
+ while (++index <= length) {
312
+ const event = events[index]
313
+
314
+ switch (event[1].type) {
315
+ case types.listUnordered:
316
+ case types.listOrdered:
317
+ case types.blockQuote: {
318
+ if (event[0] === 'enter') {
319
+ containerBalance++
320
+ } else {
321
+ containerBalance--
322
+ }
323
+
324
+ atMarker = undefined
325
+
326
+ break
327
+ }
328
+
329
+ case types.lineEndingBlank: {
330
+ if (event[0] === 'enter') {
331
+ if (
332
+ listItem &&
333
+ !atMarker &&
334
+ !containerBalance &&
335
+ !firstBlankLineIndex
336
+ ) {
337
+ firstBlankLineIndex = index
338
+ }
339
+
340
+ atMarker = undefined
341
+ }
342
+
343
+ break
344
+ }
345
+
346
+ case types.linePrefix:
347
+ case types.listItemValue:
348
+ case types.listItemMarker:
349
+ case types.listItemPrefix:
350
+ case types.listItemPrefixWhitespace: {
351
+ // Empty.
352
+
353
+ break
354
+ }
355
+
356
+ default: {
357
+ atMarker = undefined
358
+ }
359
+ }
360
+
361
+ if (
362
+ (!containerBalance &&
363
+ event[0] === 'enter' &&
364
+ event[1].type === types.listItemPrefix) ||
365
+ (containerBalance === -1 &&
366
+ event[0] === 'exit' &&
367
+ (event[1].type === types.listUnordered ||
368
+ event[1].type === types.listOrdered))
369
+ ) {
370
+ if (listItem) {
371
+ let tailIndex = index
372
+ lineIndex = undefined
373
+
374
+ while (tailIndex--) {
375
+ const tailEvent = events[tailIndex]
376
+
377
+ if (
378
+ tailEvent[1].type === types.lineEnding ||
379
+ tailEvent[1].type === types.lineEndingBlank
380
+ ) {
381
+ if (tailEvent[0] === 'exit') continue
382
+
383
+ if (lineIndex) {
384
+ events[lineIndex][1].type = types.lineEndingBlank
385
+ listSpread = true
386
+ }
387
+
388
+ tailEvent[1].type = types.lineEnding
389
+ lineIndex = tailIndex
390
+ } else if (
391
+ tailEvent[1].type === types.linePrefix ||
392
+ tailEvent[1].type === types.blockQuotePrefix ||
393
+ tailEvent[1].type === types.blockQuotePrefixWhitespace ||
394
+ tailEvent[1].type === types.blockQuoteMarker ||
395
+ tailEvent[1].type === types.listItemIndent
396
+ ) {
397
+ // Empty
398
+ } else {
399
+ break
400
+ }
401
+ }
402
+
403
+ if (
404
+ firstBlankLineIndex &&
405
+ (!lineIndex || firstBlankLineIndex < lineIndex)
406
+ ) {
407
+ listItem._spread = true
408
+ }
409
+
410
+ // Fix position.
411
+ listItem.end = Object.assign(
412
+ {},
413
+ lineIndex ? events[lineIndex][1].start : event[1].end
414
+ )
415
+
416
+ events.splice(lineIndex || index, 0, ['exit', listItem, event[2]])
417
+ index++
418
+ length++
419
+ }
420
+
421
+ // Create a new list item.
422
+ if (event[1].type === types.listItemPrefix) {
423
+ /** @type {Token} */
424
+ const item = {
425
+ type: 'listItem',
426
+ _spread: false,
427
+ start: Object.assign({}, event[1].start),
428
+ // @ts-expect-error: we’ll add `end` in a second.
429
+ end: undefined
430
+ }
431
+ listItem = item
432
+ events.splice(index, 0, ['enter', item, event[2]])
433
+ index++
434
+ length++
435
+ firstBlankLineIndex = undefined
436
+ atMarker = true
437
+ }
438
+ }
439
+ }
440
+
441
+ events[start][1]._spread = listSpread
442
+ return length
443
+ }
444
+
445
+ /**
446
+ * Create an opener handle.
447
+ *
448
+ * @param {(token: Token) => Nodes} create
449
+ * Create a node.
450
+ * @param {Handle | undefined} [and]
451
+ * Optional function to also run.
452
+ * @returns {Handle}
453
+ * Handle.
454
+ */
455
+ function opener(create, and) {
456
+ return open
457
+
458
+ /**
459
+ * @this {CompileContext}
460
+ * @param {Token} token
461
+ * @returns {undefined}
462
+ */
463
+ function open(token) {
464
+ enter.call(this, create(token), token)
465
+ if (and) and.call(this, token)
466
+ }
467
+ }
468
+
469
+ /**
470
+ * @type {CompileContext['buffer']}
471
+ */
472
+ function buffer() {
473
+ this.stack.push({type: 'fragment', children: []})
474
+ }
475
+
476
+ /**
477
+ * @type {CompileContext['enter']}
478
+ */
479
+ function enter(node, token, errorHandler) {
480
+ const parent = this.stack[this.stack.length - 1]
481
+ assert(parent, 'expected `parent`')
482
+ assert('children' in parent, 'expected `parent`')
483
+ /** @type {Array<Nodes>} */
484
+ const siblings = parent.children
485
+ siblings.push(node)
486
+ this.stack.push(node)
487
+ this.tokenStack.push([token, errorHandler || undefined])
488
+ node.position = {
489
+ start: point(token.start),
490
+ // @ts-expect-error: `end` will be patched later.
491
+ end: undefined
492
+ }
493
+ }
494
+
495
+ /**
496
+ * Create a closer handle.
497
+ *
498
+ * @param {Handle | undefined} [and]
499
+ * Optional function to also run.
500
+ * @returns {Handle}
501
+ * Handle.
502
+ */
503
+ function closer(and) {
504
+ return close
505
+
506
+ /**
507
+ * @this {CompileContext}
508
+ * @param {Token} token
509
+ * @returns {undefined}
510
+ */
511
+ function close(token) {
512
+ if (and) and.call(this, token)
513
+ exit.call(this, token)
514
+ }
515
+ }
516
+
517
+ /**
518
+ * @type {CompileContext['exit']}
519
+ */
520
+ function exit(token, onExitError) {
521
+ const node = this.stack.pop()
522
+ assert(node, 'expected `node`')
523
+ const open = this.tokenStack.pop()
524
+
525
+ if (!open) {
526
+ throw new Error(
527
+ 'Cannot close `' +
528
+ token.type +
529
+ '` (' +
530
+ stringifyPosition({start: token.start, end: token.end}) +
531
+ '): it’s not open'
532
+ )
533
+ } else if (open[0].type !== token.type) {
534
+ if (onExitError) {
535
+ onExitError.call(this, token, open[0])
536
+ } else {
537
+ const handler = open[1] || defaultOnError
538
+ handler.call(this, token, open[0])
539
+ }
540
+ }
541
+
542
+ assert(node.type !== 'fragment', 'unexpected fragment `exit`ed')
543
+ assert(node.position, 'expected `position` to be defined')
544
+ node.position.end = point(token.end)
545
+ }
546
+
547
+ /**
548
+ * @type {CompileContext['resume']}
549
+ */
550
+ function resume() {
551
+ return toString(this.stack.pop())
552
+ }
553
+
554
+ //
555
+ // Handlers.
556
+ //
557
+
558
+ /**
559
+ * @this {CompileContext}
560
+ * @type {Handle}
561
+ */
562
+ function onenterlistordered() {
563
+ this.data.expectingFirstListItemValue = true
564
+ }
565
+
566
+ /**
567
+ * @this {CompileContext}
568
+ * @type {Handle}
569
+ */
570
+ function onenterlistitemvalue(token) {
571
+ if (this.data.expectingFirstListItemValue) {
572
+ const ancestor = this.stack[this.stack.length - 2]
573
+ assert(ancestor, 'expected nodes on stack')
574
+ assert(ancestor.type === 'list', 'expected list on stack')
575
+ ancestor.start = Number.parseInt(
576
+ this.sliceSerialize(token),
577
+ constants.numericBaseDecimal
578
+ )
579
+ this.data.expectingFirstListItemValue = undefined
580
+ }
581
+ }
582
+
583
+ /**
584
+ * @this {CompileContext}
585
+ * @type {Handle}
586
+ */
587
+ function onexitcodefencedfenceinfo() {
588
+ const data = this.resume()
589
+ const node = this.stack[this.stack.length - 1]
590
+ assert(node, 'expected node on stack')
591
+ assert(node.type === 'code', 'expected code on stack')
592
+ node.lang = data
593
+ }
594
+
595
+ /**
596
+ * @this {CompileContext}
597
+ * @type {Handle}
598
+ */
599
+ function onexitcodefencedfencemeta() {
600
+ const data = this.resume()
601
+ const node = this.stack[this.stack.length - 1]
602
+ assert(node, 'expected node on stack')
603
+ assert(node.type === 'code', 'expected code on stack')
604
+ node.meta = data
605
+ }
606
+
607
+ /**
608
+ * @this {CompileContext}
609
+ * @type {Handle}
610
+ */
611
+ function onexitcodefencedfence() {
612
+ // Exit if this is the closing fence.
613
+ if (this.data.flowCodeInside) return
614
+ this.buffer()
615
+ this.data.flowCodeInside = true
616
+ }
617
+
618
+ /**
619
+ * @this {CompileContext}
620
+ * @type {Handle}
621
+ */
622
+ function onexitcodefenced() {
623
+ const data = this.resume()
624
+ const node = this.stack[this.stack.length - 1]
625
+ assert(node, 'expected node on stack')
626
+ assert(node.type === 'code', 'expected code on stack')
627
+
628
+ node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
629
+ this.data.flowCodeInside = undefined
630
+ }
631
+
632
+ /**
633
+ * @this {CompileContext}
634
+ * @type {Handle}
635
+ */
636
+ function onexitcodeindented() {
637
+ const data = this.resume()
638
+ const node = this.stack[this.stack.length - 1]
639
+ assert(node, 'expected node on stack')
640
+ assert(node.type === 'code', 'expected code on stack')
641
+
642
+ node.value = data.replace(/(\r?\n|\r)$/g, '')
643
+ }
644
+
645
+ /**
646
+ * @this {CompileContext}
647
+ * @type {Handle}
648
+ */
649
+ function onexitdefinitionlabelstring(token) {
650
+ const label = this.resume()
651
+ const node = this.stack[this.stack.length - 1]
652
+ assert(node, 'expected node on stack')
653
+ assert(node.type === 'definition', 'expected definition on stack')
654
+
655
+ node.label = label
656
+ node.identifier = normalizeIdentifier(
657
+ this.sliceSerialize(token)
658
+ ).toLowerCase()
659
+ }
660
+
661
+ /**
662
+ * @this {CompileContext}
663
+ * @type {Handle}
664
+ */
665
+ function onexitdefinitiontitlestring() {
666
+ const data = this.resume()
667
+ const node = this.stack[this.stack.length - 1]
668
+ assert(node, 'expected node on stack')
669
+ assert(node.type === 'definition', 'expected definition on stack')
670
+
671
+ node.title = data
672
+ }
673
+
674
+ /**
675
+ * @this {CompileContext}
676
+ * @type {Handle}
677
+ */
678
+ function onexitdefinitiondestinationstring() {
679
+ const data = this.resume()
680
+ const node = this.stack[this.stack.length - 1]
681
+ assert(node, 'expected node on stack')
682
+ assert(node.type === 'definition', 'expected definition on stack')
683
+
684
+ node.url = data
685
+ }
686
+
687
+ /**
688
+ * @this {CompileContext}
689
+ * @type {Handle}
690
+ */
691
+ function onexitatxheadingsequence(token) {
692
+ const node = this.stack[this.stack.length - 1]
693
+ assert(node, 'expected node on stack')
694
+ assert(node.type === 'heading', 'expected heading on stack')
695
+
696
+ if (!node.depth) {
697
+ const depth = this.sliceSerialize(token).length
698
+
699
+ assert(
700
+ depth === 1 ||
701
+ depth === 2 ||
702
+ depth === 3 ||
703
+ depth === 4 ||
704
+ depth === 5 ||
705
+ depth === 6,
706
+ 'expected `depth` between `1` and `6`'
707
+ )
708
+
709
+ node.depth = depth
710
+ }
711
+ }
712
+
713
+ /**
714
+ * @this {CompileContext}
715
+ * @type {Handle}
716
+ */
717
+ function onexitsetextheadingtext() {
718
+ this.data.setextHeadingSlurpLineEnding = true
719
+ }
720
+
721
+ /**
722
+ * @this {CompileContext}
723
+ * @type {Handle}
724
+ */
725
+ function onexitsetextheadinglinesequence(token) {
726
+ const node = this.stack[this.stack.length - 1]
727
+ assert(node, 'expected node on stack')
728
+ assert(node.type === 'heading', 'expected heading on stack')
729
+
730
+ node.depth =
731
+ this.sliceSerialize(token).codePointAt(0) === codes.equalsTo ? 1 : 2
732
+ }
733
+
734
+ /**
735
+ * @this {CompileContext}
736
+ * @type {Handle}
737
+ */
738
+ function onexitsetextheading() {
739
+ this.data.setextHeadingSlurpLineEnding = undefined
740
+ }
741
+
742
+ /**
743
+ * @this {CompileContext}
744
+ * @type {Handle}
745
+ */
746
+
747
+ function onenterdata(token) {
748
+ const node = this.stack[this.stack.length - 1]
749
+ assert(node, 'expected node on stack')
750
+ assert('children' in node, 'expected parent on stack')
751
+ /** @type {Array<Nodes>} */
752
+ const siblings = node.children
753
+
754
+ let tail = siblings[siblings.length - 1]
755
+
756
+ if (!tail || tail.type !== 'text') {
757
+ // Add a new text node.
758
+ tail = text()
759
+ tail.position = {
760
+ start: point(token.start),
761
+ // @ts-expect-error: we’ll add `end` later.
762
+ end: undefined
763
+ }
764
+ siblings.push(tail)
765
+ }
766
+
767
+ this.stack.push(tail)
768
+ }
769
+
770
+ /**
771
+ * @this {CompileContext}
772
+ * @type {Handle}
773
+ */
774
+
775
+ function onexitdata(token) {
776
+ const tail = this.stack.pop()
777
+ assert(tail, 'expected a `node` to be on the stack')
778
+ assert('value' in tail, 'expected a `literal` to be on the stack')
779
+ assert(tail.position, 'expected `node` to have an open position')
780
+ tail.value += this.sliceSerialize(token)
781
+ tail.position.end = point(token.end)
782
+ }
783
+
784
+ /**
785
+ * @this {CompileContext}
786
+ * @type {Handle}
787
+ */
788
+
789
+ function onexitlineending(token) {
790
+ const context = this.stack[this.stack.length - 1]
791
+ assert(context, 'expected `node`')
792
+
793
+ // If we’re at a hard break, include the line ending in there.
794
+ if (this.data.atHardBreak) {
795
+ assert('children' in context, 'expected `parent`')
796
+ const tail = context.children[context.children.length - 1]
797
+ assert(tail.position, 'expected tail to have a starting position')
798
+ tail.position.end = point(token.end)
799
+ this.data.atHardBreak = undefined
800
+ return
801
+ }
802
+
803
+ if (
804
+ !this.data.setextHeadingSlurpLineEnding &&
805
+ config.canContainEols.includes(context.type)
806
+ ) {
807
+ onenterdata.call(this, token)
808
+ onexitdata.call(this, token)
809
+ }
810
+ }
811
+
812
+ /**
813
+ * @this {CompileContext}
814
+ * @type {Handle}
815
+ */
816
+
817
+ function onexithardbreak() {
818
+ this.data.atHardBreak = true
819
+ }
820
+
821
+ /**
822
+ * @this {CompileContext}
823
+ * @type {Handle}
824
+ */
825
+
826
+ function onexithtmlflow() {
827
+ const data = this.resume()
828
+ const node = this.stack[this.stack.length - 1]
829
+ assert(node, 'expected node on stack')
830
+ assert(node.type === 'html', 'expected html on stack')
831
+
832
+ node.value = data
833
+ }
834
+
835
+ /**
836
+ * @this {CompileContext}
837
+ * @type {Handle}
838
+ */
839
+
840
+ function onexithtmltext() {
841
+ const data = this.resume()
842
+ const node = this.stack[this.stack.length - 1]
843
+ assert(node, 'expected node on stack')
844
+ assert(node.type === 'html', 'expected html on stack')
845
+
846
+ node.value = data
847
+ }
848
+
849
+ /**
850
+ * @this {CompileContext}
851
+ * @type {Handle}
852
+ */
853
+
854
+ function onexitcodetext() {
855
+ const data = this.resume()
856
+ const node = this.stack[this.stack.length - 1]
857
+ assert(node, 'expected node on stack')
858
+ assert(node.type === 'inlineCode', 'expected inline code on stack')
859
+
860
+ node.value = data
861
+ }
862
+
863
+ /**
864
+ * @this {CompileContext}
865
+ * @type {Handle}
866
+ */
867
+
868
+ function onexitlink() {
869
+ const node = this.stack[this.stack.length - 1]
870
+ assert(node, 'expected node on stack')
871
+ assert(node.type === 'link', 'expected link on stack')
872
+
873
+ // Note: there are also `identifier` and `label` fields on this link node!
874
+ // These are used / cleaned here.
875
+
876
+ // To do: clean.
877
+ if (this.data.inReference) {
878
+ /** @type {ReferenceType} */
879
+ const referenceType = this.data.referenceType || 'shortcut'
880
+
881
+ node.type += 'Reference'
882
+ // @ts-expect-error: mutate.
883
+ node.referenceType = referenceType
884
+ // @ts-expect-error: mutate.
885
+ delete node.url
886
+ delete node.title
887
+ } else {
888
+ // @ts-expect-error: mutate.
889
+ delete node.identifier
890
+ // @ts-expect-error: mutate.
891
+ delete node.label
892
+ }
893
+
894
+ this.data.referenceType = undefined
895
+ }
896
+
897
+ /**
898
+ * @this {CompileContext}
899
+ * @type {Handle}
900
+ */
901
+
902
+ function onexitimage() {
903
+ const node = this.stack[this.stack.length - 1]
904
+ assert(node, 'expected node on stack')
905
+ assert(node.type === 'image', 'expected image on stack')
906
+
907
+ // Note: there are also `identifier` and `label` fields on this link node!
908
+ // These are used / cleaned here.
909
+
910
+ // To do: clean.
911
+ if (this.data.inReference) {
912
+ /** @type {ReferenceType} */
913
+ const referenceType = this.data.referenceType || 'shortcut'
914
+
915
+ node.type += 'Reference'
916
+ // @ts-expect-error: mutate.
917
+ node.referenceType = referenceType
918
+ // @ts-expect-error: mutate.
919
+ delete node.url
920
+ delete node.title
921
+ } else {
922
+ // @ts-expect-error: mutate.
923
+ delete node.identifier
924
+ // @ts-expect-error: mutate.
925
+ delete node.label
926
+ }
927
+
928
+ this.data.referenceType = undefined
929
+ }
930
+
931
+ /**
932
+ * @this {CompileContext}
933
+ * @type {Handle}
934
+ */
935
+
936
+ function onexitlabeltext(token) {
937
+ const string = this.sliceSerialize(token)
938
+ const ancestor = this.stack[this.stack.length - 2]
939
+ assert(ancestor, 'expected ancestor on stack')
940
+ assert(
941
+ ancestor.type === 'image' || ancestor.type === 'link',
942
+ 'expected image or link on stack'
943
+ )
944
+
945
+ // @ts-expect-error: stash this on the node, as it might become a reference
946
+ // later.
947
+ ancestor.label = decodeString(string)
948
+ // @ts-expect-error: same as above.
949
+ ancestor.identifier = normalizeIdentifier(string).toLowerCase()
950
+ }
951
+
952
+ /**
953
+ * @this {CompileContext}
954
+ * @type {Handle}
955
+ */
956
+
957
+ function onexitlabel() {
958
+ const fragment = this.stack[this.stack.length - 1]
959
+ assert(fragment, 'expected node on stack')
960
+ assert(fragment.type === 'fragment', 'expected fragment on stack')
961
+ const value = this.resume()
962
+ const node = this.stack[this.stack.length - 1]
963
+ assert(node, 'expected node on stack')
964
+ assert(
965
+ node.type === 'image' || node.type === 'link',
966
+ 'expected image or link on stack'
967
+ )
968
+
969
+ // Assume a reference.
970
+ this.data.inReference = true
971
+
972
+ if (node.type === 'link') {
973
+ /** @type {Array<PhrasingContent>} */
974
+ const children = fragment.children
975
+
976
+ node.children = children
977
+ } else {
978
+ node.alt = value
979
+ }
980
+ }
981
+
982
+ /**
983
+ * @this {CompileContext}
984
+ * @type {Handle}
985
+ */
986
+
987
+ function onexitresourcedestinationstring() {
988
+ const data = this.resume()
989
+ const node = this.stack[this.stack.length - 1]
990
+ assert(node, 'expected node on stack')
991
+ assert(
992
+ node.type === 'image' || node.type === 'link',
993
+ 'expected image or link on stack'
994
+ )
995
+ node.url = data
996
+ }
997
+
998
+ /**
999
+ * @this {CompileContext}
1000
+ * @type {Handle}
1001
+ */
1002
+
1003
+ function onexitresourcetitlestring() {
1004
+ const data = this.resume()
1005
+ const node = this.stack[this.stack.length - 1]
1006
+ assert(node, 'expected node on stack')
1007
+ assert(
1008
+ node.type === 'image' || node.type === 'link',
1009
+ 'expected image or link on stack'
1010
+ )
1011
+ node.title = data
1012
+ }
1013
+
1014
+ /**
1015
+ * @this {CompileContext}
1016
+ * @type {Handle}
1017
+ */
1018
+
1019
+ function onexitresource() {
1020
+ this.data.inReference = undefined
1021
+ }
1022
+
1023
+ /**
1024
+ * @this {CompileContext}
1025
+ * @type {Handle}
1026
+ */
1027
+
1028
+ function onenterreference() {
1029
+ this.data.referenceType = 'collapsed'
1030
+ }
1031
+
1032
+ /**
1033
+ * @this {CompileContext}
1034
+ * @type {Handle}
1035
+ */
1036
+
1037
+ function onexitreferencestring(token) {
1038
+ const label = this.resume()
1039
+ const node = this.stack[this.stack.length - 1]
1040
+ assert(node, 'expected node on stack')
1041
+ assert(
1042
+ node.type === 'image' || node.type === 'link',
1043
+ 'expected image reference or link reference on stack'
1044
+ )
1045
+
1046
+ // @ts-expect-error: stash this on the node, as it might become a reference
1047
+ // later.
1048
+ node.label = label
1049
+ // @ts-expect-error: same as above.
1050
+ node.identifier = normalizeIdentifier(
1051
+ this.sliceSerialize(token)
1052
+ ).toLowerCase()
1053
+ this.data.referenceType = 'full'
1054
+ }
1055
+
1056
+ /**
1057
+ * @this {CompileContext}
1058
+ * @type {Handle}
1059
+ */
1060
+
1061
+ function onexitcharacterreferencemarker(token) {
1062
+ assert(
1063
+ token.type === 'characterReferenceMarkerNumeric' ||
1064
+ token.type === 'characterReferenceMarkerHexadecimal'
1065
+ )
1066
+ this.data.characterReferenceType = token.type
1067
+ }
1068
+
1069
+ /**
1070
+ * @this {CompileContext}
1071
+ * @type {Handle}
1072
+ */
1073
+ function onexitcharacterreferencevalue(token) {
1074
+ const data = this.sliceSerialize(token)
1075
+ const type = this.data.characterReferenceType
1076
+ /** @type {string} */
1077
+ let value
1078
+
1079
+ if (type) {
1080
+ value = decodeNumericCharacterReference(
1081
+ data,
1082
+ type === types.characterReferenceMarkerNumeric
1083
+ ? constants.numericBaseDecimal
1084
+ : constants.numericBaseHexadecimal
1085
+ )
1086
+ this.data.characterReferenceType = undefined
1087
+ } else {
1088
+ const result = decodeNamedCharacterReference(data)
1089
+ assert(result !== false, 'expected reference to decode')
1090
+ value = result
1091
+ }
1092
+
1093
+ const tail = this.stack[this.stack.length - 1]
1094
+ assert(tail, 'expected `node`')
1095
+ assert('value' in tail, 'expected `node.value`')
1096
+ tail.value += value
1097
+ }
1098
+
1099
+ /**
1100
+ * @this {CompileContext}
1101
+ * @type {Handle}
1102
+ */
1103
+ function onexitcharacterreference(token) {
1104
+ const tail = this.stack.pop()
1105
+ assert(tail, 'expected `node`')
1106
+ assert(tail.position, 'expected `node.position`')
1107
+ tail.position.end = point(token.end)
1108
+ }
1109
+
1110
+ /**
1111
+ * @this {CompileContext}
1112
+ * @type {Handle}
1113
+ */
1114
+ function onexitautolinkprotocol(token) {
1115
+ onexitdata.call(this, token)
1116
+ const node = this.stack[this.stack.length - 1]
1117
+ assert(node, 'expected node on stack')
1118
+ assert(node.type === 'link', 'expected link on stack')
1119
+
1120
+ node.url = this.sliceSerialize(token)
1121
+ }
1122
+
1123
+ /**
1124
+ * @this {CompileContext}
1125
+ * @type {Handle}
1126
+ */
1127
+ function onexitautolinkemail(token) {
1128
+ onexitdata.call(this, token)
1129
+ const node = this.stack[this.stack.length - 1]
1130
+ assert(node, 'expected node on stack')
1131
+ assert(node.type === 'link', 'expected link on stack')
1132
+
1133
+ node.url = 'mailto:' + this.sliceSerialize(token)
1134
+ }
1135
+
1136
+ //
1137
+ // Creaters.
1138
+ //
1139
+
1140
+ /** @returns {Blockquote} */
1141
+ function blockQuote() {
1142
+ return {type: 'blockquote', children: []}
1143
+ }
1144
+
1145
+ /** @returns {Code} */
1146
+ function codeFlow() {
1147
+ return {type: 'code', lang: null, meta: null, value: ''}
1148
+ }
1149
+
1150
+ /** @returns {InlineCode} */
1151
+ function codeText() {
1152
+ return {type: 'inlineCode', value: ''}
1153
+ }
1154
+
1155
+ /** @returns {Definition} */
1156
+ function definition() {
1157
+ return {
1158
+ type: 'definition',
1159
+ identifier: '',
1160
+ label: null,
1161
+ title: null,
1162
+ url: ''
1163
+ }
1164
+ }
1165
+
1166
+ /** @returns {Emphasis} */
1167
+ function emphasis() {
1168
+ return {type: 'emphasis', children: []}
1169
+ }
1170
+
1171
+ /** @returns {Heading} */
1172
+ function heading() {
1173
+ return {
1174
+ type: 'heading',
1175
+ // @ts-expect-error `depth` will be set later.
1176
+ depth: 0,
1177
+ children: []
1178
+ }
1179
+ }
1180
+
1181
+ /** @returns {Break} */
1182
+ function hardBreak() {
1183
+ return {type: 'break'}
1184
+ }
1185
+
1186
+ /** @returns {Html} */
1187
+ function html() {
1188
+ return {type: 'html', value: ''}
1189
+ }
1190
+
1191
+ /** @returns {Image} */
1192
+ function image() {
1193
+ return {type: 'image', title: null, url: '', alt: null}
1194
+ }
1195
+
1196
+ /** @returns {Link} */
1197
+ function link() {
1198
+ return {type: 'link', title: null, url: '', children: []}
1199
+ }
1200
+
1201
+ /**
1202
+ * @param {Token} token
1203
+ * @returns {List}
1204
+ */
1205
+ function list(token) {
1206
+ return {
1207
+ type: 'list',
1208
+ ordered: token.type === 'listOrdered',
1209
+ start: null,
1210
+ spread: token._spread,
1211
+ children: []
1212
+ }
1213
+ }
1214
+
1215
+ /**
1216
+ * @param {Token} token
1217
+ * @returns {ListItem}
1218
+ */
1219
+ function listItem(token) {
1220
+ return {
1221
+ type: 'listItem',
1222
+ spread: token._spread,
1223
+ checked: null,
1224
+ children: []
1225
+ }
1226
+ }
1227
+
1228
+ /** @returns {Paragraph} */
1229
+ function paragraph() {
1230
+ return {type: 'paragraph', children: []}
1231
+ }
1232
+
1233
+ /** @returns {Strong} */
1234
+ function strong() {
1235
+ return {type: 'strong', children: []}
1236
+ }
1237
+
1238
+ /** @returns {Text} */
1239
+ function text() {
1240
+ return {type: 'text', value: ''}
1241
+ }
1242
+
1243
+ /** @returns {ThematicBreak} */
1244
+ function thematicBreak() {
1245
+ return {type: 'thematicBreak'}
1246
+ }
1247
+ }
1248
+
1249
+ /**
1250
+ * Copy a point-like value.
1251
+ *
1252
+ * @param {Point} d
1253
+ * Point-like value.
1254
+ * @returns {Point}
1255
+ * unist point.
1256
+ */
1257
+ function point(d) {
1258
+ return {line: d.line, column: d.column, offset: d.offset}
1259
+ }
1260
+
1261
+ /**
1262
+ * @param {Config} combined
1263
+ * @param {Array<Array<Extension> | Extension>} extensions
1264
+ * @returns {undefined}
1265
+ */
1266
+ function configure(combined, extensions) {
1267
+ let index = -1
1268
+
1269
+ while (++index < extensions.length) {
1270
+ const value = extensions[index]
1271
+
1272
+ if (Array.isArray(value)) {
1273
+ configure(combined, value)
1274
+ } else {
1275
+ extension(combined, value)
1276
+ }
1277
+ }
1278
+ }
1279
+
1280
+ /**
1281
+ * @param {Config} combined
1282
+ * @param {Extension} extension
1283
+ * @returns {undefined}
1284
+ */
1285
+ function extension(combined, extension) {
1286
+ /** @type {keyof Extension} */
1287
+ let key
1288
+
1289
+ for (key in extension) {
1290
+ if (own.call(extension, key)) {
1291
+ switch (key) {
1292
+ case 'canContainEols': {
1293
+ const right = extension[key]
1294
+ if (right) {
1295
+ combined[key].push(...right)
1296
+ }
1297
+
1298
+ break
1299
+ }
1300
+
1301
+ case 'transforms': {
1302
+ const right = extension[key]
1303
+ if (right) {
1304
+ combined[key].push(...right)
1305
+ }
1306
+
1307
+ break
1308
+ }
1309
+
1310
+ case 'enter':
1311
+ case 'exit': {
1312
+ const right = extension[key]
1313
+ if (right) {
1314
+ Object.assign(combined[key], right)
1315
+ }
1316
+
1317
+ break
1318
+ }
1319
+ // No default
1320
+ }
1321
+ }
1322
+ }
1323
+ }
1324
+
1325
+ /** @type {OnEnterError} */
1326
+ function defaultOnError(left, right) {
1327
+ if (left) {
1328
+ throw new Error(
1329
+ 'Cannot close `' +
1330
+ left.type +
1331
+ '` (' +
1332
+ stringifyPosition({start: left.start, end: left.end}) +
1333
+ '): a different token (`' +
1334
+ right.type +
1335
+ '`, ' +
1336
+ stringifyPosition({start: right.start, end: right.end}) +
1337
+ ') is open'
1338
+ )
1339
+ } else {
1340
+ throw new Error(
1341
+ 'Cannot close document, a token (`' +
1342
+ right.type +
1343
+ '`, ' +
1344
+ stringifyPosition({start: right.start, end: right.end}) +
1345
+ ') is still open'
1346
+ )
1347
+ }
1348
+ }
node_modules/mdast-util-from-markdown/dev/lib/types.d.ts ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {Nodes, Parent, PhrasingContent, Root} from 'mdast'
2
+ import type {ParseOptions, Token} from 'micromark-util-types'
3
+
4
+ /**
5
+ * Compiler context.
6
+ */
7
+ export interface CompileContext {
8
+ /**
9
+ * Configuration.
10
+ */
11
+ config: Config
12
+ /**
13
+ * Info passed around;
14
+ * key/value store.
15
+ */
16
+ data: CompileData
17
+ /**
18
+ * Stack of nodes.
19
+ */
20
+ stack: Array<Fragment | Nodes>
21
+ /**
22
+ * Stack of tokens.
23
+ */
24
+ tokenStack: Array<TokenTuple>
25
+
26
+ /**
27
+ * Capture some of the output data.
28
+ *
29
+ * @param this
30
+ * Context.
31
+ * @returns
32
+ * Nothing.
33
+ */
34
+ buffer(this: CompileContext): undefined
35
+
36
+ /**
37
+ * Enter a node.
38
+ *
39
+ * @param this
40
+ * Context.
41
+ * @param node
42
+ * Node.
43
+ * @param token
44
+ * Token.
45
+ * @param onError
46
+ * Error handler.
47
+ * @returns
48
+ * Nothing.
49
+ */
50
+ enter(
51
+ this: CompileContext,
52
+ node: Nodes,
53
+ token: Token,
54
+ onError?: OnEnterError | null | undefined
55
+ ): undefined
56
+
57
+ /**
58
+ * Exit a node.
59
+ *
60
+ * @param this
61
+ * Context.
62
+ * @param token
63
+ * Token.
64
+ * @param onError
65
+ * Error handler.
66
+ * @returns
67
+ * Nothing.
68
+ */
69
+ exit(
70
+ this: CompileContext,
71
+ token: Token,
72
+ onError?: OnExitError | null | undefined
73
+ ): undefined
74
+
75
+ /**
76
+ * Stop capturing and access the output data.
77
+ *
78
+ * @param this
79
+ * Context.
80
+ * @returns
81
+ * Nothing.
82
+ */
83
+ resume(this: CompileContext): string
84
+
85
+ /**
86
+ * Get the source text that spans a token (or location).
87
+ *
88
+ * @param token
89
+ * Start/end in stream.
90
+ * @param expandTabs
91
+ * Whether to expand tabs.
92
+ * @returns
93
+ * Serialized chunks.
94
+ */
95
+ sliceSerialize(
96
+ token: Pick<Token, 'end' | 'start'>,
97
+ expandTabs?: boolean | undefined
98
+ ): string
99
+ }
100
+
101
+ /**
102
+ * Interface of tracked data.
103
+ *
104
+ * When working on extensions that use more data, extend the corresponding
105
+ * interface to register their types:
106
+ *
107
+ * ```ts
108
+ * declare module 'mdast-util-from-markdown' {
109
+ * interface CompileData {
110
+ * // Register a new field.
111
+ * mathFlowInside?: boolean | undefined
112
+ * }
113
+ * }
114
+ * ```
115
+ */
116
+ export interface CompileData {
117
+ /**
118
+ * Whether we’re inside a hard break.
119
+ */
120
+ atHardBreak?: boolean | undefined
121
+
122
+ /**
123
+ * Current character reference type.
124
+ */
125
+ characterReferenceType?:
126
+ | 'characterReferenceMarkerHexadecimal'
127
+ | 'characterReferenceMarkerNumeric'
128
+ | undefined
129
+
130
+ /**
131
+ * Whether a first list item value (`1` in `1. a`) is expected.
132
+ */
133
+ expectingFirstListItemValue?: boolean | undefined
134
+
135
+ /**
136
+ * Whether we’re in flow code.
137
+ */
138
+ flowCodeInside?: boolean | undefined
139
+
140
+ /**
141
+ * Whether we’re in a reference.
142
+ */
143
+ inReference?: boolean | undefined
144
+
145
+ /**
146
+ * Whether we’re expecting a line ending from a setext heading, which can be slurped.
147
+ */
148
+ setextHeadingSlurpLineEnding?: boolean | undefined
149
+
150
+ /**
151
+ * Current reference.
152
+ */
153
+ referenceType?: 'collapsed' | 'full' | undefined
154
+ }
155
+
156
+ /**
157
+ * Configuration.
158
+ *
159
+ * We have our defaults, but extensions will add more.
160
+ */
161
+ export interface Config {
162
+ /**
163
+ * Token types where line endings are used.
164
+ */
165
+ canContainEols: Array<string>
166
+ /**
167
+ * Opening handles.
168
+ */
169
+ enter: Handles
170
+ /**
171
+ * Closing handles.
172
+ */
173
+ exit: Handles
174
+ /**
175
+ * Tree transforms.
176
+ */
177
+ transforms: Array<Transform>
178
+ }
179
+
180
+ /**
181
+ * Change how markdown tokens from micromark are turned into mdast.
182
+ */
183
+ export interface Extension {
184
+ /**
185
+ * Token types where line endings are used.
186
+ */
187
+ canContainEols?: Array<string> | null | undefined
188
+ /**
189
+ * Opening handles.
190
+ */
191
+ enter?: Handles | null | undefined
192
+ /**
193
+ * Closing handles.
194
+ */
195
+ exit?: Handles | null | undefined
196
+ /**
197
+ * Tree transforms.
198
+ */
199
+ transforms?: Array<Transform> | null | undefined
200
+ }
201
+
202
+ /**
203
+ * Internal fragment.
204
+ */
205
+ export interface Fragment extends Parent {
206
+ /**
207
+ * Node type.
208
+ */
209
+ type: 'fragment'
210
+ /**
211
+ * Children.
212
+ */
213
+ children: Array<PhrasingContent>
214
+ }
215
+
216
+ /**
217
+ * Token types mapping to handles
218
+ */
219
+ export type Handles = Record<string, Handle>
220
+
221
+ /**
222
+ * Handle a token.
223
+ *
224
+ * @param this
225
+ * Context.
226
+ * @param token
227
+ * Current token.
228
+ * @returns
229
+ * Nothing.
230
+ */
231
+ export type Handle = (this: CompileContext, token: Token) => undefined | void
232
+
233
+ /**
234
+ * Handle the case where the `right` token is open, but it is closed (by the
235
+ * `left` token) or because we reached the end of the document.
236
+ *
237
+ * @param this
238
+ * Context.
239
+ * @param left
240
+ * Left token.
241
+ * @param right
242
+ * Right token.
243
+ * @returns
244
+ * Nothing.
245
+ */
246
+ export type OnEnterError = (
247
+ this: Omit<CompileContext, 'sliceSerialize'>,
248
+ left: Token | undefined,
249
+ right: Token
250
+ ) => undefined
251
+
252
+ /**
253
+ * Handle the case where the `right` token is open but it is closed by
254
+ * exiting the `left` token.
255
+ *
256
+ * @param this
257
+ * Context.
258
+ * @param left
259
+ * Left token.
260
+ * @param right
261
+ * Right token.
262
+ * @returns
263
+ * Nothing.
264
+ */
265
+ export type OnExitError = (
266
+ this: Omit<CompileContext, 'sliceSerialize'>,
267
+ left: Token,
268
+ right: Token
269
+ ) => undefined
270
+
271
+ /**
272
+ * Configuration.
273
+ */
274
+ export interface Options extends ParseOptions {
275
+ /**
276
+ * Extensions for this utility to change how tokens are turned into a tree.
277
+ */
278
+ mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined
279
+ }
280
+
281
+ /**
282
+ * Open token on the stack,
283
+ * with an optional error handler for when that token isn’t closed properly.
284
+ */
285
+ export type TokenTuple = [token: Token, onError: OnEnterError | undefined]
286
+
287
+ /**
288
+ * Extra transform, to change the AST afterwards.
289
+ *
290
+ * @param tree
291
+ * Tree to transform.
292
+ * @returns
293
+ * New tree or nothing (in which case the current tree is used).
294
+ */
295
+ export type Transform = (tree: Root) => Root | null | undefined | void
node_modules/mdast-util-from-markdown/dev/lib/types.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // Note: types exposed from `types.d.ts`.
2
+ export {}
node_modules/mdast-util-from-markdown/index.d.ts ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export type {Encoding, Token, Value} from 'micromark-util-types'
2
+ export type {
3
+ CompileContext,
4
+ CompileData,
5
+ Extension,
6
+ Handles,
7
+ Handle,
8
+ OnEnterError,
9
+ OnExitError,
10
+ Options,
11
+ Transform
12
+ } from './lib/types.js'
13
+ export {fromMarkdown} from './lib/index.js'
14
+
15
+ declare module 'micromark-util-types' {
16
+ interface TokenTypeMap {
17
+ listItem: 'listItem'
18
+ }
19
+
20
+ interface Token {
21
+ _spread?: boolean
22
+ }
23
+ }
node_modules/mdast-util-from-markdown/index.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // Note: types exported from `index.d.ts`.
2
+ export { fromMarkdown } from './lib/index.js';
node_modules/mdast-util-from-markdown/lib/index.d.ts ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Turn markdown into a syntax tree.
3
+ *
4
+ * @overload
5
+ * @param {Value} value
6
+ * @param {Encoding | null | undefined} [encoding]
7
+ * @param {Options | null | undefined} [options]
8
+ * @returns {Root}
9
+ *
10
+ * @overload
11
+ * @param {Value} value
12
+ * @param {Options | null | undefined} [options]
13
+ * @returns {Root}
14
+ *
15
+ * @param {Value} value
16
+ * Markdown to parse.
17
+ * @param {Encoding | Options | null | undefined} [encoding]
18
+ * Character encoding for when `value` is `Buffer`.
19
+ * @param {Options | null | undefined} [options]
20
+ * Configuration.
21
+ * @returns {Root}
22
+ * mdast tree.
23
+ */
24
+ export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root;
25
+ /**
26
+ * Turn markdown into a syntax tree.
27
+ *
28
+ * @overload
29
+ * @param {Value} value
30
+ * @param {Encoding | null | undefined} [encoding]
31
+ * @param {Options | null | undefined} [options]
32
+ * @returns {Root}
33
+ *
34
+ * @overload
35
+ * @param {Value} value
36
+ * @param {Options | null | undefined} [options]
37
+ * @returns {Root}
38
+ *
39
+ * @param {Value} value
40
+ * Markdown to parse.
41
+ * @param {Encoding | Options | null | undefined} [encoding]
42
+ * Character encoding for when `value` is `Buffer`.
43
+ * @param {Options | null | undefined} [options]
44
+ * Configuration.
45
+ * @returns {Root}
46
+ * mdast tree.
47
+ */
48
+ export function fromMarkdown(value: Value, options?: Options | null | undefined): Root;
49
+ import type { Value } from 'micromark-util-types';
50
+ import type { Encoding } from 'micromark-util-types';
51
+ import type { Options } from './types.js';
52
+ import type { Root } from 'mdast';
53
+ //# sourceMappingURL=index.d.ts.map
node_modules/mdast-util-from-markdown/lib/index.d.ts.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwDG,oCACQ,KAAK,aACL,QAAQ,GAAG,IAAI,GAAG,SAAS,YAC3B,OAAO,GAAG,IAAI,GAAG,SAAS,GACxB,IAAI,CAEd;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCACQ,KAAK,YACL,OAAO,GAAG,IAAI,GAAG,SAAS,GACxB,IAAI,CAEd;2BAvCO,sBAAsB;8BAAtB,sBAAsB;6BAUtB,YAAY;0BAhBZ,OAAO"}
node_modules/mdast-util-from-markdown/lib/index.js ADDED
@@ -0,0 +1,1177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @import {
3
+ * Break,
4
+ * Blockquote,
5
+ * Code,
6
+ * Definition,
7
+ * Emphasis,
8
+ * Heading,
9
+ * Html,
10
+ * Image,
11
+ * InlineCode,
12
+ * Link,
13
+ * ListItem,
14
+ * List,
15
+ * Nodes,
16
+ * Paragraph,
17
+ * PhrasingContent,
18
+ * ReferenceType,
19
+ * Root,
20
+ * Strong,
21
+ * Text,
22
+ * ThematicBreak
23
+ * } from 'mdast'
24
+ * @import {
25
+ * Encoding,
26
+ * Event,
27
+ * Token,
28
+ * Value
29
+ * } from 'micromark-util-types'
30
+ * @import {Point} from 'unist'
31
+ * @import {
32
+ * CompileContext,
33
+ * CompileData,
34
+ * Config,
35
+ * Extension,
36
+ * Handle,
37
+ * OnEnterError,
38
+ * Options
39
+ * } from './types.js'
40
+ */
41
+
42
+ import { toString } from 'mdast-util-to-string';
43
+ import { parse, postprocess, preprocess } from 'micromark';
44
+ import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
45
+ import { decodeString } from 'micromark-util-decode-string';
46
+ import { normalizeIdentifier } from 'micromark-util-normalize-identifier';
47
+ import { decodeNamedCharacterReference } from 'decode-named-character-reference';
48
+ import { stringifyPosition } from 'unist-util-stringify-position';
49
+ const own = {}.hasOwnProperty;
50
+
51
+ /**
52
+ * Turn markdown into a syntax tree.
53
+ *
54
+ * @overload
55
+ * @param {Value} value
56
+ * @param {Encoding | null | undefined} [encoding]
57
+ * @param {Options | null | undefined} [options]
58
+ * @returns {Root}
59
+ *
60
+ * @overload
61
+ * @param {Value} value
62
+ * @param {Options | null | undefined} [options]
63
+ * @returns {Root}
64
+ *
65
+ * @param {Value} value
66
+ * Markdown to parse.
67
+ * @param {Encoding | Options | null | undefined} [encoding]
68
+ * Character encoding for when `value` is `Buffer`.
69
+ * @param {Options | null | undefined} [options]
70
+ * Configuration.
71
+ * @returns {Root}
72
+ * mdast tree.
73
+ */
74
+ export function fromMarkdown(value, encoding, options) {
75
+ if (encoding && typeof encoding === 'object') {
76
+ options = encoding;
77
+ encoding = undefined;
78
+ }
79
+ return compiler(options)(postprocess(parse(options).document().write(preprocess()(value, encoding, true))));
80
+ }
81
+
82
+ /**
83
+ * Note this compiler only understand complete buffering, not streaming.
84
+ *
85
+ * @param {Options | null | undefined} [options]
86
+ */
87
+ function compiler(options) {
88
+ /** @type {Config} */
89
+ const config = {
90
+ transforms: [],
91
+ canContainEols: ['emphasis', 'fragment', 'heading', 'paragraph', 'strong'],
92
+ enter: {
93
+ autolink: opener(link),
94
+ autolinkProtocol: onenterdata,
95
+ autolinkEmail: onenterdata,
96
+ atxHeading: opener(heading),
97
+ blockQuote: opener(blockQuote),
98
+ characterEscape: onenterdata,
99
+ characterReference: onenterdata,
100
+ codeFenced: opener(codeFlow),
101
+ codeFencedFenceInfo: buffer,
102
+ codeFencedFenceMeta: buffer,
103
+ codeIndented: opener(codeFlow, buffer),
104
+ codeText: opener(codeText, buffer),
105
+ codeTextData: onenterdata,
106
+ data: onenterdata,
107
+ codeFlowValue: onenterdata,
108
+ definition: opener(definition),
109
+ definitionDestinationString: buffer,
110
+ definitionLabelString: buffer,
111
+ definitionTitleString: buffer,
112
+ emphasis: opener(emphasis),
113
+ hardBreakEscape: opener(hardBreak),
114
+ hardBreakTrailing: opener(hardBreak),
115
+ htmlFlow: opener(html, buffer),
116
+ htmlFlowData: onenterdata,
117
+ htmlText: opener(html, buffer),
118
+ htmlTextData: onenterdata,
119
+ image: opener(image),
120
+ label: buffer,
121
+ link: opener(link),
122
+ listItem: opener(listItem),
123
+ listItemValue: onenterlistitemvalue,
124
+ listOrdered: opener(list, onenterlistordered),
125
+ listUnordered: opener(list),
126
+ paragraph: opener(paragraph),
127
+ reference: onenterreference,
128
+ referenceString: buffer,
129
+ resourceDestinationString: buffer,
130
+ resourceTitleString: buffer,
131
+ setextHeading: opener(heading),
132
+ strong: opener(strong),
133
+ thematicBreak: opener(thematicBreak)
134
+ },
135
+ exit: {
136
+ atxHeading: closer(),
137
+ atxHeadingSequence: onexitatxheadingsequence,
138
+ autolink: closer(),
139
+ autolinkEmail: onexitautolinkemail,
140
+ autolinkProtocol: onexitautolinkprotocol,
141
+ blockQuote: closer(),
142
+ characterEscapeValue: onexitdata,
143
+ characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker,
144
+ characterReferenceMarkerNumeric: onexitcharacterreferencemarker,
145
+ characterReferenceValue: onexitcharacterreferencevalue,
146
+ characterReference: onexitcharacterreference,
147
+ codeFenced: closer(onexitcodefenced),
148
+ codeFencedFence: onexitcodefencedfence,
149
+ codeFencedFenceInfo: onexitcodefencedfenceinfo,
150
+ codeFencedFenceMeta: onexitcodefencedfencemeta,
151
+ codeFlowValue: onexitdata,
152
+ codeIndented: closer(onexitcodeindented),
153
+ codeText: closer(onexitcodetext),
154
+ codeTextData: onexitdata,
155
+ data: onexitdata,
156
+ definition: closer(),
157
+ definitionDestinationString: onexitdefinitiondestinationstring,
158
+ definitionLabelString: onexitdefinitionlabelstring,
159
+ definitionTitleString: onexitdefinitiontitlestring,
160
+ emphasis: closer(),
161
+ hardBreakEscape: closer(onexithardbreak),
162
+ hardBreakTrailing: closer(onexithardbreak),
163
+ htmlFlow: closer(onexithtmlflow),
164
+ htmlFlowData: onexitdata,
165
+ htmlText: closer(onexithtmltext),
166
+ htmlTextData: onexitdata,
167
+ image: closer(onexitimage),
168
+ label: onexitlabel,
169
+ labelText: onexitlabeltext,
170
+ lineEnding: onexitlineending,
171
+ link: closer(onexitlink),
172
+ listItem: closer(),
173
+ listOrdered: closer(),
174
+ listUnordered: closer(),
175
+ paragraph: closer(),
176
+ referenceString: onexitreferencestring,
177
+ resourceDestinationString: onexitresourcedestinationstring,
178
+ resourceTitleString: onexitresourcetitlestring,
179
+ resource: onexitresource,
180
+ setextHeading: closer(onexitsetextheading),
181
+ setextHeadingLineSequence: onexitsetextheadinglinesequence,
182
+ setextHeadingText: onexitsetextheadingtext,
183
+ strong: closer(),
184
+ thematicBreak: closer()
185
+ }
186
+ };
187
+ configure(config, (options || {}).mdastExtensions || []);
188
+
189
+ /** @type {CompileData} */
190
+ const data = {};
191
+ return compile;
192
+
193
+ /**
194
+ * Turn micromark events into an mdast tree.
195
+ *
196
+ * @param {Array<Event>} events
197
+ * Events.
198
+ * @returns {Root}
199
+ * mdast tree.
200
+ */
201
+ function compile(events) {
202
+ /** @type {Root} */
203
+ let tree = {
204
+ type: 'root',
205
+ children: []
206
+ };
207
+ /** @type {Omit<CompileContext, 'sliceSerialize'>} */
208
+ const context = {
209
+ stack: [tree],
210
+ tokenStack: [],
211
+ config,
212
+ enter,
213
+ exit,
214
+ buffer,
215
+ resume,
216
+ data
217
+ };
218
+ /** @type {Array<number>} */
219
+ const listStack = [];
220
+ let index = -1;
221
+ while (++index < events.length) {
222
+ // We preprocess lists to add `listItem` tokens, and to infer whether
223
+ // items the list itself are spread out.
224
+ if (events[index][1].type === "listOrdered" || events[index][1].type === "listUnordered") {
225
+ if (events[index][0] === 'enter') {
226
+ listStack.push(index);
227
+ } else {
228
+ const tail = listStack.pop();
229
+ index = prepareList(events, tail, index);
230
+ }
231
+ }
232
+ }
233
+ index = -1;
234
+ while (++index < events.length) {
235
+ const handler = config[events[index][0]];
236
+ if (own.call(handler, events[index][1].type)) {
237
+ handler[events[index][1].type].call(Object.assign({
238
+ sliceSerialize: events[index][2].sliceSerialize
239
+ }, context), events[index][1]);
240
+ }
241
+ }
242
+
243
+ // Handle tokens still being open.
244
+ if (context.tokenStack.length > 0) {
245
+ const tail = context.tokenStack[context.tokenStack.length - 1];
246
+ const handler = tail[1] || defaultOnError;
247
+ handler.call(context, undefined, tail[0]);
248
+ }
249
+
250
+ // Figure out `root` position.
251
+ tree.position = {
252
+ start: point(events.length > 0 ? events[0][1].start : {
253
+ line: 1,
254
+ column: 1,
255
+ offset: 0
256
+ }),
257
+ end: point(events.length > 0 ? events[events.length - 2][1].end : {
258
+ line: 1,
259
+ column: 1,
260
+ offset: 0
261
+ })
262
+ };
263
+
264
+ // Call transforms.
265
+ index = -1;
266
+ while (++index < config.transforms.length) {
267
+ tree = config.transforms[index](tree) || tree;
268
+ }
269
+ return tree;
270
+ }
271
+
272
+ /**
273
+ * @param {Array<Event>} events
274
+ * @param {number} start
275
+ * @param {number} length
276
+ * @returns {number}
277
+ */
278
+ function prepareList(events, start, length) {
279
+ let index = start - 1;
280
+ let containerBalance = -1;
281
+ let listSpread = false;
282
+ /** @type {Token | undefined} */
283
+ let listItem;
284
+ /** @type {number | undefined} */
285
+ let lineIndex;
286
+ /** @type {number | undefined} */
287
+ let firstBlankLineIndex;
288
+ /** @type {boolean | undefined} */
289
+ let atMarker;
290
+ while (++index <= length) {
291
+ const event = events[index];
292
+ switch (event[1].type) {
293
+ case "listUnordered":
294
+ case "listOrdered":
295
+ case "blockQuote":
296
+ {
297
+ if (event[0] === 'enter') {
298
+ containerBalance++;
299
+ } else {
300
+ containerBalance--;
301
+ }
302
+ atMarker = undefined;
303
+ break;
304
+ }
305
+ case "lineEndingBlank":
306
+ {
307
+ if (event[0] === 'enter') {
308
+ if (listItem && !atMarker && !containerBalance && !firstBlankLineIndex) {
309
+ firstBlankLineIndex = index;
310
+ }
311
+ atMarker = undefined;
312
+ }
313
+ break;
314
+ }
315
+ case "linePrefix":
316
+ case "listItemValue":
317
+ case "listItemMarker":
318
+ case "listItemPrefix":
319
+ case "listItemPrefixWhitespace":
320
+ {
321
+ // Empty.
322
+
323
+ break;
324
+ }
325
+ default:
326
+ {
327
+ atMarker = undefined;
328
+ }
329
+ }
330
+ if (!containerBalance && event[0] === 'enter' && event[1].type === "listItemPrefix" || containerBalance === -1 && event[0] === 'exit' && (event[1].type === "listUnordered" || event[1].type === "listOrdered")) {
331
+ if (listItem) {
332
+ let tailIndex = index;
333
+ lineIndex = undefined;
334
+ while (tailIndex--) {
335
+ const tailEvent = events[tailIndex];
336
+ if (tailEvent[1].type === "lineEnding" || tailEvent[1].type === "lineEndingBlank") {
337
+ if (tailEvent[0] === 'exit') continue;
338
+ if (lineIndex) {
339
+ events[lineIndex][1].type = "lineEndingBlank";
340
+ listSpread = true;
341
+ }
342
+ tailEvent[1].type = "lineEnding";
343
+ lineIndex = tailIndex;
344
+ } else if (tailEvent[1].type === "linePrefix" || tailEvent[1].type === "blockQuotePrefix" || tailEvent[1].type === "blockQuotePrefixWhitespace" || tailEvent[1].type === "blockQuoteMarker" || tailEvent[1].type === "listItemIndent") {
345
+ // Empty
346
+ } else {
347
+ break;
348
+ }
349
+ }
350
+ if (firstBlankLineIndex && (!lineIndex || firstBlankLineIndex < lineIndex)) {
351
+ listItem._spread = true;
352
+ }
353
+
354
+ // Fix position.
355
+ listItem.end = Object.assign({}, lineIndex ? events[lineIndex][1].start : event[1].end);
356
+ events.splice(lineIndex || index, 0, ['exit', listItem, event[2]]);
357
+ index++;
358
+ length++;
359
+ }
360
+
361
+ // Create a new list item.
362
+ if (event[1].type === "listItemPrefix") {
363
+ /** @type {Token} */
364
+ const item = {
365
+ type: 'listItem',
366
+ _spread: false,
367
+ start: Object.assign({}, event[1].start),
368
+ // @ts-expect-error: we’ll add `end` in a second.
369
+ end: undefined
370
+ };
371
+ listItem = item;
372
+ events.splice(index, 0, ['enter', item, event[2]]);
373
+ index++;
374
+ length++;
375
+ firstBlankLineIndex = undefined;
376
+ atMarker = true;
377
+ }
378
+ }
379
+ }
380
+ events[start][1]._spread = listSpread;
381
+ return length;
382
+ }
383
+
384
+ /**
385
+ * Create an opener handle.
386
+ *
387
+ * @param {(token: Token) => Nodes} create
388
+ * Create a node.
389
+ * @param {Handle | undefined} [and]
390
+ * Optional function to also run.
391
+ * @returns {Handle}
392
+ * Handle.
393
+ */
394
+ function opener(create, and) {
395
+ return open;
396
+
397
+ /**
398
+ * @this {CompileContext}
399
+ * @param {Token} token
400
+ * @returns {undefined}
401
+ */
402
+ function open(token) {
403
+ enter.call(this, create(token), token);
404
+ if (and) and.call(this, token);
405
+ }
406
+ }
407
+
408
+ /**
409
+ * @type {CompileContext['buffer']}
410
+ */
411
+ function buffer() {
412
+ this.stack.push({
413
+ type: 'fragment',
414
+ children: []
415
+ });
416
+ }
417
+
418
+ /**
419
+ * @type {CompileContext['enter']}
420
+ */
421
+ function enter(node, token, errorHandler) {
422
+ const parent = this.stack[this.stack.length - 1];
423
+ /** @type {Array<Nodes>} */
424
+ const siblings = parent.children;
425
+ siblings.push(node);
426
+ this.stack.push(node);
427
+ this.tokenStack.push([token, errorHandler || undefined]);
428
+ node.position = {
429
+ start: point(token.start),
430
+ // @ts-expect-error: `end` will be patched later.
431
+ end: undefined
432
+ };
433
+ }
434
+
435
+ /**
436
+ * Create a closer handle.
437
+ *
438
+ * @param {Handle | undefined} [and]
439
+ * Optional function to also run.
440
+ * @returns {Handle}
441
+ * Handle.
442
+ */
443
+ function closer(and) {
444
+ return close;
445
+
446
+ /**
447
+ * @this {CompileContext}
448
+ * @param {Token} token
449
+ * @returns {undefined}
450
+ */
451
+ function close(token) {
452
+ if (and) and.call(this, token);
453
+ exit.call(this, token);
454
+ }
455
+ }
456
+
457
+ /**
458
+ * @type {CompileContext['exit']}
459
+ */
460
+ function exit(token, onExitError) {
461
+ const node = this.stack.pop();
462
+ const open = this.tokenStack.pop();
463
+ if (!open) {
464
+ throw new Error('Cannot close `' + token.type + '` (' + stringifyPosition({
465
+ start: token.start,
466
+ end: token.end
467
+ }) + '): it’s not open');
468
+ } else if (open[0].type !== token.type) {
469
+ if (onExitError) {
470
+ onExitError.call(this, token, open[0]);
471
+ } else {
472
+ const handler = open[1] || defaultOnError;
473
+ handler.call(this, token, open[0]);
474
+ }
475
+ }
476
+ node.position.end = point(token.end);
477
+ }
478
+
479
+ /**
480
+ * @type {CompileContext['resume']}
481
+ */
482
+ function resume() {
483
+ return toString(this.stack.pop());
484
+ }
485
+
486
+ //
487
+ // Handlers.
488
+ //
489
+
490
+ /**
491
+ * @this {CompileContext}
492
+ * @type {Handle}
493
+ */
494
+ function onenterlistordered() {
495
+ this.data.expectingFirstListItemValue = true;
496
+ }
497
+
498
+ /**
499
+ * @this {CompileContext}
500
+ * @type {Handle}
501
+ */
502
+ function onenterlistitemvalue(token) {
503
+ if (this.data.expectingFirstListItemValue) {
504
+ const ancestor = this.stack[this.stack.length - 2];
505
+ ancestor.start = Number.parseInt(this.sliceSerialize(token), 10);
506
+ this.data.expectingFirstListItemValue = undefined;
507
+ }
508
+ }
509
+
510
+ /**
511
+ * @this {CompileContext}
512
+ * @type {Handle}
513
+ */
514
+ function onexitcodefencedfenceinfo() {
515
+ const data = this.resume();
516
+ const node = this.stack[this.stack.length - 1];
517
+ node.lang = data;
518
+ }
519
+
520
+ /**
521
+ * @this {CompileContext}
522
+ * @type {Handle}
523
+ */
524
+ function onexitcodefencedfencemeta() {
525
+ const data = this.resume();
526
+ const node = this.stack[this.stack.length - 1];
527
+ node.meta = data;
528
+ }
529
+
530
+ /**
531
+ * @this {CompileContext}
532
+ * @type {Handle}
533
+ */
534
+ function onexitcodefencedfence() {
535
+ // Exit if this is the closing fence.
536
+ if (this.data.flowCodeInside) return;
537
+ this.buffer();
538
+ this.data.flowCodeInside = true;
539
+ }
540
+
541
+ /**
542
+ * @this {CompileContext}
543
+ * @type {Handle}
544
+ */
545
+ function onexitcodefenced() {
546
+ const data = this.resume();
547
+ const node = this.stack[this.stack.length - 1];
548
+ node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '');
549
+ this.data.flowCodeInside = undefined;
550
+ }
551
+
552
+ /**
553
+ * @this {CompileContext}
554
+ * @type {Handle}
555
+ */
556
+ function onexitcodeindented() {
557
+ const data = this.resume();
558
+ const node = this.stack[this.stack.length - 1];
559
+ node.value = data.replace(/(\r?\n|\r)$/g, '');
560
+ }
561
+
562
+ /**
563
+ * @this {CompileContext}
564
+ * @type {Handle}
565
+ */
566
+ function onexitdefinitionlabelstring(token) {
567
+ const label = this.resume();
568
+ const node = this.stack[this.stack.length - 1];
569
+ node.label = label;
570
+ node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase();
571
+ }
572
+
573
+ /**
574
+ * @this {CompileContext}
575
+ * @type {Handle}
576
+ */
577
+ function onexitdefinitiontitlestring() {
578
+ const data = this.resume();
579
+ const node = this.stack[this.stack.length - 1];
580
+ node.title = data;
581
+ }
582
+
583
+ /**
584
+ * @this {CompileContext}
585
+ * @type {Handle}
586
+ */
587
+ function onexitdefinitiondestinationstring() {
588
+ const data = this.resume();
589
+ const node = this.stack[this.stack.length - 1];
590
+ node.url = data;
591
+ }
592
+
593
+ /**
594
+ * @this {CompileContext}
595
+ * @type {Handle}
596
+ */
597
+ function onexitatxheadingsequence(token) {
598
+ const node = this.stack[this.stack.length - 1];
599
+ if (!node.depth) {
600
+ const depth = this.sliceSerialize(token).length;
601
+ node.depth = depth;
602
+ }
603
+ }
604
+
605
+ /**
606
+ * @this {CompileContext}
607
+ * @type {Handle}
608
+ */
609
+ function onexitsetextheadingtext() {
610
+ this.data.setextHeadingSlurpLineEnding = true;
611
+ }
612
+
613
+ /**
614
+ * @this {CompileContext}
615
+ * @type {Handle}
616
+ */
617
+ function onexitsetextheadinglinesequence(token) {
618
+ const node = this.stack[this.stack.length - 1];
619
+ node.depth = this.sliceSerialize(token).codePointAt(0) === 61 ? 1 : 2;
620
+ }
621
+
622
+ /**
623
+ * @this {CompileContext}
624
+ * @type {Handle}
625
+ */
626
+ function onexitsetextheading() {
627
+ this.data.setextHeadingSlurpLineEnding = undefined;
628
+ }
629
+
630
+ /**
631
+ * @this {CompileContext}
632
+ * @type {Handle}
633
+ */
634
+
635
+ function onenterdata(token) {
636
+ const node = this.stack[this.stack.length - 1];
637
+ /** @type {Array<Nodes>} */
638
+ const siblings = node.children;
639
+ let tail = siblings[siblings.length - 1];
640
+ if (!tail || tail.type !== 'text') {
641
+ // Add a new text node.
642
+ tail = text();
643
+ tail.position = {
644
+ start: point(token.start),
645
+ // @ts-expect-error: we’ll add `end` later.
646
+ end: undefined
647
+ };
648
+ siblings.push(tail);
649
+ }
650
+ this.stack.push(tail);
651
+ }
652
+
653
+ /**
654
+ * @this {CompileContext}
655
+ * @type {Handle}
656
+ */
657
+
658
+ function onexitdata(token) {
659
+ const tail = this.stack.pop();
660
+ tail.value += this.sliceSerialize(token);
661
+ tail.position.end = point(token.end);
662
+ }
663
+
664
+ /**
665
+ * @this {CompileContext}
666
+ * @type {Handle}
667
+ */
668
+
669
+ function onexitlineending(token) {
670
+ const context = this.stack[this.stack.length - 1];
671
+ // If we’re at a hard break, include the line ending in there.
672
+ if (this.data.atHardBreak) {
673
+ const tail = context.children[context.children.length - 1];
674
+ tail.position.end = point(token.end);
675
+ this.data.atHardBreak = undefined;
676
+ return;
677
+ }
678
+ if (!this.data.setextHeadingSlurpLineEnding && config.canContainEols.includes(context.type)) {
679
+ onenterdata.call(this, token);
680
+ onexitdata.call(this, token);
681
+ }
682
+ }
683
+
684
+ /**
685
+ * @this {CompileContext}
686
+ * @type {Handle}
687
+ */
688
+
689
+ function onexithardbreak() {
690
+ this.data.atHardBreak = true;
691
+ }
692
+
693
+ /**
694
+ * @this {CompileContext}
695
+ * @type {Handle}
696
+ */
697
+
698
+ function onexithtmlflow() {
699
+ const data = this.resume();
700
+ const node = this.stack[this.stack.length - 1];
701
+ node.value = data;
702
+ }
703
+
704
+ /**
705
+ * @this {CompileContext}
706
+ * @type {Handle}
707
+ */
708
+
709
+ function onexithtmltext() {
710
+ const data = this.resume();
711
+ const node = this.stack[this.stack.length - 1];
712
+ node.value = data;
713
+ }
714
+
715
+ /**
716
+ * @this {CompileContext}
717
+ * @type {Handle}
718
+ */
719
+
720
+ function onexitcodetext() {
721
+ const data = this.resume();
722
+ const node = this.stack[this.stack.length - 1];
723
+ node.value = data;
724
+ }
725
+
726
+ /**
727
+ * @this {CompileContext}
728
+ * @type {Handle}
729
+ */
730
+
731
+ function onexitlink() {
732
+ const node = this.stack[this.stack.length - 1];
733
+ // Note: there are also `identifier` and `label` fields on this link node!
734
+ // These are used / cleaned here.
735
+
736
+ // To do: clean.
737
+ if (this.data.inReference) {
738
+ /** @type {ReferenceType} */
739
+ const referenceType = this.data.referenceType || 'shortcut';
740
+ node.type += 'Reference';
741
+ // @ts-expect-error: mutate.
742
+ node.referenceType = referenceType;
743
+ // @ts-expect-error: mutate.
744
+ delete node.url;
745
+ delete node.title;
746
+ } else {
747
+ // @ts-expect-error: mutate.
748
+ delete node.identifier;
749
+ // @ts-expect-error: mutate.
750
+ delete node.label;
751
+ }
752
+ this.data.referenceType = undefined;
753
+ }
754
+
755
+ /**
756
+ * @this {CompileContext}
757
+ * @type {Handle}
758
+ */
759
+
760
+ function onexitimage() {
761
+ const node = this.stack[this.stack.length - 1];
762
+ // Note: there are also `identifier` and `label` fields on this link node!
763
+ // These are used / cleaned here.
764
+
765
+ // To do: clean.
766
+ if (this.data.inReference) {
767
+ /** @type {ReferenceType} */
768
+ const referenceType = this.data.referenceType || 'shortcut';
769
+ node.type += 'Reference';
770
+ // @ts-expect-error: mutate.
771
+ node.referenceType = referenceType;
772
+ // @ts-expect-error: mutate.
773
+ delete node.url;
774
+ delete node.title;
775
+ } else {
776
+ // @ts-expect-error: mutate.
777
+ delete node.identifier;
778
+ // @ts-expect-error: mutate.
779
+ delete node.label;
780
+ }
781
+ this.data.referenceType = undefined;
782
+ }
783
+
784
+ /**
785
+ * @this {CompileContext}
786
+ * @type {Handle}
787
+ */
788
+
789
+ function onexitlabeltext(token) {
790
+ const string = this.sliceSerialize(token);
791
+ const ancestor = this.stack[this.stack.length - 2];
792
+ // @ts-expect-error: stash this on the node, as it might become a reference
793
+ // later.
794
+ ancestor.label = decodeString(string);
795
+ // @ts-expect-error: same as above.
796
+ ancestor.identifier = normalizeIdentifier(string).toLowerCase();
797
+ }
798
+
799
+ /**
800
+ * @this {CompileContext}
801
+ * @type {Handle}
802
+ */
803
+
804
+ function onexitlabel() {
805
+ const fragment = this.stack[this.stack.length - 1];
806
+ const value = this.resume();
807
+ const node = this.stack[this.stack.length - 1];
808
+ // Assume a reference.
809
+ this.data.inReference = true;
810
+ if (node.type === 'link') {
811
+ /** @type {Array<PhrasingContent>} */
812
+ const children = fragment.children;
813
+ node.children = children;
814
+ } else {
815
+ node.alt = value;
816
+ }
817
+ }
818
+
819
+ /**
820
+ * @this {CompileContext}
821
+ * @type {Handle}
822
+ */
823
+
824
+ function onexitresourcedestinationstring() {
825
+ const data = this.resume();
826
+ const node = this.stack[this.stack.length - 1];
827
+ node.url = data;
828
+ }
829
+
830
+ /**
831
+ * @this {CompileContext}
832
+ * @type {Handle}
833
+ */
834
+
835
+ function onexitresourcetitlestring() {
836
+ const data = this.resume();
837
+ const node = this.stack[this.stack.length - 1];
838
+ node.title = data;
839
+ }
840
+
841
+ /**
842
+ * @this {CompileContext}
843
+ * @type {Handle}
844
+ */
845
+
846
+ function onexitresource() {
847
+ this.data.inReference = undefined;
848
+ }
849
+
850
+ /**
851
+ * @this {CompileContext}
852
+ * @type {Handle}
853
+ */
854
+
855
+ function onenterreference() {
856
+ this.data.referenceType = 'collapsed';
857
+ }
858
+
859
+ /**
860
+ * @this {CompileContext}
861
+ * @type {Handle}
862
+ */
863
+
864
+ function onexitreferencestring(token) {
865
+ const label = this.resume();
866
+ const node = this.stack[this.stack.length - 1];
867
+ // @ts-expect-error: stash this on the node, as it might become a reference
868
+ // later.
869
+ node.label = label;
870
+ // @ts-expect-error: same as above.
871
+ node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase();
872
+ this.data.referenceType = 'full';
873
+ }
874
+
875
+ /**
876
+ * @this {CompileContext}
877
+ * @type {Handle}
878
+ */
879
+
880
+ function onexitcharacterreferencemarker(token) {
881
+ this.data.characterReferenceType = token.type;
882
+ }
883
+
884
+ /**
885
+ * @this {CompileContext}
886
+ * @type {Handle}
887
+ */
888
+ function onexitcharacterreferencevalue(token) {
889
+ const data = this.sliceSerialize(token);
890
+ const type = this.data.characterReferenceType;
891
+ /** @type {string} */
892
+ let value;
893
+ if (type) {
894
+ value = decodeNumericCharacterReference(data, type === "characterReferenceMarkerNumeric" ? 10 : 16);
895
+ this.data.characterReferenceType = undefined;
896
+ } else {
897
+ const result = decodeNamedCharacterReference(data);
898
+ value = result;
899
+ }
900
+ const tail = this.stack[this.stack.length - 1];
901
+ tail.value += value;
902
+ }
903
+
904
+ /**
905
+ * @this {CompileContext}
906
+ * @type {Handle}
907
+ */
908
+ function onexitcharacterreference(token) {
909
+ const tail = this.stack.pop();
910
+ tail.position.end = point(token.end);
911
+ }
912
+
913
+ /**
914
+ * @this {CompileContext}
915
+ * @type {Handle}
916
+ */
917
+ function onexitautolinkprotocol(token) {
918
+ onexitdata.call(this, token);
919
+ const node = this.stack[this.stack.length - 1];
920
+ node.url = this.sliceSerialize(token);
921
+ }
922
+
923
+ /**
924
+ * @this {CompileContext}
925
+ * @type {Handle}
926
+ */
927
+ function onexitautolinkemail(token) {
928
+ onexitdata.call(this, token);
929
+ const node = this.stack[this.stack.length - 1];
930
+ node.url = 'mailto:' + this.sliceSerialize(token);
931
+ }
932
+
933
+ //
934
+ // Creaters.
935
+ //
936
+
937
+ /** @returns {Blockquote} */
938
+ function blockQuote() {
939
+ return {
940
+ type: 'blockquote',
941
+ children: []
942
+ };
943
+ }
944
+
945
+ /** @returns {Code} */
946
+ function codeFlow() {
947
+ return {
948
+ type: 'code',
949
+ lang: null,
950
+ meta: null,
951
+ value: ''
952
+ };
953
+ }
954
+
955
+ /** @returns {InlineCode} */
956
+ function codeText() {
957
+ return {
958
+ type: 'inlineCode',
959
+ value: ''
960
+ };
961
+ }
962
+
963
+ /** @returns {Definition} */
964
+ function definition() {
965
+ return {
966
+ type: 'definition',
967
+ identifier: '',
968
+ label: null,
969
+ title: null,
970
+ url: ''
971
+ };
972
+ }
973
+
974
+ /** @returns {Emphasis} */
975
+ function emphasis() {
976
+ return {
977
+ type: 'emphasis',
978
+ children: []
979
+ };
980
+ }
981
+
982
+ /** @returns {Heading} */
983
+ function heading() {
984
+ return {
985
+ type: 'heading',
986
+ // @ts-expect-error `depth` will be set later.
987
+ depth: 0,
988
+ children: []
989
+ };
990
+ }
991
+
992
+ /** @returns {Break} */
993
+ function hardBreak() {
994
+ return {
995
+ type: 'break'
996
+ };
997
+ }
998
+
999
+ /** @returns {Html} */
1000
+ function html() {
1001
+ return {
1002
+ type: 'html',
1003
+ value: ''
1004
+ };
1005
+ }
1006
+
1007
+ /** @returns {Image} */
1008
+ function image() {
1009
+ return {
1010
+ type: 'image',
1011
+ title: null,
1012
+ url: '',
1013
+ alt: null
1014
+ };
1015
+ }
1016
+
1017
+ /** @returns {Link} */
1018
+ function link() {
1019
+ return {
1020
+ type: 'link',
1021
+ title: null,
1022
+ url: '',
1023
+ children: []
1024
+ };
1025
+ }
1026
+
1027
+ /**
1028
+ * @param {Token} token
1029
+ * @returns {List}
1030
+ */
1031
+ function list(token) {
1032
+ return {
1033
+ type: 'list',
1034
+ ordered: token.type === 'listOrdered',
1035
+ start: null,
1036
+ spread: token._spread,
1037
+ children: []
1038
+ };
1039
+ }
1040
+
1041
+ /**
1042
+ * @param {Token} token
1043
+ * @returns {ListItem}
1044
+ */
1045
+ function listItem(token) {
1046
+ return {
1047
+ type: 'listItem',
1048
+ spread: token._spread,
1049
+ checked: null,
1050
+ children: []
1051
+ };
1052
+ }
1053
+
1054
+ /** @returns {Paragraph} */
1055
+ function paragraph() {
1056
+ return {
1057
+ type: 'paragraph',
1058
+ children: []
1059
+ };
1060
+ }
1061
+
1062
+ /** @returns {Strong} */
1063
+ function strong() {
1064
+ return {
1065
+ type: 'strong',
1066
+ children: []
1067
+ };
1068
+ }
1069
+
1070
+ /** @returns {Text} */
1071
+ function text() {
1072
+ return {
1073
+ type: 'text',
1074
+ value: ''
1075
+ };
1076
+ }
1077
+
1078
+ /** @returns {ThematicBreak} */
1079
+ function thematicBreak() {
1080
+ return {
1081
+ type: 'thematicBreak'
1082
+ };
1083
+ }
1084
+ }
1085
+
1086
+ /**
1087
+ * Copy a point-like value.
1088
+ *
1089
+ * @param {Point} d
1090
+ * Point-like value.
1091
+ * @returns {Point}
1092
+ * unist point.
1093
+ */
1094
+ function point(d) {
1095
+ return {
1096
+ line: d.line,
1097
+ column: d.column,
1098
+ offset: d.offset
1099
+ };
1100
+ }
1101
+
1102
+ /**
1103
+ * @param {Config} combined
1104
+ * @param {Array<Array<Extension> | Extension>} extensions
1105
+ * @returns {undefined}
1106
+ */
1107
+ function configure(combined, extensions) {
1108
+ let index = -1;
1109
+ while (++index < extensions.length) {
1110
+ const value = extensions[index];
1111
+ if (Array.isArray(value)) {
1112
+ configure(combined, value);
1113
+ } else {
1114
+ extension(combined, value);
1115
+ }
1116
+ }
1117
+ }
1118
+
1119
+ /**
1120
+ * @param {Config} combined
1121
+ * @param {Extension} extension
1122
+ * @returns {undefined}
1123
+ */
1124
+ function extension(combined, extension) {
1125
+ /** @type {keyof Extension} */
1126
+ let key;
1127
+ for (key in extension) {
1128
+ if (own.call(extension, key)) {
1129
+ switch (key) {
1130
+ case 'canContainEols':
1131
+ {
1132
+ const right = extension[key];
1133
+ if (right) {
1134
+ combined[key].push(...right);
1135
+ }
1136
+ break;
1137
+ }
1138
+ case 'transforms':
1139
+ {
1140
+ const right = extension[key];
1141
+ if (right) {
1142
+ combined[key].push(...right);
1143
+ }
1144
+ break;
1145
+ }
1146
+ case 'enter':
1147
+ case 'exit':
1148
+ {
1149
+ const right = extension[key];
1150
+ if (right) {
1151
+ Object.assign(combined[key], right);
1152
+ }
1153
+ break;
1154
+ }
1155
+ // No default
1156
+ }
1157
+ }
1158
+ }
1159
+ }
1160
+
1161
+ /** @type {OnEnterError} */
1162
+ function defaultOnError(left, right) {
1163
+ if (left) {
1164
+ throw new Error('Cannot close `' + left.type + '` (' + stringifyPosition({
1165
+ start: left.start,
1166
+ end: left.end
1167
+ }) + '): a different token (`' + right.type + '`, ' + stringifyPosition({
1168
+ start: right.start,
1169
+ end: right.end
1170
+ }) + ') is open');
1171
+ } else {
1172
+ throw new Error('Cannot close document, a token (`' + right.type + '`, ' + stringifyPosition({
1173
+ start: right.start,
1174
+ end: right.end
1175
+ }) + ') is still open');
1176
+ }
1177
+ }
node_modules/mdast-util-from-markdown/lib/types.d.ts ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type {Nodes, Parent, PhrasingContent, Root} from 'mdast'
2
+ import type {ParseOptions, Token} from 'micromark-util-types'
3
+
4
+ /**
5
+ * Compiler context.
6
+ */
7
+ export interface CompileContext {
8
+ /**
9
+ * Configuration.
10
+ */
11
+ config: Config
12
+ /**
13
+ * Info passed around;
14
+ * key/value store.
15
+ */
16
+ data: CompileData
17
+ /**
18
+ * Stack of nodes.
19
+ */
20
+ stack: Array<Fragment | Nodes>
21
+ /**
22
+ * Stack of tokens.
23
+ */
24
+ tokenStack: Array<TokenTuple>
25
+
26
+ /**
27
+ * Capture some of the output data.
28
+ *
29
+ * @param this
30
+ * Context.
31
+ * @returns
32
+ * Nothing.
33
+ */
34
+ buffer(this: CompileContext): undefined
35
+
36
+ /**
37
+ * Enter a node.
38
+ *
39
+ * @param this
40
+ * Context.
41
+ * @param node
42
+ * Node.
43
+ * @param token
44
+ * Token.
45
+ * @param onError
46
+ * Error handler.
47
+ * @returns
48
+ * Nothing.
49
+ */
50
+ enter(
51
+ this: CompileContext,
52
+ node: Nodes,
53
+ token: Token,
54
+ onError?: OnEnterError | null | undefined
55
+ ): undefined
56
+
57
+ /**
58
+ * Exit a node.
59
+ *
60
+ * @param this
61
+ * Context.
62
+ * @param token
63
+ * Token.
64
+ * @param onError
65
+ * Error handler.
66
+ * @returns
67
+ * Nothing.
68
+ */
69
+ exit(
70
+ this: CompileContext,
71
+ token: Token,
72
+ onError?: OnExitError | null | undefined
73
+ ): undefined
74
+
75
+ /**
76
+ * Stop capturing and access the output data.
77
+ *
78
+ * @param this
79
+ * Context.
80
+ * @returns
81
+ * Nothing.
82
+ */
83
+ resume(this: CompileContext): string
84
+
85
+ /**
86
+ * Get the source text that spans a token (or location).
87
+ *
88
+ * @param token
89
+ * Start/end in stream.
90
+ * @param expandTabs
91
+ * Whether to expand tabs.
92
+ * @returns
93
+ * Serialized chunks.
94
+ */
95
+ sliceSerialize(
96
+ token: Pick<Token, 'end' | 'start'>,
97
+ expandTabs?: boolean | undefined
98
+ ): string
99
+ }
100
+
101
+ /**
102
+ * Interface of tracked data.
103
+ *
104
+ * When working on extensions that use more data, extend the corresponding
105
+ * interface to register their types:
106
+ *
107
+ * ```ts
108
+ * declare module 'mdast-util-from-markdown' {
109
+ * interface CompileData {
110
+ * // Register a new field.
111
+ * mathFlowInside?: boolean | undefined
112
+ * }
113
+ * }
114
+ * ```
115
+ */
116
+ export interface CompileData {
117
+ /**
118
+ * Whether we’re inside a hard break.
119
+ */
120
+ atHardBreak?: boolean | undefined
121
+
122
+ /**
123
+ * Current character reference type.
124
+ */
125
+ characterReferenceType?:
126
+ | 'characterReferenceMarkerHexadecimal'
127
+ | 'characterReferenceMarkerNumeric'
128
+ | undefined
129
+
130
+ /**
131
+ * Whether a first list item value (`1` in `1. a`) is expected.
132
+ */
133
+ expectingFirstListItemValue?: boolean | undefined
134
+
135
+ /**
136
+ * Whether we’re in flow code.
137
+ */
138
+ flowCodeInside?: boolean | undefined
139
+
140
+ /**
141
+ * Whether we’re in a reference.
142
+ */
143
+ inReference?: boolean | undefined
144
+
145
+ /**
146
+ * Whether we’re expecting a line ending from a setext heading, which can be slurped.
147
+ */
148
+ setextHeadingSlurpLineEnding?: boolean | undefined
149
+
150
+ /**
151
+ * Current reference.
152
+ */
153
+ referenceType?: 'collapsed' | 'full' | undefined
154
+ }
155
+
156
+ /**
157
+ * Configuration.
158
+ *
159
+ * We have our defaults, but extensions will add more.
160
+ */
161
+ export interface Config {
162
+ /**
163
+ * Token types where line endings are used.
164
+ */
165
+ canContainEols: Array<string>
166
+ /**
167
+ * Opening handles.
168
+ */
169
+ enter: Handles
170
+ /**
171
+ * Closing handles.
172
+ */
173
+ exit: Handles
174
+ /**
175
+ * Tree transforms.
176
+ */
177
+ transforms: Array<Transform>
178
+ }
179
+
180
+ /**
181
+ * Change how markdown tokens from micromark are turned into mdast.
182
+ */
183
+ export interface Extension {
184
+ /**
185
+ * Token types where line endings are used.
186
+ */
187
+ canContainEols?: Array<string> | null | undefined
188
+ /**
189
+ * Opening handles.
190
+ */
191
+ enter?: Handles | null | undefined
192
+ /**
193
+ * Closing handles.
194
+ */
195
+ exit?: Handles | null | undefined
196
+ /**
197
+ * Tree transforms.
198
+ */
199
+ transforms?: Array<Transform> | null | undefined
200
+ }
201
+
202
+ /**
203
+ * Internal fragment.
204
+ */
205
+ export interface Fragment extends Parent {
206
+ /**
207
+ * Node type.
208
+ */
209
+ type: 'fragment'
210
+ /**
211
+ * Children.
212
+ */
213
+ children: Array<PhrasingContent>
214
+ }
215
+
216
+ /**
217
+ * Token types mapping to handles
218
+ */
219
+ export type Handles = Record<string, Handle>
220
+
221
+ /**
222
+ * Handle a token.
223
+ *
224
+ * @param this
225
+ * Context.
226
+ * @param token
227
+ * Current token.
228
+ * @returns
229
+ * Nothing.
230
+ */
231
+ export type Handle = (this: CompileContext, token: Token) => undefined | void
232
+
233
+ /**
234
+ * Handle the case where the `right` token is open, but it is closed (by the
235
+ * `left` token) or because we reached the end of the document.
236
+ *
237
+ * @param this
238
+ * Context.
239
+ * @param left
240
+ * Left token.
241
+ * @param right
242
+ * Right token.
243
+ * @returns
244
+ * Nothing.
245
+ */
246
+ export type OnEnterError = (
247
+ this: Omit<CompileContext, 'sliceSerialize'>,
248
+ left: Token | undefined,
249
+ right: Token
250
+ ) => undefined
251
+
252
+ /**
253
+ * Handle the case where the `right` token is open but it is closed by
254
+ * exiting the `left` token.
255
+ *
256
+ * @param this
257
+ * Context.
258
+ * @param left
259
+ * Left token.
260
+ * @param right
261
+ * Right token.
262
+ * @returns
263
+ * Nothing.
264
+ */
265
+ export type OnExitError = (
266
+ this: Omit<CompileContext, 'sliceSerialize'>,
267
+ left: Token,
268
+ right: Token
269
+ ) => undefined
270
+
271
+ /**
272
+ * Configuration.
273
+ */
274
+ export interface Options extends ParseOptions {
275
+ /**
276
+ * Extensions for this utility to change how tokens are turned into a tree.
277
+ */
278
+ mdastExtensions?: Array<Extension | Array<Extension>> | null | undefined
279
+ }
280
+
281
+ /**
282
+ * Open token on the stack,
283
+ * with an optional error handler for when that token isn’t closed properly.
284
+ */
285
+ export type TokenTuple = [token: Token, onError: OnEnterError | undefined]
286
+
287
+ /**
288
+ * Extra transform, to change the AST afterwards.
289
+ *
290
+ * @param tree
291
+ * Tree to transform.
292
+ * @returns
293
+ * New tree or nothing (in which case the current tree is used).
294
+ */
295
+ export type Transform = (tree: Root) => Root | null | undefined | void
node_modules/mdast-util-from-markdown/lib/types.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ // Note: types exposed from `types.d.ts`.
2
+ export {};
node_modules/mdast-util-from-markdown/license ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (The MIT License)
2
+
3
+ Copyright (c) Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.