-
Notifications
You must be signed in to change notification settings - Fork 18
Provide support for pasting lists from google docs #72
Conversation
@Mgsy can you take a look for it? I copy-paste some general content and seems to work fine. However, maybe there is some strange browser or content structure, which might not be converted to lists properly. |
… properly recognized byt other normalizers. What can happen for partial copy-paste from Safari.
It crashes if a pasted list item is indented more than once.
Clipboard HTML: <html>
<body>
<!--StartFragment--><meta charset="utf-8"><b style="font-weight:normal;" id="docs-internal-guid-51600ef9-7fff-81d2-c69b-dfa6f7e8dedc"><ol style="margin-top:0pt;margin-bottom:0pt;"><li dir="ltr" style="list-style-type:decimal;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;margin-left: 36pt;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Test</span></p></li><ol style="margin-top:0pt;margin-bottom:0pt;"><ol style="margin-top:0pt;margin-bottom:0pt;"><li dir="ltr" style="list-style-type:lower-roman;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;margin-left: 36pt;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">test</span></p></li></ol></ol></ol></b><!--EndFragment-->
</body>
</html> |
OMG why they even allow on such a strange structure 😱. What is worse, that CKEditor doesn't support such a structure. And we could either remove those extra indentions or remove entire node with all children below :( |
The same problem occurs for Word, actually, in this PR you'll find two proposals how to solve this issue - #53. We agreed that this kind of structures should be normalized. |
I wonder about the normalization process in some specific situation: <ol>
<li>A1</li>
<ol>
<ol>
<ol>
<li>B4</li>
</ol>
<li>C3</li>
<ol>
<li>D4</li>
</ol>
</ol>
<li>E2</li>
</ol>
</ol> Element A1 possesses 2 wrong elements: B4 and C3. From the first look on task: #53 (comment) proposed normalization moves element B4 as a child of A1. However, it also Elements B4 and C3 are positioned incorrectly then both should become siblings and should be located as children of A1. So the correct structure should look like: // cc @scofalik last time you were not asked about your opinion. I won't repeat that mistake! WDYT? |
I've implemented the 2nd approach, which seems to be less time-consuming.
|
The normalization seems to look OK :) Probably @Mgsy could verify that. I can see that if user paste sub-list (ckeditor/ckeditor5#1930) nothing gets pasted. Error in the console:
pasted content: <meta http-equiv="content-type" content="text/html; charset=utf-8"><meta charset="utf-8"><ul style="margin-top:0pt;margin-bottom:0pt;" id="docs-internal-guid-8a672c83-7fff-1b35-788b-9afb3dcf7487"><ul style="margin-top:0pt;margin-bottom:0pt;"><ul style="margin-top:0pt;margin-bottom:0pt;"><ul style="margin-top:0pt;margin-bottom:0pt;"><ul style="margin-top:0pt;margin-bottom:0pt;"><ul style="margin-top:0pt;margin-bottom:0pt;"><ul style="margin-top:0pt;margin-bottom:0pt;"><li dir="ltr" style="list-style-type:disc;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">E</span></p></li></ul></ul><li dir="ltr" style="list-style-type:circle;font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">F</span></p></li></ul></ul></ul></ul></ul> |
@jodator When I create normalize I wondered if a situation like this might happen. I couldn't find a way to generate content which has nested tags from the beginning :D. And now I see it's much easier than I thought ;) |
Oh sorry I've missed that - so remove the ifs ATM as in my comments there. We decide what to do with this problem later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there ;) Some minor docs improvements, extract unwrapping element to the engine's UpcastWriter
and the Safari case is still on my mind as I would try to make things as specific as possible.
src/normalizers/genericnormalizer.js
Outdated
* | ||
* @implements module:paste-from-office/normalizer~Normalizer | ||
*/ | ||
export default class GenericNormalizer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it happen only on Safari? If so I'd still ad some env checking to be sure that this normalizer doesn't fire up too often. @mlewand WDYT? OTOH this normalizer will always fix pasted lists (even from other sources) so it may be beneficial.
I see two routes:
- Make it run only for Safari and name it more specific, like:
SafariListNormalizer
- Make it general list fixer - the I'd name it
NestedListNormalizer
and maybe add a check if pasted content has broken list (AFAICSul></ul
,/p></li
and/li><ul
could be checked - withul|ol
variants check) - but the check idea is something to give another though if it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added small changes to the list.js file:
- some re-organization (exported methods should be on top).
- last list example was misaligned with the other two
Suggested merge commit message (convention)
Feature: Provide support for pasting lists from Google Docs. Closes ckeditor/ckeditor5#2499 .
Additional information
When you copy-paste content from Safari, sometimes there is nothing to recognize that content cames from Google Docs. For example, try to copy-paste content from table.
That's why I create generic normalizer, which is applied if no other normalizer was run.
I saw 2 options here, either allow on multiple normalizers to run over the content or create a normalizer which will be executed if no other is found. I decide for the second option to not complicate code too much and have sure that only one normalizer will modify the data.content.