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

Paste from Word or LibreOffice produces block of CSS first #9719

Closed
ogalinski opened this issue Sep 9, 2018 · 13 comments · Fixed by #10019
Closed

Paste from Word or LibreOffice produces block of CSS first #9719

ogalinski opened this issue Sep 9, 2018 · 13 comments · Fixed by #10019
Labels
[Feature] Paste [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release

Comments

@ogalinski
Copy link

Description
When pasting some simple text (one heading, one paragraph) from Word or LibreOffice, Gutenberg first creates a paragraph block of some CSS text and then the content blocks.

To Reproduce

  1. Create a document in Word or LibreOffice, one heading and one paragraph (any text will do). Select all and copy.
  2. Create a new Gutenberg post.
  3. Paste content.

Expected behavior
One heading block and one paragraph block.

Screenshots
gutenberg-error

Desktop (please complete the following information):

  • Windows 10 Pro
  • Tested on Chrome 69 and FireFox Quantum 62 (64 bits)

Additional context

  • Gutenberg 3.7.0
  • Tested on local setup and also on testgutenberg.com.
@maximebj
Copy link
Contributor

maximebj commented Sep 10, 2018

I was about to post this issue too!

Same thing with Word for Mac.

capture 2018-09-10 a 11 51 09

I know than this is not a good practice to do this but we won't be able to avoid people to do this.

@youknowriad
Copy link
Contributor

Is this a known issue @iseulde @mcsf?

@ogalinski
Copy link
Author

Funny thing is, I tested this in Gutenberg v2.0 and it was working fine.

@maximebj
Copy link
Contributor

Regression! I'm calling the unit test police !

I think that it could be handled simply by removing block beginning with a styles statement + comment tag

@ianbelanger79 ianbelanger79 added [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release labels Sep 10, 2018
@designsimply
Copy link
Member

Also see #9759, #9761.

@designsimply
Copy link
Member

Tested and confirmed using LibreOffice 6.0.6.2 and WordPress 4.9.8 and Gutenberg 3.8.0-rc.1 with Firefox 62.0 on macOS 10.13.6.

Sample file https://github.com/WordPress/gutenberg/files/2367501/Word.docx
(h/t @troytempleman for linking to this sample file in another issue)

screen shot 2018-09-10 at 12 08 09 pm

screen shot 2018-09-10 at 12 08 17 pm

Seen at http://alittletestblog.com/wp-admin/post.php?post=14846&action=edit running WordPress 4.9.8 and Gutenberg 3.8.0-rc.1 using Firefox 62.0 on macOS 10.13.6.

@designsimply
Copy link
Member

I re-tested to confirm whether this is a regression and I found that the problem does not happen in 3.6.2 but does happen in 3.7. Steps to reproduce:

  1. Open https://github.com/WordPress/gutenberg/files/2367501/Word.docx with LibreOffice (or Microsoft Word).
  2. Copy all.
  3. Start a new Gutenberg post.
  4. Paste.

Result: CSS is included as content in the paste and shows in the visual editor.

@troytempleman
Copy link

Pasting into Internet Explorer gives a different result, as described in #9759. Styles don't get inserted but all text gets inserted into one block and is not properly formatted (i.e paragraph breaks, lists, etc.).

@tanjoymor
Copy link

Tested and found that using a Classic block allows for proper pasting. No CSS code and it retains formatting.

@mcsf mcsf mentioned this issue Sep 18, 2018
6 tasks
@mcsf
Copy link
Contributor

mcsf commented Sep 18, 2018

It's a bit late here for a proper Git bisecting, but we are indeed missing integration tests for document styling. See #10019 for said tests and a possible fix.

mcsf added a commit that referenced this issue Sep 18, 2018
- Input file for integration test `ms-word-styled` is a truncated
version of file provided by issue reporter. See
#9719 (comment)
mcsf added a commit that referenced this issue Sep 20, 2018
- Input file for integration test `ms-word-styled` is a truncated
version of file provided by issue reporter. See
#9719 (comment)
mcsf added a commit that referenced this issue Sep 20, 2018
* Raw handling: remove <style> tags

- Input file for integration test `ms-word-styled` is a truncated
version of file provided by issue reporter. See
#9719 (comment)

* Add Gutenberg integration test
@pwkip
Copy link
Contributor

pwkip commented Aug 15, 2021

This problem still occurs when you paste inside a block that only allows paragraphs.

To reproduce:

  • create a block that only allows paragraphs. <!-- wp:myblocks/group-content {"allowedBlocks":["core/paragraph"]} --> ... <!-- /wp:myblocks/group-content -->
  • Try to paste from word or libreoffice in this block.
  • You will see the @page styles appearing as plain text

@paaljoachim
Copy link
Contributor

WordPress 5.8
Twenty Twenty One theme
Gutenberg plugin 11.3. (Only plugin activated.)

Pasting text into a page. (I am not certain how to reproduce your testing @pwkip Jules.)

Testing with TextMakerFree from Softmaker Free office 2018.
---> Works.


Testing with LibreOffice 7.2.
---> Works.

@pwkip
Copy link
Contributor

pwkip commented Aug 30, 2021

Thanks for testing Paal. However, you would need to create your own custom group that only allows paragraph blocks before you can reproduce this. Creating your own Gutenberg blocks is still not something trivial as you will need to register the block trough PHP and include some additional JS and CSS files. Explaining how to reproduce the error would mean writing a complete tutorial first. Instead, I'll try to write a quick plugin that registers a group that only allows <p>-blocks. Will keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants