WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 8 months ago

#20444 new defect (bug)

wpautop acts on a single line of text

Reported by: niallkennedy Owned by:
Priority: normal Milestone: Awaiting Review
Component: Formatting Version:
Severity: normal Keywords:
Cc: justin@…

Description

HTML markup on a single line wrapped in a block element is interpreted and changed by wpautop. The wpautop function is described as replacing "double line-breaks with paragraph elements" which led me to expect the single line would not become many lines.

echo wpautop( '<div><p>Hello world</p><span>WordPress</span></div>' );
<div>
<p>Hello world</p>
<p><span>WordPress</span></div>

Extra <p> before the <span>.

I expected wpautop would find no newlines and return the original string.

The same string placed inside a HTML5 or XHTML 1 Strict document <body> is parsed as valid by W3C Validator.

Plugins acting on the_content with a priority less than 10 may have their single-line markup reinterpreted by wpautop.

Attachments (1)

test-wpautop.php (225 bytes) - added by niallkennedy 14 months ago.
wp-load and call wpautop with a single line div

Download all attachments as: .zip

Change History (4)

niallkennedy14 months ago

wp-load and call wpautop with a single line div

comment:1 MarcusPope10 months ago

Another (w3c valid fragment) variation that will fail is:

asdfasdfasdf<br/>asdfasdfasdf<h1>Hello</h1>

which results in:

<p>asdfasdfasdf<br/>asdfasdfasdf<br />

<h1>Hello</h1>

It's missing the closing p tag after <br />. Changing the first preg_replace|$allblocks line in formatting.php's wpautop function to replace matches with "\n\n$1" (instead of "\n$1") will fix the above, but creates problems for the test case attached to test-wpautop.php.

<div>

<p>hello</p>

<p><span>Wordpress</span></div>

Though I'm guessing this ticket will be closed invalid as #7937 was. (sigh)

comment:3 greenshady8 months ago

  • Cc justin@… added
Note: See TracTickets for help on using tickets.