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

Preserve styled markup in Code #698

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

westonruter
Copy link
Owner

@westonruter westonruter commented Mar 9, 2023

Fixes #205

As it stands right Current Code block I'm testing with:

<!-- wp:code {"highlightedLines":"4-18","showLineNumbers":true} -->
<pre class="wp-block-code"><code>&lt;br&gt;
&amp;amp;
&lt;script&gt;
if ( true &amp;&amp; "foo" &lt;= 'bar' &amp;&amp; 'baz' &gt;= "quux" ) 
{} else if ( 
  "<strong>bolded</strong>" &amp;&amp; 
  "<em>italicized</em>" &amp;&amp; 
  "<a href="https://example.com/">linked</a>" &amp;&amp; 
  "<strong><em><a href="https://example.com">all</a></em></strong>" ) 
{} else if ( 
  "bolded spanning <strong>tokens" == 123</strong> 
) {} else if ( 
  "italicized spanning <em>tokens" == null</em> 
) {} else if ( 
  "link spanning <a href="https://example.com">tokens" == true</a> 
) {} else {
  // &#91;gallery]
}
&lt;/script&gt;
&#91;test]
&#91;embed]https://twitter.com/WordPress/status/1631756836666785795&#91;/embed]

https:&#47;&#47;twitter.com/WordPress/status/1631756836666785795

&#91;sic]</code></pre>
<!-- /wp:code -->

It's currently rendered as:

Without plugin Editor Frontend
image image image

Notice that the shortcodes are no longer being rendered, which is a fix. But what is still broken is the handling of stylized text inside the Code block. It is is getting corrupted by highlight.php.

This PR seeks to address this by adding the formatting back in after the code has been highlighted.

@westonruter westonruter force-pushed the fix/code-block-markup-preservation branch from c76a0b2 to 007a08c Compare March 9, 2023 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Account for Code blocks containing rich text in Gutenberg 9.2+
1 participant