copy/paste from word without superfluous code #66
Labels
No labels
Component: User interface
Component: Wymeditor
Help wanted
Level: Difficult
Level: Easy
Level: Moderate
Pagetype: Festival
Pagetype: Mailinglist
Pagetype: Peer reviewed article
Pagetype: Text
Privacy GDPR AVG
status: has conflicts
Status: Needs changes
Status: Needs discussion
Status: Needs review
Status: Ready to merge
Status: Waiting for response
Type: Bug
Type: Enhancement
Type: Question
Usecase: De Stadsbron
Usecase: Koppelting
Usecase: MeetjeStad
Value: Coders
Value: Security
Value: Users
Value: Visitors
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
harmen/hypha#66
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
Er is een "paste from word" icoontje in de editor -Matthijs
@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?
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?
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).
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?
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!
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 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
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.
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.
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 uglifyjsor use an online version) to generate the minified version.