gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Disable "Edit as HTML" in the Cover block.

Open maddisondesigns opened this issue 7 years ago • 10 comments

Describe the bug I had a Cover Image Block in my page that wasn't showing the image. When I viewed the HTML, I noticed that the url for the image was for another one of my test sites (i.e. a different domain), so I clicked on the Edit as HTML toolbar option and replaced the image url with the url for the same image on the same domain (i.e. An image on the same site as the actual page). As soon as I clicked out of the html field, it then gave me a warning advising that "This block contains unexpected or invalid content".

screenshot_1021

I then clicked on the resolve button and the "Current HTML" was identical to the "After Conversion" HTML, yet the image under the "Current HTML" was still blank and the image under "After Conversion" wasn't.

screenshot_1020

So, the block was telling me it was broken when the html was completely valid, and identical to the "resolved" html.

To Reproduce Steps to reproduce the behavior:

  1. Add this block into your page and save
<!-- wp:cover {"url":"http://dev.wordpress-test.com/wp-content/uploads/2017/12/design-studio-2.jpg","id":2804} -->
<div class="wp-block-cover has-background-dim" style="background-image:url(http://dev.wordpress-test.com/wp-content/uploads/2017/12/design-studio-2.jpg)"></div>
<!-- /wp:cover -->
  1. Select the Block and click the 'Edit as HTML' toolbar option
  2. Change the image url to a valid image on your site and then click outside of that html edit field
  3. See error

Expected behavior Valid html shouldn't break blocks

Desktop (please complete the following information):

  • macOS Sierra
  • Firefox Quantum 64.0
  • WP 5.0.1

maddisondesigns avatar Dec 14 '18 09:12 maddisondesigns

I then clicked on the resolve button and the "Current HTML" was identical to the "After Conversion" HTML

I have experienced this as well once or twice, but not sure which block it was for.

swissspidy avatar Dec 14 '18 13:12 swissspidy

This problem also potentially happens if your block of html has an opening tag, but not a closing tag? Is still an issue in 5.0.3

dkieffer avatar Feb 20 '19 21:02 dkieffer

If you edit the URL in the content but not in the comment, the block will try to match the generated output with the one you edited manually and it will create an invalidation error and propose ways to fix it.

I agree it's not a great experience but it works as intended. I don't see how we could improve this.

youknowriad avatar Aug 20 '19 11:08 youknowriad

@youknowriad How is that working as intended? If you enter valid HTML, it should not show a message saying it's invalid, simple as that.

maddisondesigns avatar Aug 21 '19 02:08 maddisondesigns

Because it is not about the HTML markup being valid or not.

swissspidy avatar Aug 21 '19 05:08 swissspidy

I'm really not understanding this and I apologise if I'm missing something but this makes zero sense to me.

If you edit the URL in the content but not in the comment, the block will try to match the generated output with the one you edited manually and it will create an invalidation error and propose ways to fix it.

If it's not about the html, then why is showing me html, and advise me that it's 'been converted' to resolve the issue? How has it been converted when it's identical to what I already entered? If it's not about the HTML, then give me a proper message and tell me what the issue is, and how you've "resolved it". Showing me the exact same code that I entered in the first place, is not resolving anything. Don't show me the same HTML that I've just entered, advising me that you've just "resolved" the issue for me, and then tell me it's "not about the HTML markup being valid or not".

You purport that Gutenberg is making editing easier for the end user, but then you do stuff like this. You show me an error that is literally advising that my html was invalid, you tell me it actually doesn't have anything to do with the html, and that you don't see how it could be improved.

maddisondesigns avatar Aug 21 '19 07:08 maddisondesigns

In order to understand we have to step back and see how Gutenberg works.

How we edit blocks?

Gutenberg edits blocks which are objects and not a string of HTML and updates those objects as you edit the UI of a block.

For an "HTML block" for instance, it has just one attribute, it's the "HTML content" so for this particular block, any HTML content would be valid and you can just enter whatever content you want there.

But for a block list "Cover Image", you don't typically edit the HTML directly, blocks edit attributes in their UI (as explained above), so you edit the URL directly.

For regular users (which most of them don't know anything about HTML), they'll just use the visual editor to edit the block attributes causing no invalidity.

How do we save blocks?

So if we edit objects, where does the HTML come from?

The answer is that Gutenberg serialize the objects into HTML (for backward compatibility and other reasons) in order to be saved which also means if you want to edit that block again (the attributes, the object) in the editor, it needs to be parsed again from that HTML and back to its Object form. Now, you can easily understand that if someone tweaks the serialized form of the block in a way the block don't understand (can't parse), it will create what we call and "invalid" block which is a block that can't be edited visually and we'd have to resolve this invalidity in order to continue editing it. And we have options to solve the issue: Convert it to an HTML block where you're free to type any HTML content, try to "force parse" that HTML blocks which could potentially lose some undesired content in the serialized format...

Now what about this "Edit as HTML option":

This is an advanced use-case. It's for people that know HTML but also for people that can afford to understand how Gutenberg works. So if you edit the HTML and produce an invalid block, you're presented with options to solve that invalidity. If you're HTML savy and know what you're doing when using that option, It's totally fine to stay in that mode and just convert your block into an HTML block.

How can we make this less confusing

So, this means our options here are UI related? How can we update the UI to clarify why I just said:

  • We could expand the resolution options
  • We could maybe avoid "Edit as HTML" option and just replace it with "Convert to HTML block" instead (one way action) ...

I hope that helps.

youknowriad avatar Aug 21 '19 09:08 youknowriad

Thanks for taking the time to explain all that.

If it's not possible to edit a block using the Edit as HTML option, without breaking it, then there shouldn't be an Edit as HTML option. The Columns Block for example, doesn't provide the option to Edit as HTML when you click on the main block, or when selecting a column within that block. Once you click on the content within the column though, such as a Paragraph Block, then you are still able to edit as html.

Perhaps the same thing should be done here. Don't provide an option to edit the main Cover Block if it's impossible to edit it, without breaking it. Just provide the Edit as HTML option for the blocks within the cover block (e.g. a heading or paragraph block).

Users shouldn't be able to break their content this easily. If they really, really want to edit the html, there's the Code Editor under the More Tools option. When using the visual editor though, it should be made so that it's impossible to break blocks.

maddisondesigns avatar Aug 21 '19 11:08 maddisondesigns

Perhaps the same thing should be done here. Don't provide an option to edit the main Cover Block if it's impossible to edit it, without breaking it. Just provide the Edit as HTML option for the blocks within the cover block (e.g. a heading or paragraph block).

Yeah, that's a possibility. Let's rename the issue to clarify its purpose.

youknowriad avatar Aug 21 '19 14:08 youknowriad

Closed by #18730.

ZebulanStanphill avatar Dec 03 '19 18:12 ZebulanStanphill