With code blocks, we get correct ES2015 ("ES6") syntax highlighting, but in stack snippets, we don't. Since it works for blocks, it's not a Google Prettify issue; it's the information we're passing to Google Prettify. Could we fix that please?
I think it's because Stack Snippets use <!-- language: lang-js -->
but on SO we automatically tell Prettify to use language: lang-es6
instead when the javascript
tag is present on the question. (Modifying the snippet's comment manually to lang-es6
makes the snippet not a snippet anymore...)
Details:
Here's an image from SO (ES2015 highlighting doesn't appear to work on MSO at all); I've made it large because the difference between the blue and black is fairly subtle:
Note how Google Prettify knows to highlight let
in the code block, but not in the snippet. So it's not Prettify that's the problem, so this isn't covered by What is syntax highlighting and how does it work? Apparently it's how we trigger Google Prettify for snippets that's not triggering the right highlighting.
FWIW, here's that block and snippet, but again, let
isn't highlighted correctly here on MSO at all (probably because the automatic javascript
tag detection isn't enabled here), although it is on SO in a question or answer with the javascript
tag:
Code block:
var a = 1;
let b = 2;
Stack Snippet:
var a = 1;
let b = 2;