@xiee/utils 1.6.4 → 1.6.6
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 +5 -0
- package/js/dl-fieldset.js +11 -0
- package/js/dl-fieldset.min.js +1 -0
- package/js/fix-footnote.js +1 -1
- package/js/fix-footnote.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,11 @@ of their parent element.
|
|
|
37
37
|
Add a copy button to any element (by default, `<pre>` code blocks) on a page.
|
|
38
38
|
See [this post](https://yihui.org/en/2023/09/copy-button/) for details.
|
|
39
39
|
|
|
40
|
+
## dl-fieldset.js
|
|
41
|
+
|
|
42
|
+
Convert definition lists `<dl>` to `<fieldset>`. See more information [in this
|
|
43
|
+
post](https://yihui.org/en/2023/11/dl-fieldset/).
|
|
44
|
+
|
|
40
45
|
## external-link.js
|
|
41
46
|
|
|
42
47
|
If a link of `<a>` does not start with `http://` or `https://`, add the
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// convert <dl><dt>Title</dt><dd>Content</dd></dl>
|
|
2
|
+
// to <fieldset><legend>Title</legend>Content</fieldset>;
|
|
3
|
+
// see documentation at: https://yihui.org/en/2023/11/dl-fieldset/
|
|
4
|
+
document.querySelectorAll('dl').forEach(dl => {
|
|
5
|
+
if (dl.childElementCount !== 2) return;
|
|
6
|
+
const dt = dl.children[0], dd = dl.children[1];
|
|
7
|
+
if (dt.tagName !== 'DT' || dd.tagName !== 'DD') return;
|
|
8
|
+
dt.outerHTML = dt.outerHTML.replace(/^<dt(>[\s\S]*<\/)dt>$/, '<legend$1legend>');
|
|
9
|
+
dd.outerHTML = dd.innerHTML;
|
|
10
|
+
dl.outerHTML = dl.outerHTML.replace(/^<dl(>[\s\S]*<\/)dl>$/, '<fieldset$1fieldset>');
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
document.querySelectorAll("dl").forEach((e=>{if(2!==e.childElementCount)return;const t=e.children[0],l=e.children[1];"DT"===t.tagName&&"DD"===l.tagName&&(t.outerHTML=t.outerHTML.replace(/^<dt(>[\s\S]*<\/)dt>$/,"<legend$1legend>"),l.outerHTML=l.innerHTML,e.outerHTML=e.outerHTML.replace(/^<dl(>[\s\S]*<\/)dl>$/,"<fieldset$1fieldset>"))}));
|
package/js/fix-footnote.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
d.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach(el => {
|
|
4
4
|
if (!/^[0-9]+$/.test(el.innerText)) return;
|
|
5
5
|
el.innerText = `[${el.innerText}]`;
|
|
6
|
-
el.before(d.createTextNode(' '));
|
|
6
|
+
el.parentNode.before(d.createTextNode(' '));
|
|
7
7
|
});
|
|
8
8
|
// move the return symbol into the previous <p>
|
|
9
9
|
d.querySelectorAll('.footnotes > ol > li > p ~ .footnote-return').forEach(el => {
|
package/js/fix-footnote.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(e=>{e.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach((t=>{/^[0-9]+$/.test(t.innerText)&&(t.innerText=`[${t.innerText}]`,t.before(e.createTextNode(" ")))})),e.querySelectorAll(".footnotes > ol > li > p ~ .footnote-return").forEach((e=>{e.previousElementSibling.lastChild.after(e)}))})(document);
|
|
1
|
+
(e=>{e.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach((t=>{/^[0-9]+$/.test(t.innerText)&&(t.innerText=`[${t.innerText}]`,t.parentNode.before(e.createTextNode(" ")))})),e.querySelectorAll(".footnotes > ol > li > p ~ .footnote-return").forEach((e=>{e.previousElementSibling.lastChild.after(e)}))})(document);
|