@mdast2docx/html
Advanced tools
+2
-2
@@ -1,3 +0,3 @@ | ||
| "use strict";var y=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var P=(e,r)=>{for(var t in r)y(e,t,{get:r[t],enumerable:!0})},w=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of D(r))!k.call(e,s)&&s!==t&&y(e,s,{get:()=>r[s],enumerable:!(n=O(r,s))||n.enumerable});return e};var v=e=>w(y({},"__esModule",{value:!0}),e);var W={};P(W,{htmlPlugin:()=>Y});module.exports=v(W);var b=e=>{let r=document.createElement("canvas").getContext("2d");return r?(r.fillStyle=e,r.fillStyle.slice(1)):e.startsWith("#")?e.slice(1):"auto"};var d=require("docx"),x=["A","ABBR","ACRONYM","B","BDI","BDO","BIG","BR","BUTTON","CITE","CODE","DATA","DATALIST","DEL","DFN","EM","I","IMG","INPUT","INS","KBD","LABEL","MARK","METER","NOSCRIPT","OBJECT","OUTPUT","Q","RUBY","RP","RT","S","SAMP","SCRIPT","SELECT","SLOT","SMALL","SPAN","STRONG","SUB","SUP","svg","TEMPLATE","TEXTAREA","TIME","U","TT","VAR","WBR"],L=["br","hr","img","input"],U={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},M=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],G=e=>{var n;if(!e)return{};let r={},t=e.match(/border(-\w+)?:\s*[^;]+/gi);if(!t)return{};for(let s of t){let[a,p]=s.split(":").map(l=>l.trim()),h=p.split(/\s+/),i=(n=h.find(l=>l.endsWith("px")))==null?void 0:n.replace("px",""),u=h.find(l=>M.includes(l.toLowerCase())),o=h.find(l=>!l.endsWith("px")&&!M.includes(l.toLowerCase())),c=a==="border"?"border":a.replace("border-","");r[c]={...i?{width:parseInt(i,1)}:{},...u?{style:u}:{},...o?{color:o}:{}}}return r},_={solid:d.BorderStyle.SINGLE,dashed:d.BorderStyle.DASHED,dotted:d.BorderStyle.DOTTED,double:d.BorderStyle.DOUBLE,none:d.BorderStyle.NONE,ridge:d.BorderStyle.THREE_D_EMBOSS,groove:d.BorderStyle.THREE_D_ENGRAVE,inset:d.BorderStyle.INSET,outset:d.BorderStyle.OUTSET},g=e=>{if(!e||!Object.keys(e).length)return;let{width:r,color:t,style:n}=e,s={style:n?_[n]:d.BorderStyle.SINGLE};return r&&(s.size=r),t&&(s.color=b(t)),s},S=(e,r=!0)=>{var l,m;let t={};if(!(e instanceof HTMLElement||e instanceof SVGElement))return t;let{textAlign:n,fontWeight:s,fontStyle:a,textDecoration:p,textTransform:h,color:i}=e.style,u=e.getAttribute("style"),o=G(u);if(t.style=u!=null?u:void 0,r&&o.border)t.border=g(o.border);else if(Object.keys(o).length){let A={...o.border,...o.left},C={...o.border,...o.right},R={...o.border,...o.top},H={...o.border,...o.bottom};t.border={left:g(A),right:g(C),top:g(R),bottom:g(H)}}switch(n&&(Object.keys(d.AlignmentType).includes(n)?t.alignment=n:n==="justify"&&(t.alignment=d.AlignmentType.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(t.bold=!0),/(italic|oblique)/.test(a)&&(t.italics=!0),p){case"underline":t.underline={};break;case"overline":t.emphasisMark={};break;case"line-through":t.strike=!0;break}h==="uppercase"&&(t.allCaps=!0),h==="lowercase"&&(t.smallCaps=!0),i&&(t.color=b(i));let c=e.tagName;return c==="SUP"?t.superScript=!0:c==="SUB"?t.subScript=!0:["STRONG","B"].includes(c)?t.bold=!0:["EM","I"].includes(c)?t.italics=!0:["DEL","S"].includes(c)?t.strike=!0:["U","INS"].includes(c)?t.underline={}:c==="MARK"?(t.highlight="yellow",t.emphasisMark={}):c==="PRE"?t.pre=!0:c==="INPUT"&&(t.type=e.type,t.name=e.name,t.value=(l=e.value)!=null?l:e.defaultValue,t.checked=(m=e.checked)!=null?m:e.defaultChecked),t.tag=c.toLowerCase(),t},f=(e,r=!1)=>{var p,h,i,u,o,c;if(!(e instanceof HTMLElement||e instanceof SVGElement))return{type:"text",value:(h=r?e.textContent:(p=e.textContent)==null?void 0:p.replace(/^\s+|\s+$/g," "))!=null?h:""};let t=Array.from(e.childNodes).map(l=>f(l,r)),n=S(e),s=e.getAttributeNames().reduce((l,m)=>({...l,[m]:e.getAttribute(m)}),{}),a=e.tagName;switch(a){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(i=s.src)!=null?i:"",alt:(u=s.alt)!=null?u:"",data:{...n,...s}};case"svg":return{type:"svg",value:e.outerHTML,data:n};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:U[a],children:t,data:n};case"A":return{type:"link",url:(o=s.href)!=null?o:"",children:t,data:n};case"INPUT":return/(radio|checkbox)/.test(e.type)?{type:"checkbox",data:n}:{type:"text",value:(c=n.value)!=null?c:`_${e.value||"_".repeat(20)}_`,data:{...n,border:{style:d.BorderStyle.OUTSET}}}}return{type:"fragment",children:t,data:n}},T=(e,r)=>{let t=Array.from(e.childNodes),n=[],s=[];for(let a of t)(a instanceof HTMLElement||a instanceof SVGElement)&&!x.includes(a.tagName)?(s.length&&(n.push({type:"paragraph",children:s.map(p=>f(p,r==null?void 0:r.pre))}),s.length=0),n.push(V(a))):s.push(a);return s.length&&n.push({type:"paragraph",children:s.map(a=>f(a,r==null?void 0:r.pre))}),n.length===1?{...n[0],data:{...r,...n[0].data}}:{type:"fragment",children:n,data:r}},I=(e,r)=>Array.from(e.children).map(t=>{let n={...r,...S(t)};return t.tagName==="TR"?{type:"tableRow",children:Array.from(t.children).map(s=>({type:"tableCell",children:[T(s,{...n,tag:void 0})],data:{...n,tag:s.tagName.toLowerCase()}})),data:n}:I(t,n)}).flat(),E={style:"single"},$={left:E,right:E,top:E,bottom:E},V=e=>{let r=S(e),t=e.tagName;switch(t){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(t[1]),children:Array.from(e.childNodes).map(n=>f(n)),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return T(e,r);case"UL":case"OL":return{type:"list",ordered:t==="OL",children:Array.from(e.childNodes).map(n=>({type:"listItem",children:[T(n)],data:r}))};case"HR":return{type:"thematicBreak",data:r};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(e.childNodes).map(n=>T(n)),data:r};case"TABLE":return{type:"table",children:I(e),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| "use strict";var b=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var P=(e,r)=>{for(var t in r)b(e,t,{get:r[t],enumerable:!0})},w=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of D(r))!k.call(e,s)&&s!==t&&b(e,s,{get:()=>r[s],enumerable:!(n=O(r,s))||n.enumerable});return e};var U=e=>w(b({},"__esModule",{value:!0}),e);var W={};P(W,{htmlPlugin:()=>V});module.exports=U(W);var S=e=>{let r=document.createElement("canvas").getContext("2d");return r?(r.fillStyle=e,r.fillStyle.slice(1)):e.startsWith("#")?e.slice(1):"auto"};var d=require("docx"),v=["A","ABBR","ACRONYM","B","BDI","BDO","BIG","BR","BUTTON","CITE","CODE","DATA","DATALIST","DEL","DFN","EM","I","IMG","INPUT","INS","KBD","LABEL","MARK","METER","NOSCRIPT","OBJECT","OUTPUT","Q","RUBY","RP","RT","S","SAMP","SCRIPT","SELECT","SLOT","SMALL","SPAN","STRONG","SUB","SUP","svg","TEMPLATE","TEXTAREA","TIME","U","TT","VAR","WBR"],I=["br","hr","img","input"],x={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},M=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],G=e=>{var n;if(!e)return{};let r={},t=e.match(/border(-\w+)?:\s*[^;]+/gi);if(!t)return{};for(let s of t){let[a,p]=s.split(":").map(l=>l.trim()),h=p.split(/\s+/),c=(n=h.find(l=>l.endsWith("px")))==null?void 0:n.replace("px",""),u=h.find(l=>M.includes(l.toLowerCase())),o=h.find(l=>!l.endsWith("px")&&!M.includes(l.toLowerCase())),i=a==="border"?"border":a.replace("border-","");r[i]={...c?{width:parseInt(c,1)}:{},...u?{style:u}:{},...o?{color:o}:{}}}return r},_={solid:d.BorderStyle.SINGLE,dashed:d.BorderStyle.DASHED,dotted:d.BorderStyle.DOTTED,double:d.BorderStyle.DOUBLE,none:d.BorderStyle.NONE,ridge:d.BorderStyle.THREE_D_EMBOSS,groove:d.BorderStyle.THREE_D_ENGRAVE,inset:d.BorderStyle.INSET,outset:d.BorderStyle.OUTSET},T=e=>{if(!e||!Object.keys(e).length)return;let{width:r,color:t,style:n}=e,s={style:n?_[n]:d.BorderStyle.SINGLE};return r&&(s.size=r),t&&(s.color=S(t)),s},L=(e,r=!0)=>{var l,m;let t={};if(!(e instanceof HTMLElement||e instanceof SVGElement))return t;let{textAlign:n,fontWeight:s,fontStyle:a,textDecoration:p,textTransform:h,color:c}=e.style,u=e.getAttribute("style"),o=G(u);if(t.style=u!=null?u:void 0,r&&o.border)t.border=T(o.border);else if(Object.keys(o).length){let g={...o.border,...o.left},C={...o.border,...o.right},R={...o.border,...o.top},H={...o.border,...o.bottom};t.border={left:T(g),right:T(C),top:T(R),bottom:T(H)}}if(n){let g=n.toUpperCase();Object.keys(d.AlignmentType).includes(g)?t.alignment=d.AlignmentType[g]:g==="JUSTIFY"&&(t.alignment=d.AlignmentType.JUSTIFIED)}switch((/bold/.test(s)||parseInt(s)>=500)&&(t.bold=!0),/(italic|oblique)/.test(a)&&(t.italics=!0),p){case"underline":t.underline={};break;case"overline":t.emphasisMark={};break;case"line-through":t.strike=!0;break}h==="uppercase"&&(t.allCaps=!0),h==="lowercase"&&(t.smallCaps=!0),c&&(t.color=S(c));let i=e.tagName;return i==="SUP"?t.superScript=!0:i==="SUB"?t.subScript=!0:["STRONG","B"].includes(i)?t.bold=!0:["EM","I"].includes(i)?t.italics=!0:["DEL","S"].includes(i)?t.strike=!0:["U","INS"].includes(i)?t.underline={}:i==="MARK"?(t.highlight="yellow",t.emphasisMark={}):i==="PRE"?t.pre=!0:i==="INPUT"&&(t.type=e.type,t.name=e.name,t.value=(l=e.value)!=null?l:e.defaultValue,t.checked=(m=e.checked)!=null?m:e.defaultChecked),t.tag=i.toLowerCase(),t},f=(e,r=!1)=>{var p,h,c,u,o,i;if(!(e instanceof HTMLElement||e instanceof SVGElement))return{type:"text",value:(h=r?e.textContent:(p=e.textContent)==null?void 0:p.replace(/^\s+|\s+$/g," "))!=null?h:""};let t=Array.from(e.childNodes).map(l=>f(l,r)),n=L(e),s=e.getAttributeNames().reduce((l,m)=>({...l,[m]:e.getAttribute(m)}),{}),a=e.tagName;switch(a){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(c=s.src)!=null?c:"",alt:(u=s.alt)!=null?u:"",data:{...n,...s}};case"svg":return{type:"svg",value:e.outerHTML,data:n};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:x[a],children:t,data:n};case"A":return{type:"link",url:(o=s.href)!=null?o:"",children:t,data:n};case"INPUT":return/(radio|checkbox)/.test(e.type)?{type:"checkbox",data:n}:{type:"text",value:(i=n.value)!=null?i:`_${e.value||"_".repeat(20)}_`,data:{...n,border:{style:d.BorderStyle.OUTSET}}}}return{type:"fragment",children:t,data:n}},E=(e,r)=>{let t=Array.from(e.childNodes),n=[],s=[];for(let a of t)(a instanceof HTMLElement||a instanceof SVGElement)&&!v.includes(a.tagName)?(s.length&&(n.push({type:"paragraph",children:s.map(p=>f(p,r==null?void 0:r.pre))}),s.length=0),n.push(Y(a))):s.push(a);return s.length&&n.push({type:"paragraph",children:s.map(a=>f(a,r==null?void 0:r.pre))}),n.length===1?{...n[0],data:{...r,...n[0].data}}:{type:"fragment",children:n,data:r}},B=(e,r)=>Array.from(e.children).map(t=>{let n={...r,...L(t)};return t.tagName==="TR"?{type:"tableRow",children:Array.from(t.children).map(s=>({type:"tableCell",children:[E(s,{...n,tag:void 0})],data:{...n,tag:s.tagName.toLowerCase()}})),data:n}:B(t,n)}).flat(),y={style:"single"},$={left:y,right:y,top:y,bottom:y},Y=e=>{let r=L(e),t=e.tagName;switch(t){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(t[1]),children:Array.from(e.childNodes).map(n=>f(n)),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return E(e,r);case"UL":case"OL":return{type:"list",ordered:t==="OL",children:Array.from(e.childNodes).map(n=>({type:"listItem",children:[E(n)],data:r}))};case"HR":return{type:"thematicBreak",data:r};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(e.childNodes).map(n=>E(n)),data:r};case"TABLE":return{type:"table",children:B(e),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| ${e.textContent}`}],data:{...r,pre:!0,border:$}}}return{type:"paragraph",children:[f(e)],data:r}},N=e=>{var s,a,p;let r=(a=(s=e.value)==null?void 0:s.trim())!=null?a:"",t=r.split(" ")[0].slice(1),n=document.createElement("div");n.innerHTML=r.endsWith("/>")?r:`${r}</${t}>`,Object.assign(e,{...f(n.children[0]),children:(p=e.children)!=null?p:[]})},B=(e,r=!0)=>{var s,a,p,h;let t=[],n=[];for(let i of e.children){(s=i.children)!=null&&s.length&&B(i,!1);let u=i.value,o=typeof u=="string"?u:"",c=(a=o==null?void 0:o.split)==null?void 0:a.call(o," ")[0].replace(/^<|\/?>$/g,"");if(i.type==="html"&&!L.includes(c)&&/^<[^>]*[^/]>$/.test(o))if(c[0]==="/"){let m=n.shift();if(!m)throw new Error(`Invalid HTML: ${o}`);N(m),((h=(p=n[0])==null?void 0:p.children)!=null?h:t).push(m)}else n.unshift({...i,children:[],tag:c});else n.length?n[0].children.push(i):t.push(i);let l=i.type==="html"&&(L.includes(c)||/^<[^>]*\/>$/.test(o));if(l&&!r)N(i);else if(l&&r||i.type==="html"&&!/^<[^>]*>$/.test(o)){let m=document.createElement("div");m.innerHTML=o,Object.assign(i,T(m))}}e.children=t},Y=()=>({preprocess:B});0&&(module.exports={htmlPlugin}); | ||
| ${e.textContent}`}],data:{...r,pre:!0,border:$}}}return{type:"paragraph",children:[f(e)],data:r}},N=e=>{var s,a,p;let r=(a=(s=e.value)==null?void 0:s.trim())!=null?a:"",t=r.split(" ")[0].slice(1),n=document.createElement("div");n.innerHTML=r.endsWith("/>")?r:`${r}</${t}>`,Object.assign(e,{...f(n.children[0]),children:(p=e.children)!=null?p:[]})},A=(e,r=!0)=>{var s,a,p,h;let t=[],n=[];for(let c of e.children){(s=c.children)!=null&&s.length&&A(c,!1);let u=c.value,o=typeof u=="string"?u:"",i=(a=o==null?void 0:o.split)==null?void 0:a.call(o," ")[0].replace(/^<|\/?>$/g,"");if(c.type==="html"&&!I.includes(i)&&/^<[^>]*[^/]>$/.test(o))if(i[0]==="/"){let m=n.shift();if(!m)throw new Error(`Invalid HTML: ${o}`);N(m),((h=(p=n[0])==null?void 0:p.children)!=null?h:t).push(m)}else n.unshift({...c,children:[],tag:i});else n.length?n[0].children.push(c):t.push(c);let l=c.type==="html"&&(I.includes(i)||/^<[^>]*\/>$/.test(o));if(l&&!r)N(c);else if(l&&r||c.type==="html"&&!/^<[^>]*>$/.test(o)){let m=document.createElement("div");m.innerHTML=o,Object.assign(c,E(m))}}e.children=t},V=()=>({preprocess:A});0&&(module.exports={htmlPlugin}); |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import{a as y}from"./chunk-CYY6OEIU.mjs";import{AlignmentType as L,BorderStyle as m}from"docx";var O=["A","ABBR","ACRONYM","B","BDI","BDO","BIG","BR","BUTTON","CITE","CODE","DATA","DATALIST","DEL","DFN","EM","I","IMG","INPUT","INS","KBD","LABEL","MARK","METER","NOSCRIPT","OBJECT","OUTPUT","Q","RUBY","RP","RT","S","SAMP","SCRIPT","SELECT","SLOT","SMALL","SPAN","STRONG","SUB","SUP","svg","TEMPLATE","TEXTAREA","TIME","U","TT","VAR","WBR"],M=["br","hr","img","input"],D={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},N=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],k=t=>{var r;if(!t)return{};let n={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[a,d]=s.split(":").map(l=>l.trim()),u=d.split(/\s+/),i=(r=u.find(l=>l.endsWith("px")))==null?void 0:r.replace("px",""),p=u.find(l=>N.includes(l.toLowerCase())),o=u.find(l=>!l.endsWith("px")&&!N.includes(l.toLowerCase())),c=a==="border"?"border":a.replace("border-","");n[c]={...i?{width:parseInt(i,1)}:{},...p?{style:p}:{},...o?{color:o}:{}}}return n},P={solid:m.SINGLE,dashed:m.DASHED,dotted:m.DOTTED,double:m.DOUBLE,none:m.NONE,ridge:m.THREE_D_EMBOSS,groove:m.THREE_D_ENGRAVE,inset:m.INSET,outset:m.OUTSET},g=t=>{if(!t||!Object.keys(t).length)return;let{width:n,color:e,style:r}=t,s={style:r?P[r]:m.SINGLE};return n&&(s.size=n),e&&(s.color=y(e)),s},b=(t,n=!0)=>{var l,h;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:r,fontWeight:s,fontStyle:a,textDecoration:d,textTransform:u,color:i}=t.style,p=t.getAttribute("style"),o=k(p);if(e.style=p!=null?p:void 0,n&&o.border)e.border=g(o.border);else if(Object.keys(o).length){let A={...o.border,...o.left},R={...o.border,...o.right},C={...o.border,...o.top},H={...o.border,...o.bottom};e.border={left:g(A),right:g(R),top:g(C),bottom:g(H)}}switch(r&&(Object.keys(L).includes(r)?e.alignment=r:r==="justify"&&(e.alignment=L.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(a)&&(e.italics=!0),d){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}u==="uppercase"&&(e.allCaps=!0),u==="lowercase"&&(e.smallCaps=!0),i&&(e.color=y(i));let c=t.tagName;return c==="SUP"?e.superScript=!0:c==="SUB"?e.subScript=!0:["STRONG","B"].includes(c)?e.bold=!0:["EM","I"].includes(c)?e.italics=!0:["DEL","S"].includes(c)?e.strike=!0:["U","INS"].includes(c)?e.underline={}:c==="MARK"?(e.highlight="yellow",e.emphasisMark={}):c==="PRE"?e.pre=!0:c==="INPUT"&&(e.type=t.type,e.name=t.name,e.value=(l=t.value)!=null?l:t.defaultValue,e.checked=(h=t.checked)!=null?h:t.defaultChecked),e.tag=c.toLowerCase(),e},f=(t,n=!1)=>{var d,u,i,p,o,c;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(u=n?t.textContent:(d=t.textContent)==null?void 0:d.replace(/^\s+|\s+$/g," "))!=null?u:""};let e=Array.from(t.childNodes).map(l=>f(l,n)),r=b(t),s=t.getAttributeNames().reduce((l,h)=>({...l,[h]:t.getAttribute(h)}),{}),a=t.tagName;switch(a){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(i=s.src)!=null?i:"",alt:(p=s.alt)!=null?p:"",data:{...r,...s}};case"svg":return{type:"svg",value:t.outerHTML,data:r};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:D[a],children:e,data:r};case"A":return{type:"link",url:(o=s.href)!=null?o:"",children:e,data:r};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:r}:{type:"text",value:(c=r.value)!=null?c:`_${t.value||"_".repeat(20)}_`,data:{...r,border:{style:m.OUTSET}}}}return{type:"fragment",children:e,data:r}},T=(t,n)=>{let e=Array.from(t.childNodes),r=[],s=[];for(let a of e)(a instanceof HTMLElement||a instanceof SVGElement)&&!O.includes(a.tagName)?(s.length&&(r.push({type:"paragraph",children:s.map(d=>f(d,n==null?void 0:n.pre))}),s.length=0),r.push(U(a))):s.push(a);return s.length&&r.push({type:"paragraph",children:s.map(a=>f(a,n==null?void 0:n.pre))}),r.length===1?{...r[0],data:{...n,...r[0].data}}:{type:"fragment",children:r,data:n}},I=(t,n)=>Array.from(t.children).map(e=>{let r={...n,...b(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[T(s,{...r,tag:void 0})],data:{...r,tag:s.tagName.toLowerCase()}})),data:r}:I(e,r)}).flat(),E={style:"single"},w={left:E,right:E,top:E,bottom:E},U=t=>{let n=b(t),e=t.tagName;switch(e){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(e[1]),children:Array.from(t.childNodes).map(r=>f(r)),data:n};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return T(t,n);case"UL":case"OL":return{type:"list",ordered:e==="OL",children:Array.from(t.childNodes).map(r=>({type:"listItem",children:[T(r)],data:n}))};case"HR":return{type:"thematicBreak",data:n};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(r=>T(r)),data:n};case"TABLE":return{type:"table",children:I(t),data:n};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| import{a as b}from"./chunk-CYY6OEIU.mjs";import{AlignmentType as L,BorderStyle as m}from"docx";var O=["A","ABBR","ACRONYM","B","BDI","BDO","BIG","BR","BUTTON","CITE","CODE","DATA","DATALIST","DEL","DFN","EM","I","IMG","INPUT","INS","KBD","LABEL","MARK","METER","NOSCRIPT","OBJECT","OUTPUT","Q","RUBY","RP","RT","S","SAMP","SCRIPT","SELECT","SLOT","SMALL","SPAN","STRONG","SUB","SUP","svg","TEMPLATE","TEXTAREA","TIME","U","TT","VAR","WBR"],I=["br","hr","img","input"],D={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},M=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],k=t=>{var r;if(!t)return{};let n={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[a,d]=s.split(":").map(l=>l.trim()),u=d.split(/\s+/),c=(r=u.find(l=>l.endsWith("px")))==null?void 0:r.replace("px",""),p=u.find(l=>M.includes(l.toLowerCase())),o=u.find(l=>!l.endsWith("px")&&!M.includes(l.toLowerCase())),i=a==="border"?"border":a.replace("border-","");n[i]={...c?{width:parseInt(c,1)}:{},...p?{style:p}:{},...o?{color:o}:{}}}return n},P={solid:m.SINGLE,dashed:m.DASHED,dotted:m.DOTTED,double:m.DOUBLE,none:m.NONE,ridge:m.THREE_D_EMBOSS,groove:m.THREE_D_ENGRAVE,inset:m.INSET,outset:m.OUTSET},T=t=>{if(!t||!Object.keys(t).length)return;let{width:n,color:e,style:r}=t,s={style:r?P[r]:m.SINGLE};return n&&(s.size=n),e&&(s.color=b(e)),s},S=(t,n=!0)=>{var l,h;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:r,fontWeight:s,fontStyle:a,textDecoration:d,textTransform:u,color:c}=t.style,p=t.getAttribute("style"),o=k(p);if(e.style=p!=null?p:void 0,n&&o.border)e.border=T(o.border);else if(Object.keys(o).length){let g={...o.border,...o.left},C={...o.border,...o.right},R={...o.border,...o.top},H={...o.border,...o.bottom};e.border={left:T(g),right:T(C),top:T(R),bottom:T(H)}}if(r){let g=r.toUpperCase();Object.keys(L).includes(g)?e.alignment=L[g]:g==="JUSTIFY"&&(e.alignment=L.JUSTIFIED)}switch((/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(a)&&(e.italics=!0),d){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}u==="uppercase"&&(e.allCaps=!0),u==="lowercase"&&(e.smallCaps=!0),c&&(e.color=b(c));let i=t.tagName;return i==="SUP"?e.superScript=!0:i==="SUB"?e.subScript=!0:["STRONG","B"].includes(i)?e.bold=!0:["EM","I"].includes(i)?e.italics=!0:["DEL","S"].includes(i)?e.strike=!0:["U","INS"].includes(i)?e.underline={}:i==="MARK"?(e.highlight="yellow",e.emphasisMark={}):i==="PRE"?e.pre=!0:i==="INPUT"&&(e.type=t.type,e.name=t.name,e.value=(l=t.value)!=null?l:t.defaultValue,e.checked=(h=t.checked)!=null?h:t.defaultChecked),e.tag=i.toLowerCase(),e},f=(t,n=!1)=>{var d,u,c,p,o,i;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(u=n?t.textContent:(d=t.textContent)==null?void 0:d.replace(/^\s+|\s+$/g," "))!=null?u:""};let e=Array.from(t.childNodes).map(l=>f(l,n)),r=S(t),s=t.getAttributeNames().reduce((l,h)=>({...l,[h]:t.getAttribute(h)}),{}),a=t.tagName;switch(a){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(c=s.src)!=null?c:"",alt:(p=s.alt)!=null?p:"",data:{...r,...s}};case"svg":return{type:"svg",value:t.outerHTML,data:r};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:D[a],children:e,data:r};case"A":return{type:"link",url:(o=s.href)!=null?o:"",children:e,data:r};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:r}:{type:"text",value:(i=r.value)!=null?i:`_${t.value||"_".repeat(20)}_`,data:{...r,border:{style:m.OUTSET}}}}return{type:"fragment",children:e,data:r}},E=(t,n)=>{let e=Array.from(t.childNodes),r=[],s=[];for(let a of e)(a instanceof HTMLElement||a instanceof SVGElement)&&!O.includes(a.tagName)?(s.length&&(r.push({type:"paragraph",children:s.map(d=>f(d,n==null?void 0:n.pre))}),s.length=0),r.push(U(a))):s.push(a);return s.length&&r.push({type:"paragraph",children:s.map(a=>f(a,n==null?void 0:n.pre))}),r.length===1?{...r[0],data:{...n,...r[0].data}}:{type:"fragment",children:r,data:n}},B=(t,n)=>Array.from(t.children).map(e=>{let r={...n,...S(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[E(s,{...r,tag:void 0})],data:{...r,tag:s.tagName.toLowerCase()}})),data:r}:B(e,r)}).flat(),y={style:"single"},w={left:y,right:y,top:y,bottom:y},U=t=>{let n=S(t),e=t.tagName;switch(e){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return{type:"heading",depth:parseInt(e[1]),children:Array.from(t.childNodes).map(r=>f(r)),data:n};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return E(t,n);case"UL":case"OL":return{type:"list",ordered:e==="OL",children:Array.from(t.childNodes).map(r=>({type:"listItem",children:[E(r)],data:n}))};case"HR":return{type:"thematicBreak",data:n};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(r=>E(r)),data:n};case"TABLE":return{type:"table",children:B(t),data:n};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| ${t.textContent}`}],data:{...n,pre:!0,border:w}}}return{type:"paragraph",children:[f(t)],data:n}},S=t=>{var s,a,d;let n=(a=(s=t.value)==null?void 0:s.trim())!=null?a:"",e=n.split(" ")[0].slice(1),r=document.createElement("div");r.innerHTML=n.endsWith("/>")?n:`${n}</${e}>`,Object.assign(t,{...f(r.children[0]),children:(d=t.children)!=null?d:[]})},B=(t,n=!0)=>{var s,a,d,u;let e=[],r=[];for(let i of t.children){(s=i.children)!=null&&s.length&&B(i,!1);let p=i.value,o=typeof p=="string"?p:"",c=(a=o==null?void 0:o.split)==null?void 0:a.call(o," ")[0].replace(/^<|\/?>$/g,"");if(i.type==="html"&&!M.includes(c)&&/^<[^>]*[^/]>$/.test(o))if(c[0]==="/"){let h=r.shift();if(!h)throw new Error(`Invalid HTML: ${o}`);S(h),((u=(d=r[0])==null?void 0:d.children)!=null?u:e).push(h)}else r.unshift({...i,children:[],tag:c});else r.length?r[0].children.push(i):e.push(i);let l=i.type==="html"&&(M.includes(c)||/^<[^>]*\/>$/.test(o));if(l&&!n)S(i);else if(l&&n||i.type==="html"&&!/^<[^>]*>$/.test(o)){let h=document.createElement("div");h.innerHTML=o,Object.assign(i,T(h))}}t.children=e},_=()=>({preprocess:B});export{_ as htmlPlugin}; | ||
| ${t.textContent}`}],data:{...n,pre:!0,border:w}}}return{type:"paragraph",children:[f(t)],data:n}},N=t=>{var s,a,d;let n=(a=(s=t.value)==null?void 0:s.trim())!=null?a:"",e=n.split(" ")[0].slice(1),r=document.createElement("div");r.innerHTML=n.endsWith("/>")?n:`${n}</${e}>`,Object.assign(t,{...f(r.children[0]),children:(d=t.children)!=null?d:[]})},A=(t,n=!0)=>{var s,a,d,u;let e=[],r=[];for(let c of t.children){(s=c.children)!=null&&s.length&&A(c,!1);let p=c.value,o=typeof p=="string"?p:"",i=(a=o==null?void 0:o.split)==null?void 0:a.call(o," ")[0].replace(/^<|\/?>$/g,"");if(c.type==="html"&&!I.includes(i)&&/^<[^>]*[^/]>$/.test(o))if(i[0]==="/"){let h=r.shift();if(!h)throw new Error(`Invalid HTML: ${o}`);N(h),((u=(d=r[0])==null?void 0:d.children)!=null?u:e).push(h)}else r.unshift({...c,children:[],tag:i});else r.length?r[0].children.push(c):e.push(c);let l=c.type==="html"&&(I.includes(i)||/^<[^>]*\/>$/.test(o));if(l&&!n)N(c);else if(l&&n||c.type==="html"&&!/^<[^>]*>$/.test(o)){let h=document.createElement("div");h.innerHTML=o,Object.assign(c,E(h))}}t.children=e},_=()=>({preprocess:A});export{_ as htmlPlugin}; |
+3
-3
@@ -5,3 +5,3 @@ { | ||
| "private": false, | ||
| "version": "1.1.9", | ||
| "version": "1.1.10", | ||
| "description": "Extend MDAST by parsing embedded HTML in Markdown. Converts HTML into structured MDAST nodes compatible with @m2d/core for DOCX generation.", | ||
@@ -39,3 +39,3 @@ "license": "MPL-2.0", | ||
| "@testing-library/react": "^16.3.0", | ||
| "@types/node": "^24.1.0", | ||
| "@types/node": "^24.2.0", | ||
| "@types/react": "^19.1.9", | ||
@@ -51,3 +51,3 @@ "@types/react-dom": "^19.1.7", | ||
| "tsup": "^8.5.0", | ||
| "typescript": "^5.8.3", | ||
| "typescript": "^5.9.2", | ||
| "unified": "^11.0.5", | ||
@@ -54,0 +54,0 @@ "vite-tsconfig-paths": "^5.1.4", |
22495
0.3%