@awni/mdplus 0.1.1 → 0.1.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/dist/main.js CHANGED
@@ -506,7 +506,7 @@ data: ${P}
506
506
  `)},40)))}function E(T){if(!f.has(T))try{f.set(T,je.watch(T,(M,N)=>N&&C(ye.join(T,N.toString()))))}catch{}}function _(){let T=N=>je.readdirSync(N,{withFileTypes:!0}).filter(j=>!j.name.startsWith(".")&&j.name!=="node_modules").flatMap(j=>j.isDirectory()?T(ye.join(N,j.name)):/\.(md|markdown)$/i.test(j.name)?[ye.join(N,j.name)]:[]),M=T(u).map(N=>`<li><a href="${y(N)}">${G(ye.relative(u,N))}</a></li>`).join(`
507
507
  `);return`<!doctype html><meta charset="utf-8"><title>${G(ye.basename(u))}</title><style>body{font:16px/1.6 -apple-system,sans-serif;max-width:40rem;margin:2rem auto;padding:0 16px}</style><h1>${G(ye.basename(u))}</h1><ul>${M}</ul>`}function D(T){let M=JSON.parse(T),N=o.get(String(M.page));if(!N)return{code:404,out:{error:"unknown page"}};if(M.rev!==N.rev||je.readFileSync(N.file,"utf8")!==N.src)return{code:409,out:{error:"The note changed since this page was drawn. Try again."}};try{let j=D2(N.src,N.threads,M,p);return je.writeFileSync(N.file,j.src),C(N.file),{code:200,out:{ok:!0,exact:j.exact}}}catch(j){return{code:422,out:{error:j.message}}}}let q=w9.createServer((T,M)=>{let N=new URL(T.url??"/","http://localhost"),j=(Y,P,re)=>{M.writeHead(Y,{"content-type":P,"cache-control":"no-store"}),M.end(re)};try{if(N.pathname==="/__mdplus/comment"){let re=/^(127\.0\.0\.1|localhost)(:\d+)?$/.test(T.headers.host??"");if(T.method!=="POST"||!re||T.headers["x-mdplus-token"]!==m)return j(403,"application/json",'{"error":"forbidden"}');let ce="";T.on("data",ee=>{ce+=ee,ce.length>2e5&&T.destroy()}),T.on("end",()=>{let ee;try{ee=D(ce)}catch(me){ee={code:400,out:{error:me.message}}}j(ee.code,"application/json",JSON.stringify(ee.out))});return}if(N.pathname==="/__mdplus/events"){let re=N.searchParams.get("page")??"";M.writeHead(200,{"content-type":"text/event-stream","cache-control":"no-store",connection:"keep-alive"}),M.write(`: connected
508
508
 
509
- `),l.has(re)||l.set(re,new Set),l.get(re).add(M),T.on("close",()=>l.get(re)?.delete(M));return}let Y=/^\/__mdplus\/file\/(\d+)\//.exec(N.pathname);if(Y&&i[+Y[1]])return j(200,T2[ye.extname(i[+Y[1]]).toLowerCase()]??"application/octet-stream",je.readFileSync(i[+Y[1]]));if(N.pathname==="/")return n?j(200,"text/html; charset=utf-8",_()):(M.writeHead(302,{location:y(r)}),M.end());let P=ye.join(u,decodeURIComponent(N.pathname));return!P.startsWith(u+ye.sep)||!je.existsSync(P)||je.statSync(P).isDirectory()?j(404,"text/plain","not found"):/\.(md|markdown)$/i.test(P)?j(200,"text/html; charset=utf-8",x(P).html):j(200,T2[ye.extname(P).toLowerCase()]??"application/octet-stream",je.readFileSync(P))}catch(Y){j(500,"text/plain",`mdplus: ${Y.message}`)}});for(let T=e.port;;T++)try{await new Promise((M,N)=>{q.once("error",N),q.listen(T,"127.0.0.1",()=>{q.off("error",N),M()})}),console.log(`mdplus serve: http://127.0.0.1:${T}${n?"/":y(r)}`);return}catch(M){if(M.code!=="EADDRINUSE"||T>e.port+20)throw M}}var C9=`mdplus 0.1.1: Markdown with math, callouts, theorems, references and citations \u2192 HTML
509
+ `),l.has(re)||l.set(re,new Set),l.get(re).add(M),T.on("close",()=>l.get(re)?.delete(M));return}let Y=/^\/__mdplus\/file\/(\d+)\//.exec(N.pathname);if(Y&&i[+Y[1]])return j(200,T2[ye.extname(i[+Y[1]]).toLowerCase()]??"application/octet-stream",je.readFileSync(i[+Y[1]]));if(N.pathname==="/")return n?j(200,"text/html; charset=utf-8",_()):(M.writeHead(302,{location:y(r)}),M.end());let P=ye.join(u,decodeURIComponent(N.pathname));return!P.startsWith(u+ye.sep)||!je.existsSync(P)||je.statSync(P).isDirectory()?j(404,"text/plain","not found"):/\.(md|markdown)$/i.test(P)?j(200,"text/html; charset=utf-8",x(P).html):j(200,T2[ye.extname(P).toLowerCase()]??"application/octet-stream",je.readFileSync(P))}catch(Y){j(500,"text/plain",`mdplus: ${Y.message}`)}});for(let T=e.port;;T++)try{await new Promise((M,N)=>{q.once("error",N),q.listen(T,"127.0.0.1",()=>{q.off("error",N),M()})}),console.log(`mdplus serve: http://127.0.0.1:${T}${n?"/":y(r)}`);return}catch(M){if(M.code!=="EADDRINUSE"||T>e.port+20)throw M}}var C9=`mdplus 0.1.2: Markdown with math, callouts, theorems, references and citations \u2192 HTML
510
510
 
511
511
  usage:
512
512
  mdplus render <note.md> [-o out.html | -o -] write one self-contained HTML file
@@ -523,6 +523,6 @@ options:
523
523
  --author <name> serve: the name on comments made from the page (default: your user name)
524
524
  --editor <command> vscode: the editor's command-line name (default: code; e.g. cursor, codium)
525
525
  -h, --help -v, --version`,Hr=t=>{if(!t)return"<stdin>";let e=vt.relative(process.cwd(),t);return e?e.startsWith("../../")?t:e:t};function cl(t,e){let r=0;for(let n of e)n.level==="error"&&r++,process.stderr.write(`${Hr(n.file??t)}${n.line?`:${n.line}`:""}: ${n.level}: ${n.message}
526
- `);return r}function fl(t){return Vt.statSync(t).isDirectory()?Vt.readdirSync(t,{withFileTypes:!0}).filter(r=>!r.name.startsWith(".")&&r.name!=="node_modules").flatMap(r=>r.isDirectory()?fl(vt.join(t,r.name)):/\.(md|markdown)$/i.test(r.name)?[vt.join(t,r.name)]:[]):[t]}var _9=(t,e)=>e.split(".").reduce((r,n)=>r?.[n],t);async function E9(t){let{values:e,positionals:r}=A9({args:t,allowPositionals:!0,options:{output:{type:"string",short:"o"},config:{type:"string"},set:{type:"string",multiple:!0},port:{type:"string"},author:{type:"string"},editor:{type:"string"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}),[n,...u]=r;if(e.version)return console.log("0.1.1"),0;if(e.help||!n)return console.log(C9),n||e.help?0:2;let i={config:e.config,set:e.set};if(n==="render"){if(u.length!==1)throw new Error("render takes one note");let s=performance.now(),a=vt.resolve(u[0]),o=l0(Vt.readFileSync(a,"utf8"),a,i),l=e.output??a.replace(/\.(md|markdown|txt)$/i,"")+".html";return l==="-"?process.stdout.write(o.html):(Vt.writeFileSync(l,o.html),console.error(`wrote ${Hr(vt.resolve(l))} (${Math.round(o.html.length/1024)} KB, ${Math.round(performance.now()-s)} ms)`)),cl(a,o.diags)?1:0}if(n==="check"){if(!u.length)throw new Error("check needs files or folders");let s=0,a=0,o=0;for(let l of u.flatMap(fl)){let f=vt.resolve(l),d=l0(Vt.readFileSync(f,"utf8"),f,{...i,images:"check",fragment:!1});s+=cl(f,d.diags),a+=d.diags.filter(m=>m.level==="warning").length,o++}return console.error(`${o} file${o===1?"":"s"} checked: ${s} error${s===1?"":"s"}, ${a} warning${a===1?"":"s"}`),s?1:0}if(n==="comments"){if(!u.length)throw new Error("comments needs files or folders");let s=0,a=0;for(let o of u.flatMap(fl)){let l=vt.resolve(o),f=l0(Vt.readFileSync(l,"utf8"),l,{...i,set:[...i.set??[],"comments=show"],images:"check",fragment:!0});for(let d of f.threads){console.log(`${Hr(l)}:${d.line}: ${d.anchor?JSON.stringify(d.anchor.replace(/\s+/g," ")):"(point)"}`);for(let m of d.comments)console.log(` ${m.by?`@${m.by}: `:""}${m.text}`);s++,a+=d.comments.length}}return console.error(`${s} thread${s===1?"":"s"}, ${a} comment${a===1?"":"s"}`),0}if(n==="config"){if(u.length!==1)throw new Error("config takes one note");let s=vt.resolve(u[0]),a=l0(Vt.readFileSync(s,"utf8"),s,{...i,images:"check"});console.log(`config file: ${a.config?Hr(a.config):"none (built-in defaults)"}`);let o=[...a.sources.keys()],l=Math.max(...o.map(f=>f.length));for(let f of o)console.log(`${f.padEnd(l)} ${JSON.stringify(_9(a.settings,f))} (${a.sources.get(f)==="default"?"default":Hr(a.sources.get(f))||a.sources.get(f)})`);return cl(s,a.diags.filter(f=>!f.line))?1:0}if(n==="vscode"){let s=vt.join(at(),"..","mdplus.vsix"),a=e.editor??"code";if(!Vt.existsSync(s))throw new Error("the extension package is missing; in a clone, build it with: npm run vsix");let o=(f,d)=>S9(a,f,{stdio:d,shell:process.platform==="win32"}),l=o(["--install-extension",s,"--force"],"inherit");return l.error?(console.error(`mdplus: cannot run "${a}". Name your editor's command with --editor (code, cursor, codium, ...),
526
+ `);return r}function fl(t){return Vt.statSync(t).isDirectory()?Vt.readdirSync(t,{withFileTypes:!0}).filter(r=>!r.name.startsWith(".")&&r.name!=="node_modules").flatMap(r=>r.isDirectory()?fl(vt.join(t,r.name)):/\.(md|markdown)$/i.test(r.name)?[vt.join(t,r.name)]:[]):[t]}var _9=(t,e)=>e.split(".").reduce((r,n)=>r?.[n],t);async function E9(t){let{values:e,positionals:r}=A9({args:t,allowPositionals:!0,options:{output:{type:"string",short:"o"},config:{type:"string"},set:{type:"string",multiple:!0},port:{type:"string"},author:{type:"string"},editor:{type:"string"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}),[n,...u]=r;if(e.version)return console.log("0.1.2"),0;if(e.help||!n)return console.log(C9),n||e.help?0:2;let i={config:e.config,set:e.set};if(n==="render"){if(u.length!==1)throw new Error("render takes one note");let s=performance.now(),a=vt.resolve(u[0]),o=l0(Vt.readFileSync(a,"utf8"),a,i),l=e.output??a.replace(/\.(md|markdown|txt)$/i,"")+".html";return l==="-"?process.stdout.write(o.html):(Vt.writeFileSync(l,o.html),console.error(`wrote ${Hr(vt.resolve(l))} (${Math.round(o.html.length/1024)} KB, ${Math.round(performance.now()-s)} ms)`)),cl(a,o.diags)?1:0}if(n==="check"){if(!u.length)throw new Error("check needs files or folders");let s=0,a=0,o=0;for(let l of u.flatMap(fl)){let f=vt.resolve(l),d=l0(Vt.readFileSync(f,"utf8"),f,{...i,images:"check",fragment:!1});s+=cl(f,d.diags),a+=d.diags.filter(m=>m.level==="warning").length,o++}return console.error(`${o} file${o===1?"":"s"} checked: ${s} error${s===1?"":"s"}, ${a} warning${a===1?"":"s"}`),s?1:0}if(n==="comments"){if(!u.length)throw new Error("comments needs files or folders");let s=0,a=0;for(let o of u.flatMap(fl)){let l=vt.resolve(o),f=l0(Vt.readFileSync(l,"utf8"),l,{...i,set:[...i.set??[],"comments=show"],images:"check",fragment:!0});for(let d of f.threads){console.log(`${Hr(l)}:${d.line}: ${d.anchor?JSON.stringify(d.anchor.replace(/\s+/g," ")):"(point)"}`);for(let m of d.comments)console.log(` ${m.by?`@${m.by}: `:""}${m.text}`);s++,a+=d.comments.length}}return console.error(`${s} thread${s===1?"":"s"}, ${a} comment${a===1?"":"s"}`),0}if(n==="config"){if(u.length!==1)throw new Error("config takes one note");let s=vt.resolve(u[0]),a=l0(Vt.readFileSync(s,"utf8"),s,{...i,images:"check"});console.log(`config file: ${a.config?Hr(a.config):"none (built-in defaults)"}`);let o=[...a.sources.keys()],l=Math.max(...o.map(f=>f.length));for(let f of o)console.log(`${f.padEnd(l)} ${JSON.stringify(_9(a.settings,f))} (${a.sources.get(f)==="default"?"default":Hr(a.sources.get(f))||a.sources.get(f)})`);return cl(s,a.diags.filter(f=>!f.line))?1:0}if(n==="vscode"){let s=vt.join(at(),"..","mdplus.vsix"),a=e.editor??"code";if(!Vt.existsSync(s))throw new Error("the extension package is missing; in a clone, build it with: npm run vsix");let o=(f,d)=>S9(a,f,{stdio:d,shell:process.platform==="win32"}),l=o(["--install-extension",s,"--force"],"inherit");return l.error?(console.error(`mdplus: cannot run "${a}". Name your editor's command with --editor (code, cursor, codium, ...),
527
527
  or install by hand: in the editor, run "Extensions: Install from VSIX..." and choose
528
528
  ${s}`),1):(l.status===0&&o(["--uninstall-extension","local.mdplus-preview"],"ignore"),l.status??1)}if(n==="serve")return await M2(u[0]??".",{...i,port:e.port?+e.port:4500,author:e.author}),-1;throw new Error(`unknown command "${n}"`)}E9(process.argv.slice(2)).then(t=>{t>=0&&(process.exitCode=t)},t=>{console.error(`mdplus: ${t.message}`),process.exitCode=2});
package/mdplus.vsix CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awni/mdplus",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Rich documents from simple Markdown, in real time: math, theorems, cross-references, citations, callouts and in-page annotations, with a VS Code extension.",
5
5
  "keywords": ["markdown", "math", "katex", "latex", "theorem", "callouts", "cross-references", "citations", "bibtex", "criticmarkup", "html", "notes", "cli", "quarto"],
6
6
  "author": "Awni Altabaa (https://github.com/Awni00)",