Add ID to headings

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

BIN
bun.lockb Normal file

Binary file not shown.

View File

@ -23,13 +23,13 @@
},
"devDependencies": {
"@types/lodash.capitalize": "^4.2.9",
"@types/unist": "^2.0.6",
"mdast-util-to-string": "^3.1.1",
"@types/unist": "^2.0.10",
"mdast-util-to-string": "^4.0.0",
"rehype-raw": "^6.1.1",
"rehype-stringify": "^9.0.3",
"remark-parse": "^10.0.1",
"rehype-stringify": "^9.0.4",
"remark-parse": "^10.0.2",
"remark-rehype": "^10.1.0",
"typescript": "^5.0.2",
"typescript": "^5.5.4",
"unified": "^10.1.2"
}
}

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