diff --git a/node_modules/math-intrinsics/constants/maxValue.js b/node_modules/math-intrinsics/constants/maxValue.js new file mode 100644 index 0000000000000000000000000000000000000000..a2202dc39767adad11f1df67b2ffabba8aaf9cbd --- /dev/null +++ b/node_modules/math-intrinsics/constants/maxValue.js @@ -0,0 +1,5 @@ +'use strict'; + +/** @type {import('./maxValue')} */ +// eslint-disable-next-line no-extra-parens +module.exports = /** @type {import('./maxValue')} */ (Number.MAX_VALUE) || 1.7976931348623157e+308; diff --git a/node_modules/math-intrinsics/floor.d.ts b/node_modules/math-intrinsics/floor.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..9265236f288b7da2345b73a3bc290a6385d2b356 --- /dev/null +++ b/node_modules/math-intrinsics/floor.d.ts @@ -0,0 +1 @@ +export = Math.floor; \ No newline at end of file diff --git a/node_modules/math-intrinsics/floor.js b/node_modules/math-intrinsics/floor.js new file mode 100644 index 0000000000000000000000000000000000000000..ab0e5d7dcd43056d5d5288de0d08ca4177efb2db --- /dev/null +++ b/node_modules/math-intrinsics/floor.js @@ -0,0 +1,4 @@ +'use strict'; + +/** @type {import('./floor')} */ +module.exports = Math.floor; diff --git a/node_modules/math-intrinsics/isFinite.d.ts b/node_modules/math-intrinsics/isFinite.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6daae331f18e427d1057c96c8ca75d6c6c3fd211 --- /dev/null +++ b/node_modules/math-intrinsics/isFinite.d.ts @@ -0,0 +1,3 @@ +declare function isFinite(x: unknown): x is number | bigint; + +export = isFinite; \ No newline at end of file diff --git a/node_modules/math-intrinsics/isFinite.js b/node_modules/math-intrinsics/isFinite.js new file mode 100644 index 0000000000000000000000000000000000000000..b201a5a523ed18bde69edd3b3deff3b63c463120 --- /dev/null +++ b/node_modules/math-intrinsics/isFinite.js @@ -0,0 +1,12 @@ +'use strict'; + +var $isNaN = require('./isNaN'); + +/** @type {import('./isFinite')} */ +module.exports = function isFinite(x) { + return (typeof x === 'number' || typeof x === 'bigint') + && !$isNaN(x) + && x !== Infinity + && x !== -Infinity; +}; + diff --git a/node_modules/math-intrinsics/isInteger.d.ts b/node_modules/math-intrinsics/isInteger.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..13935a8ccf78a105bc508e4c8f88b9888f57f1b1 --- /dev/null +++ b/node_modules/math-intrinsics/isInteger.d.ts @@ -0,0 +1,3 @@ +declare function isInteger(argument: unknown): argument is number; + +export = isInteger; \ No newline at end of file diff --git a/node_modules/math-intrinsics/isInteger.js b/node_modules/math-intrinsics/isInteger.js new file mode 100644 index 0000000000000000000000000000000000000000..4b1b9a56d1bba183cc75a616ece707489901d4a8 --- /dev/null +++ b/node_modules/math-intrinsics/isInteger.js @@ -0,0 +1,16 @@ +'use strict'; + +var $abs = require('./abs'); +var $floor = require('./floor'); + +var $isNaN = require('./isNaN'); +var $isFinite = require('./isFinite'); + +/** @type {import('./isInteger')} */ +module.exports = function isInteger(argument) { + if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) { + return false; + } + var absValue = $abs(argument); + return $floor(absValue) === absValue; +}; diff --git a/node_modules/math-intrinsics/isNaN.d.ts b/node_modules/math-intrinsics/isNaN.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c1d4c552456bde706a914f901e9ccd523ac44e7d --- /dev/null +++ b/node_modules/math-intrinsics/isNaN.d.ts @@ -0,0 +1 @@ +export = Number.isNaN; \ No newline at end of file diff --git a/node_modules/math-intrinsics/isNaN.js b/node_modules/math-intrinsics/isNaN.js new file mode 100644 index 0000000000000000000000000000000000000000..e36475cf878ca6beda4dfd1cd3881759b72270c6 --- /dev/null +++ b/node_modules/math-intrinsics/isNaN.js @@ -0,0 +1,6 @@ +'use strict'; + +/** @type {import('./isNaN')} */ +module.exports = Number.isNaN || function isNaN(a) { + return a !== a; +}; diff --git a/node_modules/math-intrinsics/isNegativeZero.d.ts b/node_modules/math-intrinsics/isNegativeZero.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7ad88193e1f3599ebce7e63ed97854895fe87f33 --- /dev/null +++ b/node_modules/math-intrinsics/isNegativeZero.d.ts @@ -0,0 +1,3 @@ +declare function isNegativeZero(x: unknown): boolean; + +export = isNegativeZero; \ No newline at end of file diff --git a/node_modules/math-intrinsics/isNegativeZero.js b/node_modules/math-intrinsics/isNegativeZero.js new file mode 100644 index 0000000000000000000000000000000000000000..b69adcc5a7f190f38c6907584432368e77d097d0 --- /dev/null +++ b/node_modules/math-intrinsics/isNegativeZero.js @@ -0,0 +1,6 @@ +'use strict'; + +/** @type {import('./isNegativeZero')} */ +module.exports = function isNegativeZero(x) { + return x === 0 && 1 / x === 1 / -0; +}; diff --git a/node_modules/math-intrinsics/max.d.ts b/node_modules/math-intrinsics/max.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad6f43e35f4a342bcac73ec92226b342f282097e --- /dev/null +++ b/node_modules/math-intrinsics/max.d.ts @@ -0,0 +1 @@ +export = Math.max; \ No newline at end of file diff --git a/node_modules/math-intrinsics/max.js b/node_modules/math-intrinsics/max.js new file mode 100644 index 0000000000000000000000000000000000000000..edb55dfbca86a881da139244122c4f734d6a5844 --- /dev/null +++ b/node_modules/math-intrinsics/max.js @@ -0,0 +1,4 @@ +'use strict'; + +/** @type {import('./max')} */ +module.exports = Math.max; diff --git a/node_modules/math-intrinsics/min.d.ts b/node_modules/math-intrinsics/min.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd90f2d504422b14fbe14393fabdc0fc0a8db6a0 --- /dev/null +++ b/node_modules/math-intrinsics/min.d.ts @@ -0,0 +1 @@ +export = Math.min; \ No newline at end of file diff --git a/node_modules/math-intrinsics/min.js b/node_modules/math-intrinsics/min.js new file mode 100644 index 0000000000000000000000000000000000000000..5a4a7c7149a79f113c536e08888acc70213674e8 --- /dev/null +++ b/node_modules/math-intrinsics/min.js @@ -0,0 +1,4 @@ +'use strict'; + +/** @type {import('./min')} */ +module.exports = Math.min; diff --git a/node_modules/math-intrinsics/mod.d.ts b/node_modules/math-intrinsics/mod.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..549dbd46e5a4c1df5f6d75e11e690d6dc8758421 --- /dev/null +++ b/node_modules/math-intrinsics/mod.d.ts @@ -0,0 +1,3 @@ +declare function mod(number: number, modulo: number): number; + +export = mod; \ No newline at end of file diff --git a/node_modules/math-intrinsics/mod.js b/node_modules/math-intrinsics/mod.js new file mode 100644 index 0000000000000000000000000000000000000000..4a98362baf165d9190ab6bc7b627daeaad6fac8c --- /dev/null +++ b/node_modules/math-intrinsics/mod.js @@ -0,0 +1,9 @@ +'use strict'; + +var $floor = require('./floor'); + +/** @type {import('./mod')} */ +module.exports = function mod(number, modulo) { + var remain = number % modulo; + return $floor(remain >= 0 ? remain : remain + modulo); +}; diff --git a/node_modules/math-intrinsics/package.json b/node_modules/math-intrinsics/package.json new file mode 100644 index 0000000000000000000000000000000000000000..067627354b768e180e286f8c2efdb0c35a188e52 --- /dev/null +++ b/node_modules/math-intrinsics/package.json @@ -0,0 +1,86 @@ +{ + "name": "math-intrinsics", + "version": "1.1.0", + "description": "ES Math-related intrinsics and helpers, robustly cached.", + "main": false, + "exports": { + "./abs": "./abs.js", + "./floor": "./floor.js", + "./isFinite": "./isFinite.js", + "./isInteger": "./isInteger.js", + "./isNaN": "./isNaN.js", + "./isNegativeZero": "./isNegativeZero.js", + "./max": "./max.js", + "./min": "./min.js", + "./mod": "./mod.js", + "./pow": "./pow.js", + "./sign": "./sign.js", + "./round": "./round.js", + "./constants/maxArrayLength": "./constants/maxArrayLength.js", + "./constants/maxSafeInteger": "./constants/maxSafeInteger.js", + "./constants/maxValue": "./constants/maxValue.js", + "./package.json": "./package.json" + }, + "sideEffects": false, + "scripts": { + "prepack": "npmignore --auto --commentLines=autogenerated", + "prepublishOnly": "safe-publish-latest", + "prepublish": "not-in-publish || npm run prepublishOnly", + "pretest": "npm run lint", + "test": "npm run tests-only", + "tests-only": "nyc tape 'test/**/*.js'", + "posttest": "npx npm@'>= 10.2' audit --production", + "prelint": "evalmd README.md && eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)", + "lint": "eslint --ext=js,mjs .", + "postlint": "tsc && attw -P", + "version": "auto-changelog && git add CHANGELOG.md", + "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/es-shims/math-intrinsics.git" + }, + "author": "Jordan Harband ", + "license": "MIT", + "bugs": { + "url": "https://github.com/es-shims/math-intrinsics/issues" + }, + "homepage": "https://github.com/es-shims/math-intrinsics#readme", + "devDependencies": { + "@arethetypeswrong/cli": "^0.17.1", + "@ljharb/eslint-config": "^21.1.1", + "@ljharb/tsconfig": "^0.2.2", + "@types/for-each": "^0.3.3", + "@types/object-inspect": "^1.13.0", + "@types/tape": "^5.8.0", + "auto-changelog": "^2.5.0", + "eclint": "^2.8.1", + "es-value-fixtures": "^1.5.0", + "eslint": "^8.8.0", + "evalmd": "^0.0.19", + "for-each": "^0.3.3", + "in-publish": "^2.0.1", + "npmignore": "^0.3.1", + "nyc": "^10.3.2", + "object-inspect": "^1.13.3", + "safe-publish-latest": "^2.0.0", + "tape": "^5.9.0", + "typescript": "next" + }, + "auto-changelog": { + "output": "CHANGELOG.md", + "template": "keepachangelog", + "unreleased": false, + "commitLimit": false, + "backfillLimit": false, + "hideCredit": true + }, + "publishConfig": { + "ignore": [ + ".github/workflows" + ] + }, + "engines": { + "node": ">= 0.4" + } +} diff --git a/node_modules/math-intrinsics/pow.d.ts b/node_modules/math-intrinsics/pow.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5873c441e62a88335b478b30de3c2a319b945520 --- /dev/null +++ b/node_modules/math-intrinsics/pow.d.ts @@ -0,0 +1 @@ +export = Math.pow; \ No newline at end of file diff --git a/node_modules/math-intrinsics/pow.js b/node_modules/math-intrinsics/pow.js new file mode 100644 index 0000000000000000000000000000000000000000..c0a4103811f69cdfefb43e1fd0a5a866da3c0cd9 --- /dev/null +++ b/node_modules/math-intrinsics/pow.js @@ -0,0 +1,4 @@ +'use strict'; + +/** @type {import('./pow')} */ +module.exports = Math.pow; diff --git a/node_modules/math-intrinsics/round.d.ts b/node_modules/math-intrinsics/round.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..da1fde3f638b9a9a3db026668427ae9cde5bbcb7 --- /dev/null +++ b/node_modules/math-intrinsics/round.d.ts @@ -0,0 +1 @@ +export = Math.round; \ No newline at end of file diff --git a/node_modules/math-intrinsics/round.js b/node_modules/math-intrinsics/round.js new file mode 100644 index 0000000000000000000000000000000000000000..b79215663a657631fd01aef3d95dbffac635b707 --- /dev/null +++ b/node_modules/math-intrinsics/round.js @@ -0,0 +1,4 @@ +'use strict'; + +/** @type {import('./round')} */ +module.exports = Math.round; diff --git a/node_modules/math-intrinsics/sign.d.ts b/node_modules/math-intrinsics/sign.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c49cecaa240c415345f455f2e4fbed99015c1713 --- /dev/null +++ b/node_modules/math-intrinsics/sign.d.ts @@ -0,0 +1,3 @@ +declare function sign(x: number): number; + +export = sign; \ No newline at end of file diff --git a/node_modules/math-intrinsics/sign.js b/node_modules/math-intrinsics/sign.js new file mode 100644 index 0000000000000000000000000000000000000000..9e5173c80da67de620a9b3a769936d77bf68ba73 --- /dev/null +++ b/node_modules/math-intrinsics/sign.js @@ -0,0 +1,11 @@ +'use strict'; + +var $isNaN = require('./isNaN'); + +/** @type {import('./sign')} */ +module.exports = function sign(number) { + if ($isNaN(number) || number === 0) { + return number; + } + return number < 0 ? -1 : +1; +}; diff --git a/node_modules/math-intrinsics/test/index.js b/node_modules/math-intrinsics/test/index.js new file mode 100644 index 0000000000000000000000000000000000000000..0f90a5dc0f5f107d65a4b8d3f79711b8b1d5a6f7 --- /dev/null +++ b/node_modules/math-intrinsics/test/index.js @@ -0,0 +1,192 @@ +'use strict'; + +var test = require('tape'); +var v = require('es-value-fixtures'); +var forEach = require('for-each'); +var inspect = require('object-inspect'); + +var abs = require('../abs'); +var floor = require('../floor'); +var isFinite = require('../isFinite'); +var isInteger = require('../isInteger'); +var isNaN = require('../isNaN'); +var isNegativeZero = require('../isNegativeZero'); +var max = require('../max'); +var min = require('../min'); +var mod = require('../mod'); +var pow = require('../pow'); +var round = require('../round'); +var sign = require('../sign'); + +var maxArrayLength = require('../constants/maxArrayLength'); +var maxSafeInteger = require('../constants/maxSafeInteger'); +var maxValue = require('../constants/maxValue'); + +test('abs', function (t) { + t.equal(abs(-1), 1, 'abs(-1) === 1'); + t.equal(abs(+1), 1, 'abs(+1) === 1'); + t.equal(abs(+0), +0, 'abs(+0) === +0'); + t.equal(abs(-0), +0, 'abs(-0) === +0'); + + t.end(); +}); + +test('floor', function (t) { + t.equal(floor(-1.1), -2, 'floor(-1.1) === -2'); + t.equal(floor(+1.1), 1, 'floor(+1.1) === 1'); + t.equal(floor(+0), +0, 'floor(+0) === +0'); + t.equal(floor(-0), -0, 'floor(-0) === -0'); + t.equal(floor(-Infinity), -Infinity, 'floor(-Infinity) === -Infinity'); + t.equal(floor(Number(Infinity)), Number(Infinity), 'floor(+Infinity) === +Infinity'); + t.equal(floor(NaN), NaN, 'floor(NaN) === NaN'); + t.equal(floor(0), +0, 'floor(0) === +0'); + t.equal(floor(-0), -0, 'floor(-0) === -0'); + t.equal(floor(1), 1, 'floor(1) === 1'); + t.equal(floor(-1), -1, 'floor(-1) === -1'); + t.equal(floor(1.1), 1, 'floor(1.1) === 1'); + t.equal(floor(-1.1), -2, 'floor(-1.1) === -2'); + t.equal(floor(maxValue), maxValue, 'floor(maxValue) === maxValue'); + t.equal(floor(maxSafeInteger), maxSafeInteger, 'floor(maxSafeInteger) === maxSafeInteger'); + + t.end(); +}); + +test('isFinite', function (t) { + t.equal(isFinite(0), true, 'isFinite(+0) === true'); + t.equal(isFinite(-0), true, 'isFinite(-0) === true'); + t.equal(isFinite(1), true, 'isFinite(1) === true'); + t.equal(isFinite(Infinity), false, 'isFinite(Infinity) === false'); + t.equal(isFinite(-Infinity), false, 'isFinite(-Infinity) === false'); + t.equal(isFinite(NaN), false, 'isFinite(NaN) === false'); + + forEach(v.nonNumbers, function (nonNumber) { + t.equal(isFinite(nonNumber), false, 'isFinite(' + inspect(nonNumber) + ') === false'); + }); + + t.end(); +}); + +test('isInteger', function (t) { + forEach([].concat( + // @ts-expect-error TS sucks with concat + v.nonNumbers, + v.nonIntegerNumbers + ), function (nonInteger) { + t.equal(isInteger(nonInteger), false, 'isInteger(' + inspect(nonInteger) + ') === false'); + }); + + t.end(); +}); + +test('isNaN', function (t) { + forEach([].concat( + // @ts-expect-error TS sucks with concat + v.nonNumbers, + v.infinities, + v.zeroes, + v.integerNumbers + ), function (nonNaN) { + t.equal(isNaN(nonNaN), false, 'isNaN(' + inspect(nonNaN) + ') === false'); + }); + + t.equal(isNaN(NaN), true, 'isNaN(NaN) === true'); + + t.end(); +}); + +test('isNegativeZero', function (t) { + t.equal(isNegativeZero(-0), true, 'isNegativeZero(-0) === true'); + t.equal(isNegativeZero(+0), false, 'isNegativeZero(+0) === false'); + t.equal(isNegativeZero(1), false, 'isNegativeZero(1) === false'); + t.equal(isNegativeZero(-1), false, 'isNegativeZero(-1) === false'); + t.equal(isNegativeZero(NaN), false, 'isNegativeZero(NaN) === false'); + t.equal(isNegativeZero(Infinity), false, 'isNegativeZero(Infinity) === false'); + t.equal(isNegativeZero(-Infinity), false, 'isNegativeZero(-Infinity) === false'); + + forEach(v.nonNumbers, function (nonNumber) { + t.equal(isNegativeZero(nonNumber), false, 'isNegativeZero(' + inspect(nonNumber) + ') === false'); + }); + + t.end(); +}); + +test('max', function (t) { + t.equal(max(1, 2), 2, 'max(1, 2) === 2'); + t.equal(max(1, 2, 3), 3, 'max(1, 2, 3) === 3'); + t.equal(max(1, 2, 3, 4), 4, 'max(1, 2, 3, 4) === 4'); + t.equal(max(1, 2, 3, 4, 5), 5, 'max(1, 2, 3, 4, 5) === 5'); + t.equal(max(1, 2, 3, 4, 5, 6), 6, 'max(1, 2, 3, 4, 5, 6) === 6'); + t.equal(max(1, 2, 3, 4, 5, 6, 7), 7, 'max(1, 2, 3, 4, 5, 6, 7) === 7'); + + t.end(); +}); + +test('min', function (t) { + t.equal(min(1, 2), 1, 'min(1, 2) === 1'); + t.equal(min(1, 2, 3), 1, 'min(1, 2, 3) === 1'); + t.equal(min(1, 2, 3, 4), 1, 'min(1, 2, 3, 4) === 1'); + t.equal(min(1, 2, 3, 4, 5), 1, 'min(1, 2, 3, 4, 5) === 1'); + t.equal(min(1, 2, 3, 4, 5, 6), 1, 'min(1, 2, 3, 4, 5, 6) === 1'); + + t.end(); +}); + +test('mod', function (t) { + t.equal(mod(1, 2), 1, 'mod(1, 2) === 1'); + t.equal(mod(2, 2), 0, 'mod(2, 2) === 0'); + t.equal(mod(3, 2), 1, 'mod(3, 2) === 1'); + t.equal(mod(4, 2), 0, 'mod(4, 2) === 0'); + t.equal(mod(5, 2), 1, 'mod(5, 2) === 1'); + t.equal(mod(6, 2), 0, 'mod(6, 2) === 0'); + t.equal(mod(7, 2), 1, 'mod(7, 2) === 1'); + t.equal(mod(8, 2), 0, 'mod(8, 2) === 0'); + t.equal(mod(9, 2), 1, 'mod(9, 2) === 1'); + t.equal(mod(10, 2), 0, 'mod(10, 2) === 0'); + t.equal(mod(11, 2), 1, 'mod(11, 2) === 1'); + + t.end(); +}); + +test('pow', function (t) { + t.equal(pow(2, 2), 4, 'pow(2, 2) === 4'); + t.equal(pow(2, 3), 8, 'pow(2, 3) === 8'); + t.equal(pow(2, 4), 16, 'pow(2, 4) === 16'); + t.equal(pow(2, 5), 32, 'pow(2, 5) === 32'); + t.equal(pow(2, 6), 64, 'pow(2, 6) === 64'); + t.equal(pow(2, 7), 128, 'pow(2, 7) === 128'); + t.equal(pow(2, 8), 256, 'pow(2, 8) === 256'); + t.equal(pow(2, 9), 512, 'pow(2, 9) === 512'); + t.equal(pow(2, 10), 1024, 'pow(2, 10) === 1024'); + + t.end(); +}); + +test('round', function (t) { + t.equal(round(1.1), 1, 'round(1.1) === 1'); + t.equal(round(1.5), 2, 'round(1.5) === 2'); + t.equal(round(1.9), 2, 'round(1.9) === 2'); + + t.end(); +}); + +test('sign', function (t) { + t.equal(sign(-1), -1, 'sign(-1) === -1'); + t.equal(sign(+1), +1, 'sign(+1) === +1'); + t.equal(sign(+0), +0, 'sign(+0) === +0'); + t.equal(sign(-0), -0, 'sign(-0) === -0'); + t.equal(sign(NaN), NaN, 'sign(NaN) === NaN'); + t.equal(sign(Infinity), +1, 'sign(Infinity) === +1'); + t.equal(sign(-Infinity), -1, 'sign(-Infinity) === -1'); + t.equal(sign(maxValue), +1, 'sign(maxValue) === +1'); + t.equal(sign(maxSafeInteger), +1, 'sign(maxSafeInteger) === +1'); + + t.end(); +}); + +test('constants', function (t) { + t.equal(typeof maxArrayLength, 'number', 'typeof maxArrayLength === "number"'); + t.equal(typeof maxSafeInteger, 'number', 'typeof maxSafeInteger === "number"'); + t.equal(typeof maxValue, 'number', 'typeof maxValue === "number"'); + + t.end(); +}); diff --git a/node_modules/math-intrinsics/tsconfig.json b/node_modules/math-intrinsics/tsconfig.json new file mode 100644 index 0000000000000000000000000000000000000000..b131000796f0cb804c38b121021940cd962cc1a7 --- /dev/null +++ b/node_modules/math-intrinsics/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@ljharb/tsconfig", +} diff --git a/node_modules/mdast-util-find-and-replace/index.d.ts b/node_modules/mdast-util-find-and-replace/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..cc25ad44c315a932728b1c434ca6c78254d1c83d --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/index.d.ts @@ -0,0 +1,9 @@ +export { findAndReplace } from "./lib/index.js"; +export type FindAndReplaceList = import("./lib/index.js").FindAndReplaceList; +export type FindAndReplaceTuple = import("./lib/index.js").FindAndReplaceTuple; +export type Find = import("./lib/index.js").Find; +export type Options = import("./lib/index.js").Options; +export type RegExpMatchObject = import("./lib/index.js").RegExpMatchObject; +export type ReplaceFunction = import("./lib/index.js").ReplaceFunction; +export type Replace = import("./lib/index.js").Replace; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-find-and-replace/index.d.ts.map b/node_modules/mdast-util-find-and-replace/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..ca6bcb73404aaa15b9df391b9ee6cd25577ecba1 --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/index.d.ts.map @@ -0,0 +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"} \ No newline at end of file diff --git a/node_modules/mdast-util-find-and-replace/index.js b/node_modules/mdast-util-find-and-replace/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6273f921adb46114bc5b5b8f8323fc97afad3397 --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/index.js @@ -0,0 +1,11 @@ +/** + * @typedef {import('./lib/index.js').FindAndReplaceList} FindAndReplaceList + * @typedef {import('./lib/index.js').FindAndReplaceTuple} FindAndReplaceTuple + * @typedef {import('./lib/index.js').Find} Find + * @typedef {import('./lib/index.js').Options} Options + * @typedef {import('./lib/index.js').RegExpMatchObject} RegExpMatchObject + * @typedef {import('./lib/index.js').ReplaceFunction} ReplaceFunction + * @typedef {import('./lib/index.js').Replace} Replace + */ + +export {findAndReplace} from './lib/index.js' diff --git a/node_modules/mdast-util-find-and-replace/lib/index.d.ts b/node_modules/mdast-util-find-and-replace/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3ad560c2fabd9fe8189073c7d3bf4bb214b52947 --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/lib/index.d.ts @@ -0,0 +1,79 @@ +/** + * Find patterns in a tree and replace them. + * + * The algorithm searches the tree in *preorder* for complete values in `Text` + * nodes. + * Partial matches are not supported. + * + * @param {Nodes} tree + * Tree to change. + * @param {FindAndReplaceList | FindAndReplaceTuple} list + * Patterns to find. + * @param {Options | null | undefined} [options] + * Configuration (when `find` is not `Find`). + * @returns {undefined} + * Nothing. + */ +export function findAndReplace(tree: Nodes, list: FindAndReplaceList | FindAndReplaceTuple, options?: Options | null | undefined): undefined; +/** + * Info on the match. + */ +export type RegExpMatchObject = { + /** + * The index of the search at which the result was found. + */ + index: number; + /** + * A copy of the search string in the text node. + */ + input: string; + /** + * All ancestors of the text node, where the last node is the text itself. + */ + stack: [...Array, Text]; +}; +/** + * Pattern to find. + * + * Strings are escaped and then turned into global expressions. + */ +export type Find = RegExp | string; +/** + * Several find and replaces, in array form. + */ +export type FindAndReplaceList = Array; +/** + * Find and replace in tuple form. + */ +export type FindAndReplaceTuple = [Find, Replace?]; +/** + * Thing to replace with. + */ +export type Replace = ReplaceFunction | string | null | undefined; +/** + * Callback called when a search matches. + */ +export type ReplaceFunction = (...parameters: any[]) => Array | PhrasingContent | string | false | null | undefined; +/** + * Normalized find and replace. + */ +export type Pair = [RegExp, ReplaceFunction]; +/** + * All find and replaced. + */ +export type Pairs = Array; +/** + * Configuration. + */ +export type Options = { + /** + * Test for which nodes to ignore (optional). + */ + ignore?: Test | null | undefined; +}; +import type { Nodes } from 'mdast'; +import type { Parents } from 'mdast'; +import type { Text } from 'mdast'; +import type { PhrasingContent } from 'mdast'; +import type { Test } from 'unist-util-visit-parents'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-find-and-replace/lib/index.d.ts.map b/node_modules/mdast-util-find-and-replace/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..7112cb3f49a25a676dd8f5088a2f2bb96e7047cf --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/lib/index.d.ts.map @@ -0,0 +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"} \ No newline at end of file diff --git a/node_modules/mdast-util-find-and-replace/lib/index.js b/node_modules/mdast-util-find-and-replace/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..af84ba60dd09bee196f7271555bd5ea70e870cf6 --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/lib/index.js @@ -0,0 +1,261 @@ +/** + * @import {Nodes, Parents, PhrasingContent, Root, Text} from 'mdast' + * @import {BuildVisitor, Test, VisitorResult} from 'unist-util-visit-parents' + */ + +/** + * @typedef RegExpMatchObject + * Info on the match. + * @property {number} index + * The index of the search at which the result was found. + * @property {string} input + * A copy of the search string in the text node. + * @property {[...Array, Text]} stack + * All ancestors of the text node, where the last node is the text itself. + * + * @typedef {RegExp | string} Find + * Pattern to find. + * + * Strings are escaped and then turned into global expressions. + * + * @typedef {Array} FindAndReplaceList + * Several find and replaces, in array form. + * + * @typedef {[Find, Replace?]} FindAndReplaceTuple + * Find and replace in tuple form. + * + * @typedef {ReplaceFunction | string | null | undefined} Replace + * Thing to replace with. + * + * @callback ReplaceFunction + * Callback called when a search matches. + * @param {...any} parameters + * The parameters are the result of corresponding search expression: + * + * * `value` (`string`) — whole match + * * `...capture` (`Array`) — matches from regex capture groups + * * `match` (`RegExpMatchObject`) — info on the match + * @returns {Array | PhrasingContent | string | false | null | undefined} + * Thing to replace with. + * + * * when `null`, `undefined`, `''`, remove the match + * * …or when `false`, do not replace at all + * * …or when `string`, replace with a text node of that value + * * …or when `Node` or `Array`, replace with those nodes + * + * @typedef {[RegExp, ReplaceFunction]} Pair + * Normalized find and replace. + * + * @typedef {Array} Pairs + * All find and replaced. + * + * @typedef Options + * Configuration. + * @property {Test | null | undefined} [ignore] + * Test for which nodes to ignore (optional). + */ + +import escape from 'escape-string-regexp' +import {visitParents} from 'unist-util-visit-parents' +import {convert} from 'unist-util-is' + +/** + * Find patterns in a tree and replace them. + * + * The algorithm searches the tree in *preorder* for complete values in `Text` + * nodes. + * Partial matches are not supported. + * + * @param {Nodes} tree + * Tree to change. + * @param {FindAndReplaceList | FindAndReplaceTuple} list + * Patterns to find. + * @param {Options | null | undefined} [options] + * Configuration (when `find` is not `Find`). + * @returns {undefined} + * Nothing. + */ +export function findAndReplace(tree, list, options) { + const settings = options || {} + const ignored = convert(settings.ignore || []) + const pairs = toPairs(list) + let pairIndex = -1 + + while (++pairIndex < pairs.length) { + visitParents(tree, 'text', visitor) + } + + /** @type {BuildVisitor} */ + function visitor(node, parents) { + let index = -1 + /** @type {Parents | undefined} */ + let grandparent + + while (++index < parents.length) { + const parent = parents[index] + /** @type {Array | undefined} */ + const siblings = grandparent ? grandparent.children : undefined + + if ( + ignored( + parent, + siblings ? siblings.indexOf(parent) : undefined, + grandparent + ) + ) { + return + } + + grandparent = parent + } + + if (grandparent) { + return handler(node, parents) + } + } + + /** + * Handle a text node which is not in an ignored parent. + * + * @param {Text} node + * Text node. + * @param {Array} parents + * Parents. + * @returns {VisitorResult} + * Result. + */ + function handler(node, parents) { + const parent = parents[parents.length - 1] + const find = pairs[pairIndex][0] + const replace = pairs[pairIndex][1] + let start = 0 + /** @type {Array} */ + const siblings = parent.children + const index = siblings.indexOf(node) + let change = false + /** @type {Array} */ + let nodes = [] + + find.lastIndex = 0 + + let match = find.exec(node.value) + + while (match) { + const position = match.index + /** @type {RegExpMatchObject} */ + const matchObject = { + index: match.index, + input: match.input, + stack: [...parents, node] + } + let value = replace(...match, matchObject) + + if (typeof value === 'string') { + value = value.length > 0 ? {type: 'text', value} : undefined + } + + // It wasn’t a match after all. + if (value === false) { + // False acts as if there was no match. + // So we need to reset `lastIndex`, which currently being at the end of + // the current match, to the beginning. + find.lastIndex = position + 1 + } else { + if (start !== position) { + nodes.push({ + type: 'text', + value: node.value.slice(start, position) + }) + } + + if (Array.isArray(value)) { + nodes.push(...value) + } else if (value) { + nodes.push(value) + } + + start = position + match[0].length + change = true + } + + if (!find.global) { + break + } + + match = find.exec(node.value) + } + + if (change) { + if (start < node.value.length) { + nodes.push({type: 'text', value: node.value.slice(start)}) + } + + parent.children.splice(index, 1, ...nodes) + } else { + nodes = [node] + } + + return index + nodes.length + } +} + +/** + * Turn a tuple or a list of tuples into pairs. + * + * @param {FindAndReplaceList | FindAndReplaceTuple} tupleOrList + * Schema. + * @returns {Pairs} + * Clean pairs. + */ +function toPairs(tupleOrList) { + /** @type {Pairs} */ + const result = [] + + if (!Array.isArray(tupleOrList)) { + throw new TypeError('Expected find and replace tuple or list of tuples') + } + + /** @type {FindAndReplaceList} */ + // @ts-expect-error: correct. + const list = + !tupleOrList[0] || Array.isArray(tupleOrList[0]) + ? tupleOrList + : [tupleOrList] + + let index = -1 + + while (++index < list.length) { + const tuple = list[index] + result.push([toExpression(tuple[0]), toFunction(tuple[1])]) + } + + return result +} + +/** + * Turn a find into an expression. + * + * @param {Find} find + * Find. + * @returns {RegExp} + * Expression. + */ +function toExpression(find) { + return typeof find === 'string' ? new RegExp(escape(find), 'g') : find +} + +/** + * Turn a replace into a function. + * + * @param {Replace} replace + * Replace. + * @returns {ReplaceFunction} + * Function. + */ +function toFunction(replace) { + return typeof replace === 'function' + ? replace + : function () { + return replace + } +} diff --git a/node_modules/mdast-util-find-and-replace/license b/node_modules/mdast-util-find-and-replace/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-find-and-replace/package.json b/node_modules/mdast-util-find-and-replace/package.json new file mode 100644 index 0000000000000000000000000000000000000000..0950ae27d15df72657a72e1098e63f075a28aeeb --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/package.json @@ -0,0 +1,85 @@ +{ + "author": "Titus Wormer (https://wooorm.com)", + "bugs": "https://github.com/syntax-tree/mdast-util-find-and-replace/issues", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "escape-string-regexp": "^5.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.0.0" + }, + "description": "mdast utility to find and replace text in a tree", + "devDependencies": { + "@types/node": "^22.0.0", + "c8": "^10.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-builder": "^4.0.0", + "xo": "^0.60.0" + }, + "exports": "./index.js", + "files": [ + "index.d.ts.map", + "index.d.ts", + "index.js", + "lib/" + ], + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "keywords": [ + "find", + "markdown", + "mdast-util", + "mdast", + "unist", + "utility", + "util", + "replace" + ], + "license": "MIT", + "name": "mdast-util-find-and-replace", + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "repository": "syntax-tree/mdast-util-find-and-replace", + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix", + "test-api": "node --conditions development test.js", + "test-coverage": "c8 --100 --reporter lcov -- npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "sideEffects": false, + "typeCoverage": { + "atLeast": 100, + "ignoreFiles": [ + "lib/index.d.ts" + ], + "strict": true + }, + "type": "module", + "version": "3.0.2", + "xo": { + "prettier": true, + "rules": { + "unicorn/prefer-at": "off" + } + } +} diff --git a/node_modules/mdast-util-find-and-replace/readme.md b/node_modules/mdast-util-find-and-replace/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..810110d04559cb47ea29362e89c01784a1484196 --- /dev/null +++ b/node_modules/mdast-util-find-and-replace/readme.md @@ -0,0 +1,368 @@ +# mdast-util-find-and-replace + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] utility to find and replace things. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`findAndReplace(tree, list[, options])`](#findandreplacetree-list-options) + * [`Find`](#find) + * [`FindAndReplaceList`](#findandreplacelist) + * [`FindAndReplaceTuple`](#findandreplacetuple) + * [`Options`](#options) + * [`RegExpMatchObject`](#regexpmatchobject) + * [`Replace`](#replace) + * [`ReplaceFunction`](#replacefunction) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a utility that lets you find patterns (`string`, `RegExp`) in +text and replace them with nodes. + +## When should I use this? + +This utility is typically useful when you have regexes and want to modify mdast. +One example is when you have some form of “mentions” (such as +`/@([a-z][_a-z0-9])\b/gi`) and want to create links to persons from them. + +A similar package, [`hast-util-find-and-replace`][hast-util-find-and-replace] +does the same but on [hast][]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-find-and-replace +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {findAndReplace} from 'https://esm.sh/mdast-util-find-and-replace@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {findAndReplace} from 'mdast-util-find-and-replace' +import {u} from 'unist-builder' +import {inspect} from 'unist-util-inspect' + +const tree = u('paragraph', [ + u('text', 'Some '), + u('emphasis', [u('text', 'emphasis')]), + u('text', ' and '), + u('strong', [u('text', 'importance')]), + u('text', '.') +]) + +findAndReplace(tree, [ + [/and/gi, 'or'], + [/emphasis/gi, 'em'], + [/importance/gi, 'strong'], + [ + /Some/g, + function ($0) { + return u('link', {url: '//example.com#' + $0}, [u('text', $0)]) + } + ] +]) + +console.log(inspect(tree)) +``` + +Yields: + +```txt +paragraph[8] +├─0 link[1] +│ │ url: "//example.com#Some" +│ └─0 text "Some" +├─1 text " " +├─2 emphasis[1] +│ └─0 text "em" +├─3 text " " +├─4 text "or" +├─5 text " " +├─6 strong[1] +│ └─0 text "strong" +└─7 text "." +``` + +## API + +This package exports the identifier [`findAndReplace`][api-find-and-replace]. +There is no default export. + +### `findAndReplace(tree, list[, options])` + +Find patterns in a tree and replace them. + +The algorithm searches the tree in *[preorder][]* for complete values in +[`Text`][text] nodes. +Partial matches are not supported. + +###### Parameters + +* `tree` ([`Node`][node]) + — tree to change +* `list` ([`FindAndReplaceList`][api-find-and-replace-list] or + [`FindAndReplaceTuple`][api-find-and-replace-tuple]) + — one or more find-and-replace pairs +* `options` ([`Options`][api-options]) + — configuration + +###### Returns + +Nothing (`undefined`). + +### `Find` + +Pattern to find (TypeScript type). + +Strings are escaped and then turned into global expressions. + +###### Type + +```ts +type Find = RegExp | string +``` + +### `FindAndReplaceList` + +Several find and replaces, in array form (TypeScript type). + +###### Type + +```ts +type FindAndReplaceList = Array +``` + +See [`FindAndReplaceTuple`][api-find-and-replace-tuple]. + +### `FindAndReplaceTuple` + +Find and replace in tuple form (TypeScript type). + +###### Type + +```ts +type FindAndReplaceTuple = [Find, Replace?] +``` + +See [`Find`][api-find] and [`Replace`][api-replace]. + +### `Options` + +Configuration (TypeScript type). + +###### Fields + +* `ignore` ([`Test`][test], optional) + — test for which elements to ignore + +### `RegExpMatchObject` + +Info on the match (TypeScript type). + +###### Fields + +* `index` (`number`) + — the index of the search at which the result was found +* `input` (`string`) + — a copy of the search string in the text node +* `stack` ([`Array`][node]) + — all ancestors of the text node, where the last node is the text itself + +### `Replace` + +Thing to replace with (TypeScript type). + +###### Type + +```ts +type Replace = ReplaceFunction | string +``` + +See [`ReplaceFunction`][api-replace-function]. + +### `ReplaceFunction` + +Callback called when a search matches (TypeScript type). + +###### Parameters + +The parameters are the result of corresponding search expression: + +* `value` (`string`) + — whole match +* `...capture` (`Array`) + — matches from regex capture groups +* `match` ([`RegExpMatchObject`][api-regexp-match-object]) + — info on the match + +###### Returns + +Thing to replace with: + +* when `null`, `undefined`, `''`, remove the match +* …or when `false`, do not replace at all +* …or when `string`, replace with a text node of that value +* …or when `Node` or `Array`, replace with those nodes + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`Find`][api-find], +[`FindAndReplaceList`][api-find-and-replace-list], +[`FindAndReplaceTuple`][api-find-and-replace-tuple], +[`Options`][api-options], +[`RegExpMatchObject`][api-regexp-match-object], +[`Replace`][api-replace], and +[`ReplaceFunction`][api-replace-function]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-find-and-replace@^3`, compatible with Node.js 16. + +## Security + +Use of `mdast-util-find-and-replace` does not involve [hast][] or user content +so there are no openings for [cross-site scripting (XSS)][xss] attacks. + +## Related + +* [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace) + — find and replace in hast +* [`hast-util-select`](https://github.com/syntax-tree/hast-util-select) + — `querySelector`, `querySelectorAll`, and `matches` +* [`unist-util-select`](https://github.com/syntax-tree/unist-util-select) + — select unist nodes with CSS-like selectors + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organisation, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-find-and-replace/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-find-and-replace/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-find-and-replace.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-find-and-replace + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-find-and-replace.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-find-and-replace + +[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 + +[size]: https://bundlejs.com/?q=mdast-util-find-and-replace + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[hast]: https://github.com/syntax-tree/hast + +[mdast]: https://github.com/syntax-tree/mdast + +[node]: https://github.com/syntax-tree/mdast#nodes + +[preorder]: https://github.com/syntax-tree/unist#preorder + +[text]: https://github.com/syntax-tree/mdast#text + +[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[test]: https://github.com/syntax-tree/unist-util-is#api + +[hast-util-find-and-replace]: https://github.com/syntax-tree/hast-util-find-and-replace + +[api-find-and-replace]: #findandreplacetree-list-options + +[api-options]: #options + +[api-find]: #find + +[api-replace]: #replace + +[api-replace-function]: #replacefunction + +[api-find-and-replace-list]: #findandreplacelist + +[api-find-and-replace-tuple]: #findandreplacetuple + +[api-regexp-match-object]: #regexpmatchobject diff --git a/node_modules/mdast-util-from-markdown/dev/index.d.ts b/node_modules/mdast-util-from-markdown/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a7eb0b72a19aadc7e682e5d599cb0b34716c2ba --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/index.d.ts @@ -0,0 +1,23 @@ +export type {Encoding, Token, Value} from 'micromark-util-types' +export type { + CompileContext, + CompileData, + Extension, + Handles, + Handle, + OnEnterError, + OnExitError, + Options, + Transform +} from './lib/types.js' +export {fromMarkdown} from './lib/index.js' + +declare module 'micromark-util-types' { + interface TokenTypeMap { + listItem: 'listItem' + } + + interface Token { + _spread?: boolean + } +} diff --git a/node_modules/mdast-util-from-markdown/dev/index.js b/node_modules/mdast-util-from-markdown/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d8bcf034a961c84955f243715786195be3b05015 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/index.js @@ -0,0 +1,2 @@ +// Note: types exported from `index.d.ts`. +export {fromMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts b/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c8c908e205ad02dc303fd350c56c0ca4955c8636 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts @@ -0,0 +1,53 @@ +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root; +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value: Value, options?: Options | null | undefined): Root; +import type { Value } from 'micromark-util-types'; +import type { Encoding } from 'micromark-util-types'; +import type { Options } from './types.js'; +import type { Root } from 'mdast'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts.map b/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..191aab33c2a216ca23b16023babd8154ba537c0e --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/lib/index.d.ts.map @@ -0,0 +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"} \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/dev/lib/index.js b/node_modules/mdast-util-from-markdown/dev/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..51b7144c862faaa6997d9a87c6fb9717ed09f59c --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/lib/index.js @@ -0,0 +1,1348 @@ +/** + * @import { + * Break, + * Blockquote, + * Code, + * Definition, + * Emphasis, + * Heading, + * Html, + * Image, + * InlineCode, + * Link, + * ListItem, + * List, + * Nodes, + * Paragraph, + * PhrasingContent, + * ReferenceType, + * Root, + * Strong, + * Text, + * ThematicBreak + * } from 'mdast' + * @import { + * Encoding, + * Event, + * Token, + * Value + * } from 'micromark-util-types' + * @import {Point} from 'unist' + * @import { + * CompileContext, + * CompileData, + * Config, + * Extension, + * Handle, + * OnEnterError, + * Options + * } from './types.js' + */ + +import {ok as assert} from 'devlop' +import {toString} from 'mdast-util-to-string' +import {parse, postprocess, preprocess} from 'micromark' +import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference' +import {decodeString} from 'micromark-util-decode-string' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' +import {codes, constants, types} from 'micromark-util-symbol' +import {decodeNamedCharacterReference} from 'decode-named-character-reference' +import {stringifyPosition} from 'unist-util-stringify-position' + +const own = {}.hasOwnProperty + +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value, encoding, options) { + if (encoding && typeof encoding === 'object') { + options = encoding + encoding = undefined + } + + return compiler(options)( + postprocess( + parse(options) + .document() + .write(preprocess()(value, encoding, true)) + ) + ) +} + +/** + * Note this compiler only understand complete buffering, not streaming. + * + * @param {Options | null | undefined} [options] + */ +function compiler(options) { + /** @type {Config} */ + const config = { + transforms: [], + canContainEols: ['emphasis', 'fragment', 'heading', 'paragraph', 'strong'], + enter: { + autolink: opener(link), + autolinkProtocol: onenterdata, + autolinkEmail: onenterdata, + atxHeading: opener(heading), + blockQuote: opener(blockQuote), + characterEscape: onenterdata, + characterReference: onenterdata, + codeFenced: opener(codeFlow), + codeFencedFenceInfo: buffer, + codeFencedFenceMeta: buffer, + codeIndented: opener(codeFlow, buffer), + codeText: opener(codeText, buffer), + codeTextData: onenterdata, + data: onenterdata, + codeFlowValue: onenterdata, + definition: opener(definition), + definitionDestinationString: buffer, + definitionLabelString: buffer, + definitionTitleString: buffer, + emphasis: opener(emphasis), + hardBreakEscape: opener(hardBreak), + hardBreakTrailing: opener(hardBreak), + htmlFlow: opener(html, buffer), + htmlFlowData: onenterdata, + htmlText: opener(html, buffer), + htmlTextData: onenterdata, + image: opener(image), + label: buffer, + link: opener(link), + listItem: opener(listItem), + listItemValue: onenterlistitemvalue, + listOrdered: opener(list, onenterlistordered), + listUnordered: opener(list), + paragraph: opener(paragraph), + reference: onenterreference, + referenceString: buffer, + resourceDestinationString: buffer, + resourceTitleString: buffer, + setextHeading: opener(heading), + strong: opener(strong), + thematicBreak: opener(thematicBreak) + }, + exit: { + atxHeading: closer(), + atxHeadingSequence: onexitatxheadingsequence, + autolink: closer(), + autolinkEmail: onexitautolinkemail, + autolinkProtocol: onexitautolinkprotocol, + blockQuote: closer(), + characterEscapeValue: onexitdata, + characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker, + characterReferenceMarkerNumeric: onexitcharacterreferencemarker, + characterReferenceValue: onexitcharacterreferencevalue, + characterReference: onexitcharacterreference, + codeFenced: closer(onexitcodefenced), + codeFencedFence: onexitcodefencedfence, + codeFencedFenceInfo: onexitcodefencedfenceinfo, + codeFencedFenceMeta: onexitcodefencedfencemeta, + codeFlowValue: onexitdata, + codeIndented: closer(onexitcodeindented), + codeText: closer(onexitcodetext), + codeTextData: onexitdata, + data: onexitdata, + definition: closer(), + definitionDestinationString: onexitdefinitiondestinationstring, + definitionLabelString: onexitdefinitionlabelstring, + definitionTitleString: onexitdefinitiontitlestring, + emphasis: closer(), + hardBreakEscape: closer(onexithardbreak), + hardBreakTrailing: closer(onexithardbreak), + htmlFlow: closer(onexithtmlflow), + htmlFlowData: onexitdata, + htmlText: closer(onexithtmltext), + htmlTextData: onexitdata, + image: closer(onexitimage), + label: onexitlabel, + labelText: onexitlabeltext, + lineEnding: onexitlineending, + link: closer(onexitlink), + listItem: closer(), + listOrdered: closer(), + listUnordered: closer(), + paragraph: closer(), + referenceString: onexitreferencestring, + resourceDestinationString: onexitresourcedestinationstring, + resourceTitleString: onexitresourcetitlestring, + resource: onexitresource, + setextHeading: closer(onexitsetextheading), + setextHeadingLineSequence: onexitsetextheadinglinesequence, + setextHeadingText: onexitsetextheadingtext, + strong: closer(), + thematicBreak: closer() + } + } + + configure(config, (options || {}).mdastExtensions || []) + + /** @type {CompileData} */ + const data = {} + + return compile + + /** + * Turn micromark events into an mdast tree. + * + * @param {Array} events + * Events. + * @returns {Root} + * mdast tree. + */ + function compile(events) { + /** @type {Root} */ + let tree = {type: 'root', children: []} + /** @type {Omit} */ + const context = { + stack: [tree], + tokenStack: [], + config, + enter, + exit, + buffer, + resume, + data + } + /** @type {Array} */ + const listStack = [] + let index = -1 + + while (++index < events.length) { + // We preprocess lists to add `listItem` tokens, and to infer whether + // items the list itself are spread out. + if ( + events[index][1].type === types.listOrdered || + events[index][1].type === types.listUnordered + ) { + if (events[index][0] === 'enter') { + listStack.push(index) + } else { + const tail = listStack.pop() + assert(typeof tail === 'number', 'expected list to be open') + index = prepareList(events, tail, index) + } + } + } + + index = -1 + + while (++index < events.length) { + const handler = config[events[index][0]] + + if (own.call(handler, events[index][1].type)) { + handler[events[index][1].type].call( + Object.assign( + {sliceSerialize: events[index][2].sliceSerialize}, + context + ), + events[index][1] + ) + } + } + + // Handle tokens still being open. + if (context.tokenStack.length > 0) { + const tail = context.tokenStack[context.tokenStack.length - 1] + const handler = tail[1] || defaultOnError + handler.call(context, undefined, tail[0]) + } + + // Figure out `root` position. + tree.position = { + start: point( + events.length > 0 ? events[0][1].start : {line: 1, column: 1, offset: 0} + ), + end: point( + events.length > 0 + ? events[events.length - 2][1].end + : {line: 1, column: 1, offset: 0} + ) + } + + // Call transforms. + index = -1 + while (++index < config.transforms.length) { + tree = config.transforms[index](tree) || tree + } + + return tree + } + + /** + * @param {Array} events + * @param {number} start + * @param {number} length + * @returns {number} + */ + function prepareList(events, start, length) { + let index = start - 1 + let containerBalance = -1 + let listSpread = false + /** @type {Token | undefined} */ + let listItem + /** @type {number | undefined} */ + let lineIndex + /** @type {number | undefined} */ + let firstBlankLineIndex + /** @type {boolean | undefined} */ + let atMarker + + while (++index <= length) { + const event = events[index] + + switch (event[1].type) { + case types.listUnordered: + case types.listOrdered: + case types.blockQuote: { + if (event[0] === 'enter') { + containerBalance++ + } else { + containerBalance-- + } + + atMarker = undefined + + break + } + + case types.lineEndingBlank: { + if (event[0] === 'enter') { + if ( + listItem && + !atMarker && + !containerBalance && + !firstBlankLineIndex + ) { + firstBlankLineIndex = index + } + + atMarker = undefined + } + + break + } + + case types.linePrefix: + case types.listItemValue: + case types.listItemMarker: + case types.listItemPrefix: + case types.listItemPrefixWhitespace: { + // Empty. + + break + } + + default: { + atMarker = undefined + } + } + + if ( + (!containerBalance && + event[0] === 'enter' && + event[1].type === types.listItemPrefix) || + (containerBalance === -1 && + event[0] === 'exit' && + (event[1].type === types.listUnordered || + event[1].type === types.listOrdered)) + ) { + if (listItem) { + let tailIndex = index + lineIndex = undefined + + while (tailIndex--) { + const tailEvent = events[tailIndex] + + if ( + tailEvent[1].type === types.lineEnding || + tailEvent[1].type === types.lineEndingBlank + ) { + if (tailEvent[0] === 'exit') continue + + if (lineIndex) { + events[lineIndex][1].type = types.lineEndingBlank + listSpread = true + } + + tailEvent[1].type = types.lineEnding + lineIndex = tailIndex + } else if ( + tailEvent[1].type === types.linePrefix || + tailEvent[1].type === types.blockQuotePrefix || + tailEvent[1].type === types.blockQuotePrefixWhitespace || + tailEvent[1].type === types.blockQuoteMarker || + tailEvent[1].type === types.listItemIndent + ) { + // Empty + } else { + break + } + } + + if ( + firstBlankLineIndex && + (!lineIndex || firstBlankLineIndex < lineIndex) + ) { + listItem._spread = true + } + + // Fix position. + listItem.end = Object.assign( + {}, + lineIndex ? events[lineIndex][1].start : event[1].end + ) + + events.splice(lineIndex || index, 0, ['exit', listItem, event[2]]) + index++ + length++ + } + + // Create a new list item. + if (event[1].type === types.listItemPrefix) { + /** @type {Token} */ + const item = { + type: 'listItem', + _spread: false, + start: Object.assign({}, event[1].start), + // @ts-expect-error: we’ll add `end` in a second. + end: undefined + } + listItem = item + events.splice(index, 0, ['enter', item, event[2]]) + index++ + length++ + firstBlankLineIndex = undefined + atMarker = true + } + } + } + + events[start][1]._spread = listSpread + return length + } + + /** + * Create an opener handle. + * + * @param {(token: Token) => Nodes} create + * Create a node. + * @param {Handle | undefined} [and] + * Optional function to also run. + * @returns {Handle} + * Handle. + */ + function opener(create, and) { + return open + + /** + * @this {CompileContext} + * @param {Token} token + * @returns {undefined} + */ + function open(token) { + enter.call(this, create(token), token) + if (and) and.call(this, token) + } + } + + /** + * @type {CompileContext['buffer']} + */ + function buffer() { + this.stack.push({type: 'fragment', children: []}) + } + + /** + * @type {CompileContext['enter']} + */ + function enter(node, token, errorHandler) { + const parent = this.stack[this.stack.length - 1] + assert(parent, 'expected `parent`') + assert('children' in parent, 'expected `parent`') + /** @type {Array} */ + const siblings = parent.children + siblings.push(node) + this.stack.push(node) + this.tokenStack.push([token, errorHandler || undefined]) + node.position = { + start: point(token.start), + // @ts-expect-error: `end` will be patched later. + end: undefined + } + } + + /** + * Create a closer handle. + * + * @param {Handle | undefined} [and] + * Optional function to also run. + * @returns {Handle} + * Handle. + */ + function closer(and) { + return close + + /** + * @this {CompileContext} + * @param {Token} token + * @returns {undefined} + */ + function close(token) { + if (and) and.call(this, token) + exit.call(this, token) + } + } + + /** + * @type {CompileContext['exit']} + */ + function exit(token, onExitError) { + const node = this.stack.pop() + assert(node, 'expected `node`') + const open = this.tokenStack.pop() + + if (!open) { + throw new Error( + 'Cannot close `' + + token.type + + '` (' + + stringifyPosition({start: token.start, end: token.end}) + + '): it’s not open' + ) + } else if (open[0].type !== token.type) { + if (onExitError) { + onExitError.call(this, token, open[0]) + } else { + const handler = open[1] || defaultOnError + handler.call(this, token, open[0]) + } + } + + assert(node.type !== 'fragment', 'unexpected fragment `exit`ed') + assert(node.position, 'expected `position` to be defined') + node.position.end = point(token.end) + } + + /** + * @type {CompileContext['resume']} + */ + function resume() { + return toString(this.stack.pop()) + } + + // + // Handlers. + // + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onenterlistordered() { + this.data.expectingFirstListItemValue = true + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onenterlistitemvalue(token) { + if (this.data.expectingFirstListItemValue) { + const ancestor = this.stack[this.stack.length - 2] + assert(ancestor, 'expected nodes on stack') + assert(ancestor.type === 'list', 'expected list on stack') + ancestor.start = Number.parseInt( + this.sliceSerialize(token), + constants.numericBaseDecimal + ) + this.data.expectingFirstListItemValue = undefined + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfenceinfo() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'code', 'expected code on stack') + node.lang = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfencemeta() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'code', 'expected code on stack') + node.meta = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfence() { + // Exit if this is the closing fence. + if (this.data.flowCodeInside) return + this.buffer() + this.data.flowCodeInside = true + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefenced() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'code', 'expected code on stack') + + node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '') + this.data.flowCodeInside = undefined + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodeindented() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'code', 'expected code on stack') + + node.value = data.replace(/(\r?\n|\r)$/g, '') + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitionlabelstring(token) { + const label = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'definition', 'expected definition on stack') + + node.label = label + node.identifier = normalizeIdentifier( + this.sliceSerialize(token) + ).toLowerCase() + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitiontitlestring() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'definition', 'expected definition on stack') + + node.title = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitiondestinationstring() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'definition', 'expected definition on stack') + + node.url = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitatxheadingsequence(token) { + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'heading', 'expected heading on stack') + + if (!node.depth) { + const depth = this.sliceSerialize(token).length + + assert( + depth === 1 || + depth === 2 || + depth === 3 || + depth === 4 || + depth === 5 || + depth === 6, + 'expected `depth` between `1` and `6`' + ) + + node.depth = depth + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheadingtext() { + this.data.setextHeadingSlurpLineEnding = true + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheadinglinesequence(token) { + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'heading', 'expected heading on stack') + + node.depth = + this.sliceSerialize(token).codePointAt(0) === codes.equalsTo ? 1 : 2 + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheading() { + this.data.setextHeadingSlurpLineEnding = undefined + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onenterdata(token) { + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert('children' in node, 'expected parent on stack') + /** @type {Array} */ + const siblings = node.children + + let tail = siblings[siblings.length - 1] + + if (!tail || tail.type !== 'text') { + // Add a new text node. + tail = text() + tail.position = { + start: point(token.start), + // @ts-expect-error: we’ll add `end` later. + end: undefined + } + siblings.push(tail) + } + + this.stack.push(tail) + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitdata(token) { + const tail = this.stack.pop() + assert(tail, 'expected a `node` to be on the stack') + assert('value' in tail, 'expected a `literal` to be on the stack') + assert(tail.position, 'expected `node` to have an open position') + tail.value += this.sliceSerialize(token) + tail.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlineending(token) { + const context = this.stack[this.stack.length - 1] + assert(context, 'expected `node`') + + // If we’re at a hard break, include the line ending in there. + if (this.data.atHardBreak) { + assert('children' in context, 'expected `parent`') + const tail = context.children[context.children.length - 1] + assert(tail.position, 'expected tail to have a starting position') + tail.position.end = point(token.end) + this.data.atHardBreak = undefined + return + } + + if ( + !this.data.setextHeadingSlurpLineEnding && + config.canContainEols.includes(context.type) + ) { + onenterdata.call(this, token) + onexitdata.call(this, token) + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithardbreak() { + this.data.atHardBreak = true + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithtmlflow() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'html', 'expected html on stack') + + node.value = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithtmltext() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'html', 'expected html on stack') + + node.value = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitcodetext() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'inlineCode', 'expected inline code on stack') + + node.value = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlink() { + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'link', 'expected link on stack') + + // Note: there are also `identifier` and `label` fields on this link node! + // These are used / cleaned here. + + // To do: clean. + if (this.data.inReference) { + /** @type {ReferenceType} */ + const referenceType = this.data.referenceType || 'shortcut' + + node.type += 'Reference' + // @ts-expect-error: mutate. + node.referenceType = referenceType + // @ts-expect-error: mutate. + delete node.url + delete node.title + } else { + // @ts-expect-error: mutate. + delete node.identifier + // @ts-expect-error: mutate. + delete node.label + } + + this.data.referenceType = undefined + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitimage() { + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'image', 'expected image on stack') + + // Note: there are also `identifier` and `label` fields on this link node! + // These are used / cleaned here. + + // To do: clean. + if (this.data.inReference) { + /** @type {ReferenceType} */ + const referenceType = this.data.referenceType || 'shortcut' + + node.type += 'Reference' + // @ts-expect-error: mutate. + node.referenceType = referenceType + // @ts-expect-error: mutate. + delete node.url + delete node.title + } else { + // @ts-expect-error: mutate. + delete node.identifier + // @ts-expect-error: mutate. + delete node.label + } + + this.data.referenceType = undefined + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlabeltext(token) { + const string = this.sliceSerialize(token) + const ancestor = this.stack[this.stack.length - 2] + assert(ancestor, 'expected ancestor on stack') + assert( + ancestor.type === 'image' || ancestor.type === 'link', + 'expected image or link on stack' + ) + + // @ts-expect-error: stash this on the node, as it might become a reference + // later. + ancestor.label = decodeString(string) + // @ts-expect-error: same as above. + ancestor.identifier = normalizeIdentifier(string).toLowerCase() + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlabel() { + const fragment = this.stack[this.stack.length - 1] + assert(fragment, 'expected node on stack') + assert(fragment.type === 'fragment', 'expected fragment on stack') + const value = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert( + node.type === 'image' || node.type === 'link', + 'expected image or link on stack' + ) + + // Assume a reference. + this.data.inReference = true + + if (node.type === 'link') { + /** @type {Array} */ + const children = fragment.children + + node.children = children + } else { + node.alt = value + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresourcedestinationstring() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert( + node.type === 'image' || node.type === 'link', + 'expected image or link on stack' + ) + node.url = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresourcetitlestring() { + const data = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert( + node.type === 'image' || node.type === 'link', + 'expected image or link on stack' + ) + node.title = data + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresource() { + this.data.inReference = undefined + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onenterreference() { + this.data.referenceType = 'collapsed' + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitreferencestring(token) { + const label = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert( + node.type === 'image' || node.type === 'link', + 'expected image reference or link reference on stack' + ) + + // @ts-expect-error: stash this on the node, as it might become a reference + // later. + node.label = label + // @ts-expect-error: same as above. + node.identifier = normalizeIdentifier( + this.sliceSerialize(token) + ).toLowerCase() + this.data.referenceType = 'full' + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitcharacterreferencemarker(token) { + assert( + token.type === 'characterReferenceMarkerNumeric' || + token.type === 'characterReferenceMarkerHexadecimal' + ) + this.data.characterReferenceType = token.type + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcharacterreferencevalue(token) { + const data = this.sliceSerialize(token) + const type = this.data.characterReferenceType + /** @type {string} */ + let value + + if (type) { + value = decodeNumericCharacterReference( + data, + type === types.characterReferenceMarkerNumeric + ? constants.numericBaseDecimal + : constants.numericBaseHexadecimal + ) + this.data.characterReferenceType = undefined + } else { + const result = decodeNamedCharacterReference(data) + assert(result !== false, 'expected reference to decode') + value = result + } + + const tail = this.stack[this.stack.length - 1] + assert(tail, 'expected `node`') + assert('value' in tail, 'expected `node.value`') + tail.value += value + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcharacterreference(token) { + const tail = this.stack.pop() + assert(tail, 'expected `node`') + assert(tail.position, 'expected `node.position`') + tail.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitautolinkprotocol(token) { + onexitdata.call(this, token) + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'link', 'expected link on stack') + + node.url = this.sliceSerialize(token) + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitautolinkemail(token) { + onexitdata.call(this, token) + const node = this.stack[this.stack.length - 1] + assert(node, 'expected node on stack') + assert(node.type === 'link', 'expected link on stack') + + node.url = 'mailto:' + this.sliceSerialize(token) + } + + // + // Creaters. + // + + /** @returns {Blockquote} */ + function blockQuote() { + return {type: 'blockquote', children: []} + } + + /** @returns {Code} */ + function codeFlow() { + return {type: 'code', lang: null, meta: null, value: ''} + } + + /** @returns {InlineCode} */ + function codeText() { + return {type: 'inlineCode', value: ''} + } + + /** @returns {Definition} */ + function definition() { + return { + type: 'definition', + identifier: '', + label: null, + title: null, + url: '' + } + } + + /** @returns {Emphasis} */ + function emphasis() { + return {type: 'emphasis', children: []} + } + + /** @returns {Heading} */ + function heading() { + return { + type: 'heading', + // @ts-expect-error `depth` will be set later. + depth: 0, + children: [] + } + } + + /** @returns {Break} */ + function hardBreak() { + return {type: 'break'} + } + + /** @returns {Html} */ + function html() { + return {type: 'html', value: ''} + } + + /** @returns {Image} */ + function image() { + return {type: 'image', title: null, url: '', alt: null} + } + + /** @returns {Link} */ + function link() { + return {type: 'link', title: null, url: '', children: []} + } + + /** + * @param {Token} token + * @returns {List} + */ + function list(token) { + return { + type: 'list', + ordered: token.type === 'listOrdered', + start: null, + spread: token._spread, + children: [] + } + } + + /** + * @param {Token} token + * @returns {ListItem} + */ + function listItem(token) { + return { + type: 'listItem', + spread: token._spread, + checked: null, + children: [] + } + } + + /** @returns {Paragraph} */ + function paragraph() { + return {type: 'paragraph', children: []} + } + + /** @returns {Strong} */ + function strong() { + return {type: 'strong', children: []} + } + + /** @returns {Text} */ + function text() { + return {type: 'text', value: ''} + } + + /** @returns {ThematicBreak} */ + function thematicBreak() { + return {type: 'thematicBreak'} + } +} + +/** + * Copy a point-like value. + * + * @param {Point} d + * Point-like value. + * @returns {Point} + * unist point. + */ +function point(d) { + return {line: d.line, column: d.column, offset: d.offset} +} + +/** + * @param {Config} combined + * @param {Array | Extension>} extensions + * @returns {undefined} + */ +function configure(combined, extensions) { + let index = -1 + + while (++index < extensions.length) { + const value = extensions[index] + + if (Array.isArray(value)) { + configure(combined, value) + } else { + extension(combined, value) + } + } +} + +/** + * @param {Config} combined + * @param {Extension} extension + * @returns {undefined} + */ +function extension(combined, extension) { + /** @type {keyof Extension} */ + let key + + for (key in extension) { + if (own.call(extension, key)) { + switch (key) { + case 'canContainEols': { + const right = extension[key] + if (right) { + combined[key].push(...right) + } + + break + } + + case 'transforms': { + const right = extension[key] + if (right) { + combined[key].push(...right) + } + + break + } + + case 'enter': + case 'exit': { + const right = extension[key] + if (right) { + Object.assign(combined[key], right) + } + + break + } + // No default + } + } + } +} + +/** @type {OnEnterError} */ +function defaultOnError(left, right) { + if (left) { + throw new Error( + 'Cannot close `' + + left.type + + '` (' + + stringifyPosition({start: left.start, end: left.end}) + + '): a different token (`' + + right.type + + '`, ' + + stringifyPosition({start: right.start, end: right.end}) + + ') is open' + ) + } else { + throw new Error( + 'Cannot close document, a token (`' + + right.type + + '`, ' + + stringifyPosition({start: right.start, end: right.end}) + + ') is still open' + ) + } +} diff --git a/node_modules/mdast-util-from-markdown/dev/lib/types.d.ts b/node_modules/mdast-util-from-markdown/dev/lib/types.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..710de761b176901337cab011c8936732f01fb750 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/lib/types.d.ts @@ -0,0 +1,295 @@ +import type {Nodes, Parent, PhrasingContent, Root} from 'mdast' +import type {ParseOptions, Token} from 'micromark-util-types' + +/** + * Compiler context. + */ +export interface CompileContext { + /** + * Configuration. + */ + config: Config + /** + * Info passed around; + * key/value store. + */ + data: CompileData + /** + * Stack of nodes. + */ + stack: Array + /** + * Stack of tokens. + */ + tokenStack: Array + + /** + * Capture some of the output data. + * + * @param this + * Context. + * @returns + * Nothing. + */ + buffer(this: CompileContext): undefined + + /** + * Enter a node. + * + * @param this + * Context. + * @param node + * Node. + * @param token + * Token. + * @param onError + * Error handler. + * @returns + * Nothing. + */ + enter( + this: CompileContext, + node: Nodes, + token: Token, + onError?: OnEnterError | null | undefined + ): undefined + + /** + * Exit a node. + * + * @param this + * Context. + * @param token + * Token. + * @param onError + * Error handler. + * @returns + * Nothing. + */ + exit( + this: CompileContext, + token: Token, + onError?: OnExitError | null | undefined + ): undefined + + /** + * Stop capturing and access the output data. + * + * @param this + * Context. + * @returns + * Nothing. + */ + resume(this: CompileContext): string + + /** + * Get the source text that spans a token (or location). + * + * @param token + * Start/end in stream. + * @param expandTabs + * Whether to expand tabs. + * @returns + * Serialized chunks. + */ + sliceSerialize( + token: Pick, + expandTabs?: boolean | undefined + ): string +} + +/** + * Interface of tracked data. + * + * When working on extensions that use more data, extend the corresponding + * interface to register their types: + * + * ```ts + * declare module 'mdast-util-from-markdown' { + * interface CompileData { + * // Register a new field. + * mathFlowInside?: boolean | undefined + * } + * } + * ``` + */ +export interface CompileData { + /** + * Whether we’re inside a hard break. + */ + atHardBreak?: boolean | undefined + + /** + * Current character reference type. + */ + characterReferenceType?: + | 'characterReferenceMarkerHexadecimal' + | 'characterReferenceMarkerNumeric' + | undefined + + /** + * Whether a first list item value (`1` in `1. a`) is expected. + */ + expectingFirstListItemValue?: boolean | undefined + + /** + * Whether we’re in flow code. + */ + flowCodeInside?: boolean | undefined + + /** + * Whether we’re in a reference. + */ + inReference?: boolean | undefined + + /** + * Whether we’re expecting a line ending from a setext heading, which can be slurped. + */ + setextHeadingSlurpLineEnding?: boolean | undefined + + /** + * Current reference. + */ + referenceType?: 'collapsed' | 'full' | undefined +} + +/** + * Configuration. + * + * We have our defaults, but extensions will add more. + */ +export interface Config { + /** + * Token types where line endings are used. + */ + canContainEols: Array + /** + * Opening handles. + */ + enter: Handles + /** + * Closing handles. + */ + exit: Handles + /** + * Tree transforms. + */ + transforms: Array +} + +/** + * Change how markdown tokens from micromark are turned into mdast. + */ +export interface Extension { + /** + * Token types where line endings are used. + */ + canContainEols?: Array | null | undefined + /** + * Opening handles. + */ + enter?: Handles | null | undefined + /** + * Closing handles. + */ + exit?: Handles | null | undefined + /** + * Tree transforms. + */ + transforms?: Array | null | undefined +} + +/** + * Internal fragment. + */ +export interface Fragment extends Parent { + /** + * Node type. + */ + type: 'fragment' + /** + * Children. + */ + children: Array +} + +/** + * Token types mapping to handles + */ +export type Handles = Record + +/** + * Handle a token. + * + * @param this + * Context. + * @param token + * Current token. + * @returns + * Nothing. + */ +export type Handle = (this: CompileContext, token: Token) => undefined | void + +/** + * Handle the case where the `right` token is open, but it is closed (by the + * `left` token) or because we reached the end of the document. + * + * @param this + * Context. + * @param left + * Left token. + * @param right + * Right token. + * @returns + * Nothing. + */ +export type OnEnterError = ( + this: Omit, + left: Token | undefined, + right: Token +) => undefined + +/** + * Handle the case where the `right` token is open but it is closed by + * exiting the `left` token. + * + * @param this + * Context. + * @param left + * Left token. + * @param right + * Right token. + * @returns + * Nothing. + */ +export type OnExitError = ( + this: Omit, + left: Token, + right: Token +) => undefined + +/** + * Configuration. + */ +export interface Options extends ParseOptions { + /** + * Extensions for this utility to change how tokens are turned into a tree. + */ + mdastExtensions?: Array> | null | undefined +} + +/** + * Open token on the stack, + * with an optional error handler for when that token isn’t closed properly. + */ +export type TokenTuple = [token: Token, onError: OnEnterError | undefined] + +/** + * Extra transform, to change the AST afterwards. + * + * @param tree + * Tree to transform. + * @returns + * New tree or nothing (in which case the current tree is used). + */ +export type Transform = (tree: Root) => Root | null | undefined | void diff --git a/node_modules/mdast-util-from-markdown/dev/lib/types.js b/node_modules/mdast-util-from-markdown/dev/lib/types.js new file mode 100644 index 0000000000000000000000000000000000000000..c172e67f95bf21d4668a3f572002ea2e5aeb9466 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/dev/lib/types.js @@ -0,0 +1,2 @@ +// Note: types exposed from `types.d.ts`. +export {} diff --git a/node_modules/mdast-util-from-markdown/index.d.ts b/node_modules/mdast-util-from-markdown/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a7eb0b72a19aadc7e682e5d599cb0b34716c2ba --- /dev/null +++ b/node_modules/mdast-util-from-markdown/index.d.ts @@ -0,0 +1,23 @@ +export type {Encoding, Token, Value} from 'micromark-util-types' +export type { + CompileContext, + CompileData, + Extension, + Handles, + Handle, + OnEnterError, + OnExitError, + Options, + Transform +} from './lib/types.js' +export {fromMarkdown} from './lib/index.js' + +declare module 'micromark-util-types' { + interface TokenTypeMap { + listItem: 'listItem' + } + + interface Token { + _spread?: boolean + } +} diff --git a/node_modules/mdast-util-from-markdown/index.js b/node_modules/mdast-util-from-markdown/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6ceffc9ab85bd2ca47070cea3de8ab2369674217 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/index.js @@ -0,0 +1,2 @@ +// Note: types exported from `index.d.ts`. +export { fromMarkdown } from './lib/index.js'; \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/lib/index.d.ts b/node_modules/mdast-util-from-markdown/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c8c908e205ad02dc303fd350c56c0ca4955c8636 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/lib/index.d.ts @@ -0,0 +1,53 @@ +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value: Value, encoding?: Encoding | null | undefined, options?: Options | null | undefined): Root; +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value: Value, options?: Options | null | undefined): Root; +import type { Value } from 'micromark-util-types'; +import type { Encoding } from 'micromark-util-types'; +import type { Options } from './types.js'; +import type { Root } from 'mdast'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/lib/index.d.ts.map b/node_modules/mdast-util-from-markdown/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..191aab33c2a216ca23b16023babd8154ba537c0e --- /dev/null +++ b/node_modules/mdast-util-from-markdown/lib/index.d.ts.map @@ -0,0 +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"} \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/lib/index.js b/node_modules/mdast-util-from-markdown/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..90e17befb5712e97284e97cd6689bc14ac42c1ba --- /dev/null +++ b/node_modules/mdast-util-from-markdown/lib/index.js @@ -0,0 +1,1177 @@ +/** + * @import { + * Break, + * Blockquote, + * Code, + * Definition, + * Emphasis, + * Heading, + * Html, + * Image, + * InlineCode, + * Link, + * ListItem, + * List, + * Nodes, + * Paragraph, + * PhrasingContent, + * ReferenceType, + * Root, + * Strong, + * Text, + * ThematicBreak + * } from 'mdast' + * @import { + * Encoding, + * Event, + * Token, + * Value + * } from 'micromark-util-types' + * @import {Point} from 'unist' + * @import { + * CompileContext, + * CompileData, + * Config, + * Extension, + * Handle, + * OnEnterError, + * Options + * } from './types.js' + */ + +import { toString } from 'mdast-util-to-string'; +import { parse, postprocess, preprocess } from 'micromark'; +import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'; +import { decodeString } from 'micromark-util-decode-string'; +import { normalizeIdentifier } from 'micromark-util-normalize-identifier'; +import { decodeNamedCharacterReference } from 'decode-named-character-reference'; +import { stringifyPosition } from 'unist-util-stringify-position'; +const own = {}.hasOwnProperty; + +/** + * Turn markdown into a syntax tree. + * + * @overload + * @param {Value} value + * @param {Encoding | null | undefined} [encoding] + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @overload + * @param {Value} value + * @param {Options | null | undefined} [options] + * @returns {Root} + * + * @param {Value} value + * Markdown to parse. + * @param {Encoding | Options | null | undefined} [encoding] + * Character encoding for when `value` is `Buffer`. + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {Root} + * mdast tree. + */ +export function fromMarkdown(value, encoding, options) { + if (encoding && typeof encoding === 'object') { + options = encoding; + encoding = undefined; + } + return compiler(options)(postprocess(parse(options).document().write(preprocess()(value, encoding, true)))); +} + +/** + * Note this compiler only understand complete buffering, not streaming. + * + * @param {Options | null | undefined} [options] + */ +function compiler(options) { + /** @type {Config} */ + const config = { + transforms: [], + canContainEols: ['emphasis', 'fragment', 'heading', 'paragraph', 'strong'], + enter: { + autolink: opener(link), + autolinkProtocol: onenterdata, + autolinkEmail: onenterdata, + atxHeading: opener(heading), + blockQuote: opener(blockQuote), + characterEscape: onenterdata, + characterReference: onenterdata, + codeFenced: opener(codeFlow), + codeFencedFenceInfo: buffer, + codeFencedFenceMeta: buffer, + codeIndented: opener(codeFlow, buffer), + codeText: opener(codeText, buffer), + codeTextData: onenterdata, + data: onenterdata, + codeFlowValue: onenterdata, + definition: opener(definition), + definitionDestinationString: buffer, + definitionLabelString: buffer, + definitionTitleString: buffer, + emphasis: opener(emphasis), + hardBreakEscape: opener(hardBreak), + hardBreakTrailing: opener(hardBreak), + htmlFlow: opener(html, buffer), + htmlFlowData: onenterdata, + htmlText: opener(html, buffer), + htmlTextData: onenterdata, + image: opener(image), + label: buffer, + link: opener(link), + listItem: opener(listItem), + listItemValue: onenterlistitemvalue, + listOrdered: opener(list, onenterlistordered), + listUnordered: opener(list), + paragraph: opener(paragraph), + reference: onenterreference, + referenceString: buffer, + resourceDestinationString: buffer, + resourceTitleString: buffer, + setextHeading: opener(heading), + strong: opener(strong), + thematicBreak: opener(thematicBreak) + }, + exit: { + atxHeading: closer(), + atxHeadingSequence: onexitatxheadingsequence, + autolink: closer(), + autolinkEmail: onexitautolinkemail, + autolinkProtocol: onexitautolinkprotocol, + blockQuote: closer(), + characterEscapeValue: onexitdata, + characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker, + characterReferenceMarkerNumeric: onexitcharacterreferencemarker, + characterReferenceValue: onexitcharacterreferencevalue, + characterReference: onexitcharacterreference, + codeFenced: closer(onexitcodefenced), + codeFencedFence: onexitcodefencedfence, + codeFencedFenceInfo: onexitcodefencedfenceinfo, + codeFencedFenceMeta: onexitcodefencedfencemeta, + codeFlowValue: onexitdata, + codeIndented: closer(onexitcodeindented), + codeText: closer(onexitcodetext), + codeTextData: onexitdata, + data: onexitdata, + definition: closer(), + definitionDestinationString: onexitdefinitiondestinationstring, + definitionLabelString: onexitdefinitionlabelstring, + definitionTitleString: onexitdefinitiontitlestring, + emphasis: closer(), + hardBreakEscape: closer(onexithardbreak), + hardBreakTrailing: closer(onexithardbreak), + htmlFlow: closer(onexithtmlflow), + htmlFlowData: onexitdata, + htmlText: closer(onexithtmltext), + htmlTextData: onexitdata, + image: closer(onexitimage), + label: onexitlabel, + labelText: onexitlabeltext, + lineEnding: onexitlineending, + link: closer(onexitlink), + listItem: closer(), + listOrdered: closer(), + listUnordered: closer(), + paragraph: closer(), + referenceString: onexitreferencestring, + resourceDestinationString: onexitresourcedestinationstring, + resourceTitleString: onexitresourcetitlestring, + resource: onexitresource, + setextHeading: closer(onexitsetextheading), + setextHeadingLineSequence: onexitsetextheadinglinesequence, + setextHeadingText: onexitsetextheadingtext, + strong: closer(), + thematicBreak: closer() + } + }; + configure(config, (options || {}).mdastExtensions || []); + + /** @type {CompileData} */ + const data = {}; + return compile; + + /** + * Turn micromark events into an mdast tree. + * + * @param {Array} events + * Events. + * @returns {Root} + * mdast tree. + */ + function compile(events) { + /** @type {Root} */ + let tree = { + type: 'root', + children: [] + }; + /** @type {Omit} */ + const context = { + stack: [tree], + tokenStack: [], + config, + enter, + exit, + buffer, + resume, + data + }; + /** @type {Array} */ + const listStack = []; + let index = -1; + while (++index < events.length) { + // We preprocess lists to add `listItem` tokens, and to infer whether + // items the list itself are spread out. + if (events[index][1].type === "listOrdered" || events[index][1].type === "listUnordered") { + if (events[index][0] === 'enter') { + listStack.push(index); + } else { + const tail = listStack.pop(); + index = prepareList(events, tail, index); + } + } + } + index = -1; + while (++index < events.length) { + const handler = config[events[index][0]]; + if (own.call(handler, events[index][1].type)) { + handler[events[index][1].type].call(Object.assign({ + sliceSerialize: events[index][2].sliceSerialize + }, context), events[index][1]); + } + } + + // Handle tokens still being open. + if (context.tokenStack.length > 0) { + const tail = context.tokenStack[context.tokenStack.length - 1]; + const handler = tail[1] || defaultOnError; + handler.call(context, undefined, tail[0]); + } + + // Figure out `root` position. + tree.position = { + start: point(events.length > 0 ? events[0][1].start : { + line: 1, + column: 1, + offset: 0 + }), + end: point(events.length > 0 ? events[events.length - 2][1].end : { + line: 1, + column: 1, + offset: 0 + }) + }; + + // Call transforms. + index = -1; + while (++index < config.transforms.length) { + tree = config.transforms[index](tree) || tree; + } + return tree; + } + + /** + * @param {Array} events + * @param {number} start + * @param {number} length + * @returns {number} + */ + function prepareList(events, start, length) { + let index = start - 1; + let containerBalance = -1; + let listSpread = false; + /** @type {Token | undefined} */ + let listItem; + /** @type {number | undefined} */ + let lineIndex; + /** @type {number | undefined} */ + let firstBlankLineIndex; + /** @type {boolean | undefined} */ + let atMarker; + while (++index <= length) { + const event = events[index]; + switch (event[1].type) { + case "listUnordered": + case "listOrdered": + case "blockQuote": + { + if (event[0] === 'enter') { + containerBalance++; + } else { + containerBalance--; + } + atMarker = undefined; + break; + } + case "lineEndingBlank": + { + if (event[0] === 'enter') { + if (listItem && !atMarker && !containerBalance && !firstBlankLineIndex) { + firstBlankLineIndex = index; + } + atMarker = undefined; + } + break; + } + case "linePrefix": + case "listItemValue": + case "listItemMarker": + case "listItemPrefix": + case "listItemPrefixWhitespace": + { + // Empty. + + break; + } + default: + { + atMarker = undefined; + } + } + if (!containerBalance && event[0] === 'enter' && event[1].type === "listItemPrefix" || containerBalance === -1 && event[0] === 'exit' && (event[1].type === "listUnordered" || event[1].type === "listOrdered")) { + if (listItem) { + let tailIndex = index; + lineIndex = undefined; + while (tailIndex--) { + const tailEvent = events[tailIndex]; + if (tailEvent[1].type === "lineEnding" || tailEvent[1].type === "lineEndingBlank") { + if (tailEvent[0] === 'exit') continue; + if (lineIndex) { + events[lineIndex][1].type = "lineEndingBlank"; + listSpread = true; + } + tailEvent[1].type = "lineEnding"; + lineIndex = tailIndex; + } else if (tailEvent[1].type === "linePrefix" || tailEvent[1].type === "blockQuotePrefix" || tailEvent[1].type === "blockQuotePrefixWhitespace" || tailEvent[1].type === "blockQuoteMarker" || tailEvent[1].type === "listItemIndent") { + // Empty + } else { + break; + } + } + if (firstBlankLineIndex && (!lineIndex || firstBlankLineIndex < lineIndex)) { + listItem._spread = true; + } + + // Fix position. + listItem.end = Object.assign({}, lineIndex ? events[lineIndex][1].start : event[1].end); + events.splice(lineIndex || index, 0, ['exit', listItem, event[2]]); + index++; + length++; + } + + // Create a new list item. + if (event[1].type === "listItemPrefix") { + /** @type {Token} */ + const item = { + type: 'listItem', + _spread: false, + start: Object.assign({}, event[1].start), + // @ts-expect-error: we’ll add `end` in a second. + end: undefined + }; + listItem = item; + events.splice(index, 0, ['enter', item, event[2]]); + index++; + length++; + firstBlankLineIndex = undefined; + atMarker = true; + } + } + } + events[start][1]._spread = listSpread; + return length; + } + + /** + * Create an opener handle. + * + * @param {(token: Token) => Nodes} create + * Create a node. + * @param {Handle | undefined} [and] + * Optional function to also run. + * @returns {Handle} + * Handle. + */ + function opener(create, and) { + return open; + + /** + * @this {CompileContext} + * @param {Token} token + * @returns {undefined} + */ + function open(token) { + enter.call(this, create(token), token); + if (and) and.call(this, token); + } + } + + /** + * @type {CompileContext['buffer']} + */ + function buffer() { + this.stack.push({ + type: 'fragment', + children: [] + }); + } + + /** + * @type {CompileContext['enter']} + */ + function enter(node, token, errorHandler) { + const parent = this.stack[this.stack.length - 1]; + /** @type {Array} */ + const siblings = parent.children; + siblings.push(node); + this.stack.push(node); + this.tokenStack.push([token, errorHandler || undefined]); + node.position = { + start: point(token.start), + // @ts-expect-error: `end` will be patched later. + end: undefined + }; + } + + /** + * Create a closer handle. + * + * @param {Handle | undefined} [and] + * Optional function to also run. + * @returns {Handle} + * Handle. + */ + function closer(and) { + return close; + + /** + * @this {CompileContext} + * @param {Token} token + * @returns {undefined} + */ + function close(token) { + if (and) and.call(this, token); + exit.call(this, token); + } + } + + /** + * @type {CompileContext['exit']} + */ + function exit(token, onExitError) { + const node = this.stack.pop(); + const open = this.tokenStack.pop(); + if (!open) { + throw new Error('Cannot close `' + token.type + '` (' + stringifyPosition({ + start: token.start, + end: token.end + }) + '): it’s not open'); + } else if (open[0].type !== token.type) { + if (onExitError) { + onExitError.call(this, token, open[0]); + } else { + const handler = open[1] || defaultOnError; + handler.call(this, token, open[0]); + } + } + node.position.end = point(token.end); + } + + /** + * @type {CompileContext['resume']} + */ + function resume() { + return toString(this.stack.pop()); + } + + // + // Handlers. + // + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onenterlistordered() { + this.data.expectingFirstListItemValue = true; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onenterlistitemvalue(token) { + if (this.data.expectingFirstListItemValue) { + const ancestor = this.stack[this.stack.length - 2]; + ancestor.start = Number.parseInt(this.sliceSerialize(token), 10); + this.data.expectingFirstListItemValue = undefined; + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfenceinfo() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.lang = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfencemeta() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.meta = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefencedfence() { + // Exit if this is the closing fence. + if (this.data.flowCodeInside) return; + this.buffer(); + this.data.flowCodeInside = true; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodefenced() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, ''); + this.data.flowCodeInside = undefined; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcodeindented() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.value = data.replace(/(\r?\n|\r)$/g, ''); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitionlabelstring(token) { + const label = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.label = label; + node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase(); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitiontitlestring() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.title = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitdefinitiondestinationstring() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.url = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitatxheadingsequence(token) { + const node = this.stack[this.stack.length - 1]; + if (!node.depth) { + const depth = this.sliceSerialize(token).length; + node.depth = depth; + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheadingtext() { + this.data.setextHeadingSlurpLineEnding = true; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheadinglinesequence(token) { + const node = this.stack[this.stack.length - 1]; + node.depth = this.sliceSerialize(token).codePointAt(0) === 61 ? 1 : 2; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitsetextheading() { + this.data.setextHeadingSlurpLineEnding = undefined; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onenterdata(token) { + const node = this.stack[this.stack.length - 1]; + /** @type {Array} */ + const siblings = node.children; + let tail = siblings[siblings.length - 1]; + if (!tail || tail.type !== 'text') { + // Add a new text node. + tail = text(); + tail.position = { + start: point(token.start), + // @ts-expect-error: we’ll add `end` later. + end: undefined + }; + siblings.push(tail); + } + this.stack.push(tail); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitdata(token) { + const tail = this.stack.pop(); + tail.value += this.sliceSerialize(token); + tail.position.end = point(token.end); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlineending(token) { + const context = this.stack[this.stack.length - 1]; + // If we’re at a hard break, include the line ending in there. + if (this.data.atHardBreak) { + const tail = context.children[context.children.length - 1]; + tail.position.end = point(token.end); + this.data.atHardBreak = undefined; + return; + } + if (!this.data.setextHeadingSlurpLineEnding && config.canContainEols.includes(context.type)) { + onenterdata.call(this, token); + onexitdata.call(this, token); + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithardbreak() { + this.data.atHardBreak = true; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithtmlflow() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.value = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexithtmltext() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.value = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitcodetext() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.value = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlink() { + const node = this.stack[this.stack.length - 1]; + // Note: there are also `identifier` and `label` fields on this link node! + // These are used / cleaned here. + + // To do: clean. + if (this.data.inReference) { + /** @type {ReferenceType} */ + const referenceType = this.data.referenceType || 'shortcut'; + node.type += 'Reference'; + // @ts-expect-error: mutate. + node.referenceType = referenceType; + // @ts-expect-error: mutate. + delete node.url; + delete node.title; + } else { + // @ts-expect-error: mutate. + delete node.identifier; + // @ts-expect-error: mutate. + delete node.label; + } + this.data.referenceType = undefined; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitimage() { + const node = this.stack[this.stack.length - 1]; + // Note: there are also `identifier` and `label` fields on this link node! + // These are used / cleaned here. + + // To do: clean. + if (this.data.inReference) { + /** @type {ReferenceType} */ + const referenceType = this.data.referenceType || 'shortcut'; + node.type += 'Reference'; + // @ts-expect-error: mutate. + node.referenceType = referenceType; + // @ts-expect-error: mutate. + delete node.url; + delete node.title; + } else { + // @ts-expect-error: mutate. + delete node.identifier; + // @ts-expect-error: mutate. + delete node.label; + } + this.data.referenceType = undefined; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlabeltext(token) { + const string = this.sliceSerialize(token); + const ancestor = this.stack[this.stack.length - 2]; + // @ts-expect-error: stash this on the node, as it might become a reference + // later. + ancestor.label = decodeString(string); + // @ts-expect-error: same as above. + ancestor.identifier = normalizeIdentifier(string).toLowerCase(); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitlabel() { + const fragment = this.stack[this.stack.length - 1]; + const value = this.resume(); + const node = this.stack[this.stack.length - 1]; + // Assume a reference. + this.data.inReference = true; + if (node.type === 'link') { + /** @type {Array} */ + const children = fragment.children; + node.children = children; + } else { + node.alt = value; + } + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresourcedestinationstring() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.url = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresourcetitlestring() { + const data = this.resume(); + const node = this.stack[this.stack.length - 1]; + node.title = data; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitresource() { + this.data.inReference = undefined; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onenterreference() { + this.data.referenceType = 'collapsed'; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitreferencestring(token) { + const label = this.resume(); + const node = this.stack[this.stack.length - 1]; + // @ts-expect-error: stash this on the node, as it might become a reference + // later. + node.label = label; + // @ts-expect-error: same as above. + node.identifier = normalizeIdentifier(this.sliceSerialize(token)).toLowerCase(); + this.data.referenceType = 'full'; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + + function onexitcharacterreferencemarker(token) { + this.data.characterReferenceType = token.type; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcharacterreferencevalue(token) { + const data = this.sliceSerialize(token); + const type = this.data.characterReferenceType; + /** @type {string} */ + let value; + if (type) { + value = decodeNumericCharacterReference(data, type === "characterReferenceMarkerNumeric" ? 10 : 16); + this.data.characterReferenceType = undefined; + } else { + const result = decodeNamedCharacterReference(data); + value = result; + } + const tail = this.stack[this.stack.length - 1]; + tail.value += value; + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitcharacterreference(token) { + const tail = this.stack.pop(); + tail.position.end = point(token.end); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitautolinkprotocol(token) { + onexitdata.call(this, token); + const node = this.stack[this.stack.length - 1]; + node.url = this.sliceSerialize(token); + } + + /** + * @this {CompileContext} + * @type {Handle} + */ + function onexitautolinkemail(token) { + onexitdata.call(this, token); + const node = this.stack[this.stack.length - 1]; + node.url = 'mailto:' + this.sliceSerialize(token); + } + + // + // Creaters. + // + + /** @returns {Blockquote} */ + function blockQuote() { + return { + type: 'blockquote', + children: [] + }; + } + + /** @returns {Code} */ + function codeFlow() { + return { + type: 'code', + lang: null, + meta: null, + value: '' + }; + } + + /** @returns {InlineCode} */ + function codeText() { + return { + type: 'inlineCode', + value: '' + }; + } + + /** @returns {Definition} */ + function definition() { + return { + type: 'definition', + identifier: '', + label: null, + title: null, + url: '' + }; + } + + /** @returns {Emphasis} */ + function emphasis() { + return { + type: 'emphasis', + children: [] + }; + } + + /** @returns {Heading} */ + function heading() { + return { + type: 'heading', + // @ts-expect-error `depth` will be set later. + depth: 0, + children: [] + }; + } + + /** @returns {Break} */ + function hardBreak() { + return { + type: 'break' + }; + } + + /** @returns {Html} */ + function html() { + return { + type: 'html', + value: '' + }; + } + + /** @returns {Image} */ + function image() { + return { + type: 'image', + title: null, + url: '', + alt: null + }; + } + + /** @returns {Link} */ + function link() { + return { + type: 'link', + title: null, + url: '', + children: [] + }; + } + + /** + * @param {Token} token + * @returns {List} + */ + function list(token) { + return { + type: 'list', + ordered: token.type === 'listOrdered', + start: null, + spread: token._spread, + children: [] + }; + } + + /** + * @param {Token} token + * @returns {ListItem} + */ + function listItem(token) { + return { + type: 'listItem', + spread: token._spread, + checked: null, + children: [] + }; + } + + /** @returns {Paragraph} */ + function paragraph() { + return { + type: 'paragraph', + children: [] + }; + } + + /** @returns {Strong} */ + function strong() { + return { + type: 'strong', + children: [] + }; + } + + /** @returns {Text} */ + function text() { + return { + type: 'text', + value: '' + }; + } + + /** @returns {ThematicBreak} */ + function thematicBreak() { + return { + type: 'thematicBreak' + }; + } +} + +/** + * Copy a point-like value. + * + * @param {Point} d + * Point-like value. + * @returns {Point} + * unist point. + */ +function point(d) { + return { + line: d.line, + column: d.column, + offset: d.offset + }; +} + +/** + * @param {Config} combined + * @param {Array | Extension>} extensions + * @returns {undefined} + */ +function configure(combined, extensions) { + let index = -1; + while (++index < extensions.length) { + const value = extensions[index]; + if (Array.isArray(value)) { + configure(combined, value); + } else { + extension(combined, value); + } + } +} + +/** + * @param {Config} combined + * @param {Extension} extension + * @returns {undefined} + */ +function extension(combined, extension) { + /** @type {keyof Extension} */ + let key; + for (key in extension) { + if (own.call(extension, key)) { + switch (key) { + case 'canContainEols': + { + const right = extension[key]; + if (right) { + combined[key].push(...right); + } + break; + } + case 'transforms': + { + const right = extension[key]; + if (right) { + combined[key].push(...right); + } + break; + } + case 'enter': + case 'exit': + { + const right = extension[key]; + if (right) { + Object.assign(combined[key], right); + } + break; + } + // No default + } + } + } +} + +/** @type {OnEnterError} */ +function defaultOnError(left, right) { + if (left) { + throw new Error('Cannot close `' + left.type + '` (' + stringifyPosition({ + start: left.start, + end: left.end + }) + '): a different token (`' + right.type + '`, ' + stringifyPosition({ + start: right.start, + end: right.end + }) + ') is open'); + } else { + throw new Error('Cannot close document, a token (`' + right.type + '`, ' + stringifyPosition({ + start: right.start, + end: right.end + }) + ') is still open'); + } +} \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/lib/types.d.ts b/node_modules/mdast-util-from-markdown/lib/types.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..710de761b176901337cab011c8936732f01fb750 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/lib/types.d.ts @@ -0,0 +1,295 @@ +import type {Nodes, Parent, PhrasingContent, Root} from 'mdast' +import type {ParseOptions, Token} from 'micromark-util-types' + +/** + * Compiler context. + */ +export interface CompileContext { + /** + * Configuration. + */ + config: Config + /** + * Info passed around; + * key/value store. + */ + data: CompileData + /** + * Stack of nodes. + */ + stack: Array + /** + * Stack of tokens. + */ + tokenStack: Array + + /** + * Capture some of the output data. + * + * @param this + * Context. + * @returns + * Nothing. + */ + buffer(this: CompileContext): undefined + + /** + * Enter a node. + * + * @param this + * Context. + * @param node + * Node. + * @param token + * Token. + * @param onError + * Error handler. + * @returns + * Nothing. + */ + enter( + this: CompileContext, + node: Nodes, + token: Token, + onError?: OnEnterError | null | undefined + ): undefined + + /** + * Exit a node. + * + * @param this + * Context. + * @param token + * Token. + * @param onError + * Error handler. + * @returns + * Nothing. + */ + exit( + this: CompileContext, + token: Token, + onError?: OnExitError | null | undefined + ): undefined + + /** + * Stop capturing and access the output data. + * + * @param this + * Context. + * @returns + * Nothing. + */ + resume(this: CompileContext): string + + /** + * Get the source text that spans a token (or location). + * + * @param token + * Start/end in stream. + * @param expandTabs + * Whether to expand tabs. + * @returns + * Serialized chunks. + */ + sliceSerialize( + token: Pick, + expandTabs?: boolean | undefined + ): string +} + +/** + * Interface of tracked data. + * + * When working on extensions that use more data, extend the corresponding + * interface to register their types: + * + * ```ts + * declare module 'mdast-util-from-markdown' { + * interface CompileData { + * // Register a new field. + * mathFlowInside?: boolean | undefined + * } + * } + * ``` + */ +export interface CompileData { + /** + * Whether we’re inside a hard break. + */ + atHardBreak?: boolean | undefined + + /** + * Current character reference type. + */ + characterReferenceType?: + | 'characterReferenceMarkerHexadecimal' + | 'characterReferenceMarkerNumeric' + | undefined + + /** + * Whether a first list item value (`1` in `1. a`) is expected. + */ + expectingFirstListItemValue?: boolean | undefined + + /** + * Whether we’re in flow code. + */ + flowCodeInside?: boolean | undefined + + /** + * Whether we’re in a reference. + */ + inReference?: boolean | undefined + + /** + * Whether we’re expecting a line ending from a setext heading, which can be slurped. + */ + setextHeadingSlurpLineEnding?: boolean | undefined + + /** + * Current reference. + */ + referenceType?: 'collapsed' | 'full' | undefined +} + +/** + * Configuration. + * + * We have our defaults, but extensions will add more. + */ +export interface Config { + /** + * Token types where line endings are used. + */ + canContainEols: Array + /** + * Opening handles. + */ + enter: Handles + /** + * Closing handles. + */ + exit: Handles + /** + * Tree transforms. + */ + transforms: Array +} + +/** + * Change how markdown tokens from micromark are turned into mdast. + */ +export interface Extension { + /** + * Token types where line endings are used. + */ + canContainEols?: Array | null | undefined + /** + * Opening handles. + */ + enter?: Handles | null | undefined + /** + * Closing handles. + */ + exit?: Handles | null | undefined + /** + * Tree transforms. + */ + transforms?: Array | null | undefined +} + +/** + * Internal fragment. + */ +export interface Fragment extends Parent { + /** + * Node type. + */ + type: 'fragment' + /** + * Children. + */ + children: Array +} + +/** + * Token types mapping to handles + */ +export type Handles = Record + +/** + * Handle a token. + * + * @param this + * Context. + * @param token + * Current token. + * @returns + * Nothing. + */ +export type Handle = (this: CompileContext, token: Token) => undefined | void + +/** + * Handle the case where the `right` token is open, but it is closed (by the + * `left` token) or because we reached the end of the document. + * + * @param this + * Context. + * @param left + * Left token. + * @param right + * Right token. + * @returns + * Nothing. + */ +export type OnEnterError = ( + this: Omit, + left: Token | undefined, + right: Token +) => undefined + +/** + * Handle the case where the `right` token is open but it is closed by + * exiting the `left` token. + * + * @param this + * Context. + * @param left + * Left token. + * @param right + * Right token. + * @returns + * Nothing. + */ +export type OnExitError = ( + this: Omit, + left: Token, + right: Token +) => undefined + +/** + * Configuration. + */ +export interface Options extends ParseOptions { + /** + * Extensions for this utility to change how tokens are turned into a tree. + */ + mdastExtensions?: Array> | null | undefined +} + +/** + * Open token on the stack, + * with an optional error handler for when that token isn’t closed properly. + */ +export type TokenTuple = [token: Token, onError: OnEnterError | undefined] + +/** + * Extra transform, to change the AST afterwards. + * + * @param tree + * Tree to transform. + * @returns + * New tree or nothing (in which case the current tree is used). + */ +export type Transform = (tree: Root) => Root | null | undefined | void diff --git a/node_modules/mdast-util-from-markdown/lib/types.js b/node_modules/mdast-util-from-markdown/lib/types.js new file mode 100644 index 0000000000000000000000000000000000000000..ca675127ea334eb9ba12098a41f386e9a772f724 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/lib/types.js @@ -0,0 +1,2 @@ +// Note: types exposed from `types.d.ts`. +export {}; \ No newline at end of file diff --git a/node_modules/mdast-util-from-markdown/license b/node_modules/mdast-util-from-markdown/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/mdast-util-from-markdown/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-from-markdown/package.json b/node_modules/mdast-util-from-markdown/package.json new file mode 100644 index 0000000000000000000000000000000000000000..98291885f91ba36a7d457b75a12ab04f4ee1f5db --- /dev/null +++ b/node_modules/mdast-util-from-markdown/package.json @@ -0,0 +1,99 @@ +{ + "author": "Titus Wormer (https://wooorm.com)", + "bugs": "https://github.com/syntax-tree/mdast-util-from-markdown/issues", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "mdast-util-to-string": "^4.0.0", + "micromark": "^4.0.0", + "micromark-util-decode-numeric-character-reference": "^2.0.0", + "micromark-util-decode-string": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "description": "mdast utility to parse markdown", + "devDependencies": { + "@types/node": "^25.0.0", + "c8": "^10.0.0", + "commonmark.json": "^0.31.0", + "esbuild": "^0.27.0", + "gzip-size-cli": "^5.0.0", + "hast-util-from-html": "^2.0.0", + "hast-util-to-html": "^9.0.0", + "mdast-util-to-hast": "^13.0.0", + "micromark-build": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^11.0.0", + "terser": "^5.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^1.0.0" + }, + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "files": [ + "dev/", + "lib/", + "index.d.ts", + "index.js" + ], + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "keywords": [ + "ast", + "markdown", + "markup", + "mdast-util", + "mdast", + "parse", + "syntax", + "tree", + "unist", + "utility", + "util" + ], + "license": "MIT", + "name": "mdast-util-from-markdown", + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "repository": "syntax-tree/mdast-util-from-markdown", + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build && esbuild . --bundle --minify | terser | gzip-size --raw", + "format": "remark --frail --quiet --output -- . && prettier --log-level warn --write -- . && xo --fix", + "test-api-dev": "node --conditions development test/index.js", + "test-api-prod": "node --conditions production test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov -- npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "sideEffects": false, + "typeCoverage": { + "atLeast": 100, + "strict": true + }, + "type": "module", + "version": "2.0.3" +} diff --git a/node_modules/mdast-util-from-markdown/readme.md b/node_modules/mdast-util-from-markdown/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..48ad08d02330112e4d3e0986396cc44cb45da013 --- /dev/null +++ b/node_modules/mdast-util-from-markdown/readme.md @@ -0,0 +1,535 @@ +# mdast-util-from-markdown + +[![Build][badge-build-image]][badge-build-url] +[![Coverage][badge-coverage-image]][badge-coverage-url] +[![Downloads][badge-downloads-image]][badge-downloads-url] +[![Size][badge-size-image]][badge-size-url] + +**[mdast][github-mdast]** utility that turns markdown into a syntax tree. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`fromMarkdown(value[, encoding][, options])`](#frommarkdownvalue-encoding-options) + * [`CompileContext`](#compilecontext) + * [`CompileData`](#compiledata) + * [`Encoding`](#encoding) + * [`Extension`](#extension) + * [`Handle`](#handle) + * [`OnEnterError`](#onentererror) + * [`OnExitError`](#onexiterror) + * [`Options`](#options) + * [`Token`](#token) + * [`Transform`](#transform) + * [`Value`](#value) +* [List of extensions](#list-of-extensions) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a utility that takes markdown input and turns it into an +[mdast][github-mdast] syntax tree. + +This utility uses [`micromark`][github-micromark], +which turns markdown into tokens, +and then turns those tokens into nodes. +This package is used inside [`remark-parse`][github-remark-parse], +which focusses on +making it easier to transform content by abstracting these internals away. + +## When should I use this? + +If you want to handle syntax trees manually, use this. +When you *just* want to turn markdown into HTML, +use [`micromark`][github-micromark] instead. +For an easier time processing content, +use the **[remark][github-remark]** ecosystem instead. + +You can combine this package with other packages to add syntax extensions to +markdown. +Notable examples that deeply integrate with this package are +[`mdast-util-mdx`][github-mdast-util-mdx], +[`mdast-util-gfm`][github-mdast-util-gfm], +[`mdast-util-frontmatter`][github-mdast-util-frontmatter], +[`mdast-util-math`][github-mdast-util-math], and +[`mdast-util-directive`][github-mdast-util-directive]. + +## Install + +This package is [ESM only][github-gist-esm]. +In Node.js (version 16+), install with [npm][npmjs-install]: + +```sh +npm install mdast-util-from-markdown +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {fromMarkdown} from 'https://esm.sh/mdast-util-from-markdown@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say we have the following markdown file `example.md`: + +```markdown +## Hello, *World*! +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {fromMarkdown} from 'mdast-util-from-markdown' + +const doc = await fs.readFile('example.md') +const tree = fromMarkdown(doc) + +console.log(tree) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'heading', + depth: 2, + children: [ + {type: 'text', value: 'Hello, '}, + {type: 'emphasis', children: [{type: 'text', value: 'World'}]}, + {type: 'text', value: '!'} + ] + } + ] +} +``` + +## API + +This package exports the identifier [`fromMarkdown`][api-from-markdown]. +There is no default export. + +The export map supports the [`development` condition][node-packages-conditions]. +Run `node --conditions development example.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `fromMarkdown(value[, encoding][, options])` + +Turn markdown into a syntax tree. + +###### Overloads + +* `(value: Value, encoding: Encoding, options?: Options) => Root` +* `(value: Value, options?: Options) => Root` + +###### Parameters + +* `value` ([`Value`][api-value]) + — markdown to parse +* `encoding` ([`Encoding`][api-encoding], default: `'utf8'`) + — [character encoding][node-util-encoding] for when `value` is + [`Uint8Array`][mozilla-uint8-array] +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +mdast tree ([`Root`][github-mdast-root]). + +### `CompileContext` + +mdast compiler context (TypeScript type). + +###### Fields + +* `stack` ([`Array`][github-mdast-nodes]) + — stack of nodes +* `tokenStack` (`Array<[Token, OnEnterError | undefined]>`) + — stack of tokens +* `data` ([`CompileData`][api-compile-data]) + — info passed around; key/value store +* `buffer` (`() => undefined`) + — capture some of the output data +* `resume` (`() => string`) + — stop capturing and access the output data +* `enter` (`(node: Node, token: Token, onError?: OnEnterError) => undefined`) + — enter a node +* `exit` (`(token: Token, onError?: OnExitError) => undefined`) + — exit a node +* `sliceSerialize` (`(token: Token, expandTabs?: boolean) => string`) + — get the string value of a token +* `config` (`Required`) + — configuration + +### `CompileData` + +Interface of tracked data (TypeScript type). + +###### Type + +```ts +interface CompileData { /* see code */ } +``` + +When working on extensions that use more data, extend the corresponding +interface to register their types: + +```ts +declare module 'mdast-util-from-markdown' { + interface CompileData { + // Register a new field. + mathFlowInside?: boolean | undefined + } +} +``` + +### `Encoding` + +Encodings supported by the [`Uint8Array`][mozilla-uint8-array] class +(TypeScript type). + +See [`micromark`][github-micromark-api] for more info. + +###### Type + +```ts +type Encoding = 'utf8' | /* … */ +``` + +### `Extension` + +Change how markdown tokens from micromark are turned into mdast (TypeScript +type). + +###### Properties + +* `canContainEols` (`Array`, optional) + — token types where line endings are used +* `enter` ([`Record`][api-handle], optional) + — opening handles +* `exit` ([`Record`][api-handle], optional) + — closing handles +* `transforms` ([`Array`][api-transform], optional) + — tree transforms + +### `Handle` + +Handle a token (TypeScript type). + +###### Parameters + +* `this` ([`CompileContext`][api-compile-context]) + — context +* `token` ([`Token`][api-token]) + — current token + +###### Returns + +Nothing (`undefined`). + +### `OnEnterError` + +Handle the case where the `right` token is open, but it is closed (by the +`left` token) or because we reached the end of the document (TypeScript type). + +###### Parameters + +* `this` ([`CompileContext`][api-compile-context]) + — context +* `left` ([`Token`][api-token] or `undefined`) + — left token +* `right` ([`Token`][api-token]) + — right token + +###### Returns + +Nothing (`undefined`). + +### `OnExitError` + +Handle the case where the `right` token is open but it is closed by +exiting the `left` token (TypeScript type). + +###### Parameters + +* `this` ([`CompileContext`][api-compile-context]) + — context +* `left` ([`Token`][api-token]) + — left token +* `right` ([`Token`][api-token]) + — right token + +###### Returns + +Nothing (`undefined`). + +### `Options` + +Configuration (TypeScript type). + +###### Properties + +* `extensions` + ([`Array`][github-micromark-extension], optional) + — micromark extensions to change how markdown is parsed +* `mdastExtensions` + ([`Array>`][api-extension], + optional) + — extensions for this utility to change how tokens are turned into a tree + +### `Token` + +Token from micromark (TypeScript type). + +###### Type + +```ts +type Token = { /* … */ } +``` + +### `Transform` + +Extra transform, to change the AST afterwards (TypeScript type). + +###### Parameters + +* `tree` ([`Root`][github-mdast-root]) + — tree to transform + +###### Returns + +New tree ([`Root`][github-mdast-root]) or nothing +(in which case the current tree is used). + +### `Value` + +Contents of the file (TypeScript type). + +See [`micromark`][github-micromark-api] for more info. + +###### Type + +```ts +type Value = Uint8Array | string +``` + +## List of extensions + +* [`syntax-tree/mdast-util-directive`][github-mdast-util-directive] + — directives +* [`syntax-tree/mdast-util-frontmatter`][github-mdast-util-frontmatter] + — frontmatter (YAML, TOML, more) +* [`syntax-tree/mdast-util-gfm`][github-mdast-util-gfm] + — GFM +* [`syntax-tree/mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal) + — GFM autolink literals +* [`syntax-tree/mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote) + — GFM footnotes +* [`syntax-tree/mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough) + — GFM strikethrough +* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table) + — GFM tables +* [`syntax-tree/mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item) + — GFM task list items +* [`syntax-tree/mdast-util-math`][github-mdast-util-math] + — math +* [`syntax-tree/mdast-util-mdx`][github-mdast-util-mdx] + — MDX +* [`syntax-tree/mdast-util-mdx-expression`](https://github.com/syntax-tree/mdast-util-mdx-expression) + — MDX expressions +* [`syntax-tree/mdast-util-mdx-jsx`](https://github.com/syntax-tree/mdast-util-mdx-jsx) + — MDX JSX +* [`syntax-tree/mdast-util-mdxjs-esm`](https://github.com/syntax-tree/mdast-util-mdxjs-esm) + — MDX ESM + +## Syntax + +Markdown is parsed according to CommonMark. +Extensions can add support for other syntax. +If you’re interested in extending markdown, +[more information is available in micromark’s +readme][github-micromark-extension]. + +## Syntax tree + +The syntax tree is [mdast][github-mdast]. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types +[`CompileContext`][api-compile-context], +[`CompileData`][api-compile-data], +[`Encoding`][api-encoding], +[`Extension`][api-extension], +[`Handle`][api-handle], +[`OnEnterError`][api-on-enter-error], +[`OnExitError`][api-on-exit-error], +[`Options`][api-options], +[`Token`][api-token], +[`Transform`][api-transform], and +[`Value`][api-value]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-from-markdown@^2`, compatible with Node.js 16. + +## Security + +As markdown is sometimes used for HTML, and improper use of HTML can open you up +to a [cross-site scripting (XSS)][wikipedia-xss] attack, use of `mdast-util-from-markdown` +can also be unsafe. +When going to HTML, use this utility in combination with +[`hast-util-sanitize`][github-hast-util-sanitize] to make the tree safe. + +## Related + +* [`syntax-tree/mdast-util-to-markdown`](https://github.com/syntax-tree/mdast-util-to-markdown) + — serialize mdast as markdown +* [`micromark/micromark`][github-micromark] + — parse markdown +* [`remarkjs/remark`][github-remark] + — process markdown + +## Contribute + +See [`contributing.md`][health-contributing] +in +[`syntax-tree/.github`][health] +for ways to get started. +See [`support.md`][health-support] for ways to get help. + +This project has a [code of conduct][health-coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][file-license] © [Titus Wormer][wooorm] + + + +[api-compile-context]: #compilecontext + +[api-compile-data]: #compiledata + +[api-encoding]: #encoding + +[api-extension]: #extension + +[api-from-markdown]: #frommarkdownvalue-encoding-options + +[api-handle]: #handle + +[api-on-enter-error]: #onentererror + +[api-on-exit-error]: #onexiterror + +[api-options]: #options + +[api-token]: #token + +[api-transform]: #transform + +[api-value]: #value + +[badge-build-image]: https://github.com/syntax-tree/mdast-util-from-markdown/workflows/main/badge.svg + +[badge-build-url]: https://github.com/syntax-tree/mdast-util-from-markdown/actions + +[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-from-markdown.svg + +[badge-coverage-url]: https://codecov.io/github/syntax-tree/mdast-util-from-markdown + +[badge-downloads-image]: https://img.shields.io/npm/dm/mdast-util-from-markdown.svg + +[badge-downloads-url]: https://www.npmjs.com/package/mdast-util-from-markdown + +[badge-size-image]: https://img.shields.io/bundlejs/size/mdast-util-from-markdown + +[badge-size-url]: https://bundlejs.com/?q=mdast-util-from-markdown + +[esmsh]: https://esm.sh + +[file-license]: license + +[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize + +[github-mdast]: https://github.com/syntax-tree/mdast + +[github-mdast-nodes]: https://github.com/syntax-tree/mdast#nodes + +[github-mdast-root]: https://github.com/syntax-tree/mdast#root + +[github-mdast-util-directive]: https://github.com/syntax-tree/mdast-util-directive + +[github-mdast-util-frontmatter]: https://github.com/syntax-tree/mdast-util-frontmatter + +[github-mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[github-mdast-util-math]: https://github.com/syntax-tree/mdast-util-math + +[github-mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx + +[github-micromark]: https://github.com/micromark/micromark + +[github-micromark-api]: https://github.com/micromark/micromark/tree/main/packages/micromark#micromarkvalue-encoding-options + +[github-micromark-extension]: https://github.com/micromark/micromark#extensions + +[github-remark]: https://github.com/remarkjs/remark + +[github-remark-parse]: https://github.com/remarkjs/remark/tree/main/packages/remark-parse + +[health]: https://github.com/syntax-tree/.github + +[health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[health-support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[mozilla-uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array + +[node-packages-conditions]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[node-util-encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings + +[npmjs-install]: https://docs.npmjs.com/cli/install + +[typescript]: https://www.typescriptlang.org + +[wikipedia-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[wooorm]: https://wooorm.com diff --git a/node_modules/mdast-util-gfm-autolink-literal/index.d.ts b/node_modules/mdast-util-gfm-autolink-literal/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa02be6f86bcdbc1d586013becb8d1738bc922b9 --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/index.d.ts @@ -0,0 +1 @@ +export { gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown } from "./lib/index.js"; diff --git a/node_modules/mdast-util-gfm-autolink-literal/index.js b/node_modules/mdast-util-gfm-autolink-literal/index.js new file mode 100644 index 0000000000000000000000000000000000000000..029dcffb0070863a1b7d2458818b153db36647f7 --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/index.js @@ -0,0 +1,4 @@ +export { + gfmAutolinkLiteralFromMarkdown, + gfmAutolinkLiteralToMarkdown +} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-autolink-literal/lib/index.d.ts b/node_modules/mdast-util-gfm-autolink-literal/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ccd2bd554c3ce3f9543e276677bb594b79a12e2d --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/lib/index.d.ts @@ -0,0 +1,18 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM autolink + * literals in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM autolink literals. + */ +export function gfmAutolinkLiteralFromMarkdown(): FromMarkdownExtension; +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM autolink + * literals in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM autolink literals. + */ +export function gfmAutolinkLiteralToMarkdown(): ToMarkdownExtension; +import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'; +import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'; diff --git a/node_modules/mdast-util-gfm-autolink-literal/lib/index.js b/node_modules/mdast-util-gfm-autolink-literal/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c5ca771c24dd914e342f791716a822431ee32b3a --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/lib/index.js @@ -0,0 +1,280 @@ +/** + * @import {RegExpMatchObject, ReplaceFunction} from 'mdast-util-find-and-replace' + * @import {CompileContext, Extension as FromMarkdownExtension, Handle as FromMarkdownHandle, Transform as FromMarkdownTransform} from 'mdast-util-from-markdown' + * @import {ConstructName, Options as ToMarkdownExtension} from 'mdast-util-to-markdown' + * @import {Link, PhrasingContent} from 'mdast' + */ + +import {ccount} from 'ccount' +import {ok as assert} from 'devlop' +import {unicodePunctuation, unicodeWhitespace} from 'micromark-util-character' +import {findAndReplace} from 'mdast-util-find-and-replace' + +/** @type {ConstructName} */ +const inConstruct = 'phrasing' +/** @type {Array} */ +const notInConstruct = ['autolink', 'link', 'image', 'label'] + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM autolink + * literals in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM autolink literals. + */ +export function gfmAutolinkLiteralFromMarkdown() { + return { + transforms: [transformGfmAutolinkLiterals], + enter: { + literalAutolink: enterLiteralAutolink, + literalAutolinkEmail: enterLiteralAutolinkValue, + literalAutolinkHttp: enterLiteralAutolinkValue, + literalAutolinkWww: enterLiteralAutolinkValue + }, + exit: { + literalAutolink: exitLiteralAutolink, + literalAutolinkEmail: exitLiteralAutolinkEmail, + literalAutolinkHttp: exitLiteralAutolinkHttp, + literalAutolinkWww: exitLiteralAutolinkWww + } + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM autolink + * literals in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM autolink literals. + */ +export function gfmAutolinkLiteralToMarkdown() { + return { + unsafe: [ + { + character: '@', + before: '[+\\-.\\w]', + after: '[\\-.\\w]', + inConstruct, + notInConstruct + }, + { + character: '.', + before: '[Ww]', + after: '[\\-.\\w]', + inConstruct, + notInConstruct + }, + { + character: ':', + before: '[ps]', + after: '\\/', + inConstruct, + notInConstruct + } + ] + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterLiteralAutolink(token) { + this.enter({type: 'link', title: null, url: '', children: []}, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterLiteralAutolinkValue(token) { + this.config.enter.autolinkProtocol.call(this, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitLiteralAutolinkHttp(token) { + this.config.exit.autolinkProtocol.call(this, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitLiteralAutolinkWww(token) { + this.config.exit.data.call(this, token) + const node = this.stack[this.stack.length - 1] + assert(node.type === 'link') + node.url = 'http://' + this.sliceSerialize(token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitLiteralAutolinkEmail(token) { + this.config.exit.autolinkEmail.call(this, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitLiteralAutolink(token) { + this.exit(token) +} + +/** @type {FromMarkdownTransform} */ +function transformGfmAutolinkLiterals(tree) { + findAndReplace( + tree, + [ + [/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl], + [/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu, findEmail] + ], + {ignore: ['link', 'linkReference']} + ) +} + +/** + * @type {ReplaceFunction} + * @param {string} _ + * @param {string} protocol + * @param {string} domain + * @param {string} path + * @param {RegExpMatchObject} match + * @returns {Array | Link | false} + */ +// eslint-disable-next-line max-params +function findUrl(_, protocol, domain, path, match) { + let prefix = '' + + // Not an expected previous character. + if (!previous(match)) { + return false + } + + // Treat `www` as part of the domain. + if (/^w/i.test(protocol)) { + domain = protocol + domain + protocol = '' + prefix = 'http://' + } + + if (!isCorrectDomain(domain)) { + return false + } + + const parts = splitUrl(domain + path) + + if (!parts[0]) return false + + /** @type {Link} */ + const result = { + type: 'link', + title: null, + url: prefix + protocol + parts[0], + children: [{type: 'text', value: protocol + parts[0]}] + } + + if (parts[1]) { + return [result, {type: 'text', value: parts[1]}] + } + + return result +} + +/** + * @type {ReplaceFunction} + * @param {string} _ + * @param {string} atext + * @param {string} label + * @param {RegExpMatchObject} match + * @returns {Link | false} + */ +function findEmail(_, atext, label, match) { + if ( + // Not an expected previous character. + !previous(match, true) || + // Label ends in not allowed character. + /[-\d_]$/.test(label) + ) { + return false + } + + return { + type: 'link', + title: null, + url: 'mailto:' + atext + '@' + label, + children: [{type: 'text', value: atext + '@' + label}] + } +} + +/** + * @param {string} domain + * @returns {boolean} + */ +function isCorrectDomain(domain) { + const parts = domain.split('.') + + if ( + parts.length < 2 || + (parts[parts.length - 1] && + (/_/.test(parts[parts.length - 1]) || + !/[a-zA-Z\d]/.test(parts[parts.length - 1]))) || + (parts[parts.length - 2] && + (/_/.test(parts[parts.length - 2]) || + !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) + ) { + return false + } + + return true +} + +/** + * @param {string} url + * @returns {[string, string | undefined]} + */ +function splitUrl(url) { + const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url) + + if (!trailExec) { + return [url, undefined] + } + + url = url.slice(0, trailExec.index) + + let trail = trailExec[0] + let closingParenIndex = trail.indexOf(')') + const openingParens = ccount(url, '(') + let closingParens = ccount(url, ')') + + while (closingParenIndex !== -1 && openingParens > closingParens) { + url += trail.slice(0, closingParenIndex + 1) + trail = trail.slice(closingParenIndex + 1) + closingParenIndex = trail.indexOf(')') + closingParens++ + } + + return [url, trail] +} + +/** + * @param {RegExpMatchObject} match + * @param {boolean | null | undefined} [email=false] + * @returns {boolean} + */ +function previous(match, email) { + const code = match.input.charCodeAt(match.index - 1) + + return ( + (match.index === 0 || + unicodeWhitespace(code) || + unicodePunctuation(code)) && + // If it’s an email, the previous character should not be a slash. + (!email || code !== 47) + ) +} diff --git a/node_modules/mdast-util-gfm-autolink-literal/license b/node_modules/mdast-util-gfm-autolink-literal/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm-autolink-literal/package.json b/node_modules/mdast-util-gfm-autolink-literal/package.json new file mode 100644 index 0000000000000000000000000000000000000000..b0fea137d57a27c515a5e9c91ef5b093437905c8 --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/package.json @@ -0,0 +1,106 @@ +{ + "name": "mdast-util-gfm-autolink-literal", + "version": "2.0.1", + "description": "mdast extension to parse and serialize GFM autolink literals", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "autolink", + "auto", + "link", + "literal", + "url", + "raw", + "gfm" + ], + "repository": "syntax-tree/mdast-util-gfm-autolink-literal", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "ccount": "^2.0.0", + "devlop": "^1.0.0", + "mdast-util-find-and-replace": "^3.0.0", + "micromark-util-character": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^22.0.0", + "c8": "^10.0.0", + "hast-util-to-html": "^9.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-hast": "^13.0.0", + "mdast-util-to-markdown": "^2.0.0", + "micromark-extension-gfm-autolink-literal": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.59.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": "test/**/*.js", + "rules": { + "no-await-in-loop": "off" + } + } + ], + "prettier": true, + "rules": { + "unicorn/prefer-at": "off", + "unicorn/prefer-code-point": "off" + } + } +} diff --git a/node_modules/mdast-util-gfm-autolink-literal/readme.md b/node_modules/mdast-util-gfm-autolink-literal/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..309466e2b0c8e1002fb2b075e04f7658ae094440 --- /dev/null +++ b/node_modules/mdast-util-gfm-autolink-literal/readme.md @@ -0,0 +1,334 @@ +# mdast-util-gfm-autolink-literal + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] autolink literals. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmAutolinkLiteralFromMarkdown()`](#gfmautolinkliteralfrommarkdown) + * [`gfmAutolinkLiteralToMarkdown()`](#gfmautolinkliteraltomarkdown) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM autolink literals +syntax in markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +GFM autolinks in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +GFM autolinks in syntax trees to markdown). + +GitHub employs different algorithms to autolink: one at parse time and one at +transform time (similar to how `@mentions` are done at transform time). +This difference can be observed because character references and escapes are +handled differently. +But also because issues/PRs/comments omit (perhaps by accident?) the second +algorithm for `www.`, `http://`, and `https://` links (but not for email links). + +As the corresponding micromark extension +[`micromark-extension-gfm-autolink-literal`][extension] is a syntax extension, +it can only perform the first algorithm. +The tree extension `gfmAutolinkLiteralFromMarkdown` from this package can +perform the second algorithm, and as they are combined, both are done. + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with +[`micromark-extension-gfm-autolink-literal`][extension]. + +When you don’t need a syntax tree, you can use [`micromark`][micromark] +directly with `micromark-extension-gfm-autolink-literal`. + +When you are working with syntax trees and want all of GFM, use +[`mdast-util-gfm`][mdast-util-gfm] instead. + +All these packages are used [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm-autolink-literal +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'https://esm.sh/mdast-util-gfm-autolink-literal@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +www.example.com, https://example.com, and contact@example.com. +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal' +import {fromMarkdown} from 'mdast-util-from-markdown' +import { + gfmAutolinkLiteralFromMarkdown, + gfmAutolinkLiteralToMarkdown +} from 'mdast-util-gfm-autolink-literal' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.md') + +const tree = fromMarkdown(doc, { + extensions: [gfmAutolinkLiteral()], + mdastExtensions: [gfmAutolinkLiteralFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown()]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + { + type: 'link', + title: null, + url: 'http://www.example.com', + children: [{type: 'text', value: 'www.example.com'}] + }, + {type: 'text', value: ', '}, + { + type: 'link', + title: null, + url: 'https://example.com', + children: [{type: 'text', value: 'https://example.com'}] + }, + {type: 'text', value: ', and '}, + { + type: 'link', + title: null, + url: 'mailto:contact@example.com', + children: [{type: 'text', value: 'contact@example.com'}] + }, + {type: 'text', value: '.'} + ] + } + ] +} +``` + +```markdown +[www.example.com](http://www.example.com), , and . +``` + +## API + +This package exports the identifiers +[`gfmAutolinkLiteralFromMarkdown`][api-gfm-autolink-literal-from-markdown] and +[`gfmAutolinkLiteralToMarkdown`][api-gfm-autolink-literal-to-markdown]. +There is no default export. + +### `gfmAutolinkLiteralFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM autolink literals in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM autolink literals +([`FromMarkdownExtension`][from-markdown-extension]). + +### `gfmAutolinkLiteralToMarkdown()` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to +enable GFM autolink literals in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM autolink literals +([`ToMarkdownExtension`][to-markdown-extension]). + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Syntax + +See [Syntax in `micromark-extension-gfm-autolink-literal`][syntax]. + +## Syntax tree + +There are no interfaces added to **[mdast][]** by this utility, as it reuses +the existing **[Link][dfn-link]** interface. + +## Types + +This package is fully typed with [TypeScript][]. +It does not export additional types. + +The `Link` type of the mdast nodes is exposed from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-gfm-autolink-literal@^2`, compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`remarkjs/remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm] + — same but all of GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`micromark/micromark-extension-gfm-autolink-literal`][extension] + — micromark extension to parse GFM autolink literals + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-autolink-literal.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-autolink-literal + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-autolink-literal.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm-autolink-literal + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-autolink-literal + +[size]: https://bundlejs.com/?q=mdast-util-gfm-autolink-literal + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[micromark]: https://github.com/micromark/micromark + +[extension]: https://github.com/micromark/micromark-extension-gfm-autolink-literal + +[syntax]: https://github.com/micromark/micromark-extension-gfm-autolink-literal#syntax + +[gfm]: https://github.github.com/gfm/ + +[dfn-link]: https://github.com/syntax-tree/mdast#link + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[api-gfm-autolink-literal-from-markdown]: #gfmautolinkliteralfrommarkdown + +[api-gfm-autolink-literal-to-markdown]: #gfmautolinkliteraltomarkdown diff --git a/node_modules/mdast-util-gfm-footnote/index.d.ts b/node_modules/mdast-util-gfm-footnote/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..0ff949a35b2cfc43477d5414d990fc0a4c3b4b99 --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/index.d.ts @@ -0,0 +1,34 @@ +export {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from './lib/index.js' + +export interface ToMarkdownOptions { + // To do: next major: change default. + /** + * Use a blank line for the first line of footnote definitions + * (`boolean`, default: `false`). + */ + firstLineBlank?: boolean | null | undefined +} + +declare module 'mdast-util-to-markdown' { + interface ConstructNameMap { + /** + * Footnote definition. + * + * ```markdown + * > | [^a]: B. + * ^^^^^^^^ + * ``` + */ + footnoteDefinition: 'footnoteDefinition' + + /** + * Footnote reference. + * + * ```markdown + * > | A[^b]. + * ^^^^ + * ``` + */ + footnoteReference: 'footnoteReference' + } +} diff --git a/node_modules/mdast-util-gfm-footnote/index.js b/node_modules/mdast-util-gfm-footnote/index.js new file mode 100644 index 0000000000000000000000000000000000000000..be45f3aecf2b3c6b0eccbc9bec658b6177a77157 --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/index.js @@ -0,0 +1,2 @@ +// Note: extra types exported from `index.d.ts`. +export {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-footnote/lib/index.d.ts b/node_modules/mdast-util-gfm-footnote/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..07a032debfa78a483a9f32b5fbf1fa5a1f63880e --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/lib/index.d.ts @@ -0,0 +1,22 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM footnotes + * in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown`. + */ +export function gfmFootnoteFromMarkdown(): FromMarkdownExtension; +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM footnotes + * in markdown. + * + * @param {ToMarkdownOptions | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown`. + */ +export function gfmFootnoteToMarkdown(options?: ToMarkdownOptions | null | undefined): ToMarkdownExtension; +import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'; +import type { ToMarkdownOptions } from 'mdast-util-gfm-footnote'; +import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-gfm-footnote/lib/index.d.ts.map b/node_modules/mdast-util-gfm-footnote/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..2f429c43e76a8c3cc62a9b97b69ea9ee3c333b60 --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA0HA;;;;;;GAMG;AACH,2CAHa,qBAAqB,CAkBjC;AAED;;;;;;;;GAQG;AACH,gDALW,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAElC,mBAAmB,CAiD/B;wDApMS,0BAA0B;uCACA,yBAAyB;oDAKnD,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-gfm-footnote/lib/index.js b/node_modules/mdast-util-gfm-footnote/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..1930f5723719c23a321e9e0aaab890d1cf3d660d --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/lib/index.js @@ -0,0 +1,212 @@ +/** + * @import { + * CompileContext, + * Extension as FromMarkdownExtension, + * Handle as FromMarkdownHandle + * } from 'mdast-util-from-markdown' + * @import {ToMarkdownOptions} from 'mdast-util-gfm-footnote' + * @import { + * Handle as ToMarkdownHandle, + * Map, + * Options as ToMarkdownExtension + * } from 'mdast-util-to-markdown' + * @import {FootnoteDefinition, FootnoteReference} from 'mdast' + */ + +import {ok as assert} from 'devlop' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' + +footnoteReference.peek = footnoteReferencePeek + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterFootnoteCallString() { + this.buffer() +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterFootnoteCall(token) { + this.enter({type: 'footnoteReference', identifier: '', label: ''}, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterFootnoteDefinitionLabelString() { + this.buffer() +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterFootnoteDefinition(token) { + this.enter( + {type: 'footnoteDefinition', identifier: '', label: '', children: []}, + token + ) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitFootnoteCallString(token) { + const label = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node.type === 'footnoteReference') + node.identifier = normalizeIdentifier( + this.sliceSerialize(token) + ).toLowerCase() + node.label = label +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitFootnoteCall(token) { + this.exit(token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitFootnoteDefinitionLabelString(token) { + const label = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node.type === 'footnoteDefinition') + node.identifier = normalizeIdentifier( + this.sliceSerialize(token) + ).toLowerCase() + node.label = label +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitFootnoteDefinition(token) { + this.exit(token) +} + +/** @type {ToMarkdownHandle} */ +function footnoteReferencePeek() { + return '[' +} + +/** + * @type {ToMarkdownHandle} + * @param {FootnoteReference} node + */ +function footnoteReference(node, _, state, info) { + const tracker = state.createTracker(info) + let value = tracker.move('[^') + const exit = state.enter('footnoteReference') + const subexit = state.enter('reference') + value += tracker.move( + state.safe(state.associationId(node), {after: ']', before: value}) + ) + subexit() + exit() + value += tracker.move(']') + return value +} + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM footnotes + * in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown`. + */ +export function gfmFootnoteFromMarkdown() { + return { + enter: { + gfmFootnoteCallString: enterFootnoteCallString, + gfmFootnoteCall: enterFootnoteCall, + gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString, + gfmFootnoteDefinition: enterFootnoteDefinition + }, + exit: { + gfmFootnoteCallString: exitFootnoteCallString, + gfmFootnoteCall: exitFootnoteCall, + gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString, + gfmFootnoteDefinition: exitFootnoteDefinition + } + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM footnotes + * in markdown. + * + * @param {ToMarkdownOptions | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown`. + */ +export function gfmFootnoteToMarkdown(options) { + // To do: next major: change default. + let firstLineBlank = false + + if (options && options.firstLineBlank) { + firstLineBlank = true + } + + return { + handlers: {footnoteDefinition, footnoteReference}, + // This is on by default already. + unsafe: [{character: '[', inConstruct: ['label', 'phrasing', 'reference']}] + } + + /** + * @type {ToMarkdownHandle} + * @param {FootnoteDefinition} node + */ + function footnoteDefinition(node, _, state, info) { + const tracker = state.createTracker(info) + let value = tracker.move('[^') + const exit = state.enter('footnoteDefinition') + const subexit = state.enter('label') + value += tracker.move( + state.safe(state.associationId(node), {before: value, after: ']'}) + ) + subexit() + + value += tracker.move(']:') + + if (node.children && node.children.length > 0) { + tracker.shift(4) + + value += tracker.move( + (firstLineBlank ? '\n' : ' ') + + state.indentLines( + state.containerFlow(node, tracker.current()), + firstLineBlank ? mapAll : mapExceptFirst + ) + ) + } + + exit() + + return value + } +} + +/** @type {Map} */ +function mapExceptFirst(line, index, blank) { + return index === 0 ? line : mapAll(line, index, blank) +} + +/** @type {Map} */ +function mapAll(line, index, blank) { + return (blank ? '' : ' ') + line +} diff --git a/node_modules/mdast-util-gfm-footnote/license b/node_modules/mdast-util-gfm-footnote/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm-footnote/package.json b/node_modules/mdast-util-gfm-footnote/package.json new file mode 100644 index 0000000000000000000000000000000000000000..9cc9972550dc9fee5ef4263afcccb453f7677e8b --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/package.json @@ -0,0 +1,111 @@ +{ + "author": "Titus Wormer (https://wooorm.com)", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm-footnote/issues", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "devlop": "^1.1.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0" + }, + "description": "mdast extension to parse and serialize GFM footnotes", + "devDependencies": { + "@types/node": "^22.0.0", + "c8": "^10.0.0", + "micromark-extension-gfm-footnote": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^11.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.60.0" + }, + "exports": "./index.js", + "files": [ + "index.d.ts", + "index.js", + "lib/" + ], + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "keywords": [ + "footnote", + "gfm", + "markdown", + "markup", + "mdast-util", + "mdast", + "note", + "unist", + "utility", + "util" + ], + "license": "MIT", + "name": "mdast-util-gfm-footnote", + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "repository": "syntax-tree/mdast-util-gfm-footnote", + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix", + "test-api-dev": "node --conditions development test.js", + "test-api-prod": "node --conditions production test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "sideEffects": false, + "typeCoverage": { + "atLeast": 100, + "strict": true + }, + "type": "module", + "version": "2.1.0", + "xo": { + "overrides": [ + { + "files": [ + "**/*.d.ts" + ], + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] + } + } + ], + "prettier": true, + "rules": { + "unicorn/prefer-at": "off" + } + } +} diff --git a/node_modules/mdast-util-gfm-footnote/readme.md b/node_modules/mdast-util-gfm-footnote/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..b3fda5790c961cc5b9d180d8862e58e650b19726 --- /dev/null +++ b/node_modules/mdast-util-gfm-footnote/readme.md @@ -0,0 +1,494 @@ +# mdast-util-gfm-footnote + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] footnotes. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmFootnoteFromMarkdown()`](#gfmfootnotefrommarkdown) + * [`gfmFootnoteToMarkdown(options?)`](#gfmfootnotetomarkdownoptions) + * [`ToMarkdownOptions`](#tomarkdownoptions) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM footnote syntax +in markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +footnotes in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +footnotes in syntax trees to markdown). + +GFM footnotes were [announced September 30, 2021][post] but are not specified. +Their implementation on github.com is currently buggy. +The bugs have been reported on [`cmark-gfm`][cmark-gfm]. + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote]. + +When you don’t need a syntax tree, you can use [`micromark`][micromark] +directly with `micromark-extension-gfm-footnote`. + +When you are working with syntax trees and want all of GFM, use +[`mdast-util-gfm`][mdast-util-gfm] instead. + +All these packages are used [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. +If your content is not in English, you should configure that utility. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm-footnote +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from 'https://esm.sh/mdast-util-gfm-footnote@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +In the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts. + +[^mercury]: + **Mercury** is the first planet from the Sun and the smallest + in the Solar System. + +[^venus]: + **Venus** is the second planet from + the Sun. +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {fromMarkdown} from 'mdast-util-from-markdown' +import { + gfmFootnoteFromMarkdown, + gfmFootnoteToMarkdown +} from 'mdast-util-gfm-footnote' +import {toMarkdown} from 'mdast-util-to-markdown' +import {gfmFootnote} from 'micromark-extension-gfm-footnote' + +const value = await fs.readFile('example.md', 'utf8') + +const tree = fromMarkdown(value, { + extensions: [gfmFootnote()], + mdastExtensions: [gfmFootnoteFromMarkdown()] +}) + +console.log(tree) + +const result = toMarkdown(tree, { + extensions: [gfmFootnoteToMarkdown({firstLineBlank: true})] +}) + +console.log(result) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + {type: 'text', value: 'In the Solar System, Mercury'}, + {type: 'footnoteReference', identifier: 'mercury', label: 'mercury'}, + {type: 'text', value: ' and Venus'}, + {type: 'footnoteReference', identifier: 'venus', label: 'venus'}, + {type: 'text', value: ' have very small tilts.'} + ] + }, + { + type: 'footnoteDefinition', + identifier: 'mercury', + label: 'mercury', + children: [ + { + type: 'paragraph', + children: [ + {type: 'strong', children: [{type: 'text', value: 'Mercury'}]}, + { + type: 'text', + value: + ' is the first planet from the Sun and the smallest\n' + + 'in the Solar System.' + } + ] + } + ] + }, + { + type: 'footnoteDefinition', + identifier: 'venus', + label: 'venus', + children: [ + { + type: 'paragraph', + children: [ + {type: 'strong', children: [{type: 'text', value: 'Venus'}]}, + {type: 'text', value: ' is the second planet from\nthe Sun.'} + ] + } + ] + } + ] +} +``` + +```markdown +In the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts. + +[^mercury]: + **Mercury** is the first planet from the Sun and the smallest + in the Solar System. + +[^venus]: + **Venus** is the second planet from + the Sun. +``` + +## API + +This package exports the identifiers +[`gfmFootnoteFromMarkdown`][api-gfmfootnotefrommarkdown] and +[`gfmFootnoteToMarkdown`][api-gfmfootnotetomarkdown]. +There is no default export. +It exports the type [`ToMarkdownOptions`][api-to-markdown-options]. + +### `gfmFootnoteFromMarkdown()` + +Create an extension for +[`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM footnotes in markdown. + +###### Returns + +Extension for `mdast-util-from-markdown` +([`FromMarkdownExtension`][frommarkdownextension]). + +### `gfmFootnoteToMarkdown(options?)` + +Create an extension for +[`mdast-util-to-markdown`][mdast-util-to-markdown] +to enable GFM footnotes in markdown. + +###### Parameters + +* `options` ([`ToMarkdownOptions`][api-to-markdown-options], optional) + — configuration + +###### Returns + +Extension for `mdast-util-to-markdown` +([`ToMarkdownExtension`][tomarkdownextension]). + +### `ToMarkdownOptions` + +Configuration (TypeScript type). + +###### Fields + +* `firstLineBlank` (`boolean`, default: `false`) + — use a blank line for the first line of footnote definitions + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. +If your content is not in English, you should configure that utility. + +## Syntax + +See [Syntax in `micromark-extension-gfm-footnote`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `FootnoteDefinition` + +```idl +interface FootnoteDefinition <: Parent { + type: 'footnoteDefinition' + children: [FlowContent] +} + +FootnoteDefinition includes Association +``` + +**FootnoteDefinition** (**[Parent][dfn-parent]**) represents content relating +to the document that is outside its flow. + +**FootnoteDefinition** can be used where **[flow][dfn-flow-content]** content +is expected. +Its content model is also **[flow][dfn-flow-content]** content. + +**FootnoteDefinition** includes the mixin +**[Association][dfn-mxn-association]**. + +**FootnoteDefinition** should be associated with +**[FootnoteReferences][dfn-footnote-reference]**. + +For example, the following markdown: + +```markdown +[^alpha]: bravo and charlie. +``` + +Yields: + +```js +{ + type: 'footnoteDefinition', + identifier: 'alpha', + label: 'alpha', + children: [{ + type: 'paragraph', + children: [{type: 'text', value: 'bravo and charlie.'}] + }] +} +``` + +#### `FootnoteReference` + +```idl +interface FootnoteReference <: Node { + type: 'footnoteReference' +} + +FootnoteReference includes Association +``` + +**FootnoteReference** (**[Node][dfn-node]**) represents a marker through +association. + +**FootnoteReference** can be used where +**[phrasing][dfn-phrasing-content]** content is expected. +It has no content model. + +**FootnoteReference** includes the mixin **[Association][dfn-mxn-association]**. + +**FootnoteReference** should be associated with a +**[FootnoteDefinition][dfn-footnote-definition]**. + +For example, the following markdown: + +```markdown +[^alpha] +``` + +Yields: + +```js +{ + type: 'footnoteReference', + identifier: 'alpha', + label: 'alpha' +} +``` + +### Content model + +#### `FlowContent` (GFM footnotes) + +```idl +type FlowContentGfm = FootnoteDefinition | FlowContent +``` + +#### `PhrasingContent` (GFM footnotes) + +```idl +type PhrasingContentGfm = FootnoteReference | PhrasingContent +``` + +## Types + +This package is fully typed with [TypeScript][]. +It does not export additional types. + +The `FootnoteDefinition` and `FootnoteReference` types of the mdast nodes are +exposed from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-gfm-footnote@^2`, compatible with Node.js 16. + +## Related + +* [`remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`mdast-util-gfm`][mdast-util-gfm] + — same but all of GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote] + — micromark extension to parse GFM footnotes + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[api-gfmfootnotefrommarkdown]: #gfmfootnotefrommarkdown + +[api-gfmfootnotetomarkdown]: #gfmfootnotetomarkdownoptions + +[api-to-markdown-options]: #tomarkdownoptions + +[author]: https://wooorm.com + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm-footnote/actions + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-footnote/workflows/main/badge.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[cmark-gfm]: https://github.com/github/cmark-gfm + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[collective]: https://opencollective.com/unified + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-footnote + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-footnote.svg + +[dfn-flow-content]: #flowcontent-gfm-footnotes + +[dfn-footnote-definition]: #footnotedefinition + +[dfn-footnote-reference]: #footnotereference + +[dfn-mxn-association]: https://github.com/syntax-tree/mdast#association + +[dfn-node]: https://github.com/syntax-tree/unist#node + +[dfn-parent]: https://github.com/syntax-tree/mdast#parent + +[dfn-phrasing-content]: #phrasingcontent-gfm-footnotes + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm-footnote + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-footnote.svg + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[gfm]: https://github.github.com/gfm/ + +[health]: https://github.com/syntax-tree/.github + +[license]: license + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[micromark]: https://github.com/micromark/micromark + +[micromark-extension-gfm-footnote]: https://github.com/micromark/micromark-extension-gfm-footnote + +[npm]: https://docs.npmjs.com/cli/install + +[post]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/ + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[size]: https://bundlejs.com/?q=mdast-util-gfm-footnote + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-footnote + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[syntax]: https://github.com/micromark/micromark-extension-gfm-footnote#syntax + +[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[typescript]: https://www.typescriptlang.org diff --git a/node_modules/mdast-util-gfm-strikethrough/index.d.ts b/node_modules/mdast-util-gfm-strikethrough/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d3b616a17953193070f3831df960eb0e6feab998 --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/index.d.ts @@ -0,0 +1,19 @@ +export { + gfmStrikethroughFromMarkdown, + gfmStrikethroughToMarkdown +} from './lib/index.js' + +// Add custom data tracked to turn a syntax tree into markdown. +declare module 'mdast-util-to-markdown' { + interface ConstructNameMap { + /** + * Whole strikethrough. + * + * ```markdown + * > | ~~a~~ + * ^^^^^ + * ``` + */ + strikethrough: 'strikethrough' + } +} diff --git a/node_modules/mdast-util-gfm-strikethrough/index.js b/node_modules/mdast-util-gfm-strikethrough/index.js new file mode 100644 index 0000000000000000000000000000000000000000..97c87f60cc6f23873bb892f540d57e6499d3c4dd --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/index.js @@ -0,0 +1,5 @@ +// Note: extra types in `index.d.ts`. +export { + gfmStrikethroughFromMarkdown, + gfmStrikethroughToMarkdown +} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-strikethrough/lib/index.d.ts b/node_modules/mdast-util-gfm-strikethrough/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7a6fec2dd0b62c3d8cd7b60dc5cc6445a13698f8 --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/lib/index.d.ts @@ -0,0 +1,23 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM + * strikethrough in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM strikethrough. + */ +export function gfmStrikethroughFromMarkdown(): FromMarkdownExtension +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM + * strikethrough in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM strikethrough. + */ +export function gfmStrikethroughToMarkdown(): ToMarkdownExtension +export type Delete = import('mdast').Delete +export type CompileContext = import('mdast-util-from-markdown').CompileContext +export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension +export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle +export type ConstructName = import('mdast-util-to-markdown').ConstructName +export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle +export type ToMarkdownExtension = import('mdast-util-to-markdown').Options diff --git a/node_modules/mdast-util-gfm-strikethrough/lib/index.js b/node_modules/mdast-util-gfm-strikethrough/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..1a1463967110645620d922832c95e0f85e727b71 --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/lib/index.js @@ -0,0 +1,106 @@ +/** + * @typedef {import('mdast').Delete} Delete + * + * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext + * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension + * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle + * + * @typedef {import('mdast-util-to-markdown').ConstructName} ConstructName + * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle + * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension + */ + +/** + * List of constructs that occur in phrasing (paragraphs, headings), but cannot + * contain strikethrough. + * So they sort of cancel each other out. + * Note: could use a better name. + * + * Note: keep in sync with: + * + * @type {Array} + */ +const constructsWithoutStrikethrough = [ + 'autolink', + 'destinationLiteral', + 'destinationRaw', + 'reference', + 'titleQuote', + 'titleApostrophe' +] + +handleDelete.peek = peekDelete + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM + * strikethrough in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM strikethrough. + */ +export function gfmStrikethroughFromMarkdown() { + return { + canContainEols: ['delete'], + enter: {strikethrough: enterStrikethrough}, + exit: {strikethrough: exitStrikethrough} + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM + * strikethrough in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM strikethrough. + */ +export function gfmStrikethroughToMarkdown() { + return { + unsafe: [ + { + character: '~', + inConstruct: 'phrasing', + notInConstruct: constructsWithoutStrikethrough + } + ], + handlers: {delete: handleDelete} + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterStrikethrough(token) { + this.enter({type: 'delete', children: []}, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitStrikethrough(token) { + this.exit(token) +} + +/** + * @type {ToMarkdownHandle} + * @param {Delete} node + */ +function handleDelete(node, _, state, info) { + const tracker = state.createTracker(info) + const exit = state.enter('strikethrough') + let value = tracker.move('~~') + value += state.containerPhrasing(node, { + ...tracker.current(), + before: value, + after: '~' + }) + value += tracker.move('~~') + exit() + return value +} + +/** @type {ToMarkdownHandle} */ +function peekDelete() { + return '~' +} diff --git a/node_modules/mdast-util-gfm-strikethrough/license b/node_modules/mdast-util-gfm-strikethrough/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm-strikethrough/package.json b/node_modules/mdast-util-gfm-strikethrough/package.json new file mode 100644 index 0000000000000000000000000000000000000000..d24d63fc36f42e8ea8443ad6b1a70eb5a11ca926 --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/package.json @@ -0,0 +1,99 @@ +{ + "name": "mdast-util-gfm-strikethrough", + "version": "2.0.0", + "description": "mdast extension to parse and serialize GFM strikethrough", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "strikethrough", + "strike", + "through", + "del", + "delete", + "deletion", + "gfm" + ], + "repository": "syntax-tree/mdast-util-gfm-strikethrough", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm-strikethrough/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "micromark-extension-gfm-strikethrough": "^2.0.0", + "prettier": "^2.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true + } +} diff --git a/node_modules/mdast-util-gfm-strikethrough/readme.md b/node_modules/mdast-util-gfm-strikethrough/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..d192cea620865c334f1cc7bbbf32ccd9777c7489 --- /dev/null +++ b/node_modules/mdast-util-gfm-strikethrough/readme.md @@ -0,0 +1,350 @@ +# mdast-util-gfm-strikethrough + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] strikethrough. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmStrikethroughFromMarkdown()`](#gfmstrikethroughfrommarkdown) + * [`gfmStrikethroughToMarkdown()`](#gfmstrikethroughtomarkdown) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM strikethrough +syntax in markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +strikethrough in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +strikethrough in syntax trees to markdown). + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-gfm-strikethrough`][extension]. + +When you don’t need a syntax tree, you can use [`micromark`][micromark] +directly with `micromark-extension-gfm-strikethrough`. + +When you are working with syntax trees and want all of GFM, use +[`mdast-util-gfm`][mdast-util-gfm] instead. + +All these packages are used [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. +If you want a different element, you should configure that utility. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm-strikethrough +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'https://esm.sh/mdast-util-gfm-strikethrough@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +*Emphasis*, **importance**, and ~~strikethrough~~. +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'mdast-util-gfm-strikethrough' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.md') + +const tree = fromMarkdown(doc, { + extensions: [gfmStrikethrough()], + mdastExtensions: [gfmStrikethroughFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [gfmStrikethroughToMarkdown()]}) + +console.log(out) +``` + +Now, running `node example` yields: + +```js +{ + type: 'root', + children: [ + { + type: 'paragraph', + children: [ + {type: 'emphasis', children: [{type: 'text', value: 'Emphasis'}]}, + {type: 'text', value: ', '}, + {type: 'strong', children: [{type: 'text', value: 'importance'}]}, + {type: 'text', value: ', and '}, + {type: 'delete', children: [{type: 'text', value: 'strikethrough'}]}, + {type: 'text', value: '.'} + ] + } + ] +} +``` + +```markdown +*Emphasis*, **importance**, and ~~strikethrough~~. +``` + +## API + +This package exports the identifiers +[`gfmStrikethroughFromMarkdown`][api-gfm-strikethrough-from-markdown] and +[`gfmStrikethroughToMarkdown`][api-gfm-strikethrough-to-markdown]. +There is no default export. + +### `gfmStrikethroughFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM strikethrough in markdown. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable GFM strikethrough +([`FromMarkdownExtension`][from-markdown-extension]). + +### `gfmStrikethroughToMarkdown()` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to +enable GFM strikethrough in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM strikethrough +([`ToMarkdownExtension`][to-markdown-extension]). + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. +If you want a different element, you should configure that utility. + +## Syntax + +See [Syntax in `micromark-extension-gfm-strikethrough`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `Delete` + +```idl +interface Delete <: Parent { + type: 'delete' + children: [TransparentContent] +} +``` + +**Delete** (**[Parent][dfn-parent]**) represents contents that are no longer +accurate or no longer relevant. + +**Delete** can be used where **[phrasing][dfn-phrasing-content]** +content is expected. +Its content model is **[transparent][dfn-transparent-content]** content. + +For example, the following markdown: + +```markdown +~~alpha~~ +``` + +Yields: + +```js +{ + type: 'delete', + children: [{type: 'text', value: 'alpha'}] +} +``` + +### Content model + +#### `PhrasingContent` (GFM strikethrough) + +```idl +type PhrasingContentGfm = Delete | PhrasingContent +``` + +## Types + +This package is fully typed with [TypeScript][]. +It does not export additional types. + +The `Delete` type of the mdast node is exposed from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-gfm-strikethrough@^2`, compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`remarkjs/remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm] + — same but all of GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`micromark/micromark-extension-gfm-strikethrough`][extension] + — micromark extension to parse GFM strikethrough + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-strikethrough/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm-strikethrough/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-strikethrough.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-strikethrough + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-strikethrough.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm-strikethrough + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-strikethrough + +[size]: https://bundlejs.com/?q=mdast-util-gfm-strikethrough + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[gfm]: https://github.github.com/gfm/ + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[mdast]: https://github.com/syntax-tree/mdast + +[dfn-transparent-content]: https://github.com/syntax-tree/mdast#transparentcontent + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[micromark]: https://github.com/micromark/micromark + +[extension]: https://github.com/micromark/micromark-extension-gfm-strikethrough + +[syntax]: https://github.com/micromark/micromark-extension-gfm-strikethrough#syntax + +[dfn-parent]: https://github.com/syntax-tree/mdast#parent + +[dfn-phrasing-content]: #phrasingcontent-gfm-strikethrough + +[api-gfm-strikethrough-from-markdown]: #gfmstrikethroughfrommarkdown + +[api-gfm-strikethrough-to-markdown]: #gfmstrikethroughtomarkdown diff --git a/node_modules/mdast-util-gfm-table/index.d.ts b/node_modules/mdast-util-gfm-table/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f616ca16b1ccb5d536d104648e2938785f6dfffa --- /dev/null +++ b/node_modules/mdast-util-gfm-table/index.d.ts @@ -0,0 +1,54 @@ +export type {Options} from './lib/index.js' + +export {gfmTableFromMarkdown, gfmTableToMarkdown} from './lib/index.js' + +// Add custom data tracked to turn markdown into a tree. +declare module 'mdast-util-from-markdown' { + interface CompileData { + /** + * Whether we’re currently in a table. + */ + inTable?: boolean | undefined + } +} + +// Add custom data tracked to turn a syntax tree into markdown. +declare module 'mdast-util-to-markdown' { + interface ConstructNameMap { + /** + * Whole table. + * + * ```markdown + * > | | a | + * ^^^^^ + * > | | - | + * ^^^^^ + * ``` + */ + table: 'table' + + /** + * Table cell. + * + * ```markdown + * > | | a | + * ^^^^^ + * | | - | + * ``` + */ + tableCell: 'tableCell' + + /** + * Table row. + * + * ```markdown + * > | | a | + * ^^^^^ + * | | - | + * ``` + */ + tableRow: 'tableRow' + } +} + +// Note: `Table` is exposed from `@types/mdast`. diff --git a/node_modules/mdast-util-gfm-table/index.js b/node_modules/mdast-util-gfm-table/index.js new file mode 100644 index 0000000000000000000000000000000000000000..3f2bab47277b78ba82614cfdb8454676479a2b59 --- /dev/null +++ b/node_modules/mdast-util-gfm-table/index.js @@ -0,0 +1,2 @@ +// Note: types exposed from `index.d.ts`. +export {gfmTableFromMarkdown, gfmTableToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-table/lib/index.d.ts b/node_modules/mdast-util-gfm-table/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a395fc752e4c3e707ef620be347303e0625f262f --- /dev/null +++ b/node_modules/mdast-util-gfm-table/lib/index.d.ts @@ -0,0 +1,51 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM tables in + * markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM tables. + */ +export function gfmTableFromMarkdown(): FromMarkdownExtension +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM tables in + * markdown. + * + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM tables. + */ +export function gfmTableToMarkdown( + options?: Options | null | undefined +): ToMarkdownExtension +export type InlineCode = import('mdast').InlineCode +export type Table = import('mdast').Table +export type TableCell = import('mdast').TableCell +export type TableRow = import('mdast').TableRow +export type MarkdownTableOptions = import('markdown-table').Options +export type CompileContext = import('mdast-util-from-markdown').CompileContext +export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension +export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle +export type ToMarkdownExtension = import('mdast-util-to-markdown').Options +export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle +export type State = import('mdast-util-to-markdown').State +export type Info = import('mdast-util-to-markdown').Info +/** + * Configuration. + */ +export type Options = { + /** + * Whether to add a space of padding between delimiters and cells (default: + * `true`). + */ + tableCellPadding?: boolean | null | undefined + /** + * Whether to align the delimiters (default: `true`). + */ + tablePipeAlign?: boolean | null | undefined + /** + * Function to detect the length of table cell content, used when aligning + * the delimiters between cells (optional). + */ + stringLength?: MarkdownTableOptions['stringLength'] | null | undefined +} diff --git a/node_modules/mdast-util-gfm-table/lib/index.js b/node_modules/mdast-util-gfm-table/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..11e51158c5cece45ab736893d257fa98aef6cede --- /dev/null +++ b/node_modules/mdast-util-gfm-table/lib/index.js @@ -0,0 +1,300 @@ +/** + * @typedef {import('mdast').InlineCode} InlineCode + * @typedef {import('mdast').Table} Table + * @typedef {import('mdast').TableCell} TableCell + * @typedef {import('mdast').TableRow} TableRow + * + * @typedef {import('markdown-table').Options} MarkdownTableOptions + * + * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext + * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension + * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle + * + * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension + * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle + * @typedef {import('mdast-util-to-markdown').State} State + * @typedef {import('mdast-util-to-markdown').Info} Info + */ + +/** + * @typedef Options + * Configuration. + * @property {boolean | null | undefined} [tableCellPadding=true] + * Whether to add a space of padding between delimiters and cells (default: + * `true`). + * @property {boolean | null | undefined} [tablePipeAlign=true] + * Whether to align the delimiters (default: `true`). + * @property {MarkdownTableOptions['stringLength'] | null | undefined} [stringLength] + * Function to detect the length of table cell content, used when aligning + * the delimiters between cells (optional). + */ + +import {ok as assert} from 'devlop' +import {markdownTable} from 'markdown-table' +import {defaultHandlers} from 'mdast-util-to-markdown' + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM tables in + * markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM tables. + */ +export function gfmTableFromMarkdown() { + return { + enter: { + table: enterTable, + tableData: enterCell, + tableHeader: enterCell, + tableRow: enterRow + }, + exit: { + codeText: exitCodeText, + table: exitTable, + tableData: exit, + tableHeader: exit, + tableRow: exit + } + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterTable(token) { + const align = token._align + assert(align, 'expected `_align` on table') + this.enter( + { + type: 'table', + align: align.map(function (d) { + return d === 'none' ? null : d + }), + children: [] + }, + token + ) + this.data.inTable = true +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitTable(token) { + this.exit(token) + this.data.inTable = undefined +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterRow(token) { + this.enter({type: 'tableRow', children: []}, token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exit(token) { + this.exit(token) +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterCell(token) { + this.enter({type: 'tableCell', children: []}, token) +} + +// Overwrite the default code text data handler to unescape escaped pipes when +// they are in tables. +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitCodeText(token) { + let value = this.resume() + + if (this.data.inTable) { + value = value.replace(/\\([\\|])/g, replace) + } + + const node = this.stack[this.stack.length - 1] + assert(node.type === 'inlineCode') + node.value = value + this.exit(token) +} + +/** + * @param {string} $0 + * @param {string} $1 + * @returns {string} + */ +function replace($0, $1) { + // Pipes work, backslashes don’t (but can’t escape pipes). + return $1 === '|' ? $1 : $0 +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM tables in + * markdown. + * + * @param {Options | null | undefined} [options] + * Configuration. + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM tables. + */ +export function gfmTableToMarkdown(options) { + const settings = options || {} + const padding = settings.tableCellPadding + const alignDelimiters = settings.tablePipeAlign + const stringLength = settings.stringLength + const around = padding ? ' ' : '|' + + return { + unsafe: [ + {character: '\r', inConstruct: 'tableCell'}, + {character: '\n', inConstruct: 'tableCell'}, + // A pipe, when followed by a tab or space (padding), or a dash or colon + // (unpadded delimiter row), could result in a table. + {atBreak: true, character: '|', after: '[\t :-]'}, + // A pipe in a cell must be encoded. + {character: '|', inConstruct: 'tableCell'}, + // A colon must be followed by a dash, in which case it could start a + // delimiter row. + {atBreak: true, character: ':', after: '-'}, + // A delimiter row can also start with a dash, when followed by more + // dashes, a colon, or a pipe. + // This is a stricter version than the built in check for lists, thematic + // breaks, and setex heading underlines though: + // + {atBreak: true, character: '-', after: '[:|-]'} + ], + handlers: { + inlineCode: inlineCodeWithTable, + table: handleTable, + tableCell: handleTableCell, + tableRow: handleTableRow + } + } + + /** + * @type {ToMarkdownHandle} + * @param {Table} node + */ + function handleTable(node, _, state, info) { + return serializeData(handleTableAsData(node, state, info), node.align) + } + + /** + * This function isn’t really used normally, because we handle rows at the + * table level. + * But, if someone passes in a table row, this ensures we make somewhat sense. + * + * @type {ToMarkdownHandle} + * @param {TableRow} node + */ + function handleTableRow(node, _, state, info) { + const row = handleTableRowAsData(node, state, info) + const value = serializeData([row]) + // `markdown-table` will always add an align row + return value.slice(0, value.indexOf('\n')) + } + + /** + * @type {ToMarkdownHandle} + * @param {TableCell} node + */ + function handleTableCell(node, _, state, info) { + const exit = state.enter('tableCell') + const subexit = state.enter('phrasing') + const value = state.containerPhrasing(node, { + ...info, + before: around, + after: around + }) + subexit() + exit() + return value + } + + /** + * @param {Array>} matrix + * @param {Array | null | undefined} [align] + */ + function serializeData(matrix, align) { + return markdownTable(matrix, { + align, + // @ts-expect-error: `markdown-table` types should support `null`. + alignDelimiters, + // @ts-expect-error: `markdown-table` types should support `null`. + padding, + // @ts-expect-error: `markdown-table` types should support `null`. + stringLength + }) + } + + /** + * @param {Table} node + * @param {State} state + * @param {Info} info + */ + function handleTableAsData(node, state, info) { + const children = node.children + let index = -1 + /** @type {Array>} */ + const result = [] + const subexit = state.enter('table') + + while (++index < children.length) { + result[index] = handleTableRowAsData(children[index], state, info) + } + + subexit() + + return result + } + + /** + * @param {TableRow} node + * @param {State} state + * @param {Info} info + */ + function handleTableRowAsData(node, state, info) { + const children = node.children + let index = -1 + /** @type {Array} */ + const result = [] + const subexit = state.enter('tableRow') + + while (++index < children.length) { + // Note: the positional info as used here is incorrect. + // Making it correct would be impossible due to aligning cells? + // And it would need copy/pasting `markdown-table` into this project. + result[index] = handleTableCell(children[index], node, state, info) + } + + subexit() + + return result + } + + /** + * @type {ToMarkdownHandle} + * @param {InlineCode} node + */ + function inlineCodeWithTable(node, parent, state) { + let value = defaultHandlers.inlineCode(node, parent, state) + + if (state.stack.includes('tableCell')) { + value = value.replace(/\|/g, '\\$&') + } + + return value + } +} diff --git a/node_modules/mdast-util-gfm-table/license b/node_modules/mdast-util-gfm-table/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-gfm-table/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm-table/package.json b/node_modules/mdast-util-gfm-table/package.json new file mode 100644 index 0000000000000000000000000000000000000000..2ca97be9c218ea42040d54b8b8a65938a859b184 --- /dev/null +++ b/node_modules/mdast-util-gfm-table/package.json @@ -0,0 +1,101 @@ +{ + "name": "mdast-util-gfm-table", + "version": "2.0.0", + "description": "mdast extension to parse and serialize GFM tables", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "table", + "row", + "column", + "cell", + "tabular", + "gfm" + ], + "repository": "syntax-tree/mdast-util-gfm-table", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm-table/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "devlop": "^1.0.0", + "markdown-table": "^3.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "micromark-extension-gfm-table": "^2.0.0", + "prettier": "^2.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "string-width": "^6.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true + } +} diff --git a/node_modules/mdast-util-gfm-table/readme.md b/node_modules/mdast-util-gfm-table/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..24068931cd733fa6922c8369e626edcfe1699216 --- /dev/null +++ b/node_modules/mdast-util-gfm-table/readme.md @@ -0,0 +1,605 @@ +# mdast-util-gfm-table + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] tables. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmTableFromMarkdown`](#gfmtablefrommarkdown) + * [`gfmTableToMarkdown(options?)`](#gfmtabletomarkdownoptions) + * [`Options`](#options) +* [Examples](#examples) + * [Example: `stringLength`](#example-stringlength) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Enumeration](#enumeration) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM table syntax in +markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +tables in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +tables in syntax trees to markdown). + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-gfm-table`][extension]. + +When you don’t need a syntax tree, you can use [`micromark`][micromark] +directly with `micromark-extension-gfm-table`. + +When you are working with syntax trees and want all of GFM, use +[`mdast-util-gfm`][mdast-util-gfm] instead. + +All these packages are used [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm-table +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'https://esm.sh/mdast-util-gfm-table@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +| a | b | c | d | +| - | :- | -: | :-: | +| e | f | +| g | h | i | j | k | +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {gfmTable} from 'micromark-extension-gfm-table' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.md') + +const tree = fromMarkdown(doc, { + extensions: [gfmTable()], + mdastExtensions: [gfmTableFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [gfmTableToMarkdown()]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'table', + align: [null, 'left', 'right', 'center'], + children: [ + { + type: 'tableRow', + children: [ + {type: 'tableCell', children: [{type: 'text', value: 'a'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'b'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'c'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'd'}]} + ] + }, + { + type: 'tableRow', + children: [ + {type: 'tableCell', children: [{type: 'text', value: 'e'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'f'}]} + ] + }, + { + type: 'tableRow', + children: [ + {type: 'tableCell', children: [{type: 'text', value: 'g'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'h'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'i'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'j'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'k'}]} + ] + } + ] + } + ] +} +``` + +```markdown +| a | b | c | d | | +| - | :- | -: | :-: | - | +| e | f | | | | +| g | h | i | j | k | +``` + +## API + +This package exports the identifiers +[`gfmTableFromMarkdown`][api-gfm-table-from-markdown] and +[`gfmTableToMarkdown`][api-gfm-table-to-markdown]. +There is no default export. + +### `gfmTableFromMarkdown` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM tables in markdown. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable GFM tables +([`FromMarkdownExtension`][from-markdown-extension]). + +### `gfmTableToMarkdown(options?)` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to +enable GFM tables in markdown. + +###### Parameters + +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM tables +([`ToMarkdownExtension`][to-markdown-extension]). + +### `Options` + +Configuration (TypeScript type). + +###### Fields + +* `tableCellPadding` (`boolean`, default: `true`) + — whether to add a space of padding between delimiters and cells +* `tablePipeAlign` (`boolean`, default: `true`) + — whether to align the delimiters +* `stringLength` (`((value: string) => number)`, default: `s => s.length`) + — function to detect the length of table cell content, used when aligning + the delimiters between cells + +## Examples + +### Example: `stringLength` + +It’s possible to align tables based on the visual width of cells. +First, let’s show the problem: + +```js +import {gfmTable} from 'micromark-extension-gfm-table' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = `| Alpha | Bravo | +| - | - | +| 中文 | Charlie | +| 👩‍❤️‍👩 | Delta |` + +const tree = fromMarkdown(doc, { + extensions: [gfmTable], + mdastExtensions: [gfmTableFromMarkdown] +}) + +console.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]})) +``` + +The above code shows how these utilities can be used to format markdown. +The output is as follows: + +```markdown +| Alpha | Bravo | +| -------- | ------- | +| 中文 | Charlie | +| 👩‍❤️‍👩 | Delta | +``` + +To improve the alignment of these full-width characters and emoji, pass a +`stringLength` function that calculates the visual width of cells. +One such algorithm is [`string-width`][string-width]. +It can be used like so: + +```diff +@@ -2,6 +2,7 @@ import {gfmTable} from 'micromark-extension-gfm-table' + import {fromMarkdown} from 'mdast-util-from-markdown' + import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' + import {toMarkdown} from 'mdast-util-to-markdown' ++import stringWidth from 'string-width' + + const doc = `| Alpha | Bravo | + | - | - | +@@ -13,4 +14,8 @@ const tree = fromMarkdown(doc, { + mdastExtensions: [gfmTableFromMarkdown()] + }) + +-console.log(toMarkdown(tree, {extensions: [gfmTableToMarkdown()]})) ++console.log( ++ toMarkdown(tree, { ++ extensions: [gfmTableToMarkdown({stringLength: stringWidth})] ++ }) ++) +``` + +The output of our code with these changes is as follows: + +```markdown +| Alpha | Bravo | +| ----- | ------- | +| 中文 | Charlie | +| 👩‍❤️‍👩 | Delta | +``` + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Syntax + +See [Syntax in `micromark-extension-gfm-table`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `Table` + +```idl +interface Table <: Parent { + type: 'table' + align: [alignType]? + children: [TableContent] +} +``` + +**Table** (**[Parent][dfn-parent]**) represents two-dimensional data. + +**Table** can be used where **[flow][dfn-flow-content]** content is expected. +Its content model is **[table][dfn-table-content]** content. + +The *[head][term-head]* of the node represents the labels of the columns. + +An `align` field can be present. +If present, it must be a list of **[alignTypes][dfn-enum-align-type]**. +It represents how cells in columns are aligned. + +For example, the following markdown: + +```markdown +| foo | bar | +| :-- | :-: | +| baz | qux | +``` + +Yields: + +```js +{ + type: 'table', + align: ['left', 'center'], + children: [ + { + type: 'tableRow', + children: [ + { + type: 'tableCell', + children: [{type: 'text', value: 'foo'}] + }, + { + type: 'tableCell', + children: [{type: 'text', value: 'bar'}] + } + ] + }, + { + type: 'tableRow', + children: [ + { + type: 'tableCell', + children: [{type: 'text', value: 'baz'}] + }, + { + type: 'tableCell', + children: [{type: 'text', value: 'qux'}] + } + ] + } + ] +} +``` + +#### `TableRow` + +```idl +interface TableRow <: Parent { + type: "tableRow" + children: [RowContent] +} +``` + +**TableRow** (**[Parent][dfn-parent]**) represents a row of cells in a table. + +**TableRow** can be used where **[table][dfn-table-content]** content is +expected. +Its content model is **[row][dfn-row-content]** content. + +If the node is a *[head][term-head]*, it represents the labels of the columns +for its parent **[Table][dfn-table]**. + +For an example, see **[Table][dfn-table]**. + +#### `TableCell` + +```idl +interface TableCell <: Parent { + type: "tableCell" + children: [PhrasingContent] +} +``` + +**TableCell** (**[Parent][dfn-parent]**) represents a header cell in a +**[Table][dfn-table]**, if its parent is a *[head][term-head]*, or a data +cell otherwise. + +**TableCell** can be used where **[row][dfn-row-content]** content is expected. +Its content model is **[phrasing][dfn-phrasing-content]** content excluding +**[Break][dfn-break]** nodes. + +For an example, see **[Table][dfn-table]**. + +### Enumeration + +#### `alignType` + +```idl +enum alignType { + 'center' | 'left' | 'right' | null +} +``` + +**alignType** represents how phrasing content is aligned +([\[CSSTEXT\]][css-text]). + +* **`'left'`**: See the [`left`][css-left] value of the `text-align` CSS + property +* **`'right'`**: See the [`right`][css-right] value of the `text-align` + CSS property +* **`'center'`**: See the [`center`][css-center] value of the `text-align` + CSS property +* **`null`**: phrasing content is aligned as defined by the host environment + +### Content model + +#### `FlowContent` (GFM table) + +```idl +type FlowContentGfm = Table | FlowContent +``` + +#### `TableContent` + +```idl +type TableContent = TableRow +``` + +**Table** content represent the rows in a table. + +#### `RowContent` + +```idl +type RowContent = TableCell +``` + +**Row** content represent the cells in a row. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional type [`Options`][api-options]. + +The `Table`, `TableRow`, and `TableCell` types of the mdast nodes are exposed +from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-gfm-table@^2`, +compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`remarkjs/remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm] + — same but all of GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`micromark/micromark-extension-gfm-table`][extension] + — micromark extension to parse GFM tables + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-table/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm-table/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-table.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-table + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-table.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm-table + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-table + +[size]: https://bundlejs.com/?q=mdast-util-gfm-table + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[micromark]: https://github.com/micromark/micromark + +[extension]: https://github.com/micromark/micromark-extension-gfm-table + +[syntax]: https://github.com/micromark/micromark-extension-gfm-table#syntax + +[gfm]: https://github.github.com/gfm/ + +[string-width]: https://github.com/sindresorhus/string-width + +[css-text]: https://drafts.csswg.org/css-text/ + +[css-left]: https://drafts.csswg.org/css-text/#valdef-text-align-left + +[css-right]: https://drafts.csswg.org/css-text/#valdef-text-align-right + +[css-center]: https://drafts.csswg.org/css-text/#valdef-text-align-center + +[term-head]: https://github.com/syntax-tree/unist#head + +[dfn-parent]: https://github.com/syntax-tree/mdast#parent + +[dfn-phrasing-content]: https://github.com/syntax-tree/mdast#phrasingcontent + +[dfn-break]: https://github.com/syntax-tree/mdast#break + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[api-gfm-table-from-markdown]: #gfmtablefrommarkdown + +[api-gfm-table-to-markdown]: #gfmtabletomarkdownoptions + +[api-options]: #options + +[dfn-flow-content]: #flowcontent-gfm-table + +[dfn-table-content]: #tablecontent + +[dfn-enum-align-type]: #aligntype + +[dfn-row-content]: #rowcontent + +[dfn-table]: #table diff --git a/node_modules/mdast-util-gfm-task-list-item/index.d.ts b/node_modules/mdast-util-gfm-task-list-item/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..9c0c593ee9ed7fdde9846cf6c19494ec672f5df8 --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/index.d.ts @@ -0,0 +1,4 @@ +export { + gfmTaskListItemFromMarkdown, + gfmTaskListItemToMarkdown +} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-task-list-item/index.js b/node_modules/mdast-util-gfm-task-list-item/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9c0c593ee9ed7fdde9846cf6c19494ec672f5df8 --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/index.js @@ -0,0 +1,4 @@ +export { + gfmTaskListItemFromMarkdown, + gfmTaskListItemToMarkdown +} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm-task-list-item/lib/index.d.ts b/node_modules/mdast-util-gfm-task-list-item/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f1db5627d05f18657faff5a24d3e18166a76fa5b --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/lib/index.d.ts @@ -0,0 +1,23 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM task + * list items in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM task list items. + */ +export function gfmTaskListItemFromMarkdown(): FromMarkdownExtension +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM task list + * items in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM task list items. + */ +export function gfmTaskListItemToMarkdown(): ToMarkdownExtension +export type ListItem = import('mdast').ListItem +export type Paragraph = import('mdast').Paragraph +export type CompileContext = import('mdast-util-from-markdown').CompileContext +export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension +export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle +export type ToMarkdownExtension = import('mdast-util-to-markdown').Options +export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle diff --git a/node_modules/mdast-util-gfm-task-list-item/lib/index.js b/node_modules/mdast-util-gfm-task-list-item/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..80a713c56a91675a3a1fd71b275a65af2ab67d3f --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/lib/index.js @@ -0,0 +1,141 @@ +/** + * @typedef {import('mdast').ListItem} ListItem + * @typedef {import('mdast').Paragraph} Paragraph + * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext + * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension + * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle + * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension + * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle + */ + +import {ok as assert} from 'devlop' +import {defaultHandlers} from 'mdast-util-to-markdown' + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM task + * list items in markdown. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable GFM task list items. + */ +export function gfmTaskListItemFromMarkdown() { + return { + exit: { + taskListCheckValueChecked: exitCheck, + taskListCheckValueUnchecked: exitCheck, + paragraph: exitParagraphWithTaskListItem + } + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM task list + * items in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM task list items. + */ +export function gfmTaskListItemToMarkdown() { + return { + unsafe: [{atBreak: true, character: '-', after: '[:|-]'}], + handlers: {listItem: listItemWithTaskListItem} + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitCheck(token) { + // We’re always in a paragraph, in a list item. + const node = this.stack[this.stack.length - 2] + assert(node.type === 'listItem') + node.checked = token.type === 'taskListCheckValueChecked' +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitParagraphWithTaskListItem(token) { + const parent = this.stack[this.stack.length - 2] + + if ( + parent && + parent.type === 'listItem' && + typeof parent.checked === 'boolean' + ) { + const node = this.stack[this.stack.length - 1] + assert(node.type === 'paragraph') + const head = node.children[0] + + if (head && head.type === 'text') { + const siblings = parent.children + let index = -1 + /** @type {Paragraph | undefined} */ + let firstParaghraph + + while (++index < siblings.length) { + const sibling = siblings[index] + if (sibling.type === 'paragraph') { + firstParaghraph = sibling + break + } + } + + if (firstParaghraph === node) { + // Must start with a space or a tab. + head.value = head.value.slice(1) + + if (head.value.length === 0) { + node.children.shift() + } else if ( + node.position && + head.position && + typeof head.position.start.offset === 'number' + ) { + head.position.start.column++ + head.position.start.offset++ + node.position.start = Object.assign({}, head.position.start) + } + } + } + } + + this.exit(token) +} + +/** + * @type {ToMarkdownHandle} + * @param {ListItem} node + */ +function listItemWithTaskListItem(node, parent, state, info) { + const head = node.children[0] + const checkable = + typeof node.checked === 'boolean' && head && head.type === 'paragraph' + const checkbox = '[' + (node.checked ? 'x' : ' ') + '] ' + const tracker = state.createTracker(info) + + if (checkable) { + tracker.move(checkbox) + } + + let value = defaultHandlers.listItem(node, parent, state, { + ...info, + ...tracker.current() + }) + + if (checkable) { + value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check) + } + + return value + + /** + * @param {string} $0 + * @returns {string} + */ + function check($0) { + return $0 + checkbox + } +} diff --git a/node_modules/mdast-util-gfm-task-list-item/license b/node_modules/mdast-util-gfm-task-list-item/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm-task-list-item/package.json b/node_modules/mdast-util-gfm-task-list-item/package.json new file mode 100644 index 0000000000000000000000000000000000000000..f0a5c21b8015776fde7a68411f403713741b44e9 --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/package.json @@ -0,0 +1,90 @@ +{ + "name": "mdast-util-gfm-task-list-item", + "version": "2.0.0", + "description": "mdast extension to parse and serialize GFM task list items", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "task", + "list", + "item", + "check", + "checkbox", + "todo", + "gfm" + ], + "repository": "syntax-tree/mdast-util-gfm-task-list-item", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm-task-list-item/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "devlop": "^1.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "micromark-extension-gfm-task-list-item": "^2.0.0", + "prettier": "^2.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true + } +} diff --git a/node_modules/mdast-util-gfm-task-list-item/readme.md b/node_modules/mdast-util-gfm-task-list-item/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..e7959c85a21ad6f45e0558e151755cb2a5b9aca8 --- /dev/null +++ b/node_modules/mdast-util-gfm-task-list-item/readme.md @@ -0,0 +1,366 @@ +# mdast-util-gfm-task-list-item + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] task list items. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmTaskListItemFromMarkdown()`](#gfmtasklistitemfrommarkdown) + * [`gfmTaskListItemToMarkdown()`](#gfmtasklistitemtomarkdown) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM task list item +syntax in markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +task lists in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +task lists in syntax trees to markdown). + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with +[`micromark-extension-gfm-task-list-item`][extension]. + +When you don’t need a syntax tree, you can use [`micromark`][micromark] +directly with `micromark-extension-gfm-task-list-item`. + +When you are working with syntax trees and want all of GFM, use +[`mdast-util-gfm`][mdast-util-gfm] instead. + +All these packages are used [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm-task-list-item +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'https://esm.sh/mdast-util-gfm-task-list-item@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +* [ ] To do +* [x] Done + +1. Mixed… +2. [x] …messages +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'mdast-util-gfm-task-list-item' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.md') + +const tree = fromMarkdown(doc, { + extensions: [gfmTaskListItem], + mdastExtensions: [gfmTaskListItemFromMarkdown] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [gfmTaskListItemToMarkdown]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'list', + ordered: false, + start: null, + spread: false, + children: [ + { + type: 'listItem', + spread: false, + checked: false, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'To do'}]} + ] + }, + { + type: 'listItem', + spread: false, + checked: true, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'Done'}]} + ] + } + ] + }, + { + type: 'list', + ordered: true, + start: 1, + spread: false, + children: [ + { + type: 'listItem', + spread: false, + checked: null, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'Mixed…'}]} + ] + }, + { + type: 'listItem', + spread: false, + checked: true, + children: [ + {type: 'paragraph', children: [{type: 'text', value: '…messages'}]} + ] + } + ] + } + ] +} +``` + +```markdown +* [ ] To do +* [x] Done + +1. Mixed… +2. [x] …messages +``` + +## API + +This package exports the identifiers +[`gfmTaskListItemFromMarkdown`][api-gfm-task-list-item-from-markdown] and +[`gfmTaskListItemToMarkdown`][api-gfm-task-list-item-to-markdown]. +There is no default export. + +### `gfmTaskListItemFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM task list items in markdown. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable GFM task list items +([`FromMarkdownExtension`][frommarkdownextension]). + +### `gfmTaskListItemToMarkdown()` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to +enable GFM task list items in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM task list items +([`ToMarkdownExtension`][tomarkdownextension]). + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Syntax + +See [Syntax in `micromark-extension-gfm-task-list-item`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `ListItem` (GFM) + +```idl +interface ListItemGfm <: ListItem { + checked: boolean? +} +``` + +In GFM, a `checked` field can be present. +It represents whether the item is done (when `true`), not done (when `false`), +or indeterminate or not applicable (when `null` or not present). + +### Content model + +#### `ListContent` (GFM) + +```idl +type ListContentGfm = ListItemGfm +``` + +## Types + +This package is fully typed with [TypeScript][]. +It does not export additional types. + +The `ListItem` type of the mdast nodes are exposed from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-gfm-task-list-item@^2`, compatible with Node.js 16. + +## Related + +* [`remarkjs/remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm] + — same but all of GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`micromark/micromark-extension-gfm-task-list-item`][extension] + — micromark extension to parse GFM task list items + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-task-list-item/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm-task-list-item/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-task-list-item.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-task-list-item + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-task-list-item.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm-task-list-item + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-task-list-item + +[size]: https://bundlejs.com/?q=mdast-util-gfm-task-list-item + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md + +[mdast]: https://github.com/syntax-tree/mdast + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[micromark]: https://github.com/micromark/micromark + +[extension]: https://github.com/micromark/micromark-extension-gfm-task-list-item + +[syntax]: https://github.com/micromark/micromark-extension-gfm-task-list-item#syntax + +[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[gfm]: https://github.github.com/gfm/ + +[api-gfm-task-list-item-from-markdown]: #gfmtasklistitemfrommarkdown + +[api-gfm-task-list-item-to-markdown]: #gfmtasklistitemtomarkdown diff --git a/node_modules/mdast-util-gfm/index.d.ts b/node_modules/mdast-util-gfm/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f53affedb5fe39ac695632fcc74e37d27f26e7aa --- /dev/null +++ b/node_modules/mdast-util-gfm/index.d.ts @@ -0,0 +1,12 @@ +import type {ToMarkdownOptions as FootnoteOptions} from 'mdast-util-gfm-footnote' +import type {Options as TableOptions} from 'mdast-util-gfm-table' + +/** + * Configuration for `gfmToMarkdown` from `mdast-util-gfm`. + * + * Currently supports options for `mdast-util-gfm-footnote` and + * `mdast-util-gfm-table`. + */ +export interface Options extends FootnoteOptions, TableOptions {} + +export {gfmFromMarkdown, gfmToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm/index.js b/node_modules/mdast-util-gfm/index.js new file mode 100644 index 0000000000000000000000000000000000000000..24a40dee11c2c6bb0b5c01bb5a8f21e7025cf61e --- /dev/null +++ b/node_modules/mdast-util-gfm/index.js @@ -0,0 +1,2 @@ +// Note: types exposed from `index.d.ts`. +export {gfmFromMarkdown, gfmToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-gfm/lib/index.d.ts b/node_modules/mdast-util-gfm/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a4389deced2e26771c0e62db27922ba9d7966ba1 --- /dev/null +++ b/node_modules/mdast-util-gfm/lib/index.d.ts @@ -0,0 +1,24 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM (autolink + * literals, footnotes, strikethrough, tables, tasklists). + * + * @returns {Array} + * Extension for `mdast-util-from-markdown` to enable GFM (autolink literals, + * footnotes, strikethrough, tables, tasklists). + */ +export function gfmFromMarkdown(): Array; +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM (autolink + * literals, footnotes, strikethrough, tables, tasklists). + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM (autolink literals, + * footnotes, strikethrough, tables, tasklists). + */ +export function gfmToMarkdown(options?: Options | null | undefined): ToMarkdownExtension; +import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'; +import type { Options } from 'mdast-util-gfm'; +import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-gfm/lib/index.d.ts.map b/node_modules/mdast-util-gfm/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..a54498681f72f764a8280c561add1ffd0e984faf --- /dev/null +++ b/node_modules/mdast-util-gfm/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAwBA;;;;;;;GAOG;AACH,mCAJa,KAAK,CAAC,qBAAqB,CAAC,CAYxC;AAED;;;;;;;;;GASG;AACH,wCANW,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,mBAAmB,CAc/B;wDA7DoD,0BAA0B;6BACrD,gBAAgB;oDACO,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-gfm/lib/index.js b/node_modules/mdast-util-gfm/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f06b43259b96f0a70933325379ead09354081b5c --- /dev/null +++ b/node_modules/mdast-util-gfm/lib/index.js @@ -0,0 +1,63 @@ +/** + * @import {Extension as FromMarkdownExtension} from 'mdast-util-from-markdown' + * @import {Options} from 'mdast-util-gfm' + * @import {Options as ToMarkdownExtension} from 'mdast-util-to-markdown' + */ + +import { + gfmAutolinkLiteralFromMarkdown, + gfmAutolinkLiteralToMarkdown +} from 'mdast-util-gfm-autolink-literal' +import { + gfmFootnoteFromMarkdown, + gfmFootnoteToMarkdown +} from 'mdast-util-gfm-footnote' +import { + gfmStrikethroughFromMarkdown, + gfmStrikethroughToMarkdown +} from 'mdast-util-gfm-strikethrough' +import {gfmTableFromMarkdown, gfmTableToMarkdown} from 'mdast-util-gfm-table' +import { + gfmTaskListItemFromMarkdown, + gfmTaskListItemToMarkdown +} from 'mdast-util-gfm-task-list-item' + +/** + * Create an extension for `mdast-util-from-markdown` to enable GFM (autolink + * literals, footnotes, strikethrough, tables, tasklists). + * + * @returns {Array} + * Extension for `mdast-util-from-markdown` to enable GFM (autolink literals, + * footnotes, strikethrough, tables, tasklists). + */ +export function gfmFromMarkdown() { + return [ + gfmAutolinkLiteralFromMarkdown(), + gfmFootnoteFromMarkdown(), + gfmStrikethroughFromMarkdown(), + gfmTableFromMarkdown(), + gfmTaskListItemFromMarkdown() + ] +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable GFM (autolink + * literals, footnotes, strikethrough, tables, tasklists). + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable GFM (autolink literals, + * footnotes, strikethrough, tables, tasklists). + */ +export function gfmToMarkdown(options) { + return { + extensions: [ + gfmAutolinkLiteralToMarkdown(), + gfmFootnoteToMarkdown(options), + gfmStrikethroughToMarkdown(), + gfmTableToMarkdown(options), + gfmTaskListItemToMarkdown() + ] + } +} diff --git a/node_modules/mdast-util-gfm/license b/node_modules/mdast-util-gfm/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/mdast-util-gfm/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-gfm/package.json b/node_modules/mdast-util-gfm/package.json new file mode 100644 index 0000000000000000000000000000000000000000..296c0d7ec397ff251f7add82066e1001a8d2ba24 --- /dev/null +++ b/node_modules/mdast-util-gfm/package.json @@ -0,0 +1,125 @@ +{ + "author": "Titus Wormer (https://wooorm.com)", + "bugs": "https://github.com/syntax-tree/mdast-util-gfm/issues", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "dependencies": { + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-gfm-autolink-literal": "^2.0.0", + "mdast-util-gfm-footnote": "^2.0.0", + "mdast-util-gfm-strikethrough": "^2.0.0", + "mdast-util-gfm-table": "^2.0.0", + "mdast-util-gfm-task-list-item": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "description": "mdast extension to parse and serialize GFM (GitHub Flavored Markdown)", + "devDependencies": { + "@types/node": "^22.0.0", + "c8": "^10.0.0", + "github-slugger": "^2.0.0", + "hast-util-to-html": "^9.0.0", + "mdast-util-to-hast": "^13.0.0", + "micromark-extension-gfm": "^3.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^11.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "undici": "^7.0.0", + "xo": "^0.60.0" + }, + "exports": "./index.js", + "files": [ + "index.d.ts", + "index.js", + "lib/" + ], + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "keywords": [ + "autolink", + "gfm", + "github", + "markdown", + "markup", + "mdast-util", + "mdast", + "strikethrough", + "table", + "tagfilter", + "tasklist", + "unist", + "utility", + "util" + ], + "license": "MIT", + "name": "mdast-util-gfm", + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "repository": "syntax-tree/mdast-util-gfm", + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage", + "crawl": "node --conditions development script/crawl-tests.js", + "format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov -- npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "sideEffects": false, + "typeCoverage": { + "atLeast": 100, + "strict": true + }, + "type": "module", + "version": "3.1.0", + "xo": { + "overrides": [ + { + "files": [ + "**/*.d.ts" + ], + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] + } + }, + { + "files": "test/**/*.js", + "rules": { + "no-await-in-loop": "off" + } + } + ], + "prettier": true + } +} diff --git a/node_modules/mdast-util-gfm/readme.md b/node_modules/mdast-util-gfm/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..4fd7f0c8257c9e388c6a7283a76b56b47fb32900 --- /dev/null +++ b/node_modules/mdast-util-gfm/readme.md @@ -0,0 +1,497 @@ +# mdast-util-gfm + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [GFM][] (autolink literals, +footnotes, strikethrough, tables, tasklists). + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmFromMarkdown()`](#gfmfrommarkdown) + * [`gfmToMarkdown(options?)`](#gfmtomarkdownoptions) + * [`Options`](#options) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for GFM syntax in +markdown to [mdast][]: autolink literals (`www.x.com`), footnotes (`[^1]`), +strikethrough (`~~stuff~~`), tables (`| cell |…`), and tasklists (`* [x]`). +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +GFM in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +GFM in syntax trees to markdown). + +## When to use this + +This project is useful when you want to support the same features that GitHub +does in files in a repo, Gists, and several other places. +Users frequently believe that some of these extensions, specifically autolink +literals and tables, are part of normal markdown, so using `mdast-util-gfm` will +help match your implementation to their understanding of markdown. +There are several edge cases where GitHub’s implementation works in unexpected +ways or even different than described in their spec, so *writing* in GFM is not +always the best choice. + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-gfm`][extension]. + +Instead of this package, you can also use the extensions separately: + +* [`mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal) + — support GFM autolink literals +* [`mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote) + — support GFM footnotes +* [`mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough) + — support GFM strikethrough +* [`mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table) + — support GFM tables +* [`mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item) + — support GFM tasklists + +A different utility, [`mdast-util-frontmatter`][mdast-util-frontmatter], adds +support for frontmatter. +GitHub supports YAML frontmatter for files in repos and Gists but they don’t +treat it as part of GFM. + +All these packages are used in [`remark-gfm`][remark-gfm], which +focusses on making it easier to transform content by abstracting these +internals away. + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. +If your content is not in English, you should configure that utility. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-gfm +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmFromMarkdown, gfmToMarkdown} from 'https://esm.sh/mdast-util-gfm@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +# GFM + +## Autolink literals + +www.example.com, https://example.com, and contact@example.com. + +## Footnote + +A note[^1] + +[^1]: Big note. + +## Strikethrough + +~one~ or ~~two~~ tildes. + +## Table + +| a | b | c | d | +| - | :- | -: | :-: | + +## Tasklist + +* [ ] to do +* [x] done +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmFromMarkdown, gfmToMarkdown} from 'mdast-util-gfm' +import {toMarkdown} from 'mdast-util-to-markdown' +import {gfm} from 'micromark-extension-gfm' + +const value = await fs.readFile('example.md', 'utf8') + +const tree = fromMarkdown(value, { + extensions: [gfm()], + mdastExtensions: [gfmFromMarkdown()] +}) + +console.log(tree) + +const result = toMarkdown(tree, {extensions: [gfmToMarkdown()]}) + +console.log(result) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + {type: 'heading', depth: 1, children: [{type: 'text', value: 'GFM'}]}, + { + type: 'heading', + depth: 2, + children: [{type: 'text', value: 'Autolink literals'}] + }, + { + type: 'paragraph', + children: [ + { + type: 'link', + title: null, + url: 'http://www.example.com', + children: [{type: 'text', value: 'www.example.com'}] + }, + {type: 'text', value: ', '}, + { + type: 'link', + title: null, + url: 'https://example.com', + children: [{type: 'text', value: 'https://example.com'}] + }, + {type: 'text', value: ', and '}, + { + type: 'link', + title: null, + url: 'mailto:contact@example.com', + children: [{type: 'text', value: 'contact@example.com'}] + }, + {type: 'text', value: '.'} + ] + }, + {type: 'heading', depth: 2, children: [{type: 'text', value: 'Footnote'}]}, + { + type: 'paragraph', + children: [ + {type: 'text', value: 'A note'}, + {type: 'footnoteReference', identifier: '1', label: '1'} + ] + }, + { + type: 'footnoteDefinition', + identifier: '1', + label: '1', + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'Big note.'}]} + ] + }, + { + type: 'heading', + depth: 2, + children: [{type: 'text', value: 'Strikethrough'}] + }, + { + type: 'paragraph', + children: [ + { + type: 'delete', + children: [{type: 'text', value: 'one'}] + }, + {type: 'text', value: ' or '}, + { + type: 'delete', + children: [{type: 'text', value: 'two'}] + }, + {type: 'text', value: ' tildes.'} + ] + }, + {type: 'heading', depth: 2, children: [{type: 'text', value: 'Table'}]}, + { + type: 'table', + align: [null, 'left', 'right', 'center'], + children: [ + { + type: 'tableRow', + children: [ + {type: 'tableCell', children: [{type: 'text', value: 'a'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'b'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'c'}]}, + {type: 'tableCell', children: [{type: 'text', value: 'd'}]} + ] + } + ] + }, + {type: 'heading', depth: 2, children: [{type: 'text', value: 'Tasklist'}]}, + { + type: 'list', + ordered: false, + start: null, + spread: false, + children: [ + { + type: 'listItem', + spread: false, + checked: false, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'to do'}]} + ] + }, + { + type: 'listItem', + spread: false, + checked: true, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'done'}]} + ] + } + ] + } + ] +} +``` + +```markdown +# GFM + +## Autolink literals + +[www.example.com](http://www.example.com), , and . + +## Footnote + +A note[^1] + +[^1]: Big note. + +## Strikethrough + +~~one~~ or ~~two~~ tildes. + +## Table + +| a | b | c | d | +| - | :- | -: | :-: | + +## Tasklist + +* [ ] to do +* [x] done +``` + +## API + +This package exports the identifiers [`gfmFromMarkdown`][api-gfm-from-markdown] +and [`gfmToMarkdown`][api-gfm-to-markdown]. +There is no default export. + +### `gfmFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable GFM (autolink literals, footnotes, strikethrough, tables, tasklists). + +###### Returns + +Extension for `mdast-util-from-markdown` to enable GFM +([`Array`][from-markdown-extension]). + +### `gfmToMarkdown(options?)` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] +to enable GFM (autolink literals, footnotes, strikethrough, tables, tasklists). + +###### Parameters + +* `options` ([`Options`][api-options]) + — configuration + +###### Returns + +Extension for `mdast-util-to-markdown` to enable GFM +([`Array`][to-markdown-extension]). + +### `Options` + +Configuration (TypeScript type). + +###### Fields + +* `firstLineBlank` (`boolean`, default: `false`) + — use a blank line for the first line of footnote definitions +* `stringLength` (`((value: string) => number)`, default: `s => s.length`) + — function to detect the length of table cell content, used when aligning + the delimiters between cells +* `tableCellPadding` (`boolean`, default: `true`) + — whether to add a space of padding between delimiters and cells +* `tablePipeAlign` (`boolean`, default: `true`) + — whether to align the delimiters + +## HTML + +This utility does not handle how markdown is turned to HTML. +That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. + +## Syntax + +See [Syntax in `micromark-extension-gfm`][syntax]. + +## Syntax tree + +This utility combines several mdast utilities. +See their readmes for the node types supported in the tree: + +* [`mdast-util-gfm-autolink-literal`](https://github.com/syntax-tree/mdast-util-gfm-autolink-literal#syntax-tree) + — GFM autolink literals +* [`mdast-util-gfm-footnote`](https://github.com/syntax-tree/mdast-util-gfm-footnote#syntax-tree) + — GFM footnotes +* [`mdast-util-gfm-strikethrough`](https://github.com/syntax-tree/mdast-util-gfm-strikethrough#syntax-tree) + — GFM strikethrough +* [`mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table#syntax-tree) + — GFM tables +* [`mdast-util-gfm-task-list-item`](https://github.com/syntax-tree/mdast-util-gfm-task-list-item#syntax-tree) + — GFM tasklists + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional type [`Options`][api-options]. + +The `Delete`, `FootnoteDefinition`, `FootnoteReference`, `Table`, `TableRow`, +and `TableCell` types of the mdast nodes are exposed from `@types/mdast`. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-gfm@^3`, +compatible with Node.js 16. + +## Related + +* [`remark-gfm`][remark-gfm] + — remark plugin to support GFM +* [`micromark-extension-gfm`][extension] + — micromark extension to parse GFM + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[api-gfm-from-markdown]: #gfmfrommarkdown + +[api-gfm-to-markdown]: #gfmtomarkdownoptions + +[api-options]: #options + +[author]: https://wooorm.com + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-gfm/actions + +[build-badge]: https://github.com/syntax-tree/mdast-util-gfm/workflows/main/badge.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[collective]: https://opencollective.com/unified + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-gfm + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm.svg + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[extension]: https://github.com/micromark/micromark-extension-gfm + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[gfm]: https://github.github.com/gfm/ + +[health]: https://github.com/syntax-tree/.github + +[license]: license + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-frontmatter]: https://github.com/syntax-tree/mdast-util-frontmatter + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[npm]: https://docs.npmjs.com/cli/install + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[size]: https://bundlejs.com/?q=mdast-util-gfm + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[syntax]: https://github.com/micromark/micromark-extension-gfm#syntax + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[typescript]: https://www.typescriptlang.org diff --git a/node_modules/mdast-util-mdx-expression/index.d.ts b/node_modules/mdast-util-mdx-expression/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..19d5c933d95dfbd56947badfc3ea643b78f39ddb --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/index.d.ts @@ -0,0 +1,161 @@ +import type {Program} from 'estree-jsx' +import type {Data as HastData, Literal as HastLiteral} from 'hast' +import type {Data as MdastData, Literal as MdastLiteral} from 'mdast' + +export { + mdxExpressionFromMarkdown, + mdxExpressionToMarkdown +} from './lib/index.js' + +/** + * MDX expression node, occurring in flow (block). + */ +export interface MdxFlowExpression extends MdastLiteral { + /** + * Node type. + */ + type: 'mdxFlowExpression' + + /** + * Data associated with the mdast MDX expression (flow). + */ + data?: MdxFlowExpressionData | undefined +} + +/** + * Info associated with mdast MDX expression (flow) nodes by the ecosystem. + */ +export interface MdxFlowExpressionData extends MdastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX expression node, occurring in text (phrasing). + */ +export interface MdxTextExpression extends MdastLiteral { + /** + * Node type. + */ + type: 'mdxTextExpression' + + /** + * Data associated with the mdast MDX expression (text). + */ + data?: MdxTextExpressionData | undefined +} + +/** + * Info associated with mdast MDX expression (text) nodes by the ecosystem. + */ +export interface MdxTextExpressionData extends MdastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX expression node, occurring in flow (block), for hast. + */ +export interface MdxFlowExpressionHast extends HastLiteral { + /** + * Node type. + */ + type: 'mdxFlowExpression' + + /** + * Data associated with the hast MDX expression (flow). + */ + data?: MdxFlowExpressionHastData | undefined +} + +/** + * Info associated with hast MDX expression (flow) nodes by the ecosystem. + */ +export interface MdxFlowExpressionHastData extends HastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX expression node, occurring in text (phrasing), for hast. + */ +export interface MdxTextExpressionHast extends HastLiteral { + /** + * Node type. + */ + type: 'mdxTextExpression' + + /** + * Data associated with the hast MDX expression (text). + */ + data?: MdxTextExpressionHastData | undefined +} + +/** + * Info associated with hast MDX expression (text) nodes by the ecosystem. + */ +export interface MdxTextExpressionHastData extends HastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +// Add nodes to mdast content. +declare module 'mdast' { + interface RootContentMap { + /** + * MDX expression node, occurring in text (phrasing). + */ + mdxTextExpression: MdxTextExpression + /** + * MDX expression node, occurring in flow (block). + */ + mdxFlowExpression: MdxFlowExpression + } + + interface PhrasingContentMap { + /** + * MDX expression node, occurring in text (phrasing). + */ + mdxTextExpression: MdxTextExpression + } + + interface BlockContentMap { + /** + * MDX expression node, occurring in flow (block). + */ + mdxFlowExpression: MdxFlowExpression + } +} + +// Add nodes to hast content. +declare module 'hast' { + interface RootContentMap { + /** + * MDX expression node, occurring in flow (block). + */ + mdxFlowExpression: MdxFlowExpressionHast + /** + * MDX expression node, occurring in text (phrasing). + */ + mdxTextExpression: MdxTextExpressionHast + } + + interface ElementContentMap { + /** + * MDX expression node, occurring in flow (block). + */ + mdxFlowExpression: MdxFlowExpressionHast + /** + * MDX expression node, occurring in text (phrasing). + */ + mdxTextExpression: MdxTextExpressionHast + } +} diff --git a/node_modules/mdast-util-mdx-expression/index.js b/node_modules/mdast-util-mdx-expression/index.js new file mode 100644 index 0000000000000000000000000000000000000000..318a6f9f6964cfc846cd916275dc96944eef5bbf --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/index.js @@ -0,0 +1,5 @@ +// Note: types exposed from `index.d.ts`. +export { + mdxExpressionFromMarkdown, + mdxExpressionToMarkdown +} from './lib/index.js' diff --git a/node_modules/mdast-util-mdx-expression/lib/index.d.ts b/node_modules/mdast-util-mdx-expression/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5199a4e44f74d4fd98feb209d97f0ab4f83320a1 --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/lib/index.d.ts @@ -0,0 +1,22 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX expressions + * in markdown. + * + * When using the micromark syntax extension with `addResult`, nodes will have + * a `data.estree` field set to an ESTree `Program` node. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX expressions. + */ +export function mdxExpressionFromMarkdown(): FromMarkdownExtension; +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX expressions + * in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX expressions. + */ +export function mdxExpressionToMarkdown(): ToMarkdownExtension; +import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'; +import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-mdx-expression/lib/index.d.ts.map b/node_modules/mdast-util-mdx-expression/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..deaef1a915455374df177fb4a6d4efc78d0e45f0 --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,6CAHa,qBAAqB,CAgBjC;AAED;;;;;;GAMG;AACH,2CAHa,mBAAmB,CAc/B;wDAnDkG,0BAA0B;oDAEzC,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-mdx-expression/lib/index.js b/node_modules/mdast-util-mdx-expression/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..53f09cba923d125d4fa2205efd2c77ec7cc98a19 --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/lib/index.js @@ -0,0 +1,120 @@ +/** + * @import {CompileContext, Extension as FromMarkdownExtension, Handle as FromMarkdownHandle} from 'mdast-util-from-markdown' + * @import {MdxFlowExpression, MdxTextExpression} from 'mdast-util-mdx-expression' + * @import {Handle as ToMarkdownHandle, Options as ToMarkdownExtension, State} from 'mdast-util-to-markdown' + * @import {Parents} from 'mdast' + */ + +import {ok as assert} from 'devlop' + +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX expressions + * in markdown. + * + * When using the micromark syntax extension with `addResult`, nodes will have + * a `data.estree` field set to an ESTree `Program` node. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX expressions. + */ +export function mdxExpressionFromMarkdown() { + return { + enter: { + mdxFlowExpression: enterMdxFlowExpression, + mdxTextExpression: enterMdxTextExpression + }, + exit: { + mdxFlowExpression: exitMdxExpression, + mdxFlowExpressionChunk: exitMdxExpressionData, + mdxTextExpression: exitMdxExpression, + mdxTextExpressionChunk: exitMdxExpressionData + } + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX expressions + * in markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX expressions. + */ +export function mdxExpressionToMarkdown() { + return { + handlers: { + mdxFlowExpression: handleMdxExpression, + mdxTextExpression: handleMdxExpression + }, + unsafe: [ + {character: '{', inConstruct: ['phrasing']}, + {atBreak: true, character: '{'} + ] + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterMdxFlowExpression(token) { + this.enter({type: 'mdxFlowExpression', value: ''}, token) + this.buffer() +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterMdxTextExpression(token) { + this.enter({type: 'mdxTextExpression', value: ''}, token) + this.buffer() +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitMdxExpression(token) { + const value = this.resume() + const estree = token.estree + const node = this.stack[this.stack.length - 1] + assert(node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') + this.exit(token) + node.value = value + + if (estree) { + node.data = {estree} + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitMdxExpressionData(token) { + this.config.enter.data.call(this, token) + this.config.exit.data.call(this, token) +} + +/** + * @type {ToMarkdownHandle} + * @param {MdxFlowExpression | MdxTextExpression} node + * Node. + * @param {Parents | undefined} parent + * Parent, if any. + * @param {State} state + * Info passed around about the current state. + * @returns {string} + * Serialized markdown. + */ +function handleMdxExpression(node, parent, state) { + const value = node.value || '' + const result = state.indentLines(value, function (line, index, blank) { + // Tab-size to eat has to be the same as what we serialize as. + // While in some places in markdown that’s 4, in JS it’s more common as 2. + // Which is what’s also in `mdast-util-mdx-jsx`: + // + return (index === 0 || blank ? '' : ' ') + line + }) + return '{' + result + '}' +} diff --git a/node_modules/mdast-util-mdx-expression/license b/node_modules/mdast-util-mdx-expression/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-mdx-expression/package.json b/node_modules/mdast-util-mdx-expression/package.json new file mode 100644 index 0000000000000000000000000000000000000000..b007d5a97d8239e54fb275292e509822528a4610 --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/package.json @@ -0,0 +1,106 @@ +{ + "name": "mdast-util-mdx-expression", + "version": "2.0.1", + "description": "mdast extension to parse and serialize MDX (or MDX.js) expressions", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "mdx", + "mdxjs", + "expression", + "extension" + ], + "repository": "syntax-tree/mdast-util-mdx-expression", + "bugs": "https://github.com/syntax-tree/mdast-util-mdx-expression/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "complex-types.d.ts", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/estree-jsx": "^1.0.0", + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "devlop": "^1.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "devDependencies": { + "@types/acorn": "^4.0.0", + "@types/node": "^22.0.0", + "acorn": "^8.0.0", + "c8": "^10.0.0", + "micromark-extension-mdx-expression": "^3.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.59.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true, + "rules": { + "unicorn/prefer-at": "off" + } + } +} diff --git a/node_modules/mdast-util-mdx-expression/readme.md b/node_modules/mdast-util-mdx-expression/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..38208dc992febcb83ba349ab2f743f3015fb8593 --- /dev/null +++ b/node_modules/mdast-util-mdx-expression/readme.md @@ -0,0 +1,531 @@ +# mdast-util-mdx-expression + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [MDX][] expressions (`{Math.PI}`). + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`mdxExpressionFromMarkdown()`](#mdxexpressionfrommarkdown) + * [`mdxExpressionToMarkdown()`](#mdxexpressiontomarkdown) + * [`MdxFlowExpression`](#mdxflowexpression) + * [`MdxTextExpression`](#mdxtextexpression) + * [`MdxFlowExpressionHast`](#mdxflowexpressionhast) + * [`MdxTextExpressionHast`](#mdxtextexpressionhast) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for MDX expression syntax +in markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +expressions in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +expressions in syntax trees to markdown). + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-mdx-expression`][extension]. + +When you are working with syntax trees and want all of MDX, use +[`mdast-util-mdx`][mdast-util-mdx] instead. + +All these packages are used in [`remark-mdx`][remark-mdx], which +focusses on making it easier to transform content by abstracting these +internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-mdx-expression +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {mdxExpressionFromMarkdown, mdxExpressionToMarkdown} from 'https://esm.sh/mdast-util-mdx-expression@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.mdx` contains: + +```mdx +{ + a + 1 +} + +b {true}. +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import * as acorn from 'acorn' +import {mdxExpression} from 'micromark-extension-mdx-expression' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {mdxExpressionFromMarkdown, mdxExpressionToMarkdown} from 'mdast-util-mdx-expression' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.mdx') + +const tree = fromMarkdown(doc, { + extensions: [mdxExpression({acorn, addResult: true})], + mdastExtensions: [mdxExpressionFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [mdxExpressionToMarkdown()]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'mdxFlowExpression', + value: '\na + 1\n', + data: { + estree: { + type: 'Program', + body: [ + { + type: 'ExpressionStatement', + expression: { + type: 'BinaryExpression', + left: {type: 'Identifier', name: 'a'}, + operator: '+', + right: {type: 'Literal', value: 1, raw: '1'} + } + } + ], + sourceType: 'module' + } + } + }, + { + type: 'paragraph', + children: [ + {type: 'text', value: 'b '}, + { + type: 'mdxTextExpression', + value: 'true', + data: { + estree: { + type: 'Program', + body: [ + { + type: 'ExpressionStatement', + expression: {type: 'Literal', value: true, raw: 'true'} + } + ], + sourceType: 'module' + } + } + }, + {type: 'text', value: '.'} + ] + } + ] +} +``` + +```markdown +{ + a + 1 +} + +b {true}. +``` + +## API + +This package exports the identifiers +[`mdxExpressionFromMarkdown`][api-mdx-expression-from-markdown] and +[`mdxExpressionToMarkdown`][api-mdx-expression-to-markdown]. +There is no default export. + +### `mdxExpressionFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable MDX expressions in markdown. + +When using the [micromark syntax extension][extension] with `addResult`, nodes +will have a `data.estree` field set to an ESTree [`Program`][program] node. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable MDX expressions +([`FromMarkdownExtension`][from-markdown-extension]). + +### `mdxExpressionToMarkdown()` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] +to enable MDX expressions in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable MDX expressions +([`ToMarkdownExtension`][to-markdown-extension]). + +### `MdxFlowExpression` + +MDX expression node, occurring in flow (block) (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'mdast' + +interface MdxFlowExpression extends Literal { + type: 'mdxFlowExpression' + data?: MdxFlowExpressionData | undefined +} + +interface MdxFlowExpressionData extends Data { + estree?: Program | null | undefined +} +``` + +### `MdxTextExpression` + +MDX expression node, occurring in text (block) (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'mdast' + +interface MdxTextExpression extends Literal { + type: 'mdxTextExpression' + data?: MdxTextExpressionData | undefined +} + +interface MdxTextExpressionData extends Data { + estree?: Program | null | undefined +} +``` + +### `MdxFlowExpressionHast` + +Same as [`MdxFlowExpression`][api-mdx-flow-expression], but registered with +`@types/hast` (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'hast' + +interface MdxFlowExpressionHast extends Literal { + type: 'mdxFlowExpression' + data?: MdxFlowExpressionData | undefined +} + +interface MdxFlowExpressionData extends Data { + estree?: Program | null | undefined +} +``` + +### `MdxTextExpressionHast` + +Same as [`MdxTextExpression`][api-mdx-text-expression], but registered with +`@types/hast` (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'hast' + +interface MdxTextExpressionHast extends Literal { + type: 'mdxTextExpression' + data?: MdxTextExpressionData | undefined +} + +interface MdxTextExpressionData extends Data { + estree?: Program | null | undefined +} +``` + +## HTML + +MDX expressions have no representation in HTML. +Though, when you are dealing with MDX, you will likely go *through* hast. +You can enable passing MDX expressions through to hast by configuring +[`mdast-util-to-hast`][mdast-util-to-hast] with +`passThrough: ['mdxFlowExpression', 'mdxTextExpression']`. + +## Syntax + +See [Syntax in `micromark-extension-mdx-expression`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `MdxFlowExpression` + +```idl +interface MdxFlowExpression <: Literal { + type: 'mdxFlowExpression' +} +``` + +**MdxFlowExpression** (**[Literal][dfn-literal]**) represents a JavaScript +expression embedded in flow (block). +It can be used where **[flow][dfn-flow-content]** content is expected. +Its content is represented by its `value` field. + +For example, the following markdown: + +```markdown +{ + 1 + 1 +} +``` + +Yields: + +```js +{type: 'mdxFlowExpression', value: '\n1 + 1\n'} +``` + +#### `MdxTextExpression` + +```idl +interface MdxTextExpression <: Literal { + type: 'mdxTextExpression" +} +``` + +**MdxTextExpression** (**[Literal][dfn-literal]**) represents a JavaScript +expression embedded in text (span, inline). +It can be used where **[phrasing][dfn-phrasing-content]** content is expected. +Its content is represented by its `value` field. + +For example, the following markdown: + +```markdown +a {1 + 1} b. +``` + +Yields: + +```js +{type: 'mdxTextExpression', value: '1 + 1'} +``` + +### Content model + +#### `FlowContent` (MDX expression) + +```idl +type FlowContentMdxExpression = MdxFlowExpression | FlowContent +``` + +#### `PhrasingContent` (MDX expression) + +```idl +type PhrasingContentMdxExpression = MdxTextExpression | PhrasingContent +``` + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`MdxFlowExpression`][api-mdx-flow-expression], +[`MdxFlowExpressionHast`][api-mdx-flow-expression-hast], +[`MdxTextExpression`][api-mdx-text-expression], and +[`MdxTextExpressionHast`][api-mdx-text-expression-hast]. + +It also registers the node types with `@types/mdast` and `@types/hast`. +If you’re working with the syntax tree, make sure to import this utility +somewhere in your types, as that registers the new node types in the tree. + +```js +/** + * @import {} from 'mdast-util-mdx-expression' + * @import {Root} from 'mdast' + */ + +import {visit} from 'unist-util-visit' + +/** @type {Root} */ +const tree = getMdastNodeSomeHow() + +visit(tree, function (node) { + // `node` can now be an expression node. +}) +``` + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-mdx-expression@^2`, compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`remarkjs/remark-mdx`][remark-mdx] + — remark plugin to support MDX +* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx] + — mdast utility to support MDX +* [`micromark/micromark-extension-mdx-expression`][extension] + — micromark extension to parse MDX expressions + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-mdx-expression/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-mdx-expression/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-mdx-expression.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-mdx-expression + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-mdx-expression.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-mdx-expression + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdx-expression + +[size]: https://bundlejs.com/?q=mdast-util-mdx-expression + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx + +[extension]: https://github.com/micromark/micromark-extension-mdx-expression + +[syntax]: https://github.com/micromark/micromark-extension-mdx-expression#syntax + +[program]: https://github.com/estree/estree/blob/master/es2015.md#programs + +[dfn-literal]: https://github.com/syntax-tree/mdast#literal + +[remark-mdx]: https://mdxjs.com/packages/remark-mdx/ + +[mdx]: https://mdxjs.com + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[api-mdx-expression-from-markdown]: #mdxexpressionfrommarkdown + +[api-mdx-expression-to-markdown]: #mdxexpressiontomarkdown + +[api-mdx-flow-expression]: #mdxflowexpression + +[api-mdx-text-expression]: #mdxtextexpression + +[api-mdx-flow-expression-hast]: #mdxflowexpressionhast + +[api-mdx-text-expression-hast]: #mdxtextexpressionhast + +[dfn-flow-content]: #flowcontent-mdx-expression + +[dfn-phrasing-content]: #phrasingcontent-mdx-expression diff --git a/node_modules/mdast-util-mdx-jsx/index.d.ts b/node_modules/mdast-util-mdx-jsx/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1bd5ddb66d65c18f7d8132066019826d6aac46c4 --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/index.d.ts @@ -0,0 +1,344 @@ +import type {Program} from 'estree-jsx' +import type {Data as HastData, ElementContent, Parent as HastParent} from 'hast' +import type { + BlockContent, + Data as MdastData, + DefinitionContent, + Parent as MdastParent, + PhrasingContent +} from 'mdast' +import type {Data, Node} from 'unist' +import type {Tag} from './lib/index.js' + +// Expose JavaScript API. +export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js' + +// Expose options. +export type {ToMarkdownOptions} from './lib/index.js' + +// Expose node types. +/** + * MDX JSX attribute value set to an expression. + * + * ```markdown + * > | + * ^^^ + * ``` + */ +export interface MdxJsxAttributeValueExpression extends Node { + /** + * Node type. + */ + type: 'mdxJsxAttributeValueExpression' + + /** + * Value. + */ + value: string + + /** + * Data associated with the mdast MDX JSX attribute value expression. + */ + data?: MdxJsxAttributeValueExpressionData | undefined +} + +/** + * Info associated with mdast MDX JSX attribute value expression nodes by the + * ecosystem. + */ +export interface MdxJsxAttributeValueExpressionData extends Data { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX JSX attribute as an expression. + * + * ```markdown + * > | + * ^^^^^^ + * ``` + */ +export interface MdxJsxExpressionAttribute extends Node { + /** + * Node type. + */ + type: 'mdxJsxExpressionAttribute' + + /** + * Value. + */ + value: string + + /** + * Data associated with the mdast MDX JSX expression attributes. + */ + data?: MdxJsxExpressionAttributeData | undefined +} + +/** + * Info associated with mdast MDX JSX expression attribute nodes by the + * ecosystem. + */ +export interface MdxJsxExpressionAttributeData extends Data { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX JSX attribute with a key. + * + * ```markdown + * > | + * ^^^^^ + * ``` + */ +export interface MdxJsxAttribute extends Node { + /** + * Node type. + */ + type: 'mdxJsxAttribute' + /** + * Attribute name. + */ + name: string + /** + * Attribute value. + */ + value?: MdxJsxAttributeValueExpression | string | null | undefined + /** + * Data associated with the mdast MDX JSX attribute. + */ + data?: MdxJsxAttributeData | undefined +} + +/** + * Info associated with mdast MDX JSX attribute nodes by the + * ecosystem. + */ +export interface MdxJsxAttributeData extends Data {} + +/** + * MDX JSX element node, occurring in flow (block). + */ +export interface MdxJsxFlowElement extends MdastParent { + /** + * Node type. + */ + type: 'mdxJsxFlowElement' + /** + * MDX JSX element name (`null` for fragments). + */ + name: string | null + /** + * MDX JSX element attributes. + */ + attributes: Array + /** + * Content. + */ + children: Array + /** + * Data associated with the mdast MDX JSX elements (flow). + */ + data?: MdxJsxFlowElementData | undefined +} + +/** + * Info associated with mdast MDX JSX element (flow) nodes by the + * ecosystem. + */ +export interface MdxJsxFlowElementData extends MdastData {} + +/** + * MDX JSX element node, occurring in text (phrasing). + */ +export interface MdxJsxTextElement extends MdastParent { + /** + * Node type. + */ + type: 'mdxJsxTextElement' + /** + * MDX JSX element name (`null` for fragments). + */ + name: string | null + /** + * MDX JSX element attributes. + */ + attributes: Array + /** + * Content. + */ + children: PhrasingContent[] + /** + * Data associated with the mdast MDX JSX elements (text). + */ + data?: MdxJsxTextElementData | undefined +} + +/** + * Info associated with mdast MDX JSX element (text) nodes by the + * ecosystem. + */ +export interface MdxJsxTextElementData extends MdastData {} + +/** + * MDX JSX element node, occurring in flow (block), for hast. + */ +export interface MdxJsxFlowElementHast extends HastParent { + /** + * Node type. + */ + type: 'mdxJsxFlowElement' + /** + * MDX JSX element name (`null` for fragments). + */ + name: string | null + /** + * MDX JSX element attributes. + */ + attributes: Array + /** + * Content. + */ + children: ElementContent[] + /** + * Data associated with the hast MDX JSX elements (flow). + */ + data?: MdxJsxFlowElementHastData | undefined +} + +/** + * Info associated with hast MDX JSX element (flow) nodes by the + * ecosystem. + */ +export interface MdxJsxFlowElementHastData extends HastData {} + +/** + * MDX JSX element node, occurring in text (phrasing), for hast. + */ +export interface MdxJsxTextElementHast extends HastParent { + /** + * Node type. + */ + type: 'mdxJsxTextElement' + /** + * MDX JSX element name (`null` for fragments). + */ + name: string | null + /** + * MDX JSX element attributes. + */ + attributes: Array + /** + * Content. + */ + children: ElementContent[] + /** + * Data associated with the hast MDX JSX elements (text). + */ + data?: MdxJsxTextElementHastData | undefined +} + +/** + * Info associated with hast MDX JSX element (text) nodes by the + * ecosystem. + */ +export interface MdxJsxTextElementHastData extends HastData {} + +// Add nodes to mdast content. +declare module 'mdast' { + interface BlockContentMap { + /** + * MDX JSX element node, occurring in flow (block). + */ + mdxJsxFlowElement: MdxJsxFlowElement + } + + interface PhrasingContentMap { + /** + * MDX JSX element node, occurring in text (phrasing). + */ + mdxJsxTextElement: MdxJsxTextElement + } + + interface RootContentMap { + /** + * MDX JSX element node, occurring in flow (block). + */ + mdxJsxFlowElement: MdxJsxFlowElement + /** + * MDX JSX element node, occurring in text (phrasing). + */ + mdxJsxTextElement: MdxJsxTextElement + } +} + +// Add nodes to hast content. +declare module 'hast' { + interface ElementContentMap { + /** + * MDX JSX element node, occurring in text (phrasing). + */ + mdxJsxTextElement: MdxJsxTextElementHast + /** + * MDX JSX element node, occurring in flow (block). + */ + mdxJsxFlowElement: MdxJsxFlowElementHast + } + + interface RootContentMap { + /** + * MDX JSX element node, occurring in text (phrasing). + */ + mdxJsxTextElement: MdxJsxTextElementHast + /** + * MDX JSX element node, occurring in flow (block). + */ + mdxJsxFlowElement: MdxJsxFlowElementHast + } +} + +// Add custom data tracked to turn markdown into a tree. +declare module 'mdast-util-from-markdown' { + interface CompileData { + /** + * Current MDX JSX tag. + */ + mdxJsxTag?: Tag | undefined + + /** + * Current stack of open MDX JSX tags. + */ + mdxJsxTagStack?: Tag[] | undefined + } +} + +// Add custom data tracked to turn a syntax tree into markdown. +declare module 'mdast-util-to-markdown' { + interface ConstructNameMap { + /** + * Whole JSX element, in flow. + * + * ```markdown + * > | + * ^^^^^ + * ``` + */ + mdxJsxFlowElement: 'mdxJsxFlowElement' + + /** + * Whole JSX element, in text. + * + * ```markdown + * > | a . + * ^^^^^ + * ``` + */ + mdxJsxTextElement: 'mdxJsxTextElement' + } +} diff --git a/node_modules/mdast-util-mdx-jsx/index.js b/node_modules/mdast-util-mdx-jsx/index.js new file mode 100644 index 0000000000000000000000000000000000000000..37d9cd539d0fc8bdf88868e761b285609833872b --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/index.js @@ -0,0 +1,2 @@ +// Note: types exposed from `index.d.ts`. +export {mdxJsxFromMarkdown, mdxJsxToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-mdx-jsx/lib/index.d.ts b/node_modules/mdast-util-mdx-jsx/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..9106304c9a4ed3e1aea387443a9b43b53815419a --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/lib/index.d.ts @@ -0,0 +1,88 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX JSX. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX JSX. + * + * When using the syntax extension with `addResult`, nodes will have a + * `data.estree` field set to an ESTree `Program` node. + */ +export function mdxJsxFromMarkdown(): FromMarkdownExtension; +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX JSX. + * + * This extension configures `mdast-util-to-markdown` with + * `options.fences: true` and `options.resourceLink: true` too, do not + * overwrite them! + * + * @param {ToMarkdownOptions | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX JSX. + */ +export function mdxJsxToMarkdown(options?: ToMarkdownOptions | null | undefined): ToMarkdownExtension; +/** + * Single tag. + */ +export type Tag = { + /** + * Name of tag, or `undefined` for fragment. + * + * > 👉 **Note**: `null` is used in the AST for fragments, as it serializes in + * > JSON. + */ + name: string | undefined; + /** + * Attributes. + */ + attributes: Array; + /** + * Whether the tag is closing (``). + */ + close: boolean; + /** + * Whether the tag is self-closing (``). + */ + selfClosing: boolean; + /** + * Start point. + */ + start: Token["start"]; + /** + * End point. + */ + end: Token["start"]; +}; +/** + * Configuration. + */ +export type ToMarkdownOptions = { + /** + * Preferred quote to use around attribute values (default: `'"'`). + */ + quote?: "\"" | "'" | null | undefined; + /** + * Use the other quote if that results in less bytes (default: `false`). + */ + quoteSmart?: boolean | null | undefined; + /** + * Do not use an extra space when closing self-closing elements: `` + * instead of `` (default: `false`). + */ + tightSelfClosing?: boolean | null | undefined; + /** + * Try and wrap syntax at this width (default: `Infinity`). + * + * When set to a finite number (say, `80`), the formatter will print + * attributes on separate lines when a tag doesn’t fit on one line. + * The normal behavior is to print attributes with spaces between them + * instead of line endings. + */ + printWidth?: number | null | undefined; +}; +import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'; +import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'; +import type { MdxJsxAttribute } from '../index.js'; +import type { MdxJsxExpressionAttribute } from '../index.js'; +import type { Token } from 'mdast-util-from-markdown'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-mdx-jsx/lib/index.d.ts.map b/node_modules/mdast-util-mdx-jsx/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..bcc5f22b0725f8f47d7590104f81bf86d01ba01d --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAqDA;;;;;;;;GAQG;AACH,sCANa,qBAAqB,CAgcjC;AAED;;;;;;;;;;;GAWG;AACH,2CALW,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAElC,mBAAmB,CAqL/B;;;;;;;;;;;UA9qBa,MAAM,GAAG,SAAS;;;;gBAKlB,KAAK,CAAC,eAAe,GAAG,yBAAyB,CAAC;;;;WAElD,OAAO;;;;iBAEP,OAAO;;;;WAEP,KAAK,CAAC,OAAO,CAAC;;;;SAEd,KAAK,CAAC,OAAO,CAAC;;;;;;;;;YAKd,IAAG,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS;;;;iBAE5B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;uBAE1B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;;;;iBAG1B,MAAM,GAAG,IAAI,GAAG,SAAS;;wDAlC8F,0BAA0B;oDAClE,wBAAwB;qCAEc,aAAa;+CAAb,aAAa;2BAHX,0BAA0B"} \ No newline at end of file diff --git a/node_modules/mdast-util-mdx-jsx/lib/index.js b/node_modules/mdast-util-mdx-jsx/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8f73b1e1e8391cb8364c736a352dd87de2c84223 --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/lib/index.js @@ -0,0 +1,789 @@ +/** + * @import {CompileContext, Extension as FromMarkdownExtension, Handle as FromMarkdownHandle, OnEnterError, OnExitError, Token} from 'mdast-util-from-markdown' + * @import {Handle as ToMarkdownHandle, Options as ToMarkdownExtension, State, Tracker} from 'mdast-util-to-markdown' + * @import {Point} from 'unist' + * @import {MdxJsxAttribute, MdxJsxAttributeValueExpression, MdxJsxExpressionAttribute, MdxJsxFlowElement, MdxJsxTextElement} from '../index.js' + */ + +/** + * @typedef Tag + * Single tag. + * @property {string | undefined} name + * Name of tag, or `undefined` for fragment. + * + * > 👉 **Note**: `null` is used in the AST for fragments, as it serializes in + * > JSON. + * @property {Array} attributes + * Attributes. + * @property {boolean} close + * Whether the tag is closing (``). + * @property {boolean} selfClosing + * Whether the tag is self-closing (``). + * @property {Token['start']} start + * Start point. + * @property {Token['start']} end + * End point. + * + * @typedef ToMarkdownOptions + * Configuration. + * @property {'"' | "'" | null | undefined} [quote='"'] + * Preferred quote to use around attribute values (default: `'"'`). + * @property {boolean | null | undefined} [quoteSmart=false] + * Use the other quote if that results in less bytes (default: `false`). + * @property {boolean | null | undefined} [tightSelfClosing=false] + * Do not use an extra space when closing self-closing elements: `` + * instead of `` (default: `false`). + * @property {number | null | undefined} [printWidth=Infinity] + * Try and wrap syntax at this width (default: `Infinity`). + * + * When set to a finite number (say, `80`), the formatter will print + * attributes on separate lines when a tag doesn’t fit on one line. + * The normal behavior is to print attributes with spaces between them + * instead of line endings. + */ + +import {ccount} from 'ccount' +import {ok as assert} from 'devlop' +import {parseEntities} from 'parse-entities' +import {stringifyEntitiesLight} from 'stringify-entities' +import {stringifyPosition} from 'unist-util-stringify-position' +import {VFileMessage} from 'vfile-message' + +const indent = ' ' + +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX JSX. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX JSX. + * + * When using the syntax extension with `addResult`, nodes will have a + * `data.estree` field set to an ESTree `Program` node. + */ +export function mdxJsxFromMarkdown() { + return { + canContainEols: ['mdxJsxTextElement'], + enter: { + mdxJsxFlowTag: enterMdxJsxTag, + mdxJsxFlowTagClosingMarker: enterMdxJsxTagClosingMarker, + mdxJsxFlowTagAttribute: enterMdxJsxTagAttribute, + mdxJsxFlowTagExpressionAttribute: enterMdxJsxTagExpressionAttribute, + mdxJsxFlowTagAttributeValueLiteral: buffer, + mdxJsxFlowTagAttributeValueExpression: buffer, + mdxJsxFlowTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker, + + mdxJsxTextTag: enterMdxJsxTag, + mdxJsxTextTagClosingMarker: enterMdxJsxTagClosingMarker, + mdxJsxTextTagAttribute: enterMdxJsxTagAttribute, + mdxJsxTextTagExpressionAttribute: enterMdxJsxTagExpressionAttribute, + mdxJsxTextTagAttributeValueLiteral: buffer, + mdxJsxTextTagAttributeValueExpression: buffer, + mdxJsxTextTagSelfClosingMarker: enterMdxJsxTagSelfClosingMarker + }, + exit: { + mdxJsxFlowTagClosingMarker: exitMdxJsxTagClosingMarker, + mdxJsxFlowTagNamePrimary: exitMdxJsxTagNamePrimary, + mdxJsxFlowTagNameMember: exitMdxJsxTagNameMember, + mdxJsxFlowTagNameLocal: exitMdxJsxTagNameLocal, + mdxJsxFlowTagExpressionAttribute: exitMdxJsxTagExpressionAttribute, + mdxJsxFlowTagExpressionAttributeValue: data, + mdxJsxFlowTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary, + mdxJsxFlowTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal, + mdxJsxFlowTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral, + mdxJsxFlowTagAttributeValueLiteralValue: data, + mdxJsxFlowTagAttributeValueExpression: + exitMdxJsxTagAttributeValueExpression, + mdxJsxFlowTagAttributeValueExpressionValue: data, + mdxJsxFlowTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker, + mdxJsxFlowTag: exitMdxJsxTag, + + mdxJsxTextTagClosingMarker: exitMdxJsxTagClosingMarker, + mdxJsxTextTagNamePrimary: exitMdxJsxTagNamePrimary, + mdxJsxTextTagNameMember: exitMdxJsxTagNameMember, + mdxJsxTextTagNameLocal: exitMdxJsxTagNameLocal, + mdxJsxTextTagExpressionAttribute: exitMdxJsxTagExpressionAttribute, + mdxJsxTextTagExpressionAttributeValue: data, + mdxJsxTextTagAttributeNamePrimary: exitMdxJsxTagAttributeNamePrimary, + mdxJsxTextTagAttributeNameLocal: exitMdxJsxTagAttributeNameLocal, + mdxJsxTextTagAttributeValueLiteral: exitMdxJsxTagAttributeValueLiteral, + mdxJsxTextTagAttributeValueLiteralValue: data, + mdxJsxTextTagAttributeValueExpression: + exitMdxJsxTagAttributeValueExpression, + mdxJsxTextTagAttributeValueExpressionValue: data, + mdxJsxTextTagSelfClosingMarker: exitMdxJsxTagSelfClosingMarker, + mdxJsxTextTag: exitMdxJsxTag + } + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function buffer() { + this.buffer() + } + + /** + * Copy a point-like value. + * + * @param {Point} d + * Point-like value. + * @returns {Point} + * unist point. + */ + function point(d) { + return {line: d.line, column: d.column, offset: d.offset} + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function data(token) { + this.config.enter.data.call(this, token) + this.config.exit.data.call(this, token) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTag(token) { + /** @type {Tag} */ + const tag = { + name: undefined, + attributes: [], + close: false, + selfClosing: false, + start: token.start, + end: token.end + } + if (!this.data.mdxJsxTagStack) this.data.mdxJsxTagStack = [] + this.data.mdxJsxTag = tag + this.buffer() + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTagClosingMarker(token) { + const stack = this.data.mdxJsxTagStack + assert(stack, 'expected `mdxJsxTagStack`') + + if (stack.length === 0) { + throw new VFileMessage( + 'Unexpected closing slash `/` in tag, expected an open tag first', + {start: token.start, end: token.end}, + 'mdast-util-mdx-jsx:unexpected-closing-slash' + ) + } + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTagAnyAttribute(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + + if (tag.close) { + throw new VFileMessage( + 'Unexpected attribute in closing tag, expected the end of the tag', + {start: token.start, end: token.end}, + 'mdast-util-mdx-jsx:unexpected-attribute' + ) + } + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTagSelfClosingMarker(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + + if (tag.close) { + throw new VFileMessage( + 'Unexpected self-closing slash `/` in closing tag, expected the end of the tag', + {start: token.start, end: token.end}, + 'mdast-util-mdx-jsx:unexpected-self-closing-slash' + ) + } + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagClosingMarker() { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + tag.close = true + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagNamePrimary(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + tag.name = this.sliceSerialize(token) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagNameMember(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + tag.name += '.' + this.sliceSerialize(token) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagNameLocal(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + tag.name += ':' + this.sliceSerialize(token) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTagAttribute(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + enterMdxJsxTagAnyAttribute.call(this, token) + tag.attributes.push({ + type: 'mdxJsxAttribute', + name: '', + value: null, + position: { + start: point(token.start), + // @ts-expect-error: `end` will be patched later. + end: undefined + } + }) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function enterMdxJsxTagExpressionAttribute(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + enterMdxJsxTagAnyAttribute.call(this, token) + tag.attributes.push({ + type: 'mdxJsxExpressionAttribute', + value: '', + position: { + start: point(token.start), + // @ts-expect-error: `end` will be patched later. + end: undefined + } + }) + this.buffer() + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagExpressionAttribute(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const tail = tag.attributes[tag.attributes.length - 1] + assert(tail.type === 'mdxJsxExpressionAttribute') + const estree = token.estree + + tail.value = this.resume() + assert(tail.position !== undefined) + tail.position.end = point(token.end) + + if (estree) { + tail.data = {estree} + } + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagAttributeNamePrimary(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const node = tag.attributes[tag.attributes.length - 1] + assert(node.type === 'mdxJsxAttribute') + node.name = this.sliceSerialize(token) + assert(node.position !== undefined) + node.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagAttributeNameLocal(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const node = tag.attributes[tag.attributes.length - 1] + assert(node.type === 'mdxJsxAttribute') + node.name += ':' + this.sliceSerialize(token) + assert(node.position !== undefined) + node.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagAttributeValueLiteral(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const node = tag.attributes[tag.attributes.length - 1] + node.value = parseEntities(this.resume(), {nonTerminated: false}) + assert(node.position !== undefined) + node.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagAttributeValueExpression(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const tail = tag.attributes[tag.attributes.length - 1] + assert(tail.type === 'mdxJsxAttribute') + /** @type {MdxJsxAttributeValueExpression} */ + const node = {type: 'mdxJsxAttributeValueExpression', value: this.resume()} + const estree = token.estree + + if (estree) { + node.data = {estree} + } + + tail.value = node + assert(tail.position !== undefined) + tail.position.end = point(token.end) + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTagSelfClosingMarker() { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + + tag.selfClosing = true + } + + /** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ + function exitMdxJsxTag(token) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + const stack = this.data.mdxJsxTagStack + assert(stack, 'expected `mdxJsxTagStack`') + const tail = stack[stack.length - 1] + + if (tag.close && tail.name !== tag.name) { + throw new VFileMessage( + 'Unexpected closing tag `' + + serializeAbbreviatedTag(tag) + + '`, expected corresponding closing tag for `' + + serializeAbbreviatedTag(tail) + + '` (' + + stringifyPosition(tail) + + ')', + {start: token.start, end: token.end}, + 'mdast-util-mdx-jsx:end-tag-mismatch' + ) + } + + // End of a tag, so drop the buffer. + this.resume() + + if (tag.close) { + stack.pop() + } else { + this.enter( + { + type: + token.type === 'mdxJsxTextTag' + ? 'mdxJsxTextElement' + : 'mdxJsxFlowElement', + name: tag.name || null, + attributes: tag.attributes, + children: [] + }, + token, + onErrorRightIsTag + ) + } + + if (tag.selfClosing || tag.close) { + this.exit(token, onErrorLeftIsTag) + } else { + stack.push(tag) + } + } + + /** + * @this {CompileContext} + * @type {OnEnterError} + */ + function onErrorRightIsTag(closing, open) { + const stack = this.data.mdxJsxTagStack + assert(stack, 'expected `mdxJsxTagStack`') + const tag = stack[stack.length - 1] + assert(tag, 'expected `mdxJsxTag`') + const place = closing ? ' before the end of `' + closing.type + '`' : '' + const position = closing + ? {start: closing.start, end: closing.end} + : undefined + + throw new VFileMessage( + 'Expected a closing tag for `' + + serializeAbbreviatedTag(tag) + + '` (' + + stringifyPosition({start: open.start, end: open.end}) + + ')' + + place, + position, + 'mdast-util-mdx-jsx:end-tag-mismatch' + ) + } + + /** + * @this {CompileContext} + * @type {OnExitError} + */ + function onErrorLeftIsTag(a, b) { + const tag = this.data.mdxJsxTag + assert(tag, 'expected `mdxJsxTag`') + + throw new VFileMessage( + 'Expected the closing tag `' + + serializeAbbreviatedTag(tag) + + '` either after the end of `' + + b.type + + '` (' + + stringifyPosition(b.end) + + ') or another opening tag after the start of `' + + b.type + + '` (' + + stringifyPosition(b.start) + + ')', + {start: a.start, end: a.end}, + 'mdast-util-mdx-jsx:end-tag-mismatch' + ) + } + + /** + * Serialize a tag, excluding attributes. + * `self-closing` is not supported, because we don’t need it yet. + * + * @param {Tag} tag + * @returns {string} + */ + function serializeAbbreviatedTag(tag) { + return '<' + (tag.close ? '/' : '') + (tag.name || '') + '>' + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX JSX. + * + * This extension configures `mdast-util-to-markdown` with + * `options.fences: true` and `options.resourceLink: true` too, do not + * overwrite them! + * + * @param {ToMarkdownOptions | null | undefined} [options] + * Configuration (optional). + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX JSX. + */ +export function mdxJsxToMarkdown(options) { + const options_ = options || {} + const quote = options_.quote || '"' + const quoteSmart = options_.quoteSmart || false + const tightSelfClosing = options_.tightSelfClosing || false + const printWidth = options_.printWidth || Number.POSITIVE_INFINITY + const alternative = quote === '"' ? "'" : '"' + + if (quote !== '"' && quote !== "'") { + throw new Error( + 'Cannot serialize attribute values with `' + + quote + + '` for `options.quote`, expected `"`, or `\'`' + ) + } + + mdxElement.peek = peekElement + + return { + handlers: { + mdxJsxFlowElement: mdxElement, + mdxJsxTextElement: mdxElement + }, + unsafe: [ + {character: '<', inConstruct: ['phrasing']}, + {atBreak: true, character: '<'} + ], + // Always generate fenced code (never indented code). + fences: true, + // Always generate links with resources (never autolinks). + resourceLink: true + } + + /** + * @type {ToMarkdownHandle} + * @param {MdxJsxFlowElement | MdxJsxTextElement} node + */ + // eslint-disable-next-line complexity + function mdxElement(node, _, state, info) { + const flow = node.type === 'mdxJsxFlowElement' + const selfClosing = node.name + ? !node.children || node.children.length === 0 + : false + const depth = inferDepth(state) + const currentIndent = createIndent(depth) + const trackerOneLine = state.createTracker(info) + const trackerMultiLine = state.createTracker(info) + /** @type {Array} */ + const serializedAttributes = [] + const prefix = (flow ? currentIndent : '') + '<' + (node.name || '') + const exit = state.enter(node.type) + + trackerOneLine.move(prefix) + trackerMultiLine.move(prefix) + + // None. + if (node.attributes && node.attributes.length > 0) { + if (!node.name) { + throw new Error('Cannot serialize fragment w/ attributes') + } + + let index = -1 + while (++index < node.attributes.length) { + const attribute = node.attributes[index] + /** @type {string} */ + let result + + if (attribute.type === 'mdxJsxExpressionAttribute') { + result = '{' + (attribute.value || '') + '}' + } else { + if (!attribute.name) { + throw new Error('Cannot serialize attribute w/o name') + } + + const value = attribute.value + const left = attribute.name + /** @type {string} */ + let right = '' + + if (value === null || value === undefined) { + // Empty. + } else if (typeof value === 'object') { + right = '{' + (value.value || '') + '}' + } else { + // If the alternative is less common than `quote`, switch. + const appliedQuote = + quoteSmart && ccount(value, quote) > ccount(value, alternative) + ? alternative + : quote + right = + appliedQuote + + stringifyEntitiesLight(value, {subset: [appliedQuote]}) + + appliedQuote + } + + result = left + (right ? '=' : '') + right + } + + serializedAttributes.push(result) + } + } + + let attributesOnTheirOwnLine = false + const attributesOnOneLine = serializedAttributes.join(' ') + + if ( + // Block: + flow && + // Including a line ending (expressions). + (/\r?\n|\r/.test(attributesOnOneLine) || + // Current position (including ``. + (selfClosing ? (tightSelfClosing ? 2 : 3) : 1) > + printWidth) + ) { + attributesOnTheirOwnLine = true + } + + let tracker = trackerOneLine + let value = prefix + + if (attributesOnTheirOwnLine) { + tracker = trackerMultiLine + + let index = -1 + + while (++index < serializedAttributes.length) { + // Only indent first line of of attributes, we can’t indent attribute + // values. + serializedAttributes[index] = + currentIndent + indent + serializedAttributes[index] + } + + value += tracker.move( + '\n' + serializedAttributes.join('\n') + '\n' + currentIndent + ) + } else if (attributesOnOneLine) { + value += tracker.move(' ' + attributesOnOneLine) + } + + if (selfClosing) { + value += tracker.move( + (tightSelfClosing || attributesOnTheirOwnLine ? '' : ' ') + '/' + ) + } + + value += tracker.move('>') + + if (node.children && node.children.length > 0) { + if (node.type === 'mdxJsxTextElement') { + value += tracker.move( + state.containerPhrasing(node, { + ...tracker.current(), + before: '>', + after: '<' + }) + ) + } else { + tracker.shift(2) + value += tracker.move('\n') + value += tracker.move(containerFlow(node, state, tracker.current())) + value += tracker.move('\n') + } + } + + if (!selfClosing) { + value += tracker.move( + (flow ? currentIndent : '') + '' + ) + } + + exit() + return value + } +} + +// Modified copy of: +// . +// +// To do: add `indent` support to `mdast-util-to-markdown`. +// As indents are only used for JSX, it’s fine for now, but perhaps better +// there. +/** + * @param {MdxJsxFlowElement} parent + * Parent of flow nodes. + * @param {State} state + * Info passed around about the current state. + * @param {ReturnType} info + * Info on where we are in the document we are generating. + * @returns {string} + * Serialized children, joined by (blank) lines. + */ +function containerFlow(parent, state, info) { + const indexStack = state.indexStack + const children = parent.children + const tracker = state.createTracker(info) + const currentIndent = createIndent(inferDepth(state)) + /** @type {Array} */ + const results = [] + let index = -1 + + indexStack.push(-1) + + while (++index < children.length) { + const child = children[index] + + indexStack[indexStack.length - 1] = index + + const childInfo = {before: '\n', after: '\n', ...tracker.current()} + + const result = state.handle(child, parent, state, childInfo) + + const serializedChild = + child.type === 'mdxJsxFlowElement' + ? result + : state.indentLines(result, function (line, _, blank) { + return (blank ? '' : currentIndent) + line + }) + + results.push(tracker.move(serializedChild)) + + if (child.type !== 'list') { + state.bulletLastUsed = undefined + } + + if (index < children.length - 1) { + results.push(tracker.move('\n\n')) + } + } + + indexStack.pop() + + return results.join('') +} + +/** + * @param {State} state + * @returns {number} + */ +function inferDepth(state) { + let depth = 0 + let index = state.stack.length + + while (--index > -1) { + const name = state.stack[index] + + if (name === 'blockquote' || name === 'listItem') break + if (name === 'mdxJsxFlowElement') depth++ + } + + return depth +} + +/** + * @param {number} depth + * @returns {string} + */ +function createIndent(depth) { + return indent.repeat(depth) +} + +/** + * @type {ToMarkdownHandle} + */ +function peekElement() { + return '<' +} diff --git a/node_modules/mdast-util-mdx-jsx/license b/node_modules/mdast-util-mdx-jsx/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-mdx-jsx/package.json b/node_modules/mdast-util-mdx-jsx/package.json new file mode 100644 index 0000000000000000000000000000000000000000..6bf2a96c36ba0253edd5304409a986ee5d0ef19d --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/package.json @@ -0,0 +1,113 @@ +{ + "name": "mdast-util-mdx-jsx", + "version": "3.2.0", + "description": "mdast extension to parse and serialize MDX or MDX.js JSX", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "mdx", + "mdxjs", + "jsx", + "extension" + ], + "repository": "syntax-tree/mdast-util-mdx-jsx", + "bugs": "https://github.com/syntax-tree/mdast-util-mdx-jsx/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts.map", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/estree-jsx": "^1.0.0", + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "devlop": "^1.1.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0", + "parse-entities": "^4.0.0", + "stringify-entities": "^4.0.0", + "unist-util-stringify-position": "^4.0.0", + "vfile-message": "^4.0.0" + }, + "devDependencies": { + "@types/node": "^22.0.0", + "acorn": "^8.0.0", + "c8": "^10.0.0", + "micromark-extension-mdx-jsx": "^3.0.0", + "micromark-extension-mdx-md": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.60.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true, + "rules": { + "logical-assignment-operators": "off", + "unicorn/prefer-at": "off" + } + } +} diff --git a/node_modules/mdast-util-mdx-jsx/readme.md b/node_modules/mdast-util-mdx-jsx/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..1657e0bd98cb0f9969173ce75837649de790ff9b --- /dev/null +++ b/node_modules/mdast-util-mdx-jsx/readme.md @@ -0,0 +1,719 @@ +# mdast-util-mdx-jsx + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [MDX][] JSX (``). + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`mdxJsxFromMarkdown()`](#mdxjsxfrommarkdown) + * [`mdxJsxToMarkdown(options?)`](#mdxjsxtomarkdownoptions) + * [`MdxJsxAttribute`](#mdxjsxattribute) + * [`MdxJsxAttributeValueExpression`](#mdxjsxattributevalueexpression) + * [`MdxJsxExpressionAttribute`](#mdxjsxexpressionattribute) + * [`MdxJsxFlowElement`](#mdxjsxflowelement) + * [`MdxJsxFlowElementHast`](#mdxjsxflowelementhast) + * [`MdxJsxTextElement`](#mdxjsxtextelement) + * [`MdxJsxTextElementHast`](#mdxjsxtextelementhast) + * [`ToMarkdownOptions`](#tomarkdownoptions) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Mixin](#mixin) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for MDX JSX syntax in +markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +JSX in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +JSX in syntax trees to markdown). + +[JSX][] is an XML-like syntax extension to ECMAScript (JavaScript), which MDX +brings to markdown. +For more info on MDX, see [What is MDX?][what-is-mdx] + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-mdx-jsx`][micromark-extension-mdx-jsx]. + +When you are working with syntax trees and want all of MDX, use +[`mdast-util-mdx`][mdast-util-mdx] instead. + +All these packages are used in [`remark-mdx`][remark-mdx], which +focusses on making it easier to transform content by abstracting these +internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-mdx-jsx +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'https://esm.sh/mdast-util-mdx-jsx@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.mdx` contains: + +```mdx + + - a list + + + + +HTML is a lovely language. +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import * as acorn from 'acorn' +import {mdxJsx} from 'micromark-extension-mdx-jsx' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {mdxJsxFromMarkdown, mdxJsxToMarkdown} from 'mdast-util-mdx-jsx' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.mdx') + +const tree = fromMarkdown(doc, { + extensions: [mdxJsx({acorn, addResult: true})], + mdastExtensions: [mdxJsxFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [mdxJsxToMarkdown()]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'mdxJsxFlowElement', + name: 'Box', + attributes: [], + children: [ + { + type: 'list', + ordered: false, + start: null, + spread: false, + children: [ + { + type: 'listItem', + spread: false, + checked: null, + children: [ + {type: 'paragraph', children: [{type: 'text', value: 'a list'}]} + ] + } + ] + } + ] + }, + { + type: 'mdxJsxFlowElement', + name: 'MyComponent', + attributes: [ + { + type: 'mdxJsxExpressionAttribute', + value: '...props', + data: { + estree: { + type: 'Program', + body: [ + { + type: 'ExpressionStatement', + expression: { + type: 'ObjectExpression', + properties: [ + { + type: 'SpreadElement', + argument: {type: 'Identifier', name: 'props'} + } + ] + } + } + ], + sourceType: 'module' + } + } + } + ], + children: [] + }, + { + type: 'paragraph', + children: [ + { + type: 'mdxJsxTextElement', + name: 'abbr', + attributes: [ + { + type: 'mdxJsxAttribute', + name: 'title', + value: 'Hypertext Markup Language' + } + ], + children: [{type: 'text', value: 'HTML'}] + }, + {type: 'text', value: ' is a lovely language.'} + ] + } + ] +} +``` + +```markdown + + * a list + + + + +HTML is a lovely language. +``` + +## API + +This package exports the identifiers +[`mdxJsxFromMarkdown`][api-mdx-jsx-from-markdown] and +[`mdxJsxToMarkdown`][api-mdx-jsx-to-markdown]. +There is no default export. + +### `mdxJsxFromMarkdown()` + +Create an extension for +[`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable MDX JSX. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable MDX JSX +([`FromMarkdownExtension`][from-markdown-extension]). + +When using the [micromark syntax extension][micromark-extension-mdx-jsx] with +`addResult`, nodes will have a `data.estree` field set to an ESTree +[`Program`][program] node. + +### `mdxJsxToMarkdown(options?)` + +Create an extension for +[`mdast-util-to-markdown`][mdast-util-to-markdown] +to enable MDX JSX. + +This extension configures `mdast-util-to-markdown` with +[`options.fences: true`][mdast-util-to-markdown-fences] and +[`options.resourceLink: true`][mdast-util-to-markdown-resourcelink] too, do not +overwrite them! + +###### Parameters + +* `options` ([`ToMarkdownOptions`][api-to-markdown-options]) + — configuration + +###### Returns + +Extension for `mdast-util-to-markdown` to enable MDX JSX +([`FromMarkdownExtension`][to-markdown-extension]). + +### `MdxJsxAttribute` + +MDX JSX attribute with a key (TypeScript type). + +###### Type + +```ts +import type {Literal} from 'mdast' + +interface MdxJsxAttribute extends Literal { + type: 'mdxJsxAttribute' + name: string + value?: MdxJsxAttributeValueExpression | string | null | undefined +} +``` + +### `MdxJsxAttributeValueExpression` + +MDX JSX attribute value set to an expression (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Literal} from 'mdast' + +interface MdxJsxAttributeValueExpression extends Literal { + type: 'mdxJsxAttributeValueExpression' + data?: {estree?: Program | null | undefined} & Literal['data'] +} +``` + +### `MdxJsxExpressionAttribute` + +MDX JSX attribute as an expression (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Literal} from 'mdast' + +interface MdxJsxExpressionAttribute extends Literal { + type: 'mdxJsxExpressionAttribute' + data?: {estree?: Program | null | undefined} & Literal['data'] +} +``` + +### `MdxJsxFlowElement` + +MDX JSX element node, occurring in flow (block) (TypeScript type). + +###### Type + +```ts +import type {BlockContent, DefinitionContent, Parent} from 'mdast' + +export interface MdxJsxFlowElement extends Parent { + type: 'mdxJsxFlowElement' + name: string | null + attributes: Array + children: Array +} +``` + +### `MdxJsxFlowElementHast` + +Same as [`MdxJsxFlowElement`][api-mdx-jsx-flow-element], but registered with +`@types/hast` (TypeScript type). + +###### Type + +```ts +import type {ElementContent, Parent} from 'hast' + +export interface MdxJsxFlowElementHast extends Parent { + type: 'mdxJsxFlowElement' + name: string | null + attributes: Array + children: Array +} +``` + +### `MdxJsxTextElement` + +MDX JSX element node, occurring in text (phrasing) (TypeScript type). + +###### Type + +```ts +import type {Parent, PhrasingContent} from 'mdast' + +export interface MdxJsxTextElement extends Parent { + type: 'mdxJsxTextElement' + name: string | null + attributes: Array + children: Array +} +``` + +### `MdxJsxTextElementHast` + +Same as [`MdxJsxTextElement`][api-mdx-jsx-text-element], but registered with +`@types/hast` (TypeScript type). + +###### Type + +```ts +import type {ElementContent, Parent} from 'hast' + +export interface MdxJsxTextElementHast extends Parent { + type: 'mdxJsxTextElement' + name: string | null + attributes: Array + children: Array +} +``` + +### `ToMarkdownOptions` + +Configuration (TypeScript type). + +##### Fields + +* `quote` (`'"'` or `"'"`, default: `'"'`) + — preferred quote to use around attribute values +* `quoteSmart` (`boolean`, default: `false`) + — use the other quote if that results in less bytes +* `tightSelfClosing` (`boolean`, default: `false`) + — do not use an extra space when closing self-closing elements: `` + instead of `` +* `printWidth` (`number`, default: `Infinity`) + — try and wrap syntax at this width. + When set to a finite number (say, `80`), the formatter will print + attributes on separate lines when a tag doesn’t fit on one line. + The normal behavior is to print attributes with spaces between them instead + of line endings + +## HTML + +MDX JSX has no representation in HTML. +Though, when you are dealing with MDX, you will likely go *through* hast. +You can enable passing MDX JSX through to hast by configuring +[`mdast-util-to-hast`][mdast-util-to-hast] with +`passThrough: ['mdxJsxFlowElement', 'mdxJsxTextElement']`. + +## Syntax + +See [Syntax in `micromark-extension-mdx-jsx`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `MdxJsxFlowElement` + +```idl +interface MdxJsxFlowElement <: Parent { + type: 'mdxJsxFlowElement' +} + +MdxJsxFlowElement includes MdxJsxElement +``` + +**MdxJsxFlowElement** (**[Parent][dfn-parent]**) represents JSX in flow (block). +It can be used where **[flow][dfn-content-flow]** content is expected. +It includes the mixin **[MdxJsxElement][dfn-mixin-mdx-jsx-element]**. + +For example, the following markdown: + +```markdown + + z + +``` + +Yields: + +```js +{ + type: 'mdxJsxFlowElement', + name: 'w', + attributes: [{type: 'mdxJsxAttribute', name: 'x', value: 'y'}], + children: [{type: 'paragraph', children: [{type: 'text', value: 'z'}]}] +} +``` + +#### `MdxJsxTextElement` + +```idl +interface MdxJsxTextElement <: Parent { + type: 'mdxJsxTextElement' +} + +MdxJsxTextElement includes MdxJsxElement +``` + +**MdxJsxTextElement** (**[Parent][dfn-parent]**) represents JSX in text (span, +inline). +It can be used where **[phrasing][dfn-content-phrasing]** content is +expected. +It includes the mixin **[MdxJsxElement][dfn-mixin-mdx-jsx-element]**. + +For example, the following markdown: + +```markdown +a d e. +``` + +Yields: + +```js +{ + type: 'mdxJsxTextElement', + name: 'b', + attributes: [{type: 'mdxJsxAttribute', name: 'c', value: null}], + children: [{type: 'text', value: 'd'}] +} +``` + +### Mixin + +#### `MdxJsxElement` + +```idl +interface mixin MdxJsxElement { + name: string? + attributes: [MdxJsxExpressionAttribute | MdxJsxAttribute] +} + +interface MdxJsxExpressionAttribute <: Literal { + type: 'mdxJsxExpressionAttribute' +} + +interface MdxJsxAttribute <: Node { + type: 'mdxJsxAttribute' + name: string + value: MdxJsxAttributeValueExpression | string? +} + +interface MdxJsxAttributeValueExpression <: Literal { + type: 'mdxJsxAttributeValueExpression' +} +``` + +**MdxJsxElement** represents a JSX element. + +The `name` field can be present and represents an identifier. +Without `name`, the element represents a fragment, in which case no attributes +must be present. + +The `attributes` field represents information associated with the node. +The value of the `attributes` field is a list of **MdxJsxExpressionAttribute** +and **MdxJsxAttribute** nodes. + +**MdxJsxExpressionAttribute** represents an expression (typically in a +programming language) that when evaluated results in multiple attributes. + +**MdxJsxAttribute** represents a single attribute. +The `name` field must be present. +The `value` field can be present, in which case it is either a string (a static +value) or an expression (typically in a programming language) that when +evaluated results in an attribute value. + +### Content model + +###### `FlowContent` (MDX JSX) + +```idl +type MdxJsxFlowContent = MdxJsxFlowElement | FlowContent +``` + +###### `PhrasingContent` (MDX JSX) + +```idl +type MdxJsxPhrasingContent = MdxJsxTextElement | PhrasingContent +``` + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`MdxJsxAttribute`][api-mdx-jsx-attribute], +[`MdxJsxAttributeValueExpression`][api-mdx-jsx-attribute-value-expression], +[`MdxJsxExpressionAttribute`][api-mdx-jsx-expression-attribute], +[`MdxJsxFlowElement`][api-mdx-jsx-flow-element], +[`MdxJsxFlowElementHast`][api-mdx-jsx-flow-element-hast], +[`MdxJsxTextElement`][api-mdx-jsx-text-element], +[`MdxJsxTextElementHast`][api-mdx-jsx-text-element-hast], and +[`ToMarkdownOptions`][api-to-markdown-options]. + +It also registers the node types with `@types/mdast` and `@types/hast`. +If you’re working with the syntax tree, make sure to import this utility +somewhere in your types, as that registers the new node types in the tree. + +```js +/** + * @import {} from 'mdast-util-mdx-jsx' + * @import {Root} from 'mdast' + */ + +import {visit} from 'unist-util-visit' + +/** @type {Root} */ +const tree = getMdastNodeSomeHow() + +visit(tree, function (node) { + // `node` can now be one of the JSX nodes. +}) +``` + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-mdx-jsx@3`, +compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`micromark/micromark-extension-mdx-jsx`][micromark-extension-mdx-jsx] + — support MDX JSX in micromark +* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx] + — support MDX in mdast +* [`remarkjs/remark-mdx`][remark-mdx] + — support MDX in remark + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + +[build-badge]: https://github.com/syntax-tree/mdast-util-mdx-jsx/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-mdx-jsx/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-mdx-jsx.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-mdx-jsx + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-mdx-jsx.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-mdx-jsx + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdx-jsx + +[size]: https://bundlejs.com/?q=mdast-util-mdx-jsx + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx + +[program]: https://github.com/estree/estree/blob/master/es2015.md#programs + +[dfn-parent]: https://github.com/syntax-tree/mdast#parent + +[dfn-content-flow]: #flowcontent-mdx-jsx + +[dfn-content-phrasing]: #phrasingcontent-mdx-jsx + +[dfn-mixin-mdx-jsx-element]: #mdxjsxelement + +[jsx]: https://facebook.github.io/jsx/ + +[what-is-mdx]: https://mdxjs.com/docs/what-is-mdx/ + +[micromark-extension-mdx-jsx]: https://github.com/micromark/micromark-extension-mdx-jsx + +[syntax]: https://github.com/micromark/micromark-extension-mdx-jsx#syntax + +[mdast-util-to-markdown-fences]: https://github.com/syntax-tree/mdast-util-to-markdown#optionsfences + +[mdast-util-to-markdown-resourcelink]: https://github.com/syntax-tree/mdast-util-to-markdown#optionsresourcelink + +[remark-mdx]: https://mdxjs.com/packages/remark-mdx/ + +[mdx]: https://mdxjs.com + +[api-mdx-jsx-from-markdown]: #mdxjsxfrommarkdown + +[api-mdx-jsx-to-markdown]: #mdxjsxtomarkdownoptions + +[api-mdx-jsx-attribute]: #mdxjsxattribute + +[api-mdx-jsx-attribute-value-expression]: #mdxjsxattributevalueexpression + +[api-mdx-jsx-expression-attribute]: #mdxjsxexpressionattribute + +[api-mdx-jsx-flow-element]: #mdxjsxflowelement + +[api-mdx-jsx-flow-element-hast]: #mdxjsxflowelementhast + +[api-mdx-jsx-text-element]: #mdxjsxtextelement + +[api-mdx-jsx-text-element-hast]: #mdxjsxtextelementhast + +[api-to-markdown-options]: #tomarkdownoptions diff --git a/node_modules/mdast-util-mdxjs-esm/index.d.ts b/node_modules/mdast-util-mdxjs-esm/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..203f687ef2d3e652dc6dbef135fd05dcce2217e6 --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/index.d.ts @@ -0,0 +1,82 @@ +import type {Program} from 'estree-jsx' +import type {Data as HastData, Literal as HastLiteral} from 'hast' +import type {Data as MdastData, Literal as MdastLiteral} from 'mdast' + +export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js' + +/** + * MDX ESM (import/export) node. + */ +export interface MdxjsEsm extends MdastLiteral { + /** + * Node type. + */ + type: 'mdxjsEsm' + + /** + * Data associated with mdast MDX.js ESM. + */ + data?: MdxjsEsmData | undefined +} + +/** + * Info associated with mdast MDX.js ESM nodes by the ecosystem. + */ +export interface MdxjsEsmData extends MdastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +/** + * MDX ESM (import/export) node (for hast). + */ +export interface MdxjsEsmHast extends HastLiteral { + /** + * Node type. + */ + type: 'mdxjsEsm' + + /** + * Data associated with hast MDX.js ESM. + */ + data?: MdxjsEsmHastData | undefined +} + +/** + * Info associated with hast MDX.js ESM nodes by the ecosystem. + */ +export interface MdxjsEsmHastData extends HastData { + /** + * Program node from estree. + */ + estree?: Program | null | undefined +} + +// Add nodes to mdast content. +declare module 'mdast' { + interface FrontmatterContentMap { + /** + * MDX ESM. + */ + mdxjsEsm: MdxjsEsm + } + + interface RootContentMap { + /** + * MDX ESM. + */ + mdxjsEsm: MdxjsEsm + } +} + +// Add nodes to hast content. +declare module 'hast' { + interface RootContentMap { + /** + * MDX ESM. + */ + mdxjsEsm: MdxjsEsmHast + } +} diff --git a/node_modules/mdast-util-mdxjs-esm/index.js b/node_modules/mdast-util-mdxjs-esm/index.js new file mode 100644 index 0000000000000000000000000000000000000000..2aa76935faf9627152250a6f33025f6e650faca7 --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/index.js @@ -0,0 +1,2 @@ +// Note: types exposed from `index.d.ts`. +export {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from './lib/index.js' diff --git a/node_modules/mdast-util-mdxjs-esm/lib/index.d.ts b/node_modules/mdast-util-mdxjs-esm/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d356dd151caace4827111c146a32086679fc38dd --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/lib/index.d.ts @@ -0,0 +1,25 @@ +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in + * markdown. + * + * When using the micromark syntax extension with `addResult`, nodes will have + * a `data.estree` field set to an ESTree [`Program`][program] node. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX.js ESM. + */ +export function mdxjsEsmFromMarkdown(): FromMarkdownExtension; +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in + * markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX.js ESM. + */ +export function mdxjsEsmToMarkdown(): ToMarkdownExtension; +export type CompileContext = import('mdast-util-from-markdown').CompileContext; +export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension; +export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle; +export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle; +export type ToMarkdownExtension = import('mdast-util-to-markdown').Options; +export type MdxjsEsm = import('../index.js').MdxjsEsm; diff --git a/node_modules/mdast-util-mdxjs-esm/lib/index.js b/node_modules/mdast-util-mdxjs-esm/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..1992fbbe769b4ac9ccf4d82add82ab55aa63f224 --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/lib/index.js @@ -0,0 +1,87 @@ +/** + * @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext + * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension + * @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle + * + * @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle + * @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension + * + * @typedef {import('../index.js').MdxjsEsm} MdxjsEsm + */ + +// To do: next major: expose functions. +import {ok as assert} from 'devlop' + +/** + * Create an extension for `mdast-util-from-markdown` to enable MDX.js ESM in + * markdown. + * + * When using the micromark syntax extension with `addResult`, nodes will have + * a `data.estree` field set to an ESTree [`Program`][program] node. + * + * @returns {FromMarkdownExtension} + * Extension for `mdast-util-from-markdown` to enable MDX.js ESM. + */ +export function mdxjsEsmFromMarkdown() { + return { + enter: {mdxjsEsm: enterMdxjsEsm}, + exit: {mdxjsEsm: exitMdxjsEsm, mdxjsEsmData: exitMdxjsEsmData} + } +} + +/** + * Create an extension for `mdast-util-to-markdown` to enable MDX.js ESM in + * markdown. + * + * @returns {ToMarkdownExtension} + * Extension for `mdast-util-to-markdown` to enable MDX.js ESM. + */ +export function mdxjsEsmToMarkdown() { + return {handlers: {mdxjsEsm: handleMdxjsEsm}} +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function enterMdxjsEsm(token) { + this.enter({type: 'mdxjsEsm', value: ''}, token) + this.buffer() // Capture EOLs +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitMdxjsEsm(token) { + const value = this.resume() + const node = this.stack[this.stack.length - 1] + assert(node.type === 'mdxjsEsm') + + this.exit(token) + + const estree = token.estree + + node.value = value + + if (estree) { + node.data = {estree} + } +} + +/** + * @this {CompileContext} + * @type {FromMarkdownHandle} + */ +function exitMdxjsEsmData(token) { + this.config.enter.data.call(this, token) + this.config.exit.data.call(this, token) +} + +/** + * @type {ToMarkdownHandle} + * @param {MdxjsEsm} node + */ +function handleMdxjsEsm(node) { + return node.value || '' +} diff --git a/node_modules/mdast-util-mdxjs-esm/license b/node_modules/mdast-util-mdxjs-esm/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-mdxjs-esm/package.json b/node_modules/mdast-util-mdxjs-esm/package.json new file mode 100644 index 0000000000000000000000000000000000000000..2743942bad79da9e13cd6b0e477b0ae6eafd41c2 --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/package.json @@ -0,0 +1,106 @@ +{ + "name": "mdast-util-mdxjs-esm", + "version": "2.0.1", + "description": "mdast extension to parse and serialize MDX.js ESM (import/exports)", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "util", + "utility", + "markdown", + "markup", + "mdx", + "mdxjs", + "esm", + "import", + "export", + "extension" + ], + "repository": "syntax-tree/mdast-util-mdxjs-esm", + "bugs": "https://github.com/syntax-tree/mdast-util-mdxjs-esm/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/estree-jsx": "^1.0.0", + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "devlop": "^1.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-to-markdown": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "acorn": "^8.0.0", + "c8": "^8.0.0", + "micromark-extension-mdxjs-esm": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "unist-util-remove-position": "^5.0.0", + "xo": "^0.55.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test.js", + "test-api-dev": "node --conditions development test.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true, + "rules": { + "unicorn/prefer-at": "off" + } + } +} diff --git a/node_modules/mdast-util-mdxjs-esm/readme.md b/node_modules/mdast-util-mdxjs-esm/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..7f81445891dbf5a5899228acfba9f848a3a0b622 --- /dev/null +++ b/node_modules/mdast-util-mdxjs-esm/readme.md @@ -0,0 +1,448 @@ +# mdast-util-mdxjs-esm + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] extensions to parse and serialize [MDX][] ESM (import/exports). + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`mdxjsEsmFromMarkdown()`](#mdxjsesmfrommarkdown) + * [`mdxjsEsmToMarkdown()`](#mdxjsesmtomarkdown) + * [`MdxjsEsm`](#mdxjsesm) + * [`MdxjsEsmHast`](#mdxjsesmhast) +* [HTML](#html) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) + * [Content model](#content-model) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains two extensions that add support for MDX ESM syntax in +markdown to [mdast][]. +These extensions plug into +[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing +ESM in markdown into a syntax tree) and +[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing +ESM in syntax trees to markdown). + +## When to use this + +You can use these extensions when you are working with +`mdast-util-from-markdown` and `mdast-util-to-markdown` already. + +When working with `mdast-util-from-markdown`, you must combine this package +with [`micromark-extension-mdxjs-esm`][extension]. + +When you are working with syntax trees and want all of MDX, use +[`mdast-util-mdx`][mdast-util-mdx] instead. + +All these packages are used in [`remark-mdx`][remark-mdx], which +focusses on making it easier to transform content by abstracting these +internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-mdxjs-esm +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'https://esm.sh/mdast-util-mdxjs-esm@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.mdx` contains: + +```mdx +import a from 'b' +export const c = '' + +d +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import * as acorn from 'acorn' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {toMarkdown} from 'mdast-util-to-markdown' +import {mdxjsEsm} from 'micromark-extension-mdxjs-esm' +import {mdxjsEsmFromMarkdown, mdxjsEsmToMarkdown} from 'mdast-util-mdxjs-esm' + +const doc = await fs.readFile('example.mdx') + +const tree = fromMarkdown(doc, { + extensions: [mdxjsEsm({acorn, addResult: true})], + mdastExtensions: [mdxjsEsmFromMarkdown()] +}) + +console.log(tree) + +const out = toMarkdown(tree, {extensions: [mdxjsEsmToMarkdown()]}) + +console.log(out) +``` + +…now running `node example.js` yields (positional info removed for brevity): + +```js +{ + type: 'root', + children: [ + { + type: 'mdxjsEsm', + value: "import a from 'b'\nexport const c = ''", + data: { + estree: { + type: 'Program', + body: [ + { + type: 'ImportDeclaration', + specifiers: [ + { + type: 'ImportDefaultSpecifier', + local: {type: 'Identifier', name: 'a'} + } + ], + source: {type: 'Literal', value: 'b', raw: "'b'"} + }, + { + type: 'ExportNamedDeclaration', + declaration: { + type: 'VariableDeclaration', + declarations: [ + { + type: 'VariableDeclarator', + id: {type: 'Identifier', name: 'c'}, + init: {type: 'Literal', value: '', raw: "''"} + } + ], + kind: 'const' + }, + specifiers: [], + source: null + } + ], + sourceType: 'module' + } + } + }, + {type: 'paragraph', children: [{type: 'text', value: 'd'}]} + ] +} +``` + +```markdown +import a from 'b' +export const c = '' + +d +``` + +## API + +This package exports the identifiers +[`mdxjsEsmFromMarkdown`][api-mdxjs-esm-from-markdown] and +[`mdxjsEsmToMarkdown`][api-mdxjs-esm-to-markdown]. +There is no default export. + +### `mdxjsEsmFromMarkdown()` + +Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] +to enable MDX.js ESM in markdown. + +When using the [micromark syntax extension][extension] with `addResult`, nodes +will have a `data.estree` field set to an ESTree [`Program`][program] node. + +###### Returns + +Extension for `mdast-util-from-markdown` to enable MDX.js ESM +([`FromMarkdownExtension`][from-markdown-extension]). + +### `mdxjsEsmToMarkdown()` + +Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] +to enable MDX.js ESM in markdown. + +###### Returns + +Extension for `mdast-util-to-markdown` to enable MDX.js ESM +([`ToMarkdownExtension`][to-markdown-extension]). + +### `MdxjsEsm` + +MDX ESM (import/export) node (TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'mdast' + +interface MdxjsEsm extends Literal { + type: 'mdxjsEsm' + data?: MdxjsEsmData | undefined +} + +export interface MdxjsEsmData extends Data { + estree?: Program | null | undefined +} +``` + +### `MdxjsEsmHast` + +Same as [`MdxjsEsm`][api-mdxjs-esm], but registered with `@types/hast` +(TypeScript type). + +###### Type + +```ts +import type {Program} from 'estree-jsx' +import type {Data, Literal} from 'hast' + +interface MdxjsEsmHast extends Literal { + type: 'mdxjsEsm' + data?: MdxjsEsmHastData | undefined +} + +export interface MdxjsEsmHastData extends Data { + estree?: Program | null | undefined +} +``` + +## HTML + +MDX ESM has no representation in HTML. +Though, when you are dealing with MDX, you will likely go *through* hast. +You can enable passing MDX ESM through to hast by configuring +[`mdast-util-to-hast`][mdast-util-to-hast] with `passThrough: ['mdxjsEsm']`. + +## Syntax + +See [Syntax in `micromark-extension-mdxjs-esm`][syntax]. + +## Syntax tree + +The following interfaces are added to **[mdast][]** by this utility. + +### Nodes + +#### `MdxjsEsm` + +```idl +interface MdxjsEsm <: Literal { + type: 'mdxjsEsm' +} +``` + +**MdxjsEsm** (**[Literal][dfn-literal]**) represents ESM import/exports +embedded in MDX. +It can be used where **[flow][dfn-flow-content]** content is expected. +Its content is represented by its `value` field. + +For example, the following Markdown: + +```markdown +import a from 'b' +``` + +Yields: + +```js +{ + type: 'mdxjsEsm', + value: 'import a from \'b\'' +} +``` + +### Content model + +#### `FlowContent` (MDX.js ESM) + +```idl +type FlowContentMdxjsEsm = MdxjsEsm | FlowContent +``` + +Note that when ESM is present, it can only exist as top-level content: if it has +a *[parent][dfn-parent]*, that parent must be **[Root][dfn-root]**. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`MdxjsEsm`][api-mdxjs-esm] and +[`MdxjsEsmHast`][api-mdxjs-esm-hast]. + +It also registers the node type with `@types/mdast` and `@types/hast`. +If you’re working with the syntax tree, make sure to import this utility +somewhere in your types, as that registers the new node types in the tree. + +```js +/** + * @typedef {import('mdast-util-mdxjs-esm')} + */ + +import {visit} from 'unist-util-visit' + +/** @type {import('mdast').Root} */ +const tree = getMdastNodeSomeHow() + +visit(tree, function (node) { + // `node` can now be an ESM node. +}) +``` + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-mdxjs-esm@^2`, +compatible with Node.js 16. + +This utility works with `mdast-util-from-markdown` version 2+ and +`mdast-util-to-markdown` version 2+. + +## Related + +* [`remarkjs/remark-mdx`][remark-mdx] + — remark plugin to support MDX +* [`syntax-tree/mdast-util-mdx`][mdast-util-mdx] + — mdast utility to support MDX +* [`micromark/micromark-extension-mdxjs-esm`][extension] + — micromark extension to parse MDX.js ESM + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-mdxjs-esm/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-mdxjs-esm/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-mdxjs-esm.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-mdxjs-esm + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-mdxjs-esm.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-mdxjs-esm + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-mdxjs-esm + +[size]: https://bundlejs.com/?q=mdast-util-mdxjs-esm + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://wooorm.com + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast + +[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdast-util-mdx]: https://github.com/syntax-tree/mdast-util-mdx + +[extension]: https://github.com/micromark/micromark-extension-mdxjs-esm + +[syntax]: https://github.com/micromark/micromark-extension-mdxjs-esm#syntax + +[program]: https://github.com/estree/estree/blob/master/es2015.md#programs + +[dfn-literal]: https://github.com/syntax-tree/mdast#literal + +[dfn-parent]: https://github.com/syntax-tree/unist#parent-1 + +[dfn-root]: https://github.com/syntax-tree/mdast#root + +[remark-mdx]: https://mdxjs.com/packages/remark-mdx/ + +[mdx]: https://mdxjs.com + +[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension + +[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options + +[dfn-flow-content]: #flowcontent-mdxjs-esm + +[api-mdxjs-esm-from-markdown]: #mdxjsesmfrommarkdown + +[api-mdxjs-esm-to-markdown]: #mdxjsesmtomarkdown + +[api-mdxjs-esm]: #mdxjsesm + +[api-mdxjs-esm-hast]: #mdxjsesmhast diff --git a/node_modules/mdast-util-newline-to-break/index.d.ts b/node_modules/mdast-util-newline-to-break/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dca2b035ff0329b60a68bf4bf9a955669eb2e1b8 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/index.d.ts @@ -0,0 +1 @@ +export {newlineToBreak} from './lib/index.js' diff --git a/node_modules/mdast-util-newline-to-break/index.js b/node_modules/mdast-util-newline-to-break/index.js new file mode 100644 index 0000000000000000000000000000000000000000..dca2b035ff0329b60a68bf4bf9a955669eb2e1b8 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/index.js @@ -0,0 +1 @@ +export {newlineToBreak} from './lib/index.js' diff --git a/node_modules/mdast-util-newline-to-break/lib/index.d.ts b/node_modules/mdast-util-newline-to-break/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dcc9ce14d181d395e574255d4b5cf8bfacc7acf5 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/lib/index.d.ts @@ -0,0 +1,12 @@ +/** + * Turn normal line endings into hard breaks. + * + * @param {Nodes} tree + * Tree to change. + * @returns {undefined} + * Nothing. + */ +export function newlineToBreak(tree: Nodes): undefined +export type Nodes = import('mdast').Nodes +export type ReplaceFunction = + import('mdast-util-find-and-replace').ReplaceFunction diff --git a/node_modules/mdast-util-newline-to-break/lib/index.js b/node_modules/mdast-util-newline-to-break/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..07e54ac32c34727b290a0c3826cd05dd1722849d --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/lib/index.js @@ -0,0 +1,27 @@ +/** + * @typedef {import('mdast').Nodes} Nodes + * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction + */ + +import {findAndReplace} from 'mdast-util-find-and-replace' + +/** + * Turn normal line endings into hard breaks. + * + * @param {Nodes} tree + * Tree to change. + * @returns {undefined} + * Nothing. + */ +export function newlineToBreak(tree) { + findAndReplace(tree, [/\r?\n|\r/g, replace]) +} + +/** + * Replace line endings. + * + * @type {ReplaceFunction} + */ +function replace() { + return {type: 'break'} +} diff --git a/node_modules/mdast-util-newline-to-break/license b/node_modules/mdast-util-newline-to-break/license new file mode 100644 index 0000000000000000000000000000000000000000..045ffe0e075da471f1b04e204acce031b22d1c13 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2017 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-newline-to-break/package.json b/node_modules/mdast-util-newline-to-break/package.json new file mode 100644 index 0000000000000000000000000000000000000000..3c13c464ac4d320c8af7079b1b672597d501b9a0 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/package.json @@ -0,0 +1,77 @@ +{ + "name": "mdast-util-newline-to-break", + "version": "2.0.0", + "description": "mdast utility to support hard breaks without needing spaces or escapes", + "license": "MIT", + "keywords": [ + "mdast", + "markdown", + "break", + "newline", + "linefeed" + ], + "repository": "syntax-tree/mdast-util-newline-to-break", + "bugs": "https://github.com/syntax-tree/mdast-util-newline-to-break/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Remco Haszig ", + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "mdast-util-find-and-replace": "^3.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "mdast-util-from-markdown": "^1.0.0", + "mdast-util-to-markdown": "^1.0.0", + "prettier": "^2.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api": "node --conditions development test.js", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true + } +} diff --git a/node_modules/mdast-util-newline-to-break/readme.md b/node_modules/mdast-util-newline-to-break/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..179ddb683fcb6f972233ddcf0aaf48a7b70b4626 --- /dev/null +++ b/node_modules/mdast-util-newline-to-break/readme.md @@ -0,0 +1,248 @@ +# mdast-util-newline-to-break + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +**[mdast][]** utility to support hard breaks without needing spaces or +escapes (turns enters into `
`s). + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`newlineToBreak(tree)`](#newlinetobreaktree) +* [Syntax](#syntax) +* [Syntax tree](#syntax-tree) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a utility that takes an [mdast][] tree and turns soft line +endings (enters) into hard breaks (`
`s) + +This package is used inside [remark-breaks][], which focusses on making it +easier to transform content by abstracting these internals away. + +## When should I use this? + +This plugin is useful if you want to display user content closer to how it was +authored, because when a user includes a line ending, it’ll show as such. +GitHub does this in a few places (comments, issues, PRs, and releases), but it’s +not semantic according to HTML and not compliant to markdown. +Markdown already has two ways to include hard breaks, namely trailing spaces and +escapes (note that `␠` represents a normal space): + +```markdown +lorem␠␠ +ipsum + +lorem\ +ipsum +``` + +Both will turn into `
`s. +If you control who authors content or can document how markdown works, it’s +recommended to use escapes instead. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-newline-to-break +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {newlineToBreak} from 'https://esm.sh/mdast-util-newline-to-break@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say we have the following file, `example.md` (note: there are no spaces after +`a`): + +```markdown +This is a +paragraph. +``` + +And our module, `example.js`, looks as follows: + +```js +import fs from 'node:fs/promises' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {newlineToBreak} from 'mdast-util-newline-to-break' +import {toMarkdown} from 'mdast-util-to-markdown' + +const doc = await fs.readFile('example.md') +const tree = fromMarkdown(doc) + +newlineToBreak(tree) + +console.log(toMarkdown(tree)) +``` + +Now, running `node example.js` yields: + +```md +This is a\ +paragraph. +``` + +## API + +This package exports the identifier [`newlineToBreak`][api-newline-to-break]. +There is no default export. + +### `newlineToBreak(tree)` + +Turn normal line endings into hard breaks. + +#### Parameters + +* `tree` ([`Node`][node]) + — tree to modify + +## Syntax + +This utility looks for markdown line endings (`\r`, `\n`, and `\r\n`). + +## Syntax tree + +This utility adds mdast [`Break`][break] nodes to the syntax tree. +These are the same nodes that represent breaks with spaces or escapes. + +## Types + +This package is fully typed with [TypeScript][]. +There are no extra exported types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`mdast-util-newline-to-break@^2`, compatible with Node.js 16. + +## Security + +Use of `mdast-util-newline-to-break` does not involve **[hast][]** or user +content so there are no openings for [cross-site scripting (XSS)][xss] attacks. + +## Related + +* [`remark-breaks`](https://github.com/remarkjs/remark-breaks) + — provide this utility as a [unified][] [remark][] plugin. +* [`remark-gfm`](https://github.com/remarkjs/remark-gfm) + — support GFM (autolink literals, footnotes, strikethrough, tables, + tasklists) +* [`remark-github`](https://github.com/remarkjs/remark-github) + — link references to commits, issues, and users, in the same way that + GitHub does + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-newline-to-break/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-newline-to-break/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-newline-to-break.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-newline-to-break + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-newline-to-break.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-newline-to-break + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-newline-to-break + +[size]: https://bundlejs.com/?q=mdast-util-newline-to-break + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/orgs/syntax-tree/discussions + +[mdast]: https://github.com/syntax-tree/mdast + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[license]: license + +[author]: https://wooorm.com + +[remark-breaks]: https://github.com/remarkjs/remark-breaks + +[node]: https://github.com/syntax-tree/mdast#nodes + +[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[typescript]: https://www.typescriptlang.org + +[hast]: https://github.com/syntax-tree/hast + +[break]: https://github.com/syntax-tree/mdast#break + +[remark]: https://github.com/remarkjs/remark + +[api-newline-to-break]: #newlinetobreaktree + +[unified]: https://github.com/unifiedjs/unified diff --git a/node_modules/mdast-util-phrasing/index.d.ts b/node_modules/mdast-util-phrasing/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b90dfa7c5e1acef508c614aa02b5a2805e2a1059 --- /dev/null +++ b/node_modules/mdast-util-phrasing/index.d.ts @@ -0,0 +1 @@ +export { phrasing } from "./lib/index.js"; diff --git a/node_modules/mdast-util-phrasing/index.js b/node_modules/mdast-util-phrasing/index.js new file mode 100644 index 0000000000000000000000000000000000000000..2627f17a6e336455bb2d9f2d74bdee360b582680 --- /dev/null +++ b/node_modules/mdast-util-phrasing/index.js @@ -0,0 +1 @@ +export {phrasing} from './lib/index.js' diff --git a/node_modules/mdast-util-phrasing/lib/index.d.ts b/node_modules/mdast-util-phrasing/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..59c698009264acc57589b84af50dab10cdb4ceb9 --- /dev/null +++ b/node_modules/mdast-util-phrasing/lib/index.d.ts @@ -0,0 +1,3 @@ +export function phrasing(node?: unknown): node is import("mdast").Break | import("mdast").Delete | import("mdast").Emphasis | import("mdast").FootnoteReference | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").Link | import("mdast").LinkReference | import("mdast").Strong | import("mdast").Text; +export type Html = import('mdast').Html; +export type PhrasingContent = import('mdast').PhrasingContent; diff --git a/node_modules/mdast-util-phrasing/lib/index.js b/node_modules/mdast-util-phrasing/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..64f076999a3f9a05406d57d6c18ae9169d40aa8c --- /dev/null +++ b/node_modules/mdast-util-phrasing/lib/index.js @@ -0,0 +1,45 @@ +/** + * @typedef {import('mdast').Html} Html + * @typedef {import('mdast').PhrasingContent} PhrasingContent + */ + +import {convert} from 'unist-util-is' + +/** + * Check if the given value is *phrasing content*. + * + * > 👉 **Note**: Excludes `html`, which can be both phrasing or flow. + * + * @param node + * Thing to check, typically `Node`. + * @returns + * Whether `value` is phrasing content. + */ + +export const phrasing = + /** @type {(node?: unknown) => node is Exclude} */ + ( + convert([ + 'break', + 'delete', + 'emphasis', + // To do: next major: removed since footnotes were added to GFM. + 'footnote', + 'footnoteReference', + 'image', + 'imageReference', + 'inlineCode', + // Enabled by `mdast-util-math`: + 'inlineMath', + 'link', + 'linkReference', + // Enabled by `mdast-util-mdx`: + 'mdxJsxTextElement', + // Enabled by `mdast-util-mdx`: + 'mdxTextExpression', + 'strong', + 'text', + // Enabled by `mdast-util-directive`: + 'textDirective' + ]) + ) diff --git a/node_modules/mdast-util-phrasing/license b/node_modules/mdast-util-phrasing/license new file mode 100644 index 0000000000000000000000000000000000000000..6883cb5177f12e0b1bc11a5b410c547103731a79 --- /dev/null +++ b/node_modules/mdast-util-phrasing/license @@ -0,0 +1,23 @@ +(The MIT License) + +Copyright (c) 2017 Titus Wormer +Copyright (c) 2017 Victor Felder + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-phrasing/package.json b/node_modules/mdast-util-phrasing/package.json new file mode 100644 index 0000000000000000000000000000000000000000..2af70323562d031fc4cb33a314051ffdfaab87a5 --- /dev/null +++ b/node_modules/mdast-util-phrasing/package.json @@ -0,0 +1,78 @@ +{ + "name": "mdast-util-phrasing", + "version": "4.1.0", + "description": "mdast utility to check if a node is phrasing content", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast=util", + "util", + "utility", + "markdown", + "phrasing" + ], + "repository": "syntax-tree/mdast-util-phrasing", + "bugs": "https://github.com/syntax-tree/mdast-util-phrasing/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Victor Felder (https://draft.li)", + "contributors": [ + "Victor Felder (https://draft.li)", + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/mdast": "^4.0.0", + "unist-util-is": "^6.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^9.0.0", + "prettier": "^3.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.56.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api": "node --conditions development test.js", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true + } +} diff --git a/node_modules/mdast-util-phrasing/readme.md b/node_modules/mdast-util-phrasing/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..a797fef20a99e858e9808d3a125e3515c3610c90 --- /dev/null +++ b/node_modules/mdast-util-phrasing/readme.md @@ -0,0 +1,200 @@ +# mdast-util-phrasing + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] utility to check if a node is phrasing content. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`phrasing(value)`](#phrasingvalue) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a tiny utility to check that a given [node][] is [phrasing +content][phrasing]. + +## When should I use this? + +This utility is typically useful if you’re making other utilities. +It uses [`unist-util-is`][unist-util-is], which you can use for your own checks. + +A different utility, [`hast-util-phrasing`][hast-util-phrasing], does the same +but on [hast][]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-phrasing +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {phrasing} from 'https://esm.sh/mdast-util-phrasing@4' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {phrasing} from 'mdast-util-phrasing' + +phrasing({type: 'paragraph', children: [{type: 'text', value: 'Alpha'}]}) +// => false + +phrasing({type: 'strong', children: [{type: 'text', value: 'Delta'}]}) +// => true +``` + +## API + +This package exports the identifier [`phrasing`][api-phrasing]. +There is no default export. + +### `phrasing(value)` + +Check if the given value is *[phrasing content][phrasing]*. + +> 👉 **Note**: Excludes `html`, which can be both phrasing or flow. + +###### Parameters + +* `value` (`unknown`) + — thing to check, typically [`Node`][node] + +###### Returns + +Whether `value` is phrasing content (`boolean`). + +## Types + +This package is fully typed with [TypeScript][]. +It does not export extra types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-phrasing@^4`, +compatible with Node.js 16. + +## Security + +Use of `mdast-util-phrasing` does not involve **[hast][]**, user content, or +change the tree, so there are no openings for [cross-site scripting (XSS)][xss] +attacks. + +## Related + +* [`hast-util-phrasing`](https://github.com/syntax-tree/hast-util-phrasing) + — check if a hast node is phrasing content +* [`unist-util-is`](https://github.com/syntax-tree/unist-util-is) + — check if a node passes a test + +## Contribute + +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Victor Felder][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-phrasing/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-phrasing/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-phrasing.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-phrasing + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-phrasing.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-phrasing + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-phrasing + +[size]: https://bundlejs.com/?q=mdast-util-phrasing + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[license]: license + +[author]: https://draft.li + +[health]: https://github.com/syntax-tree/.github + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[hast]: https://github.com/syntax-tree/hast + +[mdast]: https://github.com/syntax-tree/mdast + +[node]: https://github.com/syntax-tree/mdast#nodes + +[phrasing]: https://github.com/syntax-tree/mdast#phrasingcontent + +[unist-util-is]: https://github.com/syntax-tree/unist-util-is + +[hast-util-phrasing]: https://github.com/syntax-tree/hast-util-phrasing + +[api-phrasing]: #phrasingvalue diff --git a/node_modules/mdast-util-to-hast/index.d.ts b/node_modules/mdast-util-to-hast/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c5c912847f35e5b4530776a5621e24f1215b1a1 --- /dev/null +++ b/node_modules/mdast-util-to-hast/index.d.ts @@ -0,0 +1,94 @@ +import type {Data, ElementContent, Literal, Properties} from 'hast' + +// Expose types. +export type { + FootnoteBackContentTemplate, + FootnoteBackLabelTemplate +} from './lib/footer.js' +export type {Handler, Handlers, Options, State} from './lib/state.js' + +// Expose JS API. +export {handlers as defaultHandlers} from './lib/handlers/index.js' +export { + defaultFootnoteBackContent, + defaultFootnoteBackLabel +} from './lib/footer.js' +export {toHast} from './lib/index.js' + +/** + * Raw string of HTML embedded into HTML AST. + */ +export interface Raw extends Literal { + /** + * Node type of raw. + */ + type: 'raw' + + /** + * Data associated with the hast raw. + */ + data?: RawData | undefined +} + +/** + * Info associated with hast raw nodes by the ecosystem. + */ +export interface RawData extends Data {} + +// Register nodes in content. +declare module 'hast' { + interface ElementData { + /** + * Custom info relating to the node, if `` in `
`.
+     *
+     * Defined by `mdast-util-to-hast` (`remark-rehype`).
+     */
+    meta?: string | null | undefined
+  }
+
+  interface ElementContentMap {
+    /**
+     * Raw string of HTML embedded into HTML AST.
+     */
+    raw: Raw
+  }
+
+  interface RootContentMap {
+    /**
+     * Raw string of HTML embedded into HTML AST.
+     */
+    raw: Raw
+  }
+}
+
+// Register data on mdast.
+declare module 'mdast' {
+  interface Data {
+    /**
+     * Field supported by `mdast-util-to-hast` to signal that a node should
+     * result in something with these children.
+     *
+     * When this is defined, when a parent is created, these children will
+     * be used.
+     */
+    hChildren?: ElementContent[] | undefined
+
+    /**
+     * Field supported by `mdast-util-to-hast` to signal that a node should
+     * result in a particular element, instead of its default behavior.
+     *
+     * When this is defined, an element with the given tag name is created.
+     * For example, when setting `hName` to `'b'`, a `` element is created.
+     */
+    hName?: string | undefined
+
+    /**
+     * Field supported by `mdast-util-to-hast` to signal that a node should
+     * result in an element with these properties.
+     *
+     * When this is defined, when an element is created, these properties will
+     * be used.
+     */
+    hProperties?: Properties | undefined
+  }
+}
diff --git a/node_modules/mdast-util-to-hast/index.js b/node_modules/mdast-util-to-hast/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..5e88898b80d043f2f96d9dd1a0db639ae0d92d38
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/index.js
@@ -0,0 +1,7 @@
+// Note: types exposed from `index.d.ts`.
+export {handlers as defaultHandlers} from './lib/handlers/index.js'
+export {toHast} from './lib/index.js'
+export {
+  defaultFootnoteBackContent,
+  defaultFootnoteBackLabel
+} from './lib/footer.js'
diff --git a/node_modules/mdast-util-to-hast/lib/footer.d.ts b/node_modules/mdast-util-to-hast/lib/footer.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..e0a08815c16104a33b1c520f3cef95503e826be8
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/footer.d.ts
@@ -0,0 +1,81 @@
+/**
+ * Generate the default content that GitHub uses on backreferences.
+ *
+ * @param {number} _
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {Array}
+ *   Content.
+ */
+export function defaultFootnoteBackContent(_: number, rereferenceIndex: number): Array;
+/**
+ * Generate the default label that GitHub uses on backreferences.
+ *
+ * @param {number} referenceIndex
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {string}
+ *   Label.
+ */
+export function defaultFootnoteBackLabel(referenceIndex: number, rereferenceIndex: number): string;
+/**
+ * Generate a hast footer for called footnote definitions.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @returns {Element | undefined}
+ *   `section` element or `undefined`.
+ */
+export function footer(state: State): Element | undefined;
+/**
+ * Generate content for the backreference dynamically.
+ *
+ * For the following markdown:
+ *
+ * ```markdown
+ * Alpha[^micromark], bravo[^micromark], and charlie[^remark].
+ *
+ * [^remark]: things about remark
+ * [^micromark]: things about micromark
+ * ```
+ *
+ * This function will be called with:
+ *
+ * *  `0` and `0` for the backreference from `things about micromark` to
+ *  `alpha`, as it is the first used definition, and the first call to it
+ * *  `0` and `1` for the backreference from `things about micromark` to
+ *  `bravo`, as it is the first used definition, and the second call to it
+ * *  `1` and `0` for the backreference from `things about remark` to
+ *  `charlie`, as it is the second used definition
+ */
+export type FootnoteBackContentTemplate = (referenceIndex: number, rereferenceIndex: number) => Array | ElementContent | string;
+/**
+ * Generate a back label dynamically.
+ *
+ * For the following markdown:
+ *
+ * ```markdown
+ * Alpha[^micromark], bravo[^micromark], and charlie[^remark].
+ *
+ * [^remark]: things about remark
+ * [^micromark]: things about micromark
+ * ```
+ *
+ * This function will be called with:
+ *
+ * *  `0` and `0` for the backreference from `things about micromark` to
+ *  `alpha`, as it is the first used definition, and the first call to it
+ * *  `0` and `1` for the backreference from `things about micromark` to
+ *  `bravo`, as it is the first used definition, and the second call to it
+ * *  `1` and `0` for the backreference from `things about remark` to
+ *  `charlie`, as it is the second used definition
+ */
+export type FootnoteBackLabelTemplate = (referenceIndex: number, rereferenceIndex: number) => string;
+import type { ElementContent } from 'hast';
+import type { State } from './state.js';
+import type { Element } from 'hast';
+//# sourceMappingURL=footer.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/footer.d.ts.map b/node_modules/mdast-util-to-hast/lib/footer.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..c3fce40c6584702a65ba95ff6a38d2f766d6ab88
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/footer.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["footer.js"],"names":[],"mappings":"AAmEA;;;;;;;;;;GAUG;AACH,8CARW,MAAM,oBAGN,MAAM,GAEJ,KAAK,CAAC,cAAc,CAAC,CAiBjC;AAED;;;;;;;;;;GAUG;AACH,yDARW,MAAM,oBAGN,MAAM,GAEJ,MAAM,CASlB;AAED;;;;;;;GAOG;AAEH,8BANW,KAAK,GAEH,OAAO,GAAG,SAAS,CAmI/B;;;;;;;;;;;;;;;;;;;;;;2DA/NU,MAAM,oBAGN,MAAM,KAEJ,KAAK,CAAC,cAAc,CAAC,GAAG,cAAc,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;yDAwBjD,MAAM,oBAGN,MAAM,KAEJ,MAAM;oCA3DuB,MAAM;2BACxB,YAAY;6BADM,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/footer.js b/node_modules/mdast-util-to-hast/lib/footer.js
new file mode 100644
index 0000000000000000000000000000000000000000..d26807c87ee5c6ed9aad068522a4b85866e1380b
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/footer.js
@@ -0,0 +1,250 @@
+/**
+ * @import {ElementContent, Element} from 'hast'
+ * @import {State} from './state.js'
+ */
+
+/**
+ * @callback FootnoteBackContentTemplate
+ *   Generate content for the backreference dynamically.
+ *
+ *   For the following markdown:
+ *
+ *   ```markdown
+ *   Alpha[^micromark], bravo[^micromark], and charlie[^remark].
+ *
+ *   [^remark]: things about remark
+ *   [^micromark]: things about micromark
+ *   ```
+ *
+ *   This function will be called with:
+ *
+ *   *  `0` and `0` for the backreference from `things about micromark` to
+ *      `alpha`, as it is the first used definition, and the first call to it
+ *   *  `0` and `1` for the backreference from `things about micromark` to
+ *      `bravo`, as it is the first used definition, and the second call to it
+ *   *  `1` and `0` for the backreference from `things about remark` to
+ *      `charlie`, as it is the second used definition
+ * @param {number} referenceIndex
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {Array | ElementContent | string}
+ *   Content for the backreference when linking back from definitions to their
+ *   reference.
+ *
+ * @callback FootnoteBackLabelTemplate
+ *   Generate a back label dynamically.
+ *
+ *   For the following markdown:
+ *
+ *   ```markdown
+ *   Alpha[^micromark], bravo[^micromark], and charlie[^remark].
+ *
+ *   [^remark]: things about remark
+ *   [^micromark]: things about micromark
+ *   ```
+ *
+ *   This function will be called with:
+ *
+ *   *  `0` and `0` for the backreference from `things about micromark` to
+ *      `alpha`, as it is the first used definition, and the first call to it
+ *   *  `0` and `1` for the backreference from `things about micromark` to
+ *      `bravo`, as it is the first used definition, and the second call to it
+ *   *  `1` and `0` for the backreference from `things about remark` to
+ *      `charlie`, as it is the second used definition
+ * @param {number} referenceIndex
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {string}
+ *   Back label to use when linking back from definitions to their reference.
+ */
+
+import structuredClone from '@ungap/structured-clone'
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+
+/**
+ * Generate the default content that GitHub uses on backreferences.
+ *
+ * @param {number} _
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {Array}
+ *   Content.
+ */
+export function defaultFootnoteBackContent(_, rereferenceIndex) {
+  /** @type {Array} */
+  const result = [{type: 'text', value: '↩'}]
+
+  if (rereferenceIndex > 1) {
+    result.push({
+      type: 'element',
+      tagName: 'sup',
+      properties: {},
+      children: [{type: 'text', value: String(rereferenceIndex)}]
+    })
+  }
+
+  return result
+}
+
+/**
+ * Generate the default label that GitHub uses on backreferences.
+ *
+ * @param {number} referenceIndex
+ *   Index of the definition in the order that they are first referenced,
+ *   0-indexed.
+ * @param {number} rereferenceIndex
+ *   Index of calls to the same definition, 0-indexed.
+ * @returns {string}
+ *   Label.
+ */
+export function defaultFootnoteBackLabel(referenceIndex, rereferenceIndex) {
+  return (
+    'Back to reference ' +
+    (referenceIndex + 1) +
+    (rereferenceIndex > 1 ? '-' + rereferenceIndex : '')
+  )
+}
+
+/**
+ * Generate a hast footer for called footnote definitions.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @returns {Element | undefined}
+ *   `section` element or `undefined`.
+ */
+// eslint-disable-next-line complexity
+export function footer(state) {
+  const clobberPrefix =
+    typeof state.options.clobberPrefix === 'string'
+      ? state.options.clobberPrefix
+      : 'user-content-'
+  const footnoteBackContent =
+    state.options.footnoteBackContent || defaultFootnoteBackContent
+  const footnoteBackLabel =
+    state.options.footnoteBackLabel || defaultFootnoteBackLabel
+  const footnoteLabel = state.options.footnoteLabel || 'Footnotes'
+  const footnoteLabelTagName = state.options.footnoteLabelTagName || 'h2'
+  const footnoteLabelProperties = state.options.footnoteLabelProperties || {
+    className: ['sr-only']
+  }
+  /** @type {Array} */
+  const listItems = []
+  let referenceIndex = -1
+
+  while (++referenceIndex < state.footnoteOrder.length) {
+    const definition = state.footnoteById.get(
+      state.footnoteOrder[referenceIndex]
+    )
+
+    if (!definition) {
+      continue
+    }
+
+    const content = state.all(definition)
+    const id = String(definition.identifier).toUpperCase()
+    const safeId = normalizeUri(id.toLowerCase())
+    let rereferenceIndex = 0
+    /** @type {Array} */
+    const backReferences = []
+    const counts = state.footnoteCounts.get(id)
+
+    // eslint-disable-next-line no-unmodified-loop-condition
+    while (counts !== undefined && ++rereferenceIndex <= counts) {
+      if (backReferences.length > 0) {
+        backReferences.push({type: 'text', value: ' '})
+      }
+
+      let children =
+        typeof footnoteBackContent === 'string'
+          ? footnoteBackContent
+          : footnoteBackContent(referenceIndex, rereferenceIndex)
+
+      if (typeof children === 'string') {
+        children = {type: 'text', value: children}
+      }
+
+      backReferences.push({
+        type: 'element',
+        tagName: 'a',
+        properties: {
+          href:
+            '#' +
+            clobberPrefix +
+            'fnref-' +
+            safeId +
+            (rereferenceIndex > 1 ? '-' + rereferenceIndex : ''),
+          dataFootnoteBackref: '',
+          ariaLabel:
+            typeof footnoteBackLabel === 'string'
+              ? footnoteBackLabel
+              : footnoteBackLabel(referenceIndex, rereferenceIndex),
+          className: ['data-footnote-backref']
+        },
+        children: Array.isArray(children) ? children : [children]
+      })
+    }
+
+    const tail = content[content.length - 1]
+
+    if (tail && tail.type === 'element' && tail.tagName === 'p') {
+      const tailTail = tail.children[tail.children.length - 1]
+      if (tailTail && tailTail.type === 'text') {
+        tailTail.value += ' '
+      } else {
+        tail.children.push({type: 'text', value: ' '})
+      }
+
+      tail.children.push(...backReferences)
+    } else {
+      content.push(...backReferences)
+    }
+
+    /** @type {Element} */
+    const listItem = {
+      type: 'element',
+      tagName: 'li',
+      properties: {id: clobberPrefix + 'fn-' + safeId},
+      children: state.wrap(content, true)
+    }
+
+    state.patch(definition, listItem)
+
+    listItems.push(listItem)
+  }
+
+  if (listItems.length === 0) {
+    return
+  }
+
+  return {
+    type: 'element',
+    tagName: 'section',
+    properties: {dataFootnotes: true, className: ['footnotes']},
+    children: [
+      {
+        type: 'element',
+        tagName: footnoteLabelTagName,
+        properties: {
+          ...structuredClone(footnoteLabelProperties),
+          id: 'footnote-label'
+        },
+        children: [{type: 'text', value: footnoteLabel}]
+      },
+      {type: 'text', value: '\n'},
+      {
+        type: 'element',
+        tagName: 'ol',
+        properties: {},
+        children: state.wrap(listItems, true)
+      },
+      {type: 'text', value: '\n'}
+    ]
+  }
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..336ab4649a1bb1bbcd68db2de7121be600bf2804
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Blockquote} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `blockquote` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Blockquote} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function blockquote(state: State, node: Blockquote): Element;
+import type { State } from '../state.js';
+import type { Blockquote } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=blockquote.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..ef0885b8d2dc8fd92d3502e24d7b3c2b9a79cf75
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["blockquote.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,kCAPW,KAAK,QAEL,UAAU,GAER,OAAO,CAanB;2BAvBuB,aAAa;gCADR,OAAO;6BADV,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/blockquote.js b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.js
new file mode 100644
index 0000000000000000000000000000000000000000..c278be1aa07f56f850f2412121c2c3bb3c80b397
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/blockquote.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Blockquote} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `blockquote` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Blockquote} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function blockquote(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'blockquote',
+    properties: {},
+    children: state.wrap(state.all(node), true)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..5289478969dae7737bc5c3d8b27ee9e6fa6b5b33
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts
@@ -0,0 +1,21 @@
+/**
+ * @import {Element, Text} from 'hast'
+ * @import {Break} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `break` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Break} node
+ *   mdast node.
+ * @returns {Array}
+ *   hast element content.
+ */
+export function hardBreak(state: State, node: Break): Array;
+import type { State } from '../state.js';
+import type { Break } from 'mdast';
+import type { Element } from 'hast';
+import type { Text } from 'hast';
+//# sourceMappingURL=break.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..824d0de0d1b47c0de81ff20abbfe23cce1b45a54
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/break.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"break.d.ts","sourceRoot":"","sources":["break.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,iCAPW,KAAK,QAEL,KAAK,GAEH,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAQjC;2BAlBuB,aAAa;2BADb,OAAO;6BADC,MAAM;0BAAN,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/break.js b/node_modules/mdast-util-to-hast/lib/handlers/break.js
new file mode 100644
index 0000000000000000000000000000000000000000..cb4868bf075d1cd2f6abcdd302fd7b1a95448a82
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/break.js
@@ -0,0 +1,22 @@
+/**
+ * @import {Element, Text} from 'hast'
+ * @import {Break} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `break` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Break} node
+ *   mdast node.
+ * @returns {Array}
+ *   hast element content.
+ */
+export function hardBreak(state, node) {
+  /** @type {Element} */
+  const result = {type: 'element', tagName: 'br', properties: {}, children: []}
+  state.patch(node, result)
+  return [state.applyData(node, result), {type: 'text', value: '\n'}]
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a709b701c9e6a27ac55abbf8c111cd73d087701d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {Code} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `code` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Code} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function code(state: State, node: Code): Element;
+import type { State } from '../state.js';
+import type { Code } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=code.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..b09744b861e0f4de04c734bc38824bc77fb2ebd2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/code.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["code.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,4BAPW,KAAK,QAEL,IAAI,GAEF,OAAO,CAmCnB;2BA7CuB,aAAa;0BADd,OAAO;6BADQ,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/code.js b/node_modules/mdast-util-to-hast/lib/handlers/code.js
new file mode 100644
index 0000000000000000000000000000000000000000..4df449a90040e080e6d9f42f9f125f20248d1125
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/code.js
@@ -0,0 +1,49 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {Code} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `code` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Code} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function code(state, node) {
+  const value = node.value ? node.value + '\n' : ''
+  /** @type {Properties} */
+  const properties = {}
+  // Someone can write `js python	ruby`.
+  const language = node.lang ? node.lang.split(/\s+/) : []
+
+  // GH/CM still drop the non-first languages.
+  if (language.length > 0) {
+    properties.className = ['language-' + language[0]]
+  }
+
+  // Create ``.
+  /** @type {Element} */
+  let result = {
+    type: 'element',
+    tagName: 'code',
+    properties,
+    children: [{type: 'text', value}]
+  }
+
+  if (node.meta) {
+    result.data = {meta: node.meta}
+  }
+
+  state.patch(node, result)
+  result = state.applyData(node, result)
+
+  // Create `
`.
+  result = {type: 'element', tagName: 'pre', properties: {}, children: [result]}
+  state.patch(node, result)
+  return result
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f64b17832fca2231efe70d218adb326ae920b24b
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Delete} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `delete` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Delete} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function strikethrough(state: State, node: Delete): Element;
+import type { State } from '../state.js';
+import type { Delete } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=delete.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..ce83f8a60d33751c6507d794b3992cdf194554f4
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/delete.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["delete.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,qCAPW,KAAK,QAEL,MAAM,GAEJ,OAAO,CAanB;2BAvBuB,aAAa;4BADZ,OAAO;6BADN,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/delete.js b/node_modules/mdast-util-to-hast/lib/handlers/delete.js
new file mode 100644
index 0000000000000000000000000000000000000000..5c0492996013e81ba14f6a53823633b218b2862d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/delete.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Delete} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `delete` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Delete} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function strikethrough(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'del',
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..44acbb4c4fd3880a4726aac1fe3d307e05ef0d45
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Emphasis} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `emphasis` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Emphasis} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function emphasis(state: State, node: Emphasis): Element;
+import type { State } from '../state.js';
+import type { Emphasis } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=emphasis.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..4181c91071a584087a342faafea9f997edaaa35d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["emphasis.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,gCAPW,KAAK,QAEL,QAAQ,GAEN,OAAO,CAanB;2BAvBuB,aAAa;8BADV,OAAO;6BADR,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/emphasis.js b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.js
new file mode 100644
index 0000000000000000000000000000000000000000..d9fa9fe6ed6e6d99a681630eb6d55e8f544a47ad
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/emphasis.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Emphasis} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `emphasis` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Emphasis} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function emphasis(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'em',
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..600ac1d2f533f7796875382cf73e4ee0c88fe974
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `footnoteReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {FootnoteReference} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function footnoteReference(state: State, node: FootnoteReference): Element;
+import type { State } from '../state.js';
+import type { FootnoteReference } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=footnote-reference.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..8a8dd3db27b7cf7ca4a5693abc833dd311d5ccf2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"footnote-reference.d.ts","sourceRoot":"","sources":["footnote-reference.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,yCAPW,KAAK,QAEL,iBAAiB,GAEf,OAAO,CAsDnB;2BAlEuB,aAAa;uCADD,OAAO;6BADjB,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.js b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.js
new file mode 100644
index 0000000000000000000000000000000000000000..8f39e79ede3391ccd22988bff7fb4f3799522d97
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/footnote-reference.js
@@ -0,0 +1,70 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {FootnoteReference} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+
+/**
+ * Turn an mdast `footnoteReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {FootnoteReference} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function footnoteReference(state, node) {
+  const clobberPrefix =
+    typeof state.options.clobberPrefix === 'string'
+      ? state.options.clobberPrefix
+      : 'user-content-'
+  const id = String(node.identifier).toUpperCase()
+  const safeId = normalizeUri(id.toLowerCase())
+  const index = state.footnoteOrder.indexOf(id)
+  /** @type {number} */
+  let counter
+
+  let reuseCounter = state.footnoteCounts.get(id)
+
+  if (reuseCounter === undefined) {
+    reuseCounter = 0
+    state.footnoteOrder.push(id)
+    counter = state.footnoteOrder.length
+  } else {
+    counter = index + 1
+  }
+
+  reuseCounter += 1
+  state.footnoteCounts.set(id, reuseCounter)
+
+  /** @type {Element} */
+  const link = {
+    type: 'element',
+    tagName: 'a',
+    properties: {
+      href: '#' + clobberPrefix + 'fn-' + safeId,
+      id:
+        clobberPrefix +
+        'fnref-' +
+        safeId +
+        (reuseCounter > 1 ? '-' + reuseCounter : ''),
+      dataFootnoteRef: true,
+      ariaDescribedBy: ['footnote-label']
+    },
+    children: [{type: 'text', value: String(counter)}]
+  }
+  state.patch(node, link)
+
+  /** @type {Element} */
+  const sup = {
+    type: 'element',
+    tagName: 'sup',
+    properties: {},
+    children: [link]
+  }
+  state.patch(node, sup)
+  return state.applyData(node, sup)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..173e4d2c0dda03e1ab3e1d347fefbaecdbf787d2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Heading} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `heading` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Heading} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function heading(state: State, node: Heading): Element;
+import type { State } from '../state.js';
+import type { Heading } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=heading.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..e9936a3b982c3fc15971af5517cdd8c20bf03835
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/heading.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["heading.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,+BAPW,KAAK,QAEL,OAAO,GAEL,OAAO,CAanB;2BAvBuB,aAAa;6BADX,OAAO;6BADP,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/heading.js b/node_modules/mdast-util-to-hast/lib/handlers/heading.js
new file mode 100644
index 0000000000000000000000000000000000000000..6e041f9e44d39326ef75a747c97be9229f2a6fed
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/heading.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Heading} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `heading` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Heading} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function heading(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'h' + node.depth,
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b07246050472837c7c29003745e3675f5bb14fa2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts
@@ -0,0 +1,23 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Html} from 'mdast'
+ * @import {State} from '../state.js'
+ * @import {Raw} from '../../index.js'
+ */
+/**
+ * Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
+ * nothing).
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Html} node
+ *   mdast node.
+ * @returns {Element | Raw | undefined}
+ *   hast node.
+ */
+export function html(state: State, node: Html): Element | Raw | undefined;
+import type { State } from '../state.js';
+import type { Html } from 'mdast';
+import type { Element } from 'hast';
+import type { Raw } from '../../index.js';
+//# sourceMappingURL=html.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..d7ad01b8e805528c06cb84fd4421f5f2411685d2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/html.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,4BAPW,KAAK,QAEL,IAAI,GAEF,OAAO,GAAG,GAAG,GAAG,SAAS,CAYrC;2BAxBuB,aAAa;0BADd,OAAO;6BADJ,MAAM;yBAGV,gBAAgB"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/html.js b/node_modules/mdast-util-to-hast/lib/handlers/html.js
new file mode 100644
index 0000000000000000000000000000000000000000..1617665588c0c8c22a4480c4218663ff577b69f3
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/html.js
@@ -0,0 +1,28 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Html} from 'mdast'
+ * @import {State} from '../state.js'
+ * @import {Raw} from '../../index.js'
+ */
+
+/**
+ * Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
+ * nothing).
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Html} node
+ *   mdast node.
+ * @returns {Element | Raw | undefined}
+ *   hast node.
+ */
+export function html(state, node) {
+  if (state.options.allowDangerousHtml) {
+    /** @type {Raw} */
+    const result = {type: 'raw', value: node.value}
+    state.patch(node, result)
+    return state.applyData(node, result)
+  }
+
+  return undefined
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..454a4bf3f9e066acde4b21f4567be1fd9e2f02a1
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `imageReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ImageReference} node
+ *   mdast node.
+ * @returns {Array | ElementContent}
+ *   hast node.
+ */
+export function imageReference(state: State, node: ImageReference): Array | ElementContent;
+import type { State } from '../state.js';
+import type { ImageReference } from 'mdast';
+import type { ElementContent } from 'hast';
+//# sourceMappingURL=image-reference.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..e2a906c052e43ea1032b68bc4b8ddafb623d5ab9
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"image-reference.d.ts","sourceRoot":"","sources":["image-reference.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,sCAPW,KAAK,QAEL,cAAc,GAEZ,KAAK,CAAC,cAAc,CAAC,GAAG,cAAc,CAsBlD;2BAnCuB,aAAa;oCADJ,OAAO;oCADc,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image-reference.js b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.js
new file mode 100644
index 0000000000000000000000000000000000000000..b758406904a972367eeabd030108f8ae8a6641c6
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image-reference.js
@@ -0,0 +1,39 @@
+/**
+ * @import {ElementContent, Element, Properties} from 'hast'
+ * @import {ImageReference} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+import {revert} from '../revert.js'
+
+/**
+ * Turn an mdast `imageReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ImageReference} node
+ *   mdast node.
+ * @returns {Array | ElementContent}
+ *   hast node.
+ */
+export function imageReference(state, node) {
+  const id = String(node.identifier).toUpperCase()
+  const definition = state.definitionById.get(id)
+
+  if (!definition) {
+    return revert(state, node)
+  }
+
+  /** @type {Properties} */
+  const properties = {src: normalizeUri(definition.url || ''), alt: node.alt}
+
+  if (definition.title !== null && definition.title !== undefined) {
+    properties.title = definition.title
+  }
+
+  /** @type {Element} */
+  const result = {type: 'element', tagName: 'img', properties, children: []}
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9dd2bf94cf46e436698c0d71ad75943fa9621903
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `image` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Image} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function image(state: State, node: Image): Element;
+import type { State } from '../state.js';
+import type { Image } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=image.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..6e6e205290cc85c034535c62ac218b6a18b9f1f3
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["image.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,6BAPW,KAAK,QAEL,KAAK,GAEH,OAAO,CAmBnB;2BA/BuB,aAAa;2BADb,OAAO;6BADO,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/image.js b/node_modules/mdast-util-to-hast/lib/handlers/image.js
new file mode 100644
index 0000000000000000000000000000000000000000..aa183932fea27c00f22bc2bcb4f38532d265bf85
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/image.js
@@ -0,0 +1,35 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {Image} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+
+/**
+ * Turn an mdast `image` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Image} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function image(state, node) {
+  /** @type {Properties} */
+  const properties = {src: normalizeUri(node.url)}
+
+  if (node.alt !== null && node.alt !== undefined) {
+    properties.alt = node.alt
+  }
+
+  if (node.title !== null && node.title !== undefined) {
+    properties.title = node.title
+  }
+
+  /** @type {Element} */
+  const result = {type: 'element', tagName: 'img', properties, children: []}
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..fb72486c5505e6bbd736185a9c63a7d13b7e87d5
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts
@@ -0,0 +1,55 @@
+export namespace handlers {
+    export { blockquote };
+    export { hardBreak as break };
+    export { code };
+    export { strikethrough as delete };
+    export { emphasis };
+    export { footnoteReference };
+    export { heading };
+    export { html };
+    export { imageReference };
+    export { image };
+    export { inlineCode };
+    export { linkReference };
+    export { link };
+    export { listItem };
+    export { list };
+    export { paragraph };
+    export { root };
+    export { strong };
+    export { table };
+    export { tableCell };
+    export { tableRow };
+    export { text };
+    export { thematicBreak };
+    export { ignore as toml };
+    export { ignore as yaml };
+    export { ignore as definition };
+    export { ignore as footnoteDefinition };
+}
+import { blockquote } from './blockquote.js';
+import { hardBreak } from './break.js';
+import { code } from './code.js';
+import { strikethrough } from './delete.js';
+import { emphasis } from './emphasis.js';
+import { footnoteReference } from './footnote-reference.js';
+import { heading } from './heading.js';
+import { html } from './html.js';
+import { imageReference } from './image-reference.js';
+import { image } from './image.js';
+import { inlineCode } from './inline-code.js';
+import { linkReference } from './link-reference.js';
+import { link } from './link.js';
+import { listItem } from './list-item.js';
+import { list } from './list.js';
+import { paragraph } from './paragraph.js';
+import { root } from './root.js';
+import { strong } from './strong.js';
+import { table } from './table.js';
+import { tableCell } from './table-cell.js';
+import { tableRow } from './table-row.js';
+import { text } from './text.js';
+import { thematicBreak } from './thematic-break.js';
+declare function ignore(): undefined;
+export {};
+//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..15185eab6e8ae3809f8c30b4c38c2095af249659
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAIyB,iBAAiB;0BAClB,YAAY;qBACjB,WAAW;8BACF,aAAa;yBAClB,eAAe;kCACN,yBAAyB;wBACnC,cAAc;qBACjB,WAAW;+BACD,sBAAsB;sBAC/B,YAAY;2BACP,kBAAkB;8BACf,qBAAqB;qBAC9B,WAAW;yBACP,gBAAgB;qBACpB,WAAW;0BACN,gBAAgB;qBACrB,WAAW;uBACT,aAAa;sBACd,YAAY;0BAER,iBAAiB;yBADlB,gBAAgB;qBAEpB,WAAW;8BACF,qBAAqB;AAuCjD,qCAEC"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/index.js b/node_modules/mdast-util-to-hast/lib/handlers/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..7ff77da09c7ee4722eca2ad054403f0ced6623fd
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/index.js
@@ -0,0 +1,68 @@
+/**
+ * @import {Handlers} from '../state.js'
+ */
+
+import {blockquote} from './blockquote.js'
+import {hardBreak} from './break.js'
+import {code} from './code.js'
+import {strikethrough} from './delete.js'
+import {emphasis} from './emphasis.js'
+import {footnoteReference} from './footnote-reference.js'
+import {heading} from './heading.js'
+import {html} from './html.js'
+import {imageReference} from './image-reference.js'
+import {image} from './image.js'
+import {inlineCode} from './inline-code.js'
+import {linkReference} from './link-reference.js'
+import {link} from './link.js'
+import {listItem} from './list-item.js'
+import {list} from './list.js'
+import {paragraph} from './paragraph.js'
+import {root} from './root.js'
+import {strong} from './strong.js'
+import {table} from './table.js'
+import {tableRow} from './table-row.js'
+import {tableCell} from './table-cell.js'
+import {text} from './text.js'
+import {thematicBreak} from './thematic-break.js'
+
+/**
+ * Default handlers for nodes.
+ *
+ * @satisfies {Handlers}
+ */
+export const handlers = {
+  blockquote,
+  break: hardBreak,
+  code,
+  delete: strikethrough,
+  emphasis,
+  footnoteReference,
+  heading,
+  html,
+  imageReference,
+  image,
+  inlineCode,
+  linkReference,
+  link,
+  listItem,
+  list,
+  paragraph,
+  // @ts-expect-error: root is different, but hard to type.
+  root,
+  strong,
+  table,
+  tableCell,
+  tableRow,
+  text,
+  thematicBreak,
+  toml: ignore,
+  yaml: ignore,
+  definition: ignore,
+  footnoteDefinition: ignore
+}
+
+// Return nothing for nodes that are ignored.
+function ignore() {
+  return undefined
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..c0b9f1b0476b433b4a2562b8ff9fc95f40d61c2d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element, Text} from 'hast'
+ * @import {InlineCode} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `inlineCode` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {InlineCode} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function inlineCode(state: State, node: InlineCode): Element;
+import type { State } from '../state.js';
+import type { InlineCode } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=inline-code.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..d4eb397bfb12999da8cbea7b5dcbf7bd843a0d46
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["inline-code.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,kCAPW,KAAK,QAEL,UAAU,GAER,OAAO,CAiBnB;2BA3BuB,aAAa;gCADR,OAAO;6BADJ,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/inline-code.js b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.js
new file mode 100644
index 0000000000000000000000000000000000000000..7edf48db604e58fb546ae12af9cc4cd8e55d02a6
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/inline-code.js
@@ -0,0 +1,31 @@
+/**
+ * @import {Element, Text} from 'hast'
+ * @import {InlineCode} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `inlineCode` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {InlineCode} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function inlineCode(state, node) {
+  /** @type {Text} */
+  const text = {type: 'text', value: node.value.replace(/\r?\n|\r/g, ' ')}
+  state.patch(node, text)
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'code',
+    properties: {},
+    children: [text]
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..39186538f5400e10a1518f80e07bc85b3e527d45
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `linkReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {LinkReference} node
+ *   mdast node.
+ * @returns {Array | ElementContent}
+ *   hast node.
+ */
+export function linkReference(state: State, node: LinkReference): Array | ElementContent;
+import type { State } from '../state.js';
+import type { LinkReference } from 'mdast';
+import type { ElementContent } from 'hast';
+//# sourceMappingURL=link-reference.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..040a6d8b0f42efed9493356045426fb283af1c95
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"link-reference.d.ts","sourceRoot":"","sources":["link-reference.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,qCAPW,KAAK,QAEL,aAAa,GAEX,KAAK,CAAC,cAAc,CAAC,GAAG,cAAc,CA2BlD;2BAxCuB,aAAa;mCADL,OAAO;oCADe,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link-reference.js b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.js
new file mode 100644
index 0000000000000000000000000000000000000000..a98c14d7165954c34838cf432bb8340d32e2da83
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link-reference.js
@@ -0,0 +1,44 @@
+/**
+ * @import {ElementContent, Element, Properties} from 'hast'
+ * @import {LinkReference} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+import {revert} from '../revert.js'
+
+/**
+ * Turn an mdast `linkReference` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {LinkReference} node
+ *   mdast node.
+ * @returns {Array | ElementContent}
+ *   hast node.
+ */
+export function linkReference(state, node) {
+  const id = String(node.identifier).toUpperCase()
+  const definition = state.definitionById.get(id)
+
+  if (!definition) {
+    return revert(state, node)
+  }
+
+  /** @type {Properties} */
+  const properties = {href: normalizeUri(definition.url || '')}
+
+  if (definition.title !== null && definition.title !== undefined) {
+    properties.title = definition.title
+  }
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'a',
+    properties,
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..e02a88acaf966cf6d3570d0f5c870af32181cb9e
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `link` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Link} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function link(state: State, node: Link): Element;
+import type { State } from '../state.js';
+import type { Link } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=link.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..efeb9839e972189cfb800e87ae8a167b70540ed9
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["link.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,4BAPW,KAAK,QAEL,IAAI,GAEF,OAAO,CAoBnB;2BAhCuB,aAAa;0BADd,OAAO;6BADQ,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/link.js b/node_modules/mdast-util-to-hast/lib/handlers/link.js
new file mode 100644
index 0000000000000000000000000000000000000000..00f970a907f56f91ea07004491c5b5287cce1722
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/link.js
@@ -0,0 +1,36 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {Link} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {normalizeUri} from 'micromark-util-sanitize-uri'
+
+/**
+ * Turn an mdast `link` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Link} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function link(state, node) {
+  /** @type {Properties} */
+  const properties = {href: normalizeUri(node.url)}
+
+  if (node.title !== null && node.title !== undefined) {
+    properties.title = node.title
+  }
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'a',
+    properties,
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b904138496edb92a6c4fad2db9bee76479bd179d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts
@@ -0,0 +1,23 @@
+/**
+ * @import {ElementContent, Element, Properties} from 'hast'
+ * @import {ListItem, Parents} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `listItem` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ListItem} node
+ *   mdast node.
+ * @param {Parents | undefined} parent
+ *   Parent of `node`.
+ * @returns {Element}
+ *   hast node.
+ */
+export function listItem(state: State, node: ListItem, parent: Parents | undefined): Element;
+import type { State } from '../state.js';
+import type { ListItem } from 'mdast';
+import type { Parents } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=list-item.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..66b66068195678fb9ea25c0bb93b12bed63eab0e
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list-item.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["list-item.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,gCATW,KAAK,QAEL,QAAQ,UAER,OAAO,GAAG,SAAS,GAEjB,OAAO,CAwEnB;2BApFuB,aAAa;8BADD,OAAO;6BAAP,OAAO;6BADW,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list-item.js b/node_modules/mdast-util-to-hast/lib/handlers/list-item.js
new file mode 100644
index 0000000000000000000000000000000000000000..eca0db3ce774dd87a388efecb428731bffc1ac9e
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list-item.js
@@ -0,0 +1,119 @@
+/**
+ * @import {ElementContent, Element, Properties} from 'hast'
+ * @import {ListItem, Parents} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `listItem` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ListItem} node
+ *   mdast node.
+ * @param {Parents | undefined} parent
+ *   Parent of `node`.
+ * @returns {Element}
+ *   hast node.
+ */
+export function listItem(state, node, parent) {
+  const results = state.all(node)
+  const loose = parent ? listLoose(parent) : listItemLoose(node)
+  /** @type {Properties} */
+  const properties = {}
+  /** @type {Array} */
+  const children = []
+
+  if (typeof node.checked === 'boolean') {
+    const head = results[0]
+    /** @type {Element} */
+    let paragraph
+
+    if (head && head.type === 'element' && head.tagName === 'p') {
+      paragraph = head
+    } else {
+      paragraph = {type: 'element', tagName: 'p', properties: {}, children: []}
+      results.unshift(paragraph)
+    }
+
+    if (paragraph.children.length > 0) {
+      paragraph.children.unshift({type: 'text', value: ' '})
+    }
+
+    paragraph.children.unshift({
+      type: 'element',
+      tagName: 'input',
+      properties: {type: 'checkbox', checked: node.checked, disabled: true},
+      children: []
+    })
+
+    // According to github-markdown-css, this class hides bullet.
+    // See: .
+    properties.className = ['task-list-item']
+  }
+
+  let index = -1
+
+  while (++index < results.length) {
+    const child = results[index]
+
+    // Add eols before nodes, except if this is a loose, first paragraph.
+    if (
+      loose ||
+      index !== 0 ||
+      child.type !== 'element' ||
+      child.tagName !== 'p'
+    ) {
+      children.push({type: 'text', value: '\n'})
+    }
+
+    if (child.type === 'element' && child.tagName === 'p' && !loose) {
+      children.push(...child.children)
+    } else {
+      children.push(child)
+    }
+  }
+
+  const tail = results[results.length - 1]
+
+  // Add a final eol.
+  if (tail && (loose || tail.type !== 'element' || tail.tagName !== 'p')) {
+    children.push({type: 'text', value: '\n'})
+  }
+
+  /** @type {Element} */
+  const result = {type: 'element', tagName: 'li', properties, children}
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
+
+/**
+ * @param {Parents} node
+ * @return {Boolean}
+ */
+function listLoose(node) {
+  let loose = false
+  if (node.type === 'list') {
+    loose = node.spread || false
+    const children = node.children
+    let index = -1
+
+    while (!loose && ++index < children.length) {
+      loose = listItemLoose(children[index])
+    }
+  }
+
+  return loose
+}
+
+/**
+ * @param {ListItem} node
+ * @return {Boolean}
+ */
+function listItemLoose(node) {
+  const spread = node.spread
+
+  return spread === null || spread === undefined
+    ? node.children.length > 1
+    : spread
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..425d30b8b00330957e5bcb4eb81773658b8680e4
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {List} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `list` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {List} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function list(state: State, node: List): Element;
+import type { State } from '../state.js';
+import type { List } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=list.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..724240b53c4962bcb475ee1145d1e46f95420d70
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,4BAPW,KAAK,QAEL,IAAI,GAEF,OAAO,CAsCnB;2BAhDuB,aAAa;0BADd,OAAO;6BADQ,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/list.js b/node_modules/mdast-util-to-hast/lib/handlers/list.js
new file mode 100644
index 0000000000000000000000000000000000000000..85bb3eb6c40dc05af1874aedcc7ab5ac530b7f59
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/list.js
@@ -0,0 +1,52 @@
+/**
+ * @import {Element, Properties} from 'hast'
+ * @import {List} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `list` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {List} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function list(state, node) {
+  /** @type {Properties} */
+  const properties = {}
+  const results = state.all(node)
+  let index = -1
+
+  if (typeof node.start === 'number' && node.start !== 1) {
+    properties.start = node.start
+  }
+
+  // Like GitHub, add a class for custom styling.
+  while (++index < results.length) {
+    const child = results[index]
+
+    if (
+      child.type === 'element' &&
+      child.tagName === 'li' &&
+      child.properties &&
+      Array.isArray(child.properties.className) &&
+      child.properties.className.includes('task-list-item')
+    ) {
+      properties.className = ['contains-task-list']
+      break
+    }
+  }
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: node.ordered ? 'ol' : 'ul',
+    properties,
+    children: state.wrap(results, true)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..5de8deb735c865182b009147f25d1b066a885f68
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Paragraph} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `paragraph` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Paragraph} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function paragraph(state: State, node: Paragraph): Element;
+import type { State } from '../state.js';
+import type { Paragraph } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=paragraph.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..86386109e364862bd820c5aa2404ca965ca4e715
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["paragraph.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,iCAPW,KAAK,QAEL,SAAS,GAEP,OAAO,CAanB;2BAvBuB,aAAa;+BADT,OAAO;6BADT,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/paragraph.js b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.js
new file mode 100644
index 0000000000000000000000000000000000000000..04d0870de73312281af72e7d1284989625f2ac69
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/paragraph.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Paragraph} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `paragraph` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Paragraph} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function paragraph(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'p',
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..fe15d197e4eb08a9d908ab1fe8adb1a3d779769d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Parents as HastParents, Root as HastRoot} from 'hast'
+ * @import {Root as MdastRoot} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `root` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {MdastRoot} node
+ *   mdast node.
+ * @returns {HastParents}
+ *   hast node.
+ */
+export function root(state: State, node: MdastRoot): HastParents;
+import type { State } from '../state.js';
+import type { Root as MdastRoot } from 'mdast';
+import type { Parents as HastParents } from 'hast';
+//# sourceMappingURL=root.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..8634371e7c0db7fcc5a453d31f42ae4f91db5ee0
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/root.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["root.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,4BAPW,KAAK,QAEL,SAAS,GAEP,WAAW,CAQvB;2BAlBuB,aAAa;uCADD,OAAO;4CADgB,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/root.js b/node_modules/mdast-util-to-hast/lib/handlers/root.js
new file mode 100644
index 0000000000000000000000000000000000000000..001a5869ae0d4b8cf824a5aadee6e2f8dd1552ea
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/root.js
@@ -0,0 +1,22 @@
+/**
+ * @import {Parents as HastParents, Root as HastRoot} from 'hast'
+ * @import {Root as MdastRoot} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `root` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {MdastRoot} node
+ *   mdast node.
+ * @returns {HastParents}
+ *   hast node.
+ */
+export function root(state, node) {
+  /** @type {HastRoot} */
+  const result = {type: 'root', children: state.wrap(state.all(node))}
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..aec2d5401548ffa99b4fdb17ec156d993e3e70df
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Strong} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `strong` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Strong} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function strong(state: State, node: Strong): Element;
+import type { State } from '../state.js';
+import type { Strong } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=strong.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..f53a0a73cf0519f3e5897036a25afa278982c733
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/strong.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["strong.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,8BAPW,KAAK,QAEL,MAAM,GAEJ,OAAO,CAanB;2BAvBuB,aAAa;4BADZ,OAAO;6BADN,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/strong.js b/node_modules/mdast-util-to-hast/lib/handlers/strong.js
new file mode 100644
index 0000000000000000000000000000000000000000..297346e5f830aad37a31b0a6c9aee525389a95da
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/strong.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {Strong} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `strong` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Strong} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function strong(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'strong',
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..449ba27f493d26651393994deec878b01d9e7999
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {TableCell} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `tableCell` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {TableCell} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function tableCell(state: State, node: TableCell): Element;
+import type { State } from '../state.js';
+import type { TableCell } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=table-cell.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..5e865e00670afb997bf7516b6b913018453c1026
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"table-cell.d.ts","sourceRoot":"","sources":["table-cell.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,iCAPW,KAAK,QAEL,SAAS,GAEP,OAAO,CAenB;2BAzBuB,aAAa;+BADT,OAAO;6BADT,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-cell.js b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.js
new file mode 100644
index 0000000000000000000000000000000000000000..ecbcd221268c3499d2f42718bace58046e717946
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-cell.js
@@ -0,0 +1,29 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {TableCell} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `tableCell` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {TableCell} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function tableCell(state, node) {
+  // Note: this function is normally not called: see `table-row` for how rows
+  // and their cells are compiled.
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'td', // Assume body cell.
+    properties: {},
+    children: state.all(node)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..b6b8d703048ab7a8e60ff17360fe4e2951f49794
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts
@@ -0,0 +1,23 @@
+/**
+ * @import {Element, ElementContent, Properties} from 'hast'
+ * @import {Parents, TableRow} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `tableRow` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {TableRow} node
+ *   mdast node.
+ * @param {Parents | undefined} parent
+ *   Parent of `node`.
+ * @returns {Element}
+ *   hast node.
+ */
+export function tableRow(state: State, node: TableRow, parent: Parents | undefined): Element;
+import type { State } from '../state.js';
+import type { TableRow } from 'mdast';
+import type { Parents } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=table-row.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..4d9c4eb7b72d61a4de7da913b5af86c00920d5a2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-row.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"table-row.d.ts","sourceRoot":"","sources":["table-row.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,gCATW,KAAK,QAEL,QAAQ,UAER,OAAO,GAAG,SAAS,GAEjB,OAAO,CA+CnB;2BA3DuB,aAAa;8BADD,OAAO;6BAAP,OAAO;6BADW,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table-row.js b/node_modules/mdast-util-to-hast/lib/handlers/table-row.js
new file mode 100644
index 0000000000000000000000000000000000000000..718561a5fa85408a95ec92e0a5d64733dd83f6dd
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table-row.js
@@ -0,0 +1,63 @@
+/**
+ * @import {Element, ElementContent, Properties} from 'hast'
+ * @import {Parents, TableRow} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `tableRow` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {TableRow} node
+ *   mdast node.
+ * @param {Parents | undefined} parent
+ *   Parent of `node`.
+ * @returns {Element}
+ *   hast node.
+ */
+export function tableRow(state, node, parent) {
+  const siblings = parent ? parent.children : undefined
+  // Generate a body row when without parent.
+  const rowIndex = siblings ? siblings.indexOf(node) : 1
+  const tagName = rowIndex === 0 ? 'th' : 'td'
+  // To do: option to use `style`?
+  const align = parent && parent.type === 'table' ? parent.align : undefined
+  const length = align ? align.length : node.children.length
+  let cellIndex = -1
+  /** @type {Array} */
+  const cells = []
+
+  while (++cellIndex < length) {
+    // Note: can also be undefined.
+    const cell = node.children[cellIndex]
+    /** @type {Properties} */
+    const properties = {}
+    const alignValue = align ? align[cellIndex] : undefined
+
+    if (alignValue) {
+      properties.align = alignValue
+    }
+
+    /** @type {Element} */
+    let result = {type: 'element', tagName, properties, children: []}
+
+    if (cell) {
+      result.children = state.all(cell)
+      state.patch(cell, result)
+      result = state.applyData(cell, result)
+    }
+
+    cells.push(result)
+  }
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'tr',
+    properties: {},
+    children: state.wrap(cells, true)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..a64956bd6c18a5bdaf7ea46b8dccca6abe1a3d06
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts
@@ -0,0 +1,15 @@
+/**
+ * Turn an mdast `table` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Table} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function table(state: State, node: Table): Element;
+import type { State } from '../state.js';
+import type { Table } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=table.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..3684f4e83e79a1758683aee02dc266d9f9fb128d
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["table.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,6BAPW,KAAK,QAEL,KAAK,GAEH,OAAO,CA6CnB;2BAzDuB,aAAa;2BAFb,OAAO;6BACL,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/table.js b/node_modules/mdast-util-to-hast/lib/handlers/table.js
new file mode 100644
index 0000000000000000000000000000000000000000..58b67703701630bd59ae638cae3ef623557fb48f
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/table.js
@@ -0,0 +1,61 @@
+/**
+ * @import {Table} from 'mdast'
+ * @import {Element} from 'hast'
+ * @import {State} from '../state.js'
+ */
+
+import {pointEnd, pointStart} from 'unist-util-position'
+
+/**
+ * Turn an mdast `table` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {Table} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function table(state, node) {
+  const rows = state.all(node)
+  const firstRow = rows.shift()
+  /** @type {Array} */
+  const tableContent = []
+
+  if (firstRow) {
+    /** @type {Element} */
+    const head = {
+      type: 'element',
+      tagName: 'thead',
+      properties: {},
+      children: state.wrap([firstRow], true)
+    }
+    state.patch(node.children[0], head)
+    tableContent.push(head)
+  }
+
+  if (rows.length > 0) {
+    /** @type {Element} */
+    const body = {
+      type: 'element',
+      tagName: 'tbody',
+      properties: {},
+      children: state.wrap(rows, true)
+    }
+
+    const start = pointStart(node.children[1])
+    const end = pointEnd(node.children[node.children.length - 1])
+    if (start && end) body.position = {start, end}
+    tableContent.push(body)
+  }
+
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'table',
+    properties: {},
+    children: state.wrap(tableContent, true)
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..d252a81a6e5600b86966b7527459f066469fd5ae
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts
@@ -0,0 +1,16 @@
+/**
+ * Turn an mdast `text` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {MdastText} node
+ *   mdast node.
+ * @returns {HastElement | HastText}
+ *   hast node.
+ */
+export function text(state: State, node: MdastText): HastElement | HastText;
+import type { State } from '../state.js';
+import type { Text as MdastText } from 'mdast';
+import type { Element as HastElement } from 'hast';
+import type { Text as HastText } from 'hast';
+//# sourceMappingURL=text.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..ef563c60d3a356bb86a984c1f2e3ce0ced1f2aee
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/text.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["text.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,4BAPW,KAAK,QAEL,SAAS,GAEP,WAAW,GAAG,QAAQ,CAQlC;2BApBuB,aAAa;uCADD,OAAO;4CADgB,MAAM;sCAAN,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/text.js b/node_modules/mdast-util-to-hast/lib/handlers/text.js
new file mode 100644
index 0000000000000000000000000000000000000000..e107e38025da0ad8772f905d03b6f18385fbc959
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/text.js
@@ -0,0 +1,24 @@
+/**
+ * @import {Element as HastElement, Text as HastText} from 'hast'
+ * @import {Text as MdastText} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+import {trimLines} from 'trim-lines'
+
+/**
+ * Turn an mdast `text` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {MdastText} node
+ *   mdast node.
+ * @returns {HastElement | HastText}
+ *   hast node.
+ */
+export function text(state, node) {
+  /** @type {HastText} */
+  const result = {type: 'text', value: trimLines(String(node.value))}
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..7b6eb0009c052690c3266dcb5da61e0e8d5ef1c0
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts
@@ -0,0 +1,20 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {ThematicBreak} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+/**
+ * Turn an mdast `thematicBreak` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ThematicBreak} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function thematicBreak(state: State, node: ThematicBreak): Element;
+import type { State } from '../state.js';
+import type { ThematicBreak } from 'mdast';
+import type { Element } from 'hast';
+//# sourceMappingURL=thematic-break.d.ts.map
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts.map b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts.map
new file mode 100644
index 0000000000000000000000000000000000000000..75ddf8fc4610fb19d8fad38f2f9b78ceafae2404
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"thematic-break.d.ts","sourceRoot":"","sources":["thematic-break.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,qCAPW,KAAK,QAEL,aAAa,GAEX,OAAO,CAanB;2BAvBuB,aAAa;mCADL,OAAO;6BADb,MAAM"}
\ No newline at end of file
diff --git a/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.js b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.js
new file mode 100644
index 0000000000000000000000000000000000000000..8b878006d8e9ac68bdb28e113bcf61805e7ea6c2
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/handlers/thematic-break.js
@@ -0,0 +1,27 @@
+/**
+ * @import {Element} from 'hast'
+ * @import {ThematicBreak} from 'mdast'
+ * @import {State} from '../state.js'
+ */
+
+/**
+ * Turn an mdast `thematicBreak` node into hast.
+ *
+ * @param {State} state
+ *   Info passed around.
+ * @param {ThematicBreak} node
+ *   mdast node.
+ * @returns {Element}
+ *   hast node.
+ */
+export function thematicBreak(state, node) {
+  /** @type {Element} */
+  const result = {
+    type: 'element',
+    tagName: 'hr',
+    properties: {},
+    children: []
+  }
+  state.patch(node, result)
+  return state.applyData(node, result)
+}
diff --git a/node_modules/mdast-util-to-hast/lib/index.d.ts b/node_modules/mdast-util-to-hast/lib/index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..37223112f9de14c56cacd6b98158a799d25ae63c
--- /dev/null
+++ b/node_modules/mdast-util-to-hast/lib/index.d.ts
@@ -0,0 +1,82 @@
+/**
+ * Transform mdast to hast.
+ *
+ * ##### Notes
+ *
+ * ###### HTML
+ *
+ * Raw HTML is available in mdast as `html` nodes and can be embedded in hast
+ * as semistandard `raw` nodes.
+ * Most utilities ignore `raw` nodes but two notable ones don’t:
+ *
+ * *   `hast-util-to-html` also has an option `allowDangerousHtml` which will
+ *     output the raw HTML.
+ *     This is typically discouraged as noted by the option name but is useful
+ *     if you completely trust authors
+ * *   `hast-util-raw` can handle the raw embedded HTML strings by parsing them
+ *     into standard hast nodes (`element`, `text`, etc).
+ *     This is a heavy task as it needs a full HTML parser, but it is the only
+ *     way to support untrusted content
+ *
+ * ###### Footnotes
+ *
+ * Many options supported here relate to footnotes.
+ * Footnotes are not specified by CommonMark, which we follow by default.
+ * They are supported by GitHub, so footnotes can be enabled in markdown with
+ * `mdast-util-gfm`.
+ *
+ * The options `footnoteBackLabel` and `footnoteLabel` define natural language
+ * that explains footnotes, which is hidden for sighted users but shown to
+ * assistive technology.
+ * When your page is not in English, you must define translated values.
+ *
+ * Back references use ARIA attributes, but the section label itself uses a
+ * heading that is hidden with an `sr-only` class.
+ * To show it to sighted users, define different attributes in
+ * `footnoteLabelProperties`.
+ *
+ * ###### Clobbering
+ *
+ * Footnotes introduces a problem, as it links footnote calls to footnote
+ * definitions on the page through `id` attributes generated from user content,
+ * which results in DOM clobbering.
+ *
+ * DOM clobbering is this:
+ *
+ * ```html
+ * 

+ * + * ``` + * + * Elements by their ID are made available by browsers on the `window` object, + * which is a security risk. + * Using a prefix solves this problem. + * + * More information on how to handle clobbering and the prefix is explained in + * Example: headings (DOM clobbering) in `rehype-sanitize`. + * + * ###### Unknown nodes + * + * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`. + * The default behavior for unknown nodes is: + * + * * when the node has a `value` (and doesn’t have `data.hName`, + * `data.hProperties`, or `data.hChildren`, see later), create a hast `text` + * node + * * otherwise, create a `
` element (which could be changed with + * `data.hName`), with its children mapped from mdast to hast as well + * + * This behavior can be changed by passing an `unknownHandler`. + * + * @param {MdastNodes} tree + * mdast tree. + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {HastNodes} + * hast tree. + */ +export function toHast(tree: MdastNodes, options?: Options | null | undefined): HastNodes; +import type { Nodes as MdastNodes } from 'mdast'; +import type { Options } from './state.js'; +import type { Nodes as HastNodes } from 'hast'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/index.d.ts.map b/node_modules/mdast-util-to-hast/lib/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e265feedf61242d15231df1a11f19acd800e2177 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,6BAPW,UAAU,YAEV,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,SAAS,CAqBrB;yCAvGqC,OAAO;6BACnB,YAAY;wCAFD,MAAM"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/index.js b/node_modules/mdast-util-to-hast/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..15b3361723b1fea643ad3dacac6ef41951ce8326 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/index.js @@ -0,0 +1,106 @@ +/** + * @import {Nodes as HastNodes} from 'hast' + * @import {Nodes as MdastNodes} from 'mdast' + * @import {Options} from './state.js' + */ + +import {ok as assert} from 'devlop' +import {footer} from './footer.js' +import {createState} from './state.js' + +/** + * Transform mdast to hast. + * + * ##### Notes + * + * ###### HTML + * + * Raw HTML is available in mdast as `html` nodes and can be embedded in hast + * as semistandard `raw` nodes. + * Most utilities ignore `raw` nodes but two notable ones don’t: + * + * * `hast-util-to-html` also has an option `allowDangerousHtml` which will + * output the raw HTML. + * This is typically discouraged as noted by the option name but is useful + * if you completely trust authors + * * `hast-util-raw` can handle the raw embedded HTML strings by parsing them + * into standard hast nodes (`element`, `text`, etc). + * This is a heavy task as it needs a full HTML parser, but it is the only + * way to support untrusted content + * + * ###### Footnotes + * + * Many options supported here relate to footnotes. + * Footnotes are not specified by CommonMark, which we follow by default. + * They are supported by GitHub, so footnotes can be enabled in markdown with + * `mdast-util-gfm`. + * + * The options `footnoteBackLabel` and `footnoteLabel` define natural language + * that explains footnotes, which is hidden for sighted users but shown to + * assistive technology. + * When your page is not in English, you must define translated values. + * + * Back references use ARIA attributes, but the section label itself uses a + * heading that is hidden with an `sr-only` class. + * To show it to sighted users, define different attributes in + * `footnoteLabelProperties`. + * + * ###### Clobbering + * + * Footnotes introduces a problem, as it links footnote calls to footnote + * definitions on the page through `id` attributes generated from user content, + * which results in DOM clobbering. + * + * DOM clobbering is this: + * + * ```html + *

+ * + * ``` + * + * Elements by their ID are made available by browsers on the `window` object, + * which is a security risk. + * Using a prefix solves this problem. + * + * More information on how to handle clobbering and the prefix is explained in + * Example: headings (DOM clobbering) in `rehype-sanitize`. + * + * ###### Unknown nodes + * + * Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`. + * The default behavior for unknown nodes is: + * + * * when the node has a `value` (and doesn’t have `data.hName`, + * `data.hProperties`, or `data.hChildren`, see later), create a hast `text` + * node + * * otherwise, create a `
` element (which could be changed with + * `data.hName`), with its children mapped from mdast to hast as well + * + * This behavior can be changed by passing an `unknownHandler`. + * + * @param {MdastNodes} tree + * mdast tree. + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {HastNodes} + * hast tree. + */ +export function toHast(tree, options) { + const state = createState(tree, options) + const node = state.one(tree, undefined) + const foot = footer(state) + /** @type {HastNodes} */ + const result = Array.isArray(node) + ? {type: 'root', children: node} + : node || {type: 'root', children: []} + + if (foot) { + // If there’s a footer, there were definitions, meaning block + // content. + // So `result` is a parent node. + assert('children' in result) + result.children.push({type: 'text', value: '\n'}, foot) + } + + return result +} diff --git a/node_modules/mdast-util-to-hast/lib/revert.d.ts b/node_modules/mdast-util-to-hast/lib/revert.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d1a9ea01c8a5be7568e1c1ab941fbcadfe95a6b9 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/revert.d.ts @@ -0,0 +1,21 @@ +/** + * @import {ElementContent} from 'hast' + * @import {Reference, Nodes} from 'mdast' + * @import {State} from './state.js' + */ +/** + * Return the content of a reference without definition as plain text. + * + * @param {State} state + * Info passed around. + * @param {Extract} node + * Reference node (image, link). + * @returns {Array} + * hast content. + */ +export function revert(state: State, node: Extract): Array; +import type { State } from './state.js'; +import type { Nodes } from 'mdast'; +import type { Reference } from 'mdast'; +import type { ElementContent } from 'hast'; +//# sourceMappingURL=revert.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/revert.d.ts.map b/node_modules/mdast-util-to-hast/lib/revert.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b743a8c9e918e63b9e45aa5b8d43fb7f3d1d585d --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/revert.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"revert.d.ts","sourceRoot":"","sources":["revert.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,8BAPW,KAAK,QAEL,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,GAEvB,KAAK,CAAC,cAAc,CAAC,CAmCjC;2BA7CuB,YAAY;2BADD,OAAO;+BAAP,OAAO;oCADT,MAAM"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/revert.js b/node_modules/mdast-util-to-hast/lib/revert.js new file mode 100644 index 0000000000000000000000000000000000000000..942382f9e211c9008bf33694dfbab28edfe397bc --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/revert.js @@ -0,0 +1,49 @@ +/** + * @import {ElementContent} from 'hast' + * @import {Reference, Nodes} from 'mdast' + * @import {State} from './state.js' + */ + +/** + * Return the content of a reference without definition as plain text. + * + * @param {State} state + * Info passed around. + * @param {Extract} node + * Reference node (image, link). + * @returns {Array} + * hast content. + */ +export function revert(state, node) { + const subtype = node.referenceType + let suffix = ']' + + if (subtype === 'collapsed') { + suffix += '[]' + } else if (subtype === 'full') { + suffix += '[' + (node.label || node.identifier) + ']' + } + + if (node.type === 'imageReference') { + return [{type: 'text', value: '![' + node.alt + suffix}] + } + + const contents = state.all(node) + const head = contents[0] + + if (head && head.type === 'text') { + head.value = '[' + head.value + } else { + contents.unshift({type: 'text', value: '['}) + } + + const tail = contents[contents.length - 1] + + if (tail && tail.type === 'text') { + tail.value += suffix + } else { + contents.push({type: 'text', value: suffix}) + } + + return contents +} diff --git a/node_modules/mdast-util-to-hast/lib/state.d.ts b/node_modules/mdast-util-to-hast/lib/state.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e6e270617a6cbb2ba7284e8a15a596b40e478a27 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/state.d.ts @@ -0,0 +1,233 @@ +/** + * Create `state` from an mdast tree. + * + * @param {MdastNodes} tree + * mdast node to transform. + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {State} + * `state` function. + */ +export function createState(tree: MdastNodes, options?: Options | null | undefined): State; +/** + * Wrap `nodes` with line endings between each node. + * + * @template {HastRootContent} Type + * Node type. + * @param {Array} nodes + * List of nodes to wrap. + * @param {boolean | undefined} [loose=false] + * Whether to add line endings at start and end (default: `false`). + * @returns {Array} + * Wrapped nodes. + */ +export function wrap(nodes: Array, loose?: boolean | undefined): Array; +/** + * Handle a node. + */ +export type Handler = (state: State, node: any, parent: MdastParents | undefined) => Array | HastElementContent | undefined; +/** + * Handle nodes. + */ +export type Handlers = Partial>; +/** + * Configuration (optional). + */ +export type Options = { + /** + * Whether to persist raw HTML in markdown in the hast tree (default: + * `false`). + */ + allowDangerousHtml?: boolean | null | undefined; + /** + * Prefix to use before the `id` property on footnotes to prevent them from + * *clobbering* (default: `'user-content-'`). + * + * Pass `''` for trusted markdown and when you are careful with + * polyfilling. + * You could pass a different prefix. + * + * DOM clobbering is this: + * + * ```html + *

+ * + * ``` + * + * The above example shows that elements are made available by browsers, by + * their ID, on the `window` object. + * This is a security risk because you might be expecting some other variable + * at that place. + * It can also break polyfills. + * Using a prefix solves these problems. + */ + clobberPrefix?: string | null | undefined; + /** + * Corresponding virtual file representing the input document (optional). + */ + file?: VFile | null | undefined; + /** + * Content of the backreference back to references (default: `defaultFootnoteBackContent`). + * + * The default value is: + * + * ```js + * function defaultFootnoteBackContent(_, rereferenceIndex) { + * const result = [{type: 'text', value: '↩'}] + * + * if (rereferenceIndex > 1) { + * result.push({ + * type: 'element', + * tagName: 'sup', + * properties: {}, + * children: [{type: 'text', value: String(rereferenceIndex)}] + * }) + * } + * + * return result + * } + * ``` + * + * This content is used in the `a` element of each backreference (the `↩` + * links). + */ + footnoteBackContent?: FootnoteBackContentTemplate | string | null | undefined; + /** + * Label to describe the backreference back to references (default: + * `defaultFootnoteBackLabel`). + * + * The default value is: + * + * ```js + * function defaultFootnoteBackLabel(referenceIndex, rereferenceIndex) { + * return ( + * 'Back to reference ' + + * (referenceIndex + 1) + + * (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') + * ) + * } + * ``` + * + * Change it when the markdown is not in English. + * + * This label is used in the `ariaLabel` property on each backreference + * (the `↩` links). + * It affects users of assistive technology. + */ + footnoteBackLabel?: FootnoteBackLabelTemplate | string | null | undefined; + /** + * Textual label to use for the footnotes section (default: `'Footnotes'`). + * + * Change it when the markdown is not in English. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different properties with the `footnoteLabelProperties` option. + */ + footnoteLabel?: string | null | undefined; + /** + * Properties to use on the footnote label (default: `{className: + * ['sr-only']}`). + * + * Change it to show the label and add other properties. + * + * This label is typically hidden visually (assuming an `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass an empty string. + * You can also add different properties. + * + * > **Note**: `id: 'footnote-label'` is always added, because footnote + * > calls use it with `aria-describedby` to provide an accessible label. + */ + footnoteLabelProperties?: HastProperties | null | undefined; + /** + * HTML tag name to use for the footnote label element (default: `'h2'`). + * + * Change it to match your document structure. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different properties with the `footnoteLabelProperties` option. + */ + footnoteLabelTagName?: string | null | undefined; + /** + * Extra handlers for nodes (optional). + */ + handlers?: Handlers | null | undefined; + /** + * List of custom mdast node types to pass through (keep) in hast (note that + * the node itself is passed, but eventual children are transformed) + * (optional). + */ + passThrough?: Array | null | undefined; + /** + * Handler for all unknown nodes (optional). + */ + unknownHandler?: Handler | null | undefined; +}; +/** + * Info passed around. + */ +export type State = { + /** + * Transform the children of an mdast parent to hast. + */ + all: (node: MdastNodes) => Array; + /** + * Honor the `data` of `from`, and generate an element instead of `node`. + */ + applyData: (from: MdastNodes, to: Type) => HastElement | Type; + /** + * Definitions by their identifier. + */ + definitionById: Map; + /** + * Footnote definitions by their identifier. + */ + footnoteById: Map; + /** + * Counts for how often the same footnote was called. + */ + footnoteCounts: Map; + /** + * Identifiers of order when footnote calls first appear in tree order. + */ + footnoteOrder: Array; + /** + * Applied handlers. + */ + handlers: Handlers; + /** + * Transform an mdast node to hast. + */ + one: (node: MdastNodes, parent: MdastParents | undefined) => Array | HastElementContent | undefined; + /** + * Configuration. + */ + options: Options; + /** + * Copy a node’s positional info. + */ + patch: (from: MdastNodes, node: HastNodes) => undefined; + /** + * Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`. + */ + wrap: (nodes: Array, loose?: boolean | undefined) => Array; +}; +import type { Nodes as MdastNodes } from 'mdast'; +import type { RootContent as HastRootContent } from 'hast'; +import type { Text as HastText } from 'hast'; +import type { Parents as MdastParents } from 'mdast'; +import type { ElementContent as HastElementContent } from 'hast'; +import type { VFile } from 'vfile'; +import type { FootnoteBackContentTemplate } from './footer.js'; +import type { FootnoteBackLabelTemplate } from './footer.js'; +import type { Properties as HastProperties } from 'hast'; +import type { Nodes as HastNodes } from 'hast'; +import type { Element as HastElement } from 'hast'; +import type { Definition as MdastDefinition } from 'mdast'; +import type { FootnoteDefinition as MdastFootnoteDefinition } from 'mdast'; +//# sourceMappingURL=state.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/state.d.ts.map b/node_modules/mdast-util-to-hast/lib/state.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..8d27127e8b80d47b449d7407fcd496c37056dba8 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/state.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["state.js"],"names":[],"mappings":"AA2LA;;;;;;;;;GASG;AACH,kCAPW,UAAU,YAEV,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,KAAK,CAiIjB;AAqGD;;;;;;;;;;;GAWG;AACH,qBAT+B,IAAI,SAAtB,eAAiB,SAEnB,KAAK,CAAC,IAAI,CAAC,UAEX,OAAO,GAAG,SAAS,GAEjB,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAsBlC;;;;8BA9aU,KAAK,QAEL,GAAG,UAEH,YAAY,GAAG,SAAS,KAEtB,KAAK,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,GAAG,SAAS;;;;uBAG1D,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;;;;;;;;;yBAK3C,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;oBAG1B,MAAM,GAAG,IAAI,GAAG,SAAS;;;;WAqBzB,KAAK,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;0BAExB,2BAA2B,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;wBAwBvD,yBAAyB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;oBAqBrD,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;;;;;8BASzB,cAAc,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;2BAcjC,MAAM,GAAG,IAAI,GAAG,SAAS;;;;eASzB,QAAQ,GAAG,IAAI,GAAG,SAAS;;;;;;kBAE3B,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS;;;;qBAI5C,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;;;;SAK1B,CAAC,IAAI,EAAE,UAAU,KAAK,KAAK,CAAC,kBAAkB,CAAC;;;;eAE/C,CAAC,IAAI,SAAS,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,KAAK,WAAW,GAAG,IAAI;;;;oBAE1E,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC;;;;kBAE5B,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAC;;;;oBAEpC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;;;mBAEnB,KAAK,CAAC,MAAM,CAAC;;;;cAEb,QAAQ;;;;SAER,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,KAAK,KAAK,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,GAAG,SAAS;;;;aAElH,OAAO;;;;WAEP,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,KAAK,SAAS;;;;UAEhD,CAAC,IAAI,SAAS,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,KAAK,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;;yCA/J7G,OAAO;oDANP,MAAM;sCAAN,MAAM;6CAMN,OAAO;0DANP,MAAM;2BAOQ,OAAO;iDAIrB,aAAa;+CAAb,aAAa;kDAXb,MAAM;wCAAN,MAAM;4CAAN,MAAM;mDAMN,OAAO;mEAAP,OAAO"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-hast/lib/state.js b/node_modules/mdast-util-to-hast/lib/state.js new file mode 100644 index 0000000000000000000000000000000000000000..0d9c9dff22022c7199b26551fdd831422f761e98 --- /dev/null +++ b/node_modules/mdast-util-to-hast/lib/state.js @@ -0,0 +1,476 @@ +/** + * @import { + * ElementContent as HastElementContent, + * Element as HastElement, + * Nodes as HastNodes, + * Properties as HastProperties, + * RootContent as HastRootContent, + * Text as HastText + * } from 'hast' + * @import { + * Definition as MdastDefinition, + * FootnoteDefinition as MdastFootnoteDefinition, + * Nodes as MdastNodes, + * Parents as MdastParents + * } from 'mdast' + * @import {VFile} from 'vfile' + * @import { + * FootnoteBackContentTemplate, + * FootnoteBackLabelTemplate + * } from './footer.js' + */ + +/** + * @callback Handler + * Handle a node. + * @param {State} state + * Info passed around. + * @param {any} node + * mdast node to handle. + * @param {MdastParents | undefined} parent + * Parent of `node`. + * @returns {Array | HastElementContent | undefined} + * hast node. + * + * @typedef {Partial>} Handlers + * Handle nodes. + * + * @typedef Options + * Configuration (optional). + * @property {boolean | null | undefined} [allowDangerousHtml=false] + * Whether to persist raw HTML in markdown in the hast tree (default: + * `false`). + * @property {string | null | undefined} [clobberPrefix='user-content-'] + * Prefix to use before the `id` property on footnotes to prevent them from + * *clobbering* (default: `'user-content-'`). + * + * Pass `''` for trusted markdown and when you are careful with + * polyfilling. + * You could pass a different prefix. + * + * DOM clobbering is this: + * + * ```html + *

+ * + * ``` + * + * The above example shows that elements are made available by browsers, by + * their ID, on the `window` object. + * This is a security risk because you might be expecting some other variable + * at that place. + * It can also break polyfills. + * Using a prefix solves these problems. + * @property {VFile | null | undefined} [file] + * Corresponding virtual file representing the input document (optional). + * @property {FootnoteBackContentTemplate | string | null | undefined} [footnoteBackContent] + * Content of the backreference back to references (default: `defaultFootnoteBackContent`). + * + * The default value is: + * + * ```js + * function defaultFootnoteBackContent(_, rereferenceIndex) { + * const result = [{type: 'text', value: '↩'}] + * + * if (rereferenceIndex > 1) { + * result.push({ + * type: 'element', + * tagName: 'sup', + * properties: {}, + * children: [{type: 'text', value: String(rereferenceIndex)}] + * }) + * } + * + * return result + * } + * ``` + * + * This content is used in the `a` element of each backreference (the `↩` + * links). + * @property {FootnoteBackLabelTemplate | string | null | undefined} [footnoteBackLabel] + * Label to describe the backreference back to references (default: + * `defaultFootnoteBackLabel`). + * + * The default value is: + * + * ```js + * function defaultFootnoteBackLabel(referenceIndex, rereferenceIndex) { + * return ( + * 'Back to reference ' + + * (referenceIndex + 1) + + * (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') + * ) + * } + * ``` + * + * Change it when the markdown is not in English. + * + * This label is used in the `ariaLabel` property on each backreference + * (the `↩` links). + * It affects users of assistive technology. + * @property {string | null | undefined} [footnoteLabel='Footnotes'] + * Textual label to use for the footnotes section (default: `'Footnotes'`). + * + * Change it when the markdown is not in English. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different properties with the `footnoteLabelProperties` option. + * @property {HastProperties | null | undefined} [footnoteLabelProperties={className: ['sr-only']}] + * Properties to use on the footnote label (default: `{className: + * ['sr-only']}`). + * + * Change it to show the label and add other properties. + * + * This label is typically hidden visually (assuming an `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass an empty string. + * You can also add different properties. + * + * > **Note**: `id: 'footnote-label'` is always added, because footnote + * > calls use it with `aria-describedby` to provide an accessible label. + * @property {string | null | undefined} [footnoteLabelTagName='h2'] + * HTML tag name to use for the footnote label element (default: `'h2'`). + * + * Change it to match your document structure. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different properties with the `footnoteLabelProperties` option. + * @property {Handlers | null | undefined} [handlers] + * Extra handlers for nodes (optional). + * @property {Array | null | undefined} [passThrough] + * List of custom mdast node types to pass through (keep) in hast (note that + * the node itself is passed, but eventual children are transformed) + * (optional). + * @property {Handler | null | undefined} [unknownHandler] + * Handler for all unknown nodes (optional). + * + * @typedef State + * Info passed around. + * @property {(node: MdastNodes) => Array} all + * Transform the children of an mdast parent to hast. + * @property {(from: MdastNodes, to: Type) => HastElement | Type} applyData + * Honor the `data` of `from`, and generate an element instead of `node`. + * @property {Map} definitionById + * Definitions by their identifier. + * @property {Map} footnoteById + * Footnote definitions by their identifier. + * @property {Map} footnoteCounts + * Counts for how often the same footnote was called. + * @property {Array} footnoteOrder + * Identifiers of order when footnote calls first appear in tree order. + * @property {Handlers} handlers + * Applied handlers. + * @property {(node: MdastNodes, parent: MdastParents | undefined) => Array | HastElementContent | undefined} one + * Transform an mdast node to hast. + * @property {Options} options + * Configuration. + * @property {(from: MdastNodes, node: HastNodes) => undefined} patch + * Copy a node’s positional info. + * @property {(nodes: Array, loose?: boolean | undefined) => Array} wrap + * Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`. + */ + +import structuredClone from '@ungap/structured-clone' +import {visit} from 'unist-util-visit' +import {position} from 'unist-util-position' +import {handlers as defaultHandlers} from './handlers/index.js' + +const own = {}.hasOwnProperty + +/** @type {Options} */ +const emptyOptions = {} + +/** + * Create `state` from an mdast tree. + * + * @param {MdastNodes} tree + * mdast node to transform. + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {State} + * `state` function. + */ +export function createState(tree, options) { + const settings = options || emptyOptions + /** @type {Map} */ + const definitionById = new Map() + /** @type {Map} */ + const footnoteById = new Map() + /** @type {Map} */ + const footnoteCounts = new Map() + /** @type {Handlers} */ + // @ts-expect-error: the root handler returns a root. + // Hard to type. + const handlers = {...defaultHandlers, ...settings.handlers} + + /** @type {State} */ + const state = { + all, + applyData, + definitionById, + footnoteById, + footnoteCounts, + footnoteOrder: [], + handlers, + one, + options: settings, + patch, + wrap + } + + visit(tree, function (node) { + if (node.type === 'definition' || node.type === 'footnoteDefinition') { + const map = node.type === 'definition' ? definitionById : footnoteById + const id = String(node.identifier).toUpperCase() + + // Mimick CM behavior of link definitions. + // See: . + if (!map.has(id)) { + // @ts-expect-error: node type matches map. + map.set(id, node) + } + } + }) + + return state + + /** + * Transform an mdast node into a hast node. + * + * @param {MdastNodes} node + * mdast node. + * @param {MdastParents | undefined} [parent] + * Parent of `node`. + * @returns {Array | HastElementContent | undefined} + * Resulting hast node. + */ + function one(node, parent) { + const type = node.type + const handle = state.handlers[type] + + if (own.call(state.handlers, type) && handle) { + return handle(state, node, parent) + } + + if (state.options.passThrough && state.options.passThrough.includes(type)) { + if ('children' in node) { + const {children, ...shallow} = node + const result = structuredClone(shallow) + // @ts-expect-error: TS doesn’t understand… + result.children = state.all(node) + // @ts-expect-error: TS doesn’t understand… + return result + } + + // @ts-expect-error: it’s custom. + return structuredClone(node) + } + + const unknown = state.options.unknownHandler || defaultUnknownHandler + + return unknown(state, node, parent) + } + + /** + * Transform the children of an mdast node into hast nodes. + * + * @param {MdastNodes} parent + * mdast node to compile + * @returns {Array} + * Resulting hast nodes. + */ + function all(parent) { + /** @type {Array} */ + const values = [] + + if ('children' in parent) { + const nodes = parent.children + let index = -1 + while (++index < nodes.length) { + const result = state.one(nodes[index], parent) + + // To do: see if we van clean this? Can we merge texts? + if (result) { + if (index && nodes[index - 1].type === 'break') { + if (!Array.isArray(result) && result.type === 'text') { + result.value = trimMarkdownSpaceStart(result.value) + } + + if (!Array.isArray(result) && result.type === 'element') { + const head = result.children[0] + + if (head && head.type === 'text') { + head.value = trimMarkdownSpaceStart(head.value) + } + } + } + + if (Array.isArray(result)) { + values.push(...result) + } else { + values.push(result) + } + } + } + } + + return values + } +} + +/** + * Copy a node’s positional info. + * + * @param {MdastNodes} from + * mdast node to copy from. + * @param {HastNodes} to + * hast node to copy into. + * @returns {undefined} + * Nothing. + */ +function patch(from, to) { + if (from.position) to.position = position(from) +} + +/** + * Honor the `data` of `from` and maybe generate an element instead of `to`. + * + * @template {HastNodes} Type + * Node type. + * @param {MdastNodes} from + * mdast node to use data from. + * @param {Type} to + * hast node to change. + * @returns {HastElement | Type} + * Nothing. + */ +function applyData(from, to) { + /** @type {HastElement | Type} */ + let result = to + + // Handle `data.hName`, `data.hProperties, `data.hChildren`. + if (from && from.data) { + const hName = from.data.hName + const hChildren = from.data.hChildren + const hProperties = from.data.hProperties + + if (typeof hName === 'string') { + // Transforming the node resulted in an element with a different name + // than wanted: + if (result.type === 'element') { + result.tagName = hName + } + // Transforming the node resulted in a non-element, which happens for + // raw, text, and root nodes (unless custom handlers are passed). + // The intent of `hName` is to create an element, but likely also to keep + // the content around (otherwise: pass `hChildren`). + else { + /** @type {Array} */ + // @ts-expect-error: assume no doctypes in `root`. + const children = 'children' in result ? result.children : [result] + result = {type: 'element', tagName: hName, properties: {}, children} + } + } + + if (result.type === 'element' && hProperties) { + Object.assign(result.properties, structuredClone(hProperties)) + } + + if ( + 'children' in result && + result.children && + hChildren !== null && + hChildren !== undefined + ) { + result.children = hChildren + } + } + + return result +} + +/** + * Transform an unknown node. + * + * @param {State} state + * Info passed around. + * @param {MdastNodes} node + * Unknown mdast node. + * @returns {HastElement | HastText} + * Resulting hast node. + */ +function defaultUnknownHandler(state, node) { + const data = node.data || {} + /** @type {HastElement | HastText} */ + const result = + 'value' in node && + !(own.call(data, 'hProperties') || own.call(data, 'hChildren')) + ? {type: 'text', value: node.value} + : { + type: 'element', + tagName: 'div', + properties: {}, + children: state.all(node) + } + + state.patch(node, result) + return state.applyData(node, result) +} + +/** + * Wrap `nodes` with line endings between each node. + * + * @template {HastRootContent} Type + * Node type. + * @param {Array} nodes + * List of nodes to wrap. + * @param {boolean | undefined} [loose=false] + * Whether to add line endings at start and end (default: `false`). + * @returns {Array} + * Wrapped nodes. + */ +export function wrap(nodes, loose) { + /** @type {Array} */ + const result = [] + let index = -1 + + if (loose) { + result.push({type: 'text', value: '\n'}) + } + + while (++index < nodes.length) { + if (index) result.push({type: 'text', value: '\n'}) + result.push(nodes[index]) + } + + if (loose && nodes.length > 0) { + result.push({type: 'text', value: '\n'}) + } + + return result +} + +/** + * Trim spaces and tabs at the start of `value`. + * + * @param {string} value + * Value to trim. + * @returns {string} + * Result. + */ +function trimMarkdownSpaceStart(value) { + let index = 0 + let code = value.charCodeAt(index) + + while (code === 9 || code === 32) { + index++ + code = value.charCodeAt(index) + } + + return value.slice(index) +} diff --git a/node_modules/mdast-util-to-hast/license b/node_modules/mdast-util-to-hast/license new file mode 100644 index 0000000000000000000000000000000000000000..8d8660d36ef2eced1f9cce91e17ae0290261734c --- /dev/null +++ b/node_modules/mdast-util-to-hast/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2016 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/mdast-util-to-hast/package.json b/node_modules/mdast-util-to-hast/package.json new file mode 100644 index 0000000000000000000000000000000000000000..99166bc4733db0a741cd0a71fa87ac9a298475c3 --- /dev/null +++ b/node_modules/mdast-util-to-hast/package.json @@ -0,0 +1,119 @@ +{ + "name": "mdast-util-to-hast", + "version": "13.2.1", + "description": "mdast utility to transform to hast", + "license": "MIT", + "keywords": [ + "unist", + "mdast", + "mdast-util", + "hast", + "hast-util", + "util", + "utility", + "markdown", + "html" + ], + "repository": "syntax-tree/mdast-util-to-hast", + "bugs": "https://github.com/syntax-tree/mdast-util-to-hast/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts.map", + "index.d.ts", + "index.js" + ], + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@ungap/structured-clone": "^1.0.0", + "devlop": "^1.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "trim-lines": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "@types/ungap__structured-clone": "^1.0.0", + "c8": "^9.0.0", + "hast-util-to-html": "^9.0.0", + "hastscript": "^9.0.0", + "mdast-util-from-markdown": "^2.0.0", + "mdast-util-gfm": "^3.0.0", + "micromark-extension-gfm": "^3.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.5.1-rc", + "xo": "^0.58.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api": "node --conditions development test/index.js", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm", + [ + "remark-lint-no-html", + false + ] + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "#": "needed `any`s", + "ignoreFiles": [ + "lib/state.d.ts" + ], + "strict": true + }, + "xo": { + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/ban-types": "off", + "@typescript-eslint/consistent-type-definitions": "off" + } + } + ], + "prettier": true, + "rules": { + "import/no-cycle": "error", + "max-depth": "off", + "unicorn/prefer-at": "off", + "unicorn/prefer-code-point": "off", + "unicorn/prefer-string-replace-all": "off" + } + } +} diff --git a/node_modules/mdast-util-to-hast/readme.md b/node_modules/mdast-util-to-hast/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..6e40d91b86a4f8b9171d0b66b5eddc0b4005e7fe --- /dev/null +++ b/node_modules/mdast-util-to-hast/readme.md @@ -0,0 +1,1725 @@ +# mdast-util-to-hast + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[mdast][] utility to transform to [hast][]. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`defaultFootnoteBackContent(referenceIndex, rereferenceIndex)`](#defaultfootnotebackcontentreferenceindex-rereferenceindex) + * [`defaultFootnoteBackLabel(referenceIndex, rereferenceIndex)`](#defaultfootnotebacklabelreferenceindex-rereferenceindex) + * [`defaultHandlers`](#defaulthandlers) + * [`toHast(tree[, options])`](#tohasttree-options) + * [`FootnoteBackContentTemplate`](#footnotebackcontenttemplate) + * [`FootnoteBackLabelTemplate`](#footnotebacklabeltemplate) + * [`Handler`](#handler) + * [`Handlers`](#handlers) + * [`Options`](#options) + * [`Raw`](#raw) + * [`State`](#state) +* [Examples](#examples) + * [Example: supporting HTML in markdown naïvely](#example-supporting-html-in-markdown-naïvely) + * [Example: supporting HTML in markdown properly](#example-supporting-html-in-markdown-properly) + * [Example: footnotes in languages other than English](#example-footnotes-in-languages-other-than-english) + * [Example: supporting custom nodes](#example-supporting-custom-nodes) +* [Algorithm](#algorithm) + * [Default handling](#default-handling) + * [Fields on nodes](#fields-on-nodes) +* [CSS](#css) +* [Syntax tree](#syntax-tree) + * [Nodes](#nodes) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a utility that takes an [mdast][] (markdown) syntax tree as +input and turns it into a [hast][] (HTML) syntax tree. + +## When should I use this? + +This project is useful when you want to deal with ASTs and turn markdown to +HTML. + +The hast utility [`hast-util-to-mdast`][hast-util-to-mdast] does the inverse of +this utility. +It turns HTML into markdown. + +The remark plugin [`remark-rehype`][remark-rehype] wraps this utility to also +turn markdown to HTML at a higher-level (easier) abstraction. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install mdast-util-to-hast +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {toHast} from 'https://esm.sh/mdast-util-to-hast@13' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say we have the following `example.md`: + +```markdown +## Hello **World**! +``` + +…and next to it a module `example.js`: + +```js +import {fs} from 'node:fs/promises' +import {toHtml} from 'hast-util-to-html' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {toHast} from 'mdast-util-to-hast' + +const markdown = String(await fs.readFile('example.md')) +const mdast = fromMarkdown(markdown) +const hast = toHast(mdast) +const html = toHtml(hast) + +console.log(html) +``` + +…now running `node example.js` yields: + +```html +

Hello World!

+``` + +## API + +This package exports the identifiers +[`defaultFootnoteBackContent`][api-default-footnote-back-content], +[`defaultFootnoteBackLabel`][api-default-footnote-back-label], +[`defaultHandlers`][api-default-handlers], and +[`toHast`][api-to-hast]. +There is no default export. + +### `defaultFootnoteBackContent(referenceIndex, rereferenceIndex)` + +Generate the default content that GitHub uses on backreferences. + +###### Parameters + +* `referenceIndex` (`number`) + — index of the definition in the order that they are first referenced, + 0-indexed +* `rereferenceIndex` (`number`) + — index of calls to the same definition, 0-indexed + +###### Returns + +Content (`Array`). + +### `defaultFootnoteBackLabel(referenceIndex, rereferenceIndex)` + +Generate the default label that GitHub uses on backreferences. + +###### Parameters + +* `referenceIndex` (`number`) + — index of the definition in the order that they are first referenced, + 0-indexed +* `rereferenceIndex` (`number`) + — index of calls to the same definition, 0-indexed + +###### Returns + +Label (`string`). + +### `defaultHandlers` + +Default handlers for nodes ([`Handlers`][api-handlers]). + +### `toHast(tree[, options])` + +Transform mdast to hast. + +###### Parameters + +* `tree` ([`MdastNode`][mdast-node]) + — mdast tree +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +hast tree ([`HastNode`][hast-node]). + +##### Notes + +###### HTML + +Raw HTML is available in mdast as [`html`][mdast-html] nodes and can be embedded +in hast as semistandard `raw` nodes. +Most utilities ignore `raw` nodes but two notable ones don’t: + +* [`hast-util-to-html`][hast-util-to-html] also has an option + `allowDangerousHtml` which will output the raw HTML. + This is typically discouraged as noted by the option name but is useful if + you completely trust authors +* [`hast-util-raw`][hast-util-raw] can handle the raw embedded HTML strings by + parsing them into standard hast nodes (`element`, `text`, etc). + This is a heavy task as it needs a full HTML parser, but it is the only way + to support untrusted content + +###### Footnotes + +Many options supported here relate to footnotes. +Footnotes are not specified by CommonMark, which we follow by default. +They are supported by GitHub, so footnotes can be enabled in markdown with +[`mdast-util-gfm`][mdast-util-gfm]. + +The options `footnoteBackLabel` and `footnoteLabel` define natural language +that explains footnotes, which is hidden for sighted users but shown to +assistive technology. +When your page is not in English, you must define translated values. + +Back references use ARIA attributes, but the section label itself uses a +heading that is hidden with an `sr-only` class. +To show it to sighted users, define different attributes in +`footnoteLabelProperties`. + +###### Clobbering + +Footnotes introduces a problem, as it links footnote calls to footnote +definitions on the page through `id` attributes generated from user content, +which results in DOM clobbering. + +DOM clobbering is this: + +```html +

+ +``` + +Elements by their ID are made available by browsers on the `window` object, +which is a security risk. +Using a prefix solves this problem. + +More information on how to handle clobbering and the prefix is explained in +[Example: headings (DOM clobbering) in `rehype-sanitize`][clobber-example]. + +###### Unknown nodes + +Unknown nodes are nodes with a type that isn’t in `handlers` or `passThrough`. +The default behavior for unknown nodes is: + +* when the node has a `value` (and doesn’t have `data.hName`, + `data.hProperties`, or `data.hChildren`, see later), create a hast `text` + node +* otherwise, create a `
` element (which could be changed with + `data.hName`), with its children mapped from mdast to hast as well + +This behavior can be changed by passing an `unknownHandler`. + +### `FootnoteBackContentTemplate` + +Generate content for the backreference dynamically. + +For the following markdown: + +```markdown +Alpha[^micromark], bravo[^micromark], and charlie[^remark]. + +[^remark]: things about remark +[^micromark]: things about micromark +``` + +This function will be called with: + +* `0` and `0` for the backreference from `things about micromark` to + `alpha`, as it is the first used definition, and the first call to it +* `0` and `1` for the backreference from `things about micromark` to + `bravo`, as it is the first used definition, and the second call to it +* `1` and `0` for the backreference from `things about remark` to + `charlie`, as it is the second used definition + +###### Parameters + +* `referenceIndex` (`number`) + — index of the definition in the order that they are first referenced, + 0-indexed +* `rereferenceIndex` (`number`) + — index of calls to the same definition, 0-indexed + +###### Returns + +Content for the backreference when linking back from definitions to their +reference (`Array`, `ElementContent`, or `string`). + +### `FootnoteBackLabelTemplate` + +Generate a back label dynamically. + +For the following markdown: + +```markdown +Alpha[^micromark], bravo[^micromark], and charlie[^remark]. + +[^remark]: things about remark +[^micromark]: things about micromark +``` + +This function will be called with: + +* `0` and `0` for the backreference from `things about micromark` to + `alpha`, as it is the first used definition, and the first call to it +* `0` and `1` for the backreference from `things about micromark` to + `bravo`, as it is the first used definition, and the second call to it +* `1` and `0` for the backreference from `things about remark` to + `charlie`, as it is the second used definition + +###### Parameters + +* `referenceIndex` (`number`) + — index of the definition in the order that they are first referenced, + 0-indexed +* `rereferenceIndex` (`number`) + — index of calls to the same definition, 0-indexed + +###### Returns + +Back label to use when linking back from definitions to their reference +(`string`). + +### `Handler` + +Handle a node (TypeScript type). + +###### Parameters + +* `state` ([`State`][api-state]) + — info passed around +* `node` ([`MdastNode`][mdast-node]) + — node to handle +* `parent` ([`MdastNode | undefined`][mdast-node]) + — parent of `node` + +###### Returns + +Result ([`Array | HastNode | undefined`][hast-node]). + +### `Handlers` + +Handle nodes (TypeScript type). + +###### Type + +```ts +type Handlers = Partial> +``` + +### `Options` + +Configuration (TypeScript type). + +###### Fields + +* `allowDangerousHtml` (`boolean`, default: `false`) + — whether to persist raw HTML in markdown in the hast tree +* `clobberPrefix` (`string`, default: `'user-content-'`) + — prefix to use before the `id` property on footnotes to prevent them from + *clobbering* +* `file` ([`VFile`][vfile], optional) + — corresponding virtual file representing the input document +* `footnoteBackContent` + ([`FootnoteBackContentTemplate`][api-footnote-back-content-template] + or `string`, default: + [`defaultFootnoteBackContent`][api-default-footnote-back-content]) + — content of the backreference back to references +* `footnoteBackLabel` + ([`FootnoteBackLabelTemplate`][api-footnote-back-label-template] + or `string`, default: + [`defaultFootnoteBackLabel`][api-default-footnote-back-label]) + — label to describe the backreference back to references +* `footnoteLabel` (`string`, default: `'Footnotes'`) + — label to use for the footnotes section (affects screen readers) +* `footnoteLabelProperties` + ([`Properties`][properties], default: `{className: ['sr-only']}`) + — properties to use on the footnote label + (note that `id: 'footnote-label'` is always added as footnote calls use it + with `aria-describedby` to provide an accessible label) +* `footnoteLabelTagName` (`string`, default: `h2`) + — tag name to use for the footnote label +* `handlers` ([`Handlers`][api-handlers], optional) + — extra handlers for nodes +* `passThrough` (`Array`, optional) + — list of custom mdast node types to pass through (keep) in hast (note that + the node itself is passed, but eventual children are transformed) +* `unknownHandler` ([`Handler`][api-handler], optional) + — handle all unknown nodes + +### `Raw` + +Raw string of HTML embedded into HTML AST (TypeScript type). + +###### Type + +```ts +import type {Data, Literal} from 'hast' + +interface Raw extends Literal { + type: 'raw' + data?: RawData | undefined +} + +interface RawData extends Data {} +``` + +### `State` + +Info passed around about the current state (TypeScript type). + +###### Fields + +* `all` (`(node: MdastNode) => Array`) + — transform the children of an mdast parent to hast +* `applyData` (`(from: MdastNode, to: Type) => Type | HastElement`) + — honor the `data` of `from` and maybe generate an element instead of `to` +* `definitionById` (`Map`) + — definitions by their uppercased identifier +* `footnoteById` (`Map`) + — footnote definitions by their uppercased identifier +* `footnoteCounts` (`Map`) + — counts for how often the same footnote was called +* `footnoteOrder` (`Array`) + — identifiers of order when footnote calls first appear in tree order +* `handlers` ([`Handlers`][api-handlers]) + — applied node handlers +* `one` (`(node: MdastNode, parent: MdastNode | undefined) => HastNode | Array | undefined`) + — transform an mdast node to hast +* `options` ([`Options`][api-options]) + — configuration +* `patch` (`(from: MdastNode, to: HastNode) => undefined`) +* `wrap` (`(nodes: Array, loose?: boolean) => Array`) + — wrap `nodes` with line endings between each node, adds initial/final line + endings when `loose` + +## Examples + +### Example: supporting HTML in markdown naïvely + +If you completely trust authors (or plugins) and want to allow them to HTML *in* +markdown, and the last utility has an `allowDangerousHtml` option as well (such +as `hast-util-to-html`) you can pass `allowDangerousHtml` to this utility +(`mdast-util-to-hast`): + +```js +import {fromMarkdown} from 'mdast-util-from-markdown' +import {toHast} from 'mdast-util-to-hast' +import {toHtml} from 'hast-util-to-html' + +const markdown = 'It works! ' +const mdast = fromMarkdown(markdown) +const hast = toHast(mdast, {allowDangerousHtml: true}) +const html = toHtml(hast, {allowDangerousHtml: true}) + +console.log(html) +``` + +…now running `node example.js` yields: + +```html +

It works!

+``` + +> ⚠️ **Danger**: observe that the XSS attack through the `onerror` attribute +> is still present. + +### Example: supporting HTML in markdown properly + +If you do not trust the authors of the input markdown, or if you want to make +sure that further utilities can see HTML embedded in markdown, use +[`hast-util-raw`][hast-util-raw]. +The following example passes `allowDangerousHtml` to this utility +(`mdast-util-to-hast`), then turns the raw embedded HTML into proper HTML nodes +(`hast-util-raw`), and finally sanitizes the HTML by only allowing safe things +(`hast-util-sanitize`): + +```js +import {raw} from 'hast-util-raw' +import {sanitize} from 'hast-util-sanitize' +import {toHtml} from 'hast-util-to-html' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {toHast} from 'mdast-util-to-hast' + +const markdown = 'It works! ' +const mdast = fromMarkdown(markdown) +const hast = raw(toHast(mdast, {allowDangerousHtml: true})) +const safeHast = sanitize(hast) +const html = toHtml(safeHast) + +console.log(html) +``` + +…now running `node example.js` yields: + +```html +

It works!

+``` + +> 👉 **Note**: observe that the XSS attack through the `onerror` attribute +> is no longer present. + +### Example: footnotes in languages other than English + +If you know that the markdown is authored in a language other than English, +and you’re using `micromark-extension-gfm` and `mdast-util-gfm` to match how +GitHub renders markdown, and you know that footnotes are (or can?) be used, you +should translate the labels associated with them. + +Let’s first set the stage: + +```js +import {toHtml} from 'hast-util-to-html' +import {gfm} from 'micromark-extension-gfm' +import {fromMarkdown} from 'mdast-util-from-markdown' +import {gfmFromMarkdown} from 'mdast-util-gfm' +import {toHast} from 'mdast-util-to-hast' + +const markdown = 'Bonjour[^1]\n\n[^1]: Monde!' +const mdast = fromMarkdown(markdown, { + extensions: [gfm()], + mdastExtensions: [gfmFromMarkdown()] +}) +const hast = toHast(mdast) +const html = toHtml(hast) + +console.log(html) +``` + +…now running `node example.js` yields: + +```html +

Bonjour1

+

Footnotes

+
    +
  1. +

    Monde! ↩

    +
  2. +
+
+``` + +This is a mix of English and French that screen readers can’t handle nicely. +Let’s say our program does know that the markdown is in French. +In that case, it’s important to translate and define the labels relating to +footnotes so that screen reader users can properly pronounce the page: + +```diff +@@ -9,7 +9,16 @@ const mdast = fromMarkdown(markdown, { + extensions: [gfm()], + mdastExtensions: [gfmFromMarkdown()] + }) +-const hast = toHast(mdast) ++const hast = toHast(mdast, { ++ footnoteLabel: 'Notes de bas de page', ++ footnoteBackLabel(referenceIndex, rereferenceIndex) { ++ return ( ++ 'Retour à la référence ' + ++ (referenceIndex + 1) + ++ (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') ++ ) ++ } ++}) + const html = toHtml(hast) + + console.log(html) +``` + +…now running `node example.js` with the above patch applied yields: + +```diff +@@ -1,8 +1,8 @@ +

Bonjour1

+-

Footnotes

++

Notes de bas de page

+
    +
  1. +-

    Monde! ↩

    ++

    Monde! ↩

    +
  2. +
+
+``` + +### Example: supporting custom nodes + +This project supports CommonMark and the GFM constructs (footnotes, +strikethrough, tables) and the frontmatter constructs YAML and TOML. +Support can be extended to other constructs in two ways: a) with handlers, b) +through fields on nodes. + +For example, when we represent a mark element in markdown and want to turn it +into a `` element in HTML, we can use a handler: + +```js +import {toHtml} from 'hast-util-to-html' +import {toHast} from 'mdast-util-to-hast' + +const mdast = { + type: 'paragraph', + children: [{type: 'mark', children: [{type: 'text', value: 'x'}]}] +} + +const hast = toHast(mdast, { + handlers: { + mark(state, node) { + return { + type: 'element', + tagName: 'mark', + properties: {}, + children: state.all(node) + } + } + } +}) + +console.log(toHtml(hast)) +``` + +We can do the same through certain fields on nodes: + +```js +import {toHtml} from 'hast-util-to-html' +import {toHast} from 'mdast-util-to-hast' + +const mdast = { + type: 'paragraph', + children: [ + { + type: 'mark', + children: [{type: 'text', value: 'x'}], + data: {hName: 'mark'} + } + ] +} + +console.log(toHtml(toHast(mdast))) +``` + +## Algorithm + +This project by default handles CommonMark, GFM (footnotes, strikethrough, +tables) and common frontmatter (YAML, TOML). + +Existing handlers can be overwritten and handlers for more nodes can be added. +It’s also possible to define how mdast is turned into hast through fields on +nodes. + +### Default handling + +The following table gives insight into what input turns into what output: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mdast nodemarkdown examplehast nodehtml example
+ +[`blockquote`](https://github.com/syntax-tree/mdast#blockquote) + + + +```markdown +> A greater than… +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`blockquote`) + + + +```html +
+

A greater than…

+
+``` + +
+ +[`break`](https://github.com/syntax-tree/mdast#break) + + + +```markdown +A backslash\ +before a line break… +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`br`) + + + +```html +

A backslash
+before a line break…

+``` + +
+ +[`code`](https://github.com/syntax-tree/mdast#code) + + + +````markdown +```js +backtick.fences('for blocks') +``` +```` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`pre` and `code`) + + + +```html +
backtick.fences('for blocks')
+
+``` + +
+ +[`delete`](https://github.com/syntax-tree/mdast#delete) (GFM) + + + +```markdown +Two ~~tildes~~ for delete. +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`del`) + + + +```html +

Two tildes for delete.

+``` + +
+ +[`emphasis`](https://github.com/syntax-tree/mdast#emphasis) + + + +```markdown +Some *asterisks* for emphasis. +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`em`) + + + +```html +

Some asterisks for emphasis.

+``` + +
+ +[`footnoteReference`](https://github.com/syntax-tree/mdast#footnotereference), +[`footnoteDefinition`](https://github.com/syntax-tree/mdast#footnotedefinition) +(GFM) + + + +```markdown +With a [^caret]. + +[^caret]: Stuff +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`section`, `sup`, `a`) + + + +```html +

With a 1.

… +``` + +
+ +[`heading`](https://github.com/syntax-tree/mdast#heading) + + + +```markdown +# One number sign… +###### Six number signs… +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`h1`…`h6`) + + + +```html +

One number sign…

+
Six number signs…
+``` + +
+ +[`html`](https://github.com/syntax-tree/mdast#html) + + + +```html +CMD+S +``` + + + +Nothing (default), `raw` (when `allowDangerousHtml: true`) + + + +n/a + +
+ +[`image`](https://github.com/syntax-tree/mdast#image) + + + +```markdown +![Alt text](/logo.png "title") +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`img`) + + + +```html +

Alt text

+``` + +
+ +[`imageReference`](https://github.com/syntax-tree/mdast#imagereference), +[`definition`](https://github.com/syntax-tree/mdast#definition) + + + +```markdown +![Alt text][logo] + +[logo]: /logo.png "title" +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`img`) + + + +```html +

Alt text

+``` + +
+ +[`inlineCode`](https://github.com/syntax-tree/mdast#inlinecode) + + + +```markdown +Some `backticks` for inline code. +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`code`) + + + +```html +

Some backticks for inline code.

+``` + +
+ +[`link`](https://github.com/syntax-tree/mdast#link) + + + +```markdown +[Example](https://example.com "title") +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`a`) + + + +```html +

Example

+``` + +
+ +[`linkReference`](https://github.com/syntax-tree/mdast#linkreference), +[`definition`](https://github.com/syntax-tree/mdast#definition) + + + +```markdown +[Example][] + +[example]: https://example.com "title" +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`a`) + + + +```html +

Example

+``` + +
+ +[`list`](https://github.com/syntax-tree/mdast#list), +[`listItem`](https://github.com/syntax-tree/mdast#listitem) + + + +```markdown +* asterisks for unordered items + +1. decimals and a dot for ordered items +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`li` and `ol` or `ul`) + + + +```html +
    +
  • asterisks for unordered items
  • +
+
    +
  1. decimals and a dot for ordered items
  2. +
+``` + +
+ +[`paragraph`](https://github.com/syntax-tree/mdast#paragraph) + + + +```markdown +Just some text… +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`p`) + + + +```html +

Just some text…

+``` + +
+ +[`root`](https://github.com/syntax-tree/mdast#root) + + + +```markdown +Anything! +``` + + + +[`root`](https://github.com/syntax-tree/hast#root) + + + +```html +

Anything!

+``` + +
+ +[`strong`](https://github.com/syntax-tree/mdast#strong) + + + +```markdown +Two **asterisks** for strong. +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`strong`) + + + +```html +

Two asterisks for strong.

+``` + +
+ +[`text`](https://github.com/syntax-tree/mdast#text) + + + +```markdown +Anything! +``` + + + +[`text`](https://github.com/syntax-tree/hast#text) + + + +```html +

Anything!

+``` + +
+ +[`table`](https://github.com/syntax-tree/mdast#table), +[`tableRow`](https://github.com/syntax-tree/mdast#tablerow), +[`tableCell`](https://github.com/syntax-tree/mdast#tablecell) + + + +```markdown +| Pipes | +| ----- | +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`table`, `thead`, +`tbody`, `tr`, `td`, `th`) + + + +```html + + + + + + +
Pipes
+``` + +
+ +[`thematicBreak`](https://github.com/syntax-tree/mdast#thematicbreak) + + + +```markdown +Three asterisks for a thematic break: + +*** +``` + + + +[`element`](https://github.com/syntax-tree/hast#element) (`hr`) + + + +```html +

Three asterisks for a thematic break:

+
+``` + +
+ +`toml` (frontmatter) + + + +```markdown ++++ +fenced = true ++++ +``` + + + +Nothing + + + +n/a + +
+ +[`yaml`](https://github.com/syntax-tree/mdast#yaml) (frontmatter) + + + +```markdown +--- +fenced: yes +--- +``` + + + +Nothing + + + +n/a + +
+ +> 👉 **Note**: GFM prescribes that the obsolete `align` attribute on `td` and +> `th` elements is used. +> To use `style` attributes instead of obsolete features, combine this utility +> with [`@mapbox/hast-util-table-cell-style`][hast-util-table-cell-style]. + +> 🧑‍🏫 **Info**: this project is concerned with turning one syntax tree into +> another. +> It does not deal with markdown syntax or HTML syntax. +> The preceding examples are illustrative rather than authoritative or +> exhaustive. + +### Fields on nodes + +A frequent problem arises when having to turn one syntax tree into another. +As the original tree (in this case, mdast for markdown) is in some cases +limited compared to the destination (in this case, hast for HTML) tree, +is it possible to provide more info in the original to define what the +result will be in the destination? +This is possible by defining data on mdast nodes, which this utility will read +as instructions on what hast nodes to create. + +An example is math, which is a nonstandard markdown extension, that this utility +doesn’t understand. +To solve this, `mdast-util-math` defines instructions on mdast nodes that this +plugin does understand because they define a certain hast structure. + +The following fields can be used: + +* `node.data.hName` — define the element’s tag name +* `node.data.hProperties` — define extra properties to use +* `node.data.hChildren` — define hast children to use + +###### `hName` + +`node.data.hName` sets the tag name of an element. +The following [mdast][]: + +```js +{ + type: 'strong', + data: {hName: 'b'}, + children: [{type: 'text', value: 'Alpha'}] +} +``` + +…yields ([hast][]): + +```js +{ + type: 'element', + tagName: 'b', + properties: {}, + children: [{type: 'text', value: 'Alpha'}] +} +``` + +###### `hProperties` + +`node.data.hProperties` sets the properties of an element. +The following [mdast][]: + +```js +{ + type: 'image', + src: 'circle.svg', + alt: 'Big red circle on a black background', + data: {hProperties: {className: ['responsive']}} +} +``` + +…yields ([hast][]): + +```js +{ + type: 'element', + tagName: 'img', + properties: { + src: 'circle.svg', + alt: 'Big red circle on a black background', + className: ['responsive'] + }, + children: [] +} +``` + +###### `hChildren` + +`node.data.hChildren` sets the children of an element. +The following [mdast][]: + +```js +{ + type: 'code', + lang: 'js', + data: { + hChildren: [ + { + type: 'element', + tagName: 'span', + properties: {className: ['hljs-meta']}, + children: [{type: 'text', value: '"use strict"'}] + }, + {type: 'text', value: ';'} + ] + }, + value: '"use strict";' +} +``` + +…yields ([hast][]): + +```js +{ + type: 'element', + tagName: 'pre', + properties: {}, + children: [{ + type: 'element', + tagName: 'code', + properties: {className: ['language-js']}, + children: [ + { + type: 'element', + tagName: 'span', + properties: {className: ['hljs-meta']}, + children: [{type: 'text', value: '"use strict"'}] + }, + {type: 'text', value: ';'} + ] + }] +} +``` + +> 👉 **Note**: the `pre` and `language-js` class are normal `mdast-util-to-hast` +> functionality. + +## CSS + +Assuming you know how to use (semantic) HTML and CSS, then it should generally +be straightforward to style the HTML produced by this plugin. +With CSS, you can get creative and style the results as you please. + +Some semistandard features, notably GFMs tasklists and footnotes, generate HTML +that be unintuitive, as it matches exactly what GitHub produces for their +website. +There is a project, [`sindresorhus/github-markdown-css`][github-markdown-css], +that exposes the stylesheet that GitHub uses for rendered markdown, which might +either be inspirational for more complex features, or can be used as-is to +exactly match how GitHub styles rendered markdown. + +The following CSS is needed to make footnotes look a bit like GitHub: + +```css +/* Style the footnotes section. */ +.footnotes { + font-size: smaller; + color: #8b949e; + border-top: 1px solid #30363d; +} + +/* Hide the section label for visual users. */ +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0, 0, 0, 0); + word-wrap: normal; + border: 0; +} + +/* Place `[` and `]` around footnote calls. */ +[data-footnote-ref]::before { + content: '['; +} + +[data-footnote-ref]::after { + content: ']'; +} +``` + +## Syntax tree + +The following interfaces are added to **[hast][]** by this utility. + +### Nodes + +#### `Raw` + +```idl +interface Raw <: Literal { + type: 'raw' +} +``` + +**Raw** (**[Literal][dfn-literal]**) represents a string if raw HTML inside +hast. +Raw nodes are typically ignored but are handled by +[`hast-util-to-html`][hast-util-to-html] and [`hast-util-raw`][hast-util-raw]. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the +[`FootnoteBackContentTemplate`][api-footnote-back-content-template], +[`FootnoteBackLabelTemplate`][api-footnote-back-label-template], +[`Handler`][api-handler], +[`Handlers`][api-handlers], +[`Options`][api-options], +[`Raw`][api-raw], and +[`State`][api-state] types. + +It also registers the `Raw` node type with `@types/hast`. +If you’re working with the syntax tree (and you pass +`allowDangerousHtml: true`), make sure to import this utility somewhere in your +types, as that registers the new node type in the tree. + +```js +/** + * @import {Root} from 'hast' + * @import {} from 'mdast-util-to-hast' + */ + +import {visit} from 'unist-util-visit' + +/** @type {Root} */ +const tree = { /* … */ } + +visit(tree, function (node) { + // `node` can now be `raw`. +}) +``` + +Finally, it also registers the `hChildren`, `hName`, and `hProperties` fields +on `Data` of `@types/mdast`. +If you’re working with the syntax tree, make sure to import this utility +somewhere in your types, as that registers the data fields in the tree. + +```js +/** + * @import {Root} from 'hast' + * @import {} from 'mdast-util-to-hast' + */ + +import {visit} from 'unist-util-visit' + +/** @type {Root} */ +const tree = { /* … */ } + +console.log(tree.data?.hName) // Types as `string | undefined`. +``` + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `mdast-util-to-hast@^13`, +compatible with Node.js 16. + +## Security + +Use of `mdast-util-to-hast` can open you up to a +[cross-site scripting (XSS)][xss] attack. +Embedded hast properties (`hName`, `hProperties`, `hChildren`), custom handlers, +and the `allowDangerousHtml` option all provide openings. + +The following example shows how a script is injected where a benign code block +is expected with embedded hast properties: + +```js +const code = {type: 'code', value: 'alert(1)'} + +code.data = {hName: 'script'} +``` + +Yields: + +```html + +``` + +The following example shows how an image is changed to fail loading and +therefore run code in a browser. + +```js +const image = {type: 'image', url: 'existing.png'} + +image.data = {hProperties: {src: 'missing', onError: 'alert(2)'}} +``` + +Yields: + +```html + +``` + +The following example shows the default handling of embedded HTML: + +```markdown +# Hello + + +``` + +Yields: + +```html +

Hello

+``` + +Passing `allowDangerousHtml: true` to `mdast-util-to-hast` is typically still +not enough to run unsafe code: + +```html +

Hello

+<script>alert(3)</script> +``` + +If `allowDangerousHtml: true` is also given to `hast-util-to-html` (or +`rehype-stringify`), the unsafe code runs: + +```html +

Hello

+ +``` + +Use [`hast-util-sanitize`][hast-util-sanitize] to make the hast tree safe. + +## Related + +* [`hast-util-to-mdast`](https://github.com/syntax-tree/hast-util-to-mdast) + — transform hast to mdast +* [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast) + — transform hast to xast +* [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize) + — sanitize hast nodes + +## Contribute + +See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/syntax-tree/mdast-util-to-hast/workflows/main/badge.svg + +[build]: https://github.com/syntax-tree/mdast-util-to-hast/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-to-hast.svg + +[coverage]: https://codecov.io/github/syntax-tree/mdast-util-to-hast + +[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-to-hast.svg + +[downloads]: https://www.npmjs.com/package/mdast-util-to-hast + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-to-hast + +[size]: https://bundlejs.com/?q=mdast-util-to-hast + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/syntax-tree/unist/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[license]: license + +[author]: https://wooorm.com + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md + +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md + +[mdast]: https://github.com/syntax-tree/mdast + +[mdast-node]: https://github.com/syntax-tree/mdast#nodes + +[mdast-html]: https://github.com/syntax-tree/mdast#html + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[hast]: https://github.com/syntax-tree/hast + +[hast-node]: https://github.com/syntax-tree/hast#nodes + +[properties]: https://github.com/syntax-tree/hast#properties + +[hast-util-table-cell-style]: https://github.com/mapbox/hast-util-table-cell-style + +[hast-util-to-mdast]: https://github.com/syntax-tree/hast-util-to-mdast + +[hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html + +[hast-util-raw]: https://github.com/syntax-tree/hast-util-raw + +[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize + +[remark-rehype]: https://github.com/remarkjs/remark-rehype + +[vfile]: https://github.com/vfile/vfile + +[clobber-example]: https://github.com/rehypejs/rehype-sanitize#example-headings-dom-clobbering + +[github-markdown-css]: https://github.com/sindresorhus/github-markdown-css + +[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting + +[dfn-literal]: https://github.com/syntax-tree/hast#literal + +[api-default-footnote-back-content]: #defaultfootnotebackcontentreferenceindex-rereferenceindex + +[api-default-footnote-back-label]: #defaultfootnotebacklabelreferenceindex-rereferenceindex + +[api-default-handlers]: #defaulthandlers + +[api-footnote-back-content-template]: #footnotebackcontenttemplate + +[api-footnote-back-label-template]: #footnotebacklabeltemplate + +[api-handler]: #handler + +[api-handlers]: #handlers + +[api-options]: #options + +[api-raw]: #raw + +[api-state]: #state + +[api-to-hast]: #tohasttree-options diff --git a/node_modules/mdast-util-to-markdown/index.d.ts b/node_modules/mdast-util-to-markdown/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..5a07a51779e45752303c6e40c3c8c3b2f49da40b --- /dev/null +++ b/node_modules/mdast-util-to-markdown/index.d.ts @@ -0,0 +1,16 @@ +export type { + ConstructNameMap, + ConstructName, + Handle, + Handlers, + Info, + Join, + Map, + Options, + SafeConfig, + State, + Tracker, + Unsafe +} from './lib/types.js' +export {toMarkdown} from './lib/index.js' +export {handle as defaultHandlers} from './lib/handle/index.js' diff --git a/node_modules/mdast-util-to-markdown/index.js b/node_modules/mdast-util-to-markdown/index.js new file mode 100644 index 0000000000000000000000000000000000000000..24a6ef3c24a6cca2baa4acdfaddea91093c49d54 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/index.js @@ -0,0 +1,3 @@ +// Note: extra types exposed from `index.d.ts`. +export {toMarkdown} from './lib/index.js' +export {handle as defaultHandlers} from './lib/handle/index.js' diff --git a/node_modules/mdast-util-to-markdown/lib/configure.d.ts b/node_modules/mdast-util-to-markdown/lib/configure.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa7253e38d42ba203e4c3c2d75ad5abaa6396551 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/configure.d.ts @@ -0,0 +1,9 @@ +/** + * @param {State} base + * @param {Options} extension + * @returns {State} + */ +export function configure(base: State, extension: Options): State; +import type { State } from './types.js'; +import type { Options } from './types.js'; +//# sourceMappingURL=configure.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/configure.d.ts.map b/node_modules/mdast-util-to-markdown/lib/configure.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..0fabd9f27011bf73b948cc563eaa094f066c3818 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/configure.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["configure.js"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,gCAJW,KAAK,aACL,OAAO,GACL,KAAK,CA+CjB;2BAvDgC,YAAY;6BAAZ,YAAY"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/configure.js b/node_modules/mdast-util-to-markdown/lib/configure.js new file mode 100644 index 0000000000000000000000000000000000000000..0442e99c55038a04e031757e040015f4ea4fb9db --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/configure.js @@ -0,0 +1,79 @@ +/** + * @import {Options, State} from './types.js' + */ + +const own = {}.hasOwnProperty + +/** + * @param {State} base + * @param {Options} extension + * @returns {State} + */ +export function configure(base, extension) { + let index = -1 + /** @type {keyof Options} */ + let key + + // First do subextensions. + if (extension.extensions) { + while (++index < extension.extensions.length) { + configure(base, extension.extensions[index]) + } + } + + for (key in extension) { + if (own.call(extension, key)) { + switch (key) { + case 'extensions': { + // Empty. + break + } + + /* c8 ignore next 4 */ + case 'unsafe': { + list(base[key], extension[key]) + break + } + + case 'join': { + list(base[key], extension[key]) + break + } + + case 'handlers': { + map(base[key], extension[key]) + break + } + + default: { + // @ts-expect-error: matches. + base.options[key] = extension[key] + } + } + } + } + + return base +} + +/** + * @template T + * @param {Array} left + * @param {Array | null | undefined} right + */ +function list(left, right) { + if (right) { + left.push(...right) + } +} + +/** + * @template T + * @param {Record} left + * @param {Record | null | undefined} right + */ +function map(left, right) { + if (right) { + Object.assign(left, right) + } +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1a933651eb6920c31d0da26afd759c52c5488e79 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts @@ -0,0 +1,17 @@ +/** + * @import {Blockquote, Parents} from 'mdast' + * @import {Info, Map, State} from 'mdast-util-to-markdown' + */ +/** + * @param {Blockquote} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function blockquote(node: Blockquote, _: Parents | undefined, state: State, info: Info): string; +import type { Blockquote } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +//# sourceMappingURL=blockquote.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..3a2337d8263f10a2f260f245681adabf6048fb69 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["blockquote.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,iCANW,UAAU,KACV,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CAalB;gCAtBqC,OAAO;6BAAP,OAAO;2BACV,wBAAwB;0BAAxB,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/blockquote.js b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.js new file mode 100644 index 0000000000000000000000000000000000000000..6d9bfe17428ef668cf8c1679519498a3d707a465 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/blockquote.js @@ -0,0 +1,29 @@ +/** + * @import {Blockquote, Parents} from 'mdast' + * @import {Info, Map, State} from 'mdast-util-to-markdown' + */ + +/** + * @param {Blockquote} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function blockquote(node, _, state, info) { + const exit = state.enter('blockquote') + const tracker = state.createTracker(info) + tracker.move('> ') + tracker.shift(2) + const value = state.indentLines( + state.containerFlow(node, tracker.current()), + map + ) + exit() + return value +} + +/** @type {Map} */ +function map(line, _, blank) { + return '>' + (blank ? '' : ' ') + line +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c15d013d23d11d800dd592093cf05ad409c38e6 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts @@ -0,0 +1,13 @@ +/** + * @param {Break} _ + * @param {Parents | undefined} _1 + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function hardBreak(_: Break, _1: Parents | undefined, state: State, info: Info): string; +import type { Break } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +//# sourceMappingURL=break.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..1ab4fa9393241b081acce3d0cadd460f33a78544 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/break.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"break.d.ts","sourceRoot":"","sources":["break.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,6BANW,KAAK,MACL,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CAiBlB;2BA5BgC,OAAO;6BAAP,OAAO;2BACV,wBAAwB;0BAAxB,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/break.js b/node_modules/mdast-util-to-markdown/lib/handle/break.js new file mode 100644 index 0000000000000000000000000000000000000000..f8be4f87b7a7bbd17c7e809734e2b172e1601cb6 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/break.js @@ -0,0 +1,30 @@ +/** + * @import {Break, Parents} from 'mdast' + * @import {Info, State} from 'mdast-util-to-markdown' + */ + +import {patternInScope} from '../util/pattern-in-scope.js' + +/** + * @param {Break} _ + * @param {Parents | undefined} _1 + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function hardBreak(_, _1, state, info) { + let index = -1 + + while (++index < state.unsafe.length) { + // If we can’t put eols in this construct (setext headings, tables), use a + // space instead. + if ( + state.unsafe[index].character === '\n' && + patternInScope(state.stack, state.unsafe[index]) + ) { + return /[ \t]/.test(info.before) ? '' : ' ' + } + } + + return '\\\n' +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2610b7ea8dd47c9161fd92626549781c30a7559c --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts @@ -0,0 +1,13 @@ +/** + * @param {Code} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function code(node: Code, _: Parents | undefined, state: State, info: Info): string; +import type { Code } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +//# sourceMappingURL=code.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b7a1d89696b2497b4dba3b809eef696a67beb903 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/code.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["code.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,2BANW,IAAI,KACJ,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CAuDlB;0BAnE+B,OAAO;6BAAP,OAAO;2BADJ,wBAAwB;0BAAxB,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/code.js b/node_modules/mdast-util-to-markdown/lib/handle/code.js new file mode 100644 index 0000000000000000000000000000000000000000..6807cb1bc34e742e993e3a27364408a7ca1ee5a5 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/code.js @@ -0,0 +1,75 @@ +/** + * @import {Info, Map, State} from 'mdast-util-to-markdown' + * @import {Code, Parents} from 'mdast' + */ + +import {longestStreak} from 'longest-streak' +import {formatCodeAsIndented} from '../util/format-code-as-indented.js' +import {checkFence} from '../util/check-fence.js' + +/** + * @param {Code} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function code(node, _, state, info) { + const marker = checkFence(state) + const raw = node.value || '' + const suffix = marker === '`' ? 'GraveAccent' : 'Tilde' + + if (formatCodeAsIndented(node, state)) { + const exit = state.enter('codeIndented') + const value = state.indentLines(raw, map) + exit() + return value + } + + const tracker = state.createTracker(info) + const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3)) + const exit = state.enter('codeFenced') + let value = tracker.move(sequence) + + if (node.lang) { + const subexit = state.enter(`codeFencedLang${suffix}`) + value += tracker.move( + state.safe(node.lang, { + before: value, + after: ' ', + encode: ['`'], + ...tracker.current() + }) + ) + subexit() + } + + if (node.lang && node.meta) { + const subexit = state.enter(`codeFencedMeta${suffix}`) + value += tracker.move(' ') + value += tracker.move( + state.safe(node.meta, { + before: value, + after: '\n', + encode: ['`'], + ...tracker.current() + }) + ) + subexit() + } + + value += tracker.move('\n') + + if (raw) { + value += tracker.move(raw + '\n') + } + + value += tracker.move(sequence) + exit() + return value +} + +/** @type {Map} */ +function map(line, _, blank) { + return (blank ? '' : ' ') + line +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d8fd8d84b55590366d3d1821592579abbcb65da1 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts @@ -0,0 +1,13 @@ +/** + * @param {Definition} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function definition(node: Definition, _: Parents | undefined, state: State, info: Info): string; +import type { Definition } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +//# sourceMappingURL=definition.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..a2b867de209fc46d0efaf82019d5307f8d050db5 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/definition.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["definition.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,iCANW,UAAU,KACV,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CA+DlB;gCAzEqC,OAAO;6BAAP,OAAO;2BADf,wBAAwB;0BAAxB,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/definition.js b/node_modules/mdast-util-to-markdown/lib/handle/definition.js new file mode 100644 index 0000000000000000000000000000000000000000..17518ad3f9f86f9767be63e6860c7390a6c39d20 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/definition.js @@ -0,0 +1,76 @@ +/** + * @import {Info, State} from 'mdast-util-to-markdown' + * @import {Definition, Parents} from 'mdast' + */ + +import {checkQuote} from '../util/check-quote.js' + +/** + * @param {Definition} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function definition(node, _, state, info) { + const quote = checkQuote(state) + const suffix = quote === '"' ? 'Quote' : 'Apostrophe' + const exit = state.enter('definition') + let subexit = state.enter('label') + const tracker = state.createTracker(info) + let value = tracker.move('[') + value += tracker.move( + state.safe(state.associationId(node), { + before: value, + after: ']', + ...tracker.current() + }) + ) + value += tracker.move(']: ') + + subexit() + + if ( + // If there’s no url, or… + !node.url || + // If there are control characters or whitespace. + /[\0- \u007F]/.test(node.url) + ) { + subexit = state.enter('destinationLiteral') + value += tracker.move('<') + value += tracker.move( + state.safe(node.url, {before: value, after: '>', ...tracker.current()}) + ) + value += tracker.move('>') + } else { + // No whitespace, raw is prettier. + subexit = state.enter('destinationRaw') + value += tracker.move( + state.safe(node.url, { + before: value, + after: node.title ? ' ' : '\n', + ...tracker.current() + }) + ) + } + + subexit() + + if (node.title) { + subexit = state.enter(`title${suffix}`) + value += tracker.move(' ' + quote) + value += tracker.move( + state.safe(node.title, { + before: value, + after: quote, + ...tracker.current() + }) + ) + value += tracker.move(quote) + subexit() + } + + exit() + + return value +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3fb034ea447e27dcfdf1116419035fe86f5f3336 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts @@ -0,0 +1,24 @@ +/** + * @param {Emphasis} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function emphasis(node: Emphasis, _: Parents | undefined, state: State, info: Info): string; +export namespace emphasis { + export { emphasisPeek as peek }; +} +import type { Emphasis } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +/** + * @param {Emphasis} _ + * @param {Parents | undefined} _1 + * @param {State} state + * @returns {string} + */ +declare function emphasisPeek(_: Emphasis, _1: Parents | undefined, state: State): string; +export {}; +//# sourceMappingURL=emphasis.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..9af598c351e78b62e05c884d7538578457ac4f15 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["emphasis.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,+BANW,QAAQ,KACR,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CA0ClB;;;;8BAxDmC,OAAO;6BAAP,OAAO;2BADb,wBAAwB;0BAAxB,wBAAwB;AA2DtD;;;;;GAKG;AACH,iCALW,QAAQ,MACR,OAAO,GAAG,SAAS,SACnB,KAAK,GACH,MAAM,CAIlB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/emphasis.js b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.js new file mode 100644 index 0000000000000000000000000000000000000000..92be547459a62ae18f813651b713d31fbc4efbe0 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/emphasis.js @@ -0,0 +1,69 @@ +/** + * @import {Info, State} from 'mdast-util-to-markdown' + * @import {Emphasis, Parents} from 'mdast' + */ + +import {checkEmphasis} from '../util/check-emphasis.js' +import {encodeCharacterReference} from '../util/encode-character-reference.js' +import {encodeInfo} from '../util/encode-info.js' + +emphasis.peek = emphasisPeek + +/** + * @param {Emphasis} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function emphasis(node, _, state, info) { + const marker = checkEmphasis(state) + const exit = state.enter('emphasis') + const tracker = state.createTracker(info) + const before = tracker.move(marker) + + let between = tracker.move( + state.containerPhrasing(node, { + after: marker, + before, + ...tracker.current() + }) + ) + const betweenHead = between.charCodeAt(0) + const open = encodeInfo( + info.before.charCodeAt(info.before.length - 1), + betweenHead, + marker + ) + + if (open.inside) { + between = encodeCharacterReference(betweenHead) + between.slice(1) + } + + const betweenTail = between.charCodeAt(between.length - 1) + const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker) + + if (close.inside) { + between = between.slice(0, -1) + encodeCharacterReference(betweenTail) + } + + const after = tracker.move(marker) + + exit() + + state.attentionEncodeSurroundingInfo = { + after: close.outside, + before: open.outside + } + return before + between + after +} + +/** + * @param {Emphasis} _ + * @param {Parents | undefined} _1 + * @param {State} state + * @returns {string} + */ +function emphasisPeek(_, _1, state) { + return state.options.emphasis || '*' +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d862a309a54ccfc169fe73b5e1dff2267ff7c365 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts @@ -0,0 +1,13 @@ +/** + * @param {Heading} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function heading(node: Heading, _: Parents | undefined, state: State, info: Info): string; +import type { Heading } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +//# sourceMappingURL=heading.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..646efee9a79a235342cc491c864639e8d655acd1 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/heading.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["heading.js"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,8BANW,OAAO,KACP,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CA6DlB;6BAxEkC,OAAO;6BAAP,OAAO;2BADZ,wBAAwB;0BAAxB,wBAAwB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/heading.js b/node_modules/mdast-util-to-markdown/lib/handle/heading.js new file mode 100644 index 0000000000000000000000000000000000000000..e421379f9239f0a5ae5aa93e5438c2b5baefbfad --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/heading.js @@ -0,0 +1,75 @@ +/** + * @import {Info, State} from 'mdast-util-to-markdown' + * @import {Heading, Parents} from 'mdast' + */ + +import {encodeCharacterReference} from '../util/encode-character-reference.js' +import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js' + +/** + * @param {Heading} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function heading(node, _, state, info) { + const rank = Math.max(Math.min(6, node.depth || 1), 1) + const tracker = state.createTracker(info) + + if (formatHeadingAsSetext(node, state)) { + const exit = state.enter('headingSetext') + const subexit = state.enter('phrasing') + const value = state.containerPhrasing(node, { + ...tracker.current(), + before: '\n', + after: '\n' + }) + subexit() + exit() + + return ( + value + + '\n' + + (rank === 1 ? '=' : '-').repeat( + // The whole size… + value.length - + // Minus the position of the character after the last EOL (or + // 0 if there is none)… + (Math.max(value.lastIndexOf('\r'), value.lastIndexOf('\n')) + 1) + ) + ) + } + + const sequence = '#'.repeat(rank) + const exit = state.enter('headingAtx') + const subexit = state.enter('phrasing') + + // Note: for proper tracking, we should reset the output positions when there + // is no content returned, because then the space is not output. + // Practically, in that case, there is no content, so it doesn’t matter that + // we’ve tracked one too many characters. + tracker.move(sequence + ' ') + + let value = state.containerPhrasing(node, { + before: '# ', + after: '\n', + ...tracker.current() + }) + + if (/^[\t ]/.test(value)) { + // To do: what effect has the character reference on tracking? + value = encodeCharacterReference(value.charCodeAt(0)) + value.slice(1) + } + + value = value ? sequence + ' ' + value : sequence + + if (state.options.closeAtx) { + value += ' ' + sequence + } + + subexit() + exit() + + return value +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c46edd692e21d014e13edd1ae28518f91ad625f8 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts @@ -0,0 +1,15 @@ +/** + * @param {Html} node + * @returns {string} + */ +export function html(node: Html): string; +export namespace html { + export { htmlPeek as peek }; +} +import type { Html } from 'mdast'; +/** + * @returns {string} + */ +declare function htmlPeek(): string; +export {}; +//# sourceMappingURL=html.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..774fc77fd49b6c5ae62bbeb2512db1d5004dbac4 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/html.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH,2BAHW,IAAI,GACF,MAAM,CAIlB;;;;0BAXsB,OAAO;AAa9B;;GAEG;AACH,6BAFa,MAAM,CAIlB"} \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/html.js b/node_modules/mdast-util-to-markdown/lib/handle/html.js new file mode 100644 index 0000000000000000000000000000000000000000..d749e6f61e06b0372da63e284349f7fd0a841e35 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/html.js @@ -0,0 +1,20 @@ +/** + * @import {Html} from 'mdast' + */ + +html.peek = htmlPeek + +/** + * @param {Html} node + * @returns {string} + */ +export function html(node) { + return node.value || '' +} + +/** + * @returns {string} + */ +function htmlPeek() { + return '<' +} diff --git a/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts b/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dc1b4ea45346a597677b63d16ac82d03a81e1860 --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts @@ -0,0 +1,21 @@ +/** + * @param {ImageReference} node + * @param {Parents | undefined} _ + * @param {State} state + * @param {Info} info + * @returns {string} + */ +export function imageReference(node: ImageReference, _: Parents | undefined, state: State, info: Info): string; +export namespace imageReference { + export { imageReferencePeek as peek }; +} +import type { ImageReference } from 'mdast'; +import type { Parents } from 'mdast'; +import type { State } from 'mdast-util-to-markdown'; +import type { Info } from 'mdast-util-to-markdown'; +/** + * @returns {string} + */ +declare function imageReferencePeek(): string; +export {}; +//# sourceMappingURL=image-reference.d.ts.map \ No newline at end of file diff --git a/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts.map b/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e44888af5bc9433b5e7a02da135aa09b5afd043b --- /dev/null +++ b/node_modules/mdast-util-to-markdown/lib/handle/image-reference.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"image-reference.d.ts","sourceRoot":"","sources":["image-reference.js"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,qCANW,cAAc,KACd,OAAO,GAAG,SAAS,SACnB,KAAK,QACL,IAAI,GACF,MAAM,CA2ClB;;;;oCArDyC,OAAO;6BAAP,OAAO;2BADnB,wBAAwB;0BAAxB,wBAAwB;AAwDtD;;GAEG;AACH,uCAFa,MAAM,CAIlB"} \ No newline at end of file