export const 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",
detail: "Remove spaces from the start and end of every line.",
},
{
type: "toggle",
label: "Double space",
detail: "Include two lines between each line of text.",
},
]
export const make = ([html, filter, trim, double]) => {
const parser = new DOMParser()
const document = parser.parseFromString(html, "text/html").documentElement
if (filter) {
Array.from(document.querySelectorAll(filter)).forEach((el) => el.remove())
}
let result = document.textContent
if (trim) {
result = result
.replace(/^ +| +$/gm, "")
.replace(/\n{3,}/g, "\n\n")
.trim()
}
if (double) {
result = result.replace(/\n+/g, "\n\n")
}
return result
}
export const options = { mode: "iframe" }