Can’t edit a List Block in HTML
Description
I am having a completely repeatable problem trying to edit List Blocks in HTML. It happens with OL and UL blocks the same way. I am using the WP editor. The WP version is 6.2. I am not having the issue with other blocks.
If I have a link block and select edit in HTML, it does display the HTML version. However it seems to be adding content, as per below. Further, if I click to another application (Word) I immediately see the dialog block:
This block contains unexpected or invalid content. “Attempt Block Recovery”
If I attempt the recovery, the block is restored.
The same thing occurs whether or not I edit the code once I return to Edit Visually. I reported this at https://wordpress.org/support/topic/cant-edit-a-list-block-in-html/#new-topic-0 and another user tested and found the same problem. He recommended I report it here.
I have taken a set of steps to see what is going on behind the scenes. Here is the HTML for 2 List Blocks, unordered and ordered, each with Item1, Item 2, Item 3 as their contents.
HTML before doing anything (from Preview>view source): (extra empty lines removed)
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Select Edit in HTML, first list.
Shows in the WP editor:
<ul><!-- wp:list-item -->
<li>item 1</li>
<!-- /wp:list-item -->
<!-- wp:list-item -->
<li>item 2</li>
<!-- /wp:list-item -->
<!-- wp:list-item -->
<li>item 3</li>
<!-- /wp:list-item --></ul>
And generates the error announcement on my switching to Word:
This block contains unexpected or invalid content. "Attempt Block Recovery"
Save draft and preview. Preview looks correct. HTML source: (extra blank lines removed)Note that the comments are not there.
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Used Attempt Block Recovery. Save. Preview. Looks the same. HTML (extra blank lines removed):
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Expand If there is additional information I can provide that would be helpful, please let me know. This looks like a WP bug to me. I have not tried changing themes or disabling plugins, since this seems particular to List Blocks.
Step-by-step reproduction instructions
Step by step is detailed above.
Screenshots, screen recording, code snippet
No response
Environment info
WP version 6.2 Theme: Betheme. No Gutenberg plugin installed, using the vanilla WP editor.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
Having submitted the above, I came back to see if there was a response and found that where I had pasted HTML code there was now just a display of the "visual" version. I will try to put it in again. The code keeps getting converted to the output. I am attaching a txt file with the HTML. Hopefully that works.
Having submitted the above, I came back to see if there was a response and found that where I had pasted HTML code there was now just a display of the "visual" version
Yep, you can add html to github comments, but the code won't be displayed.
I've edited it, you can use three backtick characters before and after the code to apply formatting in markdown. You can also now use a slash inserter like in gutenberg. 😄
@talldan Thanks for the help!
I am having the same problem. I have attacked a video link to show the problem. Has this been fixed? Is there a workaround? Thank-you all. https://youtu.be/jNodEmf1OOE?si=0gTFzy9VksGb5l-F
I found a solution to fix the issue. Follow the steps below:
Copy the HTML code from WordPress and paste it into Notepad.
Edit the HTML code in Notepad. Ensure that <ul> appears on its own line by pressing the return key immediately after it.
Then delete the unordered list from WordPress completely.
Copy the code from Notepad.
In Worpress, click on any blank area in the post/page to bring up the "add block icon" and click on it.
In the box that appears, click on the "Custom HTML" icon.
Paste in the code you copied from Notepad, and it should work perfectly.
It seems like the above work around is just that a complete work around. Is anyone able to add a new list item to an existing list? This feels so broken.
The HTML editing for the List block has been disabled in recent releases - #55656.
Editing these wrapper blocks in HTML directly is fragile and prone to breaking the users' content. HTML editing should be left to leaf-blocks.
https://github.com/WordPress/gutenberg/pull/11785#issue-380011111.
I think we can close this as "maybe later".
@mtias, do you think we can improve the HTML editing experience for wrapper blocks after block validation refactoring - #73116?
We were just discussing that with @dmsnell. I think it's an area to explore, but editing across block boundaries can be quite frail. Maybe after the validation changes it's a bit less frail and we can try it in a couple blocks.
Thanks, @mtias!
Let's close this, and we can reconsider editing across block boundaries once the new validation system is in place.