@xiee/utils
Advanced tools
Comparing version 1.3.7 to 1.3.8
@@ -11,6 +11,9 @@ // build TOC using headings | ||
var toc = d.getElementById('TOC'); | ||
toc?.remove(); // delete and rebuild TOC if it has been generated (e.g., by Pandoc) | ||
toc = d.createElement('div'); | ||
toc.id = 'TOC'; | ||
let toc = d.getElementById('TOC'); | ||
if (toc) { | ||
toc.innerHTML = ''; // empty and rebuild TOC if it has been generated (e.g., by Pandoc) | ||
} else { | ||
toc = d.createElement('div'); | ||
toc.id = 'TOC'; | ||
} | ||
@@ -48,5 +51,7 @@ let li, ul; | ||
}); | ||
// 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); | ||
if (!toc.parentNode) { | ||
// 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); | ||
} | ||
@@ -53,0 +58,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([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); | ||
(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;let n,i,l=e.getElementById("TOC");l?l.innerHTML="":(l=e.createElement("div"),l.id="TOC");let a,d=l,o=0;if(r.forEach((t=>{if(a=parseInt(t.tagName.replace(/^h/i,"")),n=e.createElement("li"),a>o)i=e.createElement("ul"),i.appendChild(n),d.appendChild(i);else if(a<o)for(let e=0;e<o-a;e++)d=d.parentNode.parentNode;a<=o&&d.parentNode.appendChild(n),d=n;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})),!l.parentNode){const e=t.querySelector("header");e?e.after(l):t.insertBefore(l,t.firstChild)}l.querySelector("span.section-number")&&l.firstElementChild.classList.add("numbered")})(document); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.3.7", | ||
"version": "1.3.8", | ||
"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
50113
784