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.
@@ -1 +1 @@
1
- import{a,b}from"./chunk-5DRL26RK.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};
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 p,e as n,f as m,g as a,h as d,i as f,j as i,k as s}from"./chunks/chunk-KEWRLSTT.js";import"./chunks/chunk-5DRL26RK.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 l}from"url";var x=l(import.meta.url),_=o.dirname(x);globalThis.__md2x_module_dir__=_;export{t as NodeDocxExporter,e as NodeHtmlExporter,r as NodePdfExporter,i as convert,s as convertFile,n as frontMatterToOptions,m as markdownToDocxBuffer,f as markdownToHtmlBuffer,d as markdownToHtmlString,a as markdownToPdfBuffer,p as parseFrontMatter};
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{d as x,e as v,j as b}from"./chunks/chunk-KEWRLSTT.js";import"./chunks/chunk-5DRL26RK.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 i from"fs";import*as n from"path";import{fileURLToPath as $}from"url";var w=$(import.meta.url),M=n.dirname(w);globalThis.__md2x_module_dir__=M;function _(){return globalThis.__md2x_module_dir__||M}function O(){let 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(i.existsSync(t)&&i.statSync(t).isDirectory())return t}catch{}return null}function d(){let o=O();if(!o)return["default"];try{let e=i.readdirSync(o,{withFileTypes:!0}).filter(r=>r.isFile()&&r.name.endsWith(".json")).map(r=>r.name.replace(/\.json$/i,"")).filter(r=>r.length>0).sort();return["default",...Array.from(new Set(e)).filter(r=>r!=="default")]}catch{return["default"]}}function k(o){return o.join(", ")}function E(){let o=d();console.log(`
3
- md2x - Convert Markdown to PDF, DOCX, or HTML
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 html (default: "pdf")
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 HTML only: img | live | none (default: live)
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
- ${k(o)}
34
- `)}function S(){let o=_(),e=[n.join(o,"../package.json"),n.join(o,"../../package.json")];for(let t of e)try{let a=JSON.parse(i.readFileSync(t,"utf-8"));if(a?.version){console.log(`md2x v${a.version}`);return}}catch{}console.log("md2x v1.0.0")}function P(){let o=d();console.log(`
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 A(o){let e={input:"",output:"",theme:"default",format:"pdf",help:!1,version:!1,listThemes:!1,diagramMode:"live",hrPageBreak:null,_explicit:new Set},t=0,a=[];for(;t<o.length;){let r=o[t];if(r==="--"){t++;continue}if(r==="-h"||r==="--help")e.help=!0;else if(r==="-v"||r==="--version")e.version=!0;else if(r==="--list-themes")e.listThemes=!0;else if(r==="--diagram-mode")if(t++,t<o.length){let s=String(o[t]).toLowerCase();s!=="img"&&s!=="live"&&s!=="none"&&(console.error(`Error: Invalid --diagram-mode "${o[t]}". Must be "img", "live", or "none".`),process.exit(1)),e.diagramMode=s,e._explicit.add("diagramMode")}else console.error("Error: --diagram-mode requires a value (img | live | none)"),process.exit(1);else if(r==="-o"||r==="--output")t++,t<o.length?e.output=o[t]:(console.error("Error: --output requires a file path"),process.exit(1));else if(r==="-t"||r==="--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(r==="-f"||r==="--format")if(t++,t<o.length){let s=o[t].toLowerCase();s!=="pdf"&&s!=="docx"&&s!=="html"&&(console.error(`Error: Invalid format "${o[t]}". Must be "pdf", "docx", or "html".`),process.exit(1)),e.format=s,e._explicit.add("format")}else console.error("Error: --format requires a format (pdf, docx, or html)"),process.exit(1);else if(r==="--hr-page-break")if(t++,t<o.length){let s=o[t].toLowerCase();s!=="true"&&s!=="false"&&(console.error(`Error: Invalid --hr-page-break "${o[t]}". Must be "true" or "false".`),process.exit(1)),e.hrPageBreak=s==="true",e._explicit.add("hrPageBreak")}else console.error("Error: --hr-page-break requires a value (true | false)"),process.exit(1);else r.startsWith("-")?(console.error(`Error: Unknown option: ${r}`),process.exit(1)):a.push(r);t++}return a.length>0&&(e.input=a[0]),a.length>1&&!e.output&&(e.output=a[1]),e}async function F(){let o=process.argv.slice(2),e=A(o);e.help&&(E(),process.exit(0)),e.version&&(S(),process.exit(0)),e.listThemes&&(P(),process.exit(0)),e.input||(console.error(`Error: Input file is required
37
- `),E(),process.exit(1));let t=n.resolve(e.input);i.existsSync(t)||(console.error(`Error: Input file not found: ${t}`),process.exit(1));try{i.accessSync(t,i.constants.R_OK)}catch{console.error(`Error: Cannot read input file: ${t}`),process.exit(1)}let a=i.readFileSync(t,"utf-8"),r=x(a),s=r.hasFrontMatter?v(r.data):{},p=e._explicit.has("format")?e.format:s.format??e.format,c=e._explicit.has("theme")?e.theme:s.theme??e.theme,f=e._explicit.has("diagramMode")?e.diagramMode:s.diagramMode??e.diagramMode,h=e._explicit.has("hrPageBreak")?e.hrPageBreak:s.hrAsPageBreak??p!=="html",u=d();u.length>0&&!u.includes(c)&&(console.error(`Error: Unknown theme: ${c}`),console.error(`Available themes: ${k(u)}`),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: ${p.toUpperCase()}`),console.log(`Theme: ${c}`),console.log(`HR as page break: ${h}`),p==="html"&&console.log(`Diagram mode: ${f}`);try{let m=await b(r.content,{format:p,theme:c,diagramMode:f,hrAsPageBreak:h,basePath:n.dirname(t),title:s.title??n.basename(t,n.extname(t)),pdf:s.pdf,standalone:s.standalone,baseTag:s.baseTag,cdn:s.cdn,skipFrontMatter:!0}),l=e.output,y=p==="pdf"?".pdf":p==="docx"?".docx":".html";if(l)l=n.resolve(l);else{let D=n.dirname(t),T=n.basename(t,n.extname(t));l=n.join(D,`${T}${y}`)}let g=n.dirname(l);i.existsSync(g)||i.mkdirSync(g,{recursive:!0}),i.writeFileSync(l,m.buffer),console.log(`Output: ${l}`),console.log("Done!")}catch(m){let l=m instanceof Error?m.message:String(m);console.error(`Error during conversion: ${l}`),process.exit(1)}}F().catch(o=>{console.error("Unexpected error:",o),process.exit(1)});
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)});