md2x 0.5.2 → 0.7.0
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 +196 -14
- package/dist/chunks/{chunk-5DRL26RK.js → chunk-EFKQH5UR.js} +23 -23
- package/dist/chunks/chunk-XTD75532.js +1023 -0
- package/dist/chunks/{docx-exporter-FGXU5MTK.js → docx-exporter-ZZ76JXFU.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/md2x.js +11 -9
- package/dist/renderer/puppeteer-render-worker.js +97 -90
- package/dist/templates/html/example.html +35 -0
- package/dist/templates/vue/PrinterComponent.vue +875 -0
- package/dist/templates/vue/example.vue +17 -0
- package/dist/types/node/src/host/browser-renderer.d.ts +120 -0
- package/dist/types/node/src/host/index.d.ts +16 -2
- package/dist/types/node/src/host/node-exporter.d.ts +54 -23
- package/dist/types/node/src/index.d.ts +4 -4
- package/dist/types/src/plugins/md2x-plugin.d.ts +9 -0
- package/package.json +1 -1
- package/dist/chunks/chunk-KEWRLSTT.js +0 -723
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"./chunk-
|
|
1
|
+
import{a,b}from"./chunk-EFKQH5UR.js";import"./chunk-DFROP2PD.js";import"./chunk-3P5X57NT.js";import"./chunk-CVKZIRZW.js";import"./chunk-DJGIYXVP.js";import"./chunk-URO5RPHJ.js";import"./chunk-YFL3W3OS.js";import"./chunk-3VL755NO.js";import"./chunk-2LPNL4GA.js";import"./chunk-MHCTK6WW.js";import"./chunk-R6G2575A.js";import"./chunk-AK6TXLWO.js";import"./chunk-PUOHPY5L.js";import"./chunk-R65AQGTF.js";import"./chunk-TRGQPVRY.js";import"./chunk-CN4F5HOV.js";import"./chunk-LLCWR7UA.js";import"./chunk-PARPCLXM.js";import"./chunk-IENSDROB.js";import"./chunk-5DPTQTJJ.js";import"./chunk-Z4LVGK7Y.js";import"./chunk-NM6J3ND7.js";export{a as convertPluginResultToDOCX,b as default};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t,b as r,c as e,d as
|
|
1
|
+
import{a as t,b as r,c as e,d as m,e as p,f as n,h as a,i as d,j as f,k as i,l as s,m as x,n as l,o as u}from"./chunks/chunk-XTD75532.js";import"./chunks/chunk-EFKQH5UR.js";import"./chunks/chunk-DFROP2PD.js";import"./chunks/chunk-3P5X57NT.js";import"./chunks/chunk-CVKZIRZW.js";import"./chunks/chunk-DJGIYXVP.js";import"./chunks/chunk-URO5RPHJ.js";import"./chunks/chunk-YFL3W3OS.js";import"./chunks/chunk-3VL755NO.js";import"./chunks/chunk-2LPNL4GA.js";import"./chunks/chunk-MHCTK6WW.js";import"./chunks/chunk-R6G2575A.js";import"./chunks/chunk-AK6TXLWO.js";import"./chunks/chunk-PUOHPY5L.js";import"./chunks/chunk-R65AQGTF.js";import"./chunks/chunk-TRGQPVRY.js";import"./chunks/chunk-CN4F5HOV.js";import"./chunks/chunk-LLCWR7UA.js";import"./chunks/chunk-PARPCLXM.js";import"./chunks/chunk-IENSDROB.js";import"./chunks/chunk-5DPTQTJJ.js";import"./chunks/chunk-Z4LVGK7Y.js";import"./chunks/chunk-NM6J3ND7.js";import*as o from"path";import{fileURLToPath as O}from"url";var _=O(import.meta.url),T=o.dirname(_);globalThis.__md2x_module_dir__=T;export{t as NodeDocxExporter,m as NodeHtmlExporter,e as NodeImageExporter,r as NodePdfExporter,l as convert,u as convertFile,n as frontMatterToOptions,a as markdownToDocxBuffer,i as markdownToHtmlBuffer,f as markdownToHtmlString,s as markdownToImageBuffer,x as markdownToImageBuffers,d as markdownToPdfBuffer,p as parseFrontMatter};
|
package/dist/md2x.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
md2x - Convert Markdown to PDF, DOCX, or
|
|
2
|
+
import{e as _,f as j,g as y,n as k}from"./chunks/chunk-XTD75532.js";import"./chunks/chunk-EFKQH5UR.js";import"./chunks/chunk-DFROP2PD.js";import"./chunks/chunk-3P5X57NT.js";import"./chunks/chunk-CVKZIRZW.js";import"./chunks/chunk-DJGIYXVP.js";import"./chunks/chunk-URO5RPHJ.js";import"./chunks/chunk-YFL3W3OS.js";import"./chunks/chunk-3VL755NO.js";import"./chunks/chunk-2LPNL4GA.js";import"./chunks/chunk-MHCTK6WW.js";import"./chunks/chunk-R6G2575A.js";import"./chunks/chunk-AK6TXLWO.js";import"./chunks/chunk-PUOHPY5L.js";import"./chunks/chunk-R65AQGTF.js";import"./chunks/chunk-TRGQPVRY.js";import"./chunks/chunk-CN4F5HOV.js";import"./chunks/chunk-LLCWR7UA.js";import"./chunks/chunk-PARPCLXM.js";import"./chunks/chunk-IENSDROB.js";import"./chunks/chunk-5DPTQTJJ.js";import"./chunks/chunk-Z4LVGK7Y.js";import"./chunks/chunk-NM6J3ND7.js";import*as a from"fs";import*as n from"path";import{fileURLToPath as I}from"url";var L=I(import.meta.url),T=n.dirname(L);globalThis.__md2x_module_dir__=T;function O(){return globalThis.__md2x_module_dir__||T}function R(o){let e=n.extname(o).toLowerCase();return e===".pdf"?"pdf":e===".docx"?"docx":e===".html"||e===".htm"?"html":e===".png"?"png":e===".jpg"?"jpg":e===".jpeg"?"jpeg":e===".webp"?"webp":null}function B(){let o=O(),e=[n.join(o,"themes","presets"),n.resolve(o,"../../src/themes/presets"),n.resolve(process.cwd(),"src/themes/presets")];for(let t of e)try{if(a.existsSync(t)&&a.statSync(t).isDirectory())return t}catch{}return null}function v(){let o=B();if(!o)return["default"];try{let e=a.readdirSync(o,{withFileTypes:!0}).filter(s=>s.isFile()&&s.name.endsWith(".json")).map(s=>s.name.replace(/\.json$/i,"")).filter(s=>s.length>0).sort();return["default",...Array.from(new Set(e)).filter(s=>s!=="default")]}catch{return["default"]}}function S(o){return o.join(", ")}function $(){let o=v();console.log(`
|
|
3
|
+
md2x - Convert Markdown to PDF, DOCX, HTML, or Image
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
6
|
npx md2x <input.md> [output] [options]
|
|
@@ -12,12 +12,13 @@ Arguments:
|
|
|
12
12
|
|
|
13
13
|
Options:
|
|
14
14
|
-o, --output Output file path
|
|
15
|
-
-f, --format Output format: pdf, docx, or
|
|
15
|
+
-f, --format Output format: pdf, docx, html, png, jpg/jpeg, or webp (default: "pdf")
|
|
16
16
|
-t, --theme Theme name (default: "default")
|
|
17
17
|
-h, --help Show this help message
|
|
18
18
|
-v, --version Show version number
|
|
19
|
-
--diagram-mode
|
|
20
|
-
--hr-page-break Convert horizontal rules to page breaks: true | false (default: true for PDF/DOCX; false for HTML)
|
|
19
|
+
--diagram-mode img | live | none (default: img for DOCX; live for HTML/Image)
|
|
20
|
+
--hr-page-break Convert horizontal rules to page breaks: true | false (default: true for PDF/DOCX; false for HTML/Image)
|
|
21
|
+
--templates-dir Extra template dir for md2x blocks (repeatable; resolved against input dir when relative)
|
|
21
22
|
--list-themes List all available themes
|
|
22
23
|
|
|
23
24
|
Examples:
|
|
@@ -27,11 +28,12 @@ Examples:
|
|
|
27
28
|
npx md2x README.md -f docx --hr-page-break false
|
|
28
29
|
npx md2x README.md -f docx -o output.docx --theme minimal
|
|
29
30
|
npx md2x README.md -f html -o output.html
|
|
31
|
+
npx md2x README.md -f png -o output.png
|
|
30
32
|
npx md2x --list-themes
|
|
31
33
|
|
|
32
34
|
Available Themes:
|
|
33
|
-
${
|
|
34
|
-
`)}function
|
|
35
|
+
${S(o)}
|
|
36
|
+
`)}function N(){let o=O(),e=[n.join(o,"../package.json"),n.join(o,"../../package.json")];for(let t of e)try{let p=JSON.parse(a.readFileSync(t,"utf-8"));if(p?.version){console.log(`md2x v${p.version}`);return}}catch{}console.log("md2x v1.0.0")}function U(){let o=v();console.log(`
|
|
35
37
|
Available Themes:
|
|
36
|
-
`),o.forEach(e=>{console.log(` - ${e}`)}),console.log("")}function
|
|
37
|
-
`)
|
|
38
|
+
`),o.forEach(e=>{console.log(` - ${e}`)}),console.log("")}function H(o){let e={input:"",output:"",theme:"default",format:"pdf",help:!1,version:!1,listThemes:!1,diagramMode:"live",templatesDir:[],hrPageBreak:null,_explicit:new Set},t=0,p=[];for(;t<o.length;){let s=o[t];if(s==="--"){t++;continue}if(s==="-h"||s==="--help")e.help=!0;else if(s==="-v"||s==="--version")e.version=!0;else if(s==="--list-themes")e.listThemes=!0;else if(s==="--diagram-mode")if(t++,t<o.length){let r=String(o[t]).toLowerCase();r!=="img"&&r!=="live"&&r!=="none"&&(console.error(`Error: Invalid --diagram-mode "${o[t]}". Must be "img", "live", or "none".`),process.exit(1)),e.diagramMode=r,e._explicit.add("diagramMode")}else console.error("Error: --diagram-mode requires a value (img | live | none)"),process.exit(1);else if(s==="-o"||s==="--output")t++,t<o.length?e.output=o[t]:(console.error("Error: --output requires a file path"),process.exit(1));else if(s==="-t"||s==="--theme")t++,t<o.length?(e.theme=o[t],e._explicit.add("theme")):(console.error("Error: --theme requires a theme name"),process.exit(1));else if(s==="-f"||s==="--format")if(t++,t<o.length){let r=o[t].toLowerCase();r!=="pdf"&&r!=="docx"&&r!=="html"&&r!=="png"&&r!=="jpg"&&r!=="jpeg"&&r!=="webp"&&(console.error(`Error: Invalid format "${o[t]}". Must be "pdf", "docx", "html", "png", "jpg/jpeg", or "webp".`),process.exit(1)),e.format=r,e._explicit.add("format")}else console.error("Error: --format requires a format (pdf, docx, html, png, jpg/jpeg, or webp)"),process.exit(1);else if(s==="--hr-page-break")if(t++,t<o.length){let r=o[t].toLowerCase();r!=="true"&&r!=="false"&&(console.error(`Error: Invalid --hr-page-break "${o[t]}". Must be "true" or "false".`),process.exit(1)),e.hrPageBreak=r==="true",e._explicit.add("hrPageBreak")}else console.error("Error: --hr-page-break requires a value (true | false)"),process.exit(1);else if(s==="--templates-dir")if(t++,t<o.length){let r=String(o[t]).trim();r||(console.error("Error: --templates-dir requires a non-empty path"),process.exit(1)),e.templatesDir.push(r),e._explicit.add("templatesDir")}else console.error("Error: --templates-dir requires a path"),process.exit(1);else s.startsWith("-")?(console.error(`Error: Unknown option: ${s}`),process.exit(1)):p.push(s);t++}return p.length>0&&(e.input=p[0]),p.length>1&&!e.output&&(e.output=p[1]),e}async function W(){let o=process.argv.slice(2),e=H(o);e.help&&($(),process.exit(0)),e.version&&(N(),process.exit(0)),e.listThemes&&(U(),process.exit(0)),e.input||(console.error(`Error: Input file is required
|
|
39
|
+
`),$(),process.exit(1));let t=n.resolve(e.input);a.existsSync(t)||(console.error(`Error: Input file not found: ${t}`),process.exit(1));try{a.accessSync(t,a.constants.R_OK)}catch{console.error(`Error: Cannot read input file: ${t}`),process.exit(1)}let p=a.readFileSync(t,"utf-8"),s=_(p),r=s.hasFrontMatter?j(s.data):{},F=!e._explicit.has("format")&&e.output?R(e.output):null,i=e._explicit.has("format")?e.format:r.format??F??e.format,f=e._explicit.has("theme")?e.theme:r.theme??e.theme,b=i==="png"||i==="jpg"||i==="jpeg"||i==="webp",P=i==="docx"?"img":"live",D=e._explicit.has("diagramMode")?e.diagramMode:r.diagramMode??P,A=e._explicit.has("templatesDir")?e.templatesDir:r.templatesDir??e.templatesDir,E=e._explicit.has("hrPageBreak")?e.hrPageBreak:r.hrAsPageBreak??!(i==="html"||i==="png"||i==="jpg"||i==="jpeg"||i==="webp"),h=v();h.length>0&&!h.includes(f)&&(console.error(`Error: Unknown theme: ${f}`),console.error(`Available themes: ${S(h)}`),console.error("Tip: run `npx md2x --list-themes` to see the full list."),process.exit(1)),console.log(`Converting: ${n.basename(t)}`),console.log(`Format: ${i.toUpperCase()}`),console.log(`Theme: ${f}`),console.log(`HR as page break: ${E}`),(i==="pdf"||i==="html"||i==="png"||i==="jpg"||i==="jpeg"||i==="webp")&&console.log(`Diagram mode: ${D}`);try{let l=e.output,m=y(i);if(l)l=n.resolve(l);else{let u=n.dirname(t),g=n.basename(t,n.extname(t));l=n.join(u,`${g}${m}`)}let w=n.dirname(l);a.existsSync(w)||a.mkdirSync(w,{recursive:!0});let C=b?{...r.image??{},type:i==="jpg"?"jpeg":i,split:r.image?.split??"auto"}:void 0,c=await k(s.content,{format:i,theme:f,diagramMode:D,hrAsPageBreak:E,basePath:n.dirname(t),title:r.title??n.basename(t,n.extname(t)),pdf:r.pdf,standalone:r.standalone,baseTag:r.baseTag,cdn:r.cdn,templatesDir:A,image:C,skipFrontMatter:!0});if(b){let u=c.buffers&&c.buffers.length>0?c.buffers:[c.buffer];if(u.length<=1){a.writeFileSync(l,u[0]),console.log(`Output: ${l}`),console.log("Done!");return}let g=l.endsWith(m)?l.slice(0,-m.length):l,x=[];for(let d=0;d<u.length;d++){let q=String(d+1).padStart(3,"0"),M=`${g}.part-${q}${m}`;a.writeFileSync(M,u[d]),x.push(M)}console.log(`Output: ${x[0]} (+${x.length-1} parts)`),console.log("Done!");return}a.writeFileSync(l,c.buffer),console.log(`Output: ${l}`),console.log("Done!")}catch(l){let m=l instanceof Error?l.message:String(l);console.error(`Error during conversion: ${m}`),process.exit(1)}}W().catch(o=>{console.error("Unexpected error:",o),process.exit(1)});
|