# Why isn't there default syntax highlighting for code?

I was going through Code Golf, and I noticed that there is no default Google code prettify like there is on Stack Overflow.

I recently updated one of my submissions to be syntax highlighted. I think we can all agree it looks much nicer than the non-highlighted version.

Why should we settle for this

When we can have this?

Right now, if you would like, you can prettify your submissions by simply adding

<!-- language-all: lang-default -->


Somewhere in them

Note: This would have to be turned off by default for some tags, such as cops and robbers - looking at the source code would (I'm fairly certain) reveal what language is highlighted

• I think when we graduate, the community should make an effort to contribute esolangs to Google Prettify so people can do <!-- language: lang-pyth --> – cat Dec 26 '15 at 16:40
• @cat It's my understanding that while languages can be contributed to Google Prettify, all but the most common subset of languages are actually extensions which are not available by default. Stack Exchange's interface to Prettify includes the basic Prettify languages as well as a very small subset of the available extensions, such as LaTeX and Lua. You could petition Meta.SE to add Pyth or whatever (as I think was done with R), but I almost guarantee you it'll be declined. – Alex A. Jan 4 '16 at 20:16
• @cat Also, from the Prettify docs: "Prettifying obfuscated code is like putting lipstick on a pig — i.e. outside the scope of this tool." – Alex A. Jan 4 '16 at 20:24
• @AlexA. ): well then I'll start my own online syntax-highlighting service with oodles of support and petition MSE to add it, or petition MSE to add it for code golf, or something... – cat Jan 4 '16 at 21:02

AFAIK there is no default syntax highlighting on SO. Instead a default syntax highlighting can be set for each tag. Almost every question on SO has a language-specific tag and those come with the appropriate syntax highlighting. This doesn't really make sense for most challenges on PPCG. Answers are in all sorts of languages, and no single language syntax highlighting would do most of them justice.

We could set them for the few language tags we have, but even those are often used for challenges about that language, not challenges where all code has to be written in that language.

(As a side note, a site that does have default syntax-highlighting everywhere is Mathematica.SE but that's a language-specific community.)

• Actually, there is the default <!-- language: lang-default --> which lets prettify interpret the code, and attempt to use the correct highlighting for that language... Try it on one of your answers - put <!-- language-all: lang-default --> above some of your code (I don't know how the leaderboards on challenges get data from submissions, but I wouldn't put it above the header) – Jojodmo Dec 25 '15 at 8:23
• @Jojodmo While there is a default setting for Google Prettify, it is not active by default on Stack Overflow. – Alex A. Dec 25 '15 at 17:06
• @AlexA. Alright, I'll turn this into a feature request, then (Merry Christmas, BTW) – Jojodmo Dec 25 '15 at 17:07
• @Jojodmo As Martin said, it doesn't make sense to do it, so why bother with a feature request? (Merry Christmas to you too ;)) – Alex A. Dec 25 '15 at 17:08
• It'd be awesome if google prettify allows you to define a grammar for additional languages – Nathan Merrill Dec 25 '15 at 17:52
• @NathanMerrill It does, but not directly in a post. You can submit your language definition to it on GitHub if I'm not mistaken, though I'm not sure whether SE supports all Prettify extensions or just a specific subset. In any case, using an unrecognized language in a Prettify tag will fall back on lang-default. – Alex A. Dec 25 '15 at 19:45
• @AlexA. Submitting a new language for GitHub for approval isn't nearly as good as defining your own (in a post, or somewhere else on initialization) – Nathan Merrill Dec 26 '15 at 1:50
• @NathanMerrill Oh sure, I agree with you entirely, I'm just saying I don't think it's currently possible using Prettify. – Alex A. Dec 26 '15 at 20:18

I would consider having lang-default active by default on the challenge tags actively harmful to submissions. It doesn't always make sense and can in some cases make the submission harder to read.

As an example, consider Matlab. There is a Prettify extension for Matlab, but Stack Exchange doesn't include it in its subset of available languages. Using the default highlighting scheme causes the following issues:

• Matlab uses % for comments, not #, so comments are highlighted like syntax
• Matlab uses ' as the transpose operator, which the default scheme assumes marks the beginning of a string. So if there's one transpose in some code, everything after it will be string colored.

If a user wants highlighting for their code, they can simply activate Prettify manually using <!-- language-all: lang-XXX -->, where XXX is default for unsupported languages.

Further resources:

• I have previously reverted at least one edit to one of my answers which added syntax highlighting for an unsupported language and made it harder to read. – Peter Taylor Jan 4 '16 at 22:13