[wp-trac] Re: [WordPress Trac] #3833: Extra </p> inside blockquote

WordPress Trac wp-trac at lists.automattic.com
Sun Feb 15 18:01:36 GMT 2009


#3833: Extra </p> inside blockquote
------------------------------------------------------------------+---------
 Reporter:  audwan                                                |        Owner:  Archibald Leaurees
     Type:  defect (bug)                                          |       Status:  new               
 Priority:  normal                                                |    Milestone:  2.9               
Component:  Validation                                            |      Version:  2.7               
 Severity:  normal                                                |   Resolution:                    
 Keywords:  blockquote invalid list paragraph tags wpautop autop  |  
------------------------------------------------------------------+---------
Changes (by Archibald Leaurees):

 * cc: Archibald, Leaurees (added)
  * owner:  anonymous => Archibald Leaurees
  * status:  reopened => new
  * component:  Administration => Validation
  * version:  2.3.1 => 2.7


Comment:

 This bug is still there.
 When wpautop deals with that content :

 {{{
     text before
     <div class="whatever">
       <blockquote>
         text inside the blockquote tag
       </blockquote>
       Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </div>
 }}}

 wpautop returns the following output :

 {{{
 <p>    text before</p>
 <div class="whatever">
 <blockquote><p>
         text inside the blockquote tag
       </p></blockquote>
 <p>      Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </p></div>

 }}}


 Everything is ok. The output of wpautop is just like we want it to be.
 But when we try the following input :

 {{{
     text before    <div class="whatever">
       <blockquote>
         text inside the blockquote tag
       </blockquote>
       Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </div>
 }}}

 wpautop returns :


 {{{
 <p>    text before
 <div class="whatever">
 <blockquote><p>
         text inside the blockquote tag
       </p></blockquote>
 <p>      Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </p></div>

 }}}

 Obviously that's not a valid HTML. There's an openning 'p' tag just at the
 beginning, which one won't be closed.

 We can reproduce that bug also using the following HTML code sample :


 {{{
     text before    <div class="whatever"><blockquote>
         text inside the blockquote tag
       </blockquote>
       Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </div>
 }}}

 After passing that content to wpautop, we have, as output, the following
 content :


 {{{
 <p>    text before
 <div class="whatever">
 <blockquote>
         text inside the blockquote tag
       </p></blockquote>
 <p>      Some text inside the div embedding the blockquote and after the
 closing blockquote tag
     </p></div>

 }}}

 As you can see there's some orphan tags. The openning p-tag before the
 beginning text and a closing p-tag just before the closing blockquote-tag.

 There's other examples. But the two given are clear enough.

 I've spent some hours looking for a solution or a patch. Helping is better
 that complaining. I've extracted the function, put it in a separated file
 and give it the real output of 'get_shortcode_regex()', because wpautopo
 uses it. you can have a look on the page I used here
 [http://www.flegme.fr/wpautopdebug.php]. And here's the same page with my
 bug fix applied [http://www.flegme.fr/wpautopdebugafter.php] (the php
 deugging file is attached as wpautopdebug.php)

 So the solution is rather simple. In the wpautop php code at line 37,38
 you've got :

 {{{

         $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1",
 $pee);
         $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
 }}}

 I've noticed that those two lines add newlines '\n' before and after some
 special tags (including the 'div' tag and the 'blockquote' tag). But the
 first regular expression adds one '\n' only where the second one adds two
 ones.

 When I modify the code that it inserts two newlines before and after the
 special tags, the bug disapears.

 So those two lines become :

 {{{

         $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n\n$1",
 $pee);
         $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
 }}}


 Maybe i've missed something and my solution is not the good one... But
 that worked fine for me.


 Regards

 Archibald Leaurees

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/3833#comment:6>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list