Skip to content

Account for Code blocks containing rich text in Gutenberg 9.2+ #205

@westonruter

Description

@westonruter

In Gutenberg 9.2, Code blocks now allow rich text editing (via WordPress/gutenberg#24689). This means you can have a Code block with formatting:

<!-- wp:code -->
<pre class="wp-block-code"><code>if ( value === 'something' ) {
    <strong><span style="color:#a30000" class="has-inline-color">// Do something here!</span></strong>
}</code></pre>
<!-- /wp:code -->

In the editor this appears as:

image

On the frontend with this plugin active, however, it appears as:

image

We're not currently expecting markup to be inside of the highlighted text. This means the markup is getting escaped, and the autodetection is also failing. Here it's detecting that the language is xml as opposed to js.

I'm not sure how best to support highlighting Code blocks which already contain rich formatting. One option would be just to bail if the content contains any child elements. That would at least prevent the block from breaking, but we wouldn't get any highlighting.

In order to support highlighting text that also has tags, perhaps we could strip the tags out, do the highlighting, and then re-add the the tags. This could be challenging to correctly re-add the tags in the right places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions