Giter Site home page Giter Site logo

Comments (4)

chadfawcett avatar chadfawcett commented on June 12, 2024 2

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.

wooorm avatar wooorm commented on June 12, 2024 1

Cool, glad those alternatives work for you!

from rehype-slug.

wooorm avatar wooorm commented on June 12, 2024

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.

github-actions avatar github-actions commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.