fix: allow remark toc to parse headings with url

This commit is contained in:
Timothy Lin 2021-08-30 23:53:41 +08:00
parent 9c5e267a59
commit b7cee5eaca

View File

@ -1,12 +1,14 @@
import { visit } from 'unist-util-visit'
import { slug } from 'github-slugger'
import { toString } from 'hast-util-to-string'
export default function remarkTocHeadings(options) {
return (tree) =>
visit(tree, 'heading', (node, index, parent) => {
const textContent = toString(node)
options.exportRef.push({
value: node.children[0].value,
url: '#' + slug(node.children[0].value),
value: textContent,
url: '#' + slug(textContent),
depth: node.depth,
})
})