@xiee/utils
Advanced tools
Comparing version 1.13.38 to 1.13.39
@@ -7,3 +7,3 @@ // turn <div class="callout-*"> to <fieldset><legend>* | ||
f.insertAdjacentHTML('afterbegin', '<legend></legend>'); | ||
f.firstChild.dataset.legend = el.dataset.legend || el.classList[0].replace('callout-', ''); | ||
f.firstChild.dataset.legend = el.dataset.legend || el.classList[0].replace('callout-', '').replace('-', ' '); | ||
el.after(f); | ||
@@ -10,0 +10,0 @@ f.append(...el.children); |
@@ -1,1 +0,1 @@ | ||
document.querySelectorAll('div[class^="callout-"]').forEach((e=>{const l=document.createElement("fieldset");l.className=e.className,l.classList.add("callout"),l.insertAdjacentHTML("afterbegin","<legend></legend>"),l.firstChild.dataset.legend=e.dataset.legend||e.classList[0].replace("callout-",""),e.after(l),l.append(...e.children),e.remove()})); | ||
document.querySelectorAll('div[class^="callout-"]').forEach((e=>{const l=document.createElement("fieldset");l.className=e.className,l.classList.add("callout"),l.insertAdjacentHTML("afterbegin","<legend></legend>"),l.firstChild.dataset.legend=e.dataset.legend||e.classList[0].replace("callout-","").replace("-"," "),e.after(l),l.append(...e.children),e.remove()})); |
@@ -17,5 +17,12 @@ // find an element with class `tabset` and convert its subsequent bullet list or headings to tabs; | ||
} | ||
let n = -1, el = h.nextElementSibling, p; | ||
// if the first sibling is <ul>, try to convert it to tabset | ||
if (links.length === 0 && el.tagName === 'UL') { | ||
function isHeading(el) { | ||
return /^H[1-6]$/.test(el.tagName); | ||
} | ||
function isEmpty(el) { | ||
return el.innerHTML.trim() === ''; | ||
} | ||
// if the tabset is heading or empty div, use next sibling, otherwise use first child | ||
let n = -1, p, el = (isHeading(h) || isEmpty(h)) ? h.nextElementSibling : h.firstElementChild; | ||
// if el is <ul>, try to convert it to tabset | ||
if (links.length === 0 && el?.tagName === 'UL') { | ||
[...el.children].forEach(li => { | ||
@@ -42,3 +49,3 @@ const l = li.firstElementChild; | ||
const t = el.tagName; | ||
if (/^H[1-6]$/.test(t)) { | ||
if (isHeading(t)) { | ||
const n2 = +t.replace('H', ''); | ||
@@ -67,3 +74,3 @@ if (n2 <= n) break; // quit after a higher-level heading | ||
// if the initial tabset container is empty, move links and panes into it | ||
if (h.innerText.trim() == '') { | ||
if (isEmpty(h)) { | ||
links.forEach(l => h.append(l)); | ||
@@ -70,0 +77,0 @@ panes.forEach(p => h.append(p)); |
@@ -1,1 +0,1 @@ | ||
document.querySelectorAll(".tabset").forEach((e=>{const t=[...e.querySelectorAll(":scope > .tab-link")],n=[...e.querySelectorAll(":scope > .tab-pane")];function a(e){function a(e,t){e.forEach(((e,n)=>e.classList[n===t?"add":"remove"]("active")))}a(t,e),a(n,e)}function i(e,t){const n=document.createElement(e);return n.className=t,n}let c,r=-1,o=e.nextElementSibling;if(0===t.length&&"UL"===o.tagName&&([...o.children].forEach((e=>{const a=e.firstElementChild;if(!a)return;const c=i("div","tab-link");c.append(a),a.outerHTML=a.innerHTML,/<!--active-->/.test(c.innerHTML)&&c.classList.add("active"),o.before(c);const r=i("div","tab-pane");c.after(r),[...e.children].forEach((e=>r.append(e))),t.push(c),n.push(r)})),o.remove()),0===t.length)for(;o&&("#comment"!==o.nodeName||o.nodeValue.trim()!==`tabset:${e.id}`);){const e=o.tagName;if(/^H[1-6]$/.test(e)){const a=+e.replace("H","");if(a<=r)break;if(r<0&&(r=a-1),a===r+1){c=i("div","tab-pane"),o.after(c),o.classList.add("tab-link"),o.querySelector(".anchor")?.remove(),o.outerHTML=o.outerHTML.replace(/^<h[1-6](.*)h[1-6]>$/,"<div$1div>"),o=c.previousElementSibling,t.push(o),n.push(c),o=c.nextSibling;continue}}c&&(c.append(o),o=c),o=o.nextSibling}""==e.innerText.trim()&&(t.forEach((t=>e.append(t))),n.forEach((t=>e.append(t))));let l=0;t.forEach(((e,n)=>{n>0&&t[n-1].after(e),e.onclick=()=>a(n),e.classList.contains("active")&&(l=n)})),a(l)})); | ||
document.querySelectorAll(".tabset").forEach((e=>{const t=[...e.querySelectorAll(":scope > .tab-link")],n=[...e.querySelectorAll(":scope > .tab-pane")];function a(e){function a(e,t){e.forEach(((e,n)=>e.classList[n===t?"add":"remove"]("active")))}a(t,e),a(n,e)}function i(e,t){const n=document.createElement(e);return n.className=t,n}function r(e){return/^H[1-6]$/.test(e.tagName)}function c(e){return""===e.innerHTML.trim()}let o,l=-1,s=r(e)||c(e)?e.nextElementSibling:e.firstElementChild;if(0===t.length&&"UL"===s?.tagName&&([...s.children].forEach((e=>{const a=e.firstElementChild;if(!a)return;const r=i("div","tab-link");r.append(a),a.outerHTML=a.innerHTML,/<!--active-->/.test(r.innerHTML)&&r.classList.add("active"),s.before(r);const c=i("div","tab-pane");r.after(c),[...e.children].forEach((e=>c.append(e))),t.push(r),n.push(c)})),s.remove()),0===t.length)for(;s&&("#comment"!==s.nodeName||s.nodeValue.trim()!==`tabset:${e.id}`);){const e=s.tagName;if(r(e)){const a=+e.replace("H","");if(a<=l)break;if(l<0&&(l=a-1),a===l+1){o=i("div","tab-pane"),s.after(o),s.classList.add("tab-link"),s.querySelector(".anchor")?.remove(),s.outerHTML=s.outerHTML.replace(/^<h[1-6](.*)h[1-6]>$/,"<div$1div>"),s=o.previousElementSibling,t.push(s),n.push(o),s=o.nextSibling;continue}}o&&(o.append(s),s=o),s=s.nextSibling}c(e)&&(t.forEach((t=>e.append(t))),n.forEach((t=>e.append(t))));let d=0;t.forEach(((e,n)=>{n>0&&t[n-1].after(e),e.onclick=()=>a(n),e.classList.contains("active")&&(d=n)})),a(d)})); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.13.38", | ||
"version": "1.13.39", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
220453
2509