-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
HTML block content gets transformed into entities #24282
Comments
I tested this and can confirm the Issue is occurring as described. I also noted the following block validation issue n the browser console:
The post body when inspected was: <!-- wp:html -->
3 < 4
<!-- /wp:html --> This notes a mismatch between what is being saved (encoded entities) and what is in the post body (string of raw HTML). I can see the block's gutenberg/packages/block-library/src/html/save.js Lines 6 to 8 in 5e77f46
...which is a wrapper around React's gutenberg/packages/element/src/raw-html.js Lines 20 to 27 in 5e77f46
This also happens when you don't save as a Reusable block. Simply enter the HTML block, save the Post as draft and reload the page. Same issue occurs. After some quick debugging this function is where the content gutenberg/packages/blocks/src/api/parser.js Lines 219 to 221 in 353eada
Specifically the
...and indeed if we refer to the MDN reference for
|
@KittMedia Do you have an example of the JavaScript you need to include that is not working. A reduced test-case form for testing would be fine. |
Of course:
|
This doesn't happen only when saving the block as a reusable block. I can also replicate with these steps:
On reopening, the block displays the HTML entity rather than the character. Reported by a WordPress.com user in https://wordpress.com/forums/topic/editing-posts-with-markdown-markup/ |
Just to confirm if you try this out by adding a HTML block then pasting in the content above you'll get a browser console log warning that block validation failed because function conditionalMemberFields() {
var membershipRadios = document.querySelectorAll( '[name="membership"]' );
var membershipConditionals = document.querySelectorAll( '.conditional-membernumber' );
if ( ! membershipRadios.length || ! membershipConditionals.length ) {
return;
}
- for ( var i = 0; i < membershipRadios.length; i++ ) {
+ for ( var i = 0; i < membershipRadios.length; i++ ) {
membershipRadios[ i ].addEventListener( 'change', function( event ) {
- for ( var n = 0; n < membershipConditionals.length; n++ ) {
+ for ( var n = 0; n < membershipConditionals.length; n++ ) {
if ( event.currentTarget.value === 'Ja' ) {
membershipConditionals[ n ].classList.remove( 'conditional-membernumber' );
}
else {
membershipConditionals[ n ].classList.add( 'conditional-membernumber' );
}
}
} );
}
} |
For anyone that might want a not-pretty workaround, when you need to do a JS less-than comparison in a HTML block: |
Hello, the issue is still in present 5.8.1 . It also happens with square brackets. |
Confirmed. Issue still present. |
@MatzeKitt With the merge of #27268 this should now be fixed. Gutenberg 14.8 will be released soon so you should be able to test it using the Gutenberg Plugin by next week. |
Update: this bug is not isolated to reusable blocks. It happens when creating a
core/html
block when it contains these characters as the HTML entities&
,<
and>
.Describe the bug
If you create an HTML block with the content
3 < 4
andstore it as reusable blocksave it, and then reload the page, the<
becomes<
.Background: I need to use this HTML block to add some JavaScript. If parts of this JavaScript gets changed by encoding to HTML entities, it just doesn’t work on the one hand and can result in a total crash of Gutenberg on the other hand.
To reproduce
Steps to reproduce the behavior:
3 < 4
Expected behavior
The block is stored as reusable with the raw content added.
Editor version (please complete the following information):
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: