Update: I've gone ahead and updated the FAQ with the specified changes
I recently became aware of the fact that the full list of language identifiers for the syntax highlighter on SE is a bit... mysterious. There's lots of confusion about it, and the list in the FAQ is a bit unreliable, mostly because it's not backed by anything official, and it has often been edited by those with good intentions but poor information (At time of writing there are 102 revisions; for reference, the final release of Google Prettify was in December of 2015, that predates Revision 52).
Having been interested in the recent syntax highlighting changes, and having discovered some issues with the highlighting lately myself, I decided to take a dive into the full, official list of languages Stack Exchange currently supports, found scattered around in SE's highlight-loader.js
file (referenced by the FAQ post). Using a little regex to find all the loaded languages and aliases1, I pulled together the (current) master list.
(For spatial brevity, I've enclosed it within a table in a snippet)
// Table-Making JS Code courtesy of Manish Mulani at https://stackoverflow.com/a/11480797/11047824
var myList=[{Language:"Default",Aliases:"[lang-default]"},{Language:"None",Aliases:"[lang-none]"},{Language:"Bash",Aliases:"[lang-bash], [lang-sh], [lang-zsh]"},{Language:"C-like",Aliases:"[lang-c-like], [lang-c], [lang-cc], [lang-h], [lang-c++], [lang-h++], [lang-hpp], [lang-hh], [lang-hxx], [lang-cxx]"},{Language:"C",Aliases:"[lang-c]"},{Language:"C++",Aliases:"[lang-cpp]"},{Language:"C#",Aliases:"[lang-csharp], [lang-cs], `lang-c#`"},{Language:"Clojure",Aliases:"[lang-clojure], [lang-clj]"},{Language:"CoffeeScript",Aliases:"[lang-coffeescript], [lang-coffee], [lang-cson], [lang-iced]"},{Language:"CSS",Aliases:"[lang-css]"},{Language:"Dart",Aliases:"[lang-dart]"},{Language:"Delphi",Aliases:"[lang-delphi], [lang-dpr], [lang-dfm], [lang-pas], [lang-pascal], [lang-freepascal], [lang-lazarus], [lang-lpr], [lang-lfm]"},{Language:"Erlang",Aliases:"[lang-erlang], [lang-erl]"},{Language:"Go",Aliases:"[lang-go], [lang-golang]"},{Language:"Haskell",Aliases:"[lang-haskell], [lang-hs]"},{Language:"Http",Aliases:"[lang-http], [lang-https]"},{Language:"Ini",Aliases:"[lang-ini], [lang-toml]"},{Language:"Java",Aliases:"[lang-java], [lang-jsp]"},{Language:"JavaScript",Aliases:"[lang-javascript], [lang-js], [lang-jsx], [lang-mjs], [lang-cjs]"},{Language:"JSON",Aliases:"[lang-json]"},{Language:"Kotlin",Aliases:"[lang-kotlin], [lang-kt]"},{Language:"LaTeX",Aliases:"[lang-latex], [lang-tex]"},{Language:"Less",Aliases:"[lang-less]"},{Language:"Lisp",Aliases:"[lang-lisp]"},{Language:"Lua",Aliases:"[lang-lua]"},{Language:"Makefile",Aliases:"[lang-makefile], [lang-mk], [lang-mak]"},{Language:"Markdown",Aliases:"[lang-markdown], [lang-md], [lang-mkdown], [lang-mkd]"},{Language:"MATLAB",Aliases:"[lang-matlab]"},{Language:"Objective-C",Aliases:"[lang-objectivec], [lang-mm], [lang-objc], [lang-obj-c]"},{Language:"OCaml",Aliases:"[lang-ocaml], [lang-ml]"},{Language:"Perl",Aliases:"[lang-perl], [lang-pl], [lang-pm]"},{Language:"PHP-Template",Aliases:"[lang-php-template]"},{Language:"PHP",Aliases:"[lang-php], [lang-php], [lang-php3], [lang-php4], [lang-php5], [lang-php6], [lang-php7]"},{Language:"Plaintext",Aliases:"[lang-plaintext], [lang-text], [lang-txt]"},{Language:"Protobuf",Aliases:"[lang-protobuf]"},{Language:"Python",Aliases:"[lang-python], [lang-py], [lang-gyp], [lang-ipython]"},{Language:"R",Aliases:"[lang-r]"},{Language:"Ruby",Aliases:"[lang-ruby], [lang-rb], [lang-gemspec], [lang-podspec], [lang-thor], [lang-irb]"},{Language:"Rust",Aliases:"[lang-rust], [lang-rs]"},{Language:"Scala",Aliases:"[lang-scala]"},{Language:"Scheme",Aliases:"[lang-scheme]"},{Language:"SCSS",Aliases:"[lang-scss]"},{Language:"Shell",Aliases:"[lang-shell], [lang-console]"},{Language:"SQL",Aliases:"[lang-sql]"},{Language:"Swift",Aliases:"[lang-swift]"},{Language:"TypeScript",Aliases:"[lang-typescript], [lang-ts]"},{Language:"VB.Net",Aliases:"[lang-vbnet], [lang-vb]"},{Language:"VHDL",Aliases:"[lang-vhdl]"},{Language:"XML",Aliases:"[lang-xml], [lang-html], [lang-xhtml], [lang-rss], [lang-atom], [lang-xjb], [lang-xsd], [lang-xsl], [lang-plist], [lang-wsf], [lang-svg]"},{Language:"YAML",Aliases:"[lang-yaml], [lang-yml], [lang-YAML]"}];function buildHtmlTable(a){for(var l=addAllColumnHeaders(myList,a),g=0;g<myList.length;g++){for(var n=$("<tr/>"),e=0;e<l.length;e++){var s=myList[g][l[e]];null==s&&(s=""),n.append($("<td/>").html(s))}$(a).append(n)}}function addAllColumnHeaders(a,l){for(var g=[],n=$("<tr/>"),e=0;e<a.length;e++){var s=a[e];for(var i in s)-1==$.inArray(i,g)&&(g.push(i),n.append($("<th/>").html(i)))}return $(l).append(n),g}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><body onLoad="buildHtmlTable('#excelDataTable')"><table id="excelDataTable" border="1"></table></body>
As I expected, I discovered a fair amount of discrepancies between the FAQ list and the master list. I went ahead and compiled the following list of those differences, cross-referencing with the highlight.js supported language list, and touching on each language or language group mentioned in the FAQ that either is missing an ID or has one or more extra IDs that are unrecognized by highlight.js. Apologies in advance for how long the following list is.
- Bash: Remove
lang-bsh
&lang-csh
, addlang-zsh
- C/ C-likes: Remove
lang-cyc
&lang-m
- C and C++: Caveats
- Currently, highlight.js does not internally distinguish between C, C-like, and C++ (reference)
- However, there are plenty of identifiers for both and more, some of which aren't currently in the FAQ
- Full list:
lang-c-like
,lang-c
,lang-cc
,lang-h
,lang-c++
,lang-h++
,lang-cpp
,lang-hpp
,lang-hh
,lang-hxx
,lang-cxx
- Full list:
- C#: Add
lang-c#
- CoffeeScript: Add
lang-cson
&lang-iced
- Go: Add
lang-golang
- Haskell: Add
lang-haskell
- Http2: Not currently included, add all:
lang-http
,lang-https
- HTML/ XML: Add
lang-xhtml
,lang-rss
,lang-atom
,lang-xjb
,lang-xsd
,lang-plist
,lang-wsf
,lang-svg
- Ini/ TOML: Not currently included, add all:
lang-ini
,lang-toml
- Java: Add
lang-jsp
- Officially JSP isn't exactly Java, but the highlighter supports the identifier
- Javascript: Add
lang-jsx
,lang-mjs
,lang-cjs
- Kotlin: Add
lang-kt
- Less: Not included, add all:
lang-less
- Lisp, Scheme: Remove all except
lang-lisp
, addlang-scheme
- Makefile: Not included, add all:
lang-makefile
,lang-mk
,lang-mak
- Markdown: Not included, but... is this one relevant?
- All:
lang-markdown
,lang-md
,lang-mkdown
,lang-mkd
- All:
- Objective-C: Add
lang-mm
,lang-objc
,lang-obj-c
- "OCaml, SML, F#, et al."
- OCaml: Add
lang-ocaml
- SML: Not included in SE's current load file
- Highlight.js supports SML, SE just didn't include it
- Special note: If SML is added,
lang-ml
shouldn't be used for OCaml, due to alias overlap
- Special note: If SML is added,
- Highlight.js supports SML, SE just didn't include it
- F#: Not included in SE's current load file
- Highlight.js supports F#, SE just didn't include it
- Until added, remove
lang-fs
- OCaml: Add
- Pascal, Delphi: Add
lang-delphi
,lang-dpr
,lang-dfm
,lang-pas
,lang-freepascal
,lang-lazarus
,lang-lpr
,lang-lfm
- Perl: Add
lang-pm
- PHP: Not included, add all:
lang-php
,lang-php3
,lang-php4
,lang-php5
,lang-php6
,lang-php7
- PHP-Template: Not included, add all:
lang-php-template
- Plaintext: Plain text support is also available, but it's practically equivalent to
lang-none
lang-plaintext
,lang-text
,lang-txt
- Protocol Buffers:
lang-proto
doesn't exist, it should belang-protobuf
- protocol-buffers's default language should be fixed to point to the real identifier
- Python: Add
lang-gyp
,lang-ipython
, Removelang-cv
- "R, S"
- S is unsupported by highlight.js, remove
lang-s
- S is unsupported by highlight.js, remove
- Regex: Unsupported, remove altogether
- Ruby: Add
lang-gemspec
,lang-podspec
,lang-thor
,lang-irb
- Rust: Remove
lang-rc
- SCSS: Not included, add all:
lang-scss
- Shell: Not included, add all:
lang-shell
,lang-console
- VHDL: Remove
lang-vhd
- "Visual Basic, VBScript":
- Visual Basic: hightlight.js only supports VB.Net, not sure whether that covers original VB or not
- IDs:
lang-vbnet
,lang-vb
- IDs:
- VBScript: Not included in SE's current load file
- Highlight.js supports VBScript, SE just didn't include it
- IDs:
lang-vbscript
,lang-vbs
- IDs:
- Until added, remove
lang-vbs
- Highlight.js supports VBScript, SE just didn't include it
- Visual Basic: hightlight.js only supports VB.Net, not sure whether that covers original VB or not
- YAML: Add
lang-yml
I'm aware that this is an... intense amount of content to drop in one post. I wanted to compile it all in one public place for reference, however, so that the list can eventually be brought up to par with the real list currently in use.
My apprehension to editing directly without posting is that any significant edits made to the FAQ language list would have likely been rolled back without a post to refer back to (the mod note below the post asks editors to link to a meta post to confirm changes).
I also hope that by putting this out in the open, some confusion might be cleared up regarding which tags are and aren't officially in use, and why some tags that are in the FAQ list aren't working as anticipated.
Bonus related note:
I also learned recently, courtesy of T.J.Crowder in his recent post, that using ```lang-X
to identify a code block is different than using ```X
, because X
alone refers to a tag, rather than a language. When you use X
above a code block, you're telling the renderer to look at the tag's default language highlighting setting to determine how it should highlight. Most of the time, this is perfect. But sometimes, it yields unexpected results, like with typescript
, which has lang-js
set as the tag default language.
1 - /hljs.registerLanguage\(('.*')|^\s+aliases: (\[.*\])/
2 - Apparently this is supposed be for "HTTP request and response headers with automatic body highlighting" (Link)