Comments (4)
Thanks for the detailed response @wooorm!
rehype-sanitize
definitely seems like the way to go for most projects. Since this is an internal project, I'm going to just go with the getElementById
/[id="3-xxx"]
syntax so I don't have to worry about the caveats with the changing classes for the other plugins (linking, syntax highlighting, etc).
I’m open to adding an option here to prefix things.
I think the two solutions you provided resolve the need for this option. Hopefully this issue can help someone in the future!
Thanks again :)
from rehype-slug.
Cool, glad those alternatives work for you!
from rehype-slug.
Hey Chad!
HTML spec was a little less clear whether it was valid or not
Starting an id attribute value with a number is valid according to HTML. It’s fine.
It only becomes a problem when trying to select it with a selector shortcut: querySelector('#3-xxx')
or #3-xxx { color:red }
.
It is fine with document.getElementById('3-xxx')
and also fine with document.querySelector('[id="3-xxx"]')
/ [id="3-xxx"] { color: red }
GitHub appends
user-content-
to all of the ids of in the rendered markdown.
GitHub doesn't include the user-content- in the url produced for each header, but instead handles that client side
Yep, and it does so to prevent DOM clobbering, as a safety measure.
That’s why we also do it at a different place in the pipeline: rehype-sanitize
. It has a whole section on how that prefix works, what it solves, and what GitHub adds client-side: https://github.com/rehypejs/rehype-sanitize#example-headings-dom-clobbering.
I’m open to adding an option here to prefix things.
Alternatively, you could investigate using rehype-sanitize
too.
But also: perhaps using attribute syntax ([id="3-xxx"]
) or getElementById
might solve it for you?
from rehype-slug.
Hi! This was closed. Team: If this was fixed, please add phase/solved
. Otherwise, please add one of the no/*
labels.
from rehype-slug.
Related Issues (11)
- Support manual custom IDs HOT 3
- Broken anchors when header contains accents HOT 10
- Add option for adding a prefix HOT 3
- add a new option to treat no-break spaces as whitespace (and yield dashes in their place) HOT 2
- Why not support a pluggable `option.slug` function (or `options.slugger` implementation)? HOT 9
- Option to capitalize slugs HOT 5
- Typescript typings for this plugin HOT 3
- Types introduced in v4 aren't exposed via the package.json
- Add support for 'German' umlaute HOT 2
- Customize which headings are included HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rehype-slug.