tailwind-nextjs-blog/lib/remark-toc-headings.ts
2022-10-17 15:37:01 +00:00

18 lines
482 B
TypeScript

//@ts-nocheck
import { Parent } from 'unist';
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) => {
const textContent = toString(node);
options.exportRef.push({
value: textContent,
url: '#' + slug(textContent),
depth: node.depth,
});
});
}