Changeset 515


Ignore:
Timestamp:
05/16/06 15:17:40 (14 years ago)
Author:
wymsy
Message:

Ticket #798: the entire contents of script tags will now be ignored.

Also some improved whitespace suppression, and some closing block tags will no longer start a new line.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/GetHtml/get-html.js

    r502 r515  
    4747/*12*/  new RegExp().compile(/(\S*\s*=\s*)?contenteditable[^=>]*(=\s*[^>\s\/]*)?/gi),//strip contenteditable 
    4848/*13*/  new RegExp().compile(/((href|src)=")([^\s]*)"/g), //find href and src for stripBaseHref() 
    49 /*14*/  new RegExp().compile(/<\/?(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|br|hr|img|embed|param|pre|script|html|head|body|meta|link|title|area)[^>]*>/g), 
    50 /*15*/  new RegExp().compile(/<\/(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),//blocklevel closing tag 
    51 /*16*/  new RegExp().compile(/<(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|html|head|body|script)( [^>]*)?>/g),//blocklevel opening tag 
    52 /*17*/  new RegExp().compile(/<(br|hr|img|embed|param|pre|meta|link|title|area)[^>]*>/g),//singlet tag 
     49/*14*/  new RegExp().compile(/<\/?(div|p|h[1-6]|table|tr|td|th|ul|ol|li|blockquote|object|br|hr|img|embed|param|pre|script|html|head|body|meta|link|title|area|input|form|textarea|select|option)[^>]*>/g), 
     50/*15*/  new RegExp().compile(/<\/(div|p|h[1-6]|table|tr|ul|ol|blockquote|object|html|head|body|script|form|select)( [^>]*)?>/g),//blocklevel closing tag 
     51/*16*/  new RegExp().compile(/<(div|p|h[1-6]|table|tr|ul|ol|blockquote|object|html|head|body|script|form|select)( [^>]*)?>/g),//blocklevel opening tag 
     52/*17*/  new RegExp().compile(/<(td|th|li|option|br|hr|img|embed|param|pre|meta|link|title|area|input|textarea)[^>]*>/g),//singlet tag or output on 1 line 
    5353/*18*/  new RegExp().compile(/(^|<\/(pre|script)>)(\s|[^\s])*?(<(pre|script)[^>]*>|$)/g),//find content NOT inside pre and script tags 
    5454/*19*/  new RegExp().compile(/(<pre[^>]*>)(\s|[^\s])*?(<\/pre>)/g),//find content inside pre tags 
    5555/*20*/  new RegExp().compile(/(^|<!--(\s|\S)*?-->)((\s|\S)*?)(?=<!--(\s|\S)*?-->|$)/g),//find content NOT inside comments 
    5656/*21*/  new RegExp().compile(/\S*=""/g), //find empty attributes 
    57 /*22*/  new RegExp().compile(/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<[^>]*>/g) //find all tags, including comments and php 
     57/*22*/  new RegExp().compile(/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<\/?\w[^>]*>/g), //find all tags, including comments and php 
     58/*23*/  new RegExp().compile(/(^|<\/script>)(\s|[^\s])*?(<script[^>]*>|$)/g) //find content NOT inside script tags 
    5859]; 
    5960 
     
    124125          });return strn; 
    125126    }); 
    126     if (s.charAt(0) == "\n") { 
    127         return s.substring(1, s.length); 
    128     } 
    129     s = s.replace(/ *\n/g,'\n');//strip spaces at end of lines 
     127    //final cleanup 
     128    s = s.replace(/^\s*/,'').//strip leading whitespace 
     129        replace(/ +\n/g,'\n').//strip spaces at end of lines 
     130        replace(/[\r\n]+<\/script>/g,'\n</script>');//strip returns added into scripts 
    130131    return s; 
    131132}; 
     
    143144                        temp.appendChild(j.cloneNode(true)); 
    144145            } 
    145             html += temp.innerHTML.replace(c[22], function(tag){ 
    146                         if(/^<[!\?]/.test(tag)) return tag; //skip comments and php tags 
    147                         else return editor.cleanHTML(tag)}); 
     146                html += temp.innerHTML.replace(c[23], function(strn) { //skip content inside script tags 
     147                        strn = strn.replace(c[22], function(tag){ 
     148                                if(/^<[!\?]/.test(tag)) return tag; //skip comments and php tags 
     149                                else return editor.cleanHTML(tag)}); 
     150                        return strn; 
     151                }); 
    148152 
    149153        } else { 
     
    171175                //pass tags to cleanHTML() one at a time 
    172176                //includes support for htmlRemoveTags config option 
    173                 html += innerhtml.replace(c[22], function(tag){ 
    174                         if(/^<[!\?]/.test(tag)) return tag; //skip comments and php tags 
    175                         else if(!(editor.config.htmlRemoveTags && editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/,'$1')))) 
    176                                 return editor.cleanHTML(tag); 
    177                         else return ''}); 
     177                html += innerhtml.replace(c[23], function(strn) { //skip content inside script tags 
     178                        strn = strn.replace(c[22], function(tag){ 
     179                                if(/^<[!\?]/.test(tag)) return tag; //skip comments and php tags 
     180                                else if(!(editor.config.htmlRemoveTags && editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/,'$1')))) 
     181                                        return editor.cleanHTML(tag); 
     182                                else return ''}); 
     183                        return strn; 
     184                }); 
    178185                //IE drops  all </li> tags in a list except the last one 
    179186                if(HTMLArea.is_ie) { 
     
    183190                } 
    184191                if(HTMLArea.is_gecko) 
    185                         html = html.replace(/(.*)<br \/>\n$/, '$1'). //strip trailing <br> added by moz 
    186                                 replace(/^\n(.*)/, '$1'); //strip leading newline added by moz 
     192                        html = html.replace(/<br \/>\n$/, ''); //strip trailing <br> added by moz 
    187193                if (outputRoot) { 
    188194                        html += "</" + root_tag + ">"; 
     
    195201}; 
    196202 
    197 //override (hack) outwardHtml() to handle onclick suppression 
     203//overload outwardHtml() to handle onclick suppression 
    198204HTMLArea.prototype._origOutwardHtml = HTMLArea.prototype.outwardHtml; 
    199205HTMLArea.prototype.outwardHtml = function(html) { 
Note: See TracChangeset for help on using the changeset viewer.