HighlightJS is auto-selecting wrong language

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?

1 Like

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

 ``` swift

To force language

3 Likes

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.

2 Likes

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:

3 Likes

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.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.