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 Google Code Prettify, and is not necessarily using the latest release of that library. Therefore, any bugs and ...
Back in May 2012, I started a project hosted on GitHub that implements MATLAB syntax highlighting for google-code-prettify (released under the MIT License). See here for the initial announcement, plus there was some discussion in the MATLAB chat room.
It comes in two flavors, one that detects and stylize all core MATLAB functions (plus functions from select ...
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 ...
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:
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:
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 ...
And why would Highlight.js be better than Google Code Prettify, considering that you admit yourself that you just heard of Highlight.js and therefore are probably unaware of its advantages/limitations/etc.?
You mention something about it looking "promising", but what does that mean? Moreover, why do we need something that only looks promising when we have ...
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.
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 ...
Syntax highlighting is dependent on the language. By default that is chosen from the tags that are on the question. However, the question doesn't have any languages tagged. So there's no syntax highlighting.
I've edited your post to manually enable C++ syntax highlighting by adding this:
<!-- language: lang-cpp -->
More Information: Syntax ...
There's no syntax highlighting because the question is lacking relevant tags.
This is by design. The backticks are for inline code, usually a single "word". You use it for stuff like root and abstract and enum and live(), etc. It will not appear on its own line unless you force it to.
A whole line of code is better put in the block codeblock--it gets its own line and is syntax highlighted as well.
Apparently not; I've added the python tag to the question and the code highlighting is now working.
I've also removed the python-2.7 tag from that question though, it is not the right tag for the question.
For future reference, you can also mark your code blocks with an explicit code hint:
<!-- language: lang-py -->
See How do I format my code ...
Which Stack Exchange sites have syntax highlighting enabled?
The syntax highlighting feature is enabled on the following sites:
Code Golf Meta
Computer Graphics Meta
You can't explicitly specify multiple languages for highlighting in a single code block.
var facebookLang = "en_US";
(function (d, s, ...
The syntax is <!-- language: lang-css -->. Note the language: part there, see How do I format my code blocks?. I've fixed that for you.
Note that normally your suggested edit stood the risk of being rejected for being too minor. Minor, quick syntax-formatting fix-only edits put an unnecessary strain on the suggested edits system, as 2 additional ...
The answer to this is pretty simple. There is no syntax highlighting in the comments. At most you can wrap your code in the usual back-ticks to give it somewhat of a different appearance, but that's about it.
You should not be posting substantial amounts of code in the comments anyway. They are not meant for that. Nor are they meant for extensive discussion ...
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 ...
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?
I've just submitted a suggested edit using the old-style code blocks and a language hint:
<!-- language: lang-r -->
That seems to work:
Your last version (revision 3) might not work since you used a capital R; language hints need to be in lower case.
I the correct method of specifying language highlighting is :
<!-- language: lang-c# -->
You were simply missing the lang- in the definition.
Check out the formatting sandbox to learn all the methods/tricks with regard to formatting.
Hit edit on any post that catches your eye and see how they did it.