#26332 closed defect (bug) (fixed)
TinyMCE stripping <a id="abc"></a> on empty line
Reported by: | Ipstenu | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.2 |
Component: | TinyMCE | Keywords: | upstream close |
Focuses: | Cc: |
Description
From http://wordpress.org/support/topic/mce-editor-stripping-attributes-and-removing-tags?replies=7 (started 11 months ago)
If you type in <a href="#"></a>
in Text mode then switch to Visual and back, that tag gets replaced with a non-breaking space
Reported as an issue in 3.7.1
Attachments (1)
Change History (22)
#2
@
11 years ago
Excellent. I was only up to 3.5 testing when you posted this :) Thank you SergeyBot!
#6
@
11 years ago
Generally empty inline tags are considered "cruft" in HTML. They are "invisible" when the HTML is rendered (both on the front-end and inside TinyMCE), cannot be created using the editor and cannot be selected or edited inside the editor. Also, can be deleted without the user realizing it.
The reason an empty <a>
tag is replaced with
is because the <a>
is wrapped in a <p>
on switching to the Visual editor. Then on switching to the Text editor the content is cleaned up, the <a>
is stripped and the empty <p>
is preserved (by popular demand) by inserting
.
#7
@
11 years ago
I understand. Was this a change in TinyMCE's processing or ours? Since this did work pre-3.1 (My personal expectation is "Yeah, invisible things go away, don't cross the streams between editors.")
#8
@
11 years ago
Not sure about pre-3.1 but MCE has been removing empty <a> for quite some time. Note that the old style "anchors" still work: <a name="abc"></a>
is not stripped. In MCE 4.0 <a id="abc"></a>
is kept too.
This ticket was mentioned in IRC in #wordpress-dev by alaminopu. View the logs.
11 years ago
#10
@
11 years ago
- Keywords needs-testing has-patch added; needs-patch removed
TinyMCE was removing empty <a> node other than having attributes 'name' and 'id'. I just stopped it to do that.
This ticket was mentioned in IRC in #wordpress-dev by alaminopu. View the logs.
11 years ago
#12
@
11 years ago
- Keywords close added; needs-testing has-patch removed
26332.diff patches TinyMCE's core. We can't do that :)
As far as I see removing empty <a>
is the expected behavior and has been done for years. Don't see a compelling user case to stop it now.
#13
follow-up:
↓ 14
@
10 years ago
Note that the old style "anchors" still work: <a name="abc"></a> is not stripped. In MCE 4.0 <a id="abc"></a> is kept too.
With MCE 4, (WP 3.9+), this is true only IF the anchor isn't on its own line.
If the anchor is on its own line, then <a name="foo"></a> is preserved, but <a id="foo"></a> is converted to a non-breaking space.
#14
in reply to:
↑ 13
@
10 years ago
Replying to azaozz:
In MCE 4.0
<a id="abc"></a>
is kept too.
Replying to MadtownLems:
If the anchor is on its own line, then <a name="foo"></a> is preserved, but <a id="foo"></a> is converted to a non-breaking space.
Yeah, for me <a id="abc"></a>
disappears too.
#15
@
10 years ago
- Keywords close removed
Yeah, seems TinyMCE is too aggressive in removing empty <a> tags, <p><a id="abc"></a></p>
is treated as empty paragraph. Worth opening a ticket upstream.
#16
@
10 years ago
- Summary changed from TinyMCE stripping attributes and removing tags to TinyMCE stripping <a id="abc"></a> on empty line
#18
@
9 years ago
- Keywords close added
For accessibility, I think WordPress shouldn't encourage the usage of empty links. Reading the post on the support forum, also the usage of links for interactive controls
<a href="#"></a>
shouldn't be encouraged. Controls that behave like buttons should be buttons.
I don't see a use case for
<a id="abc"></a>
unless I'm missing something.
Just tested and
<a name="foo"></a>
is always preserved, both within a line of text and in its own line. Would propose wontfix :)
#19
@
8 years ago
@afercia A good use case is for linking to content further down the page or to specific content on another page (rather than landing at the top of the page). You can't do that with a name property, at least that I'm aware of. Having to put content within the link doesn't always make sense - for example, I may want to put it higher than the content I want to show so that the content ends up in the middle of the viewport, rather than at the top.
#20
@
5 years ago
- Resolution set to fixed
- Status changed from new to closed
Re-tested this in WP 5.2 and it seems to be working properly. Explicit anchors like <a name="foo"></a>
are kept regardless of where they are in the HTML. Elements that are considered "empty" are removed on cleanup. Adding anchors like:
<h3>Section title<a id="abc"></a></h3>
works properly.
This also works well in the block editor. Considering this ticket "fixed".
3.1 and older versions keep the link.
3.2 and 3.3 remove it completely.
3.4 and newer versions replace it with
.