Merge pull request #215 from timlrx/fix/toc-headings

fix: allow remark toc to parse headings with url
This commit is contained in:
Timothy 2021-08-30 23:55:28 +08:00 committed by GitHub
commit cd754b5de3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,
})
})