diff --git a/src/bin/doc/html.js b/src/bin/doc/html.js
index f4be7ce13..ff07ae7c8 100644
--- a/src/bin/doc/html.js
+++ b/src/bin/doc/html.js
@@ -146,15 +146,16 @@ const buildToc = (lexed, filename, cb) => {
lexed.forEach((tok) => {
if (tok.type !== 'heading') return;
if (tok.depth - depth > 1) {
- return cb(new Error(`Inappropriate heading level\n${
- JSON.stringify(tok)}`));
+ return cb(new Error(`Inappropriate heading level\n${JSON.stringify(tok)}`));
}
depth = tok.depth;
- const id = getId(`${filename}_${tok.text.trim()}`);
- toc.push(`${new Array((depth - 1) * 2 + 1).join(' ')
- }* ${
- tok.text}`);
+
+ const slugger = new marked.Slugger();
+ const id = slugger.slug(`${filename}_${tok.text.trim()}`);
+
+ toc.push(`${new Array((depth - 1) * 2 + 1).join(' ')}* ${tok.text}`);
+
tok.text += `#`;
});
@@ -162,17 +163,3 @@ const buildToc = (lexed, filename, cb) => {
toc = marked.parse(toc.join('\n'));
cb(null, toc);
};
-
-const idCounters = {};
-const getId = (text) => {
- text = text.toLowerCase();
- text = text.replace(/[^a-z0-9]+/g, '_');
- text = text.replace(/^_+|_+$/, '');
- text = text.replace(/^([^a-z])/, '_$1');
- if (Object.prototype.hasOwnProperty.call(idCounters, text)) {
- text += `_${++idCounters[text]}`;
- } else {
- idCounters[text] = 0;
- }
- return text;
-};