prism-show-language.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. (function () {
  2. if (typeof self === 'undefined' || !self.Prism || !self.document) {
  3. return;
  4. }
  5. if (!Prism.plugins.toolbar) {
  6. console.warn('Show Languages plugin loaded before Toolbar plugin.');
  7. return;
  8. }
  9. // The languages map is built automatically with gulp
  10. var Languages = /*languages_placeholder[*/{
  11. "none": "Plain text",
  12. "html": "HTML",
  13. "xml": "XML",
  14. "svg": "SVG",
  15. "mathml": "MathML",
  16. "ssml": "SSML",
  17. "rss": "RSS",
  18. "css": "CSS",
  19. "clike": "C-like",
  20. "js": "JavaScript",
  21. "abap": "ABAP",
  22. "abnf": "ABNF",
  23. "al": "AL",
  24. "antlr4": "ANTLR4",
  25. "g4": "ANTLR4",
  26. "apacheconf": "Apache Configuration",
  27. "apl": "APL",
  28. "aql": "AQL",
  29. "arff": "ARFF",
  30. "asciidoc": "AsciiDoc",
  31. "adoc": "AsciiDoc",
  32. "aspnet": "ASP.NET (C#)",
  33. "asm6502": "6502 Assembly",
  34. "autohotkey": "AutoHotkey",
  35. "autoit": "AutoIt",
  36. "basic": "BASIC",
  37. "bbcode": "BBcode",
  38. "bnf": "BNF",
  39. "rbnf": "RBNF",
  40. "bsl": "BSL (1C:Enterprise)",
  41. "oscript": "OneScript",
  42. "csharp": "C#",
  43. "cs": "C#",
  44. "dotnet": "C#",
  45. "cpp": "C++",
  46. "cil": "CIL",
  47. "cmake": "CMake",
  48. "coffee": "CoffeeScript",
  49. "conc": "Concurnas",
  50. "csp": "Content-Security-Policy",
  51. "css-extras": "CSS Extras",
  52. "dax": "DAX",
  53. "django": "Django/Jinja2",
  54. "jinja2": "Django/Jinja2",
  55. "dns-zone-file": "DNS zone file",
  56. "dns-zone": "DNS zone file",
  57. "dockerfile": "Docker",
  58. "ebnf": "EBNF",
  59. "editorconfig": "EditorConfig",
  60. "ejs": "EJS",
  61. "etlua": "Embedded Lua templating",
  62. "erb": "ERB",
  63. "excel-formula": "Excel Formula",
  64. "xlsx": "Excel Formula",
  65. "xls": "Excel Formula",
  66. "fsharp": "F#",
  67. "firestore-security-rules": "Firestore security rules",
  68. "ftl": "FreeMarker Template Language",
  69. "gml": "GameMaker Language",
  70. "gamemakerlanguage": "GameMaker Language",
  71. "gcode": "G-code",
  72. "gdscript": "GDScript",
  73. "gedcom": "GEDCOM",
  74. "glsl": "GLSL",
  75. "graphql": "GraphQL",
  76. "hs": "Haskell",
  77. "hcl": "HCL",
  78. "hlsl": "HLSL",
  79. "http": "HTTP",
  80. "hpkp": "HTTP Public-Key-Pins",
  81. "hsts": "HTTP Strict-Transport-Security",
  82. "ichigojam": "IchigoJam",
  83. "ignore": ".ignore",
  84. "gitignore": ".gitignore",
  85. "hgignore": ".hgignore",
  86. "npmignore": ".npmignore",
  87. "inform7": "Inform 7",
  88. "javadoc": "JavaDoc",
  89. "javadoclike": "JavaDoc-like",
  90. "javastacktrace": "Java stack trace",
  91. "jq": "JQ",
  92. "jsdoc": "JSDoc",
  93. "js-extras": "JS Extras",
  94. "json": "JSON",
  95. "webmanifest": "Web App Manifest",
  96. "json5": "JSON5",
  97. "jsonp": "JSONP",
  98. "jsstacktrace": "JS stack trace",
  99. "js-templates": "JS Templates",
  100. "kts": "Kotlin Script",
  101. "kt": "Kotlin",
  102. "latex": "LaTeX",
  103. "tex": "TeX",
  104. "context": "ConTeXt",
  105. "lilypond": "LilyPond",
  106. "ly": "LilyPond",
  107. "emacs": "Lisp",
  108. "elisp": "Lisp",
  109. "emacs-lisp": "Lisp",
  110. "llvm": "LLVM IR",
  111. "lolcode": "LOLCODE",
  112. "md": "Markdown",
  113. "markup-templating": "Markup templating",
  114. "matlab": "MATLAB",
  115. "mel": "MEL",
  116. "mongodb": "MongoDB",
  117. "moon": "MoonScript",
  118. "n1ql": "N1QL",
  119. "n4js": "N4JS",
  120. "n4jsd": "N4JS",
  121. "nand2tetris-hdl": "Nand To Tetris HDL",
  122. "naniscript": "Naninovel Script",
  123. "nani": "Naninovel Script",
  124. "nasm": "NASM",
  125. "neon": "NEON",
  126. "nginx": "nginx",
  127. "nsis": "NSIS",
  128. "objectivec": "Objective-C",
  129. "objc": "Objective-C",
  130. "ocaml": "OCaml",
  131. "opencl": "OpenCL",
  132. "parigp": "PARI/GP",
  133. "objectpascal": "Object Pascal",
  134. "pcaxis": "PC-Axis",
  135. "px": "PC-Axis",
  136. "peoplecode": "PeopleCode",
  137. "pcode": "PeopleCode",
  138. "php": "PHP",
  139. "phpdoc": "PHPDoc",
  140. "php-extras": "PHP Extras",
  141. "plsql": "PL/SQL",
  142. "powerquery": "PowerQuery",
  143. "pq": "PowerQuery",
  144. "mscript": "PowerQuery",
  145. "powershell": "PowerShell",
  146. "properties": ".properties",
  147. "protobuf": "Protocol Buffers",
  148. "purebasic": "PureBasic",
  149. "pbfasm": "PureBasic",
  150. "purs": "PureScript",
  151. "py": "Python",
  152. "q": "Q (kdb+ database)",
  153. "qml": "QML",
  154. "rkt": "Racket",
  155. "jsx": "React JSX",
  156. "tsx": "React TSX",
  157. "renpy": "Ren'py",
  158. "rpy": "Ren'py",
  159. "rest": "reST (reStructuredText)",
  160. "robotframework": "Robot Framework",
  161. "robot": "Robot Framework",
  162. "rb": "Ruby",
  163. "sas": "SAS",
  164. "sass": "Sass (Sass)",
  165. "scss": "Sass (Scss)",
  166. "shell-session": "Shell session",
  167. "sh-session": "Shell session",
  168. "shellsession": "Shell session",
  169. "sml": "SML",
  170. "smlnj": "SML/NJ",
  171. "solidity": "Solidity (Ethereum)",
  172. "sol": "Solidity (Ethereum)",
  173. "solution-file": "Solution file",
  174. "sln": "Solution file",
  175. "soy": "Soy (Closure Template)",
  176. "sparql": "SPARQL",
  177. "rq": "SPARQL",
  178. "splunk-spl": "Splunk SPL",
  179. "sqf": "SQF: Status Quo Function (Arma 3)",
  180. "sql": "SQL",
  181. "iecst": "Structured Text (IEC 61131-3)",
  182. "t4-templating": "T4 templating",
  183. "t4-cs": "T4 Text Templates (C#)",
  184. "t4": "T4 Text Templates (C#)",
  185. "t4-vb": "T4 Text Templates (VB)",
  186. "tap": "TAP",
  187. "tt2": "Template Toolkit 2",
  188. "toml": "TOML",
  189. "trig": "TriG",
  190. "ts": "TypeScript",
  191. "tsconfig": "TSConfig",
  192. "uscript": "UnrealScript",
  193. "uc": "UnrealScript",
  194. "vbnet": "VB.Net",
  195. "vhdl": "VHDL",
  196. "vim": "vim",
  197. "visual-basic": "Visual Basic",
  198. "vba": "VBA",
  199. "vb": "Visual Basic",
  200. "wasm": "WebAssembly",
  201. "wiki": "Wiki markup",
  202. "xeoracube": "XeoraCube",
  203. "xml-doc": "XML doc (.net)",
  204. "xojo": "Xojo (REALbasic)",
  205. "xquery": "XQuery",
  206. "yaml": "YAML",
  207. "yml": "YAML",
  208. "yang": "YANG"
  209. }/*]*/;
  210. Prism.plugins.toolbar.registerButton('show-language', function (env) {
  211. var pre = env.element.parentNode;
  212. if (!pre || !/pre/i.test(pre.nodeName)) {
  213. return;
  214. }
  215. /**
  216. * Tries to guess the name of a language given its id.
  217. *
  218. * @param {string} id The language id.
  219. * @returns {string}
  220. */
  221. function guessTitle(id) {
  222. if (!id) {
  223. return id;
  224. }
  225. return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
  226. }
  227. var language = pre.getAttribute('data-language') || Languages[env.language] || guessTitle(env.language);
  228. if (!language) {
  229. return;
  230. }
  231. var element = document.createElement('span');
  232. element.textContent = language;
  233. return element;
  234. });
  235. })();