ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
2 lines (1 loc) • 2.42 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("vue"),k=require("./AnimationText.js"),M=require("./sanitize.js"),g=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),x=new Set(["p","li","h1","h2","h3","h4","td","th","blockquote"]);function L(i){const e={};for(const t of Array.from(i.attributes)){const o=t.name;if(o==="class")e.class=t.value;else if(o==="style")e.style=t.value;else{if(o.startsWith("on"))continue;e[o]=t.value}}return e}function p(i,e){var T,N,y,b,A,C;const{components:t,streamStatus:o,enableAnimation:u,animationConfig:f,parentTag:n,parentIsCustom:h}=e;if(i.nodeType===Node.TEXT_NODE){const r=i.textContent||"";return u&&r.trim()&&!h&&n&&x.has(n)?c.h(k.default,{text:r,animationConfig:f}):r}if(i.nodeType!==Node.ELEMENT_NODE)return null;const a=i,s=(a.localName||a.tagName||a.nodeName||"").toLowerCase()||((N=(T=(a.outerHTML||"").match(/^<\s*([a-zA-Z][\w:-]*)/))==null?void 0:T[1])==null?void 0:N.toLowerCase())||"";if(!s)return a.textContent;const v=!!(t!=null&&t[s]),E=Array.from(a.childNodes).map(r=>p(r,{...e,parentTag:s,parentIsCustom:v||h})),l=L(a),d=E.filter(r=>r!=null),m=t==null?void 0:t[s];if(m){if(s==="code"){const r=((y=(a.getAttribute("class")||"").split(/\s+/).find(S=>S.startsWith("language-")))==null?void 0:y.replace("language-",""))||((b=a.parentElement)==null?void 0:b.getAttribute("data-language"))||void 0;l.lang=r;const w=(((A=a.parentElement)==null?void 0:A.localName)||((C=a.parentElement)==null?void 0:C.tagName)||"").toLowerCase();l.block=w==="pre",l.content=a.textContent||""}return l.streamStatus=o,typeof m=="string"?c.h(m,l,g.has(s)?void 0:()=>d):c.h(m,l,g.has(s)?void 0:()=>d)}if(s==="pre"&&(t!=null&&t.code)){const r=a.querySelector(":scope > code");if(r)return p(r,e)}return c.h(s,l,g.has(s)?void 0:d)}function _(i,e={}){if(!i)return[];const t=Object.keys(e.components||{}).filter(n=>n!=="code"),o=M.sanitizeMarkdownHtml(i,{dompurifyConfig:e.dompurifyConfig,componentTags:t});if(typeof document>"u")return o?[c.h("div",null,o)]:[];const u=document.createElement("div");u.innerHTML=o;const f=e.streamStatus??"done";return Array.from(u.childNodes).map(n=>p(n,{components:e.components,streamStatus:f,enableAnimation:e.enableAnimation,animationConfig:e.animationConfig})).filter(n=>n!=null).map(n=>typeof n=="string"?c.h("span",null,n):n)}exports.htmlToVNodes=_;