1

EDIT: Ignore the part about the console warnings; these were not actually relevant to the highlighting issue. The issue was caused by the absence of the 'swift' tag and resolved by another user adding that tag to the question. Credit to CertainPerformance and Laurel for finding the canonical question and resolving the issue!


Today after posting an answer in Swift, I noticed that it has no syntax highlighting at all, which makes it very hard to read as the comments blend right into the code. Initially I assumed it was just being slow to render or that it was a browser problem, but changing browsers (Safari to Firefox) didn't fix it and it is still broken. Looking at a few other recently posted questions and answers, other code blocks seem to be rendering fine (Swift as well as other programming languages). Then I noticed that the original answers to the same question are also missing their syntax highlighting, not just mine.

Has anyone else noticed something like this? Is it possible for individual pages on Stack Overflow to have this feature go down, while it is fine for the rest of the site?

Additional info:

The code block uses the two sets of triple backticks, which is what I've always used and it has always worked until now. I didn't specify the programming language with the html tag at the top of the post like this <!--, but again it has always worked fine without that before. Opening the console for that one page didn't show any errors, but comparing it to a different page that was working correctly, it looks like there are warnings on the broken syntax-highlighting page that don't appear on the other page:

The following functions are deprecated: googletag.pubads().setTagForChildDirectedTreatment(), googletag.pubads().clearTagForChildDirectedTreatment(), googletag.pubads().setRequestNonPersonalizedAds(), and googletag.pubads().setTagForUnderAgeOfConsent(). Please use googletag.pubads().setPrivacySettings() instead.

I don't know what's causing this, since I'm not familiar with that API and don't have any browser extensions enabled other than the antivirus (so no child-specific settings or ad blockers, which is what the warnings seem to be about), but it's weird that it's happening only in one page and not on others on the same site. Is this a known bug?

3
  • Can you link to the post? Pretty sure Google ads don't have anything to do with highlight.js Jul 19, 2022 at 20:29
  • 1
    and meta.stackoverflow.com/q/274371 - at the time of your post, none of the tags on the question were associated with any highlight language, so no auto highlighting occurred Jul 19, 2022 at 20:37
  • @CertainPerformance I had no idea the tags on the question affected the syntax highlighting! I'd always assumed that it just inferred the language from the code sample somehow. Thank you for the references! Jul 19, 2022 at 20:39

1 Answer 1

0

Without a language tag or any hint, the system has no idea what to do with highlighting. (Language tags have "Code Language (used for syntax highlighting): lang-x" at the bottom of their tag wiki — see Swift for example. Only mods can edit that.)

I added to the question because it looked like that was what the question was about. As an alternative, you can add hints to code blocks in each post like so:

```swift
import UIKit
```
import UIKit
1
  • Yes, it's fixed now, thanks! I guess the warnings in the console were a complete red herring Jul 19, 2022 at 20:44

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