1

I ran into this while editing an answer. Putting an @ in front of a quoted string in C# tells the parser that any \ characters in it should be treated as literals not escape characters. StackOverflow's parser apparently doesn't know that. At first I thought it was just failing to close the string at the proper place, but something more serious appears to be going on because instead of inverting string literal and normal code everything from that point on was colored as a string literal. I was able to work around it by using an equivalent alternate syntax to get the code to display correctly; but I shouldn't've had to do so.

Error case: error case

Worked around: enter image description here

1 Answer 1

7

It's not being interpreted correctly as C# code because of the tags. The tag also has a syntax highlighting option set to lang-sql, and having multiple options on one post causes the highlighter to revert to default.

Manually adding <!-- language: lang-cs --> at the beginning of the post solves the problem.

3
  • Is there a reference page anywhere listing all the options for manually setting the language like that? Also, can U use more than one language statement if needed for different types of code? Commented Jul 20, 2014 at 22:54
  • @Dan here's the reference: meta.stackoverflow.com/editing-help#syntax-highlighting
    – Blorgbeard
    Commented Jul 20, 2014 at 22:55
  • 1
    @DanNeely Yes: you just use HTML comments for each block. In fact, by default, the comment will only apply to the first following code block unless you use language-all. The syntax is <!-- language: tagName --> or <!-- language: lang-languageName -->. For each of those, changing language to language-all applies it to all of the code blocks in the post.
    – AstroCB
    Commented Jul 20, 2014 at 22:59

You must log in to answer this question.

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