[wp-hackers] wpautop is NOT the problem.

Kevin Newman CaptainN at unFocus.com
Fri Mar 18 20:40:26 UTC 2011


I'm not sure how it could. Here is the function body for autop in JS:

_wp_Autop : function(pee) {
     var blocklist = 
'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend|hr';

     if ( pee.indexOf('<object') != -1 ) {
         pee = pee.replace(/<object[\s\S]+?<\/object>/g, function(a){
             return a.replace(/[\r\n]+/g, '');
         });
     }

     pee = pee.replace(/<[^<>]+>/g, function(a){
         return a.replace(/[\r\n]+/g, ' ');
     });

     // Protect pre|script tags
     if ( pee.indexOf('<pre') != -1 || pee.indexOf('<script') != -1 ) {
         pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, 
function(a) {
             return a.replace(/(\r\n|\n)/g, '<wp_temp_br>');
         });
     }

     pee = pee + '\n\n';
     pee = pee.replace(/<br \/>\s*<br \/>/gi, '\n\n');
     pee = pee.replace(new RegExp('(<(?:'+blocklist+')(?: [^>]*)?>)', 
'gi'), '\n$1');
     pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), 
'$1\n\n');
     pee = pee.replace(/<hr( [^>]*)?>/gi, '<hr$1>\n\n'); // hr is self 
closing block element
     pee = pee.replace(/\r\n|\r/g, '\n');
     pee = pee.replace(/\n\s*\n+/g, '\n\n');
     pee = pee.replace(/([\s\S]+?)\n\n/g, '<p>$1</p>\n');
     pee = pee.replace(/<p>\s*?<\/p>/gi, '');
     pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: 
[^>]*)?>)\\s*</p>', 'gi'), "$1");
     pee = pee.replace(/<p>(<li.+?)<\/p>/gi, '$1');
     pee = pee.replace(/<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');
     pee = pee.replace(/<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');
     pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')(?: 
[^>]*)?>)', 'gi'), "$1");
     pee = pee.replace(new RegExp('(</?(?:'+blocklist+')(?: 
[^>]*)?>)\\s*</p>', 'gi'), "$1");
     pee = pee.replace(/\s*\n/gi, '<br />\n');
     pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br 
/>', 'gi'), "$1");
     pee = pee.replace(/<br 
\/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1');
     pee = pee.replace(/(?:<p>|<br 
?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, 
'[caption$1[/caption]');

     pee = 
pee.replace(/(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, 
function(a, b, c) {
         if ( c.match(/<p( [^>]*)?>/) )
             return a;

         return b + '<p>' + c + '</p>';
     });

     // put back the line breaks in pre|script
     pee = pee.replace(/<wp_temp_br>/g, '\n');

     return pee;
},

blocklist is defined right at the top of the function list, and has no 
indication of any way to extend that list.

Kevin N.

On 3/18/2011 12:06 PM, Chip Bennett wrote:
> Does filtering the TinyMCE $init array not work?
>
> On Fri, Mar 18, 2011 at 11:04 AM, Kevin Newman<CaptainN at unfocus.com>  wrote:
>
>> That's correct, you will run into problems. But why is it like that? It
>> doesn't have to be - if I disable the WordPress JS, TinyMCE doesn't mess
>> with my stuff. From what I can tell, it seems like it should be quite
>> possible to have it both ways - it would take a source formatting step,
>> followed by autop and nop.
>>
>> There are other things an async call to the server would solve, besides
>> just making it consistent - for example, there are some hooks (adding
>> elements to the block element list) that are ignored client side (and the
>> way the js function is written, access to that list is almost impossible,
>> unless you really really know JavaScript). An async call to the server side
>> wpautop could theoretically fix that.
>>
>> Kevin N.
>>
>>
>>
>> On 3/18/2011 11:19 AM, Chip Bennett wrote:
>>
>>> If you're switching between Visual and HTML editors, and you haven't
>>> customized your TinyMCE configuration, you *WILL* run into problems.
>>>
>>> I would suggest either not switching between editors, or else customizing
>>> your TinyMCE configuration such that you avoid the changes that it makes
>>> when switching from HTML to Visual.
>>>
>>> Chip
>>>
>>> On Fri, Mar 18, 2011 at 10:12 AM, Kevin Newman<CaptainN at unfocus.com>
>>>   wrote:
>>>
>>>   So after looking into this more carefully, to try and disable what I
>>>> thought was the problem, I don't think the idea of wpautop is the
>>>> problem,
>>>> nor is the server side (php) implementation. If I just use the text
>>>> editor,
>>>> and save back to the server, things tend to work out.
>>>>
>>>> The problem seems to be the javascript implementation of wpautop that is
>>>> triggered between TinyMCE and the HTML tab.
>>>>
>>>> The question then is, how to make this work more consistently like the
>>>> PHP
>>>> version.
>>>>
>>>> I think this could be handled with an Ajax call to the actual server side
>>>> wpautop. But the JS version actually addresses another problem, which is
>>>> that content coming out of TinyMCE needs to be formatted (it's also doing
>>>> some other kind of filtering that I haven't looked closely enough at to
>>>> understand yet) - that could be handled separately before or after the
>>>> server side wpautop tag-back.
>>>>
>>>> Anyway, has anyone looked into this? I'd be a lot of the complaining
>>>> about
>>>> wpautop is actually complaints about the client side implementation of
>>>> it,
>>>> and not about wpautop in general.
>>>>
>>>> I'd be happy to attempt a solution, if there is any interest.
>>>>
>>>> Kevin N.
>>>>
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>
>>>>   _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list