* @output wp-includes/js/wp-sanitize.js
window.wp = window.wp || {};
* Helper functions to sanitize strings.
* @param {string} text Text to have the HTML tags striped out of.
stripTags: function( text ) {
.replace( /<!--[\s\S]*?(-->|$)/g, '' )
.replace( /<(script|style)[^>]*>[\s\S]*?(<\/\1>|$)/ig, '' )
.replace( /<\/?[a-z][\s\S]*?(>|$)/ig, '' );
// If the initial text is not equal to the modified text,
// do the search-replace again, until there is nothing to be replaced.
return wp.sanitize.stripTags( _text );
// Return the text with stripped tags.
* Strip HTML tags and convert HTML entities.
* @param {string} text Text to strip tags and convert HTML entities.
* @return Sanitized text. False on failure.
stripTagsAndEncodeText: function( text ) {
var _text = wp.sanitize.stripTags( text ),
textarea = document.createElement( 'textarea' );
textarea.textContent = _text;
_text = wp.sanitize.stripTags( textarea.value );