@xiee/utils 1.2.4 → 1.2.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 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.
@@ -0,0 +1,9 @@
1
+ kbd {
2
+ border: 2px solid;
3
+ box-shadow: 2px 2px;
4
+ display: inline-block;
5
+ padding: 0 5px;
6
+ border-radius: 0.25em;
7
+ min-width: 1.5em;
8
+ text-align: center;
9
+ }
@@ -1,8 +1,13 @@
1
- (function() {
2
- var links = document.getElementsByTagName('a');
3
- for (var i = 0; i < links.length; i++) {
4
- if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
5
- links[i].target = '_blank';
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"