import { visit } from 'unist-util-visit' import type { Plugin } from 'unified' import type { Root, HTML } from 'mdast' const remarkSource: Plugin = () => (tree: Root) => { visit(tree, 'html', (node: HTML, index, parent) => { if (node.value.startsWith('/) if (!match || !parent) return const [, path] = match parent.children.splice(index, 1, { type: 'source', path, data: {}, } as any) }) } export default remarkSource