I believe this doesn't surface as a problem out of the box due to class not being allowed within a elements for Basic HTML, however, if it is, e.g. in Full HTML: ck-anchor class gets added to the data view and saved to the page -- if the page is then subsequently re-edited that class persists and causes some problems:
To reproduce
- Install Drupal with standard profile
- Add the anchor link button to the full html format
- Create new basic page node
- Change format to full html
- Insert some text
- Select the text and click the anchor button - create an anchor
- Save the node
- Inspect the source, the node is rendered with (for example):
<p><a id="test" class="ck-anchor">This is my paragraph</a></p>
Observed Issues
When then re-editing the saved node, issues are as follows:
- Placing the cursor at the beginning of the anchor text link will visually insert another anchor flag, at the beginning of the anchor text link
- Actioning the edit (pencil icon) and making a change to the anchor name will visually insert another anchor flag, at the end of the anchor txt link
- Actioning the unanchor button visually removes it at the start, but replaces an anchor flag where the cursor was positioned, then following the cursor around as repositioned, and the class remaing, e.g.:
<a class="ck-anchor">anchor text</a>
But the issue will need to be attended to in the ckeditor5-anchor-drupal plugin so I made a pull request: https://github.com/northernco/ckeditor5-anchor-drupal/pull/10
With this in place the class does not get saved into the data view and the issues above are not reproducible.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3438755-demo-after-fix.gif | 524.88 KB | justcaldwell |
| #9 | 3438755-demo-before-fix.gif | 865.25 KB | justcaldwell |
Comments
Comment #2
ericgsmith commentedThis is indeed an issue for 2 scenarios.
<a class>for manually edited source tags (possible if you are not using the style plugin)I have verified this issue on a clean install using both scenarios.
Expected result - it should be rendered as:
Producing the ghost anchor issue
The anchor is removed icon is visible in the WYSIWYG and editor can not remove it:
Using the ckeditor5_dev module I can see empty a tag remains in the view where the cursor is placed:
Viewing the model it looks like it persists with class attribute set
After saving the node the empty a tag remains in the rendered HTML.
<p>This is my p<a class="ck-anchor"></a>aragraph</a></p>Editing the node again produces the same behaviour - there is a ghost anchor that can only be removed by manually editing the source.
Testing with the MR and it resolves the issue:
class="ck-anchor"attribute.Comment #3
ericgsmith commentedComment #4
klidifia commentedComment #5
ericgsmith commented@klidifia the change works - I have left a minor comment on the MR - please ping me if that suggested change looks good / works and I will retest.
Comment #6
klidifia commentedComment #7
klidifia commented@ericgsmith thank you and yes I tested the suggested changes and it works - updated the PR with it.
Comment #8
justcaldwellHello! I'm curious what version of core this is happening with.
I was unable to reproduce this issue in a fresh install of 10.2.7. I followed the steps in the IS and #2 -- using full html, no ghost anchor flags appear, the rendered markup is free from extra
<a>tags, ckeditor dev inspector looks fine.Comment #9
justcaldwellI am still unable to replicate this issue with a clean install of Drupal (now 10.3.5), BUT I did notice it was happening in our production site. I haven't figured out why — maybe there's an interaction with some other plugin/config that's not present in the clean install (?).
At any rate, I tested with the change from the MR and the issues are resolved when creating new content (thank you!). Note that any existing content that was saved with the
ck-anchorclass will still exhibit the problem, so that would still need to be sorted out.Below are recordings of the before-and-after behavior. The issues are numbered according to the Observed Issues list in the issue summary. I should also note that I've only been able to trigger "issue #1" when the anchor is the first child of a given DOM node.
Before Fix
After Fix
Comment #10
martybfly commentedAnyone got any suggestions as to how we can create a patch for this issue?
I can probably create a patch that edits the 'src' files, but not sure how the files in the 'build' folder would get updated, or even how I would build these files manually.
Any suggestions welcome.
Thanks, Martin
Comment #11
rajab natshahSame fix for the Vardot fork of the library: https://github.com/Vardot/ckeditor5-anchor-drupal/pull/21
The ck-anchor class is added only on the editing downcast now, so it stays out of the saved data. Verified on Drupal 11 and Varbase 11 with Full HTML.
Note for whoever lands this: the functional test 03-01-01-anchor-source-editing.feature asserts that the editor data contains "ck-anchor", so it needs to be inverted in the same change.
Thank you, klidifia and ericgsmith :)
Comment #12
rajab natshahThis is fixed and released in vardot/ckeditor5-anchor-drupal 2.0.5 :)
https://github.com/Vardot/ckeditor5-anchor-drupal/releases/tag/2.0.5
The ck-anchor class is added only on the editing downcast now, so it never reaches the saved content. Verified with the released package on Drupal 11 and Varbase 11.
Thank you so much, klidifia for the fix and ericgsmith for the careful review, and martybfly for following up on how to build it :)
Comment #13
rajab natshahComment #15
rajab natshah✅ Released anchor_link-3.0.5