@xiee/utils 1.3.11 → 1.3.13
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 +19 -0
- package/js/math-code.js +12 -19
- package/js/math-code.min.js +1 -1
- package/js/toc-highlight.js +21 -0
- package/js/toc-highlight.min.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,12 @@ Add `[ ]` to footnote numbers and move the return symbols in footnotes.
|
|
|
56
56
|
|
|
57
57
|
Fix the table of contents generated by lower versions of Hugo.
|
|
58
58
|
|
|
59
|
+
## fullwidth.js
|
|
60
|
+
|
|
61
|
+
Find `<pre>` and `<table>` elements and add the `fullwidth` class to them if
|
|
62
|
+
they are too wide, so they can be styled differently (e.g., [full
|
|
63
|
+
bleed](https://css-tricks.com/full-bleed/)).
|
|
64
|
+
|
|
59
65
|
## hash-notes.js
|
|
60
66
|
|
|
61
67
|
Convert HTML comments of the form `<!--# comments -->` to
|
|
@@ -93,6 +99,10 @@ expressions (by default, MathJax ignores math in `<code>`).
|
|
|
93
99
|
Add the `nohighlight` class to `<code>` in `<pre>` when it does not have a
|
|
94
100
|
class, so that highlight.js will not try to syntax highlight the code in it.
|
|
95
101
|
|
|
102
|
+
## number-sections.js
|
|
103
|
+
|
|
104
|
+
Find all section headings (`h1` - `h6`) and number them.
|
|
105
|
+
|
|
96
106
|
## render-katex.js
|
|
97
107
|
|
|
98
108
|
Simply run `renderMathInElement(document.body)` to render math expression using
|
|
@@ -102,3 +112,12 @@ KaTeX's auto-render extension.
|
|
|
102
112
|
|
|
103
113
|
Right-align a `<blockquote>` footer if the footer is a `<p>` that starts with
|
|
104
114
|
the em-dash.
|
|
115
|
+
|
|
116
|
+
## toc.js
|
|
117
|
+
|
|
118
|
+
Automatically build a table of contents (TOC) from all section headings.
|
|
119
|
+
|
|
120
|
+
## toc-highlight.js
|
|
121
|
+
|
|
122
|
+
Add a class `active` to the TOC item (`<a>`) corresponding to the section
|
|
123
|
+
heading that is currently being scrolled into view.
|
package/js/math-code.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
|
|
8
|
-
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
|
|
9
|
-
code.textContent = text;
|
|
10
|
-
}
|
|
11
|
-
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
|
|
12
|
-
/^\$(.|\s)+\$$/.test(text) ||
|
|
13
|
-
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
|
|
14
|
-
code.outerHTML = code.innerHTML; // remove <code></code>
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
i++;
|
|
1
|
+
[...document.getElementsByTagName('code')].forEach(code => {
|
|
2
|
+
if (code.parentNode.tagName === 'PRE' || code.childElementCount > 0) return;
|
|
3
|
+
const text = code.textContent;
|
|
4
|
+
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
|
|
5
|
+
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
|
|
6
|
+
code.textContent = text;
|
|
19
7
|
}
|
|
20
|
-
|
|
8
|
+
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
|
|
9
|
+
/^\$(.|\s)+\$$/.test(text) ||
|
|
10
|
+
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
|
|
11
|
+
code.outerHTML = code.innerHTML; // remove <code></code>
|
|
12
|
+
}
|
|
13
|
+
});
|
package/js/math-code.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
[...document.getElementsByTagName("code")].forEach((e=>{if("PRE"===e.parentNode.tagName||e.childElementCount>0)return;const t=e.textContent;/^\$[^$]/.test(t)&&/[^$]\$$/.test(t)&&(t=t.replace(/^\$/,"\\(").replace(/\$$/,"\\)"),e.textContent=t),(/^\\\((.|\s)+\\\)$/.test(t)||/^\\\[(.|\s)+\\\]$/.test(t)||/^\$(.|\s)+\$$/.test(t)||/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(t))&&(e.outerHTML=e.innerHTML)}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// highlight a TOC item when scrolling to a corresponding section heading
|
|
2
|
+
(function(d) {
|
|
3
|
+
// assume TOC has these possible IDs (we can also consider other selectors)
|
|
4
|
+
const toc = d.querySelector('#TableOfContents, #TOC');
|
|
5
|
+
if (!toc) return;
|
|
6
|
+
const links = toc.querySelectorAll('a');
|
|
7
|
+
if (!links.length) return;
|
|
8
|
+
|
|
9
|
+
// create a new Intersection Observer instance
|
|
10
|
+
const observer = new IntersectionObserver(els => els.forEach(el => {
|
|
11
|
+
const id = el.target.id;
|
|
12
|
+
id && el.isIntersecting && links.forEach(a => {
|
|
13
|
+
a.classList[(a.getAttribute('href') === '#' + id) ? 'add' : 'remove']('active');
|
|
14
|
+
});
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
// observe all section headings
|
|
18
|
+
d.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(h => {
|
|
19
|
+
h.nodeType === 1 && observer.observe(h);
|
|
20
|
+
});
|
|
21
|
+
})(document);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){const t=e.querySelector("#TableOfContents, #TOC");if(!t)return;const r=t.querySelectorAll("a");if(!r.length)return;const n=new IntersectionObserver((e=>e.forEach((e=>{const t=e.target.id;t&&e.isIntersecting&&r.forEach((e=>{e.classList[e.getAttribute("href")==="#"+t?"add":"remove"]("active")}))}))));e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach((e=>{1===e.nodeType&&n.observe(e)}))}(document);
|