I want to get the text content only of some HTML. I don’t know if this html is clean. I can do this as follows:
export function getTextContent(html: string) {
const el = document.createElement("div");
el.innerHTML = html;
return el.textContent || "";
};
My question is whether this is safe. By safe I mean that:
- Scripts included in the HTML don’t run
- Any inline stylesheets do not effect the document
- No requests are made for any resources (image, css, etc..) included in the markup