What is syntax highlighting?
Syntax highlighting allows code in posts to be highlighted based on the language it's written in, to make it easier to read.
How does it work?
Stack Exchange does not have its own syntax highlighting engine. It uses highlight.js, and may not necessarily be using the latest release of that library. Therefore, any bugs and feature ...
Can Stack Exchange please update to newer versions of Highlight.js on a regular cycle, rather than only on request?
As I said in my prior post reporting Google's discontinuation of Prettify, the process of filing bugs and feature requests with syntax highlighting would be quite drawn out and take a needlessly long time. The process was like this:
File a bug ...
I found it rather frustrating that I couldn't easily see how the before/after pictures differed, so I did a bit of cutting and pasting so I could look at the before/after side by side to compare them more easily. Then it occurred to me that others might like to do the same, so feel free to have a look. Should be the same basic info as in the question, but ...
I'd like to say that I appreciate this post.
It is clear, very informative, very detailled, and to me shows that person's concern for the community.
Of course, there will always be different opinion on the result ("I prefer the former highlighting" "I prefer the new one!") but that is inevitable.
I find the reasons to change (and the ...
The results of my testing were disappointing - we will not go ahead with highlight.js as a syntax highlighter for Stack Overflow and our other sites.
It is not too big
It is - I generated a custom set of languages that mirrors the exact set we currently support with prettify. Uncompressed it is 57kb, compression takes it down to 22kb - compared with the ...
<!-- language-all: lang-none --> hint doesn't seem to work anymore
This post has a <!-- language-all: lang-none --> hint at the top of the post to prevent all the code blocks in it from being highlighted. I tried changing lang-none to none and it still didn't work. (As you say in your post, Prettify identifiers will still ...
Current maintainer of Highlight.js here, though I'd add a few quick comments.
highlight.js tends to not highlight punctuation, which makes it a bit less colorful than other highlighters. This is considered a feature. Not a deal breaker by any means, but something I should mention regardless.
This is something I'm open to improving if someone wants to work ...
I have now dragged in the lang-r stuff and set it against the r tag; there may be some small delay while the cache expires etc, but you should be able to explicitly specify it via:
<!-- language: lang-r -->
Once the cache has cleared (i.e. when it picks it up implicitly from r) you should also be able to specify it (when there is ambiguity) via:
What I think SO needs is:
A button next to the button on the editor toolbar.
Clicking the button would insert:
<!-- language: x -->
The caret would be automatically placed where the x is above, and a JS-driven Intellisense-style dropdown list would populate with some choices, something like this:
Typing lang-c would present:
😄 Thanks for doing this! I'm happy about this outcome, as I was a major proponent of switching to highlight.js back in 2016.
Great! …but what changed?
To satisfy my own curiosity, I'm wondering if you have an explanation or theory for what changed between 2016 and now to make the switch feasible. Oded's performance analysis seemed to raise some major issues,...
C is not supported
There is no C syntax highlighter in highlight.js. highlight.js uses the C++ highlighter for C, and it is a nightmare. It actually makes code harder to read than not having any highlighting. I saw a post on Stack Overflow wherein the same two tokens struct List are coloured in 3 different ways:
Yes, I've checked that lang-c is in use.
The highlighting hint only works when it's placed immediately before the code block. When the code block is inside a list or blockquote, the hint also needs to be inside that list or blockquote. However, it looks like our system doesn't properly parse the hint if it's the very first thing in the blockquote.
So this will parse out the hint and incorrectly ...
What to do if highlight.js supports a language but Stack Exchange doesn't?
There's an entire Mathematica StackExchange, and so Mathematica syntax highlight is clearly very important to us. But when I did some digging to find the highlight.js bundle that SE seems to be serving, Mathematica isn't in the registerLanguage("...", ...) blocks, even ...
The default pascal highlighter coming from the prettify project is bogus.
Based on it, I've made a new Delphi Google prettify highlighter that, not being perfect, address the following issues:
The backslash is not treated as an escape character in strings, so for example S := 'C:\' + Path now correctly ends the string.
The three flavors of comments are ...
Matlab syntax support is rolling in.
This is basic syntax support without keywords, as these add a lot to the size of the highlighter and do not gzip well at all.
Still - comments should be comments and basic highlighting should work as expected.
Is there syntax highlighting for Java stack traces? Yes and no.
You can add colour to your stack trace via the features of Google Prettify's standard Java syntax highlighting, which is what Stack Exchange uses. You'll get class and package colour added to your trace but no specific functionality that handles to traces and formats them for reading.
Which Stack Exchange sites have syntax highlighting enabled?
The syntax highlighting feature is enabled on the following sites:
Code Golf Meta
Computer Graphics Meta
Currently only moderators can change it. It is read-only text to everyone else, present solely so users can figure out which highlighter is being used for a given tag.
There is no mechanism in place whatsoever for "suggesting" it be changed outside of simply creating a new support request on Meta requesting it be changed for a given tag. There is no ...
The PR for adding Elixir support in code-prettify has just been merged. Stack Overflow should be able to build a new version of their prettify-full.js with Elixir support.
Does anyone know what would be the process for requesting that?
But this is much worse now, as the ...
in LaTeX code @ should be treated as a letter, any number of examples on tex.stackexchange but
Undefined control sequence on \beamer@leftmargin indentation
\beamer@leftmargin is a single token but beamer is coloured and @leftmargin is left as unstyled text ...
There has been times that I've turned off code highlighting with <!-- language: lang-none --> because Prettify was getting it wrong, and no highlighting is better than wrong highlighting. (The example that comes to mind was a Bash snippet where # wasn't a comment indicator, but Prettify thought it was.) After this change goes through, should I go back ...
Update: I've written a Chrome extension to give us a place to land some of these ideas (and experiment with them) until hopefully they can be added to official SE one day. This fancier auto-detect isn't supported yet but there is an open issue for it if anyone wants to help.
Current maintainer of Highlight.js ...
Officially, it would be lang-m (it's based on the file extension), but the prettifier then uses the same handler as used for C and C++:
}), ['c', 'cc', 'cpp', 'cxx', 'cyc', 'm']);
so you may as ...
There are many programming languages out there. It would be hard to keep track of all to know that a question contains a language tag or not.
And not all questions need a language tag. If you asked about deployment or need help on a regular expression.
If a question misses a language tag you can ask the OP for it. (I do it all the time in the SQL area ...