iles
Version:
Vite & Vue powered static site generator with partial hydration
20 lines (18 loc) • 734 B
JavaScript
// src/node/plugin/markdown.ts
import deepEqual from "deep-equal";
var originalTags;
function detectMDXComponents(code, config, server) {
const mdxComponents = code.match(/\bmdxComponents\b(?:.*?){(.*?)}/s)?.[1];
if (!mdxComponents) return;
const foundTags = Array.from(mdxComponents.matchAll(/\b['"]?(\w+)['"]?:/g)).map((m) => m[1]);
if (!originalTags)
originalTags = config.markdown.overrideElements ||= [];
const dynamicElements = Array.from(/* @__PURE__ */ new Set([...originalTags, ...foundTags])).sort();
if (!deepEqual(dynamicElements, config.markdown.overrideElements)) {
config.markdown.overrideElements = dynamicElements;
server?.moduleGraph.invalidateAll();
}
}
export {
detectMDXComponents
};