2021-08-14 23:11:18 +08:00
|
|
|
import { visit } from 'unist-util-visit'
|
2021-08-22 17:13:14 +08:00
|
|
|
import { slug } from 'github-slugger'
|
2021-08-06 22:13:30 +08:00
|
|
|
|
2021-08-14 23:11:18 +08:00
|
|
|
export default function remarkTocHeadings(options) {
|
2021-08-06 22:13:30 +08:00
|
|
|
return (tree) =>
|
|
|
|
visit(tree, 'heading', (node, index, parent) => {
|
|
|
|
options.exportRef.push({
|
2021-08-22 17:13:14 +08:00
|
|
|
value: node.children[0].value,
|
|
|
|
url: '#' + slug(node.children[0].value),
|
2021-08-06 22:13:30 +08:00
|
|
|
depth: node.depth,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|