Skip to content

Commit 0612d03

Browse files
committed
Update the stripTags to use DOMParser
1 parent 826369c commit 0612d03

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/js/_enqueues/wp/sanitize.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
stripTags: function( text ) {
2626
let _text = text || '';
2727

28-
const htmlElement = document.createElement( 'div' );
29-
htmlElement.innerHTML = _text;
30-
_text = htmlElement.textContent || htmlElement.innerText || '';
28+
const domParser = new DOMParser();
29+
const htmlDocument = domParser.parseFromString( _text, 'text/html' );
30+
htmlDocument.body.innerText = htmlDocument.body.innerText || '';
3131

3232
// Return the text with stripped tags.
33-
return _text;
33+
return htmlDocument.body.innerHTML;
3434
},
3535

3636
/**

0 commit comments

Comments
 (0)