@mintlify/common
Version:
Commonly shared code within Mintlify
17 lines (16 loc) • 754 B
JavaScript
import { map } from 'unist-util-map';
import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
import { createCommentNode } from './createCommentNode.js';
export const remarkMdxRemoveUnknownJsx = (allowedComponents) => (tree) => {
const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
return map(tree, (node) => {
if (isMdxJsxFlowElementHast(node)) {
if (node.name &&
!(allowedComponents === null || allowedComponents === void 0 ? void 0 : allowedComponents.includes(node.name)) &&
!exportedComponentNames.includes(node.name)) {
return createCommentNode(node.name);
}
}
return node;
});
};