@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.23 kB
JavaScript
import{AlignmentType as I,convertInchesToTwip as v,LevelFormat as t}from"docx";var y=[t.DECIMAL,t.DECIMAL,t.DECIMAL,t.DECIMAL,t.UPPER_LETTER,t.LOWER_LETTER,t.LOWER_ROMAN,t.UPPER_ROMAN],E=(p,i=.4,r=.25)=>p.map((o,l)=>({level:l,format:o,text:(o===t.DECIMAL?Array(l+1).fill(0).map((u,f)=>`%${f+1}`).join("."):`%${l+1}`)+".",alignment:I.START,style:{paragraph:{indent:{left:v(i+l*r)}}}})),O=E(y),b=["\u25CF","\u25CB","\u25A0","\u25C6","\u25B6","\u25C9","\u2B24","\u2666","\u25E6","\u25AA"],d={levels:O,bullets:b,defaultBullets:!1},A=p=>{let i=crypto.randomUUID(),r=`numbering-${i}`,o=`bullet-${i}`,{levels:l,bulletLevels:u,bullets:f,defaultBullets:g}={...d,...p};return{block:(L,e,n,c)=>{var s,m;if(e.type!=="list")return[];let a=((m=(s=n.bullet)==null?void 0:s.level)!=null?m:-1)+1;return n.numbering=g?void 0:{level:a,reference:e.ordered?r:o},n.bullet={level:a},e._type=e.type,e.type="",e.data={...e.data,tag:e.ordered?"ol":"ul"},c(e,{...n,...e.data})},root:L=>{var e,n;L.numbering={config:[...(n=(e=L.numbering)==null?void 0:e.config)!=null?n:[],{reference:r,levels:l},{reference:o,levels:u!=null?u:l.map((c,a)=>{var s;return{...c,text:(s=f[a])!=null?s:"\u2022",format:t.BULLET}})}]}}}};export{E as createLevels,A as listPlugin};