Spaces:
Running
Running
File size: 619 Bytes
22b1735 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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('<source')) {
console.debug('[remarkSource] found source tag:', node.value)
}
const match = node.value.match(/<source\s+path=['"](.+?)['"]\s*\/>/)
if (!match || !parent) return
const [, path] = match
parent.children.splice(index, 1, {
type: 'source',
path,
data: {},
} as any)
})
}
export default remarkSource
|