Example: How to remove ALL HTML elements and tags from an input?
dosstx opened this issue · 2 comments
dosstx commented
Ok stupid question.....but how to remove ALL html from an input and just leave the basic text?
For example:
<b>Hello World</b>
should be Hello World
.
I tried:
Vue.use(VueDOMPurifyHTML, {
USE_PROFILES: {
html: false
}
})
But Still showed the b
element in the user input.
LeSuisse commented
Hello,
This is more a question for DOMPurify itself.
You can probably achieve what you want with the following DOMPurify config: { ALLOWED_TAGS: ['#text'] }
.
However if that is your only need for DOMPurify you might be better of without it and save a few dependencies and KB in your app by retrieving directly your text content with something like this:
function strip(html: string): string {
const doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || "";
}
Does it answer your question?
LeSuisse commented
Closing since this was not directly related to vue-dompurify-html
.