jonschlinkert / markdown-toc

API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files. Uses Remarkable to parse markdown. Used by NASA/openmct, Prisma, Joi, Mocha, Sass, Prettier, Orbit DB, FormatJS, Raneto, hapijs/code, webpack-flow, docusaurus, release-it, ts-loader, json-server, reactfire, bunyan, husky, react-easy-state, react-snap, chakra-ui, carbon, alfresco, repolinter, Assemble, Verb, and thousands of other projects.
https://github.com/jonschlinkert
MIT License
1.62k stars 703 forks source link

links to sections on github with emoji in the heading are broken #119

Open chriseppstein opened 6 years ago

chriseppstein commented 6 years ago

# ⭐️ My Fancy 💅 Heading is assigned an anchor id of -my-fancy--heading but markdown-toc generates an id containing character escapes instead.

doowb commented 6 years ago

@chriseppstein if you're using markdown-toc through the api, you can pass an optional slugify function on options. This one works for this case, but I'm not sure if it'll work for other cases:

const slugify = (title) => {
  return [...toc.slugify(title)]
    .reduce((acc, ch) => {
      if (ch.charCodeAt(0) > 255) {
        return acc;
      }
      return acc + ch;
    }, '');
};

Since we're already doing replaceDiacritics, I wonder if we could do replaceUnicode (I think that's what would it would be called).

PixievoltNo1 commented 5 years ago

This also affect READMEs as displayed on npmjs.com - they follow the GitHub convention of stripping emoji from IDs.