@xiee/utils 1.1.4 → 1.1.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/faq.css +3 -6
- package/js/fix-footnote.js +7 -3
- package/js/hash-notes.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,13 @@ to render unique `id`s for the footnote items (the `id` is `fn:-`).
|
|
|
58
58
|
|
|
59
59
|
Fix the table of contents generated by lower versions of Hugo.
|
|
60
60
|
|
|
61
|
+
## hash-notes.js
|
|
62
|
+
|
|
63
|
+
Convert HTML comments of the form `<!--# comments -->` to
|
|
64
|
+
`<span class="hash-note">comments</span>`. If such comments are found, the
|
|
65
|
+
document body will gain classes `has-notes` and `hide-notes`. You can use CSS to
|
|
66
|
+
style the notes or hide/show them as you wish.
|
|
67
|
+
|
|
61
68
|
## header-link.js
|
|
62
69
|
|
|
63
70
|
Add anchor links to all section headers (e.g., `<h2>`) that have nonempty `id`
|
package/css/faq.css
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
.faq-list > li > :first-child {
|
|
5
5
|
display: block;
|
|
6
6
|
cursor: pointer;
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
margin: -.5em;
|
|
9
|
+
padding: .5em;
|
|
7
10
|
}
|
|
8
11
|
.faq-list > :not(.faq-clicked) > * {
|
|
9
12
|
display: none;
|
|
@@ -20,11 +23,5 @@
|
|
|
20
23
|
}
|
|
21
24
|
.faq-list > li {
|
|
22
25
|
border: 1px solid #eee;
|
|
23
|
-
}
|
|
24
|
-
.faq-list > li > :first-child {
|
|
25
|
-
background: #fafafa;
|
|
26
|
-
margin: 0;
|
|
27
|
-
}
|
|
28
|
-
.faq-list > li > * {
|
|
29
26
|
padding: .5em;
|
|
30
27
|
}
|
package/js/fix-footnote.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function() {
|
|
1
|
+
(function(d) {
|
|
2
2
|
function fix_footnote(tagName) {
|
|
3
|
-
|
|
3
|
+
let tags = d.getElementsByTagName(tagName), i, tag, tag2, n = 1, href;
|
|
4
4
|
for (i = 0; i < tags.length; i++) {
|
|
5
5
|
tag = tags[i];
|
|
6
6
|
if (tagName === 'sup') {
|
|
@@ -25,4 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
fix_footnote('sup'); fix_footnote('li');
|
|
28
|
-
|
|
28
|
+
// move the return symbol into the previous <p>
|
|
29
|
+
d.querySelectorAll('.footnotes > ol > li > p ~ .footnote-return').forEach(el => {
|
|
30
|
+
el.previousElementSibling.lastChild.after(el);
|
|
31
|
+
});
|
|
32
|
+
})(document);
|
package/js/hash-notes.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// convert <!--# comments --> to <span class="hash-notes">comments</span>
|
|
2
|
+
(function(d) {
|
|
3
|
+
function toSpan(el) {
|
|
4
|
+
const t = el.textContent, r = /^#[\s\n]+([\s\S]+)[\s\n]+$/;
|
|
5
|
+
if (!r.test(t)) return;
|
|
6
|
+
d.body.classList.add('has-notes', 'hide-notes');
|
|
7
|
+
// use <p> if the comment's parent is not <p>; otherwise use inline <span>
|
|
8
|
+
const s = d.createElement(el.parentNode.nodeName === 'P' ? 'span' : 'p');
|
|
9
|
+
s.className = 'hash-note';
|
|
10
|
+
s.innerText = t.replace(r, '$1');
|
|
11
|
+
s.innerHTML = s.innerHTML
|
|
12
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank">$1</a>')
|
|
13
|
+
.replace(/(^|[^"])(https?:\/\/)([-a-zA-Z0-9%._=/\+]+)(#)?([-a-zA-Z0-9%._=\+]+)?/g, '$1<a href="$2$3$4$5" target="_blank">$3$4</a>');
|
|
14
|
+
el.before(s);
|
|
15
|
+
el.remove();
|
|
16
|
+
};
|
|
17
|
+
function findComments(el) {
|
|
18
|
+
el.childNodes.forEach(node => {
|
|
19
|
+
node.nodeType === Node.COMMENT_NODE ? toSpan(node) : findComments(node);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
findComments(d.body);
|
|
23
|
+
})(document);
|