Comments (9)
Hi. Did you see the existing issues? https://github.com/rehypejs/rehype-slug/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed
Because this has been asked a couple times.
Allowing such an option harm the ecosystem, as it fragments it. In my opinion, markdown needs standardization, not fragmentation.
There are very good alternatives: this plugin is ±5 lines, which you can write too, to suit your exact needs.
Having that option also means end users get two slug libraries, one of which isn’t used. That’s what 4kb minzipped that isn’t used or needed.
from rehype-slug.
Duplicate of #16
from rehype-slug.
Hi! Thanks for taking the time to contribute!
Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.
Thanks,
— bb
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.
Yes, I did search the existing issues and there didn't seem to be the same issue. The one linked as a potential duplicate is related but not the same. I certainly get the perspective of the fact that it is a short only 15 line plugin, but with only an extra 3 lines it could be tremendously more powerful.
A quick example of what I was think to submit (and/or fine to make its own plugin, but this seems generic enough to be pretty helpful to many while still being opinionated by default as it currently stands):
/**
* @typedef {import('hast').Root} Root
*/
/**
* @typedef {Function} SlugFunction
* Custom `slug` implementation (optional).
* @param {string} value
* String of text to 'slugify'
* @return {string}
* A unique slug string
*/
/**
* @typedef {Function} ResetFunction
* Custom `reset` implementation (optional).
* @return {void}
*/
/**
* @typedef SluggerImplementation
* Custom `Slugger` implementation (optional).
* @property {SlugFunction} slug
* The function to call for `slug(string)`
* @property {ResetFunction} [reset]
* The function to call for `reset()`
*/
/**
* @typedef Options
* Configuration (optional).
* @property {string} [prefix='']
* Prefix to add in front of `id`s.
* @property {SluggerImplementation} [slugger]
* The `Slugger` implementation to use.
*/
import Slugger from 'github-slugger'
import {hasProperty} from 'hast-util-has-property'
import {headingRank} from 'hast-util-heading-rank'
import {toString} from 'hast-util-to-string'
import {visit} from 'unist-util-visit'
const slugs = new Slugger()
/**
* Plugin to add `id`s to headings.
*
* @type {import('unified').Plugin<[Options?]|Array<void>, Root>}
*/
export default function rehypeSlug(options = {}) {
const prefix = options.prefix || ''
const slugger = options.slugger || slugs
return (tree) => {
if (slugger.reset) {
slugger.reset()
}
visit(tree, 'element', (node) => {
if (headingRank(node) && node.properties && !hasProperty(node, 'id')) {
node.properties.id = prefix + slugs.slug(toString(node))
}
})
}
}
from rehype-slug.
If that looks interesting/helpful still, let me know and happy to put in place test coverage and submit as a PR @wooorm??
from rehype-slug.
No, thanks. I think it’s a bad idea. For reasons explained above, and linked here: #16 (comment)
from rehype-slug.
Examples of behavior that contributes to creating a positive environment include:
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
from rehype-slug.
Quoting the CoC to me is a good example of not being respectful of differing viewpoints and experiences.
I have been kind to you, I am not interested in maintaining your code for the rest of my life, and I don’t want to push your code to millions of people. That does not make your code bad. You can use your code.
I’m locking this conversation as it’s done.
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
- 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.