@xiee/utils 1.3.16 → 1.3.18

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,9 +58,9 @@ Fix the table of contents generated by lower versions of Hugo.
58
58
 
59
59
  ## fullwidth.js
60
60
 
61
- Find `<pre>` and `<table>` elements and add the `fullwidth` class to them if
62
- they are too wide, so they can be styled differently (e.g., [full
63
- bleed](https://css-tricks.com/full-bleed/)).
61
+ Find `<pre>`, `<table>`, and TOC (with ID `TableOfContents`) elements and add
62
+ the `fullwidth` class to them if they are too wide, so they can be styled
63
+ differently (e.g., [full bleed](https://css-tricks.com/full-bleed/)).
64
64
 
65
65
  ## hash-notes.js
66
66
 
@@ -5,7 +5,7 @@
5
5
  // add _blank target to external links
6
6
  a.target = '_blank';
7
7
  // shorten bare links
8
- if (a.childElementCount === 0) {
8
+ if (a.childElementCount === 0 && r.test(a.innerText)) {
9
9
  a.innerText = a.innerText.replace(r, '').replace(/(.+)#.*$/, '$1');
10
10
  }
11
11
  })
@@ -1 +1 @@
1
- !function(e){const t=/^(https?:)?\/\//;e.querySelectorAll("a").forEach((e=>{t.test(e.getAttribute("href"))&&(e.target="_blank",0===e.childElementCount&&(e.innerText=e.innerText.replace(t,"").replace(/(.+)#.*$/,"$1")))}))}(document);
1
+ !function(e){const t=/^(https?:)?\/\//;e.querySelectorAll("a").forEach((e=>{t.test(e.getAttribute("href"))&&(e.target="_blank",0===e.childElementCount&&t.test(e.innerText)&&(e.innerText=e.innerText.replace(t,"").replace(/(.+)#.*$/,"$1")))}))}(document);
package/js/fullwidth.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // look for overflowed <pre> and <table>, and assign .fullwidth class to them
2
- document.querySelectorAll('pre,table').forEach(node => {
2
+ document.querySelectorAll('pre,table,#TableOfContents').forEach(node => {
3
3
  function fullwidth(el) {
4
4
  el.classList.add('fullwidth');
5
5
  }
@@ -13,5 +13,10 @@ document.querySelectorAll('pre,table').forEach(node => {
13
13
  p && p.offsetWidth < node.offsetWidth && fullwidth(node);
14
14
  break;
15
15
  default:
16
+ // assume it's #TableOfContents for now
17
+ node.querySelectorAll('a').forEach(a => {
18
+ // if a TOC line is wrapped, make TOC full-width
19
+ !node.classList.contains('fullwidth') && a.getClientRects().length > 1 && fullwidth(node);
20
+ });
16
21
  }
17
22
  });
@@ -1 +1 @@
1
- document.querySelectorAll("pre,table").forEach((t=>{function e(t){t.classList.add("fullwidth")}switch(t.tagName){case"PRE":const s=t.firstElementChild;"CODE"===s?.tagName&&s.scrollWidth>s.offsetWidth&&e(s);break;case"TABLE":const a=t.parentElement;a&&a.offsetWidth<t.offsetWidth&&e(t)}}));
1
+ document.querySelectorAll("pre,table,#TableOfContents").forEach((t=>{function e(t){t.classList.add("fullwidth")}switch(t.tagName){case"PRE":const l=t.firstElementChild;"CODE"===l?.tagName&&l.scrollWidth>l.offsetWidth&&e(l);break;case"TABLE":const a=t.parentElement;a&&a.offsetWidth<t.offsetWidth&&e(t);break;default:t.querySelectorAll("a").forEach((l=>{!t.classList.contains("fullwidth")&&l.getClientRects().length>1&&e(t)}))}}));
package/js/right-quote.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // right-align a quote footer if it starts with ---
2
2
  [...document.getElementsByTagName('blockquote')].forEach(quote => {
3
3
  const el = quote.lastElementChild;
4
- if (el?.tagName === 'P' && /^(—|---)/.test(el.textContent)) el.style.textAlign = 'right';
4
+ if (el?.tagName === 'P' && /^(—|―|---)/.test(el.textContent)) el.style.textAlign = 'right';
5
5
  });
@@ -1 +1 @@
1
- [...document.getElementsByTagName("blockquote")].forEach((t=>{const e=t.lastElementChild;"P"===e?.tagName&&/^(—|---)/.test(e.textContent)&&(e.style.textAlign="right")}));
1
+ [...document.getElementsByTagName("blockquote")].forEach((t=>{const e=t.lastElementChild;"P"===e?.tagName&&/^(—|―|---)/.test(e.textContent)&&(e.style.textAlign="right")}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.3.16",
3
+ "version": "1.3.18",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"