This happens in my development setup, in a live discourse forum https://discourse.gohugo.io/ and the discourse playground.
In general when a fenced code block has no language set we get autodetection. This succeeds in a normal Highlight.JS usage (node or browser) all of the time by selecting something.
Discurses seems to save such blocks as <code class="lang-auto">. which is no valid language ![]()
I talked with the AI-Bot ask.discourse.cm…30386:
it told that you do some magic ON RUNTIME in removing the the “lang-auto” and then let highlight.js redo the auto work. It looks like that update is not all the time happening BEFORE highlight.JS touches the code. So that looks like a quirk in the highlight.js integration and auto-detect implementation within discourse.
unsetting a default language will also not work, cause then the “remove lang-auto” does not work and looks like the discourse way does not redo the autodetect.
- setting the language manually works all of the time – for built-in and a custom (hugo-templates) language added via the PluginAPI (registerHLJSLanguage) as a theme component.
- without a language it fails depending of the content() race conditions, timings
Setting default language to “text” won’t be a way cause we want that highlighted and we want autodetection for usability (and it works…)
Here’s a Markdown example, where the second code block fails (ofc only if the default language is set to “auto”. Easily reproducable with the below markdown on https://try.discourse.org/
and within 24h : Failed Discourse Autodetection breaks rendering of fenced code blocks - support - Discourse Demo
# This works
```
{{ $currentPagemd5 := md5 $currentPage.File.Path }}
{{ $currentPagemd5ext := (print $currentPagemd5 ".json")}}
```
# This failed and assigned "lang-auto"
```
{{ $currentPage := . }}
{{ $jsonFile := "" }}
{{ with $currentPage.File }}
{{ $currentPagemd5 := md5 $currentPage.File.Path }}
{{ $currentPagemd5ext := (print $currentPagemd5 ".json")}}
{{ $files := readDir "data/commits/" }}
{{if gt (len $files ) 0}}
<div class="bord-bas"></div>
<div>
<details>
<summary>Changements de la page</summary>
<div>
{{ range $files }}
{{ if eq .Name $currentPagemd5ext }}
{{ $jsonFile := $currentPagemd5 }}
{{ $data := index $.Site.Data.commits $jsonFile }}
<ul>
{{ range $data }}
<li>
{{ dateFormat "02/01/2006" .commit_date }} : {{ trim .message "\n" }} ({{ .author }})
</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
</div>
</details>
</div>
{{ end }}
{{ end }}
```
