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.
<mark>
tag and I'd have some sort of gold background color for the mark... Bold and italic are easily lost as (as well as being used by some highlighting themes as well, like Markdown). If this wasn't a 5kb chunk of code that most users get no value from (plus the security concerns) we'd likely support it in core but ONLY for a single "blessed" tag, likemark
. As for whether SE needs this feature, I'm on the fence, but if it was added to SE I'd suggest spending a few minutes adding a tag whitelist to the plugin, which should be easy to do.If your associated text cannot or does not adequately describe the important bits of the code block, then you've already failed to write a good answer.
Over the last decade, I have written hundreds of answers with formatted code. Mostly<b>
and<strike>
. It serves well to highlight crucial bits or errors. Then you (SO) switched to Highlight.js without due diligence and broke existing answers, only to blame the otherwise excellent highlighter for your failure. Stripping<strike>
completely breaks some answers. Your presumptuous comment just adds insult to injury.<strike>
tag in an existing code block, rather disable code highlighting than HTML tags. Or better yet, enable HTML tags (at least for pre-existing posts), which is totally possible as I have learned from Josh's comments. Instead of trying to fix it - or at least admitting fault - I see presumptuous comments like the above.