quarkup 0.0.1 → 0.0.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
@@ -1,18 +1,30 @@
1
1
  # Quarkup
2
2
 
3
- A simple markdown extension that compiles markdown into tailwind styled html
3
+ A simple markdown extension that compiles markdown into tailwind styled html.
4
4
 
5
5
  ## Disclaimer
6
6
 
7
- This package is still work in progress.
7
+ This package and documentation is still work in progress.
8
8
 
9
- ## Example
9
+ ## Contents
10
10
 
11
- Compile `demo/main.md` into `test-web/html/`.
11
+ - [Quarkup](#quarkup)
12
+ - [Disclaimer](#disclaimer)
13
+ - [Contents](#contents)
14
+ - [Usage](#usage)
15
+ - [Examples](#examples)
16
+ - [Features](#features)
17
+ - [Custom Syntax](#custom-syntax)
18
+ - [Table of Contents](#table-of-contents)
12
19
 
13
- ```sh
14
- node src/main.ts c demo/main.md -o test-web/html
15
- ```
20
+ ## Usage
21
+
22
+ `npx quarkup [options] [command]`
23
+
24
+ ### Examples
25
+
26
+ - [Compile single project](./examples/single/README.md)
27
+ - [Compile multiple projects](./examples/single/README.md)
16
28
 
17
29
  ## Features
18
30
 
@@ -35,6 +47,11 @@ $keyword:optionA{value}:optionB{value}&
35
47
 
36
48
  the keyword (`$`) and option (`:`) marks can be configured.
37
49
 
38
- ### Supported Keywords
50
+ ### Table of Contents
51
+
52
+ Example: `$tableofcontents:maxDepth{1-6 [default: 6]}$`
53
+
54
+ Keyword: `tableofcontents`
39
55
 
40
- - `$tableofcontents:maxDepth{1-6 [default: 6]}$` - Creates a table of contents
56
+ Options:
57
+ - `maxDepth` - 1 up to 6 (default is 6) # Highest acceptable heading
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{Command as ut}from"commander";import Z from"path";import z from"fs";import N from"fs";import Q from"path";import{unified as tt}from"unified";import et from"remark-parse";import ot from"remark-gfm";import rt from"remark-rehype";import nt from"rehype-stringify";import it from"rehype-pretty-code";import st from"remark-math";import ct from"rehype-mathjax/svg";var E=(function(t){if(t==null)return q;if(typeof t=="function")return _(t);if(typeof t=="object")return Array.isArray(t)?L(t):U(t);if(typeof t=="string")return X(t);throw new Error("Expected function, string, or object as test")});function L(t){let e=[],o=-1;for(;++o<t.length;)e[o]=E(t[o]);return _(r);function r(...n){let i=-1;for(;++i<e.length;)if(e[i].apply(this,n))return!0;return!1}}function U(t){let e=t;return _(o);function o(r){let n=r,i;for(i in t)if(n[i]!==e[i])return!1;return!0}}function X(t){return _(e);function e(o){return o&&o.type===t}}function _(t){return e;function e(o,r,n){return!!(G(o)&&t.call(this,o,typeof r=="number"?r:void 0,n||void 0))}}function q(){return!0}function G(t){return t!==null&&typeof t=="object"&&"type"in t}function D(t){return"\x1B[33m"+t+"\x1B[39m"}var $=[],T=!0,C=!1,F="skip";function M(t,e,o,r){let n;typeof e=="function"&&typeof o!="function"?(r=o,o=e):n=e;let i=E(n),u=r?-1:1;w(t,void 0,[])();function w(c,p,d){let a=c&&typeof c=="object"?c:{};if(typeof a.type=="string"){let s=typeof a.tagName=="string"?a.tagName:typeof a.name=="string"?a.name:void 0;Object.defineProperty(k,"name",{value:"node ("+D(c.type+(s?"<"+s+">":""))+")"})}return k;function k(){let s=$,y,h,l;if((!e||i(c,p,d[d.length-1]||void 0))&&(s=H(o(c,d)),s[0]===C))return s;if("children"in c&&c.children){let b=c;if(b.children&&s[0]!==F)for(h=(r?b.children.length:-1)+u,l=d.concat(b);h>-1&&h<b.children.length;){let g=b.children[h];if(y=w(g,h,l)(),y[0]===C)return y;h=typeof y[1]=="number"?y[1]:h+u}}return s}}}function H(t){return Array.isArray(t)?t:typeof t=="number"?[T,t]:t==null?$:[t]}function W(t,e,o,r){let n,i,u;typeof e=="function"&&typeof o!="function"?(i=void 0,u=e,n=o):(i=e,u=o,n=r),M(t,i,w,n);function w(c,p){let d=p[p.length-1],a=d?d.children.indexOf(c):void 0;return u(c,a,d)}}var v=()=>t=>{W(t,"element",(e,o,r)=>{if(!(e.tagName==="mjx-container"&&e.properties?.display==="true")||r===void 0||o===void 0)return;let i={type:"element",tagName:"figure",properties:{"data-math-block":""},children:[e]};r.children[o]=i})};var V=/([a-zA-Z]+)/,j=/([a-zA-Z]+)/,K=/\{([^}]+)\}/,A=(t,e)=>{let o=new RegExp(`${t.keywordMark}${V.source}((?:${t.optionMark}${j.source}${K.source})*)${t.keywordMark}`,"g"),r=[],n=e.matchAll(o);for(let i of n){let[u,w,c]=i,p=i.index,d=p+u.length,a=[],k=new RegExp(`${t.optionMark}${j.source}${K.source}`,"g"),s;for(;(s=k.exec(c))!==null;)a.push({name:s[1],value:s[2]});r.push({name:w,options:a,start:p,end:d})}return r};import{toc as Y}from"mdast-util-toc";var I=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 r={};for(let i of o)r[i.name]=i.value;let n=this._optionsSchema.parse(r);return this._use(n,e)}};import{z as x}from"zod";var J=x.object({maxDepth:x.preprocess(t=>typeof t=="string"?parseInt(t):t,x.union([x.literal(1),x.literal(2),x.literal(3),x.literal(4),x.literal(5),x.literal(6)])).default(6)}),S=class extends I{constructor(){super("tableofcontents",J)}_use(e,o){let r=Y(o,{maxDepth:e.maxDepth});if(r.map===void 0)return null;let n=r.map;return n.data={...n.data,hProperties:{...n.data?.hProperties,"data-toc":!0}},{type:"block",value:[n]}}};var B=(t={config:{keywordMark:"&",optionMark:":"}})=>{let{config:e}=t,o=[new S],r={};for(let n of o)r[n.name]=n;return n=>{W(n,"paragraph",(i,u,w)=>{if(w===void 0||u===void 0)return;let c=[],p=[],d=!1,a=()=>{p.length>0&&(c.push({type:"paragraph",children:[...p]}),p=[])},k=(s,y)=>{a(),c.push({type:"paragraph",children:[{type:"strong",children:[{type:"text",value:s.name}]},{type:"text",value:" raised error: "},{type:"emphasis",children:[{type:"text",value:y}]}],data:{hProperties:{"data-writedown-error":!0}}})};for(let s of i.children){if(s.type!=="text"){p.push(s);continue}let y=A(e,s.value);if(y.length===0){p.push(s);continue}d=!0;let h=0;for(let l of y){l.start>h&&p.push({type:"text",value:s.value.slice(h,l.start)});let b=r[l.name];if(!b)k(l,`Unknown keyword: "${l.name}"`);else try{let g=b.use(n,l.options);g===null?k(l,`Failed to use: "${l.name}"`):g.type==="phrasing"?p.push(...g.value):g.type==="block"&&(a(),c.push(...g.value))}catch(g){k(l,`Failed to use: "${l.name}", error: ${g}`)}h=l.end}h<s.value.length&&p.push({type:"text",value:s.value.slice(h)})}if(d)return a(),w.children.splice(u,1,...c),u+c.length})}};import pt from"rehype-slug";var P=class{_sourceFile;_outputDir;constructor(e,o){this._sourceFile=e,this._outputDir=o}_readContents(e){if(!N.existsSync(e))throw new Error(`File "${e}" doesn't exist`);return N.readFileSync(e).toString()}_writeContents(e,o){N.writeFileSync(e,o)}async compile(){console.log("Compiling");let e=this._readContents(this._sourceFile),o=await tt().use(et).use(st).use(ot).use(B).use(rt).use(pt).use(ct).use(v).use(it,{theme:"github-dark-dimmed",grid:!0}).use(nt).process(e),r=String(o);this._writeContents(Q.join(this._outputDir,"index.html"),r)}};var O=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}};var R=new ut;R.name("quarkup").description("A simple markdown to HTML compiler").version("1.0.0");R.command("c").description("Compile a file").argument("<source>","file to compile").option("-o, --output <output>","the target output directory","html").action(async(t,e)=>{let o=Z.resolve(t),r=Z.resolve(e.output);z.existsSync(o)||R.error(`Error: The source file "${t}" does not exist.`);try{z.mkdirSync(r,{recursive:!0})}catch{R.error(`Error: Could not create output directory "${e.output}".`)}let n=new P(o,r);try{let i=new O;i.start(),await n.compile(),i.stop();let u=i.secondsElapsed;console.log(`Success: Compilation finished in ${u.toFixed(2)}s`)}catch(i){R.error(`Error: Compilation failed: "${i}"`)}});R.parse();
2
+ import{Command as ft}from"commander";import _ from"path";import F,{globSync as lt}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 v from"fs";import et from"path";import{unified as ot}from"unified";import rt from"remark-parse";import nt from"remark-gfm";import it from"remark-rehype";import st from"rehype-stringify";import ct from"rehype-pretty-code";import pt from"remark-math";import at from"rehype-mathjax/svg";var P=(function(t){if(t==null)return H;if(typeof t=="function")return W(t);if(typeof t=="object")return Array.isArray(t)?X(t):q(t);if(typeof t=="string")return G(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 q(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 G(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 H(){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,S=!1,M="skip";function T(t,e,o,n){let r;typeof e=="function"&&typeof o!="function"?(n=o,o=e):r=e;let i=P(r),c=n?-1:1;u(t,void 0,[])();function u(s,a,l){let d=s&&typeof s=="object"?s:{};if(typeof d.type=="string"){let p=typeof d.tagName=="string"?d.tagName:typeof d.name=="string"?d.name:void 0;Object.defineProperty(k,"name",{value:"node ("+D(s.type+(p?"<"+p+">":""))+")"})}return k;function k(){let p=K,g,y,h;if((!e||i(s,a,l[l.length-1]||void 0))&&(p=Y(o(s,l)),p[0]===S))return p;if("children"in s&&s.children){let b=s;if(b.children&&p[0]!==M)for(y=(n?b.children.length:-1)+c,h=l.concat(b);y>-1&&y<b.children.length;){let w=b.children[y];if(g=u(w,y,h)(),g[0]===S)return g;y=typeof g[1]=="number"?g[1]:y+c}}return p}}}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,c;typeof e=="function"&&typeof o!="function"?(i=void 0,c=e,r=o):(i=e,c=o,r=n),T(t,i,u,r);function u(s,a){let l=a[a.length-1],d=l?l.children.indexOf(s):void 0;return c(s,d,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 J=/([a-zA-Z]+)/,B=/([a-zA-Z]+)/,Z=/\{([^}]+)\}/,z=(t,e)=>{let o=new RegExp(`${t.keywordMark}${J.source}((?:${t.optionMark}${B.source}${Z.source})*)${t.keywordMark}`,"g"),n=[],r=e.matchAll(o);for(let i of r){let[c,u,s]=i,a=i.index,l=a+c.length,d=[],k=new RegExp(`${t.optionMark}${B.source}${Z.source}`,"g"),p;for(;(p=k.exec(s))!==null;)d.push({name:p[1],value:p[2]});n.push({name:u,options:d,start:a,end:l})}return n};import{toc as Q}from"mdast-util-toc";var j=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 x}from"zod";var tt=x.object({maxDepth:x.preprocess(t=>typeof t=="string"?parseInt(t):t,x.union([x.literal(1),x.literal(2),x.literal(3),x.literal(4),x.literal(5),x.literal(6)])).default(6)}),$=class extends j{constructor(){super("tableofcontents",tt)}_use(e,o){let n=Q(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 L=(t={config:{keywordMark:"&",optionMark:":"}})=>{let{config:e}=t,o=[new $],n={};for(let r of o)n[r.name]=r;return r=>{C(r,"paragraph",(i,c,u)=>{if(u===void 0||c===void 0)return;let s=[],a=[],l=!1,d=()=>{a.length>0&&(s.push({type:"paragraph",children:[...a]}),a=[])},k=(p,g)=>{d(),s.push({type:"paragraph",children:[{type:"strong",children:[{type:"text",value:p.name}]},{type:"text",value:" raised error: "},{type:"emphasis",children:[{type:"text",value:g}]}],data:{hProperties:{"data-writedown-error":!0}}})};for(let p of i.children){if(p.type!=="text"){a.push(p);continue}let g=z(e,p.value);if(g.length===0){a.push(p);continue}l=!0;let y=0;for(let h of g){h.start>y&&a.push({type:"text",value:p.value.slice(y,h.start)});let b=n[h.name];if(!b)k(h,`Unknown keyword: "${h.name}"`);else try{let w=b.use(r,h.options);w===null?k(h,`Failed to use: "${h.name}"`):w.type==="phrasing"?a.push(...w.value):w.type==="block"&&(d(),s.push(...w.value))}catch(w){k(h,`Failed to use: "${h.name}", error: ${w}`)}y=h.end}y<p.value.length&&a.push({type:"text",value:p.value.slice(y)})}if(l)return d(),u.children.splice(c,1,...s),c+s.length})}};import ut from"rehype-slug";var I=class{_sourceFile;_outputDir;constructor(e,o){this._sourceFile=e,this._outputDir=o}_readContents(e){if(!v.existsSync(e))throw new Error(`File "${e}" doesn't exist`);return v.readFileSync(e).toString()}_writeContents(e,o){v.writeFileSync(e,o)}async compile(){console.log(`Compiling ${this._sourceFile} to ${this._outputDir}`);let e=this._readContents(this._sourceFile),o=await ot().use(rt).use(pt).use(nt).use(L).use(it).use(ut).use(at).use(A).use(ct,{theme:"github-dark-dimmed",grid:!0}).use(st).process(e),n=String(o);this._writeContents(et.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 I(n,r);try{let c=new E;c.start(),await i.compile(),c.stop();let u=c.secondsElapsed;console.log(`Success: Compilation finished in ${u.toFixed(2)}s`)}catch(c){t.error(`Error: Compilation failed: "${c}"`)}},U=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 c=lt(`${r}/**/${n}`);console.log(`Found ${c.length} projects.`);for(let u=0;u<c.length;u++){console.log();let s=c[u],a=_.basename(_.dirname(s)),l=_.join(o,a);console.log(`[${u}] Compiling project: "${a}"`),await N(t,s,l)}};var R=new ft;R.name("quarkup").description("A simple markdown to HTML compiler").version("1.0.0");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 U(R,t,e.output,e.mainFile)});R.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quarkup",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A markdown extension",
5
5
  "author": "Radek Titěra",
6
6
  "license": "MIT",
package/src/main.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from 'commander';
4
- import path from 'path';
5
- import fs from 'fs';
6
- import { Compiler } from './Compiler.ts';
7
- import { Stopwatch } from './utils/Stopwatch.ts';
4
+ import { compileMultipleProjects, compileSingleProject } from './actions.ts';
8
5
 
9
6
  const program = new Command();
10
7
 
@@ -14,43 +11,32 @@ program
14
11
  .version('1.0.0');
15
12
 
16
13
  program
17
- .command('c')
18
- .description('Compile a file')
19
- .argument('<source>', 'file to compile')
20
- .option('-o, --output <output>', 'the target output directory', 'html')
21
- .action(async (file: string, options: { output: string }) => {
22
- const sourceFile = path.resolve(file);
23
- const outputDir = path.resolve(options.output);
24
-
25
- if (!fs.existsSync(sourceFile)) {
26
- program.error(`Error: The source file "${file}" does not exist.`);
27
- }
14
+ .command('s')
15
+ .description('Compile a single project')
16
+ .argument('<source_file>', 'source file to compile')
17
+ .option('-o, --output <output_folder>', 'the target output folder', 'html')
18
+ .action(async (sourceFile: string, options: { output: string }) => {
19
+ await compileSingleProject(program, sourceFile, options.output);
20
+ });
28
21
 
29
- try {
30
- fs.mkdirSync(outputDir, { recursive: true });
31
- } catch {
32
- program.error(
33
- `Error: Could not create output directory "${options.output}".`,
22
+ program
23
+ .command('m')
24
+ .description('Compile multiple projects')
25
+ .argument('<input_folder>', 'folder containing projects in subfolders')
26
+ .option('-o, --output <output_folder>', 'the target output folder', 'html')
27
+ .option('-m, --main-file <main_file>', 'main.md')
28
+ .action(
29
+ async (
30
+ inputFolder: string,
31
+ options: { output: string; mainFile: string },
32
+ ) => {
33
+ await compileMultipleProjects(
34
+ program,
35
+ inputFolder,
36
+ options.output,
37
+ options.mainFile,
34
38
  );
35
- }
36
-
37
- const compiler = new Compiler(sourceFile, outputDir);
38
-
39
- try {
40
- const stopwatch = new Stopwatch();
41
-
42
- stopwatch.start();
43
-
44
- await compiler.compile();
45
-
46
- stopwatch.stop();
47
-
48
- const duration = stopwatch.secondsElapsed;
49
-
50
- console.log(`Success: Compilation finished in ${duration.toFixed(2)}s`);
51
- } catch (err) {
52
- program.error(`Error: Compilation failed: "${err}"`);
53
- }
54
- });
39
+ },
40
+ );
55
41
 
56
42
  program.parse();