// Leave only opening `td` tags
import { strict as assert } from "assert";
import { stripHtml } from "../dist/string-strip-html.esm.js";
const someHtml = `
`;
// the first way
// -----------------------------------------------------------------------------
assert.equal(
stripHtml(someHtml, {
// notice there's no: onlyStripTags: ["td"]
// we operate purely via callback
cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => {
if (tag.name === "td" && !tag.slashPresent) {
rangesArr.push(proposedReturn);
}
},
}).ranges.reduce(
(acc, [from, to]) => `${acc}${someHtml.slice(from, to).trim()}`,
""
),
` | | | `
);
// the second way:
// -----------------------------------------------------------------------------
let resultStr = "";
// notice we don't even assign stripHtml() output to anything - we rely only
// on the callback, it mutates the "resultStr" in the upper scope
stripHtml(someHtml, {
// notice there's no: onlyStripTags: ["td"]
// we operate purely via callback
cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => {
if (tag.name === "td" && !tag.slashPresent) {
resultStr += someHtml.slice(deleteFrom, deleteTo).trim();
}
},
});
assert.equal(
resultStr,
` | | | | `
);
|