ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.55k stars 3.7k forks source link

HTML comments: comments located between some HTML tags are repositioned or lost #10118

Open psmyrek opened 3 years ago

psmyrek commented 3 years ago

Provide a description of the task

Steps to reproduce:

  1. Open HtmlComment manual test: http://localhost:8125/ckeditor5-html-support/tests/manual/htmlcomment.html.
  2. Set the document content to:
<figure class="table">
    <!-- C1 -->
    <table>
        <!-- C2 -->
        <tbody>
            <!-- C3 -->
            <tr>
                <!-- C4 -->
                <td>
                    <!-- C5 -->Table cell<!-- C6 -->
                </td>
                <!-- C7 -->
            </tr>
            <!-- C8 -->
        </tbody>
        <!-- C9 -->
    </table>
    <!-- C10 -->
</figure>
  1. Call editor.getData(). A few comments, originally located between <figure> and <table>, <table> and <tbody> or <tbody> and <tr> , are moved after the closing </table> tag.
<figure class="table">
    <table>
        <tbody>
            <tr>
                <!-- C4 -->
                <td>
                    <!-- C5 -->Table cell<!-- C6 -->
                </td>
                <!-- C7 -->
            </tr>
        </tbody>
    </table>
    <!-- C10 --><!-- C1 --><!-- C9 --><!-- C8 --><!-- C3 --><!-- C2 -->
</figure>

It is also easily reproducible using SourceEditing:

https://user-images.githubusercontent.com/56868128/125051559-5aa53680-e0a3-11eb-9e48-06bd48553ea8.mp4

psmyrek commented 3 years ago

Similar issue is with the List plugin, but in this case some comments are totally lost.

Example: after initializing the editor with the following content:

<!-- c1 -->
<ol>
    <!-- c2 -->
    <li>
        <!-- c3 -->
        Ordered list item
        <!-- c4 -->
    </li>
    <!-- c5 -->
</ol>
<!-- c6 -->
<ul>
    <!-- c7 -->
    <li>
        <!-- c8 -->
        Unordered list item
        <!-- c9 -->
    </li>
    <!-- c10 -->
</ul>
<!-- c11 -->

the editor.getData() returns:

<!-- c1 -->
<ol>
    <li>
        <!-- c3 -->
        Ordered list item
        <!-- c4 -->
    </li>
</ol>
<!-- c6 -->
<ul>
    <li>
        <!-- c8 -->
        Unordered list item
        <!-- c9 -->
    </li>
</ul>
<!-- c11 -->

Comments <!-- c2 -->, <!-- c5 -->, <!-- c7 --> and <!-- c10 --> are lost.

star-szr commented 11 months ago

I am currently trying to solve this issue with lists, specifically the newer DocumentList plugin. I'm working on a project where it's common for <li> items to be commented out. Would anyone be able to share some pointers on how to preserve these, whether in the HtmlComment plugin/domconverter (happy to contribute if I can help figure it out) OR with a custom plugin?

So far I've only been able to figure out that these comments (like the c2, c5, c7, c10 from the previous comment) don't make it to the upcast converter in HtmlComment, and I'm not yet sure why.

Example markup:

<ul>
    <li>
        one
    </li>
<!--
    <li>
        two
    </li>
-->
</ul>

This turns into:

<ul>
    <li>
        one
    </li>
</ul>
Witoso commented 11 months ago

@niegowski any ideas here?

star-szr commented 11 months ago

I have a potential solution for lists, I can propose a fix in a pull request. I started looking into tables to see if it could be solved in a similar way but didn't get very far yet.

Update: In some cases the comments will still get repositioned (when at the start/end of the list from what I can see), but they would not be lost. I haven't looked into any solution for repositioning yet since my main concern is data loss. I will put up a basic PR later referencing this issue, and I can work on some tests next week.

Update again: Actually List and DocumentList both need updates, I have been focused on DocumentList but will see if List can be updated as well.

imdgtm commented 9 months ago

@star-szr Any update on comment repositioned within table?

star-szr commented 9 months ago

@star-szr Any update on comment repositioned within table?

Hi, it's not needed for the project that I am working on so I am not planning to work on that.