Opened 9 years ago
Closed 9 years ago
#13516 closed Bug (fixed)
CKEditor removes empty html5 anchors without name attribute
Reported by: | Henning | Owned by: | Piotrek Koszuliński |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 4.5.4 |
Component: | General | Version: | 3.0 |
Keywords: | Cc: |
Description
Since the name attribute is obsolete for a elements in html, we made a plugin variant that creates anchors with id attribute only.
However, the anchor elements with just an id attribute are removed by CKEditor automatically.
From https://dev.ckeditor.com/ticket/10325 I do understand that you have to remove anchor elements that cannot be edited. But anchor elements having just an id (and no name) attribute are html5, and can be edited at least by our plugin variant.
I don't find a configuration of allowedContent or so to let CKEditor preserve <a id="x"></a>.
From the CKEditor source code, I see that you remove as follows:
- In core\htmldataprocessor.js
// Remove empty link but not empty anchor. (#3829) a: function( element ) { if ( !( element.children.length || element.attributes.name || element.attributes[ 'data-cke-saved-name' ] ) )
- In function validateElement
case 'a': // Code borrowed from htmlDataProcessor, so ACF does the same clean up. if ( !( element.children.length || element.attributes.name ) )
My suggestion is allowing to somewhere configure the attributes (other than name) which, if set, preserve empty a elements...
Change History (11)
comment:1 Changed 9 years ago by
Milestone: | → CKEditor 4.5.2 |
---|---|
Status: | new → confirmed |
Version: | 4.4.6 → 3.0 |
comment:2 Changed 9 years ago by
Hi Reinmar,
thank you for scheduling this issue. So we can look forward to remove my rather ugly workaround (temporarily add names to the anchors when editing the text in CKEditor).
Best, Henning
comment:3 Changed 9 years ago by
Owner: | set to Szymon Kupś |
---|---|
Status: | confirmed → assigned |
comment:4 Changed 9 years ago by
Owner: | Szymon Kupś deleted |
---|---|
Status: | assigned → confirmed |
It looks like it needs Reinmar's attention because we're hitting a bus factor wall.
Different approaches in branch:t/13516 and branch:t/13516-research.
comment:5 Changed 9 years ago by
Owner: | set to Piotrek Koszuliński |
---|---|
Status: | confirmed → assigned |
comment:6 follow-up: 7 Changed 9 years ago by
Milestone: | CKEditor 4.5.2 → CKEditor 4.5.3 |
---|
comment:9 Changed 9 years ago by
Milestone: | CKEditor 4.5.3 → CKEditor 4.5.4 |
---|
comment:10 Changed 9 years ago by
Status: | assigned → review |
---|
I pushed branch:t/13516b. As you can see it was quite easy, nothing philosophical.
comment:11 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | review → closed |
Merged changes into master with git:1f1a9b3.
I agree. The core should not make a decision about such thing itself or it should be configurable. I would keep empty anchors with id or name and base the removal on ACF's settings. For instance, currently the anchor features allows this:
It means that even when we remove that code from HTMLDP and filter.js that anchor will be removed because name is required. But it's ok, because the anchor feature does not recognise such anchors so they are not transformed into fake objects and cannot be edited (this is a thing for a separate ticket if someone misses it). But the point is that we'll unblock other developers who will be able now to use empty anchors without names.