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

Long-term code block (address line break issues) #62

Open
justintadlock opened this issue Apr 3, 2024 · 1 comment
Open

Long-term code block (address line break issues) #62

justintadlock opened this issue Apr 3, 2024 · 1 comment

Comments

@justintadlock
Copy link
Collaborator

Currently, we are using the Code Syntax Block for the Developer Blog, which extends the Core Code block. When setting a "Language" for this block in the editor, it adds <br> tags instead of \n within the code.

<br> tags are perfectly fine within <pre><code>. Nested HTML is valid here.

However, the plugin uses Prism.js, which strips HTML within code elements. And because the plugin is using <br> instead of \n, it behaves as there are no line breaks at all. So, on the front end, all the code is formatted into a single line.

There is a "Keep Markup" JS extension that may also be a front-end fix for the plugin: https://prismjs.com/plugins/keep-markup/

What we've been doing:

We've had to manually search/replace <br> tags in the editor and replace them with \n.

Short-term fix:

We have a temporary solution for the plugin here: #61

Longer term:

We need a more robust solution that:

  1. Respects valid HTML within code blocks.
  2. Consistently handles line breaks.

This could be forking the current plugin, submitting a patch to it, or picking another plugin (potentially needing to fix too).

Related history:

This initially became an issue when Gutenberg started adding <br> tags. However, this has now been addressed in Gutenberg: WordPress/gutenberg#59627

@juanmaguitar
Copy link

juanmaguitar commented May 5, 2024

It seems that the latest version of Code Syntax Block v3.2.0 has solved this issue, which has already been updated in the Developer Blog.

Screenshot 2024-05-05 at 12 32 48

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

No branches or pull requests

2 participants