-
Notifications
You must be signed in to change notification settings - Fork 8
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
wymeditor: Adds paste listener to strip superfluous code #345
Conversation
Based on the #314 by @RoukePouw and processed comments by @matthijskooijman |
In #66, I wrote:
I don't think this is addressed in this PR, right? But I think it should be somehow adressed? |
Good point! I've raised question as well and talked to @giplt about this. His reaction, and I agree, is that is more preferable to implement this feature now, with the downside that all pastes are stripped and later fix it so that it only targets Word-like code. |
A "copy" event handler exists: https://developer.mozilla.org/en-US/docs/Web/API/Element/copy_event which can probably manually retrieve the selected content, customize it to mark it as "from inside hypha" so that the paste event handler can recognize it and skip the format-stripping. One way I thought we could mark the data as being "from inside hypha" could be to tweak the "format" on the clipboard. The clipboard typically contains multiple versions (e.g. "text/plain" and "text/html"), and I hoped we could just add an "application/hypha-html" or something in addition to the default types, with identical content to the "text/html" version. However, reading the spec, I think that the formats that can be written from "untrusted" scripts is limited: https://w3c.github.io/clipboard-apis/#writing-to-clipboard. So I guess adding some wrapper or marker inside the "text/html" version should be done instead. This marker should ideally be invisible and unobtrusive, for the case that this HTML is pasted elsewhere. We should probably also try to generate a "text/plain" version, to allow copy-pasting from Wymeditor into a plain textarea or so. |
Note that this makes *all* pastes text-only and also prevents copy-pasting within the same editor, or between editors. This should be solved later. There also seems to be a corner case in the `wym.paste` function where the text is interpreted as HTML rather than text (i.e. any HTML tags in the text content, which must have been escaped as e.g. `>` in the original clipboard contents, would become actual HTML again after the paste). This only occurs when inserting into the outer body tag, so when no other container is selected (which is pretty hard to achieve, except when the editor is completely empty). This also seems to occur with the existing "Paste from word" feature as well. Since this is an existing and rare problem, it is left to be solved later. This fixes the main part of #66
12d9357
to
9c3cbf8
Compare
Rebased and updated the commit message, merging next. |
I created #348 for some followup improvements. |
Fixes #66