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

Opening Gutenberg post in Classic Visual editor adds unwanted <p>&nbsp;</p> content #6385

Closed
2 tasks
weavertheme opened this issue Apr 24, 2018 · 10 comments
Closed
2 tasks
Assignees
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability

Comments

@weavertheme
Copy link

weavertheme commented Apr 24, 2018

Issue Overview

For GB 2.7:

I don't think gutenberg_disable_editor_settings_wpautop is working as expected. I would hope that it would prevent editing a GB post with the classic editor would prevent it from changing all the blank lines between the GB blocks into <p>&nbsp;</p> which then add lines and show up in GB as a Classic block.

Steps to Reproduce (for bugs)

  1. Create a page/post with Gutenberg blocks (duplicate one you already have
  2. From the All Pages/Posts view, edit that page in the Classic Editor, save
  3. Open same page in Gutenberg - all the formerly blank lines have been changed to <p>&nbsp;</p> with unintended consequences.
  4. It seems from the comments that gutenberg_disable_editor_settings_wpautop is supposed to prevent that, but it doesn't.

Expected Behavior

Current Behavior

Possible Solution

Maybe changing the priority of the gutenberg_disable_editor_settings_wpautop filter?

Screenshots / Video

Related Issues and/or PRs

Todos

  • Tests
  • Documentation
@danielbachhuber
Copy link
Member

Related #4672 #4446

@danielbachhuber danielbachhuber self-assigned this Jun 4, 2018
@danielbachhuber danielbachhuber added the Backwards Compatibility Issues or PRs that impact backwards compatability label Jun 4, 2018
@danielbachhuber
Copy link
Member

Specifically, if you start out with the following in the Text editor:

<!-- wp:heading -->
<h2>This is a heading block</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is my paragraph text.</p>
<!-- /wp:paragraph -->

Switching to the Visual Editor and then back to the text editor leaves you with this:

<!-- wp:heading -->
<h2>This is a heading block</h2>
<!-- /wp:heading -->
<p>&nbsp;</p>
<!-- wp:paragraph -->
<p>This is my paragraph text.</p>
<!-- /wp:paragraph -->

Here's a GIF of the behavior:

nbsp

@danielbachhuber danielbachhuber changed the title gutenberg_disable_editor_settings_wpautop not working as expected Opening Gutenberg post in Classic Visual editor adds unwanted <p>&nbsp;</p> content Jun 5, 2018
@azaozz
Copy link
Contributor

azaozz commented Jun 5, 2018

This is not related to wpautop. TinyMCE can make (empty) paragraphs from HTML comments that are on a separate new line. Example: http://fiddle.tinymce.com/Ctgaab/5.

To fix this we need to fix the white space between HTML comments when loading the content in TinyMCE, something like:

content = content.replace( /-->\s+<!--/g, '--><!--' );

And of course restore that on saving and switching to the Text editor with:

content = content.replace( /-->\s*<!--/g, '-->\n\n<!--' );

Edit: actually it makes sense for this to be in core right now. It's a bugfix there too. Created https://core.trac.wordpress.org/ticket/44308, will make a patch.

@azaozz
Copy link
Contributor

azaozz commented Jun 5, 2018

@danielbachhuber
Copy link
Member

@azaozz I tested this locally against my wordpress-develop checkout:

grunt patch:https://core.trac.wordpress.org/attachment/ticket/44308/44308.patch
grunt build

However, the issue still manifests:

nbsp

Is there some other step I'm missing?

@azaozz
Copy link
Contributor

azaozz commented Jun 7, 2018

However, the issue still manifests

Testing TinyMCE in /build has some quirks. Enable SCRIPT_DEBUG and make sure the browser cache is cleared :)

@danielbachhuber
Copy link
Member

Enable SCRIPT_DEBUG and make sure the browser cache is cleared :)

Even clearing browser cache didn't work for me! Opening in incognito did though.

@danielbachhuber
Copy link
Member

@azaozz Do you think we can shim this into Gutenberg for a more immediate fix?

@azaozz
Copy link
Contributor

azaozz commented Jun 7, 2018

Sure, think there was a place to add classic editor's TinyMCE fixes somewhere. If not, will have to make a tiny TinyMCE plugin :)

azaozz added a commit that referenced this issue Jun 8, 2018
See #6385.

Same fix as in core, see https://core.trac.wordpress.org/ticket/44308.

TODO: remove this after WordPress 4.9.7 is out, this should be in it.
@danielbachhuber
Copy link
Member

👍 Looks like fix/classic-editor-paragraphs-from-comments will shortly become a pull request :)

azaozz added a commit that referenced this issue Jun 19, 2018
* Fix Classic Editor adding paragraphs from block boundaries

See #6385.

Same fix as in core, see https://core.trac.wordpress.org/ticket/44308.

TODO: remove this after WordPress 4.9.7 is out, this should be in it.

* Fix variable typo
@azaozz azaozz closed this as completed Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backwards Compatibility Issues or PRs that impact backwards compatability
Projects
None yet
Development

No branches or pull requests

3 participants