Giter Site home page Giter Site logo

Comments (5)

wooorm avatar wooorm commented on June 11, 2024 1

I recommend changing the content.

See the source: https://github.com/rehypejs/rehype-slug/blob/main/lib/index.js.
Copy/paste it, remove what you don’t need, change it to do what you want.

toUpperCase makes everything uppercase, you probably don’t want that.

headingRank(node) returns 1, 2, etc for headings. Return for 1 if you don’t want h1.

from rehype-slug.

bennycode avatar bennycode commented on June 11, 2024 1

I appreciate your input. I will try to gradually transition to the new slug structure. For now, I'm using JavaScript within my Astro pages to convert incoming legacy slugs (capitalized in my case) into the new format.

Example:

<script>
  (() => {
    const matchTS = /TS\d+/g;
    const hash = window.location.hash;
    const matches = hash.match(matchTS);
    if (matches) {
      window.location.hash = hash.replace('TS', 'ts');
    }
  })();
</script>

from rehype-slug.

wooorm avatar wooorm commented on June 11, 2024

Hey! This project is intentionally simple. So that everyone uses the same slugs. It follows GitHub. So that what you write in markdown will work here. And in VS Code. In as many places.

The goal is to not add other options. It would go against the goal of everyone using the same slugs. The alternative, writing your own plugin, is fine! We recommend learning about ASTs, and this is a good example how to learn about them.

from rehype-slug.

github-actions avatar github-actions commented on June 11, 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.

bennycode avatar bennycode commented on June 11, 2024

Thanks for your explanation. I really like the idea of creating slugs similar to how GitHub does it, and I want to use this in my projects.

I am building an Astro blog, and I need to make sure it supports some links from an older blogging system. In that older system, some of the links are like #TS2003, but the plugin changes them to #ts2003. I can't update the old content, so how can I fix this and change the way the slug is created by the rehype-slug plugin? I was thinking about building my own transformer that under-the-hood calls rehype-slug and then just runs the toUpperCase on top of it?

Also, I'm wondering if there's a way to choose which heading levels get slugs/IDs. For example, I only want IDs for H2 headings and not for H3 headings. Is there a way to do that?

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.