HighlightJS is auto-selecting wrong language

AI-generated summary

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:

NSString *str = @"hello,";
str = [str stringByAppendingString:@" world"];

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?

I think there is a system setting for the default language.
You should be able to use

 ``` swift

To force language

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.

Did you try using

 ```swift

as I recommended?

It does this:

1. var shoppingList = ["catfish", "water", "tulips"]
2. shoppingList[1] = "bottle of water"
* var occupations = [
3. "Malcolm": "Captain",
4. "Kaylee": "Mechanic",
5. ]
6. occupations["Jayne"] = "Public Relations"

EDIT: Hmm. That doesn’t look right. It looked like it worked on try.discourse.org. It seems to do the Right Thing on a test site that I have.

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.

Thanks for your help.