Allow inline HTML comments in ckeditor

Created on 18 February 2023, over 2 years ago

Problem/Motivation

It is common to use HTML comments in HTML content to document the contents. It is not currently possible to do this in the editor.

Steps to reproduce

In a piece of content with the ckeditor present.
In the editor, click the "Source" button to expose the HTML source.
Enter a comment, e.g. <!-- Hello world. -->
Disable the source mode.
Click the "Source" button again.
The comment will have been removed.

Proposed resolution

Provide a plugin that (optionally) allows HTML comments to be added to the content in ckeditor5.

Remaining tasks

Work out how to do this.

User interface changes

It will be possible to add HTML comments in the ckeditor5 editor.

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

โœจ Feature request
Status

Active

Version

10.1 โœจ

Component
CKEditor 5ย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @damienmckenna
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA

    This is an unstable feature that is not available by default, with some known issues:

    By default, all HTML comments are filtered out during the editor initialization. The HTML Comments feature allows developers to keep them in the document content and retrieve them back, e.g. while saving the editor data. The comments are transparent from the users point of view and they are not displayed in the editable content.

    The HTML comment feature is experimental and not yet production-ready.

    The support for HTML comments is at the basic level so far - see the known issues section below.

    This feature is enabled by default in the superbuild only. See the installation section to learn how to enable it in your editor.

    https://ckeditor.com/docs/ckeditor5/latest/features/general-html-support...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA

    There is a premium plugin that supports a custom comment style:
    https://ckeditor.com/docs/ckeditor5/latest/installation/plugins/features...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    That makes sense. ๐Ÿ‘

    I'll work with @lauriii to prioritize this in ๐ŸŒฑ [meta] [upstream] Prioritized CKEditor 5 upstream blockers Active . I'll bring it up at today's meeting I have with the CKEditor 5 developers.

  • Status changed to Postponed over 2 years ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Discussed with @lauriii and now prioritized โ€” see #3340578-7: [meta] [upstream] Prioritized CKEditor 5 upstream blockers โ†’ .

  • Status changed to Needs review over 2 years ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Clarifying the issue summary: the necessary plugin already exists upstream but has significant issues.

    But โ€ฆ I think that in this case, it's probably better to have some support rather than none? Although perhaps that would be more infuriating?

    Either way, I think that this is all that's needed โ€” untested, please give it a try ๐Ÿ˜Š

  • Status changed to Needs work over 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Applied the patch on Drupal 10.1 standard install
    Added

    <!-- Hello world. -->

    to the source of the ckeditor
    Clicked source again and it's gone.

  • Status changed to Postponed over 2 years ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    You probably ran into https://github.com/ckeditor/ckeditor5/issues/10118 then ๐Ÿ˜ฌ

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA

    I can't get the patch to work, it removes all comments no matter where they're placed, not just within certain HTML tags.

    Are there suppose to be any changes necessary on the text format to make it work?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Are there suppose to be any changes necessary on the text format to make it work?

    Not that I know of, but for the sake of testing, could you test it on a format that has no filters at all? ๐Ÿ™

  • ๐Ÿ‡ช๐Ÿ‡ธSpain navneet0693 Madrid

    I am having the same issue as suggested in https://www.drupal.org/project/drupal/issues/3342874#comment-14943480 โœจ [upstream] Allow inline HTML comments in ckeditor5 Postponed

    Also, I did checked on latest Drupal 10 installation with Basic HTML text editor, it behaved the same.

    The following

    <!--
    comment
    -->
    

    was stripped when we go out of source ediiting mode.

  • Status changed to Active almost 2 years ago
  • ๐Ÿ‡ช๐Ÿ‡ธSpain navneet0693 Madrid
  • First commit to issue fork.
  • Status changed to Needs review almost 2 years ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    I found that our core drupalHtmlEngine plugin is stripping out the comments. Tracing it back this was originally added in #3247246: Attribute value encoding not compatible with Xss::filter() โ†’ . I've added HTML comment support to the drupalHtmlEngine plugin. I'm not 100% sure about the approach, feedback please!

    I opened an MR to make code review easier and I'm attaching a patch with the same changes.

    Testing note: If you test by adding only an HTML comment to the editor with no other content, it will still be removed. You need to add something else: an HTML element or text for example. This seems to be the case for the upstream plugin as well so I don't think that bug is on our side: https://ckeditor.com/docs/ckeditor5/latest/features/html/html-comments.html

    Issue management note: I'm removing 'upstream' from the title because I think we have what we need to implement this but I do realize there are known issues with the upstream plugin and it's experimental. Maybe we can get something into core and then open another issue to track the known upstream issues?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States luke.leber Pennsylvania

    Aren't data loss issues supposed to be triaged as critical?

    This seems more severe than a normal data loss issue because it may be months or years until someone actually notices that data has gone missing! Maybe even so long that revision pruning has made the data unrecoverable!

  • last update almost 2 years ago
    30,487 pass, 1 fail
  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @star-szr in #17: Oh, hi again! ๐Ÿ˜„ After running into a colleague of yours at DrupalCon Lille and then seeing you on the GitLab CI Nightwatch issue, I'm now seeing you everywhere somehow ๐Ÿ˜Š

    Thanks for the research! And in fact โ€ฆ the MR looks pretty much ready! What I'm missing is a bit more test coverage: the Nightwatch JS unit test is great, but I think we want at least one end-to-end test. A new test method in \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test seems appropriate?

    @Luke.Leber in #18: Yes. But HTML comments have historically never contained actual content. Exceedingly rarely sites are putting critical content in HTML comments โ€ฆ a statement that seems to be confirmed by the fact this issue has only 11 followers. See #5 and #6 for the considerations @lauriii and I put into this.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    Hi @Wim Leers! This year I have been leading the project on our team to integrate CKEditor 5 which has involved porting and updating a contrib module โ†’ , adding table footer support to CKEditor 5 upstream, a few custom CKEditor plugins, and now this issue! So I suppose it was inevitable we would run into each other and itโ€™s always nice to see a friendly face in the queues (and on GitHub)!

    I will work on the test coverage, and agree that itโ€™s missing.

    Oh and thanks for adding the related issue. I did that at one point but had to fight with this form a bit (hence why it says there are so many patches from me in Credit & committing, I believe).

  • Status changed to Needs review almost 2 years ago
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    Now with more tests!

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    I was seeing a failure in TimestampFormatterWithTimeDiffTest and one other similar one, seems like a random fail, re-ran and it passed. I re-ran Nightwatch and the failure switched from one to another so also seems random.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Could be a coincidence for sure but I've never seen randoms back to back to back like that. Wonder if a change is causing the random errors to appear more frequent. What if we took out the change to nightwatch? Change is covered by the FunctionalJavascript test right?

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    If we remove the Nightwatch change it should be failing every time, in other words we need that change. I'm going to try running Nightwatch again.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    Same failure as last time, in Tests/Olivero/oliveroSearchFormTest. https://git.drupalcode.org/issue/drupal-3342874/-/jobs/288500#L174

  • Status changed to RTBC almost 2 years ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @star-szr in #20: ๐Ÿ˜Š๐Ÿ˜Š

    @smustgrave in #23: I've been seeing it earlier today in a completely different issue too. I suspect it's a Docker image/Chrome version/infra change thing.

    IOW: there are definitely random JS failures again โ€ฆ ๐Ÿ˜ฌ

    No more remarks, thank you so much! ๐Ÿฅณ

  • last update almost 2 years ago
    29,678 pass
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    Thanks @Wim Leers!

    Re: Nightwatch, I can sometimes trigger the failure locally, both with these changes and on 11.x. So it does seem unreliable/random.

    This test specifically: core/tests/Drupal/Nightwatch/Tests/Olivero/oliveroSearchFormTest.js

  • last update almost 2 years ago
    29,678 pass
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    (Hiding patches from the issue summary)

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Let's get this critical feature request in to 10.2.0.

    Committed and pushed 66716dc920 to 11.x and a9ee5c1044 to 10.2.x. Thanks!

    • longwave โ†’ committed a9ee5c10 on 10.2.x
      Issue #3342874 by star-szr, Wim Leers, DamienMcKenna: Allow inline HTML...
  • Status changed to Fixed almost 2 years ago
    • longwave โ†’ committed 66716dc9 on 11.x
      Issue #3342874 by star-szr, Wim Leers, DamienMcKenna: Allow inline HTML...
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States nkraft

    hi! we've been watching this for client sites. We just tested 10.2.0 -- and we are not seeing the presevation of commetns, they are still being stripped.

    Does 10.2.0 have this fix natively, or does it rely on some additional plugin to be installed still? was testing done? I don't see any "RTBC" comments above for the work done by star-szr

    Thanks for your efforts! We're really eager to see this patched into CK5. These sorts of issues have been causing us all sorts of headaces on our enterprise sites.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada star-szr

    @nkraft just to be sure, are you testing HTML comments along with other content? If the editor contains only an HTML comment it will still be stripped because CKEditor 5 doesnโ€™t see any content to render.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine _tarik_ Lutsk

    Ported the patch for those who are still on Drupal 9

    Works fine with 9.5.11

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly Hotfingers

    Hi, I've made many tests in Drupal 10.5.x, and HTML Comments wrapping actual HTML code only work if "Limit allowed HTML tags and correct faulty HTML" is not enabled. As soon as we enable it and re-save the node, with the same text format, then this:

    <p>
        Hello
    </p>
    <!--
    <p>
        World
    </p>
    -->
    

    becomes:

    <p>
        Hello
    </p>
    <p>
        World
    </p>
    <p>
        &nbsp;
    </p>
    <p>
        --&gt;
    </p>
    

    But we actually need that filter in a project that will have many editors.

    Obviously, the CKEditor "Source" widget/button must be enabled so we can add a comment.

    The "Source editing / Manually editable HTML tags" section that appears when we add the widget doesn't seem to be useful if the filter "Limit allowed HTML tags and correct faulty HTML" is not enabled, as we can add virtually any tag to the text area of the node edit without it enabled and without adding them to the "Manually editable HTML tags".

    We also tried enabling the filter and adding

    <!-- -->
    !--
    <!---->
    <!-- comment -->

    to the "Manually editable HTML tags" but they get stripped as soon as we save the text format.

    Is this working as intended? Can we apply a workaround for writing HTML comments when this filter is enabled?

    Thanks in advance.

Production build 0.71.5 2024