quarkup 0.0.2 → 0.0.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/dist/main.js +1 -1
- package/package.json +1 -1
- package/src/main.ts +2 -1
package/dist/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as ft}from"commander";import _ from"path";import F,{globSync as
|
|
2
|
+
import{Command as ft}from"commander";import _ from"path";import F,{globSync as mt}from"fs";var E=class{_start=null;_end=null;start(){this._start=process.hrtime.bigint()}stop(){if(this._start===null)throw new Error("Must start before stopping");this._end=process.hrtime.bigint()}get secondsElapsed(){return this.millisecondsElapsed/1e3}get millisecondsElapsed(){if(this._start===null||this._end===null)throw new Error("Must be started and stopped");return Number(this._end-this._start)/1e6}};import M from"fs";import ot from"path";import{unified as rt}from"unified";import nt from"remark-parse";import it from"remark-gfm";import st from"remark-rehype";import pt from"rehype-stringify";import ct from"rehype-pretty-code";import at from"remark-math";import ut from"rehype-mathjax/svg";var P=(function(t){if(t==null)return J;if(typeof t=="function")return W(t);if(typeof t=="object")return Array.isArray(t)?X(t):G(t);if(typeof t=="string")return H(t);throw new Error("Expected function, string, or object as test")});function X(t){let e=[],o=-1;for(;++o<t.length;)e[o]=P(t[o]);return W(n);function n(...r){let i=-1;for(;++i<e.length;)if(e[i].apply(this,r))return!0;return!1}}function G(t){let e=t;return W(o);function o(n){let r=n,i;for(i in t)if(r[i]!==e[i])return!1;return!0}}function H(t){return W(e);function e(o){return o&&o.type===t}}function W(t){return e;function e(o,n,r){return!!(V(o)&&t.call(this,o,typeof n=="number"?n:void 0,r||void 0))}}function J(){return!0}function V(t){return t!==null&&typeof t=="object"&&"type"in t}function D(t){return"\x1B[33m"+t+"\x1B[39m"}var K=[],O=!0,j=!1,T="skip";function v(t,e,o,n){let r;typeof e=="function"&&typeof o!="function"?(n=o,o=e):r=e;let i=P(r),p=n?-1:1;u(t,void 0,[])();function u(s,a,l){let f=s&&typeof s=="object"?s:{};if(typeof f.type=="string"){let c=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(x,"name",{value:"node ("+D(s.type+(c?"<"+c+">":""))+")"})}return x;function x(){let c=K,g,y,h;if((!e||i(s,a,l[l.length-1]||void 0))&&(c=Y(o(s,l)),c[0]===j))return c;if("children"in s&&s.children){let b=s;if(b.children&&c[0]!==T)for(y=(n?b.children.length:-1)+p,h=l.concat(b);y>-1&&y<b.children.length;){let w=b.children[y];if(g=u(w,y,h)(),g[0]===j)return g;y=typeof g[1]=="number"?g[1]:y+p}}return c}}}function Y(t){return Array.isArray(t)?t:typeof t=="number"?[O,t]:t==null?K:[t]}function C(t,e,o,n){let r,i,p;typeof e=="function"&&typeof o!="function"?(i=void 0,p=e,r=o):(i=e,p=o,r=n),v(t,i,u,r);function u(s,a){let l=a[a.length-1],f=l?l.children.indexOf(s):void 0;return p(s,f,l)}}var A=()=>t=>{C(t,"element",(e,o,n)=>{if(!(e.tagName==="mjx-container"&&e.properties?.display==="true")||n===void 0||o===void 0)return;let i={type:"element",tagName:"figure",properties:{"data-math-block":""},children:[e]};n.children[o]=i})};var Q=/([a-zA-Z]+)/,B=/([a-zA-Z]+)/,z=/\{([^}]+)\}/,Z=(t,e)=>{let o=new RegExp(`${t.keywordMark}${Q.source}((?:${t.optionMark}${B.source}${z.source})*)${t.keywordMark}`,"g"),n=[],r=e.matchAll(o);for(let i of r){let[p,u,s]=i,a=i.index,l=a+p.length,f=[],x=new RegExp(`${t.optionMark}${B.source}${z.source}`,"g"),c;for(;(c=x.exec(s))!==null;)f.push({name:c[1],value:c[2]});n.push({name:u,options:f,start:a,end:l})}return n};import{toc as tt}from"mdast-util-toc";var S=class{_name;_optionsSchema;constructor(e,o){this._name=e,this._optionsSchema=o}get name(){return this._name}get options(){return this._optionsSchema}use(e,o){let n={};for(let i of o)n[i.name]=i.value;let r=this._optionsSchema.parse(n);return this._use(r,e)}};import{z as k}from"zod";var et=k.object({maxDepth:k.preprocess(t=>typeof t=="string"?parseInt(t):t,k.union([k.literal(1),k.literal(2),k.literal(3),k.literal(4),k.literal(5),k.literal(6)])).default(6)}),I=class extends S{constructor(){super("tableofcontents",et)}_use(e,o){let n=tt(o,{maxDepth:e.maxDepth});if(n.map===void 0)return null;let r=n.map;return r.data={...r.data,hProperties:{...r.data?.hProperties,"data-toc":!0}},{type:"block",value:[r]}}};var q=(t={config:{keywordMark:"&",optionMark:":"}})=>{let{config:e}=t,o=[new I],n={};for(let r of o)n[r.name]=r;return r=>{C(r,"paragraph",(i,p,u)=>{if(u===void 0||p===void 0)return;let s=[],a=[],l=!1,f=()=>{a.length>0&&(s.push({type:"paragraph",children:[...a]}),a=[])},x=(c,g)=>{f(),s.push({type:"paragraph",children:[{type:"strong",children:[{type:"text",value:c.name}]},{type:"text",value:" raised error: "},{type:"emphasis",children:[{type:"text",value:g}]}],data:{hProperties:{"data-writedown-error":!0}}})};for(let c of i.children){if(c.type!=="text"){a.push(c);continue}let g=Z(e,c.value);if(g.length===0){a.push(c);continue}l=!0;let y=0;for(let h of g){h.start>y&&a.push({type:"text",value:c.value.slice(y,h.start)});let b=n[h.name];if(!b)x(h,`Unknown keyword: "${h.name}"`);else try{let w=b.use(r,h.options);w===null?x(h,`Failed to use: "${h.name}"`):w.type==="phrasing"?a.push(...w.value):w.type==="block"&&(f(),s.push(...w.value))}catch(w){x(h,`Failed to use: "${h.name}", error: ${w}`)}y=h.end}y<c.value.length&&a.push({type:"text",value:c.value.slice(y)})}if(l)return f(),u.children.splice(p,1,...s),p+s.length})}};import lt from"rehype-slug";var $=class{_sourceFile;_outputDir;constructor(e,o){this._sourceFile=e,this._outputDir=o}_readContents(e){if(!M.existsSync(e))throw new Error(`File "${e}" doesn't exist`);return M.readFileSync(e).toString()}_writeContents(e,o){M.writeFileSync(e,o)}async compile(){console.log(`Compiling ${this._sourceFile} to ${this._outputDir}`);let e=this._readContents(this._sourceFile),o=await rt().use(nt).use(at).use(it).use(q).use(st).use(lt).use(ut).use(A).use(ct,{theme:"github-dark-dimmed",grid:!0}).use(pt).process(e),n=String(o);this._writeContents(ot.join(this._outputDir,"index.html"),n)}};var N=async(t,e,o)=>{let n=_.resolve(e),r=_.resolve(o);F.existsSync(e)||t.error(`Error: The source file "${e}" does not exist.`);try{F.mkdirSync(o,{recursive:!0})}catch{t.error(`Error: Could not create output folder "${r}".`)}let i=new $(n,r);try{let p=new E;p.start(),await i.compile(),p.stop();let u=p.secondsElapsed;console.log(`Success: Compilation finished in ${u.toFixed(2)}s`)}catch(p){t.error(`Error: Compilation failed: "${p}"`)}},L=async(t,e,o,n)=>{let r=_.resolve(e),i=_.resolve(o);F.existsSync(r)||t.error(`Error: The input folder "${r}" does not exist.`);try{F.mkdirSync(o,{recursive:!0})}catch{t.error(`Error: Could not create output folder "${i}".`)}let p=mt(`${r}/**/${n}`);console.log(`Found ${p.length} projects.`);for(let u=0;u<p.length;u++){console.log();let s=p[u],a=_.basename(_.dirname(s)),l=_.join(o,a);console.log(`[${u}] Compiling project: "${a}"`),await N(t,s,l)}};var U={name:"quarkup",version:"0.0.3",description:"A markdown extension",author:"Radek Tit\u011Bra",license:"MIT",keywords:["markdown"],repository:{type:"git",url:"git+https://github.com/Rodak123/quarkup.git"},type:"module",main:"src/main.ts",bin:{quarkup:"./dist/main.js"},files:["dist"],scripts:{lint:"eslint .",build:"tsup src/main.ts --format esm --clean --minify --shims",prepublishOnly:"npm run build"},devDependencies:{"@types/node":"^24.12.4",eslint:"^9.39.1",tailwindcss:"^4.1.18",tsup:"^8.5.1",typescript:"~5.9.3","typescript-eslint":"^8.46.4"},dependencies:{"@shikijs/transformers":"^4.1.0","@types/mdast":"^4.0.4",commander:"^15.0.0",mdast:"^2.3.2","mdast-util-toc":"^7.1.0","rehype-mathjax":"^7.1.0","rehype-pretty-code":"^0.14.3","rehype-slug":"^6.0.0","rehype-stringify":"^10.0.1","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",unified:"^11.0.5",zod:"^4.4.3"}};var R=new ft;R.name("quarkup").description("A simple markdown to HTML compiler").version(U.version);R.command("s").description("Compile a single project").argument("<source_file>","source file to compile").option("-o, --output <output_folder>","the target output folder","html").action(async(t,e)=>{await N(R,t,e.output)});R.command("m").description("Compile multiple projects").argument("<input_folder>","folder containing projects in subfolders").option("-o, --output <output_folder>","the target output folder","html").option("-m, --main-file <main_file>","main.md").action(async(t,e)=>{await L(R,t,e.output,e.mainFile)});R.parse();
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { compileMultipleProjects, compileSingleProject } from './actions.ts';
|
|
5
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
5
6
|
|
|
6
7
|
const program = new Command();
|
|
7
8
|
|
|
8
9
|
program
|
|
9
10
|
.name('quarkup')
|
|
10
11
|
.description('A simple markdown to HTML compiler')
|
|
11
|
-
.version(
|
|
12
|
+
.version(packageJson.version);
|
|
12
13
|
|
|
13
14
|
program
|
|
14
15
|
.command('s')
|