5

See an answer I wrote here.

The code is all in white, even though the question is tagged c#

I also tried with the ```csharp syntax, and it's still white text

none of the words are highlighted

TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(userTimeZoneId);
DateTimeOffset now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tz);
8
  • It seems to work (I didn't commit any changes) if I use a different language tag and also add keywords specific to the other language. Maybe the syntax highlighter doesn't think there's anything in the code example that needs highlighting? Jul 14, 2022 at 17:38
  • 2
    This is being highlighted with csharp page source with appropriate language class. This appears to be an issue with highlightjs not anything with the markdown or tag languages.
    – Henry Ecker Mod
    Jul 14, 2022 at 18:00
  • 4
    Agree with Karl. Seems there's just nothing in the code that the highlighter wants to highlight. Adding other keywords (like public or private) or strings to the code causes it to highlight as expected.
    – animuson StaffMod
    Jul 14, 2022 at 18:08
  • 1
    I would hope for syntax highlighting, in languages with manifest static typing, to highlight type names (even if they're user-defined). That might require relatively sophisticated parsing, though. Stack Overflow isn't exactly providing an IDE here. Jul 14, 2022 at 20:17
  • 3
    It's not C#, syntax highlighting in general is "broken" (or looks broken). Since SO switched to highlight.js for no good reason other than "we want to switch", the syntax highlighting experience has been just absolutely dreadful. There isn't much to do here on SO/SE, devs will just tell you that this is [status-bydesign] (which it is, however questionable such choice might seem). The only thing you can do is roll up your sleeves and submit PRs to the upstream highlight.js repo to make it better. Jul 15, 2022 at 12:59
  • 4
    @MarcoBonelli "Since SO switched to highlight.js for no good reason other than 'we want to switch'" - That is not true. SE made the switch because Prettify development was discontinued by Google, and highlight.js is what was being requested as its replacement at the time. Here is the announcement with details surrounding that decision.
    – codewario
    Jul 15, 2022 at 15:33
  • @Bender so what? If it ain't broken, don't fix it. I don't remember anybody in the community demanding an update, there was no real reason to change highlighter engine at the time, other than "we just decided we want to, and we are going to do it". In fact, the change made syntax highlighting objectively worse if you ask me. Jul 15, 2022 at 15:47
  • @Bender The only positive thing I can see is that you can now skip asking SO/SE devs and directly contribute to upstream if you want to improve things (assuming they will accept your contribution). So far, nobody seems to have done much though (can't really blame anybody since the codebase is pretty convoluted). Jul 15, 2022 at 15:49

1 Answer 1

6

I'll answer my own question, summarizing what I've learned from the comments.

  • Stack Overflow switched from Google Prettify to highlight.js
  • Prettify would recognize and highlight C# object and method names based on their position in the code (distinguishing them from variables). Highlight.js only recognizes C# language keywords (and comments, etc.). I opened an feature request for this here.
  • Nothing in my code example uses language keywords, so nothing in my code is highlighted.

Thus, the syntax highlighting isn't broken, it just doesn't add any value in this particular situation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .