@xiee/utils 1.1.3 → 1.1.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
@@ -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`
@@ -0,0 +1,25 @@
1
+ /* Add circled numbers to h2 and TOC items generated by Hugo */
2
+ #TableOfContents, #TableOfContents ~ p:first-of-type { counter-reset: circled-numbers; }
3
+ h2::before, #TableOfContents > ul > li > ul > li::before {
4
+ counter-increment: circled-numbers;
5
+ content: counter(circled-numbers);
6
+ border-radius: 50%;
7
+ border: 1px dashed #999;
8
+ color: #333;
9
+ background: white;
10
+ display: inline-block;
11
+ min-width: 1.75em;
12
+ line-height: 1.75em;
13
+ margin-right: .5em;
14
+ text-align: center;
15
+ font-size: .8em;
16
+ }
17
+ h2::before {
18
+ vertical-align: bottom;
19
+ color: white;
20
+ border: none;
21
+ background: #999;
22
+ }
23
+ #TableOfContents > ul > li > ul > li {
24
+ display: inline-block;
25
+ }
@@ -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%._#=/\+]+)/g, '<a href="$1$2" target="_blank">$2</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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.1.3",
3
+ "version": "1.1.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"