diff --git a/dist/index.js b/dist/index.js index ad3311d..93e934c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,314 @@ -import { visit } from 'unist-util-visit'; -import { findAndReplace } from 'mdast-util-find-and-replace'; +// node_modules/unist-util-is/lib/index.js +var convert = ( + // Note: overloads in JSDoc can’t yet use different `@template`s. + /** + * @type {( + * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) & + * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) & + * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate) & + * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) & + * ((test?: Test) => Check) + * )} + */ + /** + * @param {Test} [test] + * @returns {Check} + */ + (function(test) { + if (test === null || test === void 0) { + return ok; + } + if (typeof test === "function") { + return castFactory(test); + } + if (typeof test === "object") { + return Array.isArray(test) ? anyFactory(test) : ( + // Cast because `ReadonlyArray` goes into the above but `isArray` + // narrows to `Array`. + propertiesFactory( + /** @type {Props} */ + test + ) + ); + } + if (typeof test === "string") { + return typeFactory(test); + } + throw new Error("Expected function, string, or object as test"); + }) +); +function anyFactory(tests) { + const checks = []; + let index = -1; + while (++index < tests.length) { + checks[index] = convert(tests[index]); + } + return castFactory(any); + function any(...parameters) { + let index2 = -1; + while (++index2 < checks.length) { + if (checks[index2].apply(this, parameters)) return true; + } + return false; + } +} +function propertiesFactory(check) { + const checkAsRecord = ( + /** @type {Record} */ + check + ); + return castFactory(all); + function all(node) { + const nodeAsRecord = ( + /** @type {Record} */ + /** @type {unknown} */ + node + ); + let key; + for (key in check) { + if (nodeAsRecord[key] !== checkAsRecord[key]) return false; + } + return true; + } +} +function typeFactory(check) { + return castFactory(type); + function type(node) { + return node && node.type === check; + } +} +function castFactory(testFunction) { + return check; + function check(value, index, parent) { + return Boolean( + looksLikeANode(value) && testFunction.call( + this, + value, + typeof index === "number" ? index : void 0, + parent || void 0 + ) + ); + } +} +function ok() { + return true; +} +function looksLikeANode(value) { + return value !== null && typeof value === "object" && "type" in value; +} + +// node_modules/unist-util-visit-parents/lib/color.node.js +function color(d) { + return "\x1B[33m" + d + "\x1B[39m"; +} + +// node_modules/unist-util-visit-parents/lib/index.js +var empty = []; +var CONTINUE = true; +var EXIT = false; +var SKIP = "skip"; +function visitParents(tree, test, visitor, reverse) { + let check; + if (typeof test === "function" && typeof visitor !== "function") { + reverse = visitor; + visitor = test; + } else { + check = test; + } + const is2 = convert(check); + const step = reverse ? -1 : 1; + factory(tree, void 0, [])(); + function factory(node, index, parents) { + const value = ( + /** @type {Record} */ + node && typeof node === "object" ? node : {} + ); + if (typeof value.type === "string") { + const name = ( + // `hast` + typeof value.tagName === "string" ? value.tagName : ( + // `xast` + typeof value.name === "string" ? value.name : void 0 + ) + ); + Object.defineProperty(visit2, "name", { + value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")" + }); + } + return visit2; + function visit2() { + let result = empty; + let subresult; + let offset; + let grandparents; + if (!test || is2(node, index, parents[parents.length - 1] || void 0)) { + result = toResult(visitor(node, parents)); + if (result[0] === EXIT) { + return result; + } + } + if ("children" in node && node.children) { + const nodeAsParent = ( + /** @type {UnistParent} */ + node + ); + if (nodeAsParent.children && result[0] !== SKIP) { + offset = (reverse ? nodeAsParent.children.length : -1) + step; + grandparents = parents.concat(nodeAsParent); + while (offset > -1 && offset < nodeAsParent.children.length) { + const child = nodeAsParent.children[offset]; + subresult = factory(child, offset, grandparents)(); + if (subresult[0] === EXIT) { + return subresult; + } + offset = typeof subresult[1] === "number" ? subresult[1] : offset + step; + } + } + } + return result; + } + } +} +function toResult(value) { + if (Array.isArray(value)) { + return value; + } + if (typeof value === "number") { + return [CONTINUE, value]; + } + return value === null || value === void 0 ? empty : [value]; +} + +// node_modules/unist-util-visit/lib/index.js +function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) { + let reverse; + let test; + let visitor; + { + test = testOrVisitor; + visitor = visitorOrReverse; + reverse = maybeReverse; + } + visitParents(tree, test, overload, reverse); + function overload(node, parents) { + const parent = parents[parents.length - 1]; + const index = parent ? parent.children.indexOf(node) : void 0; + return visitor(node, index, parent); + } +} + +// node_modules/mdast-util-find-and-replace/node_modules/escape-string-regexp/index.js +function escapeStringRegexp(string) { + if (typeof string !== "string") { + throw new TypeError("Expected a string"); + } + return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d"); +} + +// node_modules/mdast-util-find-and-replace/lib/index.js +function findAndReplace(tree, list, options) { + const settings = {}; + const ignored = convert(settings.ignore || []); + const pairs = toPairs(list); + let pairIndex = -1; + while (++pairIndex < pairs.length) { + visitParents(tree, "text", visitor); + } + function visitor(node, parents) { + let index = -1; + let grandparent; + while (++index < parents.length) { + const parent = parents[index]; + const siblings = grandparent ? grandparent.children : void 0; + if (ignored( + parent, + siblings ? siblings.indexOf(parent) : void 0, + grandparent + )) { + return; + } + grandparent = parent; + } + if (grandparent) { + return handler(node, parents); + } + } + function handler(node, parents) { + const parent = parents[parents.length - 1]; + const find = pairs[pairIndex][0]; + const replace = pairs[pairIndex][1]; + let start = 0; + const siblings = parent.children; + const index = siblings.indexOf(node); + let change = false; + let nodes = []; + find.lastIndex = 0; + let match = find.exec(node.value); + while (match) { + const position = match.index; + 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 } : void 0; + } + if (value === false) { + 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; + } +} +function toPairs(tupleOrList) { + const result = []; + if (!Array.isArray(tupleOrList)) { + throw new TypeError("Expected find and replace tuple or list of tuples"); + } + 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; +} +function toExpression(find) { + return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find; +} +function toFunction(replace) { + return typeof replace === "function" ? replace : function() { + return replace; + }; +} // src/transformer.ts var defaultOptions = { diff --git a/dist/index.js.map b/dist/index.js.map index f468ebb..c61bec0 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/transformer.ts"],"names":["mdastFindReplace"],"mappings":";;;;AAoBA,IAAM,cAAA,GAA8B;AAAA,EAClC,WAAA,EAAa,IAAA;AAAA,EACb,aAAA,EAAe,IAAA;AAAA,EACf,aAAA,EAAe,IAAA;AAAA,EACf,cAAA,EAAgB,IAAA;AAAA,EAChB,cAAA,EAAgB,IAAA;AAAA,EAChB,YAAA,EAAc,IAAA;AAAA,EACd,mBAAA,EAAqB,IAAA;AAAA,EACrB,cAAA,EAAgB,IAAA;AAAA,EAChB,kBAAA,EAAoB;AACtB,CAAA;AAEA,IAAM,OAAA,GAAU,IAAI,MAAA,CAAO,cAAA,EAAgB,GAAG,CAAA;AAC9C,IAAM,SAAA,GAAY,IAAI,MAAA,CAAO,oBAAA,EAAsB,GAAG,CAAA;AACtD,IAAM,SAAA,GAAY,IAAI,MAAA,CAAO,oBAAA,EAAsB,GAAG,CAAA;AAEtD,IAAM,eAAA,GAAkB,IAAI,MAAA,CAAO,oBAAA,EAAsB,GAAG,CAAA;AAC5D,IAAM,kBAAA,GAAqB,IAAI,MAAA,CAAO,cAAA,EAAgB,GAAG,CAAA;AACzD,IAA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OAAA,CAAQ,IAAA,EAAM,CAAA,aAAA;AAAA,eACtC;AAAA,aACD,CAAA;AAAA,UACH;AAEA,UAAAA,cAAA,CAAiB,MAAM,YAAY,CAAA;AAAA,QACrC,CAAA;AAAA,MACF,CAAC,CAAA;AAED,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { QuartzTransformerPlugin } from \"@quartz-community/types\";\nimport type { PluggableList } from \"unified\";\nimport { visit } from \"unist-util-visit\";\nimport type { ReplaceFunction } from \"mdast-util-find-and-replace\";\nimport { findAndReplace as mdastFindReplace } from \"mdast-util-find-and-replace\";\nimport type { Root, Html, Paragraph, Text, Link, Parent } from \"mdast\";\nimport type { BuildVisitor } from \"unist-util-visit\";\n\nexport interface RoamOptions {\n orComponent: boolean;\n TODOComponent: boolean;\n DONEComponent: boolean;\n videoComponent: boolean;\n audioComponent: boolean;\n pdfComponent: boolean;\n blockquoteComponent: boolean;\n tableComponent: boolean;\n attributeComponent: boolean;\n}\n\nconst defaultOptions: RoamOptions = {\n orComponent: true,\n TODOComponent: true,\n DONEComponent: true,\n videoComponent: true,\n audioComponent: true,\n pdfComponent: true,\n blockquoteComponent: true,\n tableComponent: true,\n attributeComponent: true,\n};\n\nconst orRegex = new RegExp(/{{or:(.*?)}}/, \"g\");\nconst TODORegex = new RegExp(/{{.*?\\bTODO\\b.*?}}/, \"g\");\nconst DONERegex = new RegExp(/{{.*?\\bDONE\\b.*?}}/, \"g\");\n\nconst blockquoteRegex = new RegExp(/(\\[\\[>\\]\\])\\s*(.*)/, \"g\");\nconst roamHighlightRegex = new RegExp(/\\^\\^(.+)\\^\\^/, \"g\");\nconst roamItalicRegex = new RegExp(/__(.+)__/, \"g\");\n\nfunction isSpecialEmbed(node: Paragraph): boolean {\n if (node.children.length !== 2) return false;\n\n const [textNode, linkNode] = node.children;\n return !!(\n textNode &&\n textNode.type === \"text\" &&\n textNode.value.startsWith(\"{{[[\") &&\n linkNode &&\n linkNode.type === \"link\" &&\n linkNode.children &&\n linkNode.children[0] &&\n linkNode.children[0].type === \"text\" &&\n linkNode.children[0].value.endsWith(\"}}\")\n );\n}\n\nfunction transformSpecialEmbed(node: Paragraph, opts: RoamOptions): Html | null {\n const [textNode, linkNode] = node.children as [Text, Link];\n const embedType = textNode.value.match(/\\{\\{\\[\\[(.*?)\\]\\]:/)?.[1]?.toLowerCase();\n const url = linkNode.url.slice(0, -2); // Remove the trailing '}}'\n\n switch (embedType) {\n case \"audio\":\n return opts.audioComponent\n ? {\n type: \"html\",\n value: ``,\n }\n : null;\n case \"video\": {\n if (!opts.videoComponent) return null;\n // Check if it's a YouTube video\n const youtubeMatch = url.match(\n /(?:https?:\\/\\/)?(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/(?:watch\\?v=)?(.+)/,\n );\n if (youtubeMatch && youtubeMatch[1]) {\n const videoId = youtubeMatch[1].split(\"&\")[0]; // Remove additional parameters\n const playlistMatch = url.match(/[?&]list=([^#&?]*)/);\n const playlistId = playlistMatch ? playlistMatch[1] : null;\n\n return {\n type: \"html\",\n value: ``,\n };\n } else {\n return {\n type: \"html\",\n value: ``,\n };\n }\n }\n case \"pdf\":\n return opts.pdfComponent\n ? {\n type: \"html\",\n value: ``,\n }\n : null;\n default:\n return null;\n }\n}\n\nexport const RoamFlavoredMarkdown: QuartzTransformerPlugin | undefined> = (\n userOpts,\n) => {\n const opts = { ...defaultOptions, ...userOpts };\n\n return {\n name: \"RoamFlavoredMarkdown\",\n markdownPlugins() {\n const plugins: PluggableList = [];\n\n plugins.push(() => {\n return (tree: Root) => {\n const replacements: [RegExp, ReplaceFunction][] = [];\n\n // Handle special embeds (audio, video, PDF)\n if (opts.audioComponent || opts.videoComponent || opts.pdfComponent) {\n visit(tree, \"paragraph\", ((node: Paragraph, index: number, parent: Parent | null) => {\n if (isSpecialEmbed(node)) {\n const transformedNode = transformSpecialEmbed(node, opts);\n if (transformedNode && parent) {\n parent.children[index] = transformedNode;\n }\n }\n }) as BuildVisitor);\n }\n\n // Roam italic syntax\n replacements.push([\n roamItalicRegex,\n (_value: string, match: string) => ({\n type: \"emphasis\",\n children: [{ type: \"text\", value: match }],\n }),\n ]);\n\n // Roam highlight syntax\n replacements.push([\n roamHighlightRegex,\n (_value: string, inner: string) => ({\n type: \"html\",\n value: `${inner}`,\n }),\n ]);\n\n if (opts.orComponent) {\n replacements.push([\n orRegex,\n (match: string) => {\n const matchResult = match.match(/{{or:(.*?)}}/);\n if (matchResult === null || !matchResult[1]) {\n return { type: \"html\", value: \"\" };\n }\n const optionsString: string = matchResult[1];\n const options: string[] = optionsString.split(\"|\");\n const selectHtml: string = ``;\n return { type: \"html\", value: selectHtml };\n },\n ]);\n }\n\n if (opts.TODOComponent) {\n replacements.push([\n TODORegex,\n () => ({\n type: \"html\",\n value: ``,\n }),\n ]);\n }\n\n if (opts.DONEComponent) {\n replacements.push([\n DONERegex,\n () => ({\n type: \"html\",\n value: ``,\n }),\n ]);\n }\n\n if (opts.blockquoteComponent) {\n replacements.push([\n blockquoteRegex,\n (_match: string, _marker: string, content: string) => ({\n type: \"html\",\n value: `
${content.trim()}
`,\n }),\n ]);\n }\n\n mdastFindReplace(tree, replacements);\n };\n });\n\n return plugins;\n },\n };\n};\n"]} \ No newline at end of file +{"version":3,"sources":["../node_modules/unist-util-is/lib/index.js","../node_modules/unist-util-visit-parents/lib/color.node.js","../node_modules/unist-util-visit-parents/lib/index.js","../node_modules/unist-util-visit/lib/index.js","../node_modules/mdast-util-find-and-replace/node_modules/escape-string-regexp/index.js","../node_modules/mdast-util-find-and-replace/lib/index.js","../src/transformer.ts"],"names":["index","is","visit"],"mappings":";AA4IO,IAAM,OAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAgBT,SAAU,IAAA,EAAM;AACd,IAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,IAAA,KAAS,MAAA,EAAW;AACvC,M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BACN,KAAA,EAAO,CAAA,YAAA,EAAe,OAAA,CAAQ,IAAA,EAAM,CAAA,aAAA;AAAA,eACtC;AAAA,aACD,CAAA;AAAA,UACH;AAEA,UAAA,cAAA,CAAiB,MAAM,YAAY,CAAA;AAAA,QACrC,CAAA;AAAA,MACF,CAAC,CAAA;AAED,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * @import {Node, Parent} from 'unist'\n */\n\n/**\n * @template Fn\n * @template Fallback\n * @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate\n */\n\n/**\n * @callback Check\n * Check that an arbitrary value is a node.\n * @param {unknown} this\n * The given context.\n * @param {unknown} [node]\n * Anything (typically a node).\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {boolean}\n * Whether this is a node and passes a test.\n *\n * @typedef {Record | Node} Props\n * Object to check for equivalence.\n *\n * Note: `Node` is included as it is common but is not indexable.\n *\n * @typedef {Array | ReadonlyArray | Props | TestFunction | string | null | undefined} Test\n * Check for an arbitrary node.\n *\n * @callback TestFunction\n * Check if a node passes a test.\n * @param {unknown} this\n * The given context.\n * @param {Node} node\n * A node.\n * @param {number | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | undefined} [parent]\n * The node’s parent.\n * @returns {boolean | undefined | void}\n * Whether this node passes the test.\n *\n * Note: `void` is included until TS sees no return as `undefined`.\n */\n\n/**\n * Check if `node` is a `Node` and whether it passes the given test.\n *\n * @param {unknown} node\n * Thing to check, typically `Node`.\n * @param {Test} test\n * A check for a specific node.\n * @param {number | null | undefined} index\n * The node’s position in its parent.\n * @param {Parent | null | undefined} parent\n * The node’s parent.\n * @param {unknown} context\n * Context object (`this`) to pass to `test` functions.\n * @returns {boolean}\n * Whether `node` is a node and passes a test.\n */\nexport const is =\n // Note: overloads in JSDoc can’t yet use different `@template`s.\n /**\n * @type {(\n * (>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) &\n * (>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) &\n * ((node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &\n * ((node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &\n * ((node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate) &\n * ((node?: null | undefined) => false) &\n * ((node: unknown, test?: null | undefined, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &\n * ((node: unknown, test?: Test, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => boolean)\n * )}\n */\n (\n /**\n * @param {unknown} [node]\n * @param {Test} [test]\n * @param {number | null | undefined} [index]\n * @param {Parent | null | undefined} [parent]\n * @param {unknown} [context]\n * @returns {boolean}\n */\n // eslint-disable-next-line max-params\n function (node, test, index, parent, context) {\n const check = convert(test)\n\n if (\n index !== undefined &&\n index !== null &&\n (typeof index !== 'number' ||\n index < 0 ||\n index === Number.POSITIVE_INFINITY)\n ) {\n throw new Error('Expected positive finite index')\n }\n\n if (\n parent !== undefined &&\n parent !== null &&\n (!is(parent) || !parent.children)\n ) {\n throw new Error('Expected parent node')\n }\n\n if (\n (parent === undefined || parent === null) !==\n (index === undefined || index === null)\n ) {\n throw new Error('Expected both parent and index')\n }\n\n return looksLikeANode(node)\n ? check.call(context, node, index, parent)\n : false\n }\n )\n\n/**\n * Generate an assertion from a test.\n *\n * Useful if you’re going to test many nodes, for example when creating a\n * utility where something else passes a compatible test.\n *\n * The created function is a bit faster because it expects valid input only:\n * a `node`, `index`, and `parent`.\n *\n * @param {Test} test\n * * when nullish, checks if `node` is a `Node`.\n * * when `string`, works like passing `(node) => node.type === test`.\n * * when `function` checks if function passed the node is true.\n * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.\n * * when `array`, checks if any one of the subtests pass.\n * @returns {Check}\n * An assertion.\n */\nexport const convert =\n // Note: overloads in JSDoc can’t yet use different `@template`s.\n /**\n * @type {(\n * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &\n * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &\n * ((test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate) &\n * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &\n * ((test?: Test) => Check)\n * )}\n */\n (\n /**\n * @param {Test} [test]\n * @returns {Check}\n */\n function (test) {\n if (test === null || test === undefined) {\n return ok\n }\n\n if (typeof test === 'function') {\n return castFactory(test)\n }\n\n if (typeof test === 'object') {\n return Array.isArray(test)\n ? anyFactory(test)\n : // Cast because `ReadonlyArray` goes into the above but `isArray`\n // narrows to `Array`.\n propertiesFactory(/** @type {Props} */ (test))\n }\n\n if (typeof test === 'string') {\n return typeFactory(test)\n }\n\n throw new Error('Expected function, string, or object as test')\n }\n )\n\n/**\n * @param {Array} tests\n * @returns {Check}\n */\nfunction anyFactory(tests) {\n /** @type {Array} */\n const checks = []\n let index = -1\n\n while (++index < tests.length) {\n checks[index] = convert(tests[index])\n }\n\n return castFactory(any)\n\n /**\n * @this {unknown}\n * @type {TestFunction}\n */\n function any(...parameters) {\n let index = -1\n\n while (++index < checks.length) {\n if (checks[index].apply(this, parameters)) return true\n }\n\n return false\n }\n}\n\n/**\n * Turn an object into a test for a node with a certain fields.\n *\n * @param {Props} check\n * @returns {Check}\n */\nfunction propertiesFactory(check) {\n const checkAsRecord = /** @type {Record} */ (check)\n\n return castFactory(all)\n\n /**\n * @param {Node} node\n * @returns {boolean}\n */\n function all(node) {\n const nodeAsRecord = /** @type {Record} */ (\n /** @type {unknown} */ (node)\n )\n\n /** @type {string} */\n let key\n\n for (key in check) {\n if (nodeAsRecord[key] !== checkAsRecord[key]) return false\n }\n\n return true\n }\n}\n\n/**\n * Turn a string into a test for a node with a certain type.\n *\n * @param {string} check\n * @returns {Check}\n */\nfunction typeFactory(check) {\n return castFactory(type)\n\n /**\n * @param {Node} node\n */\n function type(node) {\n return node && node.type === check\n }\n}\n\n/**\n * Turn a custom test into a test for a node that passes that test.\n *\n * @param {TestFunction} testFunction\n * @returns {Check}\n */\nfunction castFactory(testFunction) {\n return check\n\n /**\n * @this {unknown}\n * @type {Check}\n */\n function check(value, index, parent) {\n return Boolean(\n looksLikeANode(value) &&\n testFunction.call(\n this,\n value,\n typeof index === 'number' ? index : undefined,\n parent || undefined\n )\n )\n }\n}\n\nfunction ok() {\n return true\n}\n\n/**\n * @param {unknown} value\n * @returns {value is Node}\n */\nfunction looksLikeANode(value) {\n return value !== null && typeof value === 'object' && 'type' in value\n}\n","/**\n * @param {string} d\n * @returns {string}\n */\nexport function color(d) {\n return '\\u001B[33m' + d + '\\u001B[39m'\n}\n","/**\n * @import {Node as UnistNode, Parent as UnistParent} from 'unist'\n */\n\n/**\n * @typedef {Exclude | undefined} Test\n * Test from `unist-util-is`.\n *\n * Note: we have remove and add `undefined`, because otherwise when generating\n * automatic `.d.ts` files, TS tries to flatten paths from a local perspective,\n * which doesn’t work when publishing on npm.\n */\n\n/**\n * @typedef {(\n * Fn extends (value: any) => value is infer Thing\n * ? Thing\n * : Fallback\n * )} Predicate\n * Get the value of a type guard `Fn`.\n * @template Fn\n * Value; typically function that is a type guard (such as `(x): x is Y`).\n * @template Fallback\n * Value to yield if `Fn` is not a type guard.\n */\n\n/**\n * @typedef {(\n * Check extends null | undefined // No test.\n * ? Value\n * : Value extends {type: Check} // String (type) test.\n * ? Value\n * : Value extends Check // Partial test.\n * ? Value\n * : Check extends Function // Function test.\n * ? Predicate extends Value\n * ? Predicate\n * : never\n * : never // Some other test?\n * )} MatchesOne\n * Check whether a node matches a primitive check in the type system.\n * @template Value\n * Value; typically unist `Node`.\n * @template Check\n * Value; typically `unist-util-is`-compatible test, but not arrays.\n */\n\n/**\n * @typedef {(\n * Check extends ReadonlyArray\n * ? MatchesOne\n * : Check extends Array\n * ? MatchesOne\n * : MatchesOne\n * )} Matches\n * Check whether a node matches a check in the type system.\n * @template Value\n * Value; typically unist `Node`.\n * @template Check\n * Value; typically `unist-util-is`-compatible test.\n */\n\n/**\n * @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint\n * Number; capped reasonably.\n */\n\n/**\n * @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment\n * Increment a number in the type system.\n * @template {Uint} [I=0]\n * Index.\n */\n\n/**\n * @typedef {(\n * Node extends UnistParent\n * ? Node extends {children: Array}\n * ? Child extends Children ? Node : never\n * : never\n * : never\n * )} InternalParent\n * Collect nodes that can be parents of `Child`.\n * @template {UnistNode} Node\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n */\n\n/**\n * @typedef {InternalParent, Child>} Parent\n * Collect nodes in `Tree` that can be parents of `Child`.\n * @template {UnistNode} Tree\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n */\n\n/**\n * @typedef {(\n * Depth extends Max\n * ? never\n * :\n * | InternalParent\n * | InternalAncestor, Max, Increment>\n * )} InternalAncestor\n * Collect nodes in `Tree` that can be ancestors of `Child`.\n * @template {UnistNode} Node\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n * @template {Uint} [Max=10]\n * Max; searches up to this depth.\n * @template {Uint} [Depth=0]\n * Current depth.\n */\n\n/**\n * @typedef {InternalAncestor, Child>} Ancestor\n * Collect nodes in `Tree` that can be ancestors of `Child`.\n * @template {UnistNode} Tree\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n */\n\n/**\n * @typedef {(\n * Tree extends UnistParent\n * ? Depth extends Max\n * ? Tree\n * : Tree | InclusiveDescendant>\n * : Tree\n * )} InclusiveDescendant\n * Collect all (inclusive) descendants of `Tree`.\n *\n * > 👉 **Note**: for performance reasons, this seems to be the fastest way to\n * > recurse without actually running into an infinite loop, which the\n * > previous version did.\n * >\n * > Practically, a max of `2` is typically enough assuming a `Root` is\n * > passed, but it doesn’t improve performance.\n * > It gets higher with `List > ListItem > Table > TableRow > TableCell`.\n * > Using up to `10` doesn’t hurt or help either.\n * @template {UnistNode} Tree\n * Tree type.\n * @template {Uint} [Max=10]\n * Max; searches up to this depth.\n * @template {Uint} [Depth=0]\n * Current depth.\n */\n\n/**\n * @typedef {'skip' | boolean} Action\n * Union of the action types.\n *\n * @typedef {number} Index\n * Move to the sibling at `index` next (after node itself is completely\n * traversed).\n *\n * Useful if mutating the tree, such as removing the node the visitor is\n * currently on, or any of its previous siblings.\n * Results less than 0 or greater than or equal to `children.length` stop\n * traversing the parent.\n *\n * @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple\n * List with one or two values, the first an action, the second an index.\n *\n * @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult\n * Any value that can be returned from a visitor.\n */\n\n/**\n * @callback Visitor\n * Handle a node (matching `test`, if given).\n *\n * Visitors are free to transform `node`.\n * They can also transform the parent of node (the last of `ancestors`).\n *\n * Replacing `node` itself, if `SKIP` is not returned, still causes its\n * descendants to be walked (which is a bug).\n *\n * When adding or removing previous siblings of `node` (or next siblings, in\n * case of reverse), the `Visitor` should return a new `Index` to specify the\n * sibling to traverse after `node` is traversed.\n * Adding or removing next siblings of `node` (or previous siblings, in case\n * of reverse) is handled as expected without needing to return a new `Index`.\n *\n * Removing the children property of an ancestor still results in them being\n * traversed.\n * @param {Visited} node\n * Found node.\n * @param {Array} ancestors\n * Ancestors of `node`.\n * @returns {VisitorResult}\n * What to do next.\n *\n * An `Index` is treated as a tuple of `[CONTINUE, Index]`.\n * An `Action` is treated as a tuple of `[Action]`.\n *\n * Passing a tuple back only makes sense if the `Action` is `SKIP`.\n * When the `Action` is `EXIT`, that action can be returned.\n * When the `Action` is `CONTINUE`, `Index` can be returned.\n * @template {UnistNode} [Visited=UnistNode]\n * Visited node type.\n * @template {UnistParent} [VisitedParents=UnistParent]\n * Ancestor type.\n */\n\n/**\n * @typedef {Visitor, Check>, Ancestor, Check>>>} BuildVisitor\n * Build a typed `Visitor` function from a tree and a test.\n *\n * It will infer which values are passed as `node` and which as `parents`.\n * @template {UnistNode} [Tree=UnistNode]\n * Tree type.\n * @template {Test} [Check=Test]\n * Test type.\n */\n\nimport {convert} from 'unist-util-is'\nimport {color} from 'unist-util-visit-parents/do-not-use-color'\n\n/** @type {Readonly} */\nconst empty = []\n\n/**\n * Continue traversing as normal.\n */\nexport const CONTINUE = true\n\n/**\n * Stop traversing immediately.\n */\nexport const EXIT = false\n\n/**\n * Do not traverse this node’s children.\n */\nexport const SKIP = 'skip'\n\n/**\n * Visit nodes, with ancestral information.\n *\n * This algorithm performs *depth-first* *tree traversal* in *preorder*\n * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).\n *\n * You can choose for which nodes `visitor` is called by passing a `test`.\n * For complex tests, you should test yourself in `visitor`, as it will be\n * faster and will have improved type information.\n *\n * Walking the tree is an intensive task.\n * Make use of the return values of the visitor when possible.\n * Instead of walking a tree multiple times, walk it once, use `unist-util-is`\n * to check if a node matches, and then perform different operations.\n *\n * You can change the tree.\n * See `Visitor` for more info.\n *\n * @overload\n * @param {Tree} tree\n * @param {Check} check\n * @param {BuildVisitor} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {undefined}\n *\n * @overload\n * @param {Tree} tree\n * @param {BuildVisitor} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {undefined}\n *\n * @param {UnistNode} tree\n * Tree to traverse.\n * @param {Visitor | Test} test\n * `unist-util-is`-compatible test\n * @param {Visitor | boolean | null | undefined} [visitor]\n * Handle each node.\n * @param {boolean | null | undefined} [reverse]\n * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).\n * @returns {undefined}\n * Nothing.\n *\n * @template {UnistNode} Tree\n * Node type.\n * @template {Test} Check\n * `unist-util-is`-compatible test.\n */\nexport function visitParents(tree, test, visitor, reverse) {\n /** @type {Test} */\n let check\n\n if (typeof test === 'function' && typeof visitor !== 'function') {\n reverse = visitor\n // @ts-expect-error no visitor given, so `visitor` is test.\n visitor = test\n } else {\n // @ts-expect-error visitor given, so `test` isn’t a visitor.\n check = test\n }\n\n const is = convert(check)\n const step = reverse ? -1 : 1\n\n factory(tree, undefined, [])()\n\n /**\n * @param {UnistNode} node\n * @param {number | undefined} index\n * @param {Array} parents\n */\n function factory(node, index, parents) {\n const value = /** @type {Record} */ (\n node && typeof node === 'object' ? node : {}\n )\n\n if (typeof value.type === 'string') {\n const name =\n // `hast`\n typeof value.tagName === 'string'\n ? value.tagName\n : // `xast`\n typeof value.name === 'string'\n ? value.name\n : undefined\n\n Object.defineProperty(visit, 'name', {\n value:\n 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'\n })\n }\n\n return visit\n\n function visit() {\n /** @type {Readonly} */\n let result = empty\n /** @type {Readonly} */\n let subresult\n /** @type {number} */\n let offset\n /** @type {Array} */\n let grandparents\n\n if (!test || is(node, index, parents[parents.length - 1] || undefined)) {\n // @ts-expect-error: `visitor` is now a visitor.\n result = toResult(visitor(node, parents))\n\n if (result[0] === EXIT) {\n return result\n }\n }\n\n if ('children' in node && node.children) {\n const nodeAsParent = /** @type {UnistParent} */ (node)\n\n if (nodeAsParent.children && result[0] !== SKIP) {\n offset = (reverse ? nodeAsParent.children.length : -1) + step\n grandparents = parents.concat(nodeAsParent)\n\n while (offset > -1 && offset < nodeAsParent.children.length) {\n const child = nodeAsParent.children[offset]\n\n subresult = factory(child, offset, grandparents)()\n\n if (subresult[0] === EXIT) {\n return subresult\n }\n\n offset =\n typeof subresult[1] === 'number' ? subresult[1] : offset + step\n }\n }\n }\n\n return result\n }\n }\n}\n\n/**\n * Turn a return value into a clean result.\n *\n * @param {VisitorResult} value\n * Valid return values from visitors.\n * @returns {Readonly}\n * Clean result.\n */\nfunction toResult(value) {\n if (Array.isArray(value)) {\n return value\n }\n\n if (typeof value === 'number') {\n return [CONTINUE, value]\n }\n\n return value === null || value === undefined ? empty : [value]\n}\n","/**\n * @import {Node as UnistNode, Parent as UnistParent} from 'unist'\n * @import {VisitorResult} from 'unist-util-visit-parents'\n */\n\n/**\n * @typedef {Exclude | undefined} Test\n * Test from `unist-util-is`.\n *\n * Note: we have remove and add `undefined`, because otherwise when generating\n * automatic `.d.ts` files, TS tries to flatten paths from a local perspective,\n * which doesn’t work when publishing on npm.\n */\n\n// To do: use types from `unist-util-visit-parents` when it’s released.\n\n/**\n * @typedef {(\n * Fn extends (value: any) => value is infer Thing\n * ? Thing\n * : Fallback\n * )} Predicate\n * Get the value of a type guard `Fn`.\n * @template Fn\n * Value; typically function that is a type guard (such as `(x): x is Y`).\n * @template Fallback\n * Value to yield if `Fn` is not a type guard.\n */\n\n/**\n * @typedef {(\n * Check extends null | undefined // No test.\n * ? Value\n * : Value extends {type: Check} // String (type) test.\n * ? Value\n * : Value extends Check // Partial test.\n * ? Value\n * : Check extends Function // Function test.\n * ? Predicate extends Value\n * ? Predicate\n * : never\n * : never // Some other test?\n * )} MatchesOne\n * Check whether a node matches a primitive check in the type system.\n * @template Value\n * Value; typically unist `Node`.\n * @template Check\n * Value; typically `unist-util-is`-compatible test, but not arrays.\n */\n\n/**\n * @typedef {(\n * Check extends ReadonlyArray\n * ? MatchesOne\n * : MatchesOne\n * )} Matches\n * Check whether a node matches a check in the type system.\n * @template Value\n * Value; typically unist `Node`.\n * @template Check\n * Value; typically `unist-util-is`-compatible test.\n */\n\n/**\n * @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint\n * Number; capped reasonably.\n */\n\n/**\n * @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment\n * Increment a number in the type system.\n * @template {Uint} [I=0]\n * Index.\n */\n\n/**\n * @typedef {(\n * Node extends UnistParent\n * ? Node extends {children: Array}\n * ? Child extends Children ? Node : never\n * : never\n * : never\n * )} InternalParent\n * Collect nodes that can be parents of `Child`.\n * @template {UnistNode} Node\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n */\n\n/**\n * @typedef {InternalParent, Child>} Parent\n * Collect nodes in `Tree` that can be parents of `Child`.\n * @template {UnistNode} Tree\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n */\n\n/**\n * @typedef {(\n * Depth extends Max\n * ? never\n * :\n * | InternalParent\n * | InternalAncestor, Max, Increment>\n * )} InternalAncestor\n * Collect nodes in `Tree` that can be ancestors of `Child`.\n * @template {UnistNode} Node\n * All node types in a tree.\n * @template {UnistNode} Child\n * Node to search for.\n * @template {Uint} [Max=10]\n * Max; searches up to this depth.\n * @template {Uint} [Depth=0]\n * Current depth.\n */\n\n/**\n * @typedef {(\n * Tree extends UnistParent\n * ? Depth extends Max\n * ? Tree\n * : Tree | InclusiveDescendant>\n * : Tree\n * )} InclusiveDescendant\n * Collect all (inclusive) descendants of `Tree`.\n *\n * > 👉 **Note**: for performance reasons, this seems to be the fastest way to\n * > recurse without actually running into an infinite loop, which the\n * > previous version did.\n * >\n * > Practically, a max of `2` is typically enough assuming a `Root` is\n * > passed, but it doesn’t improve performance.\n * > It gets higher with `List > ListItem > Table > TableRow > TableCell`.\n * > Using up to `10` doesn’t hurt or help either.\n * @template {UnistNode} Tree\n * Tree type.\n * @template {Uint} [Max=10]\n * Max; searches up to this depth.\n * @template {Uint} [Depth=0]\n * Current depth.\n */\n\n/**\n * @callback Visitor\n * Handle a node (matching `test`, if given).\n *\n * Visitors are free to transform `node`.\n * They can also transform `parent`.\n *\n * Replacing `node` itself, if `SKIP` is not returned, still causes its\n * descendants to be walked (which is a bug).\n *\n * When adding or removing previous siblings of `node` (or next siblings, in\n * case of reverse), the `Visitor` should return a new `Index` to specify the\n * sibling to traverse after `node` is traversed.\n * Adding or removing next siblings of `node` (or previous siblings, in case\n * of reverse) is handled as expected without needing to return a new `Index`.\n *\n * Removing the children property of `parent` still results in them being\n * traversed.\n * @param {Visited} node\n * Found node.\n * @param {Visited extends UnistNode ? number | undefined : never} index\n * Index of `node` in `parent`.\n * @param {Ancestor extends UnistParent ? Ancestor | undefined : never} parent\n * Parent of `node`.\n * @returns {VisitorResult}\n * What to do next.\n *\n * An `Index` is treated as a tuple of `[CONTINUE, Index]`.\n * An `Action` is treated as a tuple of `[Action]`.\n *\n * Passing a tuple back only makes sense if the `Action` is `SKIP`.\n * When the `Action` is `EXIT`, that action can be returned.\n * When the `Action` is `CONTINUE`, `Index` can be returned.\n * @template {UnistNode} [Visited=UnistNode]\n * Visited node type.\n * @template {UnistParent} [Ancestor=UnistParent]\n * Ancestor type.\n */\n\n/**\n * @typedef {Visitor>} BuildVisitorFromMatch\n * Build a typed `Visitor` function from a node and all possible parents.\n *\n * It will infer which values are passed as `node` and which as `parent`.\n * @template {UnistNode} Visited\n * Node type.\n * @template {UnistParent} Ancestor\n * Parent type.\n */\n\n/**\n * @typedef {(\n * BuildVisitorFromMatch<\n * Matches,\n * Extract\n * >\n * )} BuildVisitorFromDescendants\n * Build a typed `Visitor` function from a list of descendants and a test.\n *\n * It will infer which values are passed as `node` and which as `parent`.\n * @template {UnistNode} Descendant\n * Node type.\n * @template {Test} Check\n * Test type.\n */\n\n/**\n * @typedef {(\n * BuildVisitorFromDescendants<\n * InclusiveDescendant,\n * Check\n * >\n * )} BuildVisitor\n * Build a typed `Visitor` function from a tree and a test.\n *\n * It will infer which values are passed as `node` and which as `parent`.\n * @template {UnistNode} [Tree=UnistNode]\n * Node type.\n * @template {Test} [Check=Test]\n * Test type.\n */\n\nimport {visitParents} from 'unist-util-visit-parents'\n\nexport {CONTINUE, EXIT, SKIP} from 'unist-util-visit-parents'\n\n/**\n * Visit nodes.\n *\n * This algorithm performs *depth-first* *tree traversal* in *preorder*\n * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).\n *\n * You can choose for which nodes `visitor` is called by passing a `test`.\n * For complex tests, you should test yourself in `visitor`, as it will be\n * faster and will have improved type information.\n *\n * Walking the tree is an intensive task.\n * Make use of the return values of the visitor when possible.\n * Instead of walking a tree multiple times, walk it once, use `unist-util-is`\n * to check if a node matches, and then perform different operations.\n *\n * You can change the tree.\n * See `Visitor` for more info.\n *\n * @overload\n * @param {Tree} tree\n * @param {Check} check\n * @param {BuildVisitor} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {undefined}\n *\n * @overload\n * @param {Tree} tree\n * @param {BuildVisitor} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {undefined}\n *\n * @param {UnistNode} tree\n * Tree to traverse.\n * @param {Visitor | Test} testOrVisitor\n * `unist-util-is`-compatible test (optional, omit to pass a visitor).\n * @param {Visitor | boolean | null | undefined} [visitorOrReverse]\n * Handle each node (when test is omitted, pass `reverse`).\n * @param {boolean | null | undefined} [maybeReverse=false]\n * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).\n * @returns {undefined}\n * Nothing.\n *\n * @template {UnistNode} Tree\n * Node type.\n * @template {Test} Check\n * `unist-util-is`-compatible test.\n */\nexport function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {\n /** @type {boolean | null | undefined} */\n let reverse\n /** @type {Test} */\n let test\n /** @type {Visitor} */\n let visitor\n\n if (\n typeof testOrVisitor === 'function' &&\n typeof visitorOrReverse !== 'function'\n ) {\n test = undefined\n visitor = testOrVisitor\n reverse = visitorOrReverse\n } else {\n // @ts-expect-error: assume the overload with test was given.\n test = testOrVisitor\n // @ts-expect-error: assume the overload with test was given.\n visitor = visitorOrReverse\n reverse = maybeReverse\n }\n\n visitParents(tree, test, overload, reverse)\n\n /**\n * @param {UnistNode} node\n * @param {Array} parents\n */\n function overload(node, parents) {\n const parent = parents[parents.length - 1]\n const index = parent ? parent.children.indexOf(node) : undefined\n return visitor(node, index, parent)\n }\n}\n","export default function escapeStringRegexp(string) {\n\tif (typeof string !== 'string') {\n\t\tthrow new TypeError('Expected a string');\n\t}\n\n\t// Escape characters with special meaning either inside or outside character sets.\n\t// Use a simple backslash escape when it’s always valid, and a `\\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.\n\treturn string\n\t\t.replace(/[|\\\\{}()[\\]^$+*?.]/g, '\\\\$&')\n\t\t.replace(/-/g, '\\\\x2d');\n}\n","/**\n * @import {Nodes, Parents, PhrasingContent, Root, Text} from 'mdast'\n * @import {BuildVisitor, Test, VisitorResult} from 'unist-util-visit-parents'\n */\n\n/**\n * @typedef RegExpMatchObject\n * Info on the match.\n * @property {number} index\n * The index of the search at which the result was found.\n * @property {string} input\n * A copy of the search string in the text node.\n * @property {[...Array, Text]} stack\n * All ancestors of the text node, where the last node is the text itself.\n *\n * @typedef {RegExp | string} Find\n * Pattern to find.\n *\n * Strings are escaped and then turned into global expressions.\n *\n * @typedef {Array} FindAndReplaceList\n * Several find and replaces, in array form.\n *\n * @typedef {[Find, Replace?]} FindAndReplaceTuple\n * Find and replace in tuple form.\n *\n * @typedef {ReplaceFunction | string | null | undefined} Replace\n * Thing to replace with.\n *\n * @callback ReplaceFunction\n * Callback called when a search matches.\n * @param {...any} parameters\n * The parameters are the result of corresponding search expression:\n *\n * * `value` (`string`) — whole match\n * * `...capture` (`Array`) — matches from regex capture groups\n * * `match` (`RegExpMatchObject`) — info on the match\n * @returns {Array | PhrasingContent | string | false | null | undefined}\n * Thing to replace with.\n *\n * * when `null`, `undefined`, `''`, remove the match\n * * …or when `false`, do not replace at all\n * * …or when `string`, replace with a text node of that value\n * * …or when `Node` or `Array`, replace with those nodes\n *\n * @typedef {[RegExp, ReplaceFunction]} Pair\n * Normalized find and replace.\n *\n * @typedef {Array} Pairs\n * All find and replaced.\n *\n * @typedef Options\n * Configuration.\n * @property {Test | null | undefined} [ignore]\n * Test for which nodes to ignore (optional).\n */\n\nimport escape from 'escape-string-regexp'\nimport {visitParents} from 'unist-util-visit-parents'\nimport {convert} from 'unist-util-is'\n\n/**\n * Find patterns in a tree and replace them.\n *\n * The algorithm searches the tree in *preorder* for complete values in `Text`\n * nodes.\n * Partial matches are not supported.\n *\n * @param {Nodes} tree\n * Tree to change.\n * @param {FindAndReplaceList | FindAndReplaceTuple} list\n * Patterns to find.\n * @param {Options | null | undefined} [options]\n * Configuration (when `find` is not `Find`).\n * @returns {undefined}\n * Nothing.\n */\nexport function findAndReplace(tree, list, options) {\n const settings = options || {}\n const ignored = convert(settings.ignore || [])\n const pairs = toPairs(list)\n let pairIndex = -1\n\n while (++pairIndex < pairs.length) {\n visitParents(tree, 'text', visitor)\n }\n\n /** @type {BuildVisitor} */\n function visitor(node, parents) {\n let index = -1\n /** @type {Parents | undefined} */\n let grandparent\n\n while (++index < parents.length) {\n const parent = parents[index]\n /** @type {Array | undefined} */\n const siblings = grandparent ? grandparent.children : undefined\n\n if (\n ignored(\n parent,\n siblings ? siblings.indexOf(parent) : undefined,\n grandparent\n )\n ) {\n return\n }\n\n grandparent = parent\n }\n\n if (grandparent) {\n return handler(node, parents)\n }\n }\n\n /**\n * Handle a text node which is not in an ignored parent.\n *\n * @param {Text} node\n * Text node.\n * @param {Array} parents\n * Parents.\n * @returns {VisitorResult}\n * Result.\n */\n function handler(node, parents) {\n const parent = parents[parents.length - 1]\n const find = pairs[pairIndex][0]\n const replace = pairs[pairIndex][1]\n let start = 0\n /** @type {Array} */\n const siblings = parent.children\n const index = siblings.indexOf(node)\n let change = false\n /** @type {Array} */\n let nodes = []\n\n find.lastIndex = 0\n\n let match = find.exec(node.value)\n\n while (match) {\n const position = match.index\n /** @type {RegExpMatchObject} */\n const matchObject = {\n index: match.index,\n input: match.input,\n stack: [...parents, node]\n }\n let value = replace(...match, matchObject)\n\n if (typeof value === 'string') {\n value = value.length > 0 ? {type: 'text', value} : undefined\n }\n\n // It wasn’t a match after all.\n if (value === false) {\n // False acts as if there was no match.\n // So we need to reset `lastIndex`, which currently being at the end of\n // the current match, to the beginning.\n find.lastIndex = position + 1\n } else {\n if (start !== position) {\n nodes.push({\n type: 'text',\n value: node.value.slice(start, position)\n })\n }\n\n if (Array.isArray(value)) {\n nodes.push(...value)\n } else if (value) {\n nodes.push(value)\n }\n\n start = position + match[0].length\n change = true\n }\n\n if (!find.global) {\n break\n }\n\n match = find.exec(node.value)\n }\n\n if (change) {\n if (start < node.value.length) {\n nodes.push({type: 'text', value: node.value.slice(start)})\n }\n\n parent.children.splice(index, 1, ...nodes)\n } else {\n nodes = [node]\n }\n\n return index + nodes.length\n }\n}\n\n/**\n * Turn a tuple or a list of tuples into pairs.\n *\n * @param {FindAndReplaceList | FindAndReplaceTuple} tupleOrList\n * Schema.\n * @returns {Pairs}\n * Clean pairs.\n */\nfunction toPairs(tupleOrList) {\n /** @type {Pairs} */\n const result = []\n\n if (!Array.isArray(tupleOrList)) {\n throw new TypeError('Expected find and replace tuple or list of tuples')\n }\n\n /** @type {FindAndReplaceList} */\n // @ts-expect-error: correct.\n const list =\n !tupleOrList[0] || Array.isArray(tupleOrList[0])\n ? tupleOrList\n : [tupleOrList]\n\n let index = -1\n\n while (++index < list.length) {\n const tuple = list[index]\n result.push([toExpression(tuple[0]), toFunction(tuple[1])])\n }\n\n return result\n}\n\n/**\n * Turn a find into an expression.\n *\n * @param {Find} find\n * Find.\n * @returns {RegExp}\n * Expression.\n */\nfunction toExpression(find) {\n return typeof find === 'string' ? new RegExp(escape(find), 'g') : find\n}\n\n/**\n * Turn a replace into a function.\n *\n * @param {Replace} replace\n * Replace.\n * @returns {ReplaceFunction}\n * Function.\n */\nfunction toFunction(replace) {\n return typeof replace === 'function'\n ? replace\n : function () {\n return replace\n }\n}\n","import type { QuartzTransformerPlugin } from \"@quartz-community/types\";\nimport type { PluggableList } from \"unified\";\nimport { visit } from \"unist-util-visit\";\nimport type { ReplaceFunction } from \"mdast-util-find-and-replace\";\nimport { findAndReplace as mdastFindReplace } from \"mdast-util-find-and-replace\";\nimport type { Root, Html, Paragraph, Text, Link, Parent } from \"mdast\";\nimport type { BuildVisitor } from \"unist-util-visit\";\n\nexport interface RoamOptions {\n orComponent: boolean;\n TODOComponent: boolean;\n DONEComponent: boolean;\n videoComponent: boolean;\n audioComponent: boolean;\n pdfComponent: boolean;\n blockquoteComponent: boolean;\n tableComponent: boolean;\n attributeComponent: boolean;\n}\n\nconst defaultOptions: RoamOptions = {\n orComponent: true,\n TODOComponent: true,\n DONEComponent: true,\n videoComponent: true,\n audioComponent: true,\n pdfComponent: true,\n blockquoteComponent: true,\n tableComponent: true,\n attributeComponent: true,\n};\n\nconst orRegex = new RegExp(/{{or:(.*?)}}/, \"g\");\nconst TODORegex = new RegExp(/{{.*?\\bTODO\\b.*?}}/, \"g\");\nconst DONERegex = new RegExp(/{{.*?\\bDONE\\b.*?}}/, \"g\");\n\nconst blockquoteRegex = new RegExp(/(\\[\\[>\\]\\])\\s*(.*)/, \"g\");\nconst roamHighlightRegex = new RegExp(/\\^\\^(.+)\\^\\^/, \"g\");\nconst roamItalicRegex = new RegExp(/__(.+)__/, \"g\");\n\nfunction isSpecialEmbed(node: Paragraph): boolean {\n if (node.children.length !== 2) return false;\n\n const [textNode, linkNode] = node.children;\n return !!(\n textNode &&\n textNode.type === \"text\" &&\n textNode.value.startsWith(\"{{[[\") &&\n linkNode &&\n linkNode.type === \"link\" &&\n linkNode.children &&\n linkNode.children[0] &&\n linkNode.children[0].type === \"text\" &&\n linkNode.children[0].value.endsWith(\"}}\")\n );\n}\n\nfunction transformSpecialEmbed(node: Paragraph, opts: RoamOptions): Html | null {\n const [textNode, linkNode] = node.children as [Text, Link];\n const embedType = textNode.value.match(/\\{\\{\\[\\[(.*?)\\]\\]:/)?.[1]?.toLowerCase();\n const url = linkNode.url.slice(0, -2); // Remove the trailing '}}'\n\n switch (embedType) {\n case \"audio\":\n return opts.audioComponent\n ? {\n type: \"html\",\n value: ``,\n }\n : null;\n case \"video\": {\n if (!opts.videoComponent) return null;\n // Check if it's a YouTube video\n const youtubeMatch = url.match(\n /(?:https?:\\/\\/)?(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/(?:watch\\?v=)?(.+)/,\n );\n if (youtubeMatch && youtubeMatch[1]) {\n const videoId = youtubeMatch[1].split(\"&\")[0]; // Remove additional parameters\n const playlistMatch = url.match(/[?&]list=([^#&?]*)/);\n const playlistId = playlistMatch ? playlistMatch[1] : null;\n\n return {\n type: \"html\",\n value: ``,\n };\n } else {\n return {\n type: \"html\",\n value: ``,\n };\n }\n }\n case \"pdf\":\n return opts.pdfComponent\n ? {\n type: \"html\",\n value: ``,\n }\n : null;\n default:\n return null;\n }\n}\n\nexport const RoamFlavoredMarkdown: QuartzTransformerPlugin | undefined> = (\n userOpts,\n) => {\n const opts = { ...defaultOptions, ...userOpts };\n\n return {\n name: \"RoamFlavoredMarkdown\",\n markdownPlugins() {\n const plugins: PluggableList = [];\n\n plugins.push(() => {\n return (tree: Root) => {\n const replacements: [RegExp, ReplaceFunction][] = [];\n\n // Handle special embeds (audio, video, PDF)\n if (opts.audioComponent || opts.videoComponent || opts.pdfComponent) {\n visit(tree, \"paragraph\", ((node: Paragraph, index: number, parent: Parent | null) => {\n if (isSpecialEmbed(node)) {\n const transformedNode = transformSpecialEmbed(node, opts);\n if (transformedNode && parent) {\n parent.children[index] = transformedNode;\n }\n }\n }) as BuildVisitor);\n }\n\n // Roam italic syntax\n replacements.push([\n roamItalicRegex,\n (_value: string, match: string) => ({\n type: \"emphasis\",\n children: [{ type: \"text\", value: match }],\n }),\n ]);\n\n // Roam highlight syntax\n replacements.push([\n roamHighlightRegex,\n (_value: string, inner: string) => ({\n type: \"html\",\n value: `${inner}`,\n }),\n ]);\n\n if (opts.orComponent) {\n replacements.push([\n orRegex,\n (match: string) => {\n const matchResult = match.match(/{{or:(.*?)}}/);\n if (matchResult === null || !matchResult[1]) {\n return { type: \"html\", value: \"\" };\n }\n const optionsString: string = matchResult[1];\n const options: string[] = optionsString.split(\"|\");\n const selectHtml: string = ``;\n return { type: \"html\", value: selectHtml };\n },\n ]);\n }\n\n if (opts.TODOComponent) {\n replacements.push([\n TODORegex,\n () => ({\n type: \"html\",\n value: ``,\n }),\n ]);\n }\n\n if (opts.DONEComponent) {\n replacements.push([\n DONERegex,\n () => ({\n type: \"html\",\n value: ``,\n }),\n ]);\n }\n\n if (opts.blockquoteComponent) {\n replacements.push([\n blockquoteRegex,\n (_match: string, _marker: string, content: string) => ({\n type: \"html\",\n value: `
${content.trim()}
`,\n }),\n ]);\n }\n\n mdastFindReplace(tree, replacements);\n };\n });\n\n return plugins;\n },\n };\n};\n"]} \ No newline at end of file diff --git a/package.json b/package.json index b2213ca..c7c628e 100644 --- a/package.json +++ b/package.json @@ -44,10 +44,7 @@ }, "peerDependencies": { "@jackyzha0/quartz": "^4.5.2", - "mdast-util-find-and-replace": "^3.0.1", - "preact": "^10.0.0", - "unified": "^11.0.5", - "unist-util-visit": "^5.0.0" + "preact": "^10.0.0" }, "peerDependenciesMeta": { "@jackyzha0/quartz": { @@ -55,20 +52,10 @@ }, "preact": { "optional": false - }, - "mdast-util-find-and-replace": { - "optional": true - }, - "unified": { - "optional": true - }, - "unist-util-visit": { - "optional": true } }, "dependencies": { - "@quartz-community/types": "github:quartz-community/types", - "mdast": "^3.0.0" + "@quartz-community/types": "github:quartz-community/types" }, "devDependencies": { "@types/hast": "^3.0.4", @@ -78,6 +65,7 @@ "@typescript-eslint/parser": "^7.18.0", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", + "mdast": "^3.0.0", "mdast-util-find-and-replace": "^3.0.2", "preact": "^10.28.2", "prettier": "^3.6.2",