Make WordPress Core

Changeset 7716


Ignore:
Timestamp:
04/17/2008 07:11:21 PM (16 years ago)
Author:
ryan
Message:

Protect the <pre> and <script> tags when switching editors. Props azaozz. fixes #6610 for trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/editor.js

    r7513 r7716  
    1414
    1515    saveCallback : function(el, content, body) {
    16    
     16
    1717        document.getElementById(el).style.color = '#fff';
    1818        if ( tinyMCE.activeEditor.isHidden() )
     
    2727        // We have a TON of cleanup to do. Line breaks are already stripped.
    2828
     29        // Protect pre|script tags
     30        content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
     31            a = a.replace(/<br ?\/?>[\r\n]*/g, '<wp_temp>');
     32            return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<wp_temp>');
     33        });
     34
    2935        // Pretty it up for the source editor
    30         var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|pre|p';
     36        var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p';
    3137        content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
    3238        content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
     
    4753        content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div');
    4854        content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n');
    49        
     55
    5056        var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre';
    5157        content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
     
    6571        content = content.replace(new RegExp('^\\s*', ''), '');
    6672        content = content.replace(new RegExp('\\s*$', ''), '');
     73
     74        // put back the line breaks in pre|script
     75        content = content.replace(/<wp_temp>/g, '\n');
    6776
    6877        // Hope.
     
    110119            }
    111120
    112             ta.style.color = '';
     121            ta.style.color = '';
    113122            this.wpSetDefaultEditor('html');
    114123        }
     
    149158        pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
    150159        pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
    151         pee = pee.replace(new RegExp('<p><blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
    152         pee = pee.replace(new RegExp('</blockquote></p>', 'gi'), '</p></blockquote>');
     160        pee = pee.replace(new RegExp('<p>\\s*<blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
     161        pee = pee.replace(new RegExp('</blockquote>\\s*</p>', 'gi'), '</p></blockquote>');
    153162        pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
    154163        pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
     
    156165        pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
    157166        pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
    158         pee = pee.replace(new RegExp('^((?:&nbsp;)*)\\s', 'mg'), '$1&nbsp;');
    159         //pee = pee.replace(new RegExp('(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' "); // Hmm...
    160         return pee;
     167        // pee = pee.replace(new RegExp('^((?:&nbsp;)*)\\s', 'mg'), '$1&nbsp;');
     168
     169        // Fix the pre|script tags     
     170        pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
     171            a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
     172            return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
     173        });
     174
     175        return pee;
    161176    }
    162177}
Note: See TracChangeset for help on using the changeset viewer.