The Stack Exchange engine will not add syntax highlighting by default. However, you can add explicit language hints like this:

<!-- language: lang-html -->

This is what we've been doing so far, but there is an even better way.

Stack Exchange allows to assign a language hint to every tag. It will then use that language to highlight the code in the question and its answers. If there's more than one tag that has syntax highlighting, it lets the highlighting engine infer what's the best language to use. See more information here:

What is syntax highlighting and how does it work?

You can see the assigned language on a tag's information page:

enter image description here

So far, I've assigned a default syntax to (C#) and (XML) and it works really well.

How you can help

Think of you favorite tags and post an answer to this question that will list tag names with desired syntax highlighting.

  • 1
    Annoyingly there is no lang-ps listed, but it does work.
    – Richard Seal Mod
    Commented Nov 1, 2016 at 21:16

2 Answers 2

  • 1
    Thank you! I applied these. As there's no option for lang-ps and lang-razor, I looked up corresponding tags on SO and applied the same highlighting options. For Powershell they have lang-bsh and for Razor-flavored tags they just use default, which essentially means "autodetect". Commented Nov 2, 2016 at 6:29
  • @DmytroShevchenko Today I learned. The default highlighter does a pretty decent job with Razor. Commented Nov 2, 2016 at 16:55
  • Well yes, it does a great job with most code blocks that have enough language-specific clues for it to recognize the language. Once it's aware it's the Razor syntax, it will prettify it in exactly the same way as if you specified lang-razor explicitly. Commented Nov 2, 2016 at 17:09

You must log in to answer this question.

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