As of 2024, on Stack Overflow, this does not appear to work for either Markdown style code blocks or indented code blocks with a language "hinting" comment.
Note: I assume the reason Groovy was dropped, was due to the fact that Kotlin has replaced it in the Gradle/Android community.
Markdown style
```groovy
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'com.microsoft.playwright:playwright:1.44.0'
}
test {
useJUnitPlatform()
}
```
Indented code block with hinting
<!-- language: lang-groovy -->
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
They both renders as lang-none
:
<pre class="lang-none s-code-block">
<code>
<!-- Code here -->
</code>
</pre>
Research
I viewed the Stack Overflow highlight.js script:
https://cdn.sstatic.net/Js/highlightjs-loader.en.js
And I searched for "grmr_", and noticed that only 48 languages are supported.
The official highlight.js docs state:
Supported languages:
Note: The languages available will depend on how you’ve built or are included the library in your app. For example our default minified web build includes only ~40 popular languages. See Getting the Library and Importing the Library in the README for examples of how to load additional/specific languages.
The number ~40 coincides with the 48 languages that Stack Overflow supports:
- bash
- c, clojure, coffeescript, cpp, csharp, css
- dart, delphi
- erlang
- go
- haskell, http
- ini
- java, javascript, json, julia
- kotlin
- latex, less, lisp, lua
- makefile, markdown, matlab
- objectivec, ocaml
- perl, php, php_template, plaintext, protobuf, python
- r, ruby, rust
- scala, scheme, scss, shell, sql, swift
- typescript
- vbnet, vhdl
- xml
- yaml
Conclusion
So I am wondering why Stack Overflow can't build their own minified build with more supported languages?
Update
This kind of works, but only in a live preview; prior to submission. I assume it defaulted to bash
because that was the first one in the list.
<!-- language: lang-groovy -->
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
It renders as:
<pre class="lang-groovy s-code-block">
<code data-highlighted="yes" class="hljs language-bash">
<!-- Code here -->
</code>
</pre>
```groovy
seems to be working fine. I edited (but didn't submit) one of your answers. Here's the "before and after".lang-groovy
syntax highlighter in our system, on either Prettify or highlight.js processors. It is supported by highlight.js but we did not pull the language in because we did not support it previously. The groovy tag is set to default, which means the highlighter will attempt to highlight the code based on generic language constructs because it does not know the actual language. If you'd like support, I'd suggest turning this into a feature request.lang-groovy
construct worked fine for years with Prettify. Feel free to check with an older version of StackOverflow.