For many years, it's been possible to apply rich text formatting to code blocks inside posts by formatting the code block using the HTML tags <pre><code>
and using more HTML tags inside the post.
As an example, the following code:
<pre><code>.This is <b>bold</b>, <i>italic</i>, and <strike>striked-out</strike> text..</code></pre>
results in:
.This is bold, italic, and striked-out text..
Today, this functionality continues to work so long as the block is not being syntax-highlighted. In the past, however, this used to work for all posts, since it was supported by SE's previous highlighter Prettify and by the original version of the new Highlight.js highlighter to be deployed here, version 10. However, this feature was removed in version 11. The same code, when highlighted as default, has said formatting stripped out:
.This is bold, italic, and striked-out text..
When looking at the post source, both of the above two code blocks have the identical source, the one in the first block above: the only difference is in the HTML comments above each in the source: the former has highlighting disabled, while the latter has it enabled.
The stated reason for the removal of support in version 11 is to prevent against inadvertent HTML injection if a user puts in HTML code into an HTML code block. However, a plugin exists and can be installed by Stack Exchange to restore the prior functionality. Installing this plugin, as far as I can tell, requires no more overhead than adding support for an additional highlighting language already supported by Highlight.js but not by SE.
Querying for affected posts is difficult due to requiring a regex and using regex to parse HTML* go through the site's database is difficult due to SO's massive database size, so I'd like to start a discussion to gauge from the community as to how important they perceive having this feature. There has been at least one complaint on the global meta regarding answers being broken as a result of this change to Highlight.js, but I'd like the overall community consensus.
Should the plug-in be implemented, or should the current configuration be retained?
Reasons to install it
- It un-breaks older posts which depended on the feature without needing to edit them.
- It prevents unexpected formatting removals when users type posts (users wondering where their formatting went/why it vanished despite it working in the 5-second window when highlighting is turned off in the post editor).
- It removes the requirement to turn off syntax highlighting in revision histories and suggested edit reviews (the highlighter was swallowing the strikethrough formatting), and as such makes it easier to detect inappropriate changes to syntax highlighting language in HTML comments (changes to a post's hidden content aren't shown by default unless a hyperlink is changed).
Reasons to retain the current configuration
- Text formatting in code blocks is rarely used due to it not being supported in four-space indent or triple-backtick code blocks.
- A workaround exists for posts where it's important, to disable syntax highlighting for that particular block or post using the HTML comment
<!-- language[-all]: lang-none -->
. Broken posts which depended on the feature can be edited to fix them using this. - It doesn't require dev team effort (which isn't that much given that the plugin already exists; the team just needs to implement it).
* That is, fundamentally, what a regex to search for affected posts would be doing anyway.