[wp-trac] [WordPress Trac] #43394: wpautop inserts extraneous line breaks if hard return around commented content
WordPress Trac
noreply at wordpress.org
Fri Feb 23 20:02:20 UTC 2018
#43394: wpautop inserts extraneous line breaks if hard return around commented
content
--------------------------+-----------------------------
Reporter: davidshq | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.9.4
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Problem: If one has code comments before content in a WordPress post/page
and there are hard returns before and after the code comment, WordPress
will insert an extraneous line break. Further, if there are hard returns
between multiple comments an extraneous line break will be added.
This problem can be reproduced by doing the following:
1. Edit a WordPress post or page.
2. Add a code comment with hard returns before and after it such as:
{{{
<!-- My Code Comment-->
}}}
3. Publish/preview the page.
4. Use Inspect to examine the area where you placed the above comment and
you'll notice an extra line break.
This may seem like a very edge case and a minor annoyance, but we ran into
this issue recently when we had multiple code comments following each
other like so:
{{{
<p>Some regular content here.</p>
<!-- This is Important -->
<!-- Don't Forget This -->
<!-- Why are you Forgetting? -->
<!-- Adding individual comments for each line is -->
<!-- fun! -->
<p>Some regular content here.</p>
}}}
An extraneous line break now becomes four line breaks.
This becomes quite confusing for editors as when they look at the post the
extra returns are not apparent yet inserted when the page is actually
posted.
I'm thinking that resolving this issue might also resolve many other cases
of wpautop gone rogue.
My suggestion would be that wpautop be changed so that:
1. If there is a code comment with a hard return before and after the
comment, it does not automatically add wpautop. (one can argue that this
is behaving as expected, but I doubt many are thinking when they add a
code comment that it will add a nice line break for them...and in any
case, this can be much more obviously/easily remedied by inserting a <br>
in the editor if one truly did want a line break caused in this manner,
whereas it can be quite time consuming to discover why extra line breaks
are mysteriously appearing)
2. Similarly, with shortcodes, if the shortcode is tested valid then don't
add line breaks with wpautop around the shortcode.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43394>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list