copy/paste from word without superfluous code #66

Closed
opened 2018-09-03 13:16:08 +00:00 by tammoterhark · 11 comments
tammoterhark commented 2018-09-03 13:16:08 +00:00 (Migrated from github.com)

Clean input from Word: http://wymeditor.readthedocs.io/en/v1.1.1/wymeditor_plugins/third_party_plugins/catch_paste.html
strip all javascript and css when pasting in editor
. Perhaps keep paragraphs, bold/italic tags and lists?
. Does the paste-from-word option do this already? If so, can we simply capture paste events and redirect them to this function?
. https://stackoverflow.com/questions/11626319/strip-html-to-remove-all-js-css-html-tags-to-give-actual-textdisplayed-on-brows

Clean input from Word: http://wymeditor.readthedocs.io/en/v1.1.1/wymeditor_plugins/third_party_plugins/catch_paste.html strip all javascript and css when pasting in editor . Perhaps keep paragraphs, bold/italic tags and lists? . Does the paste-from-word option do this already? If so, can we simply capture paste events and redirect them to this function? . https://stackoverflow.com/questions/11626319/strip-html-to-remove-all-js-css-html-tags-to-give-actual-textdisplayed-on-brows
tammoterhark commented 2018-09-27 09:21:08 +00:00 (Migrated from github.com)

Er is een "paste from word" icoontje in de editor -Matthijs

Er is een "paste from word" icoontje in de editor -Matthijs
matthijskooijman commented 2018-11-26 21:15:33 +00:00 (Migrated from github.com)

@tammo, do you know if the existing "paste from word"-icon is being used? If so, does it not work sufficiently? If not, is this something we should point out to users, or automate?

@tammo, do you know if the existing "paste from word"-icon is being used? If so, does it not work sufficiently? If not, is this something we should point out to users, or automate?
tammoterhark commented 2018-11-27 11:24:21 +00:00 (Migrated from github.com)

I will have to ask, I do not know how users do this. But still: would it be possible to intercept pasting by keyboard commands and clean the pasted stuff?

I will have to ask, I do not know how users do this. But still: would it be possible to intercept pasting by keyboard commands and clean the pasted stuff?
matthijskooijman commented 2018-11-27 11:32:48 +00:00 (Migrated from github.com)

The way paste-from-word works is that it gives you a plain-text field to paste in, which forces removal of all formatting before inserting the text into wymeditor. In effect, this means that either Word or the browser handles converting the original text into plaintext, which is probably the most reliable way.

I suspect that, from javascript, we can detect when Crl-V is pressed and something is pasted in, but probably not intercept it and change the handling. After detecting the paste, we can probably figure out the part of the text that was just pasted and strip any formatting from it. I suspect that it is more tricky to turn the pasted garbage into clean text this way than when Word or the browser handles it.

One alternative that might work, is to detect Ctrl-V and show a message to the user to tell them about paste-from-word. Alternatively, we might be able to disable Ctrl-V handling, so the user cannot paste normally, but instead gets a message about paste from word. This is probably counterproductive, though, since this also prevents pasting clean formatted text (e.g. from another wymeditor or another part of the same editor).

Note that most of this is based on assumptions, so things might be different (and there might be other options that I haven't thought of yet).

The way paste-from-word works is that it gives you a plain-text field to paste in, which forces removal of *all* formatting before inserting the text into wymeditor. In effect, this means that either Word or the browser handles converting the original text into plaintext, which is probably the most reliable way. I suspect that, from javascript, we can detect when Crl-V is pressed and something is pasted in, but probably not intercept it and change the handling. After detecting the paste, we can probably figure out the part of the text that was just pasted and strip any formatting from it. I suspect that it is more tricky to turn the pasted garbage into clean text this way than when Word or the browser handles it. One alternative that *might* work, is to detect Ctrl-V and show a message to the user to tell them about paste-from-word. Alternatively, we might be able to disable Ctrl-V handling, so the user cannot paste normally, but instead gets a message about paste from word. This is probably counterproductive, though, since this also prevents pasting clean formatted text (e.g. from another wymeditor or another part of the same editor). Note that most of this is based on assumptions, so things might be different (and there might be other options that I haven't thought of yet).
RoukePouw commented 2020-05-15 07:18:03 +00:00 (Migrated from github.com)

https://github.com/PlanBCode/hypha/pull/314

Auto paste from word

I've succesfully captured the paste event and routed that through a hidden textarea - as the paste from word button does - before pasting.

But...I can't test it on word data. Because I don't have Word and the trial version (for which I used up my 30 day free trial) doesn't allow editing or even copying :-S

Paste from Word Button on Safari

The Paste From Word button (and probably other wym features) did not work on Safari as the form submit functions did not return false. This causes Safari to reload a page and loose all content.
For now I've hacked into the unminified wym file and used that. But this needs a better implementation.
What would be the preferred way of hacking?

Paste from Word Button if auto paste from word works

Do we still want the button there if we get paste from word working automatically?

https://github.com/PlanBCode/hypha/pull/314 **Auto paste from word** I've succesfully captured the paste event and routed that through a hidden textarea - as the paste from word button does - before pasting. But...I can't test it on word data. Because I don't have Word and the trial version (for which I used up my 30 day free trial) doesn't allow editing or even copying :-S **Paste from Word Button on Safari** The Paste From Word button (and probably other wym features) did not work on Safari as the form submit functions did not return false. This causes Safari to reload a page and loose all content. For now I've hacked into the unminified wym file and used that. But this needs a better implementation. What would be the preferred way of `hacking`? **Paste from Word Button if auto paste from word works** Do we still want the button there if we get paste from word working automatically?
giplt commented 2020-05-15 08:20:14 +00:00 (Migrated from github.com)

Great! I don't have Word either but could look out for some stray computers to test. How about other word processors that people might also use to paste from? E.g. Pages or Google Docs?

I guess the preferred way for implementation would be through an upsteam pull request at Wymeditor, however the repo https://github.com/wymeditor/wymeditor seems to be abandoned and the most recent (and still open) pull request was submitted in 2017 by matthijskooijman :-/
I haven't cheched the various forks on github for a living spinoff though.

If the function works fine I would say we don't need a separate button anymore. Less is more in this case!

Great! I don't have Word either but could look out for some stray computers to test. How about other word processors that people might also use to paste from? E.g. Pages or Google Docs? I guess the preferred way for implementation would be through an upsteam pull request at Wymeditor, however the repo https://github.com/wymeditor/wymeditor seems to be abandoned and the most recent (and still open) pull request was submitted in 2017 by matthijskooijman :-/ I haven't cheched the various forks on github for a living spinoff though. If the function works fine I would say we don't need a separate button anymore. Less is more in this case!
matthijskooijman commented 2020-05-15 08:33:22 +00:00 (Migrated from github.com)

I haven't cheched the various forks on github for a living spinoff though.

I just looked, nothing more recent. There still seems to be some interest, so maybe we should just fork with the changes we need, and maybe others will contribute things as well? See https://github.com/wymeditor/wymeditor/issues/791

As for testing: I suspect that paste-from-libreoffice might produce similar results. Haven't tested yet. Also, I don't have Word on any computer here either.

One thing to consider: If this catches all pastes, that might be counter-productive when pasting within the wymeditor (e.g. if you want to move a bit of test with markup within a page or article). If that is currently also pasted through a textarea, stripping all markup, that might break things like creating a homepage or newsletter (though you can always paste raw HTML maybe).

> I haven't cheched the various forks on github for a living spinoff though. I just looked, nothing more recent. There still seems to be *some* interest, so maybe we should just fork with the changes we need, and maybe others will contribute things as well? See https://github.com/wymeditor/wymeditor/issues/791 As for testing: I suspect that paste-from-libreoffice might produce similar results. Haven't tested yet. Also, I don't have Word on any computer here either. One thing to consider: If this catches *all* pastes, that might be counter-productive when pasting within the wymeditor (e.g. if you want to move a bit of test *with* markup within a page or article). If that is currently also pasted through a textarea, stripping *all* markup, that might break things like creating a homepage or newsletter (though you can always paste raw HTML maybe).
tammoterhark commented 2020-05-15 08:36:00 +00:00 (Migrated from github.com)

I will test, but this will take place this weekend or next week.

Op vr 15 mei 2020 om 10:20 schreef Harmen G. Zijp <notifications@github.com

:

Great! I don't have Word either but could look out for some stray
computers to test. How about other word processors that people might also
use to paste from? E.g. Pages or Google Docs?

I guess the preferred way for implementation would be through an upsteam
pull request at Wymeditor, however the repo
https://github.com/wymeditor/wymeditor seems to be abandoned and the most
recent pull request was submitted in 2017 by matthijskooijman :-/
I haven't cheched the various forks on github for a living spinoff though.

If the function works fine I would say we don't need a separate button
anymore. Less is more in this case!


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/PlanBCode/hypha/issues/66#issuecomment-629100998, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ABRO25II7GTAEZRBQLCCNC3RRT3MZANCNFSM4FS6NBOQ
.

I will test, but this will take place this weekend or next week. Op vr 15 mei 2020 om 10:20 schreef Harmen G. Zijp <notifications@github.com >: > Great! I don't have Word either but could look out for some stray > computers to test. How about other word processors that people might also > use to paste from? E.g. Pages or Google Docs? > > I guess the preferred way for implementation would be through an upsteam > pull request at Wymeditor, however the repo > https://github.com/wymeditor/wymeditor seems to be abandoned and the most > recent pull request was submitted in 2017 by matthijskooijman :-/ > I haven't cheched the various forks on github for a living spinoff though. > > If the function works fine I would say we don't need a separate button > anymore. Less is more in this case! > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/PlanBCode/hypha/issues/66#issuecomment-629100998>, or > unsubscribe > <https://github.com/notifications/unsubscribe-auth/ABRO25II7GTAEZRBQLCCNC3RRT3MZANCNFSM4FS6NBOQ> > . >
matthijskooijman commented 2020-05-15 09:34:33 +00:00 (Migrated from github.com)

I created a wymeditor fork here and gave you all write access: https://github.com/PlanBCode/wymeditor

I would suggest that for any changes we need to make to the wymeditor core, we just create a PR there, then regenerate a minified version and import that into hypha again. Of course, to test things initially, just switching to the non-minified version and making changes directly, like @RoukePouw has done now, is the easiest way.

I created a wymeditor fork here and gave you all write access: https://github.com/PlanBCode/wymeditor I would suggest that for any changes we need to make to the wymeditor core, we just create a PR there, then regenerate a minified version and import that into hypha again. Of course, to test things initially, just switching to the non-minified version and making changes directly, like @RoukePouw has done now, is the easiest way.
giplt commented 2020-05-17 20:33:10 +00:00 (Migrated from github.com)

One thing to consider: If this catches all pastes, that might be counter-productive when pasting within the wymeditor (e.g. if you want to move a bit of test with markup within a page or article). If that is currently also pasted through a textarea, stripping all markup, that might break things like creating a homepage or newsletter (though you can always paste raw HTML maybe).

Good one. Maybe we can add some special code when copying from wymeditor, so we can discriminate between paste-from-wym and paste-from-other.

> One thing to consider: If this catches _all_ pastes, that might be counter-productive when pasting within the wymeditor (e.g. if you want to move a bit of test _with_ markup within a page or article). If that is currently also pasted through a textarea, stripping _all_ markup, that might break things like creating a homepage or newsletter (though you can always paste raw HTML maybe). Good one. Maybe we can *add* some special code when copying from wymeditor, so we can discriminate between paste-from-wym and paste-from-other.
matthijskooijman commented 2020-06-11 13:44:02 +00:00 (Migrated from github.com)

I would suggest that for any changes we need to make to the wymeditor core, we just create a PR there, then regenerate a minified version and import that into hypha again. Of course, to test things initially, just switching to the non-minified version and making changes directly, like @RoukePouw has done now, is the easiest way.

I changed my mind about this. I just tried rebuilding wymeditor from the original sources (which collects js from separate source files into one js file and then minifies it), which worked, but it needed 1300 (!) npm packages, giving a lot of deprecated version warnings. Then, I discovered that @laurensmartina had alreay made some changes to the wymeditor sources, which would then also need to be ported over, so this will get complicated quickly. Given no development is expected to happen upstream, I suggest we just keep any changes we need in our own repository.

Let's just copy the approach of 94a707d: Make changes to the non-minified version and then use uglifyjs (apt-get install uglifyjs or use an online version) to generate the minified version.

> I would suggest that for any changes we need to make to the wymeditor core, we just create a PR there, then regenerate a minified version and import that into hypha again. Of course, to test things initially, just switching to the non-minified version and making changes directly, like @RoukePouw has done now, is the easiest way. I changed my mind about this. I just tried rebuilding wymeditor from the original sources (which collects js from separate source files into one js file and then minifies it), which worked, but it needed 1300 (!) npm packages, giving a lot of deprecated version warnings. Then, I discovered that @laurensmartina had alreay made some changes to the wymeditor sources, which would then also need to be ported over, so this will get complicated quickly. Given no development is expected to happen upstream, I suggest we just keep any changes we need in our own repository. Let's just copy the approach of 94a707d: Make changes to the non-minified version and then use uglifyjs (`apt-get install uglifyjs` or [use an online version](https://skalman.github.io/UglifyJS-online/)) to generate the minified version.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
harmen/hypha#66
No description provided.