Skip to content
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

Text always bold when pasted from Docs #2462

Closed
nikolafilchev opened this issue Jan 16, 2019 · 5 comments · Fixed by #3989
Closed

Text always bold when pasted from Docs #2462

nikolafilchev opened this issue Jan 16, 2019 · 5 comments · Fixed by #3989

Comments

@nikolafilchev
Copy link

Text always bold when pasted from Docs, including pasting table data.

Steps for Reproduction

  1. Visit https://codepen.io/nikolafilchev/pen/vvMOMG
  2. Paste text from Docs

Expected behavior:
Maintained formatting text is pasted

Actual behavior:
Bold text is pasted

Platforms:
Everywhere that I tested

Version:
2.0.0-dev.3

@edhowler
Copy link
Contributor

Is there any workaround for this? I'm having problems with this issue.

@edhowler
Copy link
Contributor

I got it, here is what I did:

var Clipboard = Quill.import('modules/clipboard');
class Clipboard2 extends Clipboard {
    onCapturePaste(e) {
        if (e.defaultPrevented || !this.quill.isEnabled()) return;
        e.preventDefault();
        const range = this.quill.getSelection(true);
        if (range == null) return;
        let html = e.clipboardData.getData('text/html');
        html = html.replace('<b style="font-weight:normal;"', '<span"');
        const text = e.clipboardData.getData('text/plain');
        const files = Array.from(e.clipboardData.files || []);
        if (!html && files.length > 0) {
            this.quill.uploader.upload(range, files);
        }
        else {
            this.onPaste(range, { html, text });
        }
    }
}
window.Quill.register({'modules/clipboard': Clipboard2}, true);

@gs-mtripathi
Copy link

Does anybody have any update on this? I am still facing this issue in Firefox. Even on disabling formatting of pasted text, the content is bold. Can see the strong tag in Firefox. Looks fine in chrome, both with/without formatting.

@burmashave
Copy link

It's the same issue ProseMirror had in 2016 (since fixed):
ProseMirror/prosemirror#459

For some reason, Google Docs uses a "<b style="font-weight:normal id="..."> wrapper around documents, which Firefox naturally interprets as bold. Haven't yet tried the fix by @edhowler but it looks like it would work.

@burmashave
Copy link

So I'm able to remove the bolding when pasting from Google Docs into Firefox with a simple matcher like this:

let Delta = Quill.import('delta');

quill.clipboard.addMatcher('B', function(node, delta) {
    let val = true;
    if (node.style.fontWeight === 'normal') { val = false; }
    return delta.compose(new Delta().retain(delta.length(), { bold: val }));
});

Unfortunately, it also removes the formatting from any intentionally bolded text. I don't understand the matchers & deltas well enough to know how to preserve that formatting, but maybe someone else here does...?

tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 5, 2021
tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 5, 2021
tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 5, 2021
fix #365 [Editor] - Texts become bold when copy and paste from Google doc

References:
- facebookarchive/draft-js#393 (comment)
- [Superdesk CMS is using DraftJS](https://github.com/superdesk/superdesk-client-core/blob/develop/scripts/core/editor3/html/from-html/index.ts#L60) and internally calling docsSoap to resolve this
- slab/quill#2462 has some dirty fix with side effects
- ProseMirror/prosemirror#459 (comment) this fix mentioned ProseMirror/prosemirror-schema-basic@cbbdc1a691 in ProseMirror looks much cleaner
tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 5, 2021
fix #365 [Editor] - Texts become bold when copy and paste from Google doc

References:
- facebookarchive/draft-js#393 (comment)
- [Superdesk CMS is using DraftJS](https://github.com/superdesk/superdesk-client-core/blob/develop/scripts/core/editor3/html/from-html/index.ts#L60) and internally calling docsSoap to resolve this
- slab/quill#2462 has some dirty fix with side effects
- ProseMirror/prosemirror#459 (comment) this fix mentioned ProseMirror/prosemirror-schema-basic@cbbdc1a691 in ProseMirror looks much cleaner
tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 7, 2021
fix #365 [Editor] - Texts become bold when copy and paste from Google doc

References:
- facebookarchive/draft-js#393 (comment)
- [Superdesk CMS is using DraftJS](https://github.com/superdesk/superdesk-client-core/blob/develop/scripts/core/editor3/html/from-html/index.ts#L60) and internally calling docsSoap to resolve this
- slab/quill#2462 has some dirty fix with side effects
- ProseMirror/prosemirror#459 (comment) this fix mentioned ProseMirror/prosemirror-schema-basic@cbbdc1a691 in ProseMirror looks much cleaner
tx0c pushed a commit to thematters/matters-editor that referenced this issue Oct 7, 2021
fix #365 [Editor] - Texts become bold when copy and paste from Google doc

References:
- facebookarchive/draft-js#393 (comment)
- [Superdesk CMS is using DraftJS](https://github.com/superdesk/superdesk-client-core/blob/develop/scripts/core/editor3/html/from-html/index.ts#L60) and internally calling docsSoap to resolve this
- slab/quill#2462 has some dirty fix with side effects
- ProseMirror/prosemirror#459 (comment) this fix mentioned ProseMirror/prosemirror-schema-basic@cbbdc1a691 in ProseMirror looks much cleaner
@luin luin closed this as completed in #3989 Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants