rehype-slug
rehype-slug copied to clipboard
Add option for adding a prefix
Initial checklist
- [X] I read the support docs
- [X] I read the contributing guide
- [X] I agree to follow the code of conduct
- [X] I searched issues and couldn’t find anything (or linked relevant results below)
Problem
I thought it would be useful to be able to add a prefix to the generated slugs. Had the case where on the same page there were multiple instances of rehype and I needed to make sure each slug generated, was unique throughout the page and prefixing them with an id related to the instance solved the problem.
Solution
Since I needed this feature, I've made a fork: https://github.com/rehypejs/rehype-slug/commit/82d837cf4464601c242e33c25be66beb3a70b221
Alternatives
I'm not sure there any alternatives, maybe adding some hidden content to the headings? Correct me if I'm wrong..
See https://github.com/rehypejs/rehype-slug/issues/13. Your case is interesting and different though.
GH does some things like this for footnotes in comments (which are numbered, so, #fn-1). Where they prefix with a hash of the comment.
They never render headings with IDs from different sources on the same page though.
Interested in PRing the feature to this project?
I'm not sure about the GH case you are talking about (care to point it out)?
Anyway, I'll open a PR.
Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.