[wp-trac] [WordPress Trac] #2833: wpautop breaks style and script tags
WordPress Trac
noreply at wordpress.org
Tue Apr 23 19:20:12 UTC 2019
#2833: wpautop breaks style and script tags
--------------------------------------------+-----------------------------
Reporter: Nazgul | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: low | Milestone: Future Release
Component: Formatting | Version: 2.0.3
Severity: normal | Resolution:
Keywords: wpautop has-patch dev-feedback | Focuses:
--------------------------------------------+-----------------------------
Comment (by aduth):
Since Gutenberg implements a direct JavaScript port of the PHP
implementation, it too suffers the same issues described here, which is
particularly problematic when considering that it applies `autop` to
pre-5.0 content for compatibility between block- and non-block content.
A description of the issue and related findings at:
https://github.com/WordPress/gutenberg/issues/9056#issuecomment-485885555
For that reason, I was inspired to pull some of the work here in
comment:19 and comment:23 toward a fix in Gutenberg's JavaScript-based
implementation:
https://github.com/WordPress/gutenberg/pull/15129
In doing so, I have some remarks on the proposed patches for the PHP
implementation:
@pento's patch at attachment:2833.3.diff :
- It did serve to avoid the addition of `br` elements where linebreaks
occur in `script` and `style` tags, but did not help the issue with the
addition of `p` elements.
- In the `else` path of the patch, there is a reference to an unset
`$replace` variable. I believe this should be revised to `$replace_pairs[
$needle ]`.
- I may be mistaken, but I believe the `$i += 2` in the `else` path of the
patch should instead be `$i++`, as otherwise it can skip the fragments of
text which include newlines.
@cmmarslender patch at attachment:2833.2.diff :
- This resolves both issues of `br` elements and `p` elements insertion.
In fact, it resolves it so well it should also include removal of the
previous attempts to fix the issue added in r3965 (it's no longer
necessary to create the temporary `WPPreserveNewline`)
Another issue I'd encountered -- not reflected in an patches here -- is
that script tags are wrongly ''wrapped'' in a `p` tag:
{{{
wp> wpautop( '<script></script>' );
=> string(25) "<p><script></script></p>
}}}
As best I can tell, the resolution here is to include `script` in the set
of `$allblocks`, as is done already for `style`:
https://github.com/WordPress/wordpress-
develop/blob/1b9fd43f259f20313f3e6a269d7cbf20a819fca6/src/wp-
includes/formatting.php#L495
--
Ticket URL: <https://core.trac.wordpress.org/ticket/2833#comment:36>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list