#1099 closed defect (bug) (duplicate)
wpautop filter may product invalid markup
Reported by: | idanso | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 2.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
The wpautop filter, enabled by default on Wordpress 1.5, produces not well formed XHTML in some cases.
One such case occurs when the input has a 'pee' block contained within a 'div' block, and there is a newline, followed by atext between the end of the 'pee' block and the end of the 'div' block.
In such a case, wpautop will open a 'pee' block at the start of the text block, but will not close it.
For example:
<div>
<p>Hello</p>
World</div>
Will product:
<div>
<p>Hello</p>
<p>World</div>
Attachments (2)
Change History (9)
#3
@
19 years ago
- Cc turnip@… added
Well, here's a patch (kinda). It might need some more elements, and probably needs a bit more testing, but it worked for me...
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $pee); // make paragraphs, including one at the end + $pee = preg_replace('!(<(?:div|address|form)[^>]*>)([^<]+)</p>!', "$1<p>$2</p>", $pee); + $pee = preg_replace('!<p>([^<]+)\s*?(</(?:div|address|form)[^>]*>)!', "<p>$1</p>$2", $pee); $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
To prevent the invalid markup being produced, I found that at least two newlines were needed between the containing elements's tag (div, address etc.) and the text that needs to be peed. So this would be ok:
<div> some words some more words </div>
But this wouldn't:
<div> some words some more words </div>
#4
@
18 years ago
- Keywords bg|has-patch added
- Milestone set to 2.1
- Version changed from 1.5.1 to 2.1
Jon Leighton's patch (which I've attached) works for me.
#5
@
18 years ago
- Milestone changed from 2.1 to 2.2
The patch breaks when there is any markup in the string:
<div> some words some more <a href="">and a link</a> words </div>
This could be related to http://mosquito.wordpress.org/view.php?id=488
It was once fixed with pre and code but is broken with code now.