Opened 12 years ago
Closed 4 years ago
#20444 closed defect (bug) (duplicate)
wpautop acts on a single line of text
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | wpautop has-patch needs-refresh |
Focuses: | Cc: |
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 (3)
Change History (13)
#1
@
11 years 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)
#4
@
10 years ago
Hi, the p tag is considered a blocking element. In this case the output from wpautop should be:
<div> <p>Hello world</p> <p><span>WordPress</span></p> </div>
I'm in the process of writing a comprehensive set of unit tests on the wpautop function to verify its current functionality and allow proper regression testing as new enhancements are requested. I've added the above as a test case to confirm that the second p tag is properly closed.
It might be another week till it gets put up for review as there are a good amount of tickets to go through.
#6
@
10 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to Future Release
mdbitz's ticket with tests ended up being #25856.
Fine with trying to establish a fix for this. Let's make sure we have strong test coverage though.
wp-load and call wpautop with a single line div