Here on mathematica.stackexchange we will most of the time have to deal with Mathematica code, but it clearly happens too, that someone posts Java-code for JLink or C-code for MathLink, etc. just look at
$InstallationDirectory/SystemFiles/Links to get an idea how many language bindings we have.
Google-code-prettify which is used for highlighting can deal with many languages, but I don't know how good the automatic code recognition works. I checked prettify.js and don't think the automatic detection can handle custom language plugins. Our Mathematica-extension is a custom made language-extension to google-prettify, which means we will have to tell at html-basis, that code posted here is
lang-mma. When the language is fixed, meaning when you make a code-block here it is replace by the editor with something like
<pre class="prettyprint lang-mma" id="mma">
(* Your code here *)
every code-block will be highlighted as Mathematica. This seems to be pretty much the same behavior which all SO sites have. You can inspect this by using Chrome and browsing a randomly chosen Java or C++ question, right click on the gray area inside a code block and chose Inspect Element. You see that the html-tags are always language specific. If you now draft an answer in the C++ question and post Java-code (use
instanceOf to make it crystal clear) and inspect the element in the preview, you see it's still C++. So no language detection.
Question: Would it be possible and feasible to highlight code on mathematica.SE always as Mathematica-code, but to have the opportunity to give a hint to the code-environment if the language is something else?
A quick search on meta.SO brought these two related threads to daylight:
- VB.NET/VBScript syntax highlighting does not properly support comments
- Improve The Code Tag Highlighting
There are several more questions about this, but they are tagged
prettify which suggests, that they talk about the development of prettify and not the inclusion in SO, am I right?