Skip to content

Change the logic of generating the id of h tags #432

Closed

Description

@whzhyh

Now the logic of generating the id of h tags is raw.toLowerCase().replace(/[^\w]+/g, '-').

By using this method, if the header includes other none-English words, the id just is '-'.

Then if we need the id to be used as anchors, this won't work.

Now I am using marked-toc to generate index of the headers, it uses uslug to generate the anchors, the logic is slugify(raw.toLowerCase(), {allowedChars: '-'}).

I think that is a good solution. if you support this modification, I can do it and create a pull request. Thanks

Activity

  1. Feder1co5oave commented on Jul 16, 2014

    @Feder1co5oave
    Contributor

    There's no perfect way to slugify any text. I think the best course of action is to define our own slugify function (hopefully based on uslag, since it looks pretty good) and use it to generate ids both in marked and in marked-toc.
    In marked, this is very easy since you can override the renderer function for headings.
    marked-toc lacks this capability. In fact, I think I'm going to post a pull request to allow this.

  2. joshbruce commented on Dec 25, 2017

    @joshbruce
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions