tailwind-nextjs-blog/lib/remark-toc-headings.ts

18 lines
475 B
TypeScript
Raw Normal View History

//@ts-nocheck
import { Parent } from 'unist'
2022-07-17 21:40:41 +08:00
import { visit } from 'unist-util-visit'
import { slug } from 'github-slugger'
import { toString } from 'mdast-util-to-string'
export default function remarkTocHeadings(options) {
return (tree: Parent) =>
visit(tree, 'heading', (node) => {
2022-07-17 21:40:41 +08:00
const textContent = toString(node)
options.exportRef.push({
value: textContent,
url: '#' + slug(textContent),
depth: node.depth,
})
})
}