DOMPurify Keep text between tags || Remove only Tags

3.5k views Asked by At

I have an Test string.

const html = '{%remove%} useful {{remove}} <svg></p><style><a id="</style><img src=1 onerror=alert(1)>"> keep';

And I'm trying to remove all the html content and the {{, }}, {%, %}. But I'd like to keep the useful and keep words on string.

const purifyConfig = {
    FORBID_TAGS: ['{{', '{%',],
    SAFE_FOR_TEMPLATES: true,
    RETURN_TRUSTED_TYPE: true,
    ALLOW_DATA_ATTR: false,
    KEEP_CONTENT: true,
};
const clean = DOMPurify.sanitize(html, purifyConfig);

The clean Result in a Empty string. What configuration should I use to do this?

0

There are 0 answers