Giter Site home page Giter Site logo

Comments (9)

wooorm avatar wooorm commented on June 12, 2024 1

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.

wooorm avatar wooorm commented on June 12, 2024 1

Duplicate of #16

from rehype-slug.

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

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.

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.

agrohs avatar agrohs commented on June 12, 2024

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.

agrohs avatar agrohs commented on June 12, 2024

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.

wooorm avatar wooorm commented on June 12, 2024

No, thanks. I think it’s a bad idea. For reasons explained above, and linked here: #16 (comment)

from rehype-slug.

agrohs avatar agrohs commented on June 12, 2024

Code of Conduct

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.

wooorm avatar wooorm commented on June 12, 2024

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)

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.