Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Paste from Google Docs #393

Closed
gesposito opened this issue May 14, 2016 · 6 comments
Closed

Paste from Google Docs #393

gesposito opened this issue May 14, 2016 · 6 comments

Comments

@gesposito
Copy link

gesposito commented May 14, 2016

I'm addressing a particular use case where I should paste content copied from a generic Google Docs document.
So far, on a Mac with OS X 10.11 with Chrome 50 whenever I try to do so, somehow the whole document get styled 'BOLD'.
If I try to do the same, but going through the "Notes" app (copy > paste > copy > paste), then the content looks alright.
I'm not sure where I should look at while trying to address such issue, any idea?

@aem
Copy link

aem commented May 24, 2016

This is an issue you should probably handle yourself, it seems out of scope for this kind of a library to handle the nuances of Google Docs' clipboard handling. If you look at the clipboard content coming from Google Docs (set a breakpoint inside of a handlePastedText handler) you'll see that Google Docs surrounds its entire HTML structure in a <b> tag, which Draft technically handles correctly. I have an in-house solution that I'm planning on open-sourcing soon, but the gist of it is you need to process the HTML to extract the inner HTML elements and then use Modifier to insert the result into the document.

@sophiebits
Copy link
Contributor

Google Docs surrounds its entire HTML structure in a <b> tag

why would it do that… @_@

@aem
Copy link

aem commented May 25, 2016

¯_(ツ)_/¯ not sure why the wrapping in a <b> tag, but all of their blocks are styled inline, so a bold chunk of text is a <span style="...;font-weight:700;...">, etc. Writing the parser was a party

@gesposito
Copy link
Author

Thanks @aem, I wasn't sure what was happening, I'm having a look at the solution you're suggesting.

@aem
Copy link

aem commented Jun 8, 2016

As followup, today I open-sourced the solution that I built internally. Doesn't cover all cases, but should be enough to get started. Contributions welcome :)

@khudiiash
Copy link

khudiiash commented Feb 7, 2020

This worked for me

handlePastedText = (text, html,editorState) => {
      const blocksFromHTML = convertFromHTML(html.replace(/<b/g,'<p').replace(/<\/b/,'</p'));
      const newState = ContentState.createFromBlockArray(
        blocksFromHTML.contentBlocks,
        blocksFromHTML.entityMap,
      );

      this.onChange(EditorState.push(editorState, newState, 'insert-fragment'))
      return true
  }

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
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants