markdown-toc
markdown-toc copied to clipboard
links to sections on github with emoji in the heading are broken
# ⭐️ My Fancy 💅 Heading is assigned an anchor id of -my-fancy--heading but markdown-toc generates an id containing character escapes instead.
@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).
This also affect READMEs as displayed on npmjs.com - they follow the GitHub convention of stripping emoji from IDs.