@xiee/utils 1.7.0 → 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 CHANGED
@@ -122,6 +122,10 @@ 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.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"