Opened 6 years ago
Last modified 3 years ago
#4857 accepted defect (bug)
More issues with wpautop()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | low | Milestone: | Future Release |
| Component: | Formatting | Version: | 2.3 |
| Severity: | normal | Keywords: | wpautop needs-patch needs-unit-tests |
| Cc: | wptrac@… |
Description
Not sure if this should slide into 2.3 or if it can wait for 2.4. Change as need be.
wpautop() has issues with closing </p>'s when it comes to HTML.
For example:
Foo<div>Bar</div>
Results in:
<p>Foo <div>Bar</div>
Change History (12)
comment:2
follow-up:
↓ 4
foolswisdom — 6 years ago
- Milestone changed from 2.3 to 2.4 (next)
Viper007Bond a "real world" example would be great too, because when I look at that input I wonder if it isn't such an edge case that it could complicate solutions for more general problems.
comment:3
Viper007Bond — 6 years ago
- Cc wptrac@… added
comment:4
in reply to:
↑ 2
Viper007Bond — 6 years ago
Replying to foolswisdom:
Viper007Bond a "real world" example would be great too, because when I look at that input I wonder if it isn't such an edge case that it could complicate solutions for more general problems.
It seems to only do it with block level items.
For example:
This is some <pre>code</pre>
gets turned into:
<p>This is some <pre>code</pre>
comment:5
Viper007Bond — 6 years ago
I don't know how to get much more "real world" than that BTW. :/
- Keywords wpautop added
- Owner changed from anonymous to mdawaffe
- Status changed from new to assigned
I look at your first (and second) example and expect the paragraph to only wrap around "Foo":
<p>Foo</p> <div>Bar</div>
since paragraph elements can only contain inline content*. For that reason, I do not expect the paragraph to wrap the whole thing:
mdawaffe thinks this is wrong <p>Foo<div>Bar</div></p>
comment:7
in reply to:
↑ description
whoismanu — 5 years ago
Replying to Viper007Bond:
Not sure if this should slide into 2.3 or if it can wait for 2.4. Change as need be.
wpautop() has issues with closing </p>'s when it comes to HTML.
For example:
Foo<div>Bar</div>Results in:
<p>Foo <div>Bar</div>
obviously it didn't make it into 2.3 ;-( let's hope it will make it into 2.4. here is a real world example from my photoblog plugin. i hope it shows that the problem really is annoying whenever there is need to have some structured content in the content section of the post. i of course also hope it could help raise the priority level of this one ;-). so here you go:
my plugin writes an image plus a corresponding description into the post like this:
<img width="700" height="525" src="someimage.jpg" /> <p class="description">Description of image</p>
The p tag with css class is needed to give the user the possibility to style the result. so i cannot just use line breaks between the image and its description like the wordpress editor would do to separate paragraphs.
The result after it has been deformed by wpautop:
<p><img width="700" height="525" src="someimage.jpg" /> <p class="description">Description of image</p>
which is obviously not valid xhtml. what i would expect is
<img width="700" height="525" src="someimage.jpg" /> <p class="description">Description of image</p>
or if you really have to put p tags all over the place:
<p><img width="700" height="525" src="someimage.jpg" /></p> <p class="description">Description of image</p>
yes, the paragraph should not wrap the whole thing because of the reason you mention. yes, the bug concerns all blocklevel elements, so
<img width="700" height="525" src="someimage.jpg" /> <div class="description">Description of image</div>
results in
<p><img width="700" height="525" src="someimage.jpg" /> <div class="description">Description of image</div>
thanks a lot for fixing this.
Issue Semi-resolved.
<img width="700" height="525" src="someimage.jpg" /> <p class="description">Description of image</p>
results in: (Incorrect, double <p>'s)
<p><img src="someimage.jpg" height="525" width="700" /></p> <p><p class="description">Description of image</p></p>
<img width="700" height="525" src="someimage.jpg" /> <div class="description">Description of image</div>
results in: (Which seems to be correct?)
<p><img src="someimage.jpg" height="525" width="700" /></p> <div class="description">Description of image</div>
Mind you, The resulting HTML in all cases seems to validate for me, But i'm pretty sure the nested <p>'s isnt right. (At least they're balanced now though)
- Component changed from Template to Formatting
comment:11
hakre — 4 years ago
comment:12
azaozz — 3 years ago
- Keywords needs-unit-tests added
- Milestone changed from 2.9 to Future Release

Obviously what's generated is incorrect :)
What output do you expect?