I have plenty of old answers where I used <pre><code>
to format code, with HTML tags such as <b>
or <strike>
inside such blocks.
That has been broken for some time now, on SO as well as on dba.SE. It's particularly annoying where it completely breaks the meaning. Like here:
This used to work, but now renders without the strike-through (and bold) format, basically breaking my answer.
Original code:
<pre><code>...
GROUP BY model.name, attempt.type, <strike><b>attempt.result</b></strike>
...</code></pre>
Expected result (except for missing syntax highlighting):
...
GROUP BY model.name, attempt.type, attempt.result
...
Actual result:
...
GROUP BY model.name, attempt.type, attempt.result
...
Demo with more details:
The result should really get syntax highlighting for the declared (or derived) language and added manual formatting. It used to work like that.
This happens because the syntax highlighter, Highlight.js, strips all tags before adding colors. The code renders just fine here on Meta.SE since highlighting is off by default. But it can be reproduced by declaring a language in an HTML comment. OTOH, after disabling highlighting for the block or post using <!-- language[-all]: lang-none -->
manual HTML tags are kept.
Also, while editing, the local rendering of the preview honors HTML tags until the draft is saved and syntax highlighting kicks in. I wouldn't mind that for stylistic details. But I do mind completely breaking some of my answers.
These FAQ answers on meta.SE and meta.SO still suggest <pre><code>
for code blocks, without mentioning the severe side-effects:
(I have since edited both to reflect current behaviour.)
How to unbreak?
Update: This bug was reported to the authors of Highlight.js, who responded that SE needs to implement a plugin on their end to fix this issue.
<!-- language-all: lang-none -->
to disable syntax highlighting for the post: I've suggested an edit to your linked post that does so.textContent
of the element to be highlighted, which loses all HTML by design. There is nothing we can do about it.before/afterHighlightElement
hooks), so if Stack Overflow truly desired this behavior they could have it with minimal effort. We have plugin APIs specifically to allow these kind of things to live outside of the core library.diff
to showcase the changes you wish someone to make instead of embeddingstrike
markup.