From 451cf00951ca268e9bedfbe733482d5f59971d61 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 10 Apr 2017 23:31:56 -0700 Subject: [PATCH] docs: add incrementing value to repeated anchors --- docs/generate.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/generate.js b/docs/generate.js index 52bc3e70..4bc76499 100644 --- a/docs/generate.js +++ b/docs/generate.js @@ -27,6 +27,7 @@ function generate(pathname) { if (pathname.match(/\.md$/)) { var outputFilename = pathname.replace(/\.md$/, ".html") var markdown = fs.readFileSync(pathname, "utf-8") + var anchors = {} var fixed = markdown .replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags return "" + (a + b + c).replace(/\|/g, "|") + "" @@ -53,6 +54,12 @@ function generate(pathname) { .replace(/(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors var anchor = text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-"); + if(anchor in anchors) { + anchor += ++anchors[anchor] + } else { + anchors[anchor] = 0; + } + return `${text}`; }) fs.writeFileSync("./dist/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")