md2x 0.7.5 → 0.7.7
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 +50 -18
- package/dist/chunks/{chunk-54X5GPSM.js → chunk-HHNNUKAW.js} +71 -71
- package/dist/chunks/{chunk-US45GBOT.js → chunk-UZ7TETMS.js} +1 -1
- package/dist/chunks/docx-exporter-GL6CNCQD.js +1 -0
- package/dist/chunks/mcp-server-V5MM5C5I.js +53 -0
- package/dist/index.js +1 -1
- package/dist/md2x.js +8 -5
- package/dist/renderer/live-runtime-md2x.js +1 -1
- package/package.json +4 -2
- package/dist/chunks/docx-exporter-7C6T4DFB.js +0 -1
|
@@ -363,7 +363,7 @@ l0,-`+(r+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
363
363
|
`),o=r.slice(n+1).join(`
|
|
364
364
|
`);return[i,o]}parseFrontmatterData(t){let r=t.split(`
|
|
365
365
|
`),n={};for(let a of r){let i=a.indexOf(":");if(i>0){let o=a.substring(0,i).trim(),s=a.substring(i+1).trim();o&&(n[o]=s)}}return n}parseMarkdown(t){let[r,n]=this.extractFrontmatter(t);this.frontmatterContent=r;let a=hT().use(bp).use(x8).use(Op,{singleTilde:!1}).use(t0).use(r0).use(ux),i=a.parse(n),o=a.runSync(i);return this.linkDefinitions=new Map,Un(o,"definition",s=>{let l=s;l.identifier&&this.linkDefinitions.set(l.identifier.toLowerCase(),{url:l.url||"",title:l.title??null})}),o}isTocMarker(t){if(t.type!=="paragraph"||!t.children||t.children.length!==1)return!1;let r=t.children[0];if(r.type!=="text")return!1;let n=(r.value||"").trim();return/^\[toc\]$/i.test(n)}async convertFrontmatterToDocx(){if(!this.frontmatterContent||this.frontmatterDisplay==="hide")return[];let t=[],r=this.themeStyles?.default?.paragraph?.spacing||{before:0,after:200,line:276};if(this.frontmatterDisplay==="table"){let n=this.parseFrontmatterData(this.frontmatterContent),a=Object.entries(n);if(a.length>0&&this.tableConverter){let i={type:"table",align:["left","left"],children:[{type:"tableRow",children:[{type:"tableCell",children:[{type:"text",value:"Property"}]},{type:"tableCell",children:[{type:"text",value:"Value"}]}]},...a.map(([s,l])=>({type:"tableRow",children:[{type:"tableCell",children:[{type:"text",value:s}]},{type:"tableCell",children:[{type:"text",value:l}]}]}))]},o=await this.tableConverter.convertTable(i);t.push(o),t.push(new pt({text:"",spacing:{before:r.before,after:r.after}}))}}else if(this.frontmatterDisplay==="raw"){let n=this.themeStyles?.characterStyles?.code||{font:"Consolas",size:20},a=this.themeStyles?.characterStyles?.code?.background||"F6F8FA",i=this.themeStyles?.codeColors?.foreground||"24292E",o=[];this.frontmatterContent.split(`
|
|
366
|
-
`).forEach((l,c)=>{c>0&&o.push(new Et({break:1})),o.push(new Et({text:l||" ",font:n.font,size:n.size,color:i}))}),t.push(new pt({children:o,wordWrap:!0,alignment:tt.LEFT,spacing:{before:200,after:200,line:276},shading:{fill:a},indent:{left:200,right:200},border:{top:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},bottom:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},left:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},right:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6}}})),t.push(new pt({text:"",spacing:{before:r.before,after:r.after}}))}return t}async convertAstToDocx(t){let r=[],n=null;this.listInstanceCounter=0;let a=await this.convertFrontmatterToDocx();if(r.push(...a),a.length>0&&(n="frontmatter"),!t.children)return r;for(let i of t.children){if(this.isTocMarker(i)){let s=new Vm("Contents",{hyperlink:!0,headingStyleRange:"1-6"});r.push(s),r.push(new pt({text:"",spacing:{before:240,after:120}})),n="toc";continue}!this.docxHrAsPageBreak&&i.type==="thematicBreak"&&n==="thematicBreak"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:0,after:0,line:1,lineRule:"exact"}})),i.type==="table"&&n==="table"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:120,after:120,line:240}})),i.type==="blockquote"&&n==="blockquote"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:120,after:120,line:240}}));let o=await this.convertNode(i);o&&(Array.isArray(o)?r.push(...o):r.push(o)),n=i.type}return r}async convertNode(t,r={},n=0,a=0){let i={Paragraph:pt,TextRun:Et,ImageRun:$i,AlignmentType:tt,convertInchesToTwip:$t,themeStyles:this.themeStyles},o=this.renderer?{render:async(l,c)=>{let u=await this.renderer.render(l,c);if(!u)throw new Error("Plugin renderer returned empty result");if(typeof u.width!="number"||typeof u.height!="number")throw new Error("Plugin renderer returned invalid dimensions");let d=typeof u.format=="string"&&u.format?u.format:"png";return{base64:u.base64,width:u.width,height:u.height,format:d,error:u.error}}}:{render:async()=>{throw new Error("Renderer not available")}},s=await UP(t,o,i,()=>this.reportResourceProgress());if(s)return s;switch(t.type){case"heading":return this.convertHeading(t);case"paragraph":return await this.convertParagraph(t,r);case"list":return await this.listConverter.convertList(t);case"code":return this.convertCodeBlock(t,n,a);case"blockquote":return await this.blockquoteConverter.convertBlockquote(t,n);case"table":return await this.tableConverter.convertTable(t,n);case"thematicBreak":return this.convertThematicBreak();case"html":return this.convertHtml(t);case"math":return this.convertMathBlock(t);default:return null}}convertHeading(t){let r={1:Mo.HEADING_1,2:Mo.HEADING_2,3:Mo.HEADING_3,4:Mo.HEADING_4,5:Mo.HEADING_5,6:Mo.HEADING_6},n=this.inlineConverter.extractText({type:"root",children:t.children||[]}),a=t.depth||1,i=this.themeStyles?.paragraphStyles?.[`heading${a}`],o={text:n,heading:r[a]||Mo.HEADING_1};return i?.paragraph?.alignment==="center"&&(o.alignment=tt.CENTER),new pt(o)}async convertParagraph(t,r={}){let n=await this.inlineConverter.convertInlineNodes(t.children||[],r),a=this.themeStyles?.default?.paragraph?.spacing||{before:0,after:200,line:276};return new pt({children:n.length>0?n:void 0,text:n.length===0?"":void 0,spacing:{before:a.before,after:a.after,line:a.line},alignment:tt.LEFT})}convertCodeBlock(t,r=0,n=0){let a=this.codeHighlighter.getHighlightedRunsForCode(t.value??"",t.lang),i=this.themeStyles?.characterStyles?.code?.background||"F6F8FA",o=200,l=(r>0?$t(.5*r):0)+o,c=n>0?300*n:0,u=o+c;return new pt({children:a,wordWrap:!0,alignment:tt.LEFT,spacing:{before:200,after:200,line:276},shading:{fill:i},indent:{left:l,right:u},border:{top:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},bottom:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},left:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},right:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6}}})}convertHtml(t){return new pt({children:[new Et({text:"[HTML Content]",italics:!0,color:"666666"})],alignment:tt.LEFT,spacing:{before:120,after:120}})}convertThematicBreak(){return this.docxHrAsPageBreak?new pt({pageBreakBefore:!0,children:[new Et({text:"",size:1})],spacing:{before:0,after:0,line:1,lineRule:"exact"},alignment:tt.LEFT}):new pt({text:"",alignment:tt.LEFT,spacing:{before:300,after:300,line:120,lineRule:"exact"},border:{bottom:{color:"E1E4E8",space:1,style:Ct.SINGLE,size:12}}})}convertMathBlock(t){try{let r=tp(t.value||"");return new pt({children:[r],spacing:{before:120,after:120},alignment:tt.CENTER})}catch(r){console.warn("Math conversion error:",r);let n=this.themeStyles?.characterStyles?.code||{font:"Consolas",size:20};return new pt({children:[new Et({text:t.value||"",font:n.font,size:n.size})],alignment:tt.LEFT,spacing:{before:120,after:120}})}}toAlignmentType(t){if(!t)return;let r=t.trim().toLowerCase();if(!r)return;let a={left:tt.LEFT,center:tt.CENTER,right:tt.RIGHT,justify:tt.JUSTIFIED,justified:tt.JUSTIFIED,start:tt.START,end:tt.END}[r];return a||(Object.values(tt).includes(r)?r:void 0)}toDocumentDefaults(t){let r=t.paragraph?{spacing:t.paragraph.spacing,alignment:this.toAlignmentType(t.paragraph.alignment)}:void 0;return{run:t.run,paragraph:r}}toHeadingStyle(t){let r={spacing:t.paragraph.spacing,alignment:this.toAlignmentType(t.paragraph.alignment)};return{name:t.name,basedOn:t.basedOn,next:t.next,run:t.run,paragraph:r}}async fetchImageAsBuffer(t){if(this.imageCache.has(t))return this.imageCache.get(t);if(t.startsWith("data:")){let a=t.match(/^data:([^;,]+)[^,]*,(.+)$/);if(!a)throw new Error("Invalid data URL format");let i=a[1],o=atob(a[2]),s=new Uint8Array(o.length);for(let c=0;c<o.length;c++)s[c]=o.charCodeAt(c);let l={buffer:s,contentType:i};return this.imageCache.set(t,l),l}let r=this.getDocumentService();if(!r)throw new Error("DocumentService not available - platform not initialized");let n=t.startsWith("http://")||t.startsWith("https://");try{if(n){let a=await r.fetchRemote(t),i=this.guessContentType(t),o={buffer:a,contentType:i};return this.imageCache.set(t,o),o}else{let a=await r.readRelativeFile(t,{binary:!0}),i=atob(a),o=new Uint8Array(i.length);for(let c=0;c<i.length;c++)o[c]=i.charCodeAt(c);let s=this.guessContentType(t),l={buffer:o,contentType:s};return this.imageCache.set(t,l),l}}catch(a){throw new Error(`Failed to fetch image: ${t} - ${a.message}`)}}guessContentType(t){let r=t.split(".").pop()?.toLowerCase().split("?")[0]||"";return{png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml"}[r]||"image/png"}},F6e=wS;export{
|
|
366
|
+
`).forEach((l,c)=>{c>0&&o.push(new Et({break:1})),o.push(new Et({text:l||" ",font:n.font,size:n.size,color:i}))}),t.push(new pt({children:o,wordWrap:!0,alignment:tt.LEFT,spacing:{before:200,after:200,line:276},shading:{fill:a},indent:{left:200,right:200},border:{top:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},bottom:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},left:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},right:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6}}})),t.push(new pt({text:"",spacing:{before:r.before,after:r.after}}))}return t}async convertAstToDocx(t){let r=[],n=null;this.listInstanceCounter=0;let a=await this.convertFrontmatterToDocx();if(r.push(...a),a.length>0&&(n="frontmatter"),!t.children)return r;for(let i of t.children){if(this.isTocMarker(i)){let s=new Vm("Contents",{hyperlink:!0,headingStyleRange:"1-6"});r.push(s),r.push(new pt({text:"",spacing:{before:240,after:120}})),n="toc";continue}!this.docxHrAsPageBreak&&i.type==="thematicBreak"&&n==="thematicBreak"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:0,after:0,line:1,lineRule:"exact"}})),i.type==="table"&&n==="table"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:120,after:120,line:240}})),i.type==="blockquote"&&n==="blockquote"&&r.push(new pt({text:"",alignment:tt.LEFT,spacing:{before:120,after:120,line:240}}));let o=await this.convertNode(i);o&&(Array.isArray(o)?r.push(...o):r.push(o)),n=i.type}return r}async convertNode(t,r={},n=0,a=0){let i={Paragraph:pt,TextRun:Et,ImageRun:$i,AlignmentType:tt,convertInchesToTwip:$t,themeStyles:this.themeStyles},o=this.renderer?{render:async(l,c)=>{let u=await this.renderer.render(l,c);if(!u)throw new Error("Plugin renderer returned empty result");if(typeof u.width!="number"||typeof u.height!="number")throw new Error("Plugin renderer returned invalid dimensions");let d=typeof u.format=="string"&&u.format?u.format:"png";return{base64:u.base64,width:u.width,height:u.height,format:d,error:u.error}}}:{render:async()=>{throw new Error("Renderer not available")}},s=await UP(t,o,i,()=>this.reportResourceProgress());if(s)return s;switch(t.type){case"heading":return this.convertHeading(t);case"paragraph":return await this.convertParagraph(t,r);case"list":return await this.listConverter.convertList(t);case"code":return this.convertCodeBlock(t,n,a);case"blockquote":return await this.blockquoteConverter.convertBlockquote(t,n);case"table":return await this.tableConverter.convertTable(t,n);case"thematicBreak":return this.convertThematicBreak();case"html":return this.convertHtml(t);case"math":return this.convertMathBlock(t);default:return null}}convertHeading(t){let r={1:Mo.HEADING_1,2:Mo.HEADING_2,3:Mo.HEADING_3,4:Mo.HEADING_4,5:Mo.HEADING_5,6:Mo.HEADING_6},n=this.inlineConverter.extractText({type:"root",children:t.children||[]}),a=t.depth||1,i=this.themeStyles?.paragraphStyles?.[`heading${a}`],o={text:n,heading:r[a]||Mo.HEADING_1};return i?.paragraph?.alignment==="center"&&(o.alignment=tt.CENTER),new pt(o)}async convertParagraph(t,r={}){let n=await this.inlineConverter.convertInlineNodes(t.children||[],r),a=this.themeStyles?.default?.paragraph?.spacing||{before:0,after:200,line:276};return new pt({children:n.length>0?n:void 0,text:n.length===0?"":void 0,spacing:{before:a.before,after:a.after,line:a.line},alignment:tt.LEFT})}convertCodeBlock(t,r=0,n=0){let a=this.codeHighlighter.getHighlightedRunsForCode(t.value??"",t.lang),i=this.themeStyles?.characterStyles?.code?.background||"F6F8FA",o=200,l=(r>0?$t(.5*r):0)+o,c=n>0?300*n:0,u=o+c;return new pt({children:a,wordWrap:!0,alignment:tt.LEFT,spacing:{before:200,after:200,line:276},shading:{fill:i},indent:{left:l,right:u},border:{top:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},bottom:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},left:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6},right:{color:"E1E4E8",space:10,style:Ct.SINGLE,size:6}}})}convertHtml(t){return new pt({children:[new Et({text:"[HTML Content]",italics:!0,color:"666666"})],alignment:tt.LEFT,spacing:{before:120,after:120}})}convertThematicBreak(){return this.docxHrAsPageBreak?new pt({pageBreakBefore:!0,children:[new Et({text:"",size:1})],spacing:{before:0,after:0,line:1,lineRule:"exact"},alignment:tt.LEFT}):new pt({text:"",alignment:tt.LEFT,spacing:{before:300,after:300,line:120,lineRule:"exact"},border:{bottom:{color:"E1E4E8",space:1,style:Ct.SINGLE,size:12}}})}convertMathBlock(t){try{let r=tp(t.value||"");return new pt({children:[r],spacing:{before:120,after:120},alignment:tt.CENTER})}catch(r){console.warn("Math conversion error:",r);let n=this.themeStyles?.characterStyles?.code||{font:"Consolas",size:20};return new pt({children:[new Et({text:t.value||"",font:n.font,size:n.size})],alignment:tt.LEFT,spacing:{before:120,after:120}})}}toAlignmentType(t){if(!t)return;let r=t.trim().toLowerCase();if(!r)return;let a={left:tt.LEFT,center:tt.CENTER,right:tt.RIGHT,justify:tt.JUSTIFIED,justified:tt.JUSTIFIED,start:tt.START,end:tt.END}[r];return a||(Object.values(tt).includes(r)?r:void 0)}toDocumentDefaults(t){let r=t.paragraph?{spacing:t.paragraph.spacing,alignment:this.toAlignmentType(t.paragraph.alignment)}:void 0;return{run:t.run,paragraph:r}}toHeadingStyle(t){let r={spacing:t.paragraph.spacing,alignment:this.toAlignmentType(t.paragraph.alignment)};return{name:t.name,basedOn:t.basedOn,next:t.next,run:t.run,paragraph:r}}async fetchImageAsBuffer(t){if(this.imageCache.has(t))return this.imageCache.get(t);if(t.startsWith("data:")){let a=t.match(/^data:([^;,]+)[^,]*,(.+)$/);if(!a)throw new Error("Invalid data URL format");let i=a[1],o=atob(a[2]),s=new Uint8Array(o.length);for(let c=0;c<o.length;c++)s[c]=o.charCodeAt(c);let l={buffer:s,contentType:i};return this.imageCache.set(t,l),l}let r=this.getDocumentService();if(!r)throw new Error("DocumentService not available - platform not initialized");let n=t.startsWith("http://")||t.startsWith("https://");try{if(n){let a=await r.fetchRemote(t),i=this.guessContentType(t),o={buffer:a,contentType:i};return this.imageCache.set(t,o),o}else{let a=await r.readRelativeFile(t,{binary:!0}),i=atob(a),o=new Uint8Array(i.length);for(let c=0;c<i.length;c++)o[c]=i.charCodeAt(c);let s=this.guessContentType(t),l={buffer:o,contentType:s};return this.imageCache.set(t,l),l}}catch(a){throw new Error(`Failed to fetch image: ${t} - ${a.message}`)}}guessContentType(t){let r=t.split(".").pop()?.toLowerCase().split("?")[0]||"";return{png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml"}[r]||"image/png"}},F6e=wS;export{he as a,AS as b,_a as c,hT as d,bp as e,Un as f,Op as g,t0 as h,ux as i,gS as j,F6e as k,C9 as l,zL as m,yP as n,jP as o,Cue as p};
|
|
367
367
|
/*! Bundled license information:
|
|
368
368
|
|
|
369
369
|
mhchemparser/dist/mhchemParser.js:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as a,k as b}from"./chunk-UZ7TETMS.js";export{a as convertPluginResultToDOCX,b as default};
|