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

Fix compatibility with Gutenberg 17.1 after it removed preserveWhiteSpace serialisation differences #791

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"core": null,
"plugins": [ "." ]
"plugins": [
".",
"https://downloads.wordpress.org/plugin/gutenberg.zip"
],
"config": {
"WP_DEBUG_LOG": true
}
}
5 changes: 4 additions & 1 deletion inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,12 @@ function render_block( array $attributes, string $content ): string {

$language = $attributes['language'];

// As of Gutenberg 17.1, line breaks in Code blocks are serialized as <br> tags whereas previously they were newlines.
$content = str_replace( '<br>', "\n", $matches['content'] );

// Note that the decoding here is reversed later in the escape() function.
// @todo Now that Code blocks may have markup (e.g. bolding, italics, and hyperlinks), these need to be removed and then restored after highlighting is completed.
$content = html_entity_decode( $matches['content'], ENT_QUOTES );
$content = html_entity_decode( $content, ENT_QUOTES );

// Convert from Prism.js languages names.
if ( 'clike' === $language ) {
Expand Down