@xiee/utils 1.2.4 → 1.2.7
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 +7 -0
- package/css/key-buttons.css +14 -0
- package/js/external-link.js +12 -7
- package/js/key-buttons.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,6 +70,13 @@ style the notes or hide/show them as you wish.
|
|
|
70
70
|
Add anchor links to all section headers (e.g., `<h2>`) that have nonempty `id`
|
|
71
71
|
attributes.
|
|
72
72
|
|
|
73
|
+
## key-buttons.js
|
|
74
|
+
|
|
75
|
+
Find keyboard keys in `<code></code>` and convert the tag to `<kbd></kbd>`,
|
|
76
|
+
e.g., convert `<code>Ctrl + C</code>` to `<kbd>Ctrl</kbd>` + `<kbd>C</kbd>`.
|
|
77
|
+
With `key-buttons.css`, the keys will be styled as boxes with shadows like
|
|
78
|
+
buttons.
|
|
79
|
+
|
|
73
80
|
## load-highlight.js
|
|
74
81
|
|
|
75
82
|
Disable highlight.js's auto language detection, and then apply highlighting.
|
package/js/external-link.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
(function(d) {
|
|
2
|
+
const r = /^(https?:)?\/\//;
|
|
3
|
+
d.querySelectorAll('a').forEach(a => {
|
|
4
|
+
// add _blank target to external links
|
|
5
|
+
if (r.test(a.getAttribute('href'))) {
|
|
6
|
+
a.target = '_blank';
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// shorten bare links
|
|
9
|
+
if (a.childElementCount === 0) {
|
|
10
|
+
a.innerText = a.innerText.replace(r, '').replace(/#.*$/, '');
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
})(document);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
(function(d) {
|
|
2
|
+
// 1. individual keys; 2. modifiers; 3. normal keys
|
|
3
|
+
const k1 = 'Esc|Tab|Enter|PageUp|PageDown|Up|Down|Left|Right|' +
|
|
4
|
+
Array(12).fill().map((v, i) => 'F' + (i + 1)).join('|'),
|
|
5
|
+
k2 = 'Ctrl|Control|Shift|Alt|Cmd|Command|fn',
|
|
6
|
+
k3 = '[a-zA-Z0-9]|Click',
|
|
7
|
+
r1 = new RegExp('^(' + k1 + '|' + k2 + ')$'),
|
|
8
|
+
r2 = new RegExp('^(' + k2 + ') [/+] '),
|
|
9
|
+
r3 = new RegExp('^(' + [k1, k2, k3].join('|') + ')( [/+] )(.*)');
|
|
10
|
+
d.querySelectorAll(':not(pre) > code').forEach(el => {
|
|
11
|
+
if (el.childElementCount > 0) return;
|
|
12
|
+
let t = el.innerText;
|
|
13
|
+
if (r1.test(t)) {
|
|
14
|
+
el.outerHTML = '<kbd>' + t + '</kbd>';
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!r2.test(t)) return;
|
|
18
|
+
let t2 = ''; t += ' + ';
|
|
19
|
+
while (r3.test(t)) {
|
|
20
|
+
t2 += t.replace(r3, '<kbd>$1</kbd>$2');
|
|
21
|
+
t = t.replace(r3, '$3');
|
|
22
|
+
}
|
|
23
|
+
if (t === '') el.outerHTML = t2.replace(/ \+ $/, '');
|
|
24
|
+
});
|
|
25
|
+
})(document);
|