-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pasting content/text copied from iOS Notes app has formatting issues. #128
Comments
Info pasted from Notes is just text with newlines (as opposed to HTML), and the newlines should come in to the MarkupEditor as <p><br></p>. The logic for cleaning up the newlines definitely has some bugs in it. I am working on it and will add some tests to make sure it's covered properly. Thanks. |
This has been made more complicated because I am working on MacOS 14 Sonoma, and some behavior on the JavaScript side changes that I was implicitly relying on. For example, it seems that range.extractContents() leaves the selection in the document in a slightly different state, and I have code that was relying on that state, particularly in handling Enter across selections. That isn't directly related to this bug, but it's preventing me from passing tests cleanly. So, I pulled on that thread until I found its end, and all my tests pass again. Unfortunately, there is a regression in one of the GitHub Actions Ventura-based tests that I have to sort out in a way that passes both on Ventura and Sonoma. I'm going to open up a Discussion on supporting RTF-based pasting. I found that the Notes application paste buffer does not contain a public.html type, only a public.rtf type. It doesn't look difficult (haha) to go from RTF->AnnotatedString and then from AnnotatedString->HTML which could then be "cleaned up" like other HTML and pasted into the MarkupEditor. However, I'm not sure how much would be lost in that flow, and I don't want to deal with it right now. Still, it's annoying to lose bold/italic/underline and lists from content grabbed from Notes and probably other places. |
The fixes for this pasting-from-notes issue should be fixed with #133. I added new tests into testPasteTextPreprocessing and testPasteHtmlPreprocessing to cover it. It does raise another issue about embedded newlines in pasted text. These are currently kept in-place during paste, unless they occur at the beginning or end of the pasted text, in which case they result in empty paragraph elements (<p><br></p>). So, for example, pasting "Hello<br>world" into an empty paragraph (<p><br></p>) results in <p>Hello<br>world</p> and displays properly, except that the line spacing is compressed because it's not two paragraphs. I think this is correct and what people would expect. Unfortunately, there is no way to put a <br> into text yourself while editing, which is inconsistent. (FWIW, it's pretty easy to do that in Markdown using a trailing \). I'm going to open another issue on this topic. |
Hi @stevengharris, I am checking on this issue again as it does not seem to have worked on iOS Notes. I have tested this on my real device. I saw you have added testing code for MacOS Notes app copied text. I tried to replicate it on MacOS Notes to an iOS simulator and it does seem to be working fine. However with the same note copied from iOS Notes app and paste the exact same way, it does not work. I went to check a little into the UIPasteboard logic. For the iOS copied text on, there are 6 pasteboard types, ▿ 6 elements
I think this difference is the first reason why there are two different behaviors for the app on MacOS and iOS. The second issue that I suspect is the logic for
This is the text on my notes app on iPhone. This is the string from pasteboard.string This is the html string that is derived from String(data: data, encoding: .utf8) Based on my understanding of pasteHtml() function, I can see that the passed in html string gets escaped one more time. This makes the html string double-escaped. After html.escaped, the string is
Could this be the issue? Side note: I also noticed that for the above |
From what I gather, The iOS Notes app
|
I tried to insert a test case with the full html tag with DOCTYPE on
It seems to me that the |
Thanks for all the detail. I will look into it. It's a kind of weird and no doubt brittle guessing game on how to deal with the pasteboard types. Basically, I thought the logic should be: if an image is present, use it; else if html is present, use it; else, use text if present. I suppose I could use the com.apple.notes.richtext (or public.rtf) if it's present without public.html, and then do some kind of rtf-to-html conversion, but I don't know how well that will translate and presumably it could still be a bit different between iOS and Mac Notes unless I always prefer the rtf over html. I will have to play with it a bit. Let me know if you have an opinion on the best way to go. |
I am not sure about rtf conversion to html will resolve this issue, but that still involves clean up on the copied text, just in a different format. Perhaps it could be an additional cleanup method to remove these tags properly, without causing the addition of
I noticed that your test cases handle the simple paragraph |
Hi @stevengharris, I was considering the possibilities over the holidays. RTF-based copy and paste HTML-based copy and paste Otherwise text-based copy and paste Cheers & Happy New Year! |
Thanks again for looking into it further. I had suggested the RTF conversion in cases where HTML was missing in #128 (comment) mainly because in #128 (comment) you showed that iOS Notes was providing RTF+HTML while MacOS Notes was only providing RTF without the HTML. Both cases showed up with text, so that would always be there for a fallback (or if the user chooses "paste without formatting". This way you would get some reasonably formatted text on both iOS and Mac, although there might be differences depending on what I use for the conversion. I am using SwiftSoup elsewhere and could use that here, too. I will be checking out the header issues and the p-followed-by-p cases you mention above next. I am hoping also maybe to come up with a kind of Rosetta stone of a Notes content case that I can then bake into a paste test. I envision something with various formatting, lists, checkboxes (won't be good on the MarkupEditor side, I'm sure, per #120), and images. |
Thanks for considering my inputs. May I know if there is a foreseeable timeline in which I can revisit this issue? Currently, this library is being used in production in my company. I am looking into this issue as the stakeholders in my company are raising this as a bug, and I am wondering how to solve this without going into specifics of the javascript codes. |
I am just about done and will push something tomorrow even if it's just on a branch. It looks very good but is causing a few issues with the tests. I did add the rtf as a supported paste type. |
I think this and issue #179 are fixed on the https://github.com/stevengharris/MarkupEditor/tree/pasteFromNotes branch, with PR #180. Unfortunately, the |
Hi @stevengharris, I retracted my previous reply. It is working now. I just have to point to your latest markup.js code changes. |
Hi @stevengharris
I am testing a common workflow on iOS that when a user copies a simple text from the default iOS Notes app. It results in a blocks of \n around the text.
From my investigation, the text copied directly from Notes app is a html text in the format below.
The resulting view will look like this
Could this be an issue with the pasteboard adding \n to the copied text?
Related issue:
This time I am appending the paste string on the top of an existing content.
The paste string does not show up upon Paste.
Another experiment where I tried to unescape the text above and the text shows up on the screen. But it also has the big block of spaces above.
The text was updated successfully, but these errors were encountered: