-4

On the editing help page, there's an example showing syntax highlighting with a specified language.

For C# it specifies <!-- language: c# --> (you need to expand the section to see it), however this doesn't actually work.

It should be <!-- language: csharp -->.

5
  • 4
    I believe this is correct, "You can use either one of the supported prettify language codes, like lang-cpp or lang-sql, or you can specify a tag, "
    – gunr2171
    Commented Mar 4, 2015 at 22:00
  • I can use this correctly on the main site. It won't work here on meta because meta doesn't have a c# tag.
    – gunr2171
    Commented Mar 4, 2015 at 22:01
  • I tried using "c#" on stackoverflow.com/a/28865671/270348 and it didn't work.
    – RobSiklos
    Commented Mar 4, 2015 at 22:05
  • @RobSiklos It's not in the revision history.
    – Servy
    Commented Mar 4, 2015 at 22:16
  • @Servy that's because I made the edit too soon after posting the answer
    – RobSiklos
    Commented Mar 5, 2015 at 1:30

1 Answer 1

8

csharp is a Google Prettifier language code, so you'd spell it like:

<!-- language: lang-csharp -->

or

<!-- language: lang-cs -->

Note the lang- prefix. Without the prefix you can specify a Stack Exchange tag name, and then you'd use c#, so there is no bug here. The tag is configured to use lang-cs already, see the bottom of the tag wiki:

Code Language (used for syntax highlighting): lang-cs

As it happens, csharp is also a tag; it is a synonym for the [tag:c#] tag, so the same language association is in effect.

You may have missed this on the editing help page, but it is clearly documented there:

You can use either one of the supported prettify language codes, like lang-cpp or lang-sql, or you can specify a tag, and the syntax highlighting language associated with this tag will be used.

I changed your answer source to use <!-- language: c# --> and the highlighting is working just fine still. Perhaps you tried this in the editing preview and didn't wait for the timeout to pass before highlighting is applied?

6
  • Very weird, I don't understand why it seems to be working now. Oh well, sorry for the spam, I guess.
    – RobSiklos
    Commented Mar 5, 2015 at 1:31
  • 1
    @RobSiklos it could be you forgot the newline before the comment or made another typo along those lines. Commented Mar 5, 2015 at 7:44
  • Syntax highlighting doesn't always work in the editing preview. Commented Mar 8, 2015 at 9:45
  • @NisseEngström did you wait a few seconds? Highlighting is only applied after you stop editing for a while, after a timeout. Commented Mar 8, 2015 at 10:05
  • @MartinPieters: Much more than five seconds. I have no idea why it doesn't work occasionally. Commented Mar 8, 2015 at 10:58
  • 1
    @NisseEngström I never use tags in the syntax, I always use the lang- prefix. Perhaps that is the difference? Using a tag requires looking up the right Prettifier language to use on the server. Commented Mar 8, 2015 at 11:32

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