@m2d/table
Version:
Plugin to convert Markdown tables (MDAST) to DOCX with support for rich formatting and seamless integration into mdast2docx.
2 lines (1 loc) • 2.37 kB
JavaScript
var u=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(n,l)=>{for(var t in l)u(n,t,{get:l[t],enumerable:!0})},B=(n,l,t,g)=>{if(l&&typeof l=="object"||typeof l=="function")for(let a of H(l))!x.call(n,a)&&a!==t&&u(n,a,{get:()=>l[a],enumerable:!(g=V(l,a))||g.enumerable});return n};var F=n=>B(u({},"__esModule",{value:!0}),n);var v={};S(v,{defaultTableOptions:()=>y,tablePlugin:()=>L});module.exports=F(v);var e=require("docx"),m=require("@m2d/core/utils"),p={style:e.BorderStyle.SINGLE,color:"auto",size:1},y={tableProps:{width:{size:100,type:e.WidthType.PERCENTAGE},margins:{top:(0,e.convertMillimetersToTwip)(2),right:(0,e.convertMillimetersToTwip)(4),bottom:(0,e.convertMillimetersToTwip)(2),left:(0,e.convertMillimetersToTwip)(4)},borders:{top:p,right:p,bottom:p,left:p,insideHorizontal:p,insideVertical:p}},rowProps:{},cellProps:{width:{size:100}},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:e.ShadingType.SOLID,fill:"b79c2f"},alignment:e.AlignmentType.CENTER},alignments:{defaultVerticalAlign:e.VerticalAlignTable.CENTER,defaultHorizontalAlign:e.AlignmentType.CENTER,preferMdData:!0}},G=["paragraph","heading","code","list","blockquote","thematicBreak","fragment","table"],L=n=>({block:(l,t,g,a)=>{var b,T;if(t.type!=="table")return[];let{Table:h,TableRow:d,TableCell:R}=l,{tableProps:w,firstRowProps:C,firstRowCellProps:{data:s,alignment:I,...A},rowProps:O,cellProps:{data:E,...M},alignments:c}=(0,m.mergeOptions)(n,y),P=(b=s==null?void 0:s.alignment)!=null?b:I,f=(T=t.align)==null?void 0:T.map(i=>{switch(i){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),N=i=>{let o=[],r=[];for(t of i.children)G.includes(t.type)?(r.length>0&&(o.push({type:"paragraph",children:[...r]}),r.length=0),o.push(t)):r.push(t);r.length>0&&o.push({type:"paragraph",children:r}),i.children=o},k=(i,o)=>new d({...O,...o===0?C:{},children:i.children.map((r,z)=>(N(r),new R({verticalAlign:c.defaultVerticalAlign,...M,...o===0?A:{},children:a(r,{alignment:o===0&&P?P:c.preferMdData?f==null?void 0:f[z]:c.defaultHorizontalAlign,...o===0?s:E})})))}),D=t.children.map(k);return t._type=t.type,t.type="",[new h({...w,rows:D})]}});0&&(module.exports={defaultTableOptions,tablePlugin});
;