3
\$\begingroup\$

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

enter image description here

When we can have this?

enter image description here

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

\$\endgroup\$
4
  • 6
    \$\begingroup\$ I think when we graduate, the community should make an effort to contribute esolangs to Google Prettify so people can do <!-- language: lang-pyth --> \$\endgroup\$
    – cat
    Dec 26, 2015 at 16:40
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – Alex A.
    Jan 4, 2016 at 20:16
  • 5
    \$\begingroup\$ @cat Also, from the Prettify docs: "Prettifying obfuscated code is like putting lipstick on a pig — i.e. outside the scope of this tool." \$\endgroup\$
    – Alex A.
    Jan 4, 2016 at 20:24
  • 3
    \$\begingroup\$ @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... \$\endgroup\$
    – cat
    Jan 4, 2016 at 21:02

2 Answers 2

11
\$\begingroup\$

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

\$\endgroup\$
8
  • 1
    \$\begingroup\$ 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) \$\endgroup\$
    – Jojodmo
    Dec 25, 2015 at 8:23
  • 2
    \$\begingroup\$ @Jojodmo While there is a default setting for Google Prettify, it is not active by default on Stack Overflow. \$\endgroup\$
    – Alex A.
    Dec 25, 2015 at 17:06
  • \$\begingroup\$ @AlexA. Alright, I'll turn this into a feature request, then (Merry Christmas, BTW) \$\endgroup\$
    – Jojodmo
    Dec 25, 2015 at 17:07
  • 1
    \$\begingroup\$ @Jojodmo As Martin said, it doesn't make sense to do it, so why bother with a feature request? (Merry Christmas to you too ;)) \$\endgroup\$
    – Alex A.
    Dec 25, 2015 at 17:08
  • 2
    \$\begingroup\$ It'd be awesome if google prettify allows you to define a grammar for additional languages \$\endgroup\$ Dec 25, 2015 at 17:52
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Alex A.
    Dec 25, 2015 at 19:45
  • 1
    \$\begingroup\$ @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) \$\endgroup\$ Dec 26, 2015 at 1:50
  • 1
    \$\begingroup\$ @NathanMerrill Oh sure, I agree with you entirely, I'm just saying I don't think it's currently possible using Prettify. \$\endgroup\$
    – Alex A.
    Dec 26, 2015 at 20:18
6
\$\begingroup\$

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:

\$\endgroup\$
1
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ Jan 4, 2016 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .