The discussion revolves around the issue of HighlightJS auto-selecting the wrong language for a block of Swift code. topogram tried using ~~~swift...~~~ to specify the language, but it didn’t work, with the engine defaulting to either makefile or nginx. pfaffman suggested using ```swift to force the language, but this didn’t work for topogram.
pmusaraj then pointed out that Swift is not enabled by default and needs to be added to the highlighted languages site setting. This was confirmed to be the solution by topogram, who added Swift to the site settings and removed unused languages, resolving the issue.
Is there any way to disable the syntax highlighting engine’s ability to auto select the language? I am trying to get a block of Swift code highlighted on my install of Discourse:
I’m flanking the code fence with ~~~swift...~~~ but that’s not working.
but the highlighting engine insists on highlighting it as either makefile or nginx. My website only really uses a handful of languages (Xojo, Python, C# and Swift). Is there a way to remove / unload the unnecessary languages loaded by Discourse?
Using swift</code> or <code> swift doesn’t seem to work for me. Is Swift one of the included languages? It seems to be in the stable channel for Highlight.js.
Yes, you can add/remove languages from the highlighted languages site setting. Swift is not enabled by default and likely not enabled on your site, which is probably why
```swift
is not working for you. (Swift is also not enabled on meta.) It does work for me locally when I add Swift to the site setting:
Found the issue. I had to add Swift as a supported language in the site settings. I also removed a bunch of languages that my community doesn’t use. It’s fixed the issue.