Skip to content

Widgets: HTML block is formatted using autop and has its attributes removed #33832

@sabernhardt

Description

@sabernhardt

Description

In the new widget editor, Custom HTML widget blocks can get (additional) paragraph and line break tags.

Originally reported by jim5471 on Trac #53778

Step-by-step reproduction instructions

  1. Go to Dashboard > Appearance > Widgets.
  2. Insert a Custom HTML Block into the footer and insert this code:
<div><p>some text</p>
<a href="http://www.test.com">link text</a>
</div>
<svg height="90" width="200">
  <text x="10" y="20" style="fill:red;">Several lines:
    <tspan x="10" y="45">First line.</tspan>
    <tspan x="10" y="70">Second line.</tspan>
  </text>
</svg> 
  1. Update and check it appears on the webpage and is correct.
  2. Go back to Dashboard and then back to Appearance > Widgets.
  3. Observe the Custom HTML code has additional paragraph and line break tags.

Firefox:

<div>
<p>some text</p>
<p><a href="http://www.test.com">link text</a>
</p></div>
<p><svg height="90" width="200"><br></br>
  <text x="10" y="20" style="fill:red;">Several lines:<br></br>
    <tspan x="10" y="45">First line.</tspan><br></br>
    <tspan x="10" y="70">Second line.</tspan><br></br>
  </text><br></br>
</svg></p>

Edge/Chrome:

<div>
<p>some text</p>
<p><a href="http://www.test.com">link text</a>
</p>
</div>
<p><svg height="90" width="200"></svg><br>
  <text x="10" y="20" style="fill:red;">Several lines:<br>
    <tspan x="10" y="45">First line.</tspan><br>
    <tspan x="10" y="70">Second line.</tspan><br>
  </text>
</p>
  1. Change another widget and update.
  2. Go back to Dashboard and then back to Appearance > Widgets.
  3. In Chrome and Edge, the code stays the same as in step 5. In Firefox, though, the Custom HTML code changes again:
<div>
<p>some text</p>
<p><a href="http://www.test.com">link text</a>
</p>
</div>
<p><svg height="90" width="200"><br></br></svg><br><br>
  <text x="10" y="20" style="fill:red;">Several lines:<br><br><br>
    <tspan x="10" y="45">First line.</tspan><br><br><br>
    <tspan x="10" y="70">Second line.</tspan><br><br><br>
  </text><br><br><br>
</p>

Expected Behavior

The Custom HTML block widget contents should remain exactly as entered.

Current Behavior

The block widget has autop formatting (from @wordpress/autop).

WordPress Information

WordPress 5.8
Twenty Twenty-One theme
no plugins
local installation with PHP 7.3.21

Gutenberg Information

Gutenberg not activated

What browsers are you seeing the problem on?

Firefox, Chrome, Microsoft Edge

Device Information

Desktop browsers:
Google Chrome 92.0.4515.107 (64-bit) - Incognito mode
Mozilla Firefox 90.0.2 (64-bit) - Private window
Microsoft Edge Version 92.0.902.62 (64-bit)

Operating System Information

Windows 10 Home 20H2 19042.1110

Is there an existing issue for this?

  • I have searched the existing issues

Have you tried deactivating all plugins except Gutenberg?

  • I have tested with all plugins deactivated.

Have you tried replicating the bug using a default theme e.g. Twenty Twenty?

  • I have tested with a default theme.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions