If the identifier you use in the language directive
- starts with
lang-
- but is not listed under "Language codes" in this post
you would get the default syntax highlighting behavior.
Specifically, invalid identifiers such as lang-csharp
, lang-doesnotexist
, and lang-iambanana
are treated as lang-default
.
The default syntax highlighting (lang-default
) works by highlighting any keyword from any predefined keyword list in prettify.js. This means it can "grab" keywords from multiple languages, even though the code is written in a single language.
== End of TL;DR region ==
Some examples to illustrate what I'm saying
Example 1: lang-cs
This markdown
<!-- language: lang-cs -->
public static bool IsAwesome { get { return true; } }
renders as

Example 2: lang-i-am-a-banana
This markdown
<!-- language: lang-i-am-a-banana -->
public static bool IsAwesome { get { return true; } }
renders as

The difference between lang-cs
and lang-i-am-a-banana
If we compare Examples 1 and 2, note that bool
and get
which was not highlighted with lang-cs
was highlighted with lang-i-am-a-banana
.
Looking at the C#'s keyword list
var FLOW_CONTROL_KEYWORDS = ["break,continue,do,else,for,if,return,while"];
var C_KEYWORDS = [FLOW_CONTROL_KEYWORDS,"auto,case,char,const,default," +
"double,enum,extern,float,goto,inline,int,long,register,short,signed," +
"sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];
var COMMON_KEYWORDS = [C_KEYWORDS,"catch,class,delete,false,import," +
"new,operator,private,protected,public,this,throw,true,try,typeof"];
var CSHARP_KEYWORDS = [COMMON_KEYWORDS,
"abstract,as,base,bool,by,byte,checked,decimal,delegate,descending," +
"dynamic,event,finally,fixed,foreach,from,group,implicit,in,interface," +
"internal,into,is,let,lock,null,object,out,override,orderby,params," +
"partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong," +
"unchecked,unsafe,ushort,var,virtual,where"];
- I'm not sure why
bool
was not highlighted with lang-cs
, maybe SO/SE is not using the most recent revision of prettify.js? The latest revision at the time of writing, r303 added bool
to C#'s keyword list.
get
is most definitely not in C#'s keyword list, even in the latest revision
Assuming that SO/SE is using an older revision, in lang-i-am-a-banana
mode, bool
is "grabbed" from C++'s keyword list
var CPP_KEYWORDS = [COMMON_KEYWORDS,"alignof,align_union,asm,axiom,bool," +
"concept,concept_map,const_cast,constexpr,decltype,delegate," +
"dynamic_cast,explicit,export,friend,generic,late_check," +
"mutable,namespace,nullptr,property,reinterpret_cast,static_assert," +
"static_cast,template,typeid,typename,using,virtual,where"];
in lang-i-am-a-banana
mode, get
is "grabbed" from JavaScript's keyword list
var JSCRIPT_KEYWORDS = [COMMON_KEYWORDS,
"debugger,eval,export,function,get,null,set,undefined,var,with," +
"Infinity,NaN"];
Invalid identifiers that don't start with lang-
The fallback to lang-default
isn't triggered if your identifier doesn't start with lang-
<!-- language: i-am-a-banana -->
public static bool IsAwesome { get { return true; } }
renders as

or renders according to language tag the question is using. In this case, the language directive simply gets silently ignored.
lang-csharp
does not exist. You're seeing the default syntax highlighting by using that. The c# tag is set to uselang-cs
.namespace
isn't highlighted.lang-cs
doesn't work for some keywords. But thelang-csharp
works.lang-cs
orlang-c#
(tag name) can be used.lang-csharp
does not exist. By using that it's reverting to default. If those keywords happen to get highlighted, that's merely coincidence.lang-csharp
?lang-csharp
is not real.lang-cs
. Maybe I'll file a issue on their site.