@mintlify/scraping
Version:
Scrape documentation frameworks to Mintlify docs
19 lines (16 loc) • 560 B
text/typescript
import type { Root as MdastRoot } from 'mdast';
import { CONTINUE, visit } from 'unist-util-visit';
export function remarkRemoveEmptyEmphases() {
return function (root: MdastRoot) {
return removeEmptyEmphases(root);
};
}
function removeEmptyEmphases(root: MdastRoot) {
visit(root, function (node, index, parent) {
if (node.type !== 'emphasis' && node.type !== 'strong') return CONTINUE;
if (node.children.length === 0) {
if (!parent || typeof index !== 'number') return CONTINUE;
parent.children.splice(index, 1);
}
});
}