@xiee/utils 1.9.1 → 1.9.3
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 +5 -0
- package/js/center-img.js +1 -1
- package/js/center-img.min.js +1 -1
- package/js/code-lang.js +10 -0
- package/js/code-lang.min.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,11 @@ Then the image will have a tooltip on mouseover.
|
|
|
32
32
|
Center `<img>`, `<video>`, and `<object>` on a page if they are the only child
|
|
33
33
|
of their parent element.
|
|
34
34
|
|
|
35
|
+
## code-lang.js
|
|
36
|
+
|
|
37
|
+
Add the `language-` prefix to the class name of `<code>` inside `<pre>` when
|
|
38
|
+
appropriate, so that syntax highlighters such as prism.js can work.
|
|
39
|
+
|
|
35
40
|
## copy-button.js
|
|
36
41
|
|
|
37
42
|
Add a copy button to any element (by default, `<pre>` code blocks) on a page.
|
package/js/center-img.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
if (parent.nodeName === 'P') {
|
|
25
25
|
parent.style.textAlign = 'center';
|
|
26
|
-
if (!parentA && tagName === 'img') {
|
|
26
|
+
if (!parentA && tagName === 'img' && !/^data:/.test(tag.src)) {
|
|
27
27
|
parent.innerHTML = `<a href="${tag.src}" style="border: none;">${tag.outerHTML}</a>`;
|
|
28
28
|
}
|
|
29
29
|
}
|
package/js/center-img.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(e=>{function t(e){if(1!==e.childElementCount)return!1;const t=e.childNodes;if(1===t.length)return!0;for(let e in t){let n=t[e];if("#text"===n.nodeName&&!/^\s$/.test(n.textContent))return!1}return!0}["img","embed","object"].forEach((function(n){e.querySelectorAll(n).forEach((e=>{let r=e.parentElement;if(t(r)){const l="A"===r.nodeName;if(l){if(r=r.parentElement,!t(r))return;r.firstElementChild.style.border="none"}"P"===r.nodeName&&(r.style.textAlign="center",l||"img"!==n||(r.innerHTML=`<a href="${e.src}" style="border: none;">${e.outerHTML}</a>`))}}))})),e.querySelectorAll("p").forEach((e=>{"* * *"===e.innerText&&(e.style.textAlign="center")}))})(document);
|
|
1
|
+
(e=>{function t(e){if(1!==e.childElementCount)return!1;const t=e.childNodes;if(1===t.length)return!0;for(let e in t){let n=t[e];if("#text"===n.nodeName&&!/^\s$/.test(n.textContent))return!1}return!0}["img","embed","object"].forEach((function(n){e.querySelectorAll(n).forEach((e=>{let r=e.parentElement;if(t(r)){const l="A"===r.nodeName;if(l){if(r=r.parentElement,!t(r))return;r.firstElementChild.style.border="none"}"P"===r.nodeName&&(r.style.textAlign="center",l||"img"!==n||/^data:/.test(e.src)||(r.innerHTML=`<a href="${e.src}" style="border: none;">${e.outerHTML}</a>`))}}))})),e.querySelectorAll("p").forEach((e=>{"* * *"===e.innerText&&(e.style.textAlign="center")}))})(document);
|
package/js/code-lang.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// add 'language-' prefix to <code> inside <pre> for syntax highlighters to work (e.g., prism.js)
|
|
2
|
+
document.querySelectorAll('pre').forEach(pre => {
|
|
3
|
+
const code = pre.querySelector('code');
|
|
4
|
+
// no code or already highlighted
|
|
5
|
+
if (!code || code.querySelector('span')) return;
|
|
6
|
+
const c1 = pre.className, c2 = code.className, r = /^lang(uage)?-/;
|
|
7
|
+
// at least one of pre or code must have className, which shouldn't start with lang prefix
|
|
8
|
+
if (!(c1 || c2) || r.test(c1) || r.test(c2)) return;
|
|
9
|
+
code.className = 'language-' + (c2 || c1);
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
document.querySelectorAll("pre").forEach((e=>{const a=e.querySelector("code");if(!a||a.querySelector("span"))return;const c=e.className,s=a.className,t=/^lang(uage)?-/;!c&&!s||t.test(c)||t.test(s)||(a.className="language-"+(s||c))}));
|