docs: add incrementing value to repeated anchors
This commit is contained in:
parent
96fb9a5bbd
commit
451cf00951
1 changed files with 7 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ function generate(pathname) {
|
||||||
if (pathname.match(/\.md$/)) {
|
if (pathname.match(/\.md$/)) {
|
||||||
var outputFilename = pathname.replace(/\.md$/, ".html")
|
var outputFilename = pathname.replace(/\.md$/, ".html")
|
||||||
var markdown = fs.readFileSync(pathname, "utf-8")
|
var markdown = fs.readFileSync(pathname, "utf-8")
|
||||||
|
var anchors = {}
|
||||||
var fixed = markdown
|
var fixed = markdown
|
||||||
.replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags
|
.replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags
|
||||||
return "<code>" + (a + b + c).replace(/\|/g, "|") + "</code>"
|
return "<code>" + (a + b + c).replace(/\|/g, "|") + "</code>"
|
||||||
|
|
@ -53,6 +54,12 @@ function generate(pathname) {
|
||||||
.replace(/<h(.) id="([^"]+?)">(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors
|
.replace(/<h(.) id="([^"]+?)">(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors
|
||||||
var anchor = text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-");
|
var anchor = text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-");
|
||||||
|
|
||||||
|
if(anchor in anchors) {
|
||||||
|
anchor += ++anchors[anchor]
|
||||||
|
} else {
|
||||||
|
anchors[anchor] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return `<h${n} id="${anchor}"><a href="#${anchor}">${text}</a></h${n}>`;
|
return `<h${n} id="${anchor}"><a href="#${anchor}">${text}</a></h${n}>`;
|
||||||
})
|
})
|
||||||
fs.writeFileSync("./dist/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
fs.writeFileSync("./dist/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue