@mdast2docx/html
Advanced tools
+2
-2
@@ -1,3 +0,3 @@ | ||
| "use strict";var y=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var D=(t,r)=>{for(var e in r)y(t,e,{get:r[e],enumerable:!0})},k=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of H(r))!O.call(t,s)&&s!==e&&y(t,s,{get:()=>r[s],enumerable:!(n=R(r,s))||n.enumerable});return t};var P=t=>k(y({},"__esModule",{value:!0}),t);var V={};D(V,{htmlPlugin:()=>$});module.exports=P(V);var b=t=>{let r=document.createElement("canvas").getContext("2d");return r?(r.fillStyle=t,r.fillStyle.slice(1)):t.startsWith("#")?t.slice(1):"auto"};var p=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"],x={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},S=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],w=t=>{var n;if(!t)return{};let r={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[c,i]=s.split(":").map(u=>u.trim()),o=i.split(/\s+/),h=(n=o.find(u=>u.endsWith("px")))==null?void 0:n.replace("px",""),l=o.find(u=>S.includes(u.toLowerCase())),a=o.find(u=>!u.endsWith("px")&&!S.includes(u.toLowerCase())),d=c==="border"?"border":c.replace("border-","");r[d]={...h?{width:parseInt(h,1)}:{},...l?{style:l}:{},...a?{color:a}:{}}}return r},U={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},f=t=>{if(!t||!Object.keys(t).length)return;let{width:r,color:e,style:n}=t,s={style:n?U[n]:p.BorderStyle.SINGLE};return r&&(s.size=r),e&&(s.color=b(e)),s},E=(t,r=!0)=>{var u;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:n,fontWeight:s,fontStyle:c,textDecoration:i,textTransform:o,color:h}=t.style,l=t.getAttribute("style"),a=w(l);if(e.style=l!=null?l:void 0,r&&a.border)e.border=f(a.border);else if(Object.keys(a).length){let L={...a.border,...a.left},B={...a.border,...a.right},A={...a.border,...a.top},C={...a.border,...a.bottom};e.border={left:f(L),right:f(B),top:f(A),bottom:f(C)}}switch(n&&(Object.keys(p.AlignmentType).includes(n)?e.alignment=n:n==="justify"&&(e.alignment=p.AlignmentType.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(c)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}o==="uppercase"&&(e.allCaps=!0),o==="lowercase"&&(e.smallCaps=!0),h&&(e.color=b(h));let d=t.tagName;return d==="SUP"?e.superScript=!0:d==="SUB"?e.subScript=!0:["STRONG","B"].includes(d)?e.bold=!0:["EM","I"].includes(d)?e.italics=!0:["DEL","S"].includes(d)?e.strike=!0:["U","INS"].includes(d)?e.underline={}:d==="MARK"?(e.highlight="yellow",e.emphasisMark={}):d==="PRE"?e.pre=!0:/(radio|checkbox)/.test(d)&&(e.type=t.type,e.name=t.name,e.value=t.value,e.checked=(u=t.checked)!=null?u:t.defaultChecked),e.tag=d.toLowerCase(),e},m=(t,r=!1)=>{var i,o,h,l,a;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(o=r?t.textContent:(i=t.textContent)==null?void 0:i.replace(/^\s+|\s+$/g," "))!=null?o:""};let e=Array.from(t.childNodes).map(d=>m(d,r)),n=E(t),s=t.getAttributeNames().reduce((d,u)=>({...d,[u]:t.getAttribute(u)}),{}),c=t.tagName;switch(c){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(h=s.src)!=null?h:"",alt:(l=s.alt)!=null?l:"",data:{...n,...s}};case"svg":return{type:"svg",value:t.outerHTML,data:n};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:x[c],children:e,data:n};case"A":return{type:"link",url:(a=s.href)!=null?a:"",children:e,data:n};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:n}:{type:"text",value:`_${t.value||"_".repeat(20)}_`,data:{...n,border:{style:p.BorderStyle.OUTSET}}}}return{type:"fragment",children:e,data:n}},g=(t,r)=>{let e={...r,...E(t)},n=Array.from(t.childNodes),s=[],c=[];for(let i of n)(i instanceof HTMLElement||i instanceof SVGElement)&&!v.includes(i.tagName)?(c.length&&(s.push({type:"paragraph",children:c.map(o=>m(o,e==null?void 0:e.pre))}),c.length=0),s.push(_(i))):c.push(i);return c.length&&s.push({type:"paragraph",children:c.map(i=>m(i,e==null?void 0:e.pre))}),s.length===1?{...s[0],data:{...e,...s[0].data}}:{type:"fragment",children:s,data:e}},N=(t,r)=>Array.from(t.children).map(e=>{let n={...r,...E(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[g(s,n)]})),data:n}:N(e,n)}).flat(),T={style:"single"},G={left:T,right:T,top:T,bottom:T},_=t=>{let r=E(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(n=>m(n)),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return g(t,r);case"UL":case"OL":return{type:"list",ordered:e==="OL",children:Array.from(t.childNodes).map(n=>({type:"listItem",children:[g(n)],data:r}))};case"HR":return{type:"thematicBreak",data:r};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(n=>g(n)),data:r};case"TABLE":return{type:"table",children:N(t),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| "use strict";var b=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var k=(t,r)=>{for(var e in r)b(t,e,{get:r[e],enumerable:!0})},P=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of O(r))!D.call(t,s)&&s!==e&&b(t,s,{get:()=>r[s],enumerable:!(n=H(r,s))||n.enumerable});return t};var v=t=>P(b({},"__esModule",{value:!0}),t);var W={};k(W,{htmlPlugin:()=>V});module.exports=v(W);var S=t=>{let r=document.createElement("canvas").getContext("2d");return r?(r.fillStyle=t,r.fillStyle.slice(1)):t.startsWith("#")?t.slice(1):"auto"};var u=require("docx"),w=["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"],x={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},I=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],U=t=>{var n;if(!t)return{};let r={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[c,i]=s.split(":").map(p=>p.trim()),o=i.split(/\s+/),h=(n=o.find(p=>p.endsWith("px")))==null?void 0:n.replace("px",""),l=o.find(p=>I.includes(p.toLowerCase())),a=o.find(p=>!p.endsWith("px")&&!I.includes(p.toLowerCase())),d=c==="border"?"border":c.replace("border-","");r[d]={...h?{width:parseInt(h,1)}:{},...l?{style:l}:{},...a?{color:a}:{}}}return r},G={solid:u.BorderStyle.SINGLE,dashed:u.BorderStyle.DASHED,dotted:u.BorderStyle.DOTTED,double:u.BorderStyle.DOUBLE,none:u.BorderStyle.NONE,ridge:u.BorderStyle.THREE_D_EMBOSS,groove:u.BorderStyle.THREE_D_ENGRAVE,inset:u.BorderStyle.INSET,outset:u.BorderStyle.OUTSET},g=t=>{if(!t||!Object.keys(t).length)return;let{width:r,color:e,style:n}=t,s={style:n?G[n]:u.BorderStyle.SINGLE};return r&&(s.size=r),e&&(s.color=S(e)),s},y=(t,r=!0)=>{var p,f;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:n,fontWeight:s,fontStyle:c,textDecoration:i,textTransform:o,color:h}=t.style,l=t.getAttribute("style"),a=U(l);if(e.style=l!=null?l:void 0,r&&a.border)e.border=g(a.border);else if(Object.keys(a).length){let B={...a.border,...a.left},A={...a.border,...a.right},C={...a.border,...a.top},R={...a.border,...a.bottom};e.border={left:g(B),right:g(A),top:g(C),bottom:g(R)}}switch(n&&(Object.keys(u.AlignmentType).includes(n)?e.alignment=n:n==="justify"&&(e.alignment=u.AlignmentType.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(c)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}o==="uppercase"&&(e.allCaps=!0),o==="lowercase"&&(e.smallCaps=!0),h&&(e.color=S(h));let d=t.tagName;return d==="SUP"?e.superScript=!0:d==="SUB"?e.subScript=!0:["STRONG","B"].includes(d)?e.bold=!0:["EM","I"].includes(d)?e.italics=!0:["DEL","S"].includes(d)?e.strike=!0:["U","INS"].includes(d)?e.underline={}:d==="MARK"?(e.highlight="yellow",e.emphasisMark={}):d==="PRE"?e.pre=!0:d==="INPUT"&&(e.type=t.type,e.name=t.name,e.value=(p=t.value)!=null?p:t.defaultValue,e.checked=(f=t.checked)!=null?f:t.defaultChecked),e.tag=d.toLowerCase(),e},m=(t,r=!1)=>{var i,o,h,l,a,d;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(o=r?t.textContent:(i=t.textContent)==null?void 0:i.replace(/^\s+|\s+$/g," "))!=null?o:""};let e=Array.from(t.childNodes).map(p=>m(p,r)),n=y(t),s=t.getAttributeNames().reduce((p,f)=>({...p,[f]:t.getAttribute(f)}),{}),c=t.tagName;switch(c){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(h=s.src)!=null?h:"",alt:(l=s.alt)!=null?l:"",data:{...n,...s}};case"svg":return{type:"svg",value:t.outerHTML,data:n};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:x[c],children:e,data:n};case"A":return{type:"link",url:(a=s.href)!=null?a:"",children:e,data:n};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:n}:{type:"text",value:(d=n.value)!=null?d:`_${t.value||"_".repeat(20)}_`,data:{...n,border:{style:u.BorderStyle.OUTSET}}}}return{type:"fragment",children:e,data:n}},T=(t,r)=>{let e={...r,...y(t)},n=Array.from(t.childNodes),s=[],c=[];for(let i of n)(i instanceof HTMLElement||i instanceof SVGElement)&&!w.includes(i.tagName)?(c.length&&(s.push({type:"paragraph",children:c.map(o=>m(o,e==null?void 0:e.pre))}),c.length=0),s.push($(i))):c.push(i);return c.length&&s.push({type:"paragraph",children:c.map(i=>m(i,e==null?void 0:e.pre))}),s.length===1?{...s[0],data:{...e,...s[0].data}}:{type:"fragment",children:s,data:e}},N=(t,r)=>Array.from(t.children).map(e=>{let n={...r,...y(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[T(s,n)]})),data:n}:N(e,n)}).flat(),E={style:"single"},_={left:E,right:E,top:E,bottom:E},$=t=>{let r=y(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(n=>m(n)),data:r};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return T(t,r);case"UL":case"OL":return{type:"list",ordered:e==="OL",children:Array.from(t.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(t.childNodes).map(n=>T(n)),data:r};case"TABLE":return{type:"table",children:N(t),data:r};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| ${t.textContent}`}],data:{...r,pre:!0,border:G}}}return{type:"paragraph",children:[m(t)],data:r}},M=t=>{var s,c,i;let r=(c=(s=t.value)==null?void 0:s.trim())!=null?c:"",e=r.split(" ")[0].slice(1),n=document.createElement("div");n.innerHTML=r.endsWith("/>")?r:`${r}</${e}>`,Object.assign(t,{...m(n.children[0]),children:(i=t.children)!=null?i:[]})},I=(t,r=!0)=>{var s,c,i;let e=[],n=[];for(let o of t.children){if((s=o.children)!=null&&s.length&&I(o,!1),o.type==="html"&&/^<[^>]*[^/]>$/.test(o.value)){let l=o.value.split(" ")[0].replace(/^<|>$/g,"");if(l[0]==="/"){let a=n.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);M(a),((i=(c=n[0])==null?void 0:c.children)!=null?i:e).push(a)}else n.unshift({...o,children:[],tag:l})}else n.length?n[0].children.push(o):e.push(o);let h=o.type==="html"&&/^<[^>]*\/>$/.test(o.value);if(h&&!r)M(o);else if(h&&r||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let l=document.createElement("div");l.innerHTML=o.value,Object.assign(o,g(l))}}t.children=e},$=()=>({preprocess:I});0&&(module.exports={htmlPlugin}); | ||
| ${t.textContent}`}],data:{...r,pre:!0,border:_}}}return{type:"paragraph",children:[m(t)],data:r}},M=t=>{var s,c,i;let r=(c=(s=t.value)==null?void 0:s.trim())!=null?c:"",e=r.split(" ")[0].slice(1),n=document.createElement("div");n.innerHTML=r.endsWith("/>")?r:`${r}</${e}>`,Object.assign(t,{...m(n.children[0]),children:(i=t.children)!=null?i:[]})},L=(t,r=!0)=>{var s,c,i;let e=[],n=[];for(let o of t.children){if((s=o.children)!=null&&s.length&&L(o,!1),o.type==="html"&&/^<[^>]*[^/]>$/.test(o.value)){let l=o.value.split(" ")[0].replace(/^<|>$/g,"");if(l[0]==="/"){let a=n.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);M(a),((i=(c=n[0])==null?void 0:c.children)!=null?i:e).push(a)}else n.unshift({...o,children:[],tag:l})}else n.length?n[0].children.push(o):e.push(o);let h=o.type==="html"&&/^<[^>]*\/>$/.test(o.value);if(h&&!r)M(o);else if(h&&r||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let l=document.createElement("div");l.innerHTML=o.value,Object.assign(o,T(l))}}t.children=e},V=()=>({preprocess:L});0&&(module.exports={htmlPlugin}); |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import{a as y}from"./chunk-CYY6OEIU.mjs";import{AlignmentType as b,BorderStyle as h}from"docx";var C=["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"],H={A:"link",B:"strong",BR:"break",EM:"emphasis",STRONG:"strong",I:"emphasis",IMG:"image",DEL:"delete",S:"delete"},S=["solid","dashed","dotted","double","none","ridge","groove","inset","outset"],O=t=>{var r;if(!t)return{};let s={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let n of e){let[c,i]=n.split(":").map(p=>p.trim()),o=i.split(/\s+/),u=(r=o.find(p=>p.endsWith("px")))==null?void 0:r.replace("px",""),l=o.find(p=>S.includes(p.toLowerCase())),a=o.find(p=>!p.endsWith("px")&&!S.includes(p.toLowerCase())),d=c==="border"?"border":c.replace("border-","");s[d]={...u?{width:parseInt(u,1)}:{},...l?{style:l}:{},...a?{color:a}:{}}}return s},D={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},f=t=>{if(!t||!Object.keys(t).length)return;let{width:s,color:e,style:r}=t,n={style:r?D[r]:h.SINGLE};return s&&(n.size=s),e&&(n.color=y(e)),n},E=(t,s=!0)=>{var p;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:r,fontWeight:n,fontStyle:c,textDecoration:i,textTransform:o,color:u}=t.style,l=t.getAttribute("style"),a=O(l);if(e.style=l!=null?l:void 0,s&&a.border)e.border=f(a.border);else if(Object.keys(a).length){let L={...a.border,...a.left},B={...a.border,...a.right},A={...a.border,...a.top},R={...a.border,...a.bottom};e.border={left:f(L),right:f(B),top:f(A),bottom:f(R)}}switch(r&&(Object.keys(b).includes(r)?e.alignment=r:r==="justify"&&(e.alignment=b.JUSTIFIED)),(/bold/.test(n)||parseInt(n)>=500)&&(e.bold=!0),/(italic|oblique)/.test(c)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}o==="uppercase"&&(e.allCaps=!0),o==="lowercase"&&(e.smallCaps=!0),u&&(e.color=y(u));let d=t.tagName;return d==="SUP"?e.superScript=!0:d==="SUB"?e.subScript=!0:["STRONG","B"].includes(d)?e.bold=!0:["EM","I"].includes(d)?e.italics=!0:["DEL","S"].includes(d)?e.strike=!0:["U","INS"].includes(d)?e.underline={}:d==="MARK"?(e.highlight="yellow",e.emphasisMark={}):d==="PRE"?e.pre=!0:/(radio|checkbox)/.test(d)&&(e.type=t.type,e.name=t.name,e.value=t.value,e.checked=(p=t.checked)!=null?p:t.defaultChecked),e.tag=d.toLowerCase(),e},m=(t,s=!1)=>{var i,o,u,l,a;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(o=s?t.textContent:(i=t.textContent)==null?void 0:i.replace(/^\s+|\s+$/g," "))!=null?o:""};let e=Array.from(t.childNodes).map(d=>m(d,s)),r=E(t),n=t.getAttributeNames().reduce((d,p)=>({...d,[p]:t.getAttribute(p)}),{}),c=t.tagName;switch(c){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(u=n.src)!=null?u:"",alt:(l=n.alt)!=null?l:"",data:{...r,...n}};case"svg":return{type:"svg",value:t.outerHTML,data:r};case"EM":case"I":case"STRONG":case"B":case"DEL":case"S":return{type:H[c],children:e,data:r};case"A":return{type:"link",url:(a=n.href)!=null?a:"",children:e,data:r};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:r}:{type:"text",value:`_${t.value||"_".repeat(20)}_`,data:{...r,border:{style:h.OUTSET}}}}return{type:"fragment",children:e,data:r}},g=(t,s)=>{let e={...s,...E(t)},r=Array.from(t.childNodes),n=[],c=[];for(let i of r)(i instanceof HTMLElement||i instanceof SVGElement)&&!C.includes(i.tagName)?(c.length&&(n.push({type:"paragraph",children:c.map(o=>m(o,e==null?void 0:e.pre))}),c.length=0),n.push(P(i))):c.push(i);return c.length&&n.push({type:"paragraph",children:c.map(i=>m(i,e==null?void 0:e.pre))}),n.length===1?{...n[0],data:{...e,...n[0].data}}:{type:"fragment",children:n,data:e}},N=(t,s)=>Array.from(t.children).map(e=>{let r={...s,...E(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(n=>({type:"tableCell",children:[g(n,r)]})),data:r}:N(e,r)}).flat(),T={style:"single"},k={left:T,right:T,top:T,bottom:T},P=t=>{let s=E(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:s};case"PRE":case"P":case"DIV":case"DETAILS":case"SUMMARY":case"FORM":case"LI":return g(t,s);case"UL":case"OL":return{type:"list",ordered:e==="OL",children:Array.from(t.childNodes).map(r=>({type:"listItem",children:[g(r)],data:s}))};case"HR":return{type:"thematicBreak",data:s};case"BLOCKQUOTE":return{type:"blockquote",children:Array.from(t.childNodes).map(r=>g(r)),data:s};case"TABLE":return{type:"table",children:N(t),data:s};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| import{a as b}from"./chunk-CYY6OEIU.mjs";import{AlignmentType as I,BorderStyle as h}from"docx";var H=["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"],O={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"],D=t=>{var r;if(!t)return{};let n={},e=t.match(/border(-\w+)?:\s*[^;]+/gi);if(!e)return{};for(let s of e){let[c,i]=s.split(":").map(p=>p.trim()),o=i.split(/\s+/),u=(r=o.find(p=>p.endsWith("px")))==null?void 0:r.replace("px",""),l=o.find(p=>M.includes(p.toLowerCase())),a=o.find(p=>!p.endsWith("px")&&!M.includes(p.toLowerCase())),d=c==="border"?"border":c.replace("border-","");n[d]={...u?{width:parseInt(u,1)}:{},...l?{style:l}:{},...a?{color:a}:{}}}return n},k={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?k[r]:h.SINGLE};return n&&(s.size=n),e&&(s.color=b(e)),s},y=(t,n=!0)=>{var p,f;let e={};if(!(t instanceof HTMLElement||t instanceof SVGElement))return e;let{textAlign:r,fontWeight:s,fontStyle:c,textDecoration:i,textTransform:o,color:u}=t.style,l=t.getAttribute("style"),a=D(l);if(e.style=l!=null?l:void 0,n&&a.border)e.border=g(a.border);else if(Object.keys(a).length){let B={...a.border,...a.left},A={...a.border,...a.right},R={...a.border,...a.top},C={...a.border,...a.bottom};e.border={left:g(B),right:g(A),top:g(R),bottom:g(C)}}switch(r&&(Object.keys(I).includes(r)?e.alignment=r:r==="justify"&&(e.alignment=I.JUSTIFIED)),(/bold/.test(s)||parseInt(s)>=500)&&(e.bold=!0),/(italic|oblique)/.test(c)&&(e.italics=!0),i){case"underline":e.underline={};break;case"overline":e.emphasisMark={};break;case"line-through":e.strike=!0;break}o==="uppercase"&&(e.allCaps=!0),o==="lowercase"&&(e.smallCaps=!0),u&&(e.color=b(u));let d=t.tagName;return d==="SUP"?e.superScript=!0:d==="SUB"?e.subScript=!0:["STRONG","B"].includes(d)?e.bold=!0:["EM","I"].includes(d)?e.italics=!0:["DEL","S"].includes(d)?e.strike=!0:["U","INS"].includes(d)?e.underline={}:d==="MARK"?(e.highlight="yellow",e.emphasisMark={}):d==="PRE"?e.pre=!0:d==="INPUT"&&(e.type=t.type,e.name=t.name,e.value=(p=t.value)!=null?p:t.defaultValue,e.checked=(f=t.checked)!=null?f:t.defaultChecked),e.tag=d.toLowerCase(),e},m=(t,n=!1)=>{var i,o,u,l,a,d;if(!(t instanceof HTMLElement||t instanceof SVGElement))return{type:"text",value:(o=n?t.textContent:(i=t.textContent)==null?void 0:i.replace(/^\s+|\s+$/g," "))!=null?o:""};let e=Array.from(t.childNodes).map(p=>m(p,n)),r=y(t),s=t.getAttributeNames().reduce((p,f)=>({...p,[f]:t.getAttribute(f)}),{}),c=t.tagName;switch(c){case"BR":return{type:"break"};case"IMG":return{type:"image",url:(u=s.src)!=null?u:"",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:O[c],children:e,data:r};case"A":return{type:"link",url:(a=s.href)!=null?a:"",children:e,data:r};case"INPUT":return/(radio|checkbox)/.test(t.type)?{type:"checkbox",data:r}:{type:"text",value:(d=r.value)!=null?d:`_${t.value||"_".repeat(20)}_`,data:{...r,border:{style:h.OUTSET}}}}return{type:"fragment",children:e,data:r}},T=(t,n)=>{let e={...n,...y(t)},r=Array.from(t.childNodes),s=[],c=[];for(let i of r)(i instanceof HTMLElement||i instanceof SVGElement)&&!H.includes(i.tagName)?(c.length&&(s.push({type:"paragraph",children:c.map(o=>m(o,e==null?void 0:e.pre))}),c.length=0),s.push(v(i))):c.push(i);return c.length&&s.push({type:"paragraph",children:c.map(i=>m(i,e==null?void 0:e.pre))}),s.length===1?{...s[0],data:{...e,...s[0].data}}:{type:"fragment",children:s,data:e}},S=(t,n)=>Array.from(t.children).map(e=>{let r={...n,...y(e)};return e.tagName==="TR"?{type:"tableRow",children:Array.from(e.children).map(s=>({type:"tableCell",children:[T(s,r)]})),data:r}:S(e,r)}).flat(),E={style:"single"},P={left:E,right:E,top:E,bottom:E},v=t=>{let n=y(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:S(t),data:n};case"STYLE":return{type:"paragraph",children:[{type:"text",value:`Not supported yet! | ||
| ${t.textContent}`}],data:{...s,pre:!0,border:k}}}return{type:"paragraph",children:[m(t)],data:s}},M=t=>{var n,c,i;let s=(c=(n=t.value)==null?void 0:n.trim())!=null?c:"",e=s.split(" ")[0].slice(1),r=document.createElement("div");r.innerHTML=s.endsWith("/>")?s:`${s}</${e}>`,Object.assign(t,{...m(r.children[0]),children:(i=t.children)!=null?i:[]})},I=(t,s=!0)=>{var n,c,i;let e=[],r=[];for(let o of t.children){if((n=o.children)!=null&&n.length&&I(o,!1),o.type==="html"&&/^<[^>]*[^/]>$/.test(o.value)){let l=o.value.split(" ")[0].replace(/^<|>$/g,"");if(l[0]==="/"){let a=r.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);M(a),((i=(c=r[0])==null?void 0:c.children)!=null?i:e).push(a)}else r.unshift({...o,children:[],tag:l})}else r.length?r[0].children.push(o):e.push(o);let u=o.type==="html"&&/^<[^>]*\/>$/.test(o.value);if(u&&!s)M(o);else if(u&&s||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let l=document.createElement("div");l.innerHTML=o.value,Object.assign(o,g(l))}}t.children=e},x=()=>({preprocess:I});export{x as htmlPlugin}; | ||
| ${t.textContent}`}],data:{...n,pre:!0,border:P}}}return{type:"paragraph",children:[m(t)],data:n}},N=t=>{var s,c,i;let n=(c=(s=t.value)==null?void 0:s.trim())!=null?c:"",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:(i=t.children)!=null?i:[]})},L=(t,n=!0)=>{var s,c,i;let e=[],r=[];for(let o of t.children){if((s=o.children)!=null&&s.length&&L(o,!1),o.type==="html"&&/^<[^>]*[^/]>$/.test(o.value)){let l=o.value.split(" ")[0].replace(/^<|>$/g,"");if(l[0]==="/"){let a=r.shift();if(!a)throw new Error(`Invalid HTML: ${o.value}`);N(a),((i=(c=r[0])==null?void 0:c.children)!=null?i:e).push(a)}else r.unshift({...o,children:[],tag:l})}else r.length?r[0].children.push(o):e.push(o);let u=o.type==="html"&&/^<[^>]*\/>$/.test(o.value);if(u&&!n)N(o);else if(u&&n||o.type==="html"&&!/^<[^>]*>$/.test(o.value)){let l=document.createElement("div");l.innerHTML=o.value,Object.assign(o,T(l))}}t.children=e},G=()=>({preprocess:L});export{G as htmlPlugin}; |
+1
-1
@@ -5,3 +5,3 @@ { | ||
| "private": false, | ||
| "version": "1.1.4", | ||
| "version": "1.1.5", | ||
| "description": "Extend MDAST by parsing embedded HTML in Markdown. Converts HTML into structured MDAST nodes compatible with @m2d/core for DOCX generation.", | ||
@@ -8,0 +8,0 @@ "license": "MPL-2.0", |
21897
0.33%