Readme

Strip HTML

Remove HTML tags from a string by parsing the HTML. There are certainly faster ways of doing this, ie

html.replace(/<\/[^>]+(>|$)/g, "") // source https://stackoverflow.com/a/5002161

but this way is likely the most correct in that you're using a proper HTML parser.

1
2
3
4
5
6
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
export function stripHTML(html: string) {
const doc = new DOMParser().parseFromString(html, "text/html");
return doc.body.textContent;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 22, 2024