[wp-trac] [WordPress Trac] #7937: Problem with the wpautop function ads a extra <p> tag if there is more span tag

WordPress Trac wp-trac at lists.automattic.com
Tue Oct 21 02:44:25 GMT 2008


#7937: Problem with the wpautop function ads a extra <p> tag if there is more span
tag
-------------------------+--------------------------------------------------
 Reporter:  keithdsouza  |       Owner:  anonymous
     Type:  defect       |      Status:  new      
 Priority:  normal       |   Milestone:  2.7      
Component:  Template     |     Version:  2.7      
 Severity:  normal       |    Keywords:           
-------------------------+--------------------------------------------------
 There is a small bug in the cleanup code wpautop where it adds a extra <p>
 tag if there is a more section in the post.

 The problem starts on this line of code

 '''$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee);
 // make paragraphs, including one at the end'''

 For starters run the method in a standalone mode on this html snippet

 <p>hello</p> <span id="more-2689"></span>  <p>hello1</p>

 once this line of code is applied the new html code is

 <p><p>hello</p></p>
 '''<p>''' <span id="more-2689"></span>
 <p>hello1</p>'''</p>'''

 As you can see it added the <p> tag before span but missed out on adding
 the end tag, on the other hand it still added <p> tags to all other start
 and end tags

 This line $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!',
 "$1", $pee);

 removes the duplicate tags but the output leaves a invalid xhtml in the
 form of a open <p> tag

 <p>hello</p>
 '''<p>''' <span id="more-2689"></span> '''(missing close p tag here)'''
 <p>hello1</p>

 The solution would be to change the first regex to this

 $pee = preg_replace('/'''\n\n'''?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n",
 $pee); // make paragraphs, including one at the end

 Note the \n\n because you are already adding two line breaks in the
 earlier regex, hopefully you can add this to the coming version

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7937>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list