What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

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.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
Wow, two bugs at once...not wonder I was so confused. It's looking good now, thanks! –  Stephen McDaniel Sep 17 '11 at 15:47

You must log in to answer this question.

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