UNPKG

@md2docx/table

Version:

Plugin to convert Markdown tables (MDAST) to DOCX with support for rich formatting and seamless integration into mdast2docx.

2 lines (1 loc) 1.89 kB
"use strict";var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var H=(t,l)=>{for(var r in l)T(t,r,{get:l[r],enumerable:!0})},M=(t,l,r,i)=>{if(l&&typeof l=="object"||typeof l=="function")for(let o of V(l))!z.call(t,o)&&o!==r&&T(t,o,{get:()=>l[o],enumerable:!(i=D(l,o))||i.enumerable});return t};var N=t=>M(T({},"__esModule",{value:!0}),t);var S={};H(S,{defaultTableOptions:()=>g,tablePlugin:()=>k});module.exports=N(S);var e=require("docx"),n={style:e.BorderStyle.SINGLE,color:"auto",size:1},g={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:n,right:n,bottom:n,left:n,insideHorizontal:n,insideVertical:n}},rowProps:{},cellProps:{},firstRowProps:{tableHeader:!0},firstRowCellProps:{shading:{type:e.ShadingType.SOLID,fill:"b79c2f"}},alignments:{defaultVerticalAlign:e.VerticalAlignTable.CENTER,defaultHorizontalAlign:e.AlignmentType.CENTER,preferMdData:!0}},k=t=>({block:(l,r,i,o,c)=>{var b;if(r.type!=="table")return[];let{Table:f,TableRow:u,TableCell:m,Paragraph:w}=l,{tableProps:y,firstRowProps:d,firstRowCellProps:R,rowProps:A,cellProps:h,alignments:a}={...g,...t},p=(b=r.align)==null?void 0:b.map(s=>{switch(s){case"left":return l.AlignmentType.LEFT;case"right":return l.AlignmentType.RIGHT;case"center":return l.AlignmentType.CENTER;default:return}}),I=(s,P)=>new u({...A,...P===0?d:{},children:s.children.map((O,E)=>new m({verticalAlign:a.defaultVerticalAlign,...h,...P===0?R:{},children:[new w({children:c(O),alignment:a.preferMdData?p==null?void 0:p[E]:a.defaultHorizontalAlign})]}))}),C=r.children.map(I);return r.type="",[new f({...y,rows:C})]}});0&&(module.exports={defaultTableOptions,tablePlugin});