quarkup 0.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ ## License
2
+
3
+ This project is licensed under the MIT License.
4
+
5
+ # MIT License
6
+
7
+ Copyright (c) 2026 Radek Titěra
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Quarkup
2
+
3
+ A simple markdown extension that compiles markdown into tailwind styled html
4
+
5
+ ## Disclaimer
6
+
7
+ This package is still work in progress.
8
+
9
+ ## Example
10
+
11
+ Compile `demo/main.md` into `test-web/html/`.
12
+
13
+ ```sh
14
+ node src/main.ts c demo/main.md -o test-web/html
15
+ ```
16
+
17
+ ## Features
18
+
19
+ - [x] Paragraphs
20
+ - [x] Headings with slugs
21
+ - [x] Links
22
+ - [x] Code blocks
23
+ - [x] [GitHub Flavored Markdown](https://github.github.com/gfm/)
24
+ - [x] Table of Contents
25
+ - [ ] References and Sources
26
+ - [ ] Local images
27
+
28
+ ## Custom Syntax
29
+
30
+ Writedown uses keywords with options:
31
+
32
+ ```md
33
+ $keyword:optionA{value}:optionB{value}&
34
+ ```
35
+
36
+ the keyword (`$`) and option (`:`) marks can be configured.
37
+
38
+ ### Supported Keywords
39
+
40
+ - `$tableofcontents:maxDepth{1-6 [default: 6]}$` - Creates a table of contents
package/dist/main.js ADDED
@@ -0,0 +1,2 @@
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();
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "quarkup",
3
+ "version": "0.0.1",
4
+ "description": "A markdown extension",
5
+ "author": "Radek Titěra",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "markdown"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Rodak123/quarkup.git"
13
+ },
14
+ "type": "module",
15
+ "main": "src/main.ts",
16
+ "bin": {
17
+ "quarkup": "./dist/main.js"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "lint": "eslint .",
24
+ "build": "tsup src/main.ts --format esm --clean --minify --shims",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^24.12.4",
29
+ "eslint": "^9.39.1",
30
+ "tailwindcss": "^4.1.18",
31
+ "tsup": "^8.5.1",
32
+ "typescript": "~5.9.3",
33
+ "typescript-eslint": "^8.46.4"
34
+ },
35
+ "dependencies": {
36
+ "@shikijs/transformers": "^4.1.0",
37
+ "@types/mdast": "^4.0.4",
38
+ "commander": "^15.0.0",
39
+ "mdast": "^2.3.2",
40
+ "mdast-util-toc": "^7.1.0",
41
+ "rehype-mathjax": "^7.1.0",
42
+ "rehype-pretty-code": "^0.14.3",
43
+ "rehype-slug": "^6.0.0",
44
+ "rehype-stringify": "^10.0.1",
45
+ "remark-gfm": "^4.0.1",
46
+ "remark-math": "^6.0.0",
47
+ "remark-parse": "^11.0.0",
48
+ "remark-rehype": "^11.1.2",
49
+ "unified": "^11.0.5",
50
+ "zod": "^4.4.3"
51
+ }
52
+ }
package/src/main.ts ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+
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';
8
+
9
+ const program = new Command();
10
+
11
+ program
12
+ .name('quarkup')
13
+ .description('A simple markdown to HTML compiler')
14
+ .version('1.0.0');
15
+
16
+ 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
+ }
28
+
29
+ try {
30
+ fs.mkdirSync(outputDir, { recursive: true });
31
+ } catch {
32
+ program.error(
33
+ `Error: Could not create output directory "${options.output}".`,
34
+ );
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
+ });
55
+
56
+ program.parse();