what-a-look 1.0.0 → 1.1.0
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/dist/index.js +18 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import T from"node:path";import E from"node:util";var m=`<!--
|
|
2
2
|
SPDX-FileCopyrightText: 2026 Benjamin DIDIER <contact@aziks.aleeas.com>
|
|
3
3
|
|
|
4
4
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
@@ -31,18 +31,18 @@ import O from"node:path";import T from"node:util";var m=`<!--
|
|
|
31
31
|
</article>
|
|
32
32
|
</body>
|
|
33
33
|
</html>
|
|
34
|
-
`;var v=(o)=>o===0||o===4||o===1||o===5||o===3,C=(o)=>o.startsWith("#"),b=(o)=>/^(-|\*|\+|\d+\.)\s/m.test(o),c=(o)=>o.startsWith("```"),z=(o)=>/^\[\^\d+\]:/m.test(o),
|
|
35
|
-
`)};for(let
|
|
36
|
-
`);continue}if(
|
|
37
|
-
`);continue}if(
|
|
38
|
-
`)}
|
|
39
|
-
`),
|
|
40
|
-
`),c(n.trim()))break}continue}if(
|
|
41
|
-
`);continue}if(
|
|
42
|
-
`);continue}r.push(`${d.trim()} `)}return r},
|
|
43
|
-
`;let i=!0;t=t.map((
|
|
44
|
-
`),
|
|
45
|
-
`},y=(o)=>{let t=o.split(/\r?\n/).map((d)=>{let n=F(d.trimStart());return{group:n?0:1,line:n?d.replace(">",""):d}});if(t.length===0)return"";let
|
|
34
|
+
`;var v=(o)=>o===0||o===4||o===1||o===5||o===3,C=(o)=>o.startsWith("#"),b=(o)=>/^(-|\*|\+|\d+\.)\s/m.test(o),c=(o)=>o.startsWith("```"),z=(o)=>/^\[.*?\]:/m.test(o),S=(o)=>/^\[\^\d+\]:/m.test(o),M=(o)=>/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/im.test(o),L=(o)=>/(\s{2}|\\)$/m.test(o),F=(o)=>o.startsWith(">"),B=(o)=>{let r=o.trim();if(r.length===0)return 5;if(C(r))return 0;if(c(r))return 1;if(b(r))return 4;if(S(r))return 6;if(z(r))return 7;return 2},I=(o)=>{let r=[],t=0,e=0,i=()=>{if(v(t))return;let a=r.pop();if(a===void 0)return;r.push(`${a}
|
|
35
|
+
`)};for(let a=0;a<o.length;a++){let d=o[a]??"";if(t=e,e=B(d),e===5){i(),r.push(`
|
|
36
|
+
`);continue}if(e===0){i(),r.push(`${d}
|
|
37
|
+
`);continue}if(e===4){i();for(;a<o.length;a++){let n=o[a]??"";if(!b(n.trim()))break;r.push(`${n}
|
|
38
|
+
`)}a--;continue}if(e===1){i(),r.push(`${d}
|
|
39
|
+
`),a++;for(;a<o.length;a++){let n=o[a]??"";if(r.push(`${n}
|
|
40
|
+
`),c(n.trim()))break}continue}if(e===6||e===7){i(),r.push(`${d} `);continue}if(t===4){e=4;let n=r.pop();if(n===void 0)continue;n=n.slice(0,-1),r.push(`${n.trimEnd()} ${d.trimStart()}
|
|
41
|
+
`);continue}if(L(d)){e=3;let n=r.pop();if(n===void 0)continue;r.push(`${n.trimEnd()} ${d.trimStart()}
|
|
42
|
+
`);continue}r.push(`${d.trim()} `)}return r},N=(o,r)=>{let t=I(o);if(r===0){let e=t[0];if(e&&M(e.trimStart()))t[0]=`${e}
|
|
43
|
+
`;let i=!0;t=t.map((a)=>{if(i)a=`> ${a}`;return i=a.endsWith(`
|
|
44
|
+
`),a})}return`${t.join("")}
|
|
45
|
+
`},y=(o)=>{let t=o.split(/\r?\n/).map((d)=>{let n=F(d.trimStart());return{group:n?0:1,line:n?d.replace(">",""):d}});if(t.length===0)return"";let e=t[0]?.group??1,i=[],a="";for(let{group:d,line:n}of t){if(d!==e)a+=N(i,e),e=d,i=[];i.push(n)}return a};var p=`.markdown-body {
|
|
46
46
|
--base-size-16: 1rem;
|
|
47
47
|
--base-size-24: 1.5rem;
|
|
48
48
|
--base-size-4: 0.25rem;
|
|
@@ -1290,7 +1290,7 @@ import O from"node:path";import T from"node:util";var m=`<!--
|
|
|
1290
1290
|
min-height: 52px;
|
|
1291
1291
|
}
|
|
1292
1292
|
|
|
1293
|
-
`;var g=p,
|
|
1293
|
+
`;var g=p,H=()=>g.replace(/@media \(prefers-color-scheme: dark\)(?:.*?\r?\n)}/s,(r)=>r.slice(r.indexOf("{")+1,r.lastIndexOf("}"))).replace(/@media \(prefers-color-scheme: light\)(?:.*?\r?\n)}/s,""),k=(o)=>{if(o)return H();return g};import h from"node:fs";var s=(o)=>o instanceof Error?o.message:`${o}`,l=(o)=>{console.error(`Error: ${o}`),process.exit(1)},w=(o)=>{try{return h.readFileSync(o,"utf8")}catch(r){let t=s(r);return l(`Failed to read file at path '${o}': ${t}`)}},f=(o,r)=>{try{h.writeFileSync(o,r)}catch(t){let e=s(t);l(`Failed to write file at path '${o}': ${e}`)}};var A=m,O=async(o)=>{try{let r=await fetch("https://api.github.com/markdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"gfm",text:o})});if(!r.ok)throw`${r.status} ${await r.text()}`;return await r.text()}catch(r){let t=r instanceof Error?r.message:r;return l(`Failed to fetch GitHub API: ${t}`)}},u=async(o,r)=>{let t=y(o),e=await O(t);return A.replace("{{ GITHUB_MARKDOWN_BODY }}",e).replace("{{ GITHUB_MARKDOWN_CSS }}",k(r))};var U=`what-a-look, get an html file to preview your GitHub markdown files.
|
|
1294
1294
|
|
|
1295
1295
|
Usage: what-a-look [OPTIONS]
|
|
1296
1296
|
|
|
@@ -1298,10 +1298,10 @@ Options:
|
|
|
1298
1298
|
-i, --in Path to markdown file. It needs the '.md' extension.
|
|
1299
1299
|
-o, --out Out file. Default is to print to stdout.
|
|
1300
1300
|
--force-dark Force the preview to use dark-mode.
|
|
1301
|
-
-h, --help Print help.`,
|
|
1301
|
+
-h, --help Print help.`,j=()=>{try{let{values:o}=E.parseArgs({options:{in:{type:"string",short:"i"},out:{type:"string",short:"o",default:""},"force-dark":{type:"boolean",default:!1},help:{type:"boolean",short:"h",default:!1}},allowPositionals:!1,strict:!0});return o}catch(o){let r=s(o);return l(`${r}
|
|
1302
1302
|
|
|
1303
|
-
For more information, try '--help'.`)}},
|
|
1303
|
+
For more information, try '--help'.`)}},R=async()=>{let o=j();if(o.help){console.log(U);return}if(!o.in)return l(`Missing option '--in'
|
|
1304
1304
|
|
|
1305
|
-
For more information, try '--help'.`);if(
|
|
1305
|
+
For more information, try '--help'.`);if(T.extname(o.in)!==".md")l(`Input file is not a markdown file
|
|
1306
1306
|
|
|
1307
|
-
Maybe consider adding the '.md' extension.`);let r=w(o.in),t=await u(r,o["force-dark"]);if(o.out.length===0){console.log(t);return}f(o.out,t)};
|
|
1307
|
+
Maybe consider adding the '.md' extension.`);let r=w(o.in),t=await u(r,o["force-dark"]);if(o.out.length===0){console.log(t);return}f(o.out,t)};R();
|