I made an edit to this old answer of mine. Among other changes, I converted from indentation-defined code blocks to code fence-defined code blocks. Despite the question being tagged as C#, I provided c#
language hints for the code blocks because I like to be explicit like that; I have never had an issue doing that in the past.
Since the edit, I no longer see syntax highlighting on my answer:
This is after giving the highlighting a few seconds to appear, Reloading the page, and Shift + Reloading the page. I do still see syntax highlighting on the question and its other answers, however.
During the edit, syntax highlighting worked as expected in the answer preview. You can see that is still the case if I start to edit from the current Revision 5:
I found Snippets aren't working when refreshing an edit, but that relates to the prompt to reload a post while viewing it, whereas I have tried a full page reload as well as a "non-reload reload" by clicking the question title link at the top of the page. I am also aware of the change to a new Markdown renderer (which only now do I notice is scheduled for...today on Stack Overflow), but I don't believe there to be any problematic Markdown used either before or after the edit.
I am using Mozilla Firefox 77.0.1 on Windows with uBlock Origin in Medium mode and the necessary whitelist rules for Stack Overflow to work properly.
Looking at the resulting HTML I see that my code blocks become <pre>
elements with no CSS styles. For example, the first code block becomes this:
<pre>string path = string.Format("WinNT://{0},computer", Environment.MachineName);
using (DirectoryEntry computerEntry = new DirectoryEntry(path))
{
IEnumerable<string> userNames = computerEntry.Children
.Cast<DirectoryEntry>()
.Where(childEntry => childEntry.SchemaClassName == "User")
.Select(userEntry => userEntry.Name);
foreach (string name in userNames)
Console.WriteLine(name);
}
</pre>
...whereas in the edit preview the same code block opens like this...
<pre class="lang-cs prettyprint prettyprinted" style=""><code>
...and includes a whole lot of <span>
tags. So, that would seem to answer the question of why syntax highlighting isn't working (because there's none in the markup), but then raises a new question: why isn't the necessary markup for prettyprinting being generated?
Just as a sanity check, I found this recent answer of mine with the same kind of formatting (code fence with a c#
language hint despite the question being tagged as such, no empty lines surrounding the code fence) and the syntax highlighting works fine.
<span>
elements within the<pre><code>
are added by the in-page JavaScript that does the syntax formatting. It is the various CSS classes on the<pre>
element which trigger the in-page JavaScript to perform the highlighting. The highlighting is not in the HTML delivered by SE.lang-cs
makes it work as you expect. Not sure why the preview would show it fine, other than perhaps they differ in implementation. I made an answer there (now deleted) to have a quick test and changed one of the declarations to lang-cs; I now note that on the main page where my deleted answer shows pink the syntax highlighting is fine and on the edit mode it is now the preview that is broken.. ?!#
, maybe server-side. That would explain why it works in the edit mode, but not in the rendered post.```c++
are not being syntax highlighted anymore, either. But previews work fine. Answers are syntax highlighted if```
is used with a c++ tag, or```cpp
is used.