I've had some problems trying to get my answer to have code blocks that are syntax highlighted with for different languages. The answer I'm talking about is here. The question is tagged for C# so by default everything got highlighted as C# (which makes sense). But part of my answer involved some Visual Basic code. I tried putting <!-- language: vb --> and <!-- language: lang-vb --> but neither of those worked. In the preview, the code was still highlighted as C#. I was thinking maybe the tags overrule what I specified.

Not wanting to give up so easily, I then tried <!-- language-all: vb --> which ended up working! The preview showed the C# code highlighted as C# and the one VB code block highlighted as VB. I posted my answer but then noticed that the 'real' (non-preview) view of the answer, had everything highlighted as C#!

I didn't want to keep fiddling with my question so I'm fine to leave it as is with the weird formatting for one code block, but it seems like we should be able to mix languages like this? At the least, it would be nice if the preview matches what actually ended up getting posted. Even now, I can go back and edit the question and then it looks fine in the preview.

1 Answer 1


You were doing everything correctly; you just uncovered two bugs at once. Both ways you tried should be working just fine. Unfortunately the way those two bugs worked together can be quite confusing.

  1. A bug in the JavaScript Markdown-to-HTML converter caused the generated HTML to have the wrong structure. This broke the <!-- language: XXX --> overrides, but not the <!-- language-all: XXX --> ones. Hence your first version looked wrong in the preview (ironically, it would have looked correct after submitting), but the second one looked as intended.
  2. A bug in the handling of global overrides (i.e. language-all) on the server side caused the code to pick the tag (i.e. vb), not the language code (i.e. lang-vb) to be applied to the codeblock, and that is just silently ignored. That's why your second try looked wrong after submitting (using lang-vb would have worked correctly), even though it looked correct in the preview (which didn't have this bug).

Sorry for the confusion; both bugs are fixed now. I've made a dummy edit to your post to force re-rendering; it is now highlighted as intended.

  • Wow, two bugs at once...not wonder I was so confused. It's looking good now, thanks! Sep 17, 2011 at 15:47

You must log in to answer this question.

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