# HighlightJS is auto-selecting wrong language

**URL:** https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739
**Category:** Support
**Created:** [February 16, 2020, 11:11am UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739 "2020-02-16T11:11:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![topogram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/topogram/32/155563_2.png) [@topogram](https://meta.discourse.org/u/topogram)
#### Post date: [February 16, 2020, 11:11am UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/1 "2020-02-16T11:11:08Z")

</div>

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:

```swift
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?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 16, 2020, 12:49pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/2 "2020-02-16T12:49:20Z")

</div>

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

````
 ``` swift

````

To force language

---

<div class="post-metadata">

### Author: ![topogram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/topogram/32/155563_2.png) [@topogram](https://meta.discourse.org/u/topogram)
#### Post date: [February 16, 2020, 5:46pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/3 "2020-02-16T17:46:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 16, 2020, 6:02pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/4 "2020-02-16T18:02:13Z")

</div>

Did you try using

````
 ```swift

````

as I recommended?

It does this:

```swift
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](http://try.discourse.org). It seems to do the Right Thing on a test site that I have.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [February 17, 2020, 2:28pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/5 "2020-02-17T14:28:34Z")

</div>

> [@topogram](#):
>
> Is there a way to remove / unload the unnecessary languages loaded by Discourse?

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

````plaintext
```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:

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/0/90d5b7b863773cf1e2ec8e05ec73bbeccd0bf33b.png)

---

<div class="post-metadata">

### Author: ![topogram](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/topogram/32/155563_2.png) [@topogram](https://meta.discourse.org/u/topogram)
#### Post date: [February 17, 2020, 4:33pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/6 "2020-02-17T16:33:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 18, 2020, 8:14pm UTC](https://meta.discourse.org/t/highlightjs-is-auto-selecting-wrong-language/141739/8 "2020-03-18T20:14:39Z")

</div>

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