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