Open Jules-Bertholet opened 3 years ago
I was trying to reproduce this issue, but without success.
It all depends on what is copied/pasted:
Case 1: plain text is copied from equation input box → plain text is inserted
Case 2: HTML content is copied from editor view → HTML content is inserted
It seems that it has nothing to do with the HtmlDataProcessor#_toDom()
method in CKEditor 5.
The same behavior can be observed in your https://github.com/isaul32/ckeditor5-math/issues/34, where in the first video you copied & pasted plain text, but in the second video you copied & pasted HTML content.
Please let me know if my conclusions are correct.
@psmyrek The first video in the linked issue https://github.com/isaul32/ckeditor5-math/issues/34 doesn't actually demonstrate this issue (#9659). Yes, copying and pasting plain text copies and pastes plain text, this is normal. As for your case 2, the one that is relevant to reproduce this issue: in your video you have ckeditor5-math
configured to use span
tags; the issue only becomes apparent when the plugin is configured to use script
tags (edit: see https://github.com/isaul32/ckeditor5-math#plugin-options for config instructions).
@psmyrek Video demonstrating the bug
Thanks for the clarification.
I tried again, this time I think I followed the same steps as you did: I cloned https://github.com/isaul32/ckeditor5-math.git
, installed all dependencies and started the development server on http://localhost:8080
with the yarn start
. Also the ckeditor5-math
package is configured to use script
instead of span
as its output type.
However, I am still unable to reproduce this error on my side. The copied equation in my case is always a complete HTML content: <html>\r\n<body>\r\n<!--StartFragment--><script type=\"math/tex\">e=mc^2</script><!--EndFragment-->\r\n</body>\r\n</html>
. I wonder why on your side the <html>
and <body>
tags are missing and where did you get the <meta>
tag from, that precedes the <script>
tag in the copied equation.
I've checked this issue in latest versions of Chrome, Firefox, Edge and Brave browsers and it works exactly the same in all of them, as I expected, but I wanted to make sure that the browser doesn't have any effect here.
Could you help me reproduce this issue? Do you know what I did different than you? Did I miss something?
@psmyrek I notice that you have Windows line endings (\r\n
) in the HTML snippet in the debugger... maybe this is an OS-dependent-thing? I am on Fedora 34, with GNOME. Also, can you try dragging and dropping the equation? That should also reproduce the issue
@psmyrek Yes, this does in fact appear to be a Windows-specific behavior: https://docs.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format
Thanks @Jules-Bertholet for the hints, this could be OS-related issue indeed.
📝 Provide detailed reproduction steps (if any)
I discovered this problem while debugging https://github.com/isaul32/ckeditor5-math/issues/35. The plugin makes it easy to observe the incorrect behavior:
The issue is that when content is pasted,
_setupPasteDrop()
fromClipboardPipeline
processes the content withHtmlDataProcessor
'stoView()
, which itself calls_toDom()
, which processes the pasted HTML via aDOMParser
:_toDom()
only retains nodes in thebody
ofDOMParser.parseFromString()
's response. However, when DOMParser encounters certain tags, like<script>
, that are alone and not surrounded by text, it places these tags in the<head>
and not the<body>
. Therefore, if plugins (like the aforementioned math plugin) use<script>
tags to store view elements, those elements can be stripped on paste.✔️ Expected result
All HTML tags are retained when content is pasted into CKEditor.
❌ Actual result
Lone
<script>
tags are stripped upon pasting into CKEditor.📃 Other details
If you'd like to see this fixed sooner, add a 👍 reaction to this post.