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 +26 -9
- package/dist/main.js +1 -1
- package/package.json +1 -1
- package/src/main.ts +26 -40
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
|
-
##
|
|
9
|
+
## Contents
|
|
10
10
|
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
###
|
|
50
|
+
### Table of Contents
|
|
51
|
+
|
|
52
|
+
Example: `$tableofcontents:maxDepth{1-6 [default: 6]}$`
|
|
53
|
+
|
|
54
|
+
Keyword: `tableofcontents`
|
|
39
55
|
|
|
40
|
-
|
|
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
|
|
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
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
|
|
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('
|
|
18
|
-
.description('Compile a
|
|
19
|
-
.argument('<
|
|
20
|
-
.option('-o, --output <
|
|
21
|
-
.action(async (
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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();
|