diff --git a/common/header.html b/common/header.html index fe592cb..38e85ec 100644 --- a/common/header.html +++ b/common/header.html @@ -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 = $("
", { 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) - .append(createAnchors(id)) - .addClass("d-toc-post-heading"); } + + heading + .attr({ + id: id, + "data-d-toc": id + }) + .append(createAnchors(id)) + .addClass("d-toc-post-heading"); }); body