Created
April 3, 2021 11:24
-
-
Save revelt/93334d0b11aa40f4a1a0b8f2b394ad48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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 __create = Object.create; | |
var __defProp = Object.defineProperty; | |
var __getProtoOf = Object.getPrototypeOf; | |
var __hasOwnProp = Object.prototype.hasOwnProperty; | |
var __getOwnPropNames = Object.getOwnPropertyNames; | |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | |
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | |
var __propIsEnum = Object.prototype.propertyIsEnumerable; | |
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value; | |
var __assign = (a, b) => { | |
for (var prop in b || (b = {})) | |
if (__hasOwnProp.call(b, prop)) | |
__defNormalProp(a, prop, b[prop]); | |
if (__getOwnPropSymbols) | |
for (var prop of __getOwnPropSymbols(b)) { | |
if (__propIsEnum.call(b, prop)) | |
__defNormalProp(a, prop, b[prop]); | |
} | |
return a; | |
}; | |
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true}); | |
var __export = (target, all) => { | |
for (var name in all) | |
__defProp(target, name, {get: all[name], enumerable: true}); | |
}; | |
var __exportStar = (target, module2, desc) => { | |
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | |
for (let key of __getOwnPropNames(module2)) | |
if (!__hasOwnProp.call(target, key) && key !== "default") | |
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable}); | |
} | |
return target; | |
}; | |
var __toModule = (module2) => { | |
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2); | |
}; | |
// src/main.ts | |
__markAsModule(exports); | |
__export(exports, { | |
defaults: () => defaults, | |
stripHtml: () => stripHtml, | |
version: () => version2 | |
}); | |
var import_lodash = __toModule(require("lodash.isplainobject")); | |
var import_lodash2 = __toModule(require("lodash.trim")); | |
var import_lodash3 = __toModule(require("lodash.without")); | |
var import_html_entities = __toModule(require("html-entities")); | |
var import_ranges_apply = __toModule(require("ranges-apply")); | |
var import_ranges_push = __toModule(require("ranges-push")); | |
var import_string_left_right = __toModule(require("string-left-right")); | |
// src/util.ts | |
function characterSuitableForNames(char) { | |
return /[-_A-Za-z0-9]/.test(char); | |
} | |
function prepHopefullyAnArray(something, name) { | |
if (!something) { | |
return []; | |
} | |
if (Array.isArray(something)) { | |
return something.filter((val) => typeof val === "string" && val.trim()); | |
} | |
if (typeof something === "string") { | |
return something.trim() ? [something] : []; | |
} | |
throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_03] ${name} must be array containing zero or more strings or something falsey. Currently it's equal to: ${something}, that a type of ${typeof something}.`); | |
} | |
function xBeforeYOnTheRight(str, startingIdx, x, y) { | |
for (let i = startingIdx, len = str.length; i < len; i++) { | |
if (str.startsWith(x, i)) { | |
return true; | |
} | |
if (str.startsWith(y, i)) { | |
return false; | |
} | |
} | |
return false; | |
} | |
function notWithinAttrQuotes(tag, str, i) { | |
return !tag || !tag.quotes || !xBeforeYOnTheRight(str, i + 1, tag.quotes.value, ">"); | |
} | |
// package.json | |
var version = "8.2.9"; | |
// src/main.ts | |
var version2 = version; | |
var defaults = { | |
ignoreTags: [], | |
onlyStripTags: [], | |
stripTogetherWithTheirContents: ["script", "style", "xml"], | |
skipHtmlDecoding: false, | |
trimOnlySpaces: false, | |
dumpLinkHrefsNearby: { | |
enabled: false, | |
putOnNewLine: false, | |
wrapHeads: "", | |
wrapTails: "" | |
}, | |
cb: null | |
}; | |
function stripHtml(str, originalOpts) { | |
const start = Date.now(); | |
const definitelyTagNames = 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" | |
]); | |
const singleLetterTags = new Set(["a", "b", "i", "p", "q", "s", "u"]); | |
const punctuation = new Set([ | |
".", | |
",", | |
"?", | |
";", | |
")", | |
"\u2026", | |
'"', | |
"\xBB" | |
]); | |
const rangedOpeningTags = []; | |
const allTagLocations = []; | |
let filteredTagLocations = []; | |
let tag = {}; | |
function resetTag() { | |
tag = {attributes: []}; | |
} | |
resetTag(); | |
let chunkOfWhitespaceStartsAt = null; | |
let chunkOfSpacesStartsAt = null; | |
let attrObj = {}; | |
let hrefDump = { | |
tagName: "", | |
hrefValue: "", | |
openingTagEnds: void 0 | |
}; | |
let stringToInsertAfter = ""; | |
let hrefInsertionActive = false; | |
let spacesChunkWhichFollowsTheClosingBracketEndsAt = null; | |
function existy(x) { | |
return x != null; | |
} | |
function isStr(something) { | |
return typeof something === "string"; | |
} | |
function treatRangedTags(i, opts2, rangesToDelete2) { | |
/* @__PURE__ */ console.log(`281 treatRangedTags(${i}) called`); | |
/* @__PURE__ */ console.log(`283 opts.stripTogetherWithTheirContents = ${JSON.stringify(opts2.stripTogetherWithTheirContents, null, 0)}; tag.name = ${tag.name}`); | |
if (Array.isArray(opts2.stripTogetherWithTheirContents) && (opts2.stripTogetherWithTheirContents.includes(tag.name) || opts2.stripTogetherWithTheirContents.includes("*"))) { | |
/* @__PURE__ */ console.log(`302 FIY, ${`[${33}m${`rangedOpeningTags`}[${39}m`} = ${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
if (Array.isArray(rangedOpeningTags) && rangedOpeningTags.some((obj) => obj.name === tag.name && obj.lastClosingBracketAt < i)) { | |
/* @__PURE__ */ console.log(`316 [${31}m${`treatRangedTags():`}[${39}m closing ranged tag`); | |
for (let y = rangedOpeningTags.length; y--; ) { | |
if (rangedOpeningTags[y].name === tag.name) { | |
/* @__PURE__ */ console.log(`rangesToDelete.current(): ${JSON.stringify(rangesToDelete2.current(), null, 0)}`); | |
/* @__PURE__ */ console.log(`343 ABOUT TO cb()-PUSH RANGE: [${rangedOpeningTags[y].lastOpeningBracketAt}, ${i}]`); | |
/* @__PURE__ */ console.log(`351 FIY, ${`[${33}m${`rangedOpeningTags`}[${39}m`} = ${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
if (opts2.stripTogetherWithTheirContents.includes(tag.name) || opts2.stripTogetherWithTheirContents.includes("*")) { | |
/* @__PURE__ */ console.log(`364 ${`[${33}m${`filteredTagLocations`}[${39}m`} BEFORE: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
filteredTagLocations = filteredTagLocations.filter(([from, upto]) => (from < rangedOpeningTags[y].lastOpeningBracketAt || from >= i + 1) && (upto <= rangedOpeningTags[y].lastOpeningBracketAt || upto > i + 1)); | |
/* @__PURE__ */ console.log(`378 ${`[${33}m${`filteredTagLocations`}[${39}m`} AFTER: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
} | |
let endingIdx = i + 1; | |
if (tag.lastClosingBracketAt) { | |
endingIdx = tag.lastClosingBracketAt + 1; | |
} | |
/* @__PURE__ */ console.log(`392 ${`[${32}m${`PUSH`}[${39}m`} [${rangedOpeningTags[y].lastOpeningBracketAt}, ${endingIdx}] to filteredTagLocations`); | |
filteredTagLocations.push([ | |
rangedOpeningTags[y].lastOpeningBracketAt, | |
endingIdx | |
]); | |
if (punctuation.has(str[i]) && opts2.cb) { | |
opts2.cb({ | |
tag, | |
deleteFrom: rangedOpeningTags[y].lastOpeningBracketAt, | |
deleteTo: i + 1, | |
insert: null, | |
rangesArr: rangesToDelete2, | |
proposedReturn: [ | |
rangedOpeningTags[y].lastOpeningBracketAt, | |
i, | |
null | |
] | |
}); | |
} else if (opts2.cb) { | |
opts2.cb({ | |
tag, | |
deleteFrom: rangedOpeningTags[y].lastOpeningBracketAt, | |
deleteTo: i, | |
insert: "", | |
rangesArr: rangesToDelete2, | |
proposedReturn: [ | |
rangedOpeningTags[y].lastOpeningBracketAt, | |
i, | |
"" | |
] | |
}); | |
} | |
rangedOpeningTags.splice(y, 1); | |
/* @__PURE__ */ console.log(`438 new [${33}m${`rangedOpeningTags`}[${39}m = ${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
break; | |
} | |
} | |
} else { | |
/* @__PURE__ */ console.log(`451 [${31}m${`treatRangedTags():`}[${39}m opening ranged tag`); | |
rangedOpeningTags.push(tag); | |
/* @__PURE__ */ console.log(`455 pushed tag{} to [${33}m${`rangedOpeningTags`}[${39}m | |
which is now equal to: | |
${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
} | |
} | |
} | |
function calculateWhitespaceToInsert(str2, currCharIdx, fromIdx, toIdx, lastOpeningBracketAt, lastClosingBracketAt) { | |
/* @__PURE__ */ console.log(`474 [${35}m${`calculateWhitespaceToInsert() called`}[${39}m`); | |
/* @__PURE__ */ console.log(`477 calculateWhitespaceToInsert(): ${`[${33}m${`currCharIdx`}[${39}m`} = ${JSON.stringify(currCharIdx, null, 0)}; ${`[${33}m${`str2[currCharIdx]`}[${39}m`} = ${JSON.stringify(str2[currCharIdx], null, 0)}; ${`[${33}m${`str2[tag.leftOuterWhitespace]`}[${39}m`} = ${JSON.stringify(str2[tag.leftOuterWhitespace], null, 0)}; ${`[${33}m${`str2[tag.leftOuterWhitespace - 1]`}[${39}m`} = ${JSON.stringify(str2[tag.leftOuterWhitespace - 1], null, 0)}; ${`[${33}m${`fromIdx`}[${39}m`} = ${JSON.stringify(fromIdx, null, 0)}; ${`[${33}m${`toIdx`}[${39}m`} = ${JSON.stringify(toIdx, null, 0)}`); | |
let strToEvaluateForLineBreaks = ""; | |
if (Number.isInteger(fromIdx) && fromIdx < lastOpeningBracketAt) { | |
strToEvaluateForLineBreaks += str2.slice(fromIdx, lastOpeningBracketAt); | |
/* @__PURE__ */ console.log(`513 strToEvaluateForLineBreaks = ${JSON.stringify(strToEvaluateForLineBreaks, null, 0)} (length ${strToEvaluateForLineBreaks.length}; sliced [${fromIdx}, ${lastOpeningBracketAt}])`); | |
} | |
if (Number.isInteger(toIdx) && toIdx > lastClosingBracketAt + 1) { | |
const temp = str2.slice(lastClosingBracketAt + 1, toIdx); | |
if (temp.includes("\n") && isOpeningAt(toIdx, str2)) { | |
strToEvaluateForLineBreaks += " "; | |
} else { | |
strToEvaluateForLineBreaks += temp; | |
} | |
/* @__PURE__ */ console.log(`535 strToEvaluateForLineBreaks = ${JSON.stringify(strToEvaluateForLineBreaks, null, 0)} (length ${strToEvaluateForLineBreaks.length}; sliced [${lastClosingBracketAt + 1}, ${toIdx}])`); | |
} | |
/* @__PURE__ */ console.log(`545 strToEvaluateForLineBreaks = ${JSON.stringify(strToEvaluateForLineBreaks, null, 0)} (length ${strToEvaluateForLineBreaks.length})`); | |
if (!punctuation.has(str2[currCharIdx]) && str2[currCharIdx] !== "!") { | |
const foundLineBreaks = strToEvaluateForLineBreaks.match(/\n/g); | |
if (Array.isArray(foundLineBreaks) && foundLineBreaks.length) { | |
if (foundLineBreaks.length === 1) { | |
return "\n"; | |
} | |
if (foundLineBreaks.length === 2) { | |
return "\n\n"; | |
} | |
return "\n\n\n"; | |
} | |
return " "; | |
} | |
return ""; | |
} | |
function calculateHrefToBeInserted(opts2) { | |
if (opts2.dumpLinkHrefsNearby.enabled && hrefDump.tagName && hrefDump.tagName === tag.name && tag.lastOpeningBracketAt && (hrefDump.openingTagEnds && tag.lastOpeningBracketAt > hrefDump.openingTagEnds || !hrefDump.openingTagEnds)) { | |
hrefInsertionActive = true; | |
/* @__PURE__ */ console.log(`582 calculateHrefToBeInserted(): hrefInsertionActive = "${hrefInsertionActive}"`); | |
} | |
if (hrefInsertionActive) { | |
const lineBreaks = opts2.dumpLinkHrefsNearby.putOnNewLine ? "\n\n" : ""; | |
stringToInsertAfter = `${lineBreaks}${hrefDump.hrefValue}${lineBreaks}`; | |
/* @__PURE__ */ console.log(`590 calculateHrefToBeInserted(): stringToInsertAfter = ${stringToInsertAfter}`); | |
} | |
} | |
function isOpeningAt(i, customStr) { | |
if (customStr) { | |
return customStr[i] === "<" && customStr[i + 1] !== "%"; | |
} | |
return str[i] === "<" && str[i + 1] !== "%"; | |
} | |
function isClosingAt(i) { | |
return str[i] === ">" && str[i - 1] !== "%"; | |
} | |
if (typeof str !== "string") { | |
throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_01] Input must be string! Currently it's: ${(typeof str).toLowerCase()}, equal to: | |
${JSON.stringify(str, null, 4)}`); | |
} | |
if (originalOpts && !(0, import_lodash.default)(originalOpts)) { | |
throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_02] Optional Options Object must be a plain object! Currently it's: ${(typeof originalOpts).toLowerCase()}, equal to: | |
${JSON.stringify(originalOpts, null, 4)}`); | |
} | |
function resetHrefMarkers() { | |
if (hrefInsertionActive) { | |
hrefDump = { | |
tagName: "", | |
hrefValue: "", | |
openingTagEnds: void 0 | |
}; | |
hrefInsertionActive = false; | |
} | |
} | |
const opts = __assign(__assign({}, defaults), originalOpts); | |
if (Object.prototype.hasOwnProperty.call(opts, "returnRangesOnly")) { | |
throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_03] opts.returnRangesOnly has been removed from the API since v.5 release.`); | |
} | |
opts.ignoreTags = prepHopefullyAnArray(opts.ignoreTags, "opts.ignoreTags"); | |
opts.onlyStripTags = prepHopefullyAnArray(opts.onlyStripTags, "opts.onlyStripTags"); | |
const onlyStripTagsMode = !!opts.onlyStripTags.length; | |
if (opts.onlyStripTags.length && opts.ignoreTags.length) { | |
opts.onlyStripTags = (0, import_lodash3.default)(opts.onlyStripTags, ...opts.ignoreTags); | |
} | |
if (!(0, import_lodash.default)(opts.dumpLinkHrefsNearby)) { | |
opts.dumpLinkHrefsNearby = __assign({}, defaults.dumpLinkHrefsNearby); | |
} | |
opts.dumpLinkHrefsNearby = defaults.dumpLinkHrefsNearby; | |
if (originalOpts && Object.prototype.hasOwnProperty.call(originalOpts, "dumpLinkHrefsNearby") && existy(originalOpts.dumpLinkHrefsNearby)) { | |
if ((0, import_lodash.default)(originalOpts.dumpLinkHrefsNearby)) { | |
opts.dumpLinkHrefsNearby = __assign(__assign({}, defaults.dumpLinkHrefsNearby), originalOpts.dumpLinkHrefsNearby); | |
} else if (originalOpts.dumpLinkHrefsNearby) { | |
throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_04] Optional Options Object's key dumpLinkHrefsNearby was set to ${typeof originalOpts.dumpLinkHrefsNearby}, equal to ${JSON.stringify(originalOpts.dumpLinkHrefsNearby, null, 4)}. The only allowed value is a plain object. See the API reference.`); | |
} | |
} | |
if (!opts.stripTogetherWithTheirContents) { | |
opts.stripTogetherWithTheirContents = []; | |
} else if (typeof opts.stripTogetherWithTheirContents === "string" && opts.stripTogetherWithTheirContents.length) { | |
opts.stripTogetherWithTheirContents = [opts.stripTogetherWithTheirContents]; | |
} | |
const somethingCaught = {}; | |
if (opts.stripTogetherWithTheirContents && Array.isArray(opts.stripTogetherWithTheirContents) && opts.stripTogetherWithTheirContents.length && !opts.stripTogetherWithTheirContents.every((el, i) => { | |
if (!(typeof el === "string")) { | |
somethingCaught.el = el; | |
somethingCaught.i = i; | |
return false; | |
} | |
return true; | |
})) { | |
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 ${somethingCaught.i} has a value ${somethingCaught.el} which is not string but ${(typeof somethingCaught.el).toLowerCase()}.`); | |
} | |
/* @__PURE__ */ console.log(`730 opts.cb type = ${typeof opts.cb}`); | |
if (!opts.cb) { | |
opts.cb = ({rangesArr, proposedReturn}) => { | |
if (proposedReturn) { | |
rangesArr.push(...proposedReturn); | |
} | |
}; | |
} | |
/* @__PURE__ */ console.log(`740 string-strip-html: final ${`[${33}m${`opts`}[${39}m`} = ${JSON.stringify(opts, null, 4)}; ${`[${33}m${`input`}[${39}m`} = "${str}"`); | |
const rangesToDelete = new import_ranges_push.Ranges({ | |
limitToBeAddedWhitespace: true, | |
limitLinebreaksCount: 2 | |
}); | |
if (!opts.skipHtmlDecoding) { | |
while (str !== (0, import_html_entities.decode)(str, {scope: "strict"})) { | |
str = (0, import_html_entities.decode)(str, {scope: "strict"}); | |
} | |
} | |
for (let i = 0, len = str.length; i < len; i++) { | |
/* @__PURE__ */ console.log(`[${36}m${`===============================`}[${39}m [${35}m${`str[ ${i} ] = ${`[${31}m${str[i] && str[i].trim() === "" ? str[i] === null ? "null" : str[i] === "\n" ? "line break" : str[i] === " " ? "tab" : "space" : str[i]}[${39}m`}`}[${39}m [${36}m${`===============================`}[${39}m`); | |
if (Object.keys(tag).length > 1 && tag.lastClosingBracketAt && tag.lastClosingBracketAt < i && str[i] !== " " && spacesChunkWhichFollowsTheClosingBracketEndsAt === null) { | |
spacesChunkWhichFollowsTheClosingBracketEndsAt = i; | |
} | |
if (isClosingAt(i)) { | |
/* @__PURE__ */ console.log(`801 closing bracket caught`); | |
if ((!tag || Object.keys(tag).length < 2) && i > 1) { | |
/* @__PURE__ */ console.log("804 TRAVERSE BACKWARDS"); | |
for (let y = i; y--; ) { | |
/* @__PURE__ */ console.log(`[${35}m${`str[${y}] = ${str[y]}`}[${39}m`); | |
if (str[y - 1] === void 0 || isClosingAt(y)) { | |
/* @__PURE__ */ console.log("810 BREAK"); | |
const startingPoint = str[y - 1] === void 0 ? y : y + 1; | |
const culprit = str.slice(startingPoint, i + 1); | |
/* @__PURE__ */ console.log(`815 CULPRIT: "${`[${31}m${culprit}[${39}m`}"`); | |
/* @__PURE__ */ console.log(`825 "${(0, import_lodash2.default)(culprit.trim().split(/\s+/).filter((val2) => val2.trim()).filter((_val3, i3) => i3 === 0), "/>")}"`); | |
if (str !== `<${(0, import_lodash2.default)(culprit.trim(), "/>")}>` && [...definitelyTagNames].some((val) => (0, import_lodash2.default)(culprit.trim().split(/\s+/).filter((val2) => val2.trim()).filter((_val3, i3) => i3 === 0), "/>").toLowerCase() === val) && stripHtml(`<${culprit.trim()}>`, opts).result === "") { | |
if (!allTagLocations.length || allTagLocations[allTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
allTagLocations.push([startingPoint, i + 1]); | |
/* @__PURE__ */ console.log(`858 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${tag.lastClosingBracketAt + 1}] to allTagLocations`); | |
} | |
if (!filteredTagLocations.length || filteredTagLocations[filteredTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
filteredTagLocations.push([startingPoint, i + 1]); | |
/* @__PURE__ */ console.log(`872 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${tag.lastClosingBracketAt + 1}] to filteredTagLocations`); | |
} | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, i, startingPoint, i + 1, startingPoint, i + 1); | |
/* @__PURE__ */ console.log(`887 [${33}m${`SUBMIT RANGE #3: [${startingPoint}, ${i + 1}, "${whiteSpaceCompensation}"]`}[${39}m`); | |
let deleteUpTo = i + 1; | |
if (str[deleteUpTo] && !str[deleteUpTo].trim()) { | |
for (let z = deleteUpTo; z < len; z++) { | |
if (str[z].trim()) { | |
deleteUpTo = z; | |
break; | |
} | |
} | |
} | |
/* @__PURE__ */ console.log(`901 cb()-PUSHING [${startingPoint}, ${deleteUpTo}, "${whiteSpaceCompensation}"]`); | |
opts.cb({ | |
tag, | |
deleteFrom: startingPoint, | |
deleteTo: deleteUpTo, | |
insert: whiteSpaceCompensation, | |
rangesArr: rangesToDelete, | |
proposedReturn: [ | |
startingPoint, | |
deleteUpTo, | |
whiteSpaceCompensation | |
] | |
}); | |
} | |
break; | |
} | |
} | |
} | |
} | |
if (str[i] === "/" && !(tag.quotes && tag.quotes.value) && Number.isInteger(tag.lastOpeningBracketAt) && !Number.isInteger(tag.lastClosingBracketAt)) { | |
/* @__PURE__ */ console.log(`930 [${33}m${`tag.slashPresent`}[${39}m = true`); | |
tag.slashPresent = i; | |
} | |
if (str[i] === '"' || str[i] === "'") { | |
if (tag.nameStarts && tag.quotes && tag.quotes.value && tag.quotes.value === str[i]) { | |
attrObj.valueEnds = i; | |
attrObj.value = str.slice(attrObj.valueStarts, i); | |
/* @__PURE__ */ console.log(`947 PUSHING ${`[${33}m${`attrObj`}[${39}m`} = ${JSON.stringify(attrObj, null, 4)}`); | |
tag.attributes.push(attrObj); | |
attrObj = {}; | |
tag.quotes = void 0; | |
let hrefVal; | |
if (opts.dumpLinkHrefsNearby.enabled && tag.attributes.some((obj) => { | |
if (obj.name && obj.name.toLowerCase() === "href") { | |
hrefVal = `${opts.dumpLinkHrefsNearby.wrapHeads || ""}${obj.value}${opts.dumpLinkHrefsNearby.wrapTails || ""}`; | |
return true; | |
} | |
})) { | |
hrefDump = { | |
tagName: tag.name, | |
hrefValue: hrefVal, | |
openingTagEnds: void 0 | |
}; | |
/* @__PURE__ */ console.log(`978 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`hrefDump`}[${39}m`} = ${JSON.stringify(hrefDump, null, 4)}`); | |
} | |
} else if (!tag.quotes && tag.nameStarts) { | |
/* @__PURE__ */ console.log(`988 ${`[${32}m${`SET`}[${39}m`} tag.quotes = {}, tag.quotes.value = ${str[i]}, tag.quotes.start = ${i}`); | |
tag.quotes = {}; | |
tag.quotes.value = str[i]; | |
tag.quotes.start = i; | |
if (attrObj.nameStarts && attrObj.nameEnds && attrObj.nameEnds < i && attrObj.nameStarts < i && !attrObj.valueStarts) { | |
attrObj.name = str.slice(attrObj.nameStarts, attrObj.nameEnds); | |
/* @__PURE__ */ console.log(`1005 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`attrObj`}[${39}m`} = ${JSON.stringify(attrObj, null, 4)}`); | |
} | |
} | |
} | |
if (tag.nameStarts !== void 0 && tag.nameEnds === void 0 && (!str[i].trim() || !characterSuitableForNames(str[i]))) { | |
tag.nameEnds = i; | |
/* @__PURE__ */ console.log(`1025 ${`[${32}m${`SET`}[${39}m`} [${33}m${`tag.nameEnds`}[${39}m = ${tag.nameEnds}`); | |
tag.name = str.slice(tag.nameStarts, tag.nameEnds + (!isClosingAt(i) && str[i] !== "/" && str[i + 1] === void 0 ? 1 : 0)); | |
/* @__PURE__ */ console.log(`1039 ${`[${32}m${`SET`}[${39}m`} [${33}m${`tag.name`}[${39}m = ${tag.name}`); | |
/* @__PURE__ */ console.log(`1045 ${`[${33}m${`tag`}[${39}m`} is currently = ${JSON.stringify(tag, null, 4)}`); | |
if (str[tag.nameStarts - 1] !== "!" && !tag.name.replace(/-/g, "").length || /^\d+$/.test(tag.name[0])) { | |
tag = {}; | |
continue; | |
} | |
if (isOpeningAt(i)) { | |
/* @__PURE__ */ console.log(`1065 opening bracket caught`); | |
calculateHrefToBeInserted(opts); | |
/* @__PURE__ */ console.log(`1069 ${`[${33}m${`stringToInsertAfter`}[${39}m`} = ${JSON.stringify(stringToInsertAfter, null, 4)}`); | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, i, tag.leftOuterWhitespace, i, tag.lastOpeningBracketAt, i); | |
/* @__PURE__ */ console.log(`1093 [${33}m${`cb()-PUSH: [${tag.leftOuterWhitespace}, ${i}, "${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}"]`}[${39}m`); | |
/* @__PURE__ */ console.log(`1096 ${`[${33}m${`tag`}[${39}m`} = ${JSON.stringify(tag, null, 4)}`); | |
if (opts.stripTogetherWithTheirContents.includes(tag.name) || opts.stripTogetherWithTheirContents.includes("*")) { | |
/* @__PURE__ */ console.log(`1110 ${`[${33}m${`filteredTagLocations`}[${39}m`} BEFORE: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
filteredTagLocations = filteredTagLocations.filter(([from, upto]) => !(from === tag.leftOuterWhitespace && upto === i)); | |
/* @__PURE__ */ console.log(`1121 ${`[${33}m${`filteredTagLocations`}[${39}m`} AFTER: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
} | |
opts.cb({ | |
tag, | |
deleteFrom: tag.leftOuterWhitespace, | |
deleteTo: i, | |
insert: `${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}`, | |
rangesArr: rangesToDelete, | |
proposedReturn: [ | |
tag.leftOuterWhitespace, | |
i, | |
`${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}` | |
] | |
}); | |
resetHrefMarkers(); | |
treatRangedTags(i, opts, rangesToDelete); | |
} | |
} | |
if (tag.quotes && tag.quotes.start && tag.quotes.start < i && !tag.quotes.end && attrObj.nameEnds && attrObj.equalsAt && !attrObj.valueStarts) { | |
/* @__PURE__ */ console.log(`1167 ${`[${32}m${`SET`}[${39}m`} [${33}m${`attrObj.valueStarts`}[${39}m = ${attrObj.valueStarts}`); | |
attrObj.valueStarts = i; | |
} | |
if (!tag.quotes && attrObj.nameEnds && str[i] === "=" && !attrObj.valueStarts && !attrObj.equalsAt) { | |
attrObj.equalsAt = i; | |
/* @__PURE__ */ console.log(`1185 ${`[${32}m${`SET`}[${39}m`} [${33}m${`attrObj.equalsAt`}[${39}m = ${attrObj.equalsAt}`); | |
} | |
if (!tag.quotes && attrObj.nameStarts && attrObj.nameEnds && !attrObj.valueStarts && str[i].trim() && str[i] !== "=") { | |
tag.attributes.push(attrObj); | |
/* @__PURE__ */ console.log("1208 PUSHED attrObj into tag.attributes, reset attrObj"); | |
attrObj = {}; | |
} | |
if (!tag.quotes && attrObj.nameStarts && !attrObj.nameEnds) { | |
/* @__PURE__ */ console.log("1215"); | |
if (!str[i].trim()) { | |
attrObj.nameEnds = i; | |
/* @__PURE__ */ console.log(`1219 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`attrObj.nameEnds`}[${39}m`} = ${JSON.stringify(attrObj.nameEnds, null, 4)}`); | |
attrObj.name = str.slice(attrObj.nameStarts, attrObj.nameEnds); | |
} else if (str[i] === "=") { | |
/* @__PURE__ */ console.log(`1227 equal char clauses`); | |
if (!attrObj.equalsAt) { | |
/* @__PURE__ */ console.log(`1230 equal hasn't been met`); | |
attrObj.nameEnds = i; | |
/* @__PURE__ */ console.log(`1233 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`attrObj.nameEnds`}[${39}m`} = ${JSON.stringify(attrObj.nameEnds, null, 4)}`); | |
attrObj.equalsAt = i; | |
/* @__PURE__ */ console.log(`1241 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`attrObj.equalsAt`}[${39}m`} = ${JSON.stringify(attrObj.equalsAt, null, 4)}`); | |
attrObj.name = str.slice(attrObj.nameStarts, attrObj.nameEnds); | |
} | |
} else if (str[i] === "/" || isClosingAt(i)) { | |
/* @__PURE__ */ console.log(`1251 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`attrObj.nameEnds`}[${39}m`} = ${JSON.stringify(attrObj.nameEnds, null, 4)}`); | |
attrObj.nameEnds = i; | |
attrObj.name = str.slice(attrObj.nameStarts, attrObj.nameEnds); | |
/* @__PURE__ */ console.log(`1260 [${33}m${`PUSH attrObj and wipe`}[${39}m`); | |
tag.attributes.push(attrObj); | |
attrObj = {}; | |
} else if (isOpeningAt(i)) { | |
/* @__PURE__ */ console.log(`1269 [${33}m${`ATTR NAME ENDS WITH NEW TAG`}[${39}m - ${`[${31}m${`TODO`}[${39}m`}`); | |
attrObj.nameEnds = i; | |
attrObj.name = str.slice(attrObj.nameStarts, attrObj.nameEnds); | |
tag.attributes.push(attrObj); | |
attrObj = {}; | |
} | |
} | |
if (!tag.quotes && tag.nameEnds < i && !str[i - 1].trim() && str[i].trim() && !`<>/!`.includes(str[i]) && !attrObj.nameStarts && !tag.lastClosingBracketAt) { | |
attrObj.nameStarts = i; | |
/* @__PURE__ */ console.log(`1295 ${`[${32}m${`SET`}[${39}m`} [${33}m${`attrObj.nameStarts`}[${39}m = ${attrObj.nameStarts}`); | |
} | |
if (tag.lastOpeningBracketAt !== null && tag.lastOpeningBracketAt < i && str[i] === "/" && tag.onlyPlausible) { | |
tag.onlyPlausible = false; | |
} | |
if (tag.lastOpeningBracketAt !== null && tag.lastOpeningBracketAt < i && str[i] !== "/") { | |
if (tag.onlyPlausible === void 0) { | |
if ((!str[i].trim() || isOpeningAt(i)) && !tag.slashPresent) { | |
tag.onlyPlausible = true; | |
} else { | |
tag.onlyPlausible = false; | |
} | |
/* @__PURE__ */ console.log(`1327 ${`[${32}m${`SET`}[${39}m`} [${33}m${`tag.onlyPlausible`}[${39}m = ${tag.onlyPlausible}`); | |
} | |
if (str[i].trim() && tag.nameStarts === void 0 && !isOpeningAt(i) && str[i] !== "/" && !isClosingAt(i) && str[i] !== "!") { | |
tag.nameStarts = i; | |
tag.nameContainsLetters = false; | |
/* @__PURE__ */ console.log(`1345 [${33}m${`tag.nameStarts`}[${39}m = ${tag.nameStarts}`); | |
} | |
} | |
if (tag.nameStarts && !tag.quotes && str[i].toLowerCase() !== str[i].toUpperCase()) { | |
tag.nameContainsLetters = true; | |
} | |
if (isClosingAt(i) && notWithinAttrQuotes(tag, str, i)) { | |
const itIsClosing = true; | |
if (itIsClosing && tag.lastOpeningBracketAt !== void 0) { | |
tag.lastClosingBracketAt = i; | |
/* @__PURE__ */ console.log(`1381 ${`[${32}m${`SET`}[${39}m`} tag.lastClosingBracketAt = ${tag.lastClosingBracketAt}`); | |
spacesChunkWhichFollowsTheClosingBracketEndsAt = null; | |
if (Object.keys(attrObj).length) { | |
/* @__PURE__ */ console.log(`1390 ${`[${32}m${`PUSH`}[${39}m`} [${33}m${`attrObj`}[${39}m & reset`); | |
tag.attributes.push(attrObj); | |
attrObj = {}; | |
} | |
if (opts.dumpLinkHrefsNearby.enabled && hrefDump.tagName && !hrefDump.openingTagEnds) { | |
hrefDump.openingTagEnds = i; | |
/* @__PURE__ */ console.log(`1407 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`hrefDump`}[${39}m`} = ${JSON.stringify(hrefDump, null, 4)}`); | |
} | |
} | |
} | |
if (tag.lastOpeningBracketAt !== void 0) { | |
/* @__PURE__ */ console.log(`1422 opening bracket has been met`); | |
/* @__PURE__ */ console.log(`1424 FIY, ${`[${33}m${`tag.lastClosingBracketAt`}[${39}m`} = ${JSON.stringify(tag.lastClosingBracketAt, null, 4)}`); | |
if (tag.lastClosingBracketAt === void 0) { | |
/* @__PURE__ */ console.log(`1431 closing bracket hasn't been met`); | |
if (tag.lastOpeningBracketAt < i && !isOpeningAt(i) && (str[i + 1] === void 0 || isOpeningAt(i + 1)) && tag.nameContainsLetters) { | |
/* @__PURE__ */ console.log(`1438 str[i + 1] = ${str[i + 1]}`); | |
tag.name = str.slice(tag.nameStarts, tag.nameEnds ? tag.nameEnds : i + 1).toLowerCase(); | |
/* @__PURE__ */ console.log(`1445 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`tag.name`}[${39}m`} = ${JSON.stringify(tag.name, null, 4)}`); | |
if (!allTagLocations.length || allTagLocations[allTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
allTagLocations.push([tag.lastOpeningBracketAt, i + 1]); | |
/* @__PURE__ */ console.log(`1461 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${i + 1}] to allTagLocations`); | |
} | |
if (opts.ignoreTags.includes(tag.name) || tag.onlyPlausible && !definitelyTagNames.has(tag.name)) { | |
/* @__PURE__ */ console.log(`1474 Ignored tag - [${31}m${`WIPE AND RESET`}[${39}m`); | |
tag = {}; | |
attrObj = {}; | |
continue; | |
} | |
/* @__PURE__ */ console.log(`1484`); | |
if ((definitelyTagNames.has(tag.name) || singleLetterTags.has(tag.name)) && (tag.onlyPlausible === false || tag.onlyPlausible === true && tag.attributes.length) || str[i + 1] === void 0) { | |
calculateHrefToBeInserted(opts); | |
/* @__PURE__ */ console.log(`1494 ${`[${33}m${`stringToInsertAfter`}[${39}m`} = ${JSON.stringify(stringToInsertAfter, null, 4)}`); | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, i, tag.leftOuterWhitespace, i + 1, tag.lastOpeningBracketAt, tag.lastClosingBracketAt); | |
/* @__PURE__ */ console.log(`1511 [${33}m${`cb()-PUSH: [${tag.leftOuterWhitespace}, ${i + 1}, "${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}"]`}[${39}m`); | |
/* @__PURE__ */ console.log(`1516 ${`[${33}m${`tag`}[${39}m`} = ${JSON.stringify(tag, null, 4)}`); | |
opts.cb({ | |
tag, | |
deleteFrom: tag.leftOuterWhitespace, | |
deleteTo: i + 1, | |
insert: `${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}`, | |
rangesArr: rangesToDelete, | |
proposedReturn: [ | |
tag.leftOuterWhitespace, | |
i + 1, | |
`${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation}` | |
] | |
}); | |
resetHrefMarkers(); | |
treatRangedTags(i, opts, rangesToDelete); | |
} | |
/* @__PURE__ */ console.log(`1540`); | |
if (!filteredTagLocations.length || filteredTagLocations[filteredTagLocations.length - 1][0] !== tag.lastOpeningBracketAt && filteredTagLocations[filteredTagLocations.length - 1][1] !== i + 1) { | |
/* @__PURE__ */ console.log(`1550`); | |
if (opts.stripTogetherWithTheirContents.includes(tag.name) || opts.stripTogetherWithTheirContents.includes("*")) { | |
/* @__PURE__ */ console.log(`1559 FIY, ${`[${33}m${`rangedOpeningTags`}[${39}m`} = ${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
let lastRangedOpeningTag; | |
for (let z = rangedOpeningTags.length; z--; ) { | |
if (rangedOpeningTags[z].name === tag.name) { | |
lastRangedOpeningTag = rangedOpeningTags[z]; | |
/* @__PURE__ */ console.log(`1575 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`lastRangedOpeningTag`}[${39}m`} = ${JSON.stringify(lastRangedOpeningTag, null, 4)}`); | |
/* @__PURE__ */ console.log(`1581 BREAK`); | |
} | |
} | |
if (lastRangedOpeningTag) { | |
/* @__PURE__ */ console.log(`1588 ${`[${33}m${`filteredTagLocations`}[${39}m`} BEFORE: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
filteredTagLocations = filteredTagLocations.filter(([from]) => from !== lastRangedOpeningTag.lastOpeningBracketAt); | |
/* @__PURE__ */ console.log(`1598 ${`[${33}m${`filteredTagLocations`}[${39}m`} AFTER: ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
filteredTagLocations.push([ | |
lastRangedOpeningTag.lastOpeningBracketAt, | |
i + 1 | |
]); | |
/* @__PURE__ */ console.log(`1610 ${`[${32}m${`PUSH`}[${39}m`} [${lastRangedOpeningTag.lastOpeningBracketAt}, ${i + 1}] to filteredTagLocations`); | |
} else { | |
filteredTagLocations.push([tag.lastOpeningBracketAt, i + 1]); | |
/* @__PURE__ */ console.log(`1618 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${i + 1}] to filteredTagLocations`); | |
} | |
} else { | |
filteredTagLocations.push([tag.lastOpeningBracketAt, i + 1]); | |
/* @__PURE__ */ console.log(`1627 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${i + 1}] to filteredTagLocations`); | |
} | |
} | |
} | |
/* @__PURE__ */ console.log(`1634 end`); | |
} else if (i > tag.lastClosingBracketAt && str[i].trim() || str[i + 1] === void 0) { | |
/* @__PURE__ */ console.log(`1639 closing bracket has been met`); | |
let endingRangeIndex = tag.lastClosingBracketAt === i ? i + 1 : i; | |
/* @__PURE__ */ console.log(`1649 ${`[${33}m${`endingRangeIndex`}[${39}m`} = ${JSON.stringify(endingRangeIndex, null, 4)}`); | |
if (opts.trimOnlySpaces && endingRangeIndex === len - 1 && spacesChunkWhichFollowsTheClosingBracketEndsAt !== null && spacesChunkWhichFollowsTheClosingBracketEndsAt < i) { | |
endingRangeIndex = spacesChunkWhichFollowsTheClosingBracketEndsAt; | |
} | |
/* @__PURE__ */ console.log(`1670 ${`[${33}m${`tag.name`}[${39}m`} = ${JSON.stringify(tag.name, null, 4)}`); | |
if (!allTagLocations.length || allTagLocations[allTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
allTagLocations.push([ | |
tag.lastOpeningBracketAt, | |
tag.lastClosingBracketAt + 1 | |
]); | |
/* @__PURE__ */ console.log(`1689 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${tag.lastClosingBracketAt + 1}] to allTagLocations`); | |
} | |
if (!onlyStripTagsMode && opts.ignoreTags.includes(tag.name) || onlyStripTagsMode && !opts.onlyStripTags.includes(tag.name)) { | |
opts.cb({ | |
tag, | |
deleteFrom: null, | |
deleteTo: null, | |
insert: null, | |
rangesArr: rangesToDelete, | |
proposedReturn: null | |
}); | |
/* @__PURE__ */ console.log(`1713 Ignored tag - [${31}m${`WIPE AND RESET`}[${39}m`); | |
tag = {}; | |
attrObj = {}; | |
} else if (!tag.onlyPlausible || tag.attributes.length === 0 && tag.name && (definitelyTagNames.has(tag.name.toLowerCase()) || singleLetterTags.has(tag.name.toLowerCase())) || tag.attributes && tag.attributes.some((attrObj2) => attrObj2.equalsAt)) { | |
if (!filteredTagLocations.length || filteredTagLocations[filteredTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
filteredTagLocations.push([ | |
tag.lastOpeningBracketAt, | |
tag.lastClosingBracketAt + 1 | |
]); | |
/* @__PURE__ */ console.log(`1741 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${tag.lastClosingBracketAt + 1}] to filteredTagLocations`); | |
} | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, i, tag.leftOuterWhitespace, endingRangeIndex, tag.lastOpeningBracketAt, tag.lastClosingBracketAt); | |
/* @__PURE__ */ console.log(`1759 ${`[${33}m${`whiteSpaceCompensation`}[${39}m`} = ${JSON.stringify(whiteSpaceCompensation, null, 4)} (length: ${whiteSpaceCompensation.length})`); | |
stringToInsertAfter = ""; | |
hrefInsertionActive = false; | |
calculateHrefToBeInserted(opts); | |
/* @__PURE__ */ console.log(`1773 ${`[${33}m${`stringToInsertAfter`}[${39}m`} = ${JSON.stringify(stringToInsertAfter, null, 4)}`); | |
let insert; | |
if (isStr(stringToInsertAfter) && stringToInsertAfter.length) { | |
insert = `${whiteSpaceCompensation}${stringToInsertAfter}${whiteSpaceCompensation === "\n\n" ? "\n" : whiteSpaceCompensation}`; | |
/* @__PURE__ */ console.log(`1786 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`insert`}[${39}m`} = ${JSON.stringify(insert, null, 4)}`); | |
} else { | |
insert = whiteSpaceCompensation; | |
/* @__PURE__ */ console.log(`1795 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`insert`}[${39}m`} = ${JSON.stringify(insert, null, 4)}`); | |
} | |
if (tag.leftOuterWhitespace === 0 || !(0, import_string_left_right.right)(str, endingRangeIndex - 1)) { | |
insert = ""; | |
/* @__PURE__ */ console.log(`1809 ${`[${32}m${`SET`}[${39}m`} ${`[${33}m${`insert`}[${39}m`} = ${JSON.stringify(insert, null, 4)}`); | |
} | |
/* @__PURE__ */ console.log(`1819 [${33}m${`cb()-SUBMIT RANGE #2: [${tag.leftOuterWhitespace}, ${endingRangeIndex}, ${JSON.stringify(insert, null, 0)}]`}[${39}m`); | |
opts.cb({ | |
tag, | |
deleteFrom: tag.leftOuterWhitespace, | |
deleteTo: endingRangeIndex, | |
insert, | |
rangesArr: rangesToDelete, | |
proposedReturn: [tag.leftOuterWhitespace, endingRangeIndex, insert] | |
}); | |
resetHrefMarkers(); | |
treatRangedTags(i, opts, rangesToDelete); | |
} else { | |
/* @__PURE__ */ console.log(`1840 [${33}m${`RESET tag{}`}[${39}m`); | |
tag = {}; | |
} | |
if (!isClosingAt(i)) { | |
/* @__PURE__ */ console.log(`1846 [${33}m${`RESET tag{}`}[${39}m`); | |
tag = {}; | |
} | |
} | |
} | |
if (isOpeningAt(i) && !isOpeningAt(i - 1) && !`'"`.includes(str[i + 1]) && (!`'"`.includes(str[i + 2]) || /\w/.test(str[i + 1])) && !(str[i + 1] === "c" && str[i + 2] === ":") && !(str[i + 1] === "f" && str[i + 2] === "m" && str[i + 3] === "t" && str[i + 4] === ":") && !(str[i + 1] === "s" && str[i + 2] === "q" && str[i + 3] === "l" && str[i + 4] === ":") && !(str[i + 1] === "x" && str[i + 2] === ":") && !(str[i + 1] === "f" && str[i + 2] === "n" && str[i + 3] === ":") && notWithinAttrQuotes(tag, str, i)) { | |
/* @__PURE__ */ console.log(`1887 caught opening bracket`); | |
if (isClosingAt((0, import_string_left_right.right)(str, i))) { | |
/* @__PURE__ */ console.log(`1891 cases like <><><>`); | |
continue; | |
} else { | |
/* @__PURE__ */ console.log(`1894 opening brackets else clauses`); | |
/* @__PURE__ */ console.log(`1899 R1: ${!!tag.nameEnds}; R2: ${tag.nameEnds < i}; R3: ${!tag.lastClosingBracketAt}`); | |
if (tag.nameEnds && tag.nameEnds < i && !tag.lastClosingBracketAt) { | |
/* @__PURE__ */ console.log(`1904`); | |
/* @__PURE__ */ console.log(`1906 R1: ${!!tag.onlyPlausible}; R2: ${!definitelyTagNames.has(tag.name)}; R3: ${!singleLetterTags.has(tag.name)}; R4: ${!(tag.attributes && tag.attributes.length)}`); | |
if (tag.onlyPlausible === true && tag.attributes && tag.attributes.length || tag.onlyPlausible === false) { | |
/* @__PURE__ */ console.log(`1918`); | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, i, tag.leftOuterWhitespace, i, tag.lastOpeningBracketAt, i); | |
/* @__PURE__ */ console.log(`1930 cb()-PUSH range [${tag.leftOuterWhitespace}, ${i}, "${whiteSpaceCompensation}"]`); | |
opts.cb({ | |
tag, | |
deleteFrom: tag.leftOuterWhitespace, | |
deleteTo: i, | |
insert: whiteSpaceCompensation, | |
rangesArr: rangesToDelete, | |
proposedReturn: [ | |
tag.leftOuterWhitespace, | |
i, | |
whiteSpaceCompensation | |
] | |
}); | |
treatRangedTags(i, opts, rangesToDelete); | |
tag = {}; | |
attrObj = {}; | |
} | |
} | |
if (tag.lastOpeningBracketAt !== void 0 && tag.onlyPlausible && tag.name && !tag.quotes) { | |
/* @__PURE__ */ console.log(`1962 ${`[${31}m${`RESET`}[${39}m`} tag`); | |
tag.lastOpeningBracketAt = void 0; | |
tag.name = void 0; | |
tag.onlyPlausible = false; | |
/* @__PURE__ */ console.log(`1967 NOW ${`[${33}m${`tag`}[${39}m`} = ${JSON.stringify(tag, null, 4)}`); | |
} | |
if ((tag.lastOpeningBracketAt === void 0 || !tag.onlyPlausible) && !tag.quotes) { | |
tag.lastOpeningBracketAt = i; | |
tag.slashPresent = false; | |
tag.attributes = []; | |
if (chunkOfWhitespaceStartsAt === null) { | |
tag.leftOuterWhitespace = i; | |
} else if (opts.trimOnlySpaces && chunkOfWhitespaceStartsAt === 0) { | |
tag.leftOuterWhitespace = chunkOfSpacesStartsAt || i; | |
} else { | |
tag.leftOuterWhitespace = chunkOfWhitespaceStartsAt; | |
} | |
/* @__PURE__ */ console.log(`2003 ${`[${32}m${`SET`}[${39}m`} [${33}m${`tag.leftOuterWhitespace`}[${39}m = ${tag.leftOuterWhitespace}; [${33}m${`tag.lastOpeningBracketAt`}[${39}m = ${tag.lastOpeningBracketAt}; [${33}m${`tag.slashPresent`}[${39}m = false`); | |
if (`${str[i + 1]}${str[i + 2]}${str[i + 3]}` === "!--" || `${str[i + 1]}${str[i + 2]}${str[i + 3]}${str[i + 4]}${str[i + 5]}${str[i + 6]}${str[i + 7]}${str[i + 8]}` === "![CDATA[") { | |
/* @__PURE__ */ console.log(`2020 [${31}m${`\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588`}[${39}m`); | |
let cdata = true; | |
if (str[i + 2] === "-") { | |
cdata = false; | |
} | |
/* @__PURE__ */ console.log("2027 traversing forward"); | |
let closingFoundAt; | |
for (let y = i; y < len; y++) { | |
/* @__PURE__ */ console.log(`${`[${33}m${`str[${y}]`}[${39}m`} = ${str[y]}`); | |
if (!closingFoundAt && cdata && `${str[y - 2]}${str[y - 1]}${str[y]}` === "]]>" || !cdata && `${str[y - 2]}${str[y - 1]}${str[y]}` === "-->") { | |
closingFoundAt = y; | |
/* @__PURE__ */ console.log(`2040 closingFoundAt = ${closingFoundAt}`); | |
} | |
if (closingFoundAt && (closingFoundAt < y && str[y].trim() || str[y + 1] === void 0)) { | |
/* @__PURE__ */ console.log("2048 END detected"); | |
let rangeEnd = y; | |
if (str[y + 1] === void 0 && !str[y].trim() || str[y] === ">") { | |
rangeEnd += 1; | |
} | |
if (!allTagLocations.length || allTagLocations[allTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
allTagLocations.push([ | |
tag.lastOpeningBracketAt, | |
closingFoundAt + 1 | |
]); | |
/* @__PURE__ */ console.log(`2069 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${closingFoundAt + 1}] to allTagLocations`); | |
} | |
if (!filteredTagLocations.length || filteredTagLocations[filteredTagLocations.length - 1][0] !== tag.lastOpeningBracketAt) { | |
filteredTagLocations.push([ | |
tag.lastOpeningBracketAt, | |
closingFoundAt + 1 | |
]); | |
/* @__PURE__ */ console.log(`2086 ${`[${32}m${`PUSH`}[${39}m`} [${tag.lastOpeningBracketAt}, ${closingFoundAt + 1}] to filteredTagLocations`); | |
} | |
const whiteSpaceCompensation = calculateWhitespaceToInsert(str, y, tag.leftOuterWhitespace, rangeEnd, tag.lastOpeningBracketAt, closingFoundAt); | |
/* @__PURE__ */ console.log(`2101 cb()-PUSH range [${tag.leftOuterWhitespace}, ${rangeEnd}, "${whiteSpaceCompensation}"]`); | |
opts.cb({ | |
tag, | |
deleteFrom: tag.leftOuterWhitespace, | |
deleteTo: rangeEnd, | |
insert: whiteSpaceCompensation, | |
rangesArr: rangesToDelete, | |
proposedReturn: [ | |
tag.leftOuterWhitespace, | |
rangeEnd, | |
whiteSpaceCompensation | |
] | |
}); | |
i = y - 1; | |
if (str[y] === ">") { | |
i = y; | |
} | |
tag = {}; | |
attrObj = {}; | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
if (!str[i].trim()) { | |
if (chunkOfWhitespaceStartsAt === null) { | |
chunkOfWhitespaceStartsAt = i; | |
/* @__PURE__ */ console.log(`2140 ${`[${32}m${`SET`}[${39}m`} [${33}m${`chunkOfWhitespaceStartsAt`}[${39}m = ${chunkOfWhitespaceStartsAt}`); | |
if (tag.lastOpeningBracketAt !== void 0 && tag.lastOpeningBracketAt < i && tag.nameStarts && tag.nameStarts < tag.lastOpeningBracketAt && i === tag.lastOpeningBracketAt + 1 && !rangedOpeningTags.some((rangedTagObj) => rangedTagObj.name === tag.name)) { | |
/* @__PURE__ */ console.log(`2155 RESET ALL [${31}m${`\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588`}[${39}m`); | |
tag.onlyPlausible = true; | |
tag.name = void 0; | |
tag.nameStarts = void 0; | |
} | |
} | |
} else if (chunkOfWhitespaceStartsAt !== null) { | |
/* @__PURE__ */ console.log("2163"); | |
if (!tag.quotes && attrObj.equalsAt > chunkOfWhitespaceStartsAt - 1 && attrObj.nameEnds && attrObj.equalsAt > attrObj.nameEnds && str[i] !== '"' && str[i] !== "'") { | |
if ((0, import_lodash.default)(attrObj)) { | |
/* @__PURE__ */ console.log(`2176 PUSHING ${`[${33}m${`attrObj`}[${39}m`} = ${JSON.stringify(attrObj, null, 4)}`); | |
tag.attributes.push(attrObj); | |
} | |
attrObj = {}; | |
tag.equalsSpottedAt = void 0; | |
} | |
chunkOfWhitespaceStartsAt = null; | |
/* @__PURE__ */ console.log(`2192 ${`[${32}m${`SET`}[${39}m`} [${33}m${`chunkOfWhitespaceStartsAt`}[${39}m = ${chunkOfWhitespaceStartsAt}`); | |
} | |
if (str[i] === " ") { | |
if (chunkOfSpacesStartsAt === null) { | |
chunkOfSpacesStartsAt = i; | |
/* @__PURE__ */ console.log(`2204 ${`[${32}m${`SET`}[${39}m`} [${33}m${`chunkOfSpacesStartsAt`}[${39}m = ${chunkOfSpacesStartsAt}`); | |
} | |
} else if (chunkOfSpacesStartsAt !== null) { | |
chunkOfSpacesStartsAt = null; | |
/* @__PURE__ */ console.log(`2211 ${`[${32}m${`SET`}[${39}m`} [${33}m${`chunkOfSpacesStartsAt`}[${39}m = ${chunkOfSpacesStartsAt}`); | |
} | |
/* @__PURE__ */ console.log(`[${32}m${`===============`}[${39}m`); | |
/* @__PURE__ */ console.log(`2226 ${`[${33}m${`rangedOpeningTags`}[${39}m`} = ${JSON.stringify(rangedOpeningTags, null, 4)}`); | |
/* @__PURE__ */ console.log(`2233 ${`[${33}m${`filteredTagLocations`}[${39}m`} = ${JSON.stringify(filteredTagLocations, null, 4)}`); | |
/* @__PURE__ */ console.log(`2240 ${`[${33}m${`spacesChunkWhichFollowsTheClosingBracketEndsAt`}[${39}m`} = ${JSON.stringify(spacesChunkWhichFollowsTheClosingBracketEndsAt, null, 4)}`); | |
/* @__PURE__ */ console.log(`2254 ${`[${33}m${`hrefDump`}[${39}m`} = ${JSON.stringify(hrefDump, null, 4)}`); | |
/* @__PURE__ */ console.log(`2261 ${`[${33}m${`attrObj`}[${39}m`} = ${JSON.stringify(attrObj, null, 4)}`); | |
/* @__PURE__ */ console.log(`2268 ${Object.keys(tag).length ? `${`[${35}m${`tag`}[${39}m`} = ${Object.keys(tag).map((key) => { | |
return `${`[${90}m${`[${7}m${key}[${27}m`}[${39}m`} ${`[${90}m: ${(0, import_lodash.default)(tag[key]) || Array.isArray(tag[key]) ? JSON.stringify(tag[key], null, 4) : tag[key]}[${39}m`}`; | |
}).join(",\n")} | |
` : ""}${rangesToDelete.current() ? `RANGES: ${JSON.stringify(rangesToDelete.current(), null, 0)}` : ""}`); | |
} | |
/* @__PURE__ */ console.log("\n\n\n\n\n\n END \n\n\n\n\n\n"); | |
if (str && (opts.trimOnlySpaces && str[0] === " " || !opts.trimOnlySpaces && !str[0].trim())) { | |
/* @__PURE__ */ console.log(`2304 trim frontal part`); | |
for (let i = 0, len = str.length; i < len; i++) { | |
if (opts.trimOnlySpaces && str[i] !== " " || !opts.trimOnlySpaces && str[i].trim()) { | |
/* @__PURE__ */ console.log(`2310 PUSH [0, ${i}]`); | |
rangesToDelete.push([0, i]); | |
break; | |
} else if (!str[i + 1]) { | |
/* @__PURE__ */ console.log(`2315 PUSH [0, ${i + 1}]`); | |
rangesToDelete.push([0, i + 1]); | |
} | |
} | |
} | |
if (str && (opts.trimOnlySpaces && str[str.length - 1] === " " || !opts.trimOnlySpaces && !str[str.length - 1].trim())) { | |
for (let i = str.length; i--; ) { | |
if (opts.trimOnlySpaces && str[i] !== " " || !opts.trimOnlySpaces && str[i].trim()) { | |
/* @__PURE__ */ console.log(`2337 PUSH [i + 1, ${str.length}]`); | |
rangesToDelete.push([i + 1, str.length]); | |
break; | |
} | |
} | |
} | |
const curr = rangesToDelete.current(); | |
if ((!originalOpts || !originalOpts.cb) && curr) { | |
if (curr[0] && !curr[0][0]) { | |
/* @__PURE__ */ console.log(`2358 ${`[${33}m${`the first range`}[${39}m`} = ${JSON.stringify(curr[0], null, 4)}`); | |
const startingIdx = curr[0][1]; | |
/* @__PURE__ */ console.log(`2367 ${`[${33}m${`startingIdx`}[${39}m`} = ${JSON.stringify(startingIdx, null, 4)}`); | |
rangesToDelete.ranges[0] = [ | |
rangesToDelete.ranges[0][0], | |
rangesToDelete.ranges[0][1] | |
]; | |
} | |
if (curr[curr.length - 1] && curr[curr.length - 1][1] === str.length) { | |
/* @__PURE__ */ console.log(`2386 ${`[${33}m${`the last range`}[${39}m`} = ${JSON.stringify(curr[curr.length - 1], null, 4)}; str.length = ${str.length}`); | |
const startingIdx = curr[curr.length - 1][0]; | |
/* @__PURE__ */ console.log(`2395 ${`[${33}m${`startingIdx`}[${39}m`} = ${JSON.stringify(startingIdx, null, 4)}`); | |
if (rangesToDelete.ranges) { | |
let startingIdx2 = rangesToDelete.ranges[rangesToDelete.ranges.length - 1][0]; | |
if (str[startingIdx2 - 1] && (opts.trimOnlySpaces && str[startingIdx2 - 1] === " " || !opts.trimOnlySpaces && !str[startingIdx2 - 1].trim())) { | |
startingIdx2 -= 1; | |
} | |
const backupWhatToAdd = rangesToDelete.ranges[rangesToDelete.ranges.length - 1][2]; | |
rangesToDelete.ranges[rangesToDelete.ranges.length - 1] = [ | |
startingIdx2, | |
rangesToDelete.ranges[rangesToDelete.ranges.length - 1][1] | |
]; | |
if (backupWhatToAdd && backupWhatToAdd.trim()) { | |
rangesToDelete.ranges[rangesToDelete.ranges.length - 1].push(backupWhatToAdd.trimEnd()); | |
} | |
} | |
} | |
} | |
const res = { | |
log: { | |
timeTakenInMilliseconds: Date.now() - start | |
}, | |
result: (0, import_ranges_apply.rApply)(str, rangesToDelete.current()), | |
ranges: rangesToDelete.current(), | |
allTagLocations, | |
filteredTagLocations | |
}; | |
/* @__PURE__ */ console.log(`2450 ${`[${32}m${`FINAL RESULT`}[${39}m`} = ${JSON.stringify(res, null, 4)}`); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment