Add ID to headings

This commit is contained in:
2024-08-21 13:50:40 +02:00
parent e4838643d4
commit f87f742547
3 changed files with 14 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import capitalize from "lodash.capitalize"
import { visit } from "unist-util-visit"
import { toHast } from "mdast-util-to-hast"
import { toHtml } from "hast-util-to-html"
import { toString } from 'mdast-util-to-string';
import { FindAndReplaceList, findAndReplace as mdastFindReplace } from "mdast-util-find-and-replace"
// !? -> optional embedding
@@ -320,5 +321,13 @@ export default function ofm() {
}
}
})
visit(tree, "heading", (node) => {
node.data = {
hProperties: {
id: toString(node)
}
};
});
}
}