@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})},v=(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 w=e=>v(y({},"__esModule",{value:!0}),e);var W={};P(W,{htmlPlugin:()=>Y});module.exports=w(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 p=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[i,u]=s.split(":").map(d=>d.trim()),h=u.split(/\s+/),o=(n=h.find(d=>d.endsWith("px")))==null?void 0:n.replace("px",""),l=h.find(d=>M.includes(d.toLowerCase())),c=h.find(d=>!d.endsWith("px")&&!M.includes(d.toLowerCase())),a=i==="border"?"border":i.replace("border-","");r[a]={...o?{width:parseInt(o,1)}:{},...l?{style:l}:{},...c?{color:c}:{}}}return r},_={solid:p.BorderStyle.SINGLE,dashed:p.BorderStyle.DASHED,dotted:p.BorderStyle.DOTTED,double:p.BorderStyle.DOUBLE,none:p.BorderStyle.NONE,ridge:p.BorderStyle.THREE_D_EMBOSS,groove:p.BorderStyle.THREE_D_ENGRAVE,inset:p.BorderStyle.INSET,outset:p.BorderStyle.OUTSET},g=e=>{if(!e||!Object.keys(e).length)return;let{width:r,color:t,style:n}=e,s={style:n?_[n]:p.BorderStyle.SINGLE};return r&&(s.size=r),t&&(s.color=b(t)),s},S=(e,r=!0)=>{var d,f;let t={};if(!(e instanceof HTMLElement||e instanceof SVGElement))return t;let{textAlign:n,fontWeight:s,fontStyle:i,textDecoration:u,textTransform:h,color:o}=e.style,l=e.getAttribute("style"),c=G(l);if(t.style=l!=null?l:void 0,r&&c.border)t.border=g(c.border);else if(Object.keys(c).length){let A={...c.border,...c.left},C={...c.border,...c.right},R={...c.border,...c.top},H={...c.border,...c.bottom};t.border={left:g(A),right:g(C),top:g(R),bottom:g(H)}}switch(n&&(Object.keys(p.AlignmentType).includes(n)?t.alignment=n:n==="justify"&&(t.alignment=p.AlignmentType.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(t.bold=!0),/(italic|oblique)/.test(i)&&(t.italics=!0),u){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),o&&(t.color=b(o));let a=e.tagName;return a==="SUP"?t.superScript=!0:a==="SUB"?t.subScript=!0:["STRONG","B"].includes(a)?t.bold=!0:["EM","I"].includes(a)?t.italics=!0:["DEL","S"].includes(a)?t.strike=!0:["U","INS"].includes(a)?t.underline={}:a==="MARK"?(t.highlight="yellow",t.emphasisMark={}):a==="PRE"?t.pre=!0:a==="INPUT"&&(t.type=e.type,t.name=e.name,t.value=(d=e.value)!=null?d:e.defaultValue,t.checked=(f=e.checked)!=null?f:e.defaultChecked),t.tag=a.toLowerCase(),t},m=(e,r=!1)=>{var u,h,o,l,c,a;if(!(e instanceof HTMLElement||e instanceof SVGElement))return{type:"text",value:(h=r?e.textContent:(u=e.textContent)==null?void 0:u.replace(/^\s+|\s+$/g," "))!=null?h:""};let t=Array.from(e.childNodes).map(d=>m(d,r)),n=S(e),s=e.getAttributeNames().reduce((d,f)=>({...d,[f]:e.getAttribute(f)}),{}),i=e.tagName;switch(i){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(o=s.src)!=null?o:"",alt:(l=s.alt)!=null?l:"",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[i],children:t,data:n};case"A":return{type:"link",url:(c=s.href)!=null?c:"",children:t,data:n};case"INPUT":return/(radio|checkbox)/.test(e.type)?{type:"checkbox",data:n}:{type:"text",value:(a=n.value)!=null?a:`_${e.value||"_".repeat(20)}_`,data:{...n,border:{style:p.BorderStyle.OUTSET}}}}return{type:"fragment",children:t,data:n}},T=(e,r)=>{let t=Array.from(e.childNodes),n=[],s=[];for(let i of t)(i instanceof HTMLElement||i instanceof SVGElement)&&!x.includes(i.tagName)?(s.length&&(n.push({type:"paragraph",children:s.map(u=>m(u,r==null?void 0:r.pre))}),s.length=0),n.push(V(i))):s.push(i);return s.length&&n.push({type:"paragraph",children:s.map(i=>m(i,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=>m(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 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! | ||
| ${e.textContent}`}],data:{...r,pre:!0,border:$}}}return{type:"paragraph",children:[m(e)],data:r}},N=e=>{var s,i,u;let r=(i=(s=e.value)==null?void 0:s.trim())!=null?i:"",t=r.split(" ")[0].slice(1),n=document.createElement("div");n.innerHTML=r.endsWith("/>")?r:`${r}</${t}>`,Object.assign(e,{...m(n.children[0]),children:(u=e.children)!=null?u:[]})},B=(e,r=!0)=>{var s,i,u,h;let t=[],n=[];for(let o of e.children){(s=o.children)!=null&&s.length&&B(o,!1);let l=(i=o.value)==null?void 0:i.split(" ")[0].replace(/^<|\/?>$/g,"");if(o.type==="html"&&!L.includes(l)&&/^<[^>]*[^/]>$/.test(o.value))if(l[0]==="/"){let a=n.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);N(a),((h=(u=n[0])==null?void 0:u.children)!=null?h:t).push(a)}else n.unshift({...o,children:[],tag:l});else n.length?n[0].children.push(o):t.push(o);let c=o.type==="html"&&(L.includes(l)||/^<[^>]*\/>$/.test(o.value));if(c&&!r)N(o);else if(c&&r||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let a=document.createElement("div");a.innerHTML=o.value,Object.assign(o,T(a))}}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:[]})},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}); |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import{a as y}from"./chunk-CYY6OEIU.mjs";import{AlignmentType as L,BorderStyle as h}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[i,p]=s.split(":").map(d=>d.trim()),u=p.split(/\s+/),o=(r=u.find(d=>d.endsWith("px")))==null?void 0:r.replace("px",""),l=u.find(d=>N.includes(d.toLowerCase())),c=u.find(d=>!d.endsWith("px")&&!N.includes(d.toLowerCase())),a=i==="border"?"border":i.replace("border-","");n[a]={...o?{width:parseInt(o,1)}:{},...l?{style:l}:{},...c?{color:c}:{}}}return n},P={solid:h.SINGLE,dashed:h.DASHED,dotted:h.DOTTED,double:h.DOUBLE,none:h.NONE,ridge:h.THREE_D_EMBOSS,groove:h.THREE_D_ENGRAVE,inset:h.INSET,outset:h.OUTSET},g=t=>{if(!t||!Object.keys(t).length)return;let{width:n,color:e,style:r}=t,s={style:r?P[r]:h.SINGLE};return n&&(s.size=n),e&&(s.color=y(e)),s},b=(t,n=!0)=>{var d,f;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:r,fontWeight:s,fontStyle:i,textDecoration:p,textTransform:u,color:o}=t.style,l=t.getAttribute("style"),c=k(l);if(e.style=l!=null?l:void 0,n&&c.border)e.border=g(c.border);else if(Object.keys(c).length){let A={...c.border,...c.left},C={...c.border,...c.right},R={...c.border,...c.top},H={...c.border,...c.bottom};e.border={left:g(A),right:g(C),top:g(R),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(i)&&(e.italics=!0),p){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),o&&(e.color=y(o));let a=t.tagName;return a==="SUP"?e.superScript=!0:a==="SUB"?e.subScript=!0:["STRONG","B"].includes(a)?e.bold=!0:["EM","I"].includes(a)?e.italics=!0:["DEL","S"].includes(a)?e.strike=!0:["U","INS"].includes(a)?e.underline={}:a==="MARK"?(e.highlight="yellow",e.emphasisMark={}):a==="PRE"?e.pre=!0:a==="INPUT"&&(e.type=t.type,e.name=t.name,e.value=(d=t.value)!=null?d:t.defaultValue,e.checked=(f=t.checked)!=null?f:t.defaultChecked),e.tag=a.toLowerCase(),e},m=(t,n=!1)=>{var p,u,o,l,c,a;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(u=n?t.textContent:(p=t.textContent)==null?void 0:p.replace(/^\s+|\s+$/g," "))!=null?u:""};let e=Array.from(t.childNodes).map(d=>m(d,n)),r=b(t),s=t.getAttributeNames().reduce((d,f)=>({...d,[f]:t.getAttribute(f)}),{}),i=t.tagName;switch(i){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(o=s.src)!=null?o:"",alt:(l=s.alt)!=null?l:"",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[i],children:e,data:r};case"A":return{type:"link",url:(c=s.href)!=null?c:"",children:e,data:r};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:r}:{type:"text",value:(a=r.value)!=null?a:`_${t.value||"_".repeat(20)}_`,data:{...r,border:{style:h.OUTSET}}}}return{type:"fragment",children:e,data:r}},T=(t,n)=>{let e=Array.from(t.childNodes),r=[],s=[];for(let i of e)(i instanceof HTMLElement||i instanceof SVGElement)&&!O.includes(i.tagName)?(s.length&&(r.push({type:"paragraph",children:s.map(p=>m(p,n==null?void 0:n.pre))}),s.length=0),r.push(w(i))):s.push(i);return s.length&&r.push({type:"paragraph",children:s.map(i=>m(i,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"},v={left:E,right:E,top:E,bottom:E},w=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=>m(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 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! | ||
| ${t.textContent}`}],data:{...n,pre:!0,border:v}}}return{type:"paragraph",children:[m(t)],data:n}},S=t=>{var s,i,p;let n=(i=(s=t.value)==null?void 0:s.trim())!=null?i:"",e=n.split(" ")[0].slice(1),r=document.createElement("div");r.innerHTML=n.endsWith("/>")?n:`${n}</${e}>`,Object.assign(t,{...m(r.children[0]),children:(p=t.children)!=null?p:[]})},B=(t,n=!0)=>{var s,i,p,u;let e=[],r=[];for(let o of t.children){(s=o.children)!=null&&s.length&&B(o,!1);let l=(i=o.value)==null?void 0:i.split(" ")[0].replace(/^<|\/?>$/g,"");if(o.type==="html"&&!M.includes(l)&&/^<[^>]*[^/]>$/.test(o.value))if(l[0]==="/"){let a=r.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);S(a),((u=(p=r[0])==null?void 0:p.children)!=null?u:e).push(a)}else r.unshift({...o,children:[],tag:l});else r.length?r[0].children.push(o):e.push(o);let c=o.type==="html"&&(M.includes(l)||/^<[^>]*\/>$/.test(o.value));if(c&&!n)S(o);else if(c&&n||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let a=document.createElement("div");a.innerHTML=o.value,Object.assign(o,T(a))}}t.children=e},_=()=>({preprocess:B});export{_ as htmlPlugin}; | ||
| ${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}; |
+5
-5
@@ -5,3 +5,3 @@ { | ||
| "private": false, | ||
| "version": "1.1.8", | ||
| "version": "1.1.9", | ||
| "description": "Extend MDAST by parsing embedded HTML in Markdown. Converts HTML into structured MDAST nodes compatible with @m2d/core for DOCX generation.", | ||
@@ -39,6 +39,6 @@ "license": "MPL-2.0", | ||
| "@testing-library/react": "^16.3.0", | ||
| "@types/node": "^24.0.4", | ||
| "@types/react": "^19.1.8", | ||
| "@types/react-dom": "^19.1.6", | ||
| "@vitejs/plugin-react": "^4.6.0", | ||
| "@types/node": "^24.1.0", | ||
| "@types/react": "^19.1.9", | ||
| "@types/react-dom": "^19.1.7", | ||
| "@vitejs/plugin-react": "^4.7.0", | ||
| "@vitest/coverage-v8": "^3.2.4", | ||
@@ -45,0 +45,0 @@ "docx": "^9.5.1", |
+5
-1
| # `@m2d/html` <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" height="40"/> | ||
| [](https://www.npmjs.com/package/@m2d/html)   | ||
| [](https://github.com/md2docx/html/actions/workflows/test.yml) | ||
| [](https://codecov.io/gh/md2docx/html) | ||
| [](https://www.npmjs.com/package/@m2d/html) | ||
|  | ||
|  | ||
@@ -5,0 +9,0 @@ > Parses embedded **HTML** into extended **MDAST nodes** to unlock full HTML-to-DOCX conversion support. |
22428
1.29%138
2.99%