UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

23 lines (22 loc) • 869 B
import { d as showCondition, f as showDeclaration, p as showElement } from "../code-output-BZYBFRsN.js"; import { d as walk, l as toEsm, o as isJsxElement } from "../utils-C7sTEOQI.js"; // src/mdx-plugins/remark-show.ts /** * `<show when={...}>` renders its content when the condition holds, like `props.framework === 'next'` with the params of * a page as props. The outputs of other plugins (TOC, structured data, Markdown) check the conditions too. */ function remarkShow() { return (tree, file) => { let used = false; walk(tree, (node) => { if (!isJsxElement(node) || node.name !== "show") return; node.name = showElement; if (!showCondition(node)) file.fail("`<show>` needs a `when` expression", node); used = true; }); if (!used) return; tree.children.unshift(toEsm(showDeclaration)); file.data._show = true; }; } export { remarkShow };