UNPKG

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