Opened 3 years ago

Closed 3 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 3 years ago by Piotrek Koszuliński

Milestone: CKEditor 4.5.2
Status: newconfirmed
Version: 4.4.63.0

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:

allowedContent: 'a[!name,id]',

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.

comment:2 Changed 3 years ago by Henning

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 3 years ago by Szymon Kupś

Owner: set to Szymon Kupś
Status: confirmedassigned

comment:4 Changed 3 years ago by Olek Nowodziński

Owner: Szymon Kupś deleted
Status: assignedconfirmed

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 3 years ago by Piotrek Koszuliński

Owner: set to Piotrek Koszuliński
Status: confirmedassigned

comment:6 Changed 3 years ago by Piotrek Koszuliński

Milestone: CKEditor 4.5.2CKEditor 4.5.3

comment:7 in reply to:  6 Changed 3 years ago by Olek Nowodziński

Replying to Reinmar: So it's bigger that expected?

comment:8 Changed 3 years ago by Piotrek Koszuliński

No, it isn't. I just won't be able to properly review it in 4.5.2.

comment:9 Changed 3 years ago by Olek Nowodziński

Milestone: CKEditor 4.5.3CKEditor 4.5.4

comment:10 Changed 3 years ago by Piotrek Koszuliński

Status: assignedreview

I pushed branch:t/13516b. As you can see it was quite easy, nothing philosophical.

comment:11 Changed 3 years ago by Szymon Kupś

Resolution: fixed
Status: reviewclosed

Merged changes into master with git:1f1a9b3.

Note: See TracTickets for help on using tickets.
© 2003 – 2017 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy