UNPKG

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