Opened 17 years ago
Closed 19 months ago
#4298 closed defect (bug) (wontfix)
wpautop: Avoid wrapping <table> tags with a paragraph
Reported by: | Denis-de-Bernardy | Owned by: | markjaquith |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | minor | Version: | 2.7 |
Component: | Formatting | Keywords: | needs-patch needs-unit-tests wpautop |
Focuses: | Cc: |
Description
wpautop should at least ignore multiline html tags, and possibly ignore any area enclosed within html.
<table style="width: 120px; height: 92px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="7" cellspacing="2"> <tbody> <tr> <td><small><small style="font-family: Arial;">Once I saw it here, I instantly knew what I wanted. I love my new woven wood shades.</small></small><br> <small><small>- Ginny Good</small></small></td> </tr> </tbody> </table>
gets formatted as:
<table<br /> style="width: 120px; height: 92px; text-align: left; margin-left: auto; margin-right: auto;"<br /> border="1" cellpadding="7" cellspacing="2"><br /> <tbody> <tr> <td><small><small style="font-family: Arial;">Once<br /> I saw it here, I instantly knew what I wanted. I love my new woven wood<br /> shades.</small></small><br /><br /> <small><small>- Ginny Good</small></small></td> </tr> </tbody> </table>
Attachments (2)
Change History (44)
#4
@
17 years ago
- Priority changed from normal to low
- Severity changed from normal to minor
It should occur after escaping stuff we don't want to autop, though, i.e. scripts, objects, etc.
#6
@
16 years ago
- Keywords has-patch tested dev-feedback added
- Milestone changed from 2.9 to 2.8
- Version changed from 2.2 to 2.7
#9
@
15 years ago
- Keywords needs-patch added; has-patch tested dev-feedback removed
- Milestone changed from 2.8 to Future Release
better approach would be to apply this before saving the post's contents and excerpts.
#10
@
15 years ago
code I use in my plugin:
add_filter('content_save_pre', array('sem_fixes', 'fix_wpautop'), 0); add_filter('excerpt_save_pre', array('sem_fixes', 'fix_wpautop'), 0); add_filter('pre_term_description', array('sem_fixes', 'fix_wpautop'), 0); add_filter('pre_user_description', array('sem_fixes', 'fix_wpautop'), 0); add_filter('pre_link_description', array('sem_fixes', 'fix_wpautop'), 0); # # fix_wpautop() # http://core.trac.wordpress.org/ticket/4298 # function fix_wpautop($content) { $content = str_replace(array("\r\n", "\r"), "\n", $content); while ( preg_match("/<[^<>]*\n/", $content) ) { $content = preg_replace("/(<[^<>]*)\n+/", "$1", $content); } return $content; } # fix_wpautop()
#12
@
15 years ago
- Keywords has-patch tested commit added; needs-patch removed
- Milestone changed from Future Release to 2.8
#14
@
15 years ago
Before we carry on modifying autop I would really like to see a set of test cases written using the wordpress-tests setup so that we can really get a defined behaviour for this function and iron out all the bugs ;-)
I'm not sure we should make any changes to it's behaviour without these tests.
#15
@
15 years ago
- Milestone changed from 2.8 to Future Release
agreed to a large extent. but I won't be writing them (I currently have a miles long list of things to do already).
punting this to future pending the unit tests.
#16
@
15 years ago
- Milestone changed from Future Release to 2.8
doh, wait. I thought this was another ticket.
it's not a wpautop ticket, or rather it is, but it fixes a genuine bug in it. you don't need a unit test for this one. the stuff in the patch is done by the latest tinymce already. it's the php version that has a problem.
it merely turns stuff like:
<p class="foo">
... which gets wrecked by wpautop, into:
<p class="foo">
it has been working successfully for over a year on thousands of sites, and bugs would have been reported long ago if any were present.
the while loop stands for: until there is no open tag (<) followed by a newline char, turn the newline char into a space.
#17
@
15 years ago
until there is no open tag (<) followed by a newline char before it's closed, turn the newline char into a space. even.
#18
@
15 years ago
the ticket that needs unit tests is #3833. this one needs absolutely none of it. it's a bug, and the suggested patch is absolutely harmless.
#23
@
15 years ago
- Milestone changed from 2.9 to 3.0
- Owner set to markjaquith
- Status changed from assigned to accepted
Early 3.0, for sure. Just hadn't seen this until now.
#24
@
15 years ago
- Keywords needs-patch added; has-patch tested commit removed
A quick note on this one, because an issue was brought to my attention a few weeks ago. My patch actually breaks things such as:
<?php $foo = $bar; ?>
What I'm currently doing, in case it inspires a better solution:
/** * fix_wpautop() * * @param string $content * @return string $content **/ function fix_wpautop($content) { $content = str_replace(array("\r\n", "\r"), "\n", $content); if ( !preg_match("/<[a-z][^<>]*\n/i", $content) ) return $content; global $sem_fixes_escape; $sem_fixes_escape = array(); $content = preg_replace_callback("/<\?php.+\?>/is", array('sem_fixes_admin', 'escape_php_callback'), $content); while ( preg_match("/<[a-z][^<>]*\n/i", $content) ) { $content = preg_replace("/(<[a-z][^<>]*)\n+/i", "$1", $content); } if ( $sem_fixes_escape ) $content = str_replace(array_keys($sem_fixes_escape), array_values($sem_fixes_escape), $content); return $content; } # fix_wpautop() /** * escape_php_callback() * * @param array $match * @return string $out **/ function escape_php_callback($match) { global $sem_fixes_escape; $tag_id = "----sem_fixes_escape:" . md5($match[0]) . "----"; $sem_fixes_escape[$tag_id] = $match[0]; return $tag_id; } # escape_php_callback() # http://core.trac.wordpress.org/ticket/4298 add_filter('content_save_pre', array('sem_fixes_admin', 'fix_wpautop'), 0); add_filter('excerpt_save_pre', array('sem_fixes_admin', 'fix_wpautop'), 0); add_filter('pre_term_description', array('sem_fixes_admin', 'fix_wpautop'), 0); add_filter('pre_user_description', array('sem_fixes_admin', 'fix_wpautop'), 0); add_filter('pre_link_description', array('sem_fixes_admin', 'fix_wpautop'), 0);
#25
follow-up:
↓ 26
@
15 years ago
Think this is mostly fixed now. It can only happen when using the HTML editor. By default the visual editor removes all line breaks (except in <pre> tag) as they are insignificant and the JS version of autop removes any breaks inside tags when switching HTML to visual. What remains is perhaps post by email, atompub, etc.
#26
in reply to:
↑ 25
@
15 years ago
Replying to azaozz:
Think this is mostly fixed now. It can only happen when using the HTML editor. By default the visual editor removes all line breaks (except in <pre> tag) as they are insignificant and the JS version of autop removes any breaks inside tags when switching HTML to visual. What remains is perhaps post by email, atompub, etc.
The user who reported it was pasting HTML code from Dreamweaver, I think, into the HTML editor. It was a real annoyance (for him anyway). You're welcome to close if you're not interested in fixing it; only a handful of users reported the issue to me, and I've a plugin that adds the above-mentioned filters.
#29
@
15 years ago
There are several tickets about autop and HTML block elements that can contain other blocks. Think we should handle them together but first will need well made test cases as @westi suggests. Without them don't think we will be able to do this properly.
#30
@
14 years ago
- Keywords wpautop added
- Milestone changed from 3.0 to Future Release
Moving to future, we need test cases and maybe we can take care of the whole group of wpautop tickets.
#31
@
11 years ago
- Keywords wpautop early dev-feedback removed
Tested: Works in visual fails in Text.
#33
@
9 years ago
- Keywords needs-unit-tests added; wpautop removed
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from accepted to closed
Closing as wontfix. Complete lack of interest on the ticket over the last 6 years. Feel free to reopen when more interest re-emerges (particularly if there's a patch)
#34
@
9 years ago
- Keywords wpautop added
- Milestone set to Future Release
- Resolution wontfix deleted
- Status changed from closed to reopened
#35
@
20 months ago
Just tested:
<table style="width: 120px; height: 92px; text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="7" cellspacing="2"> <tbody> <tr> <td><small><small style="font-family: Arial;">Once I saw it here, I instantly knew what I wanted. I love my new woven wood shades.</small></small><br> <small><small>- Ginny Good</small></small></td> </tr> </tbody> </table>
And now generates:
<p><table style="width: 120px; height: 92px; text-align: left; margin-left: auto; margin-right: auto;" cellspacing="2" cellpadding="7" border="1"> <tbody> <tr> <td><small><small style="font-family: Arial;">Once I saw it here, I instantly knew what I wanted. I love my new woven wood shades.</small></small><br> <small><small>– Ginny Good</small></small></td> </tr> </tbody> </table></p>
We can see that just ignored all the HTML content and added a paragraph to wrap everything.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
19 months ago
#38
@
19 months ago
So our discussion right now is to understand if it is valid that a paragraph can include a table or not as for the spec https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p is not clear.
I will investigate on that.
#39
follow-up:
↓ 42
@
19 months ago
- Keywords close removed
- Summary changed from wpautop bugs to wpautop: Avoid wrapping <table> tags with a paragraph
As per today's Old Tickets Triage session, it looks like there is still an issue: <p> element can't contain <table> elements (see MDN Specs).
#40
@
19 months ago
Just a HTML example to test in the W3C validator (https://validator.w3.org/#validate_by_input):
<!DOCTYPE html> <html lang="en"> <head> <title>My Table-y paragraph.</title> </head> <body> <p> <table> <tr> <td>Hello</td> </tr> </table> </p> </body> </html>
#41
@
19 months ago
So reading the spec https://www.w3.org/TR/html4/struct/text.html#h-9.3 (I think that is the same as HTML5 the W3C validator infact report it as error) paragraph cannot contain a table element.
Reading seems that we open a paragraph, we add a table and the close of the table tag close the paragraph.
This means that we need to fix wpautop and add some tests for that case.
#42
in reply to:
↑ 39
@
19 months ago
- Milestone Future Release deleted
- Resolution set to wontfix
- Status changed from reopened to closed
Replying to audrasjb:
it looks like there is still an issue: <p> element can't contain <table>...
Yes, generally wpautop doesn't support tables. There is a workaround: no line breaks between any of the table tags (tr, td, etc.). Then the tables mostly work properly.
This ticket hasn't been fixed for 19 years because similar changes to wpautop tend to introduce bugs and other/new edge cases. Another reason is that some of the incorrect behavior may be expected by other code and fixing it would break that code.
Re-closing as "wontfix" seems the right thing to do here.
Reformatting tags like this before auto-formatting might work:
$str = preg_replace("/
D.