4

On a few occasion, I've seen code blocks such as:

#! /bin/zsh -

echo foo/*
echo this is not part of a C comment.

Being highlighted as C code even though the Q&A had a zsh tag and the shebang made it explicit what language the code is written in.

I feel like it should be relatively easy for the syntax highlighting code to detect this kind of situation and select the zsh syntax highlighter automatically here based on the shebang.

In any case, that's not limited to zsh, zsh just happens to be the language I use in most of my posts here. It would be useful for code blocks starting with #! /bin/bash - / #! /usr/bin/perl --, etc as well.

2
  • Glorfindel's answer makes me wonder if it's a problem for bash shebang as well. – Jeff Schaller Jan 4 at 1:06
  • @JeffSchaller, my point here was more a feature request about getting the highlighter to consider the shebang. Yes, I've seen the highlighter making the wrong guess for a number of languages, not only zsh. – Stéphane Chazelas Jan 4 at 6:40
3

If the question is tagged , it will already apply syntax highlighting 'shell style'. You can see that by checking the Tag Info; at the bottom there's a little message:

Code Language (used for syntax highlighting): lang-bsh

For the record, ♦ moderators are able to change this.

Stack Exchange highlighting isn't smart enough to parse shebangs, but we can help it by applying the correct tags to questions.

1
  • 2
    Today I learned about changing highlighting for tags -- thank you! – Jeff Schaller Jan 4 at 1:05

You must log in to answer this question.

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