#25646 closed defect (bug) (fixed)
figcaption should not be treated as a block by wpautop()
Reported by: | laacz | Owned by: | |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.6.1 |
Component: | Formatting | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
Tested against clean Wordpress 3.6.1 with default theme. Result can be seen here: http://dev.laacz.lv/wp-vanilla/?p=4 and in provided attachment.
When composing entry in "text" mode, following generates invalid (or unwanted) markup.
Post content:
<figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /> <figcaption>Test figure with a test caption (linebreak after <img/>)</figcaption> </figure> <figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /><figcaption>Test figure with a test caption (no linebreak after <img/>)</figcaption> </figure>
Generated markup (note invalid </p> and unwanted <br/>):
<figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /></p> <figcaption>Test figure with a test caption (linebreak after <img/>)</figcaption> </figure> <figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /><br /> <figcaption>Test figure with a test caption (no linebreak after <img/>)</figcaption> </figure>
Expected output:
<figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /> <figcaption>Test figure with a test caption (linebreak after <img/>)</figcaption> </figure> <figure> <img src="http://dev.laacz.lv/wp-vanilla/wp-content/uploads/2013/10/figcaption.jpg" /><figcaption>Test figure with a test caption (no linebreak after <img/>)</figcaption> </figure>
Attachments (3)
Change History (17)
#1
@
11 years ago
- Milestone changed from Awaiting Review to 3.9
- Summary changed from Paragraph and linebreak elements get added when using figure, a, img and figcaption to figcaption should not be treated as a block by wpautop()
Thanks for the report, laacz. Looks like there are two distinct bugs here.
- figcaption is being treated as a block-level element by wpautop(), and you don't want it to be. figcaption is an interesting element — it must be either the first or last child of figure. Otherwise, figure contains flow content. Figcaption is neither block-like or flow-like in and of itself, it's just an extension of figure. So we should not be treating it as block-level, you are right.
I'm going to tweak the summary of this bug report slightly to reflect a focus on the second bullet.
#3
@
11 years ago
Hello, I don't know if this is ok, but since it's a really simple change (I think) I wanted to step in and try to submit a patch. Let me know if it's ok or I missed something.
#4
@
11 years ago
Hi oso96_2000, figcaption-not-block.25646.diff looks great. Totally okay for you to step in!
A change has to occur in JavaScript as well — a version of wpautop exists there, too. You'll find it in wp-admin/js/editor.js: https://core.trac.wordpress.org/browser/tags/3.8/src/wp-admin/js/editor.js#L163.
#5
@
11 years ago
Thanks nacin! :D
I missed that one. Uploaded a new patch with both instances modified. Hope it works now.
#8
follow-up:
↓ 9
@
11 years ago
- Keywords wpautop has-patch needs-testing removed
[27527] helped this on its way but has not completed fixed the issue. A <br>
is still inserted within <figure>
, however this occurs regardless of whether there's a <figcaption>
in there or not.
Is there a way we can treat <figure>
like <pre>
and treat its contents as-is?
#9
in reply to:
↑ 8
@
11 years ago
Replying to johnbillion:
[27527] helped this on its way but has not completed fixed the issue. A
<br>
is still inserted within<figure>
, however this occurs regardless of whether there's a<figcaption>
in there or not.
Is there a way we can treat
<figure>
like<pre>
and treat its contents as-is?
I'm not sure contents should be treated as-is... Wouldn't a line break be preferred in some instances?
Some unit tests to explain expected and actual (when figcaption is present and isn't) would go a long way to fixing this.
Screenshot of generated HTML.