Correspondance of codemirror modes, file extensions, and github flavored markdown code languages?

852 Views Asked by At

I'd like to embed local files as code snippets in a static website I'm making with jade, marked and codemirror for syntax highlighing. I will write a jade filter to do this.

What it boils down to is that I need to come up with the codemirror mode and github flavored markdown language (what you write when you do ```language) from the file extension.

At least some codemirror modes correspond to gfm languages. Do all of them coincide? Is there a list somewhere, or some rationale for the names?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

The mode/meta.js file in CodeMirror's distribution associates names with modes (via the CodeMirror.findModeByName function), and if you get CodeMirror version 4.8 (released yesterday), the gfm mode will use this list to try and use the right mode for fenced code blocks that declare a language.

0
On

This list from the Brackets matches file extension with cm mode. I've turned it into this:

{"groovy": "groovy",
"ini": "properties",
"properties": "properties",
"css": "css",
"scss": "css",
"html": "htmlmixed",
"htm": "htmlmixed",
"shtm": "htmlmixed",
"shtml": "htmlmixed",
"xhtml": "htmlmixed",
"cfm": "htmlmixed",
"cfml": "htmlmixed",
"cfc": "htmlmixed",
"dhtml": "htmlmixed",
"xht": "htmlmixed",
"tpl": "htmlmixed",
"twig": "htmlmixed",
"hbs": "htmlmixed",
"handlebars": "htmlmixed",
"kit": "htmlmixed",
"jsp": "htmlmixed",
"aspx": "htmlmixed",
"ascx": "htmlmixed",
"asp": "htmlmixed",
"master": "htmlmixed",
"cshtml": "htmlmixed",
"vbhtml": "htmlmixed",
"ejs": "htmlembedded",
"dust": "htmlembedded",
"erb": "htmlembedded",
"js": "javascript",
"jsx": "javascript",
"jsm": "javascript",
"_js": "javascript",
"vbs": "vbscript",
"vb": "vb",
"json": "javascript",
"xml": "xml",
"svg": "xml",
"wxs": "xml",
"wxl": "xml",
"wsdl": "xml",
"rss": "xml",
"atom": "xml",
"rdf": "xml",
"xslt": "xml",
"xsl": "xml",
"xul": "xml",
"xbl": "xml",
"mathml": "xml",
"config": "xml",
"plist": "xml",
"xaml": "xml",
"php": "php",
"php3": "php",
"php4": "php",
"php5": "php",
"phtm": "php",
"phtml": "php",
"ctp": "php",
"c": "clike",
"h": "clike",
"i": "clike",
"cc": "clike",
"cp": "clike",
"cpp": "clike",
"c++": "clike",
"cxx": "clike",
"hh": "clike",
"hpp": "clike",
"hxx": "clike",
"h++": "clike",
"ii": "clike",
"ino": "clike",
"cs": "clike",
"asax": "clike",
"ashx": "clike",
"java": "clike",
"scala": "clike",
"sbt": "clike",
"coffee": "coffeescript",
"cf": "coffeescript",
"cson": "coffeescript",
"_coffee": "coffeescript",
"clj": "clojure",
"cljs": "clojure",
"cljx": "clojure",
"pl": "perl",
"pm": "perl",
"rb": "ruby",
"ru": "ruby",
"gemspec": "ruby",
"rake": "ruby",
"py": "python",
"pyw": "python",
"wsgi": "python",
"sass": "sass",
"lua": "lua",
"sql": "sql",
"diff": "diff",
"patch": "diff",
"md": "markdown",
"markdown": "markdown",
"mdown": "markdown",
"mkdn": "markdown",
"yaml": "yaml",
"yml": "yaml",
"hx": "haxe",
"sh": "shell",
"command": "shell",
"bash": "shell"}