@xiee/utils 1.11.2 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/appendix.js +15 -1
- package/js/appendix.min.js +1 -1
- package/package.json +1 -1
package/js/appendix.js
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
// find <h[1-6] class="appendix"> and
|
|
1
|
+
// find <h[1-6] class="appendix"> and either add the class 'appendix' to
|
|
2
|
+
// wrappers of appendix elements or create a new <div> next to the parent
|
|
2
3
|
// element to hold all appendix elements
|
|
3
4
|
(d => {
|
|
4
5
|
const h = d.querySelector([1, 2, 3, 4, 5, 6].map(i => `h${i}.appendix`).join(','));
|
|
5
6
|
if (!h) return;
|
|
6
7
|
h.classList.remove('appendix');
|
|
8
|
+
// if h is in a wrapper whose next sibling has the same class, simply add class to wrappers
|
|
9
|
+
const p1 = h.parentNode; let p2 = p1, wrapper = false;
|
|
10
|
+
while (p1) {
|
|
11
|
+
p2 = p2.nextElementSibling;
|
|
12
|
+
if (!p2 || p1.tagName !== p2.tagName || p1.className !== p2.className) break;
|
|
13
|
+
p2.classList.add('appendix');
|
|
14
|
+
wrapper = true;
|
|
15
|
+
}
|
|
16
|
+
if (wrapper) {
|
|
17
|
+
p1.classList.add('appendix');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// create a new div instead
|
|
7
21
|
const a = d.createElement('div');
|
|
8
22
|
a.className = 'appendix';
|
|
9
23
|
a.append(h.cloneNode(true));
|
package/js/appendix.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(e=>{const
|
|
1
|
+
(e=>{const a=e.querySelector([1,2,3,4,5,6].map((e=>`h${e}.appendix`)).join(","));if(!a)return;a.classList.remove("appendix");const n=a.parentNode;let t=n,d=!1;for(;n&&(t=t.nextElementSibling,t&&n.tagName===t.tagName&&n.className===t.className);)t.classList.add("appendix"),d=!0;if(d)return void n.classList.add("appendix");const p=e.createElement("div");for(p.className="appendix",p.append(a.cloneNode(!0));a.nextSibling;)p.append(a.nextSibling);"BODY"===a.parentNode.tagName?e.body.append(p):a.parentNode.after(p),a.remove()})(document);
|