Problem/Motivation
In our websites we don't want to allow site builders to insert <div> elements into the CKEditor. They often copy/paste text from text editor programs like Microsoft Word and most of the time it leads to formatting/styling issues.
Steps to reproduce
When you save the CKEditor configuration is add's the <div> element to the allowed formats.
Proposed resolution
We've seen that the last version of https://github.com/akilli/ckeditor4-detail/blob/master/plugin.js inserts a temporary <div> that get's removed in the downcast function. We have modified the plugin.js file to resemble that one and it seems to work. We also removed the drupal media references as they don't seem to be necessary.
Remaining tasks
Check if this still works for other use cases
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | ckeditor-details-no-eval-build-3244311-24.patch | 17.54 KB | ptsimard |
| #18 | 3244311-18.diff | 18.15 KB | rhezios |
| #15 | detail before_1.png | 150.2 KB | roshanibhangale |
| #15 | detail before.png | 150.36 KB | roshanibhangale |
| #15 | detail after.png | 148.38 KB | roshanibhangale |
Issue fork ckeditor_details-3244311
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
gertlor commentedComment #3
gertlor commentedComment #4
timohuismanWe've been using this patch in some of our production sites for a few months now with no issues. Just tested it again with version 2.0.3 against drupal/core:9.4.5, works as intended.
Comment #5
mandclu commentedThe patch seems to change the indentation, which makes it difficult to see what code changes are actually being proposed. Can we get an updated patch that doesn't change the indentation? Also, it would be useful to know if the same changes are needed for the CKEditor5 version of the plugin introduced in the 2.1.x branch.
Comment #6
casey commentedPatch for CKEditor 5 (only) support
Comment #7
nvandijk commentedI've tested 3244311-6.patch, running into a few issues.
The order of the elements changes on load of the editor.
To reproduce:
<p>) to itVideo demonstrating the issue (also attached)
Some elements get stripped from the content of the details, such as heading elements.
To reproduce:
<p>Video demonstrating the issue (also attached)
Please note that this not only happens when switching from source editing to regular editing, also when re-opening the edit page after saving. Without switching in between the values in the database are 'correct' but get swapped when opening the editor again. Headings are still allowed, just disappear when opening the editor again.
Comment #8
nvandijk commentedComment #9
smulvih2I tested patch #6, was running into the same issues reported in #7. In my case, I have a large migration, and migrated
<details>elements didn't have the contents wrapped in a<div>. This would result in the plugin removing all contents of thedetailWrapperexcept the<summary>element.My new patch extends #6 and fixes the reported issues in #7. Now the migrated content works as expected and the plugin handles the markup correctly.
Outline of changes
Upcast Converter
Introduces explicit handling of
<summary>usingconvertItemto differentiate between<summary>and other child elements. This ensures<summary>maps todetailSummaryand all other children map todetailWrapper, maintaining the correct order.Data Downcast Converter
Explicitly removes
<div>from the serialized output by usingcreateSlotfordetailWrapper. Adds logic to serialize<summary>first and then process all other child elements ofdetailWrapperin their original order.Editing Downcast Converter
Dynamically appends child elements to the editable
details-wrapperdiv in their original order, ensuring no reordering during editing.I just tested a complex details element containing
<p>tags,<div>tags, h2 heading, and nested<details>elements and the changes seem to be working as expected.Comment #10
timohuismanI've tested #9 with
drupal/core:10.3.7anddrupal/ckeditor_details:2.1.0-beta1.The issues mentioned in #7 are resolved. I've created a details element with a few different tags and they all stayed in the expected order after switching between the 'source editing' modus.
Back to RTBC.
Comment #11
smulvih2Need this patch again on a upgrade from D9-D10. Existing details content is not wrapped in a single
<div>, so without this patch all body content of the details element is removed in node edit for CKE5.Comment #14
dydave commentedThanks a lot everyone for the great work on this issue!
Quick follow-up on #5:
I've created an initial merge request above at #13 for the 2.1.x branch, based on the patch above at #9:
I have tested a bit the changes myself locally and they seemed to work pretty well, great job! 👍
One thought though:
Could this be something we would like to be able to configure? Enable/disable, for example, or maybe select a tag (from a dropdown list)?
Or do you it be fine to just switch over to use the
<p>tag?Therefore, at this point, moving back issue to Needs review, as an attempt to collect more feedback, comments and reviews.
Feel free to let us know if you have any questions, suggestions or concerns on any aspects of the merge request or this issue in general, we would surely be glad to help.
Thanks in advance! 🙂
Comment #15
roshanibhangale commentedHi
have manually tested MR 9 on Drupal 2.1.x version.
The MR is applied Successfully...
The CKEditor 's detail element is able to place without
Attaching screenshot for reference
RTBC+1
Comment #16
smulvih2@dydave this should not be configurable, we should just allow any markup inside the
<details>element. In a few of my projects where we have migrated content, we have<details>elements with different elements inside, like<p>,<ul>,<div>, etc... And this is valid markup so we should allow this. By default, if you create a<details>element in CKE5 with this patch, and type some text, it will wrap in a<p>tag as expected.Comment #17
smulvih2Need patch #9 on yet another project. Client is used to entering HTML manually in CKE4, but complains that in CKE5 the contents of their details element are being stripped. I told them a workaround is to add their content within a
<div class="details-wrapper">but they were keen to get this patch included so they can continue to author with valid markup as they did in CKE4.Can we get this included in a new release? I have used this patch on 3 projects now and it's working as expected.
Comment #18
rhezios commentedPatch #18 contains a snapshot of MR!9 containing the recompiled assets
Comment #19
mandclu commentedThe div wrapper was intentionally added in #3159065: Wrap details content in a div.details-wrapper to match the expected markup by drupal/collapse to match the markup expected by the shim in Drupal core. I recognize that was years ago and caniuse now lists browser support for details elements at around 96%. TBH I'm not sure if core even contains this shim anymore, but keeping the shim should allow details elements created by this module to match any created by core.
I would personally lean towards making this configurable, but I'm also open to other perspectives.
Comment #20
dydave commentedThanks Martin (@mandclu)!
Same comment I had above at #14.
Stephen (@smulvih2) is this something that could be added to the MR?
Stephen, this would perhaps allow a smoother/easier integration of this feature to the module by allowing to keep the existing/current behavior, while still being able to extend/override with specific site configurations.
Thanks again everyone for the great work on this feature!
Comment #21
smulvih2From my experience on the three projects noted above, completely removing the wrapping
<div>elements fixes all issues across the following scenarios:<details>element (p, div, h2, ul, etc...)From testing on these projects, no issues reported across browsers. I have used this patch on both Drupal 10 and Drupal 11.
I'm not sure what benefit it would give to allow the nesting under the single div again as an option. Maybe we can get this into an alpha/beta version and get some feedback from users? Not sure of best way to move forward besides keep using this patch on my projects :)
Comment #23
liam morlandComment #24
ptsimard commentedCKEditor was failing to load due to CSPs because patch #9 replaced js/build/detail.js with a webpack build that uses eval(...).
Our Content Security Policies does not allow 'unsafe-eval', and CKEditor’s docs say self-hosted CKEditor 5 should work with script-src 'self' without requiring it.
Patch #24 keeps the same Drupal behavior change, but rebuilds detail.js without eval(...).
Comment #25
liam morlandComment #26
liam morlandRerolled.
I have added the eslint fixes from #3611707: Fix issues raised by eslint.
That issue should be merged before this.It has now been merged. The eslint checks are now passing.Comment #27
scotwith1tMR !9 is working for me. We had a similar situation as #9 where we migrated in a large amount of these elements and won't have the requisite wrapper and enabling this without the patching strips the details altogether. Thanks! RTBC to me...
Comment #29
liam morlandThanks everyone!