@xiee/utils 1.2.7 → 1.2.9
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 +2 -1
- package/css/key-buttons.css +1 -0
- package/js/fix-footnote.js +4 -26
- package/js/key-buttons.js +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,8 @@ attributes.
|
|
|
75
75
|
Find keyboard keys in `<code></code>` and convert the tag to `<kbd></kbd>`,
|
|
76
76
|
e.g., convert `<code>Ctrl + C</code>` to `<kbd>Ctrl</kbd>` + `<kbd>C</kbd>`.
|
|
77
77
|
With `key-buttons.css`, the keys will be styled as boxes with shadows like
|
|
78
|
-
buttons.
|
|
78
|
+
buttons. You can learn more details [in this
|
|
79
|
+
post](https://yihui.org/en/2023/02/key-buttons/).
|
|
79
80
|
|
|
80
81
|
## load-highlight.js
|
|
81
82
|
|
package/css/key-buttons.css
CHANGED
package/js/fix-footnote.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
(function(d) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (tagName === 'sup') {
|
|
7
|
-
if (tag.className !== 'footnote-ref' || tag.id !== 'fnref:-') continue;
|
|
8
|
-
tag.id += n;
|
|
9
|
-
if (tag.children.length === 1) {
|
|
10
|
-
tag2 = tag.children[0];
|
|
11
|
-
href = tag2.getAttribute('href');
|
|
12
|
-
if (tag2.nodeName === 'A' && href === '#fn:-') {
|
|
13
|
-
tag2.setAttribute('href', href + n);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
} else if (tagName === 'li') {
|
|
17
|
-
if (tag.id !== 'fn:-') continue;
|
|
18
|
-
tag.id += n;
|
|
19
|
-
tag2 = tag.lastChild; href = tag2.getAttribute('href');
|
|
20
|
-
if (tag2.nodeName === 'A' && href === '#fnref:-') {
|
|
21
|
-
tag2.setAttribute('href', href + n);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n++;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
fix_footnote('sup'); fix_footnote('li');
|
|
2
|
+
// add [] to footnote numbers
|
|
3
|
+
d.querySelectorAll('sup[id^="fnref:"] > a.footnote-ref, a.footnote-ref > sup').forEach(el => {
|
|
4
|
+
if (/^[0-9]+$/.test(el.innerText)) el.innerText = ' [' + el.innerText + ']';
|
|
5
|
+
});
|
|
28
6
|
// move the return symbol into the previous <p>
|
|
29
7
|
d.querySelectorAll('.footnotes > ol > li > p ~ .footnote-return').forEach(el => {
|
|
30
8
|
el.previousElementSibling.lastChild.after(el);
|
package/js/key-buttons.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
(function(d) {
|
|
2
|
+
const a1 = ['Enter', 'Up', 'Down', 'Left', 'Right'];
|
|
3
|
+
const a2 = ['↵', '↑', '↓', '←', '→'];
|
|
4
|
+
function drawArrows(x) {
|
|
5
|
+
a1.map((v, i) => x = x.replace(new RegExp('>' + v + '<', 'g'), ' title="' + v + (i ? ' Arrow' : '') + '">' + a2[i] + '<'));
|
|
6
|
+
return x;
|
|
7
|
+
}
|
|
2
8
|
// 1. individual keys; 2. modifiers; 3. normal keys
|
|
3
|
-
const k1 = 'Esc|Tab|
|
|
4
|
-
Array(12).fill().map((v, i) => 'F' + (i + 1)).join('|'),
|
|
9
|
+
const k1 = 'Esc|Tab|PageUp|PageDown|Space|Delete|Home|End|PrtScr?|PrintScreen|' +
|
|
10
|
+
Array(12).fill().map((v, i) => 'F' + (i + 1)).concat(a1).join('|'),
|
|
5
11
|
k2 = 'Ctrl|Control|Shift|Alt|Cmd|Command|fn',
|
|
6
12
|
k3 = '[a-zA-Z0-9]|Click',
|
|
7
13
|
r1 = new RegExp('^(' + k1 + '|' + k2 + ')$'),
|
|
@@ -11,7 +17,7 @@
|
|
|
11
17
|
if (el.childElementCount > 0) return;
|
|
12
18
|
let t = el.innerText;
|
|
13
19
|
if (r1.test(t)) {
|
|
14
|
-
el.outerHTML = '<kbd>' + t + '</kbd>';
|
|
20
|
+
el.outerHTML = drawArrows('<kbd>' + t + '</kbd>');
|
|
15
21
|
return;
|
|
16
22
|
}
|
|
17
23
|
if (!r2.test(t)) return;
|
|
@@ -20,6 +26,6 @@
|
|
|
20
26
|
t2 += t.replace(r3, '<kbd>$1</kbd>$2');
|
|
21
27
|
t = t.replace(r3, '$3');
|
|
22
28
|
}
|
|
23
|
-
if (t === '') el.outerHTML = t2.replace(/ \+ $/, '');
|
|
29
|
+
if (t === '') el.outerHTML = drawArrows(t2.replace(/ \+ $/, ''));
|
|
24
30
|
});
|
|
25
31
|
})(document);
|