return false;
}
- function canRemoveElement(tag) {
- return tag !== 'textarea';
+ function canRemoveElement(tag, attrs) {
+ if (tag === 'textarea') {
+ return false;
+ }
+
+ if (tag === 'script') {
+ for (var i = attrs.length - 1; i >= 0; i--) {
+ if (attrs[i].name === 'src') {
+ return false;
+ }
+ }
+ }
+
+ return true;
}
function canCollapseWhitespace(tag) {
buffer.push(token);
}
},
- end: function( tag ) {
+ end: function( tag, attrs ) {
if (isIgnoring) {
buffer.push('</' + tag + '>');
}
var isElementEmpty = currentChars === '' && tag === currentTag;
- if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag))) {
+ if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) {
// remove last "element" from buffer, return
for ( var i = buffer.length - 1; i >= 0; i-- ) {
if ( /^<[^\/!]/.test(buffer[i]) ) {
// Close all the open elements, up the stack
for ( var i = stack.length - 1; i >= pos; i-- ) {
if ( handler.end ) {
- handler.end( stack[ i ].tag );
+ handler.end( stack[ i ].tag, stack[ i ].attrs );
}
}