Opened 11 months ago
Last modified 5 weeks ago
#20943 new defect (bug)
Paragraphs get removed in table cells when Visual editor is refreshed
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Formatting | Version: | 3.2 |
| Severity: | normal | Keywords: | needs-testing needs-unit-tests needs-patch |
| Cc: | JboyJW, palpatine1976, steph@…, knut@…, nicolas.girardet@…, johanronstrom |
Description
As far as I know, this issue has been around since 3.1. It's not a bug in 3.0.4. I even stopped upgrading at 3.0.4 for any sites where I knew the client would need to edit tabular data. For security reasons, it's time to upgrade these and I'd REALLY like this issue to be fixed.
The problem happens when using paragraphs in a table cell. When I hit enter to create a new paragraph within a table cell, it looks fine. If I then hit Update/Publish, when the page refreshes, WordPress converts that paragraph break into a single line break. If I then click Update again, WordPress removes that linebreak entirely and the paragraphs are essentially merged.
I can also reproduce this behaviour without even clicking Update. If you just switch to HTML mode and then back to Visual mode, the same issue occurs.
Attachments (2)
Change History (27)
Replying to Otto42:
Confirmed, the issue is in TinyMCE somewhere.
No, the issue is in wpautop (both JS and PHP versions). It doesn't handle well block elements that can contain other blocks. To reproduce: save a draft with the above html code from the HTML editor and check the source when viewing the post. It is:
<table> <tbody> <tr> <td> Test one</p> <p>Test two</p> <p>Test three </td> </tr> </tbody> </table>
where only the first paragraph is broken as HTML 5 allows for no closing </p>.
- Keywords has-patch added
This change to wpautop seems to fix the issue without obvious side effects. However, it would need extensive testing.
Couldn't find the JS version of autop that you are referring to. Not sure where that is.
SergeyBiryukov — 11 months ago
comment:8
SergeyBiryukov — 11 months ago
20943.2.diff brings the same change to the JS version.
- Keywords needs-unit-tests added
Unfortunately it's not that easy :)
The patch works for the above example html code but fails for:
<td>Test one Test two Test three</td>
The problem with <p> in block tags that can contain other blocks is that it's optional, i.e. it can be <td>some text</td> or <td><p>some text</p></td> or even <td>some text<p>some more text</p></td>.
We will need separate rules for these cases. The alternative is to standardize on always having the <p> in there, but that's undesirable.
Also, this would need good/extensive unit tests if we are to get it right.
comment:10
in reply to:
↑ 9
;
follow-up:
↓ 11
Otto42 — 11 months ago
Replying to azaozz:
The alternative is to standardize on always having the <p> in there, but that's undesirable.
I'd be perfectly okay with always adding the p in there. That's sort of the whole point of wpautop. :)
Also, this would need good/extensive unit tests if we are to get it right.
Agreed.
comment:11
in reply to:
↑ 10
azaozz — 11 months ago
Replying to Otto42:
I'd be perfectly okay with always adding the p in there. That's sort of the whole point of wpautop. :)
That may prove "unpopular". If a user wants a tight table like:
_____________ | abc | 123 |
it will turn it into:
_____________ | | | | abc | 123 | | | |
Also <li> is one of these "block parents" and we don't want to force <li><p>...</p></li> everywhere but still would need to support it.
All that gets even more complicated when adding HTML 5.0 into the mix. Unfortunately in HTML 5 there aren't clearly pre-determined block tags in the same sense as in HTML 4 / XTHML 1. Most of the block rules there are "<p> can contain <a> but not if <a> contains block tag".
comment:12
JboyJW — 11 months ago
- Cc JboyJW added
comment:13
nacin — 8 months ago
My take: Paragraphs, if specified for table cells or list items, should remain and/or be corrected. But they shouldn't be added forcefully if they did not exist.
comment:14
SergeyBiryukov — 6 months ago
#22397 was marked as a duplicate.
comment:15
difreo — 5 months ago
- Keywords needs-patch added; has-patch removed
- Severity changed from normal to major
This issue is a horror. It also happens when you wrap your text in a <div> Why change something that was good in previous versions? "I know better what you want - (L)USER" - said the program...
comment:16
palpatine1976 — 5 months ago
- Cc palpatine1976 added
comment:17
markoheijnen — 5 months ago
- Severity changed from major to normal
Just out of curiosity if what Nacin said wouldn't that make the patch correct. It seems that it only applies for when you do insert paragraphs yourself.
comment:18
sillybean — 4 months ago
- Cc steph@… added
comment:19
knutsp — 4 months ago
- Cc knut@… added
comment:20
SergeyBiryukov — 4 months ago
#23324 was marked as a duplicate.
comment:21
SergeyBiryukov — 4 months ago
#19917 was marked as a duplicate.
comment:22
nic0tin — 3 months ago
- Cc nicolas.girardet@… added
comment:23
johanronstrom — 3 months ago
- Cc johanronstrom added
comment:24
SergeyBiryukov — 5 weeks ago
#24125 was marked as a duplicate.
comment:25
SergeyBiryukov — 5 weeks ago
- Version changed from 3.3.2 to 3.2
Reproduced in 3.2 as well. Could not reproduce in 3.1.

Confirmed, the issue is in TinyMCE somewhere.
To reproduce, make a new post in HTML mode with this text:
Switch to visual and back. Notice that the Test one and two are now combined. Updating the post and then the subsequent reload of the visual editor causes the same problem.