@xiee/utils 1.6.9 → 1.8.0
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/README.md +11 -0
- package/js/faq.js +4 -4
- package/js/faq.min.js +1 -1
- package/js/number-captions.js +18 -0
- package/js/number-captions.min.js +1 -0
- package/js/ol-id.js +23 -0
- package/js/ol-id.min.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,10 +122,21 @@ expressions (by default, MathJax ignores math in `<code>`).
|
|
|
122
122
|
Add the `nohighlight` class to `<code>` in `<pre>` when it does not have a
|
|
123
123
|
class, so that highlight.js will not try to syntax highlight the code in it.
|
|
124
124
|
|
|
125
|
+
## number-captions.js
|
|
126
|
+
|
|
127
|
+
Number figure and table captions.
|
|
128
|
+
|
|
125
129
|
## number-sections.js
|
|
126
130
|
|
|
127
131
|
Find all section headings (`h1` - `h6`) and number them.
|
|
128
132
|
|
|
133
|
+
## ol-id.js
|
|
134
|
+
|
|
135
|
+
Add IDs of the form `li-N` to items in ordered lists, where `N` is the index of
|
|
136
|
+
a list item. This makes it possible to reference or locate a specific item on a
|
|
137
|
+
page by a hash in the URL. If you hold `Alt` and click on an item, you will get
|
|
138
|
+
the URL with the hash in the address bar of your browser.
|
|
139
|
+
|
|
129
140
|
## render-katex.js
|
|
130
141
|
|
|
131
142
|
Simply run `renderMathInElement(document.body)` to render math expression using
|
package/js/faq.js
CHANGED
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
|
|
30
30
|
// add anchor links after questions
|
|
31
31
|
for (let i = 0; i < lis.length; i++) {
|
|
32
|
-
let li = lis[i]
|
|
32
|
+
let li = lis[i];
|
|
33
|
+
li.id = 'faq-' + (id ? id + '-' : '') + (i + 1);
|
|
33
34
|
let p = li.firstElementChild;
|
|
34
|
-
p.
|
|
35
|
-
|
|
36
|
-
if (location.hash === '#' + hash) {
|
|
35
|
+
p.insertAdjacentHTML('beforeend', ` <span class="anchor"><a href="#${li.id}">#</a></span>`);
|
|
36
|
+
if (location.hash === '#' + li.id) {
|
|
37
37
|
li.scrollIntoView();
|
|
38
38
|
li.classList.add(cls_clicked);
|
|
39
39
|
}
|
package/js/faq.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(t=>{const
|
|
1
|
+
(t=>{const e="faq-list",n="faq-clicked";function l(l,o){const i=l.children;if(0===i.length)return;for(let t of i)if(t.childElementCount<2)return;let c=l.classList;if(c.length>0&&!c.contains(e))return;c.add(e);const s=t.createElement("span");let a=!1;s.className="faq-button",s.innerText="⊕",s.onclick=function(){a=!a,this.innerText=a?"⊖":"⊕";for(const t of l.children)t.classList.toggle(n,a)},l.before(s);for(let t=0;t<i.length;t++){let e=i[t];e.id="faq-"+(o?o+"-":"")+(t+1);let l=e.firstElementChild;l.insertAdjacentHTML("beforeend",` <span class="anchor"><a href="#${e.id}">#</a></span>`),location.hash==="#"+e.id&&(e.scrollIntoView(),e.classList.add(n)),l.onclick=function(t){e.classList.toggle(n)}}}const o=t.querySelectorAll(["div","main","section","article"].map((t=>t+":not(.footnotes) > ol")).join(","));for(let t=0;t<o.length;t++){l(o[t],o.length>1?t+1:0)}})(document);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// number figure and table captions
|
|
2
|
+
|
|
3
|
+
// config options via data-foo attributes of this <script>:
|
|
4
|
+
// * data-colon: the colon character (':' by default);
|
|
5
|
+
// * data-fig-label: label for figure captions ('Figure ' by default)
|
|
6
|
+
// * data-tab-label: lable for table captions ('Table ' by default)
|
|
7
|
+
(d => {
|
|
8
|
+
const cfg = d.currentScript?.dataset, colon = cfg?.colon || ':';
|
|
9
|
+
function NUM(target, label) {
|
|
10
|
+
d.querySelectorAll(target).forEach((el, i) => {
|
|
11
|
+
// do not number it again if already numbered
|
|
12
|
+
el.querySelector('.cap-num') ||
|
|
13
|
+
el.insertAdjacentHTML('afterbegin', `<span class="cap-num">${label}${i + 1}${colon}</span> `);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
NUM('figure > figcaption, .figure > p.caption, .float > .figcaption', cfg?.figLabel || 'Figure ');
|
|
17
|
+
NUM('table > caption', cfg?.tabLabel || 'Table ');
|
|
18
|
+
})(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(a=>{const e=a.currentScript?.dataset,t=e?.colon||":";function c(e,c){a.querySelectorAll(e).forEach(((a,e)=>{a.querySelector(".cap-num")||a.insertAdjacentHTML("afterbegin",`<span class="cap-num">${c}${e+1}${t}</span> `)}))}c("figure > figcaption, .figure > p.caption, .float > .figcaption",e?.figLabel||"Figure "),c("table > caption",e?.tabLabel||"Table ")})(document);
|
package/js/ol-id.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// add ID to <ol> items so that they can be referenced via URL hashes like #li-N
|
|
2
|
+
((d) => {
|
|
3
|
+
// add IDs to top-level <ol>s
|
|
4
|
+
const ols = d.querySelectorAll(':not(li) > ol');
|
|
5
|
+
ols.forEach((ol, i) => {
|
|
6
|
+
ol.querySelectorAll(':scope > li').forEach((li, j) => {
|
|
7
|
+
if (!li.id) li.id = 'li-' + (ols.length > 1 ? i + 1 + '-' : '') + (j + 1);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
// add IDs to all <ol>s
|
|
11
|
+
d.querySelectorAll('ol').forEach((ol, i) => {
|
|
12
|
+
let l = ol.parentNode, id, p; // p: ID prefix
|
|
13
|
+
if (l?.tagName === 'LI') id = l.id;
|
|
14
|
+
p = (id ? id : 'li-' + (i + 1)) + '-';
|
|
15
|
+
ol.querySelectorAll(':scope > li').forEach((li, j) => {
|
|
16
|
+
if (!li.id) li.id = p + (j + 1);
|
|
17
|
+
// Alt + Click => adding hash to URL
|
|
18
|
+
li.addEventListener('click', e => {
|
|
19
|
+
e.altKey && (location.hash = li.id, e.stopPropagation());
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
})(document);
|
package/js/ol-id.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(e=>{const l=e.querySelectorAll(":not(li) > ol");l.forEach(((e,o)=>{e.querySelectorAll(":scope > li").forEach(((e,t)=>{e.id||(e.id="li-"+(l.length>1?o+1+"-":"")+(t+1))}))})),e.querySelectorAll("ol").forEach(((e,l)=>{let o,t,c=e.parentNode;"LI"===c?.tagName&&(o=c.id),t=(o||"li-"+(l+1))+"-",e.querySelectorAll(":scope > li").forEach(((e,l)=>{e.id||(e.id=t+(l+1)),e.addEventListener("click",(l=>{l.altKey&&(location.hash=e.id,l.stopPropagation())}))}))}))})(document);
|