[wp-trac] [WordPress Trac] #42340: Spurious Insertion of <p>aragraph Tags

WordPress Trac noreply at wordpress.org
Fri Oct 27 13:00:24 UTC 2017


#42340: Spurious Insertion of <p>aragraph Tags
--------------------------+------------------------------
 Reporter:  oeconomist    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Formatting    |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by JPry):

 Replying to [comment:4 oeconomist]:
 > I would guess that at some point WordPress converts two consecutive
 newlines into two break elements, and that wpautop effectively assumes
 that all back-to-back instances of two break elements arose from such a
 conversion.

 There are actually two portions of code within the function that triggers
 the behavior you're seeing. The first portion is where consecutive
 {{{<br>}}} tags '''with nothing but whitespace between them''' are
 converted into a double newline:

 {{{#!php
 <?php
         // Change multiple <br>s into two line breaks, which will turn
 into paragraphs.
         $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
 }}}


 Later in the function, the content is divided at any set of double
 newlines:
 {{{#!php
 <?php
         // Split up the contents into an array of strings, separated by
 double line breaks.
         $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
 }}}

 Each of the resulting pieces is wrapped in {{{<p>}}} tags.

 The bold text earlier is key to the functionality. As the function
 currently exists, you can prevent your consecutive {{{<br>}}} tags from
 being replaced by including some non-whitespace text between them.

 > I suggest that it be replaced by a substitution such as “<br /><!--
 wpautop convertible --><br />” and that wpautop act when it encounters
 this new substring, leaving alone two back-to-back break elements.

 As the code currently works, you '''should''' be able to do something like
 this to '''prevent''' your consecutive breaks from being converted to
 newlines, and from there being matched as new paragraph dividers.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42340#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list