2

So Sometimes my code will highlight properly and other times, it gets no colors or anything. What gives! I can't find anything on this meta that has discussed this aspect of this issue.

1 Answer 1

2

This is called syntax highlighting as explained over in the SE-meta post :

Before you do anything, are you sure that you've got the correct highlighting turned on? Behind the scenes, Stack Exchanges uses the tags on the question to infer the language you are using. If there's more than one tag that has syntax highlighting, it uses a default and lets Prettify infer what's the best language to use. If you're curious whether a tag has a language hint, any user is capable of checking by visiting that tag's wiki page.

Bolding mine. So, if you're offering a code answer to a question that isn't tagged with the code, you won't get syntax highlighting by default.

You can force a specific syntax by using Prettify language codes. Put this immediately before a code block, and it'll be highlighted as Bash:

<!-- language: bash -->

    for f in *.mp3; do echo "$f"; done
2
  • @slhck I tried that with lang-vb but I'm thinking I wasn't clear on exactly where it should be. In the code? Outside the code? Mar 5, 2015 at 13:39
  • 1
    Outside the code, before the code block. See for example here: superuser.com/posts/885595/edit
    – slhck
    Mar 5, 2015 at 13:39

You must log in to answer this question.

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