Transclude of ${url}${block}`, } } // otherwise, fall through to regular link } // internal link const url = fp + anchor return { type: "link", url, children: [ { type: "text", value: alias ?? fp, }, ], } }, ]) } if (opts.highlight) { replacements.push([ highlightRegex, (_value: string, ...capture: string[]) => { const [inner] = capture return { type: "html", value: `${inner}`, } }, ]) } if (opts.comments) { replacements.push([ commentRegex, (_value: string, ..._capture: string[]) => { return { type: "text", value: "", } }, ]) } if (opts.parseTags) { replacements.push([ tagRegex, (_value: string, tag: string) => { // Check if the tag only includes numbers if (/^\d+$/.test(tag)) { return false } tag = slugTag(tag) if (file.data.frontmatter && !file.data.frontmatter.tags.includes(tag)) { file.data.frontmatter.tags.push(tag) } return { type: "link", url: base + `/tags/${tag}`, data: { hProperties: { className: ["tag-link"], }, }, children: [ { type: "text", value: `#${tag}`, }, ], } }, ]) } if (opts.enableInHtmlEmbed) { visit(tree, "html", (node: Html) => { for (const [regex, replace] of replacements) { if (typeof replace === "string") { node.value = node.value.replace(regex, replace) } else { node.value = node.value.replaceAll(regex, (substring: string, ...args) => { const replaceValue = replace(substring, ...args) if (typeof replaceValue === "string") { return replaceValue } else if (Array.isArray(replaceValue)) { return replaceValue.map(mdastToHtml).join("") } else if (typeof replaceValue === "object" && replaceValue !== null) { return mdastToHtml(replaceValue) } else { return substring } }) } } }) } mdastFindReplace(tree, replacements) } }) if (opts.callouts) { plugins.push(() => { return (tree: Root, _file) => { visit(tree, "blockquote", (node) => { if (node.children.length === 0) { return } // find first line const firstChild = node.children[0] if (firstChild.type !== "paragraph" || firstChild.children[0]?.type !== "text") { return } const text = firstChild.children[0].value const restChildren = firstChild.children.slice(1) const [firstLine, ...remainingLines] = text.split("\n") const remainingText = remainingLines.join("\n") const match = firstLine.match(calloutRegex) if (match && match.input) { const [calloutDirective, typeString, collapseChar] = match const calloutType = canonicalizeCallout( typeString.toLowerCase() as keyof typeof calloutMapping, ) const collapse = collapseChar === "+" || collapseChar === "-" const defaultState = collapseChar === "-" ? "collapsed" : "expanded" const titleContent = match.input.slice(calloutDirective.length).trim() || capitalize(calloutType) const titleNode: Paragraph = { type: "paragraph", children: [{ type: "text", value: titleContent + " " }, ...restChildren], } const title = mdastToHtml(titleNode) const toggleIcon = `` const titleHtml: Html = { type: "html", value: `