Comments (5)
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.
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.
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.
Hi! This was closed. Team: If this was fixed, please add phase/solved
. Otherwise, please add one of the no/*
labels.
from rehype-slug.
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)
- Support manual custom IDs HOT 3
- Broken anchors when header contains accents HOT 10
- Handle titles starting with numbers HOT 4
- 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
- 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.