7

Right now the code blocks on SF don't support syntax highlighting. Instead we get boring, grey, hard to read code.

I spent some time today on the Unix & Linux SE, which does offer syntax highlighting. It does so based on the assumption that any code in blocks is probably in some sort of shell language like bash.

Could we have a similar system on SF that uses the tags to form assumptions?

E.g. if a question is tagged PowerShell, the code blocks in the question and answers will probably contain PowerShell.

4

We do have syntax highlighting on some tags. We just don't turn it on by default since we get sooooo vastly more log-snippets than code-snippets that generic highlighting doesn't work. We had it on at the w-a-y beginning in 2009, but turned it off since it didn't do anything for us.

I just can't find where mods set it on the tags. I do know it's per-tag though.

  • 1
    +1 It'd be pretty useless even on a per-tag basis. Too many logs... – Chris S Jan 19 '12 at 14:01
  • Manual specification of the language, supposedly overriding the highlighting from the tags, doesn't work. See this answer, for instance; I specified <!-- language: lang-c --> at the top of the code block and it didn't do anything. – Shane Madden Jan 19 '12 at 16:04
  • What'd be nice is if there were some good coloring for some of the common config file types we see - XML coloring would catch the handful of XML configs, but it'd be really cool to see some good coloring on Puppet manifests, Apache configs, Cisco configs, etc. I wonder how much of a pain it'd be to add types? – Shane Madden Jan 19 '12 at 16:18
  • 2
    You can't find the setting because code highlighting is turned off for Server Fault. Let us know if you want to give it another try, we can turn it on then. – balpha Jan 20 '12 at 7:04
  • @balpha Looks like a "yes": meta.serverfault.com/questions/2717/… – Shane Madden Jan 25 '12 at 16:44
6

As proposed by balpha, we should make up our mind about this and put it to a vote. I'll check back for comments here but if I haven't heard back before monday I'll make a vote-Question.

4

We should enable Manually specify language for syntax highlighting so people in the know can add the relevant language descriptor to posts. It'd be nice too if the Question box auto prompted you (a box on the right side perhaps) when you paste a log/code snipet, giving you a list of possible lang specifications that the user can easily click on.

2

While on the surface this sounds like a great idea it's not as attractive after giving it some more thought. Due to the diversity of what we work with I just can't see tags being a good way to go.

What if someone used the powershell tag but is actually asking "how can I do the equivalent of this bash script in PS?"

A question may have bind9 and perl tags. What syntax gets applied? The code may refer to either a Perl code snippet or to part of a BIND config file. Possibly even one of each.

If the user has to over-ride that with special markup things just get messier. The markup used on SE sites is quite unintuitive and many (most?) of us only use the small sub-set we've managed to remember, or none at all.

  • Indeed, a common case on ServerFault would be to see a question tagged with [apache2] and [php] with code blocks containing log files as well as those two languages. Worse, the log files can even contain snippets of PHP. Heuristically identifying the language might be plausible but I think manually specifying or getting no highlighting would be the only safe option. The markup syntax problem should be solved by adding a dropdown in the buttons above the text area. – Ladadadada Jan 24 '12 at 22:01

You must log in to answer this question.

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