@xiee/utils
Advanced tools
Comparing version 1.3.6 to 1.3.7
@@ -8,3 +8,3 @@ // build TOC using headings | ||
}); | ||
const hs = b.querySelectorAll('h1, h2, h3, h4, h5, h6'); | ||
const hs = b.querySelectorAll([1, 2, 3, 4, 5, 6].map(i => `:scope > h${i}`).join(',')); | ||
if (hs.length === 0) return; | ||
@@ -48,3 +48,5 @@ | ||
}); | ||
b.insertBefore(toc, b.firstChild); | ||
// if there is <header> in the article body, insert TOC after it | ||
const header = b.querySelector('header'); | ||
header ? header.after(toc) : b.insertBefore(toc, b.firstChild); | ||
@@ -51,0 +53,0 @@ // check if headings are numbered |
@@ -1,1 +0,1 @@ | ||
(e=>{let t;[".article",".body","article","body"].forEach((r=>{t||(t=e.querySelector(r))}));const r=t.querySelectorAll("h1, h2, h3, h4, h5, h6");if(0===r.length)return;var n=e.getElementById("TOC");let l,i;n?.remove(),(n=e.createElement("div")).id="TOC";let a,d=n,c=0;r.forEach((t=>{if(a=parseInt(t.tagName.replace(/^h/i,"")),l=e.createElement("li"),a>c)i=e.createElement("ul"),i.appendChild(l),d.appendChild(i);else if(a<c)for(let e=0;e<c-a;e++)d=d.parentNode.parentNode;a<=c&&d.parentNode.appendChild(l),d=l;const r=e.createElement("a");if(r.innerHTML=t.innerHTML,t.id)r.href="#"+t.id;else{const e=t.parentNode;e.classList.contains("section")&&e.id&&(r.href="#"+e.id)}d.appendChild(r),c=a})),t.insertBefore(n,t.firstChild),n.querySelector("span.section-number")&&n.firstElementChild.classList.add("numbered")})(document); | ||
(e=>{let t;[".article",".body","article","body"].forEach((r=>{t||(t=e.querySelector(r))}));const r=t.querySelectorAll([1,2,3,4,5,6].map((e=>`:scope > h${e}`)).join(","));if(0===r.length)return;var n=e.getElementById("TOC");let l,i;n?.remove(),(n=e.createElement("div")).id="TOC";let a,d=n,o=0;r.forEach((t=>{if(a=parseInt(t.tagName.replace(/^h/i,"")),l=e.createElement("li"),a>o)i=e.createElement("ul"),i.appendChild(l),d.appendChild(i);else if(a<o)for(let e=0;e<o-a;e++)d=d.parentNode.parentNode;a<=o&&d.parentNode.appendChild(l),d=l;const r=e.createElement("a");if(r.innerHTML=t.innerHTML,t.id)r.href="#"+t.id;else{const e=t.parentNode;e.classList.contains("section")&&e.id&&(r.href="#"+e.id)}d.appendChild(r),o=a}));const c=t.querySelector("header");c?c.after(n):t.insertBefore(n,t.firstChild),n.querySelector("span.section-number")&&n.firstElementChild.classList.add("numbered")})(document); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.3.6", | ||
"version": "1.3.7", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50020
779