Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save revelt/a450c0a4ebd0c4ad8bb736b0329352bb to your computer and use it in GitHub Desktop.
Save revelt/a450c0a4ebd0c4ad8bb736b0329352bb to your computer and use it in GitHub Desktop.
/**
* @name string-strip-html
* @fileoverview Strips HTML tags from strings. No parser, accepts mixed sources.
* @version 8.2.9
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/string-strip-html/}
*/
var ie=Object.create,w=Object.defineProperty,oe=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,re=Object.getOwnPropertyNames,ue=Object.getOwnPropertyDescriptor,Y=Object.getOwnPropertySymbols,ge=Object.prototype.propertyIsEnumerable;var z=(n,r,c)=>r in n?w(n,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):n[r]=c,L=(n,r)=>{for(var c in r||(r={}))V.call(r,c)&&z(n,c,r[c]);if(Y)for(var c of Y(r))ge.call(r,c)&&z(n,c,r[c]);return n},K=n=>w(n,"__esModule",{value:!0});var $e=(n,r)=>{for(var c in r)w(n,c,{get:r[c],enumerable:!0})},me=(n,r,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let O of re(r))!V.call(n,O)&&O!=="default"&&w(n,O,{get:()=>r[O],enumerable:!(c=ue(r,O))||c.enumerable});return n},C=n=>me(K(w(n!=null?ie(oe(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);K(exports);$e(exports,{defaults:()=>v,stripHtml:()=>ne,version:()=>be});var R=C(require("lodash.isplainobject")),q=C(require("lodash.trim")),X=C(require("lodash.without")),D=C(require("html-entities")),ee=C(require("ranges-apply")),te=C(require("ranges-push")),_=C(require("string-left-right"));function Q(n){return/[-_A-Za-z0-9]/.test(n)}function U(n,r){if(!n)return[];if(Array.isArray(n))return n.filter(c=>typeof c=="string"&&c.trim());if(typeof n=="string")return n.trim()?[n]:[];throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_03] ${r} must be array containing zero or more strings or something falsey. Currently it's equal to: ${n}, that a type of ${typeof n}.`)}function ce(n,r,c,O){for(let k=r,J=n.length;k<J;k++){if(n.startsWith(c,k))return!0;if(n.startsWith(O,k))return!1}return!1}function x(n,r,c){return!n||!n.quotes||!ce(r,c+1,n.quotes.value,">")}var Z="8.2.9";var be=Z,v={ignoreTags:[],onlyStripTags:[],stripTogetherWithTheirContents:["script","style","xml"],skipHtmlDecoding:!1,trimOnlySpaces:!1,dumpLinkHrefsNearby:{enabled:!1,putOnNewLine:!1,wrapHeads:"",wrapTails:""},cb:null};function ne(n,r){let c=Date.now(),O=new Set(["!doctype","abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"]),k=new Set(["a","b","i","p","q","s","u"]),J=new Set([".",",","?",";",")","\u2026",'"',"\xBB"]),b=[],f=[],g=[],e={};function le(){e={attributes:[]}}le();let S=null,N=null,l={},h={tagName:"",hrefValue:"",openingTagEnds:void 0},d="",W=!1,B=null;function se(t){return t!=null}function ae(t){return typeof t=="string"}function P(t,u,s){if(""+t,""+JSON.stringify(u.stripTogetherWithTheirContents,null,0)+e.name,Array.isArray(u.stripTogetherWithTheirContents)&&(u.stripTogetherWithTheirContents.includes(e.name)||u.stripTogetherWithTheirContents.includes("*")))if(""+`[${33}mrangedOpeningTags[${39}m`+JSON.stringify(b,null,4),Array.isArray(b)&&b.some(i=>i.name===e.name&&i.lastClosingBracketAt<t)){""+31+39;for(let i=b.length;i--;)if(b[i].name===e.name){""+JSON.stringify(s.current(),null,0),""+b[i].lastOpeningBracketAt+t,""+`[${33}mrangedOpeningTags[${39}m`+JSON.stringify(b,null,4),(u.stripTogetherWithTheirContents.includes(e.name)||u.stripTogetherWithTheirContents.includes("*"))&&(""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4),g=g.filter(([p,m])=>(p<b[i].lastOpeningBracketAt||p>=t+1)&&(m<=b[i].lastOpeningBracketAt||m>t+1)),""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4));let o=t+1;e.lastClosingBracketAt&&(o=e.lastClosingBracketAt+1),""+`[${32}mPUSH[${39}m`+b[i].lastOpeningBracketAt+o,g.push([b[i].lastOpeningBracketAt,o]),J.has(n[t])&&u.cb?u.cb({tag:e,deleteFrom:b[i].lastOpeningBracketAt,deleteTo:t+1,insert:null,rangesArr:s,proposedReturn:[b[i].lastOpeningBracketAt,t,null]}):u.cb&&u.cb({tag:e,deleteFrom:b[i].lastOpeningBracketAt,deleteTo:t,insert:"",rangesArr:s,proposedReturn:[b[i].lastOpeningBracketAt,t,""]}),b.splice(i,1),""+33+39+JSON.stringify(b,null,4);break}}else""+31+39,b.push(e),""+33+39+JSON.stringify(b,null,4)}function H(t,u,s,i,o,p){""+35+39,""+`[${33}mcurrCharIdx[${39}m`+JSON.stringify(u,null,0)+`[${33}mstr2[currCharIdx][${39}m`+JSON.stringify(t[u],null,0)+`[${33}mstr2[tag.leftOuterWhitespace][${39}m`+JSON.stringify(t[e.leftOuterWhitespace],null,0)+`[${33}mstr2[tag.leftOuterWhitespace - 1][${39}m`+JSON.stringify(t[e.leftOuterWhitespace-1],null,0)+`[${33}mfromIdx[${39}m`+JSON.stringify(s,null,0)+`[${33}mtoIdx[${39}m`+JSON.stringify(i,null,0);let m="";if(Number.isInteger(s)&&s<o&&(m+=t.slice(s,o),""+JSON.stringify(m,null,0)+m.length+s+o),Number.isInteger(i)&&i>p+1){let y=t.slice(p+1,i);y.includes(`
`)&&A(i,t)?m+=" ":m+=y,""+JSON.stringify(m,null,0)+m.length+(p+1)+i}if(""+JSON.stringify(m,null,0)+m.length,!J.has(t[u])&&t[u]!=="!"){let y=m.match(/\n/g);return Array.isArray(y)&&y.length?y.length===1?`
`:y.length===2?`
`:`
`:" "}return""}function I(t){if(t.dumpLinkHrefsNearby.enabled&&h.tagName&&h.tagName===e.name&&e.lastOpeningBracketAt&&(h.openingTagEnds&&e.lastOpeningBracketAt>h.openingTagEnds||!h.openingTagEnds)&&(W=!0,""+W),W){let u=t.dumpLinkHrefsNearby.putOnNewLine?`
`:"";d=`${u}${h.hrefValue}${u}`,""+d}}function A(t,u){return u?u[t]==="<"&&u[t+1]!=="%":n[t]==="<"&&n[t+1]!=="%"}function E(t){return n[t]===">"&&n[t-1]!=="%"}if(typeof n!="string")throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_01] Input must be string! Currently it's: ${(typeof n).toLowerCase()}, equal to:
${JSON.stringify(n,null,4)}`);if(r&&!(0,R.default)(r))throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_02] Optional Options Object must be a plain object! Currently it's: ${(typeof r).toLowerCase()}, equal to:
${JSON.stringify(r,null,4)}`);function F(){W&&(h={tagName:"",hrefValue:"",openingTagEnds:void 0},W=!1)}let a=L(L({},v),r);if(Object.prototype.hasOwnProperty.call(a,"returnRangesOnly"))throw new TypeError("string-strip-html/stripHtml(): [THROW_ID_03] opts.returnRangesOnly has been removed from the API since v.5 release.");a.ignoreTags=U(a.ignoreTags,"opts.ignoreTags"),a.onlyStripTags=U(a.onlyStripTags,"opts.onlyStripTags");let M=!!a.onlyStripTags.length;if(a.onlyStripTags.length&&a.ignoreTags.length&&(a.onlyStripTags=(0,X.default)(a.onlyStripTags,...a.ignoreTags)),(0,R.default)(a.dumpLinkHrefsNearby)||(a.dumpLinkHrefsNearby=L({},v.dumpLinkHrefsNearby)),a.dumpLinkHrefsNearby=v.dumpLinkHrefsNearby,r&&Object.prototype.hasOwnProperty.call(r,"dumpLinkHrefsNearby")&&se(r.dumpLinkHrefsNearby)){if((0,R.default)(r.dumpLinkHrefsNearby))a.dumpLinkHrefsNearby=L(L({},v.dumpLinkHrefsNearby),r.dumpLinkHrefsNearby);else if(r.dumpLinkHrefsNearby)throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_04] Optional Options Object's key dumpLinkHrefsNearby was set to ${typeof r.dumpLinkHrefsNearby}, equal to ${JSON.stringify(r.dumpLinkHrefsNearby,null,4)}. The only allowed value is a plain object. See the API reference.`)}a.stripTogetherWithTheirContents?typeof a.stripTogetherWithTheirContents=="string"&&a.stripTogetherWithTheirContents.length&&(a.stripTogetherWithTheirContents=[a.stripTogetherWithTheirContents]):a.stripTogetherWithTheirContents=[];let j={};if(a.stripTogetherWithTheirContents&&Array.isArray(a.stripTogetherWithTheirContents)&&a.stripTogetherWithTheirContents.length&&!a.stripTogetherWithTheirContents.every((t,u)=>typeof t!="string"?(j.el=t,j.i=u,!1):!0))throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_05] Optional Options Object's key stripTogetherWithTheirContents was set to contain not just string elements! For example, element at index ${j.i} has a value ${j.el} which is not string but ${(typeof j.el).toLowerCase()}.`);""+typeof a.cb,a.cb||(a.cb=({rangesArr:t,proposedReturn:u})=>{u&&t.push(...u)}),""+`[${33}mopts[${39}m`+JSON.stringify(a,null,4)+`[${33}minput[${39}m`+n;let $=new te.Ranges({limitToBeAddedWhitespace:!0,limitLinebreaksCount:2});if(!a.skipHtmlDecoding)for(;n!==(0,D.decode)(n,{scope:"strict"});)n=(0,D.decode)(n,{scope:"strict"});for(let t=0,u=n.length;t<u;t++){if(""+36+39+35+`str[ ${t} ] = ${`[${31}m${n[t]&&n[t].trim()===""?n[t]===null?"null":n[t]===`
`?"line break":n[t]===" "?"tab":"space":n[t]}[${39}m`}`+39+36+39,Object.keys(e).length>1&&e.lastClosingBracketAt&&e.lastClosingBracketAt<t&&n[t]!==" "&&B===null&&(B=t),E(t)&&(!e||Object.keys(e).length<2)&&t>1){for(let s=t;s--;)if(""+35+`str[${s}] = ${n[s]}`+39,n[s-1]===void 0||E(s)){let i=n[s-1]===void 0?s:s+1,o=n.slice(i,t+1);if(""+`[${31}m${o}[${39}m`,""+(0,q.default)(o.trim().split(/\s+/).filter(p=>p.trim()).filter((p,m)=>m===0),"/>"),n!==`<${(0,q.default)(o.trim(),"/>")}>`&&[...O].some(p=>(0,q.default)(o.trim().split(/\s+/).filter(m=>m.trim()).filter((m,y)=>y===0),"/>").toLowerCase()===p)&&ne(`<${o.trim()}>`,a).result===""){(!f.length||f[f.length-1][0]!==e.lastOpeningBracketAt)&&(f.push([i,t+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(e.lastClosingBracketAt+1)),(!g.length||g[g.length-1][0]!==e.lastOpeningBracketAt)&&(g.push([i,t+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(e.lastClosingBracketAt+1));let p=H(n,t,i,t+1,i,t+1);""+33+`SUBMIT RANGE #3: [${i}, ${t+1}, "${p}"]`+39;let m=t+1;if(n[m]&&!n[m].trim()){for(let y=m;y<u;y++)if(n[y].trim()){m=y;break}}""+i+m+p,a.cb({tag:e,deleteFrom:i,deleteTo:m,insert:p,rangesArr:$,proposedReturn:[i,m,p]})}break}}if(n[t]==="/"&&!(e.quotes&&e.quotes.value)&&Number.isInteger(e.lastOpeningBracketAt)&&!Number.isInteger(e.lastClosingBracketAt)&&(""+33+39,e.slashPresent=t),n[t]==='"'||n[t]==="'")if(e.nameStarts&&e.quotes&&e.quotes.value&&e.quotes.value===n[t]){l.valueEnds=t,l.value=n.slice(l.valueStarts,t),""+`[${33}mattrObj[${39}m`+JSON.stringify(l,null,4),e.attributes.push(l),l={},e.quotes=void 0;let s;a.dumpLinkHrefsNearby.enabled&&e.attributes.some(i=>{if(i.name&&i.name.toLowerCase()==="href")return s=`${a.dumpLinkHrefsNearby.wrapHeads||""}${i.value}${a.dumpLinkHrefsNearby.wrapTails||""}`,!0})&&(h={tagName:e.name,hrefValue:s,openingTagEnds:void 0},""+`[${32}mSET[${39}m`+`[${33}mhrefDump[${39}m`+JSON.stringify(h,null,4))}else!e.quotes&&e.nameStarts&&(""+`[${32}mSET[${39}m`+n[t]+t,e.quotes={},e.quotes.value=n[t],e.quotes.start=t,l.nameStarts&&l.nameEnds&&l.nameEnds<t&&l.nameStarts<t&&!l.valueStarts&&(l.name=n.slice(l.nameStarts,l.nameEnds),""+`[${32}mSET[${39}m`+`[${33}mattrObj[${39}m`+JSON.stringify(l,null,4)));if(e.nameStarts!==void 0&&e.nameEnds===void 0&&(!n[t].trim()||!Q(n[t]))){if(e.nameEnds=t,""+`[${32}mSET[${39}m`+33+39+e.nameEnds,e.name=n.slice(e.nameStarts,e.nameEnds+(!E(t)&&n[t]!=="/"&&n[t+1]===void 0?1:0)),""+`[${32}mSET[${39}m`+33+39+e.name,""+`[${33}mtag[${39}m`+JSON.stringify(e,null,4),n[e.nameStarts-1]!=="!"&&!e.name.replace(/-/g,"").length||/^\d+$/.test(e.name[0])){e={};continue}if(A(t)){I(a),""+`[${33}mstringToInsertAfter[${39}m`+JSON.stringify(d,null,4);let s=H(n,t,e.leftOuterWhitespace,t,e.lastOpeningBracketAt,t);""+33+`cb()-PUSH: [${e.leftOuterWhitespace}, ${t}, "${s}${d}${s}"]`+39,""+`[${33}mtag[${39}m`+JSON.stringify(e,null,4),(a.stripTogetherWithTheirContents.includes(e.name)||a.stripTogetherWithTheirContents.includes("*"))&&(""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4),g=g.filter(([i,o])=>!(i===e.leftOuterWhitespace&&o===t)),""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4)),a.cb({tag:e,deleteFrom:e.leftOuterWhitespace,deleteTo:t,insert:`${s}${d}${s}`,rangesArr:$,proposedReturn:[e.leftOuterWhitespace,t,`${s}${d}${s}`]}),F(),P(t,a,$)}}if(e.quotes&&e.quotes.start&&e.quotes.start<t&&!e.quotes.end&&l.nameEnds&&l.equalsAt&&!l.valueStarts&&(""+`[${32}mSET[${39}m`+33+39+l.valueStarts,l.valueStarts=t),!e.quotes&&l.nameEnds&&n[t]==="="&&!l.valueStarts&&!l.equalsAt&&(l.equalsAt=t,""+`[${32}mSET[${39}m`+33+39+l.equalsAt),!e.quotes&&l.nameStarts&&l.nameEnds&&!l.valueStarts&&n[t].trim()&&n[t]!=="="&&(e.attributes.push(l),l={}),!e.quotes&&l.nameStarts&&!l.nameEnds&&(n[t].trim()?n[t]==="="?l.equalsAt||(l.nameEnds=t,""+`[${32}mSET[${39}m`+`[${33}mattrObj.nameEnds[${39}m`+JSON.stringify(l.nameEnds,null,4),l.equalsAt=t,""+`[${32}mSET[${39}m`+`[${33}mattrObj.equalsAt[${39}m`+JSON.stringify(l.equalsAt,null,4),l.name=n.slice(l.nameStarts,l.nameEnds)):n[t]==="/"||E(t)?(""+`[${32}mSET[${39}m`+`[${33}mattrObj.nameEnds[${39}m`+JSON.stringify(l.nameEnds,null,4),l.nameEnds=t,l.name=n.slice(l.nameStarts,l.nameEnds),""+33+39,e.attributes.push(l),l={}):A(t)&&(""+33+39+`[${31}mTODO[${39}m`,l.nameEnds=t,l.name=n.slice(l.nameStarts,l.nameEnds),e.attributes.push(l),l={}):(l.nameEnds=t,""+`[${32}mSET[${39}m`+`[${33}mattrObj.nameEnds[${39}m`+JSON.stringify(l.nameEnds,null,4),l.name=n.slice(l.nameStarts,l.nameEnds))),!e.quotes&&e.nameEnds<t&&!n[t-1].trim()&&n[t].trim()&&!"<>/!".includes(n[t])&&!l.nameStarts&&!e.lastClosingBracketAt&&(l.nameStarts=t,""+`[${32}mSET[${39}m`+33+39+l.nameStarts),e.lastOpeningBracketAt!==null&&e.lastOpeningBracketAt<t&&n[t]==="/"&&e.onlyPlausible&&(e.onlyPlausible=!1),e.lastOpeningBracketAt!==null&&e.lastOpeningBracketAt<t&&n[t]!=="/"&&(e.onlyPlausible===void 0&&((!n[t].trim()||A(t))&&!e.slashPresent?e.onlyPlausible=!0:e.onlyPlausible=!1,""+`[${32}mSET[${39}m`+33+39+e.onlyPlausible),n[t].trim()&&e.nameStarts===void 0&&!A(t)&&n[t]!=="/"&&!E(t)&&n[t]!=="!"&&(e.nameStarts=t,e.nameContainsLetters=!1,""+33+39+e.nameStarts)),e.nameStarts&&!e.quotes&&n[t].toLowerCase()!==n[t].toUpperCase()&&(e.nameContainsLetters=!0),E(t)&&x(e,n,t)&&!0&&e.lastOpeningBracketAt!==void 0&&(e.lastClosingBracketAt=t,""+`[${32}mSET[${39}m`+e.lastClosingBracketAt,B=null,Object.keys(l).length&&(""+`[${32}mPUSH[${39}m`+33+39,e.attributes.push(l),l={}),a.dumpLinkHrefsNearby.enabled&&h.tagName&&!h.openingTagEnds&&(h.openingTagEnds=t,""+`[${32}mSET[${39}m`+`[${33}mhrefDump[${39}m`+JSON.stringify(h,null,4))),e.lastOpeningBracketAt!==void 0){if(""+`[${33}mtag.lastClosingBracketAt[${39}m`+JSON.stringify(e.lastClosingBracketAt,null,4),e.lastClosingBracketAt===void 0){if(e.lastOpeningBracketAt<t&&!A(t)&&(n[t+1]===void 0||A(t+1))&&e.nameContainsLetters){if(""+n[t+1],e.name=n.slice(e.nameStarts,e.nameEnds?e.nameEnds:t+1).toLowerCase(),""+`[${32}mSET[${39}m`+`[${33}mtag.name[${39}m`+JSON.stringify(e.name,null,4),(!f.length||f[f.length-1][0]!==e.lastOpeningBracketAt)&&(f.push([e.lastOpeningBracketAt,t+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(t+1)),a.ignoreTags.includes(e.name)||e.onlyPlausible&&!O.has(e.name)){""+31+39,e={},l={};continue}if((O.has(e.name)||k.has(e.name))&&(e.onlyPlausible===!1||e.onlyPlausible===!0&&e.attributes.length)||n[t+1]===void 0){I(a),""+`[${33}mstringToInsertAfter[${39}m`+JSON.stringify(d,null,4);let s=H(n,t,e.leftOuterWhitespace,t+1,e.lastOpeningBracketAt,e.lastClosingBracketAt);""+33+`cb()-PUSH: [${e.leftOuterWhitespace}, ${t+1}, "${s}${d}${s}"]`+39,""+`[${33}mtag[${39}m`+JSON.stringify(e,null,4),a.cb({tag:e,deleteFrom:e.leftOuterWhitespace,deleteTo:t+1,insert:`${s}${d}${s}`,rangesArr:$,proposedReturn:[e.leftOuterWhitespace,t+1,`${s}${d}${s}`]}),F(),P(t,a,$)}if(!g.length||g[g.length-1][0]!==e.lastOpeningBracketAt&&g[g.length-1][1]!==t+1)if(a.stripTogetherWithTheirContents.includes(e.name)||a.stripTogetherWithTheirContents.includes("*")){""+`[${33}mrangedOpeningTags[${39}m`+JSON.stringify(b,null,4);let s;for(let i=b.length;i--;)b[i].name===e.name&&(s=b[i],""+`[${32}mSET[${39}m`+`[${33}mlastRangedOpeningTag[${39}m`+JSON.stringify(s,null,4));s?(""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4),g=g.filter(([i])=>i!==s.lastOpeningBracketAt),""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4),g.push([s.lastOpeningBracketAt,t+1]),""+`[${32}mPUSH[${39}m`+s.lastOpeningBracketAt+(t+1)):(g.push([e.lastOpeningBracketAt,t+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(t+1))}else g.push([e.lastOpeningBracketAt,t+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(t+1)}}else if(t>e.lastClosingBracketAt&&n[t].trim()||n[t+1]===void 0){let s=e.lastClosingBracketAt===t?t+1:t;if(""+`[${33}mendingRangeIndex[${39}m`+JSON.stringify(s,null,4),a.trimOnlySpaces&&s===u-1&&B!==null&&B<t&&(s=B),""+`[${33}mtag.name[${39}m`+JSON.stringify(e.name,null,4),(!f.length||f[f.length-1][0]!==e.lastOpeningBracketAt)&&(f.push([e.lastOpeningBracketAt,e.lastClosingBracketAt+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(e.lastClosingBracketAt+1)),!M&&a.ignoreTags.includes(e.name)||M&&!a.onlyStripTags.includes(e.name))a.cb({tag:e,deleteFrom:null,deleteTo:null,insert:null,rangesArr:$,proposedReturn:null}),""+31+39,e={},l={};else if(!e.onlyPlausible||e.attributes.length===0&&e.name&&(O.has(e.name.toLowerCase())||k.has(e.name.toLowerCase()))||e.attributes&&e.attributes.some(i=>i.equalsAt)){(!g.length||g[g.length-1][0]!==e.lastOpeningBracketAt)&&(g.push([e.lastOpeningBracketAt,e.lastClosingBracketAt+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(e.lastClosingBracketAt+1));let i=H(n,t,e.leftOuterWhitespace,s,e.lastOpeningBracketAt,e.lastClosingBracketAt);""+`[${33}mwhiteSpaceCompensation[${39}m`+JSON.stringify(i,null,4)+i.length,d="",W=!1,I(a),""+`[${33}mstringToInsertAfter[${39}m`+JSON.stringify(d,null,4);let o;ae(d)&&d.length?(o=`${i}${d}${i===`
`?`
`:i}`,""+`[${32}mSET[${39}m`+`[${33}minsert[${39}m`+JSON.stringify(o,null,4)):(o=i,""+`[${32}mSET[${39}m`+`[${33}minsert[${39}m`+JSON.stringify(o,null,4)),(e.leftOuterWhitespace===0||!(0,_.right)(n,s-1))&&(o="",""+`[${32}mSET[${39}m`+`[${33}minsert[${39}m`+JSON.stringify(o,null,4)),""+33+`cb()-SUBMIT RANGE #2: [${e.leftOuterWhitespace}, ${s}, ${JSON.stringify(o,null,0)}]`+39,a.cb({tag:e,deleteFrom:e.leftOuterWhitespace,deleteTo:s,insert:o,rangesArr:$,proposedReturn:[e.leftOuterWhitespace,s,o]}),F(),P(t,a,$)}else""+33+39,e={};E(t)||(""+33+39,e={})}}if(A(t)&&!A(t-1)&&!`'"`.includes(n[t+1])&&(!`'"`.includes(n[t+2])||/\w/.test(n[t+1]))&&!(n[t+1]==="c"&&n[t+2]===":")&&!(n[t+1]==="f"&&n[t+2]==="m"&&n[t+3]==="t"&&n[t+4]===":")&&!(n[t+1]==="s"&&n[t+2]==="q"&&n[t+3]==="l"&&n[t+4]===":")&&!(n[t+1]==="x"&&n[t+2]===":")&&!(n[t+1]==="f"&&n[t+2]==="n"&&n[t+3]===":")&&x(e,n,t)){if(E((0,_.right)(n,t)))continue;if(""+!!e.nameEnds+(e.nameEnds<t)+!e.lastClosingBracketAt,e.nameEnds&&e.nameEnds<t&&!e.lastClosingBracketAt&&(""+!!e.onlyPlausible+!O.has(e.name)+!k.has(e.name)+!(e.attributes&&e.attributes.length),e.onlyPlausible===!0&&e.attributes&&e.attributes.length||e.onlyPlausible===!1)){let s=H(n,t,e.leftOuterWhitespace,t,e.lastOpeningBracketAt,t);""+e.leftOuterWhitespace+t+s,a.cb({tag:e,deleteFrom:e.leftOuterWhitespace,deleteTo:t,insert:s,rangesArr:$,proposedReturn:[e.leftOuterWhitespace,t,s]}),P(t,a,$),e={},l={}}if(e.lastOpeningBracketAt!==void 0&&e.onlyPlausible&&e.name&&!e.quotes&&(""+`[${31}mRESET[${39}m`,e.lastOpeningBracketAt=void 0,e.name=void 0,e.onlyPlausible=!1,""+`[${33}mtag[${39}m`+JSON.stringify(e,null,4)),(e.lastOpeningBracketAt===void 0||!e.onlyPlausible)&&!e.quotes&&(e.lastOpeningBracketAt=t,e.slashPresent=!1,e.attributes=[],S===null?e.leftOuterWhitespace=t:a.trimOnlySpaces&&S===0?e.leftOuterWhitespace=N||t:e.leftOuterWhitespace=S,""+`[${32}mSET[${39}m`+33+39+e.leftOuterWhitespace+33+39+e.lastOpeningBracketAt+33+39,`${n[t+1]}${n[t+2]}${n[t+3]}`=="!--"||`${n[t+1]}${n[t+2]}${n[t+3]}${n[t+4]}${n[t+5]}${n[t+6]}${n[t+7]}${n[t+8]}`=="![CDATA[")){""+31+39;let s=!0;n[t+2]==="-"&&(s=!1);let i;for(let o=t;o<u;o++)if(""+`[${33}m${`str[${o}]`}[${39}m`+n[o],(!i&&s&&`${n[o-2]}${n[o-1]}${n[o]}`=="]]>"||!s&&`${n[o-2]}${n[o-1]}${n[o]}`=="-->")&&(i=o,""+i),i&&(i<o&&n[o].trim()||n[o+1]===void 0)){let p=o;(n[o+1]===void 0&&!n[o].trim()||n[o]===">")&&(p+=1),(!f.length||f[f.length-1][0]!==e.lastOpeningBracketAt)&&(f.push([e.lastOpeningBracketAt,i+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(i+1)),(!g.length||g[g.length-1][0]!==e.lastOpeningBracketAt)&&(g.push([e.lastOpeningBracketAt,i+1]),""+`[${32}mPUSH[${39}m`+e.lastOpeningBracketAt+(i+1));let m=H(n,o,e.leftOuterWhitespace,p,e.lastOpeningBracketAt,i);""+e.leftOuterWhitespace+p+m,a.cb({tag:e,deleteFrom:e.leftOuterWhitespace,deleteTo:p,insert:m,rangesArr:$,proposedReturn:[e.leftOuterWhitespace,p,m]}),t=o-1,n[o]===">"&&(t=o),e={},l={};break}}}n[t].trim()?S!==null&&(!e.quotes&&l.equalsAt>S-1&&l.nameEnds&&l.equalsAt>l.nameEnds&&n[t]!=='"'&&n[t]!=="'"&&((0,R.default)(l)&&(""+`[${33}mattrObj[${39}m`+JSON.stringify(l,null,4),e.attributes.push(l)),l={},e.equalsSpottedAt=void 0),S=null,""+`[${32}mSET[${39}m`+33+39+S):S===null&&(S=t,""+`[${32}mSET[${39}m`+33+39+S,e.lastOpeningBracketAt!==void 0&&e.lastOpeningBracketAt<t&&e.nameStarts&&e.nameStarts<e.lastOpeningBracketAt&&t===e.lastOpeningBracketAt+1&&!b.some(s=>s.name===e.name)&&(""+31+39,e.onlyPlausible=!0,e.name=void 0,e.nameStarts=void 0)),n[t]===" "?N===null&&(N=t,""+`[${32}mSET[${39}m`+33+39+N):N!==null&&(N=null,""+`[${32}mSET[${39}m`+33+39+N),""+32+39,""+`[${33}mrangedOpeningTags[${39}m`+JSON.stringify(b,null,4),""+`[${33}mfilteredTagLocations[${39}m`+JSON.stringify(g,null,4),""+`[${33}mspacesChunkWhichFollowsTheClosingBracketEndsAt[${39}m`+JSON.stringify(B,null,4),""+`[${33}mhrefDump[${39}m`+JSON.stringify(h,null,4),""+`[${33}mattrObj[${39}m`+JSON.stringify(l,null,4),""+(Object.keys(e).length?`${`[${35}mtag[${39}m`} = ${Object.keys(e).map(s=>`${`[${90}m${`[${7}m${s}[${27}m`}[${39}m`} ${`[${90}m: ${(0,R.default)(e[s])||Array.isArray(e[s])?JSON.stringify(e[s],null,4):e[s]}[${39}m`}`).join(`,
`)}
`:"")+($.current()?`RANGES: ${JSON.stringify($.current(),null,0)}`:"")}if(n&&(a.trimOnlySpaces&&n[0]===" "||!a.trimOnlySpaces&&!n[0].trim()))for(let t=0,u=n.length;t<u;t++)if(a.trimOnlySpaces&&n[t]!==" "||!a.trimOnlySpaces&&n[t].trim()){""+t,$.push([0,t]);break}else n[t+1]||(""+(t+1),$.push([0,t+1]));if(n&&(a.trimOnlySpaces&&n[n.length-1]===" "||!a.trimOnlySpaces&&!n[n.length-1].trim())){for(let t=n.length;t--;)if(a.trimOnlySpaces&&n[t]!==" "||!a.trimOnlySpaces&&n[t].trim()){""+n.length,$.push([t+1,n.length]);break}}let T=$.current();if((!r||!r.cb)&&T){if(T[0]&&!T[0][0]){""+`[${33}mthe first range[${39}m`+JSON.stringify(T[0],null,4);let t=T[0][1];""+`[${33}mstartingIdx[${39}m`+JSON.stringify(t,null,4),$.ranges[0]=[$.ranges[0][0],$.ranges[0][1]]}if(T[T.length-1]&&T[T.length-1][1]===n.length){""+`[${33}mthe last range[${39}m`+JSON.stringify(T[T.length-1],null,4)+n.length;let t=T[T.length-1][0];if(""+`[${33}mstartingIdx[${39}m`+JSON.stringify(t,null,4),$.ranges){let u=$.ranges[$.ranges.length-1][0];n[u-1]&&(a.trimOnlySpaces&&n[u-1]===" "||!a.trimOnlySpaces&&!n[u-1].trim())&&(u-=1);let s=$.ranges[$.ranges.length-1][2];$.ranges[$.ranges.length-1]=[u,$.ranges[$.ranges.length-1][1]],s&&s.trim()&&$.ranges[$.ranges.length-1].push(s.trimEnd())}}}let G={log:{timeTakenInMilliseconds:Date.now()-c},result:(0,ee.rApply)(n,$.current()),ranges:$.current(),allTagLocations:f,filteredTagLocations:g};return""+`[${32}mFINAL RESULT[${39}m`+JSON.stringify(G,null,4),G}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment