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