UNPKG

@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) 904 B
import{a as p}from"./chunk-RVQBABBW.mjs";import{a as P,d}from"./chunk-NIBTWVZC.mjs";import{Document as b,Packer as u}from"docx";var S=async(n,h={},e={},x="blob")=>{var y;let s=1,m={},i={...d,...h};(y=e==null?void 0:e.plugins)==null||y.forEach(t=>{var o;return(o=t.root)==null?void 0:o.call(t,i)});let f=await Promise.all((Array.isArray(n)?n:[{ast:n}]).map(async({ast:t,props:o})=>{var I;let{definitions:a,footnoteDefinitions:c}=P(t.children);return await Promise.all(Object.values(c).map(async r=>{r.id=s,m[s]=await p({type:"root",children:r.children},a,{}),s++})),(I=o==null?void 0:o.plugins)==null||I.forEach(r=>{var D;return(D=r.root)==null?void 0:D.call(r,i)}),{ast:t,props:{...e,...o},definitions:a,footnoteDefinitions:c}})),l=await Promise.all(f.map(({ast:t,props:o,definitions:a,footnoteDefinitions:c})=>p(t,a,c,o))),A=new b({...i,footnotes:m,sections:l});return u.pack(A,x)};export{S as toDocx};