@xiee/utils 1.9.0 → 1.9.2

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
@@ -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.
@@ -28,16 +28,18 @@ table {
28
28
  border: 0;
29
29
  }
30
30
  td.docs, td.code {
31
- width: 50%;
32
31
  vertical-align: top;
33
32
  padding: 1em 1em 1px 2em;
34
33
  }
34
+ td.docs {
35
+ width: 50%;
36
+ }
35
37
  td.code{
36
38
  background: #f5f5ff;
37
39
  overflow-x: hidden;
38
40
  }
39
41
  code{
40
- font-size: .8em;
42
+ font-size: .9em;
41
43
  }
42
44
  td.docs code{
43
45
  background: #f8f8ff;
@@ -48,7 +50,6 @@ img {
48
50
  }
49
51
  pre code{
50
52
  display: block;
51
- line-height: 1;
52
53
  }
53
54
  pre code:hover {
54
55
  white-space: pre-wrap;
@@ -1 +1 @@
1
- body{font-family:'Palatino Linotype','Book Antiqua',Palatino,FreeSerif,serif;line-height:1.5;color:#30404f;margin:0;padding:0}h1,h2,h3,h4,h5,h6{color:#123;font-weight:400;margin:0 0 1rem 0}.frontmatter{text-align:center;margin-top:2em}a{color:#08c;text-decoration:none}a:focus,a:hover{color:#005580;text-decoration:underline}table{width:100%;border:0}td.code,td.docs{width:50%;vertical-align:top;padding:1em 1em 1px 2em}td.code{background:#f5f5ff;overflow-x:hidden}code{font-size:.8em}td.docs code{background:#f8f8ff;border:1px solid #dedede}img{max-width:100%}pre code{display:block;line-height:1}pre code:hover{white-space:pre-wrap}.pilwrap{position:relative}.pilcrow{font:12px Arial;text-decoration:none;color:#454545;position:absolute;top:3px;left:-1.5em;padding:1px 2px;opacity:0}td.docs:hover .pilcrow{opacity:1}blockquote{border-left:4px solid #ddd;padding:0 1em;color:#777}.container{position:relative}.handler{width:5px;padding:0;cursor:col-resize;position:absolute;z-index:5}
1
+ body{font-family:'Palatino Linotype','Book Antiqua',Palatino,FreeSerif,serif;line-height:1.5;color:#30404f;margin:0;padding:0}h1,h2,h3,h4,h5,h6{color:#123;font-weight:400;margin:0 0 1rem 0}.frontmatter{text-align:center;margin-top:2em}a{color:#08c;text-decoration:none}a:focus,a:hover{color:#005580;text-decoration:underline}table{width:100%;border:0}td.code,td.docs{vertical-align:top;padding:1em 1em 1px 2em}td.docs{width:50%}td.code{background:#f5f5ff;overflow-x:hidden}code{font-size:.9em}td.docs code{background:#f8f8ff;border:1px solid #dedede}img{max-width:100%}pre code{display:block}pre code:hover{white-space:pre-wrap}.pilwrap{position:relative}.pilcrow{font:12px Arial;text-decoration:none;color:#454545;position:absolute;top:3px;left:-1.5em;padding:1px 2px;opacity:0}td.docs:hover .pilcrow{opacity:1}blockquote{border-left:4px solid #ddd;padding:0 1em;color:#777}.container{position:relative}.handler{width:5px;padding:0;cursor:col-resize;position:absolute;z-index:5}
@@ -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))}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"