({
options: { mode: "iframe" },
take: [
{ type: "code", label: "HTML" },
{
type: "code",
label: "Filter",
detail:
"Elements matching this CSS selector will be removed from the result.",
},
{ type: "toggle", label: "Trim whitespace" },
],
make: ([html, filter, trim]) => {
const parser = new DOMParser()
const result = parser.parseFromString(html, "text/html").documentElement
if (filter) {
Array.from(result.querySelectorAll(filter)).forEach((el) => el.remove())
}
if (trim) {
return result.textContent
.replace(/^ +/gm, "")
.replace(/\n{3,}/g, "\n\n")
.trim()
} else {
return result.textContent
}
},
})