4

I have manually specified the lang-cmake syntax highlighting for the code blocks in my question:
How to instruct the CMake to use a specific CMAKE_GENERATOR_TOOLSET?

The syntax highligting works correctly in the preview pane when I am editing the question, but after saving the changes, the CMake syntax highlighting does not work. Why?

P.S.
This is the opposite behavior to the one described in the question below:
Code sample not syntax highlighted in edit mode, but is highlighted after posting

1 Answer 1

4

Keep in mind that CMake is not one of Stack Exchange's supported languages and as such the lang-cmake hint is invalid here. As noted there, Stack Exchange only supports a subset of Highlight.js's supported languages, to prevent the highlighting script it serves to others from being too large.

This is happening because in October 2024, changes were made to the syntax highlighting behavior for invalid language hints - prior to then, invalid identifiers would trigger an automatic language detection, then it was changed to not highlight at all. The reasoning behind the change is in the question which that post is answering. However, only the server-side renderer was changed; the client-side renderer was not updated to reflect the change. (Stack Exchange uses different renderers for the client-side preview and the server-side post rendering; occasionally there can be differences between both if one's changed while the other isn't.)

Therefore, in the preview, you see highlighting because your invalid identifier is triggering an automatic language detection (old behavior), while in the rendered post you don't see highlighting (new behavior). Looking at the Developer Tools on the preview's code blocks, it seems that your first code block is being recognized as Swift while your second one is being recognized as SCSS.

While the above third link technically does also report this bug (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), it primarily reports a separate bug, its title only mentions said separate bug, and the internal ticket that gets created upon a question getting the tag only has the title attached, so I'm going to let this stand as a separate report.

3
  • CMake is one of the languages supported by highlight.js, see: github.com/highlightjs/highlight.js/blob/main/… That is the first thing I checked. Commented Nov 15 at 20:15
  • 2
    @GeorgeRobinson It seems you missed the parts in the Meta.SE FAQ which say Not all languages supported by highlight.js are supported on Stack Exchange, Note that, as mentioned before, this is a subset of all languages supported by highlight.js, and the bulleted list below the second quote which lists languages. See also the "Note to editors" at its bottom. Commented Nov 15 at 20:15
  • Oh, for Pete's sake! Anyway, there is still the bug of the "discrepancy between what's shown in the preview and what's shown in the edited post for unsupported languages". Commented Nov 17 at 3:26

You must log in to answer this question.

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