@m2d/core
Version: 
Core engine to convert extended MDAST to DOCX. Supports plugins for footnotes, images, lists, tables, and more. Designed for seamless Markdown-to-DOCX conversion.
2 lines (1 loc) • 1.02 kB
JavaScript
import{b as m}from"./chunk-XZD64HEJ.mjs";import{a as f,c as h,d as R}from"./chunk-66DCUUGU.mjs";import{Document as S,Packer as b}from"docx";var _=async(p,x={},e=h,A="blob")=>{var P;let n={},y={...R,...x},r=(P=e==null?void 0:e.plugins)!=null?P:[],T=await Promise.all((Array.isArray(p)?p:[{ast:p}]).map(async({ast:o,props:t})=>{var d;let{definitions:s,footnoteDefinitions:a}=f(o.children),{footnoteProps:M,...c}={...t,...e};return await Promise.all(Object.values(a).map(async(i,D)=>{let O=D+1;i.id=D+1,n[O]=await m({type:"root",children:i.children},s,{},{footnoteProps:M})})),r.push(...(d=c==null?void 0:c.plugins)!=null?d:[]),{ast:o,props:c,definitions:s,footnoteDefinitions:a}}));r==null||r.forEach(o=>{var t;(t=o==null?void 0:o.root)==null||t.call(o,y)});let I=await Promise.all(T.map(({ast:o,props:t,definitions:s,footnoteDefinitions:a})=>m(o,s,a,t)));r==null||r.forEach(o=>{var t;(t=o==null?void 0:o.postprocess)==null||t.call(o,I)});let w=new S({...y,footnotes:n,sections:I});return b.pack(w,A)};export{_ as toDocx};