26

As cocomac points out in the comments, this specific instance of the issue may be explained by this; so the example below, that showcases the bug for lang-vim, is an unfortunate one.

However:

  1. The same also happens for lang-console, which is listed among the supported languages, and at the same time lang-shell works, so it seems like the bug is there anyways, and it's affecting some aliases handled by Highlight.js and, as shown by the tests conducted by zcoop98, also some "main" language codes (see the lang-javascript example in their answer; in that case, lang-javascript, a "main" language code, is broken; bizarrely, lang-js, an SE alias for lang-javascript, works);
  2. I'd argue that there's also a side-bug in the discrepancy between what's shown in the preview and what's shown in the edited post for unsupported languages; preview and edited post should be consistent with each other. A minor thing, I agree, but still kinda annoying. Personally, I like to see exactly how my post is gonna look like.

Initial (partially wrong) report, now amended by the paragraphs above:

This is new, it used to work fine up until a few days ago.

On multiple sites (I've experienced this on Ask Ubuntu and Unix & Linux), syntax highlighting when using lang-* with a language that doesn't have a tag that hints at it is broken; the post is displayed correctly in the preview while editing it, but syntax highlighting isn't applied at all after the edit has been sent through.

I'm saying "with a language that doesn't have a tag that hints at it" because, on the same post, lang-bash (which I'm pretty sure it's hinted at by ) works.

The screenshots were taken on Chromium 129.0.6668.89 stable / openSUSE Leap 15.6, however I think the issue may be browser-agnostic (server-sided even, due to the nature of the issue); however, for reference, I get the exact same on Firefox and Chrome on Ubuntu 24.04.

This is the link to the post in the example however this also shouldn't really matter as I'm getting this everywhere, on questions, answers and across sites.

While editing:

s1

After the edit has been sent through:

s2

But lang-bash works:

s3

14
  • 5
    Probably related: This staff answer to Stop guessing/auto-detecting a language when you KNOW it will be incorrect.
    – cocomac
    Commented Oct 10, 2024 at 2:38
  • 1
    @cocomac If that's the case I'd argue the bug is in syntax-hihglighting the preview, however: lang-console is still listed among the supported languages, yet I'm getting the same even for lang-console. So either the list is not updated or there's something else going on as well (and regardless, the discrepancy is kinda annoying, shouldn't a language that is not going to be highlighted not be higlighted in the preview as well?)
    – kos
    Commented Oct 10, 2024 at 2:48
  • 2
    The lang-console thing is weird, here's it working just fine a week ago: unix.stackexchange.com/a/784428/70524 (or at least, it's still showing the correct syntax highlighting and the HTML shows that console is used, but your post shows none is used.
    – muru
    Commented Oct 10, 2024 at 4:41
  • 1
    @muru Yeah exactly, it stopped working out of the blue. Both this and the fact that it doesn't affect old posts are consistent with how they said the change would roll out, however lang-console is still (supposedly) supported, so I don''t know.
    – kos
    Commented Oct 10, 2024 at 4:57
  • 3
    lang-console is listed as Highlight.js alias (inside parentheses), so I wonder if it's only the aliases that don't work now. Commented Oct 10, 2024 at 5:59
  • @MetaAndrewT. Spot on, lang-shell works. I'll edit the question
    – kos
    Commented Oct 10, 2024 at 6:07
  • 1
    @zcoop98 Absolutely, I thought it had something to do with that at first because I wasn't aware of the changes to supported languages (and neither lang-vim nor lang-bash are aliases), so the only thing that that explained the discrepancy (in my mind at the time) was the "being hinted at by a tag" thing; I left that part of the question as is, amending it just in the initial paragraph once I got the full picture thanks to the comments
    – kos
    Commented Oct 10, 2024 at 19:14
  • I think, based on that, the only real bug here is lang-console not working in the linked Unix.SE post. The reason lang-vim is colorless because it's not on the supported list, and the new change makes hints for non-supported languages intentionally colorless. But something odd is definitely going on with that console hint, since it should work, and does in the preview pane, but doesn't in posted posts.
    – zcoop98
    Commented Oct 10, 2024 at 19:22
  • 2
    @zcoop98 Yeah exactly. Also, the additional bug is that unsupported languages (which won't be highlighted in the actual post per the recent changes), are highlighted in the preview, as if they were gonna be highlighted in the actual post
    – kos
    Commented Oct 10, 2024 at 19:31
  • 2
    You're absolutely right, the preview highlight definitely should match what's going to post. This is pretty bad; e.g. the only hint that currently works for JavaScript of the five listed is lang-js, and I can't imagine that's the only case. The update seems to have broken many hints.
    – zcoop98
    Commented Oct 10, 2024 at 19:35
  • 1
    @zcoop98 Actually I'll take that back: if only Highlight.js aliases were broken, lang-javascript should've worked, but your tests show it doesn't. So it's a mess. And I now feel like I'm debugging my own crappy code, which I've had enough of for today, so I guess I'll let devs figure out exactly what's going on :)
    – kos
    Commented Oct 10, 2024 at 19:57
  • 2
    I can't understand what sort of highlighting one might expect from lang-vim, or why. It's a text editor; the entire point is that the syntax highlighting will depend on what you're editing, not on what you use to edit it. Commented Oct 12, 2024 at 3:43
  • 4
    @KarlKnechtel That's entirely beside the point, however Vimscript is a fully-fledged scripting language and as such has tokens, much like any language, that can be highlighted to enhance readability.
    – kos
    Commented Oct 12, 2024 at 5:00
  • 1
    This was tagged as completed yesterday. Commenting here so you're notified. @Frog Would be nice to know what the glitch was and how it was fixed. Commented Apr 5 at 2:17

2 Answers 2

16

This issue doesn't seem to have anything to do with tags, especially since it's replicable here on MSE where virtually no language hints have a tag with the same name.

Instead, like you mentioned in your edit, it seems like we've got two distinct issues here:

  1. Highlighting in post previews is broken, possibly because it wasn't updated to use the new rules now applied to actual, rendered posts.

    E.g. using lang-nonexistent on a post still produces highlighting in preview:

    Highlighted code despite garbage lang hint

    Despite this not doing anything in rendered posts:

    console.log('Hello highlighter!');
    
  2. Many aliases are now completely broken, and do not produce any highlighting. E.g., for JavaScript there are 5 aliases:

    lang-javascript, lang-js, (lang-jsx, lang-mjs, lang-cjs)

    But only the lang-js appears to actually work when posted:

    lang-javascript
    console.log('Hello highlighter!');
    
    lang-js
    console.log('Hello highlighter!');
    
    lang-jsx
    console.log('Hello highlighter!');
    
    lang-mjs
    console.log('Hello highlighter!');
    
    lang-cjs
    console.log('Hello highlighter!');
    

    Despite all of the above working in preview:

    All five above code blocks highlighted properly in preview

3
  • 9
    I'll report this here as well; at first sight one may think only aliases are broken, however these tests show that also "main" codes are broken (lang-javascript should be a "main" code, and lang-js an SE alias for lang-javascript). In short, it's a mess.
    – kos
    Commented Oct 10, 2024 at 19:59
  • 2
    same for lang-ts and lang-typescript
    – aepot
    Commented Oct 15, 2024 at 14:45
  • 1
    Seems to have been fixed. Note that it still continued to show incorrectly until I forced a rebake. Commented Apr 14 at 17:16
9

We've addressed the all the issues raised by kos & zcoop98 that were caused by updates in Stop guessing/auto-detecting a language when you KNOW it will be incorrect

  1. We now exclude tags that aren't part of our predefined list of known good tags from highlighting in both preview and when rendered. This is somewhat tricky because we have two different MD -> HTML engines, one running in client-side running in JS, one in server-side running in C#.
  2. We shored up the aliases used for each language block client and server side so they're the same.

Test Case 1 - Non Existent language tag

Input

```lang-nonexistant
var x = "123";
```

Output

var x = "123";

Test Case 2 - Supported Language Aliases

Input

```lang-js
var x = "123";
```

```lang-javascript
var x = "123";
```

```lang-bash
grep "pattern" filename.txt
```

```lang-sh
grep "pattern" filename.txt
```

Output

var x = "123";
var x = "123";
grep "pattern" filename.txt
grep "pattern" filename.txt

It should be noted that existing posts that have been affected by this bug need to be edited to have the fix - existing posts have not been re-rendered.

Thanks for reporting!

5
  • 6
    Thanks for the update, and please folks give a nice warm meta welcome to Craig!
    – KyleMit StaffMod
    Commented Apr 14 at 17:03
  • 3
    Just a note: prior affected posts will need to be re-edited to fix the problem, as the incorrect rendering without highlighting will remain cached otherwise. Also, welcome! Commented Apr 14 at 17:17
  • 3
    I would be baffled if your changes would convert grep "pattern" filename.txt into #!/bin/bash - could you please adjust the last two examples in Test Case 2? (and welcome to Meta.SE, where we scrutinize first answers :D)
    – Glorfindel Mod
    Commented Apr 14 at 18:17
  • 2
    Yep, @Sonic-missesShadow-Hedgehog, confirming old posts would need to get edited/rebaked. We usually don't rebake old posts unless we have a good sense of high impact ids that we should batch through.
    – KyleMit StaffMod
    Commented Apr 14 at 18:50
  • 3
    @Glorfindel, but wouldn't it be wild if it did! Yeah, copy pasta on my end. Fixed the post to make it more clear
    – KyleMit StaffMod
    Commented Apr 14 at 18:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.