irkode
July 28, 2026, 7:59pm
7
Just for Info:
while checking how it’s going with the highlight I found that sometimes blocks are not highlighted at all…and not only with my grammar thought about timing linits, … but it was a hard CAP by code block size.
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...
Reading time: 1 min 🕑
Likes: 4 ❤
and here is a PR that should solve the problem
Still a hard limit on 30000 bytes
raise the autodetect limit to 2K
if it’s longer, use the first 2000 bytes to try autodetect
main ← fix-code-highlight-auto-detect
opened 05:47PM - 28 Jul 26 UTC
Fenced code blocks with no language are cooked as `<code class="lang-auto">` and… highlighted via auto-detection at runtime. Blocks over 1000 characters of markup were skipped entirely, and that early-out left the invalid `lang-auto` class on the element, so they rendered unhighlighted and unstyled. The threshold was arbitrary and small enough to catch ordinary snippets.
Auto-detection weighs the content against every enabled language, so its cost grows with both block size and language count. Rather than cap by size, detect the language from a bounded prefix and then highlight the full block with just that language, keeping detection cost constant regardless of block size.
The `lang-auto` marker is now always removed, so a block that still cannot be highlighted degrades to plain text instead of carrying an invalid class.
and live: How to capture/generate revisions of page? - #2 by Welsh