@mintlify/common
Version:
Commonly shared code within Mintlify
23 lines (22 loc) • 1.13 kB
JavaScript
import { map } from 'unist-util-map';
import { allowedComponents } from '../../../index.js';
import { isMdxJsxFlowElementHast } from '../../../lib/index.js';
import { getExportedFunctionNames } from '../remarkMdxClientComponentBoundaries.js';
import { createCommentNode } from './createCommentNode.js';
export const remarkMdxRemoveUnknownJsx = ({ allowlist } = {}) => (tree) => {
// Components defined in the MDX itself are "known" and must not be stripped. Shared with
// remarkMdxClientComponentBoundaries so the two plugins agree on what counts as a component.
const exportedComponentNames = getExportedFunctionNames(tree);
return map(tree, (node) => {
if (isMdxJsxFlowElementHast(node)) {
if (node.name &&
Array.isArray(allowedComponents) &&
!allowedComponents.includes(node.name) &&
!exportedComponentNames.has(node.name) &&
!(allowlist === null || allowlist === void 0 ? void 0 : allowlist.includes(node.name))) {
return createCommentNode(node.name);
}
}
return node;
});
};