rehype-slug icon indicating copy to clipboard operation
rehype-slug copied to clipboard

Add option for adding a prefix

Open onyxcodes opened this issue 3 years ago • 1 comments
trafficstars

Initial checklist

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..

onyxcodes avatar Oct 27 '22 00:10 onyxcodes

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?

wooorm avatar Oct 27 '22 10:10 wooorm

I'm not sure about the GH case you are talking about (care to point it out)?

Anyway, I'll open a PR.

onyxcodes avatar Oct 27 '22 21:10 onyxcodes

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

github-actions[bot] avatar Oct 31 '22 09:10 github-actions[bot]