561

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 ...


173

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 ...


115

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 ...


59

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 ...


35

Yep, these changes are intentional. We had to move some variables around to clean up our CSS. These were matched with the closest re-usable color values we have in our design system. ๐Ÿ‘‹


34

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 ...


27

bug status-bydesign <!-- 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 ...


27

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 ...


22

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: <...


21

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: My 2ยข.


21

No, there isn't, partially since "pseudocode" is ill defined and can be of many different formats. There are no plans to include anything that cannot be properly defined.


20

๐Ÿ˜„ 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,...


20

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. I ...


18

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 ...


18

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 ...


16

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 ...


15

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.


14

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. An ...


14

Which Stack Exchange sites have syntax highlighting enabled? The syntax highlighting feature is enabled on the following sites: Arduino Arduino Meta Ask Different Ask Ubuntu Bioinformatics Bioinformatics Meta Blender CS50 CS50 Meta Chemistry Chemistry Meta Code Golf Code Golf Meta Code Review Computational Science Computer Graphics Computer Graphics Meta ...


14

Kotlin highlighting is now live!


13

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 ...


12

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?


12

Why not use the same stack as the one used by GitHub flavored markdown? According to GitHub doc they use Linguist as language detector, which has a pretty long list of supported languages.


12

I've just tried the following piece of JavaScript code (from this answer of mine in Code Golf) because Google Prettify was not parsing the regular expression followed by an inline comment correctly. That's why I used alternate slash characters in the original post (I've turned them back into regular slash characters below). But this is much worse now, as the ...


12

in LaTeX code @ should be treated as a letter, any number of examples on tex.stackexchange but Undefined control sequence on \beamer@leftmargin indentation \begin{frame}[fragile]{E} \makeatletter \hskip-\beamer@leftmargin \makeatother \lipsum[2] \end{frame} \beamer@leftmargin is a single token but beamer is coloured and @leftmargin is left as unstyled text ...


11

I have added the syntax highlighting logic for YAML. It is now live (as you can see above).


11

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 ...


11

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. https://github.com/joshgoebel/se_highlightjs Current maintainer of Highlight.js ...


10

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++: registerLangHandler(sourceDecorator({ 'keywords': CPP_KEYWORDS, 'hashComments': true, 'cStyleComments': true, 'types': C_TYPES }), ['c', 'cc', 'cpp', 'cxx', 'cyc', 'm']); so you may as ...


10

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 ...


Only top voted, non community-wiki answers of a minimum length are eligible