FEATURE: support non-Latin characters (#4)

This commit is contained in:
Joe 2019-04-19 03:58:36 -07:00 committed by GitHub
parent 4f25b2d213
commit 80c1f17f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 15 deletions

View File

@ -23,10 +23,13 @@
const cleanItem = item const cleanItem = item
.trim() .trim()
.toLowerCase() .toLowerCase()
.replace(/[^\w]+/g, "-") .replace(
/[\{\}\[\]\\\/\<\>\(\)\|\+\?\*\^\'\`\'\"\.\_\d\s~!@#$%&,;:=]/gi,
"-"
)
.replace(/\-\-+/g, "-")
.replace(/^\-/, "") .replace(/^\-/, "")
.replace(/\-$/, "") .replace(/\-$/, "");
.replace(/\-\-+/g, "-");
return cleanItem; return cleanItem;
}; };
@ -45,8 +48,6 @@
const unique = item.attr("id"); const unique = item.attr("id");
const text = item.text(); const text = item.text();
item.attr({ "data-d-toc": unique });
const tocItem = $("<li/>", { const tocItem = $("<li/>", {
class: "d-toc-item", class: "d-toc-item",
"data-d-toc": unique "data-d-toc": unique
@ -298,18 +299,17 @@
let id = heading.attr("id") || ""; let id = heading.attr("id") || "";
if (id.length) { if (!id.length) {
heading
.attr("id", id)
.append(createAnchors(id))
.addClass("d-toc-post-heading");
} else {
id = cleanUp(heading.text()); id = cleanUp(heading.text());
}
heading heading
.attr("id", id) .attr({
id: id,
"data-d-toc": id
})
.append(createAnchors(id)) .append(createAnchors(id))
.addClass("d-toc-post-heading"); .addClass("d-toc-post-heading");
}
}); });
body body