UNPKG

5.1 kBJavaScriptView Raw
1(function () {
2
3 if (typeof self === 'undefined' || !self.Prism || !self.document) {
4 return;
5 }
6
7 if (!Prism.plugins.toolbar) {
8 console.warn('Show Languages plugin loaded before Toolbar plugin.');
9
10 return;
11 }
12
13 // The languages map is built automatically with gulp
14 var Languages = /*languages_placeholder[*/{
15 "html": "HTML",
16 "xml": "XML",
17 "svg": "SVG",
18 "mathml": "MathML",
19 "css": "CSS",
20 "clike": "C-like",
21 "js": "JavaScript",
22 "abap": "ABAP",
23 "abnf": "Augmented Backus–Naur form",
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 "asm6502": "6502 Assembly",
33 "aspnet": "ASP.NET (C#)",
34 "autohotkey": "AutoHotkey",
35 "autoit": "AutoIt",
36 "shell": "Bash",
37 "basic": "BASIC",
38 "bbcode": "BBcode",
39 "shortcode": "BBcode",
40 "bnf": "Backus–Naur form",
41 "rbnf": "Routing Backus–Naur form",
42 "conc": "Concurnas",
43 "csharp": "C#",
44 "cs": "C#",
45 "dotnet": "C#",
46 "cpp": "C++",
47 "cil": "CIL",
48 "coffee": "CoffeeScript",
49 "cmake": "CMake",
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": "Extended Backus–Naur form",
59 "ejs": "EJS",
60 "etlua": "Embedded Lua templating",
61 "erb": "ERB",
62 "excel-formula": "Excel Formula",
63 "xlsx": "Excel Formula",
64 "xls": "Excel Formula",
65 "fsharp": "F#",
66 "firestore-security-rules": "Firestore security rules",
67 "ftl": "FreeMarker Template Language",
68 "gcode": "G-code",
69 "gdscript": "GDScript",
70 "gedcom": "GEDCOM",
71 "glsl": "GLSL",
72 "gml": "GameMaker Language",
73 "gamemakerlanguage": "GameMaker Language",
74 "graphql": "GraphQL",
75 "hs": "Haskell",
76 "hcl": "HCL",
77 "http": "HTTP",
78 "hpkp": "HTTP Public-Key-Pins",
79 "hsts": "HTTP Strict-Transport-Security",
80 "ichigojam": "IchigoJam",
81 "inform7": "Inform 7",
82 "javadoc": "JavaDoc",
83 "javadoclike": "JavaDoc-like",
84 "javastacktrace": "Java stack trace",
85 "jq": "JQ",
86 "jsdoc": "JSDoc",
87 "js-extras": "JS Extras",
88 "js-templates": "JS Templates",
89 "json": "JSON",
90 "jsonp": "JSONP",
91 "json5": "JSON5",
92 "latex": "LaTeX",
93 "tex": "TeX",
94 "context": "ConTeXt",
95 "lilypond": "LilyPond",
96 "ly": "LilyPond",
97 "emacs": "Lisp",
98 "elisp": "Lisp",
99 "emacs-lisp": "Lisp",
100 "llvm": "LLVM IR",
101 "lolcode": "LOLCODE",
102 "md": "Markdown",
103 "markup-templating": "Markup templating",
104 "matlab": "MATLAB",
105 "mel": "MEL",
106 "moon": "MoonScript",
107 "n1ql": "N1QL",
108 "n4js": "N4JS",
109 "n4jsd": "N4JS",
110 "nand2tetris-hdl": "Nand To Tetris HDL",
111 "nasm": "NASM",
112 "neon": "NEON",
113 "nginx": "nginx",
114 "nsis": "NSIS",
115 "objectivec": "Objective-C",
116 "ocaml": "OCaml",
117 "opencl": "OpenCL",
118 "parigp": "PARI/GP",
119 "objectpascal": "Object Pascal",
120 "pcaxis": "PC-Axis",
121 "px": "PC-Axis",
122 "php": "PHP",
123 "phpdoc": "PHPDoc",
124 "php-extras": "PHP Extras",
125 "plsql": "PL/SQL",
126 "powerquery": "PowerQuery",
127 "pq": "PowerQuery",
128 "mscript": "PowerQuery",
129 "powershell": "PowerShell",
130 "properties": ".properties",
131 "protobuf": "Protocol Buffers",
132 "py": "Python",
133 "q": "Q (kdb+ database)",
134 "qml": "QML",
135 "jsx": "React JSX",
136 "tsx": "React TSX",
137 "renpy": "Ren'py",
138 "rest": "reST (reStructuredText)",
139 "robotframework": "Robot Framework",
140 "robot": "Robot Framework",
141 "rb": "Ruby",
142 "sas": "SAS",
143 "sass": "Sass (Sass)",
144 "scss": "Sass (Scss)",
145 "shell-session": "Shell session",
146 "solidity": "Solidity (Ethereum)",
147 "solution-file": "Solution file",
148 "sln": "Solution file",
149 "soy": "Soy (Closure Template)",
150 "sparql": "SPARQL",
151 "rq": "SPARQL",
152 "splunk-spl": "Splunk SPL",
153 "sqf": "SQF: Status Quo Function (Arma 3)",
154 "sql": "SQL",
155 "tap": "TAP",
156 "toml": "TOML",
157 "tt2": "Template Toolkit 2",
158 "trig": "TriG",
159 "ts": "TypeScript",
160 "t4-cs": "T4 Text Templates (C#)",
161 "t4": "T4 Text Templates (C#)",
162 "t4-vb": "T4 Text Templates (VB)",
163 "t4-templating": "T4 templating",
164 "vbnet": "VB.Net",
165 "vhdl": "VHDL",
166 "vim": "vim",
167 "visual-basic": "Visual Basic",
168 "vb": "Visual Basic",
169 "wasm": "WebAssembly",
170 "wiki": "Wiki markup",
171 "xeoracube": "XeoraCube",
172 "xojo": "Xojo (REALbasic)",
173 "xquery": "XQuery",
174 "yaml": "YAML",
175 "yml": "YAML"
176 }/*]*/;
177
178 Prism.plugins.toolbar.registerButton('show-language', function (env) {
179 var pre = env.element.parentNode;
180 if (!pre || !/pre/i.test(pre.nodeName)) {
181 return;
182 }
183
184 /**
185 * Tries to guess the name of a language given its id.
186 *
187 * @param {string} id The language id.
188 * @returns {string}
189 */
190 function guessTitle(id) {
191 if (!id) {
192 return id;
193 }
194 return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
195 }
196
197 var language = pre.getAttribute('data-language') || Languages[env.language] || guessTitle(env.language);
198
199 if (!language) {
200 return;
201 }
202 var element = document.createElement('span');
203 element.textContent = language;
204
205 return element;
206 });
207
208})();