7

On Stack Overflow I have answered many questions about Spock and Geb, two Groovy test frameworks. For years, I have used <!-- language: lang-groovy --> in combination with indentation by four spaces. Now I found out this syntax is deprecated, but for other languages like Java it still works, as I can see in my old answers. They have not been migrated to ```java. So I have several questions:

  1. Will there be automatic migration from tag-based code block syntax highlighting to backtick-based one without indentation?

  2. Specifically for Groovy, syntax highlighting does not work at all anymore, no matter if I use any of

    • <!-- language: lang-groovy -->
    • <!-- language: groovy -->
    • ```lang-groovy
    • ```groovy

    Will this be fixed? How do I correctly activate Groovy syntax highlighting now? It is not a super exotic language but one of the most popular JVM languages.


Update: This seems to be related to the syntax highlighter migration from Prettify to highlight.js which seems to have happened yesterday. But according to the list of supported languages (select categories "misc" or "all"), Groovy is supported by highlight.js.

  • ```groovy seems to be working fine. I edited (but didn't submit) one of your answers. Here's the "before and after". – 41686d6564 Sep 25 at 7:41
  • I also successfully edited one of my answers just now. But it does not work in many cases, for example here. I even saved the edit and dedented the code, but to no avail. So there must be a serious bug. Same goes for other answers I tried. Anyway, even if it would work, does anyone seriously consider it a good idea that I have to do that manually for dozens or hundreds of answers? – kriegaex Sep 25 at 8:07
  • 1
    Yes, I can reproduce this. You might want to add that link to your question. Or (probably better), post this bug report as an answer in the linked question as advised there: "Any bugs and feedback can be posted here as an answer." – 41686d6564 Sep 25 at 8:11
  • 2
    We have never had a 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. – animuson Sep 25 at 14:38
  • Thanks for the report. This is indeed due to syntax highlighter migration. Groovy is not on our list of officially supported languages, so if it worked before, it must have been snuck in with a Prettify update and not documented. Marking this as status-review for now and will follow up soon. – Ben Kelly Sep 25 at 14:59
  • The lang-groovy construct worked fine for years with Prettify. Feel free to check with an older version of StackOverflow. – kriegaex Sep 25 at 15:21
  • 3
    @kriegaex It has never been implemented. In Prettify, an invalid identifier reverted to default, and that is what you were seeing. – animuson Sep 25 at 15:42
  • Thanks for the insight. I never said it was implemented. As a normal user I have zero insight there. Some years ago I just tried and miraculously it worked. From a user perspective that was the important thing: I used it, it worked and it was extremely helpful. – kriegaex Sep 26 at 2:54
6

This has been "fixed". We still do not support the groovy language explicitly, but syntax autohighlighting should at least kick in for unrecognized lang-* language overrides (on sites that allow for it, such as Stack Overflow). Due to not officially supporting the groovy syntax, this may have unintended highlighting depending on what language highlight.js decides the code snippet is.

| improve this answer | |
  • Thank you so much. I can see that ```lang-groovy is now working, but not ```groovy. Actually in the past few years I was amazed at how good this worked and even for short and ambiguous snippets did not mess up highlighting due to auto-detection. Ben, ist there any chance to get Groovy supported officially? This was my very first question on Meta, I would not know how to go about making a feature request but also would not be surprised if someone already created one long before me. Would it be a big effort to support it, given the fact that highlight.js already does (as did Prettify)? – kriegaex Sep 26 at 2:51
  • Another thought: Auto-detection might work for Groovy because the highlighter detects Java. But there are some syntactic differences, so dedicated Groovy support would be helpful for the big Groovy community on SO. – kriegaex Sep 26 at 3:04
  • 1
    Just FYI: our Groovy grammar currently weighs in at 3387 bytes uncompressed if SO chose to add it. Pretty small. – Josh Goebel Oct 17 at 21:23
  • After watching this for a while, I noticed that highlight.js seems to guess wrong about which language to highlight more often than Prettify, especially for short code snippets. So for now I manually select Java as the target language, which is kind of suboptimal, like I said. It also means that snippets using java instead of lang-groovy will not automatically be highlighted correctly after maybe in the future Groovy will be supported officially. These facts make it even more plausible to add Groovy support for SO syntax highlighting. Spock, Geb and Grails are quite popular tools. – kriegaex yesterday
  • @kriegaex what SO needs to do if Java is a decent fit is just map groovy to Java. Highlight.js makes this trivial to do with aliases. This is also future proof in that if stack overflow adds groovy highlighting in the future then they can just change the mapping and the new highlighting will happen. Letting auto detect randomly pick a language every time when it’s known the language is missing is going to result in terrible and very inconsistent highlighting. This is very bad behavior. – Josh Goebel 16 hours ago
  • Sorry, no. Java and Groovy syntaxes are not the same. Java is just a crutch, workaround. The alias would be better than nothing temporarily, but there is quite some Groovy stuff that is not highlighted correctly in Java mode. If someone invests effort and time here, I guess it should be done right. Also, whenever Groovy highlighting gets fixes, updates or improvements, SO users would automatically profit from it. – kriegaex 16 hours ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .