UNPKG

@mdast2docx/list

Version:

Plugin to convert ordered and unordered lists from Markdown (MDAST) to DOCX. Supports nesting, custom bullets, and numbering styles.

2 lines (1 loc) 1.83 kB
"use strict";var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var b=(o,t)=>{for(var s in t)m(o,s,{get:t[s],enumerable:!0})},d=(o,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of E(t))!O.call(o,l)&&l!==s&&m(o,l,{get:()=>t[l],enumerable:!(i=y(t,l))||i.enumerable});return o};var P=o=>d(m({},"__esModule",{value:!0}),o);var _={};b(_,{createLevels:()=>I,listPlugin:()=>M});module.exports=P(_);var e=require("docx"),R=[e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.DECIMAL,e.LevelFormat.UPPER_LETTER,e.LevelFormat.LOWER_LETTER,e.LevelFormat.LOWER_ROMAN,e.LevelFormat.UPPER_ROMAN],I=(o,t=.4,s=.25)=>o.map((i,l)=>({level:l,format:i,text:(i===e.LevelFormat.DECIMAL?Array(l+1).fill(0).map((a,f)=>`%${f+1}`).join("."):`%${l+1}`)+".",alignment:e.AlignmentType.START,style:{paragraph:{indent:{left:(0,e.convertInchesToTwip)(t+l*s)}}}})),A=I(R),D=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],T={levels:A,bullets:D,defaultBullets:!1},M=o=>{let t=crypto.randomUUID(),s=`numbering-${t}`,i=`bullet-${t}`,{levels:l,bulletLevels:a,bullets:f,defaultBullets:v}={...T,...o};return{block:(L,n,r,c)=>{var u,g;if(n.type!=="list")return[];let p=((g=(u=r.bullet)==null?void 0:u.level)!=null?g:-1)+1;return r.numbering=v?void 0:{level:p,reference:n.ordered?s:i},r.bullet={level:p},n._type=n.type,n.type="",n.data={...n.data,tag:n.ordered?"ol":"ul"},c(n,{...r,...n.data})},root:L=>{var n,r;L.numbering={config:[...(r=(n=L.numbering)==null?void 0:n.config)!=null?r:[],{reference:s,levels:l},{reference:i,levels:a!=null?a:l.map((c,p)=>{var u;return{...c,text:(u=f[p])!=null?u:"\u2022",format:e.LevelFormat.BULLET}})}]}}}};0&&(module.exports={createLevels,listPlugin});