Long-term code block (address line break issues)
justintadlock opened this issue · 1 comments
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:
- Respects valid HTML within code blocks.
- 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
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.