PageSourceSearch

https://exploremydata.com/assets/xmlFormat-EhR5zpat.js

js exploremydata.com collected 2026-09-25 20:07:55 UTC 4,609 bytes, 7 lines download raw bytes

1import{emptyPreview as x,textBlob as $,replaceExtension as b,stripBom as w}from"./util-CkZ8KZK2.js";const y=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),m=new Set(["pre","textarea","script","style"]);function C(t){const o=[];let c=0;for(;c<t.length;){const i=t.indexOf("<",c);if(i===-1){const e=t.slice(c);e.trim().length>0&&o.push({kind:"text",text:e});break}if(i>c){const e=t.slice(c,i);e.trim().length>0&&o.push({kind:"text",text:e})}if(t.startsWith("<!--",i)){const e=t.indexOf("-->",i+4),s=e===-1?t.length:e+3;o.push({kind:"comment",text:t.slice(i,s)}),c=s;continue}if(t.startsWith("<![CDATA[",i)){const e=t.indexOf("]]>",i+9),s=e===-1?t.length:e+3;o.push({kind:"cdata",text:t.slice(i,s)}),c=s;continue}if(t.startsWith("<?",i)){const e=t.indexOf("?>",i+2),s=e===-1?t.length:e+2;o.push({kind:"declaration",text:t.slice(i,s)}),c=s;continue}if(t.startsWith("<!",i)){const e=t.indexOf(">",i+2),s=e===-1?t.length:e+1;o.push({kind:"doctype",text:t.slice(i,s)}),c=s;continue}let r=i+1,n=null;for(;r<t.length;){const e=t[r];if(n)e===n&&(n=null);else if(e==='"'||e==="'")n=e;else if(e===">")break;r+=1}const a=t.slice(i,Math.min(r+1,t.length));c=r+1;const u=/^<\/?\s*([A-Za-z_:][\w.:-]*)/.exec(a),h=(u==null?void 0:u[1])??"";a.startsWith("</")?o.push({kind:"close",text:a,name:h}):a.endsWith("/>")||y.has(h.toLowerCase())?o.push({kind:"selfClosing",text:a,name:h,attributes:g(a)}):o.push({kind:"open",text:a,name:h,attributes:g(a)})}return o}function g(t){const o=t.replace(/^<\/?\s*[A-Za-z_:][\w.:-]*/,"").replace(/\/?>$/,""),c=[],i=/([^\s=/]+)(?:\s*=\s*("(?:[^"]*)"|'(?:[^']*)'|[^\s>]+))?/g;for(const r of o.matchAll(i))c.push({name:r[1],value:r[2]??""});return c}function k(t,o,c){if(!o.attributePerLine||!t.attributes||t.attributes.length<2)return t.text;const i=t.kind==="selfClosing"&&t.text.endsWith("/>")?" />":">",r=[`<${t.name}`];for(const n of t.attributes)r.push(`${c}${o.indent}${n.name}${n.value?`=${n.value}`:""}`);return r.push(`${c}${i.trim()}`),r.join(`
2`)}function E(t,o){const c=w(t).trim();if(c.length===0)throw new Error("There is nothing to format. The input is empty.");if(!c.includes("<"))throw new Error("That does not contain a single tag, so it is not XML or HTML.");const i=C(c),r=i.filter(e=>e.kind==="open"||e.kind==="selfClosing").length;if(o.mode==="minify"){const e=[];for(const s of i)if(!(s.kind==="comment"&&!o.keepComments)){if(s.kind==="text"){const f=s.text.replace(/\s+/g," ").trim();f.length>0&&e.push(f);continue}e.push(s.text.replace(/\s+/g," ").replace(/\s+>/,">").replace(/\s+\/>/,"/>"))}return{text:`${e.join("")}
3`,elements:r}}const n=[];let a=0,u=0;const h=[];for(let e=0;e<i.length;e+=1){const s=i[e];if(s.kind==="comment"&&!o.keepComments)continue;if(u>0){if(s.kind==="close"&&m.has((s.name??"").toLowerCase())){u-=1,a=Math.max(0,a-1),h.pop(),n[n.length-1]=`${n[n.length-1]}${s.text}`;continue}n[n.length-1]=`${n[n.length-1]}${s.text}`;continue}const f=o.indent.repeat(a);if(s.kind==="close"){a=Math.max(0,a-1),h.pop();const d=o.indent.repeat(a),l=i[e-1],p=i[e-2];if((l==null?void 0:l.kind)==="text"&&(p==null?void 0:p.kind)==="open"&&p.name===s.name&&!l.text.includes(`
4`)){n[n.length-1]=`${n[n.length-1]}${s.text}`;continue}n.push(`${d}${s.text}`);continue}if(s.kind==="text"){const d=i[e-1],l=i[e+1],p=s.text.replace(/\s+/g," ").trim();if(p.length===0)continue;if((d==null?void 0:d.kind)==="open"&&(l==null?void 0:l.kind)==="close"&&d.name===l.name){n[n.length-1]=`${n[n.length-1]}${p}`;continue}n.push(`${f}${p}`);continue}if(s.kind==="open"){n.push(`${f}${k(s,o,f)}`),h.push(s.name??""),a+=1,m.has((s.name??"").toLowerCase())&&(u+=1);continue}n.push(`${f}${k(s,o,f)}`)}return{text:`${n.join(`
5`)}
6`,elements:r}}const T=async t=>{t.ctx.onProgress("Reading the markup…");const o=typeof t.text=="string"?t.text:t.file?await t.file.text():"",c=t.options.mode==="minify"?"minify":"pretty",i=t.options.indent==="tab"?"	":t.options.indent==="4"?"    ":"  ";t.ctx.onProgress(c==="minify"?"Minifying…":"Formatting…");const r=E(o,{mode:c,indent:i,keepComments:t.options.keepComments!=="no",attributePerLine:t.options.attributePerLine==="yes"}),n=o.trimStart().toLowerCase().startsWith("<!doctype html")?"html":"xml";return{status:"ok",output:{filename:b(t.filename,n),blob:$(r.text,n==="html"?"text/html":"application/xml"),text:r.text,copyKind:"text",previewText:r.text,preview:x(),summary:[c==="minify"?"minified":"pretty printed",`${r.elements} element${r.elements===1?"":"s"}`,`${r.text.split(`
7`).length-1} lines`]}}};export{T as default,E as formatXml,g as parseAttributes,C as tokenizeXml};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.