@hep-code-runner/vue2 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -162
- package/dist/index.mjs +2275 -475
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1,57 +1,1732 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var y = (o, e, t) => e in o ? w(o, e, { enumerable: true, configurable: true, writable: true, value: t }) : o[e] = t;
|
|
3
|
+
var c = (o, e, t) => y(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
let u = null;
|
|
5
|
+
class W {
|
|
6
|
+
constructor(e = {}) {
|
|
7
|
+
c(this, "baseUrl");
|
|
8
|
+
c(this, "timeout");
|
|
9
|
+
this.baseUrl = e.pistonUrl || "/api/piston", this.timeout = e.timeout || 3e3;
|
|
10
|
+
}
|
|
11
|
+
async getRuntimes(e = false) {
|
|
12
|
+
if (u && !e)
|
|
13
|
+
return u;
|
|
14
|
+
try {
|
|
15
|
+
const t = await fetch(`${this.baseUrl}/runtimes`, {
|
|
16
|
+
method: "GET",
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (!t.ok)
|
|
22
|
+
throw new Error(`Failed to fetch runtimes: ${t.statusText}`);
|
|
23
|
+
const n = await t.json();
|
|
24
|
+
return u = n, n;
|
|
25
|
+
} catch (t) {
|
|
26
|
+
throw console.error("Failed to fetch runtimes:", t), t;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async execute(e, t, n = {}) {
|
|
30
|
+
const l = (await this.getRuntimes()).find(
|
|
31
|
+
(a) => {
|
|
32
|
+
var r;
|
|
33
|
+
return a.language.toLowerCase() === e.toLowerCase() || ((r = a.aliases) == null ? void 0 : r.some((i) => i.toLowerCase() === e.toLowerCase()));
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
if (!l)
|
|
37
|
+
throw new Error(`Language '${e}' is not supported`);
|
|
38
|
+
const p = this.getFileName(e), h = {
|
|
39
|
+
language: l.language,
|
|
40
|
+
version: n.version || l.version,
|
|
41
|
+
files: [
|
|
42
|
+
{
|
|
43
|
+
name: p,
|
|
44
|
+
content: t
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
stdin: n.stdin || "",
|
|
48
|
+
args: n.args || [],
|
|
49
|
+
run_timeout: n.runTimeout || this.timeout,
|
|
50
|
+
compile_timeout: this.timeout
|
|
51
|
+
}, d = Date.now();
|
|
52
|
+
try {
|
|
53
|
+
const a = await fetch(`${this.baseUrl}/execute`, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json"
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify(h)
|
|
59
|
+
});
|
|
60
|
+
if (!a.ok)
|
|
61
|
+
throw new Error(`Execute failed: ${a.statusText}`);
|
|
62
|
+
const r = await a.json(), i = Date.now() - d, g = r.run.stdout || "", f = r.run.stderr || "";
|
|
63
|
+
return {
|
|
64
|
+
success: r.run.code === 0,
|
|
65
|
+
output: g,
|
|
66
|
+
stderr: f,
|
|
67
|
+
code: r.run.code,
|
|
68
|
+
executionTime: i,
|
|
69
|
+
compile: r.compile ? {
|
|
70
|
+
stdout: r.compile.stdout || "",
|
|
71
|
+
stderr: r.compile.stderr || "",
|
|
72
|
+
code: r.compile.code
|
|
73
|
+
} : void 0
|
|
74
|
+
};
|
|
75
|
+
} catch (a) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
output: "",
|
|
79
|
+
stderr: a instanceof Error ? a.message : "Unknown error",
|
|
80
|
+
code: -1,
|
|
81
|
+
executionTime: Date.now() - d
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getFileName(e) {
|
|
86
|
+
return {
|
|
87
|
+
javascript: "main.js",
|
|
88
|
+
typescript: "main.ts",
|
|
89
|
+
python: "main.py",
|
|
90
|
+
python3: "main.py",
|
|
91
|
+
go: "main.go",
|
|
92
|
+
rust: "main.rs",
|
|
93
|
+
java: "Main.java",
|
|
94
|
+
c: "main.c",
|
|
95
|
+
cpp: "main.cpp",
|
|
96
|
+
csharp: "Main.cs",
|
|
97
|
+
ruby: "main.rb",
|
|
98
|
+
php: "main.php",
|
|
99
|
+
bash: "main.sh",
|
|
100
|
+
shell: "main.sh",
|
|
101
|
+
perl: "main.pl",
|
|
102
|
+
lua: "main.lua",
|
|
103
|
+
swift: "main.swift",
|
|
104
|
+
kotlin: "Main.kt",
|
|
105
|
+
scala: "Main.scala",
|
|
106
|
+
haskell: "main.hs",
|
|
107
|
+
dart: "main.dart",
|
|
108
|
+
html: "index.html",
|
|
109
|
+
css: "style.css",
|
|
110
|
+
sql: "query.sql",
|
|
111
|
+
markdown: "readme.md"
|
|
112
|
+
}[e.toLowerCase()] || `main.${e}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const m = {
|
|
116
|
+
javascript: 'console.log("Hello, World!");',
|
|
117
|
+
typescript: 'console.log("Hello, World!");',
|
|
118
|
+
python: 'print("Hello, World!")',
|
|
119
|
+
python3: 'print("Hello, World!")',
|
|
120
|
+
go: `package main
|
|
121
|
+
|
|
122
|
+
import "fmt"
|
|
123
|
+
|
|
124
|
+
func main() {
|
|
125
|
+
fmt.Println("Hello, World!")
|
|
126
|
+
}`,
|
|
127
|
+
rust: `fn main() {
|
|
128
|
+
println!("Hello, World!");
|
|
129
|
+
}`,
|
|
130
|
+
java: `public class Main {
|
|
131
|
+
public static void main(String[] args) {
|
|
132
|
+
System.out.println("Hello, World!");
|
|
133
|
+
}
|
|
134
|
+
}`,
|
|
135
|
+
c: `#include <stdio.h>
|
|
136
|
+
|
|
137
|
+
int main() {
|
|
138
|
+
printf("Hello, World!\\n");
|
|
139
|
+
return 0;
|
|
140
|
+
}`,
|
|
141
|
+
cpp: `#include <iostream>
|
|
142
|
+
|
|
143
|
+
int main() {
|
|
144
|
+
std::cout << "Hello, World!" << std::endl;
|
|
145
|
+
return 0;
|
|
146
|
+
}`,
|
|
147
|
+
csharp: `using System;
|
|
148
|
+
|
|
149
|
+
class Main {
|
|
150
|
+
static void Main() {
|
|
151
|
+
Console.WriteLine("Hello, World!");
|
|
152
|
+
}
|
|
153
|
+
}`,
|
|
154
|
+
ruby: 'puts "Hello, World!"',
|
|
155
|
+
php: `<?php
|
|
156
|
+
echo "Hello, World!";
|
|
157
|
+
?>`,
|
|
158
|
+
bash: 'echo "Hello, World!"',
|
|
159
|
+
shell: 'echo "Hello, World!"',
|
|
160
|
+
perl: 'print "Hello, World!\\n";',
|
|
161
|
+
lua: 'print("Hello, World!")',
|
|
162
|
+
r: 'print("Hello, World!")',
|
|
163
|
+
swift: 'print("Hello, World!")',
|
|
164
|
+
kotlin: `fun main() {
|
|
165
|
+
println("Hello, World!")
|
|
166
|
+
}`,
|
|
167
|
+
scala: `object Main extends App {
|
|
168
|
+
println("Hello, World!")
|
|
169
|
+
}`,
|
|
170
|
+
haskell: 'main = putStrLn "Hello, World!"',
|
|
171
|
+
elixir: 'IO.puts "Hello, World!"',
|
|
172
|
+
erlang: 'main() -> io:fwrite("Hello, World!~n").',
|
|
173
|
+
clojure: '(println "Hello, World!")',
|
|
174
|
+
fsharp: 'printfn "Hello, World!"',
|
|
175
|
+
dart: `void main() {
|
|
176
|
+
print("Hello, World!");
|
|
177
|
+
}`,
|
|
178
|
+
assembly: `section .data
|
|
179
|
+
msg db 'Hello, World!', 0
|
|
180
|
+
section .text
|
|
181
|
+
global _start
|
|
182
|
+
_start:
|
|
183
|
+
mov rax, 1
|
|
184
|
+
mov rdi, 1
|
|
185
|
+
mov rsi, msg
|
|
186
|
+
mov rdx, 13
|
|
187
|
+
syscall
|
|
188
|
+
mov rax, 60
|
|
189
|
+
xor rdi, rdi
|
|
190
|
+
syscall`,
|
|
191
|
+
html: `<!DOCTYPE html>
|
|
192
|
+
<html>
|
|
193
|
+
<head>
|
|
194
|
+
<title>Hello</title>
|
|
195
|
+
</head>
|
|
196
|
+
<body>
|
|
197
|
+
<h1>Hello, World!</h1>
|
|
198
|
+
</body>
|
|
199
|
+
</html>`,
|
|
200
|
+
css: `body {
|
|
201
|
+
background-color: #f0f0f0;
|
|
202
|
+
font-family: Arial, sans-serif;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
h1 {
|
|
206
|
+
color: #333;
|
|
207
|
+
}`,
|
|
208
|
+
sql: "SELECT 'Hello, World!' AS message;",
|
|
209
|
+
markdown: `# Hello, World!
|
|
210
|
+
|
|
211
|
+
This is a sample markdown document.`
|
|
212
|
+
};
|
|
213
|
+
function j(o) {
|
|
214
|
+
const e = o.toLowerCase();
|
|
215
|
+
return m[e] || `// ${o}
|
|
216
|
+
// Write your code here`;
|
|
217
|
+
}
|
|
218
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
219
|
+
function getDefaultExportFromCjs(x) {
|
|
220
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
221
|
+
}
|
|
222
|
+
var prism = { exports: {} };
|
|
223
|
+
(function(module) {
|
|
224
|
+
var _self = typeof window !== "undefined" ? window : typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope ? self : {};
|
|
225
|
+
/**
|
|
226
|
+
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
227
|
+
*
|
|
228
|
+
* @license MIT <https://opensource.org/licenses/MIT>
|
|
229
|
+
* @author Lea Verou <https://lea.verou.me>
|
|
230
|
+
* @namespace
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
var Prism2 = function(_self2) {
|
|
234
|
+
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
|
235
|
+
var uniqueId = 0;
|
|
236
|
+
var plainTextGrammar = {};
|
|
237
|
+
var _ = {
|
|
238
|
+
/**
|
|
239
|
+
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
|
240
|
+
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
|
241
|
+
* additional languages or plugins yourself.
|
|
242
|
+
*
|
|
243
|
+
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
|
244
|
+
*
|
|
245
|
+
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
|
246
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
|
247
|
+
*
|
|
248
|
+
* ```js
|
|
249
|
+
* window.Prism = window.Prism || {};
|
|
250
|
+
* Prism.manual = true;
|
|
251
|
+
* // add a new <script> to load Prism's script
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @default false
|
|
255
|
+
* @type {boolean}
|
|
256
|
+
* @memberof Prism
|
|
257
|
+
* @public
|
|
258
|
+
*/
|
|
259
|
+
manual: _self2.Prism && _self2.Prism.manual,
|
|
260
|
+
/**
|
|
261
|
+
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
|
262
|
+
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
|
263
|
+
* own worker, you don't want it to do this.
|
|
264
|
+
*
|
|
265
|
+
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
|
266
|
+
*
|
|
267
|
+
* You obviously have to change this value before Prism executes. To do this, you can add an
|
|
268
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
|
269
|
+
*
|
|
270
|
+
* ```js
|
|
271
|
+
* window.Prism = window.Prism || {};
|
|
272
|
+
* Prism.disableWorkerMessageHandler = true;
|
|
273
|
+
* // Load Prism's script
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* @default false
|
|
277
|
+
* @type {boolean}
|
|
278
|
+
* @memberof Prism
|
|
279
|
+
* @public
|
|
280
|
+
*/
|
|
281
|
+
disableWorkerMessageHandler: _self2.Prism && _self2.Prism.disableWorkerMessageHandler,
|
|
282
|
+
/**
|
|
283
|
+
* A namespace for utility methods.
|
|
284
|
+
*
|
|
285
|
+
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
286
|
+
* change or disappear at any time.
|
|
287
|
+
*
|
|
288
|
+
* @namespace
|
|
289
|
+
* @memberof Prism
|
|
290
|
+
*/
|
|
291
|
+
util: {
|
|
292
|
+
encode: function encode(tokens) {
|
|
293
|
+
if (tokens instanceof Token) {
|
|
294
|
+
return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
|
295
|
+
} else if (Array.isArray(tokens)) {
|
|
296
|
+
return tokens.map(encode);
|
|
297
|
+
} else {
|
|
298
|
+
return tokens.replace(/&/g, "&").replace(/</g, "<").replace(/\u00a0/g, " ");
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
/**
|
|
302
|
+
* Returns the name of the type of the given value.
|
|
303
|
+
*
|
|
304
|
+
* @param {any} o
|
|
305
|
+
* @returns {string}
|
|
306
|
+
* @example
|
|
307
|
+
* type(null) === 'Null'
|
|
308
|
+
* type(undefined) === 'Undefined'
|
|
309
|
+
* type(123) === 'Number'
|
|
310
|
+
* type('foo') === 'String'
|
|
311
|
+
* type(true) === 'Boolean'
|
|
312
|
+
* type([1, 2]) === 'Array'
|
|
313
|
+
* type({}) === 'Object'
|
|
314
|
+
* type(String) === 'Function'
|
|
315
|
+
* type(/abc+/) === 'RegExp'
|
|
316
|
+
*/
|
|
317
|
+
type: function(o) {
|
|
318
|
+
return Object.prototype.toString.call(o).slice(8, -1);
|
|
319
|
+
},
|
|
320
|
+
/**
|
|
321
|
+
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
322
|
+
*
|
|
323
|
+
* @param {Object} obj
|
|
324
|
+
* @returns {number}
|
|
325
|
+
*/
|
|
326
|
+
objId: function(obj) {
|
|
327
|
+
if (!obj["__id"]) {
|
|
328
|
+
Object.defineProperty(obj, "__id", { value: ++uniqueId });
|
|
329
|
+
}
|
|
330
|
+
return obj["__id"];
|
|
331
|
+
},
|
|
332
|
+
/**
|
|
333
|
+
* Creates a deep clone of the given object.
|
|
334
|
+
*
|
|
335
|
+
* The main intended use of this function is to clone language definitions.
|
|
336
|
+
*
|
|
337
|
+
* @param {T} o
|
|
338
|
+
* @param {Record<number, any>} [visited]
|
|
339
|
+
* @returns {T}
|
|
340
|
+
* @template T
|
|
341
|
+
*/
|
|
342
|
+
clone: function deepClone(o, visited) {
|
|
343
|
+
visited = visited || {};
|
|
344
|
+
var clone;
|
|
345
|
+
var id;
|
|
346
|
+
switch (_.util.type(o)) {
|
|
347
|
+
case "Object":
|
|
348
|
+
id = _.util.objId(o);
|
|
349
|
+
if (visited[id]) {
|
|
350
|
+
return visited[id];
|
|
351
|
+
}
|
|
352
|
+
clone = /** @type {Record<string, any>} */
|
|
353
|
+
{};
|
|
354
|
+
visited[id] = clone;
|
|
355
|
+
for (var key in o) {
|
|
356
|
+
if (o.hasOwnProperty(key)) {
|
|
357
|
+
clone[key] = deepClone(o[key], visited);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return (
|
|
361
|
+
/** @type {any} */
|
|
362
|
+
clone
|
|
363
|
+
);
|
|
364
|
+
case "Array":
|
|
365
|
+
id = _.util.objId(o);
|
|
366
|
+
if (visited[id]) {
|
|
367
|
+
return visited[id];
|
|
368
|
+
}
|
|
369
|
+
clone = [];
|
|
370
|
+
visited[id] = clone;
|
|
371
|
+
/** @type {Array} */
|
|
372
|
+
/** @type {any} */
|
|
373
|
+
o.forEach(function(v, i) {
|
|
374
|
+
clone[i] = deepClone(v, visited);
|
|
375
|
+
});
|
|
376
|
+
return (
|
|
377
|
+
/** @type {any} */
|
|
378
|
+
clone
|
|
379
|
+
);
|
|
380
|
+
default:
|
|
381
|
+
return o;
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
/**
|
|
385
|
+
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
|
386
|
+
*
|
|
387
|
+
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
|
388
|
+
*
|
|
389
|
+
* @param {Element} element
|
|
390
|
+
* @returns {string}
|
|
391
|
+
*/
|
|
392
|
+
getLanguage: function(element) {
|
|
393
|
+
while (element) {
|
|
394
|
+
var m2 = lang.exec(element.className);
|
|
395
|
+
if (m2) {
|
|
396
|
+
return m2[1].toLowerCase();
|
|
397
|
+
}
|
|
398
|
+
element = element.parentElement;
|
|
399
|
+
}
|
|
400
|
+
return "none";
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* Sets the Prism `language-xxxx` class of the given element.
|
|
404
|
+
*
|
|
405
|
+
* @param {Element} element
|
|
406
|
+
* @param {string} language
|
|
407
|
+
* @returns {void}
|
|
408
|
+
*/
|
|
409
|
+
setLanguage: function(element, language) {
|
|
410
|
+
element.className = element.className.replace(RegExp(lang, "gi"), "");
|
|
411
|
+
element.classList.add("language-" + language);
|
|
412
|
+
},
|
|
413
|
+
/**
|
|
414
|
+
* Returns the script element that is currently executing.
|
|
415
|
+
*
|
|
416
|
+
* This does __not__ work for line script element.
|
|
417
|
+
*
|
|
418
|
+
* @returns {HTMLScriptElement | null}
|
|
419
|
+
*/
|
|
420
|
+
currentScript: function() {
|
|
421
|
+
if (typeof document === "undefined") {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
if (document.currentScript && document.currentScript.tagName === "SCRIPT" && 1 < 2) {
|
|
425
|
+
return (
|
|
426
|
+
/** @type {any} */
|
|
427
|
+
document.currentScript
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
throw new Error();
|
|
432
|
+
} catch (err) {
|
|
433
|
+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
|
434
|
+
if (src) {
|
|
435
|
+
var scripts = document.getElementsByTagName("script");
|
|
436
|
+
for (var i in scripts) {
|
|
437
|
+
if (scripts[i].src == src) {
|
|
438
|
+
return scripts[i];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return null;
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
/**
|
|
446
|
+
* Returns whether a given class is active for `element`.
|
|
447
|
+
*
|
|
448
|
+
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
|
449
|
+
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
|
450
|
+
* given class is just the given class with a `no-` prefix.
|
|
451
|
+
*
|
|
452
|
+
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
|
453
|
+
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
|
454
|
+
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
|
455
|
+
*
|
|
456
|
+
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
|
457
|
+
* version of it, the class is considered active.
|
|
458
|
+
*
|
|
459
|
+
* @param {Element} element
|
|
460
|
+
* @param {string} className
|
|
461
|
+
* @param {boolean} [defaultActivation=false]
|
|
462
|
+
* @returns {boolean}
|
|
463
|
+
*/
|
|
464
|
+
isActive: function(element, className, defaultActivation) {
|
|
465
|
+
var no = "no-" + className;
|
|
466
|
+
while (element) {
|
|
467
|
+
var classList = element.classList;
|
|
468
|
+
if (classList.contains(className)) {
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
if (classList.contains(no)) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
element = element.parentElement;
|
|
475
|
+
}
|
|
476
|
+
return !!defaultActivation;
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
/**
|
|
480
|
+
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
481
|
+
*
|
|
482
|
+
* @namespace
|
|
483
|
+
* @memberof Prism
|
|
484
|
+
* @public
|
|
485
|
+
*/
|
|
486
|
+
languages: {
|
|
487
|
+
/**
|
|
488
|
+
* The grammar for plain, unformatted text.
|
|
489
|
+
*/
|
|
490
|
+
plain: plainTextGrammar,
|
|
491
|
+
plaintext: plainTextGrammar,
|
|
492
|
+
text: plainTextGrammar,
|
|
493
|
+
txt: plainTextGrammar,
|
|
494
|
+
/**
|
|
495
|
+
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
496
|
+
*
|
|
497
|
+
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
498
|
+
* will be overwritten at its original position.
|
|
499
|
+
*
|
|
500
|
+
* ## Best practices
|
|
501
|
+
*
|
|
502
|
+
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
503
|
+
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
504
|
+
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
505
|
+
*
|
|
506
|
+
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
507
|
+
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
508
|
+
*
|
|
509
|
+
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
510
|
+
* @param {Grammar} redef The new tokens to append.
|
|
511
|
+
* @returns {Grammar} The new language created.
|
|
512
|
+
* @public
|
|
513
|
+
* @example
|
|
514
|
+
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
515
|
+
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
516
|
+
* // at its original position
|
|
517
|
+
* 'comment': { ... },
|
|
518
|
+
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
519
|
+
* 'color': /\b(?:red|green|blue)\b/
|
|
520
|
+
* });
|
|
521
|
+
*/
|
|
522
|
+
extend: function(id, redef) {
|
|
523
|
+
var lang2 = _.util.clone(_.languages[id]);
|
|
524
|
+
for (var key in redef) {
|
|
525
|
+
lang2[key] = redef[key];
|
|
526
|
+
}
|
|
527
|
+
return lang2;
|
|
528
|
+
},
|
|
529
|
+
/**
|
|
530
|
+
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
531
|
+
*
|
|
532
|
+
* ## Usage
|
|
533
|
+
*
|
|
534
|
+
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
535
|
+
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
536
|
+
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
537
|
+
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
538
|
+
* this:
|
|
539
|
+
*
|
|
540
|
+
* ```js
|
|
541
|
+
* Prism.languages.markup.style = {
|
|
542
|
+
* // token
|
|
543
|
+
* };
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
546
|
+
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
547
|
+
* before existing tokens. For the CSS example above, you would use it like this:
|
|
548
|
+
*
|
|
549
|
+
* ```js
|
|
550
|
+
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
551
|
+
* 'style': {
|
|
552
|
+
* // token
|
|
553
|
+
* }
|
|
554
|
+
* });
|
|
555
|
+
* ```
|
|
556
|
+
*
|
|
557
|
+
* ## Special cases
|
|
558
|
+
*
|
|
559
|
+
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
560
|
+
* will be ignored.
|
|
561
|
+
*
|
|
562
|
+
* This behavior can be used to insert tokens after `before`:
|
|
563
|
+
*
|
|
564
|
+
* ```js
|
|
565
|
+
* Prism.languages.insertBefore('markup', 'comment', {
|
|
566
|
+
* 'comment': Prism.languages.markup.comment,
|
|
567
|
+
* // tokens after 'comment'
|
|
568
|
+
* });
|
|
569
|
+
* ```
|
|
570
|
+
*
|
|
571
|
+
* ## Limitations
|
|
572
|
+
*
|
|
573
|
+
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
574
|
+
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
575
|
+
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
576
|
+
* deleting properties which is necessary to insert at arbitrary positions.
|
|
577
|
+
*
|
|
578
|
+
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
579
|
+
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
580
|
+
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
581
|
+
*
|
|
582
|
+
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
583
|
+
* you hold the target object in a variable, then the value of the variable will not change.
|
|
584
|
+
*
|
|
585
|
+
* ```js
|
|
586
|
+
* var oldMarkup = Prism.languages.markup;
|
|
587
|
+
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
588
|
+
*
|
|
589
|
+
* assert(oldMarkup !== Prism.languages.markup);
|
|
590
|
+
* assert(newMarkup === Prism.languages.markup);
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
594
|
+
* object to be modified.
|
|
595
|
+
* @param {string} before The key to insert before.
|
|
596
|
+
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
597
|
+
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
598
|
+
* object to be modified.
|
|
599
|
+
*
|
|
600
|
+
* Defaults to `Prism.languages`.
|
|
601
|
+
* @returns {Grammar} The new grammar object.
|
|
602
|
+
* @public
|
|
603
|
+
*/
|
|
604
|
+
insertBefore: function(inside, before, insert, root) {
|
|
605
|
+
root = root || /** @type {any} */
|
|
606
|
+
_.languages;
|
|
607
|
+
var grammar = root[inside];
|
|
608
|
+
var ret = {};
|
|
609
|
+
for (var token in grammar) {
|
|
610
|
+
if (grammar.hasOwnProperty(token)) {
|
|
611
|
+
if (token == before) {
|
|
612
|
+
for (var newToken in insert) {
|
|
613
|
+
if (insert.hasOwnProperty(newToken)) {
|
|
614
|
+
ret[newToken] = insert[newToken];
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (!insert.hasOwnProperty(token)) {
|
|
619
|
+
ret[token] = grammar[token];
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
var old = root[inside];
|
|
624
|
+
root[inside] = ret;
|
|
625
|
+
_.languages.DFS(_.languages, function(key, value) {
|
|
626
|
+
if (value === old && key != inside) {
|
|
627
|
+
this[key] = ret;
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
return ret;
|
|
631
|
+
},
|
|
632
|
+
// Traverse a language definition with Depth First Search
|
|
633
|
+
DFS: function DFS(o, callback, type, visited) {
|
|
634
|
+
visited = visited || {};
|
|
635
|
+
var objId = _.util.objId;
|
|
636
|
+
for (var i in o) {
|
|
637
|
+
if (o.hasOwnProperty(i)) {
|
|
638
|
+
callback.call(o, i, o[i], type || i);
|
|
639
|
+
var property = o[i];
|
|
640
|
+
var propertyType = _.util.type(property);
|
|
641
|
+
if (propertyType === "Object" && !visited[objId(property)]) {
|
|
642
|
+
visited[objId(property)] = true;
|
|
643
|
+
DFS(property, callback, null, visited);
|
|
644
|
+
} else if (propertyType === "Array" && !visited[objId(property)]) {
|
|
645
|
+
visited[objId(property)] = true;
|
|
646
|
+
DFS(property, callback, i, visited);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
plugins: {},
|
|
653
|
+
/**
|
|
654
|
+
* This is the most high-level function in Prism’s API.
|
|
655
|
+
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
|
656
|
+
* each one of them.
|
|
657
|
+
*
|
|
658
|
+
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
|
659
|
+
*
|
|
660
|
+
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
|
661
|
+
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
|
662
|
+
* @memberof Prism
|
|
663
|
+
* @public
|
|
664
|
+
*/
|
|
665
|
+
highlightAll: function(async, callback) {
|
|
666
|
+
_.highlightAllUnder(document, async, callback);
|
|
667
|
+
},
|
|
668
|
+
/**
|
|
669
|
+
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
|
670
|
+
* {@link Prism.highlightElement} on each one of them.
|
|
671
|
+
*
|
|
672
|
+
* The following hooks will be run:
|
|
673
|
+
* 1. `before-highlightall`
|
|
674
|
+
* 2. `before-all-elements-highlight`
|
|
675
|
+
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
|
676
|
+
*
|
|
677
|
+
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
|
678
|
+
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
|
679
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
|
680
|
+
* @memberof Prism
|
|
681
|
+
* @public
|
|
682
|
+
*/
|
|
683
|
+
highlightAllUnder: function(container, async, callback) {
|
|
684
|
+
var env = {
|
|
685
|
+
callback,
|
|
686
|
+
container,
|
|
687
|
+
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
|
688
|
+
};
|
|
689
|
+
_.hooks.run("before-highlightall", env);
|
|
690
|
+
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
|
691
|
+
_.hooks.run("before-all-elements-highlight", env);
|
|
692
|
+
for (var i = 0, element; element = env.elements[i++]; ) {
|
|
693
|
+
_.highlightElement(element, async === true, env.callback);
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
/**
|
|
697
|
+
* Highlights the code inside a single element.
|
|
698
|
+
*
|
|
699
|
+
* The following hooks will be run:
|
|
700
|
+
* 1. `before-sanity-check`
|
|
701
|
+
* 2. `before-highlight`
|
|
702
|
+
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
|
703
|
+
* 4. `before-insert`
|
|
704
|
+
* 5. `after-highlight`
|
|
705
|
+
* 6. `complete`
|
|
706
|
+
*
|
|
707
|
+
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
|
708
|
+
* the element's language.
|
|
709
|
+
*
|
|
710
|
+
* @param {Element} element The element containing the code.
|
|
711
|
+
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
|
712
|
+
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
|
713
|
+
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
|
714
|
+
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
|
715
|
+
*
|
|
716
|
+
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
|
717
|
+
* asynchronous highlighting to work. You can build your own bundle on the
|
|
718
|
+
* [Download page](https://prismjs.com/download.html).
|
|
719
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
|
720
|
+
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
|
721
|
+
* @memberof Prism
|
|
722
|
+
* @public
|
|
723
|
+
*/
|
|
724
|
+
highlightElement: function(element, async, callback) {
|
|
725
|
+
var language = _.util.getLanguage(element);
|
|
726
|
+
var grammar = _.languages[language];
|
|
727
|
+
_.util.setLanguage(element, language);
|
|
728
|
+
var parent = element.parentElement;
|
|
729
|
+
if (parent && parent.nodeName.toLowerCase() === "pre") {
|
|
730
|
+
_.util.setLanguage(parent, language);
|
|
731
|
+
}
|
|
732
|
+
var code = element.textContent;
|
|
733
|
+
var env = {
|
|
734
|
+
element,
|
|
735
|
+
language,
|
|
736
|
+
grammar,
|
|
737
|
+
code
|
|
738
|
+
};
|
|
739
|
+
function insertHighlightedCode(highlightedCode) {
|
|
740
|
+
env.highlightedCode = highlightedCode;
|
|
741
|
+
_.hooks.run("before-insert", env);
|
|
742
|
+
env.element.innerHTML = env.highlightedCode;
|
|
743
|
+
_.hooks.run("after-highlight", env);
|
|
744
|
+
_.hooks.run("complete", env);
|
|
745
|
+
callback && callback.call(env.element);
|
|
746
|
+
}
|
|
747
|
+
_.hooks.run("before-sanity-check", env);
|
|
748
|
+
parent = env.element.parentElement;
|
|
749
|
+
if (parent && parent.nodeName.toLowerCase() === "pre" && !parent.hasAttribute("tabindex")) {
|
|
750
|
+
parent.setAttribute("tabindex", "0");
|
|
751
|
+
}
|
|
752
|
+
if (!env.code) {
|
|
753
|
+
_.hooks.run("complete", env);
|
|
754
|
+
callback && callback.call(env.element);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
_.hooks.run("before-highlight", env);
|
|
758
|
+
if (!env.grammar) {
|
|
759
|
+
insertHighlightedCode(_.util.encode(env.code));
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
if (async && _self2.Worker) {
|
|
763
|
+
var worker = new Worker(_.filename);
|
|
764
|
+
worker.onmessage = function(evt) {
|
|
765
|
+
insertHighlightedCode(evt.data);
|
|
766
|
+
};
|
|
767
|
+
worker.postMessage(JSON.stringify({
|
|
768
|
+
language: env.language,
|
|
769
|
+
code: env.code,
|
|
770
|
+
immediateClose: true
|
|
771
|
+
}));
|
|
772
|
+
} else {
|
|
773
|
+
insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
/**
|
|
777
|
+
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
778
|
+
* and the language definitions to use, and returns a string with the HTML produced.
|
|
779
|
+
*
|
|
780
|
+
* The following hooks will be run:
|
|
781
|
+
* 1. `before-tokenize`
|
|
782
|
+
* 2. `after-tokenize`
|
|
783
|
+
* 3. `wrap`: On each {@link Token}.
|
|
784
|
+
*
|
|
785
|
+
* @param {string} text A string with the code to be highlighted.
|
|
786
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
787
|
+
*
|
|
788
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
789
|
+
* @param {string} language The name of the language definition passed to `grammar`.
|
|
790
|
+
* @returns {string} The highlighted HTML.
|
|
791
|
+
* @memberof Prism
|
|
792
|
+
* @public
|
|
793
|
+
* @example
|
|
794
|
+
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
795
|
+
*/
|
|
796
|
+
highlight: function(text, grammar, language) {
|
|
797
|
+
var env = {
|
|
798
|
+
code: text,
|
|
799
|
+
grammar,
|
|
800
|
+
language
|
|
801
|
+
};
|
|
802
|
+
_.hooks.run("before-tokenize", env);
|
|
803
|
+
if (!env.grammar) {
|
|
804
|
+
throw new Error('The language "' + env.language + '" has no grammar.');
|
|
805
|
+
}
|
|
806
|
+
env.tokens = _.tokenize(env.code, env.grammar);
|
|
807
|
+
_.hooks.run("after-tokenize", env);
|
|
808
|
+
return Token.stringify(_.util.encode(env.tokens), env.language);
|
|
809
|
+
},
|
|
810
|
+
/**
|
|
811
|
+
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
812
|
+
* and the language definitions to use, and returns an array with the tokenized code.
|
|
813
|
+
*
|
|
814
|
+
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
815
|
+
*
|
|
816
|
+
* This method could be useful in other contexts as well, as a very crude parser.
|
|
817
|
+
*
|
|
818
|
+
* @param {string} text A string with the code to be highlighted.
|
|
819
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
820
|
+
*
|
|
821
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
822
|
+
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
823
|
+
* @memberof Prism
|
|
824
|
+
* @public
|
|
825
|
+
* @example
|
|
826
|
+
* let code = `var foo = 0;`;
|
|
827
|
+
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
828
|
+
* tokens.forEach(token => {
|
|
829
|
+
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
830
|
+
* console.log(`Found numeric literal: ${token.content}`);
|
|
831
|
+
* }
|
|
832
|
+
* });
|
|
833
|
+
*/
|
|
834
|
+
tokenize: function(text, grammar) {
|
|
835
|
+
var rest = grammar.rest;
|
|
836
|
+
if (rest) {
|
|
837
|
+
for (var token in rest) {
|
|
838
|
+
grammar[token] = rest[token];
|
|
839
|
+
}
|
|
840
|
+
delete grammar.rest;
|
|
841
|
+
}
|
|
842
|
+
var tokenList = new LinkedList();
|
|
843
|
+
addAfter(tokenList, tokenList.head, text);
|
|
844
|
+
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
|
845
|
+
return toArray(tokenList);
|
|
846
|
+
},
|
|
847
|
+
/**
|
|
848
|
+
* @namespace
|
|
849
|
+
* @memberof Prism
|
|
850
|
+
* @public
|
|
851
|
+
*/
|
|
852
|
+
hooks: {
|
|
853
|
+
all: {},
|
|
854
|
+
/**
|
|
855
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
856
|
+
*
|
|
857
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
858
|
+
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
859
|
+
*
|
|
860
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
861
|
+
*
|
|
862
|
+
* @param {string} name The name of the hook.
|
|
863
|
+
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
864
|
+
* @public
|
|
865
|
+
*/
|
|
866
|
+
add: function(name, callback) {
|
|
867
|
+
var hooks = _.hooks.all;
|
|
868
|
+
hooks[name] = hooks[name] || [];
|
|
869
|
+
hooks[name].push(callback);
|
|
870
|
+
},
|
|
871
|
+
/**
|
|
872
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
873
|
+
*
|
|
874
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
875
|
+
*
|
|
876
|
+
* @param {string} name The name of the hook.
|
|
877
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
878
|
+
* @public
|
|
879
|
+
*/
|
|
880
|
+
run: function(name, env) {
|
|
881
|
+
var callbacks = _.hooks.all[name];
|
|
882
|
+
if (!callbacks || !callbacks.length) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
for (var i = 0, callback; callback = callbacks[i++]; ) {
|
|
886
|
+
callback(env);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
},
|
|
890
|
+
Token
|
|
891
|
+
};
|
|
892
|
+
_self2.Prism = _;
|
|
893
|
+
function Token(type, content, alias, matchedStr) {
|
|
894
|
+
this.type = type;
|
|
895
|
+
this.content = content;
|
|
896
|
+
this.alias = alias;
|
|
897
|
+
this.length = (matchedStr || "").length | 0;
|
|
898
|
+
}
|
|
899
|
+
Token.stringify = function stringify(o, language) {
|
|
900
|
+
if (typeof o == "string") {
|
|
901
|
+
return o;
|
|
902
|
+
}
|
|
903
|
+
if (Array.isArray(o)) {
|
|
904
|
+
var s = "";
|
|
905
|
+
o.forEach(function(e) {
|
|
906
|
+
s += stringify(e, language);
|
|
907
|
+
});
|
|
908
|
+
return s;
|
|
909
|
+
}
|
|
910
|
+
var env = {
|
|
911
|
+
type: o.type,
|
|
912
|
+
content: stringify(o.content, language),
|
|
913
|
+
tag: "span",
|
|
914
|
+
classes: ["token", o.type],
|
|
915
|
+
attributes: {},
|
|
916
|
+
language
|
|
917
|
+
};
|
|
918
|
+
var aliases = o.alias;
|
|
919
|
+
if (aliases) {
|
|
920
|
+
if (Array.isArray(aliases)) {
|
|
921
|
+
Array.prototype.push.apply(env.classes, aliases);
|
|
922
|
+
} else {
|
|
923
|
+
env.classes.push(aliases);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
_.hooks.run("wrap", env);
|
|
927
|
+
var attributes = "";
|
|
928
|
+
for (var name in env.attributes) {
|
|
929
|
+
attributes += " " + name + '="' + (env.attributes[name] || "").replace(/"/g, """) + '"';
|
|
930
|
+
}
|
|
931
|
+
return "<" + env.tag + ' class="' + env.classes.join(" ") + '"' + attributes + ">" + env.content + "</" + env.tag + ">";
|
|
932
|
+
};
|
|
933
|
+
function matchPattern(pattern, pos, text, lookbehind) {
|
|
934
|
+
pattern.lastIndex = pos;
|
|
935
|
+
var match = pattern.exec(text);
|
|
936
|
+
if (match && lookbehind && match[1]) {
|
|
937
|
+
var lookbehindLength = match[1].length;
|
|
938
|
+
match.index += lookbehindLength;
|
|
939
|
+
match[0] = match[0].slice(lookbehindLength);
|
|
940
|
+
}
|
|
941
|
+
return match;
|
|
942
|
+
}
|
|
943
|
+
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
944
|
+
for (var token in grammar) {
|
|
945
|
+
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
var patterns = grammar[token];
|
|
949
|
+
patterns = Array.isArray(patterns) ? patterns : [patterns];
|
|
950
|
+
for (var j2 = 0; j2 < patterns.length; ++j2) {
|
|
951
|
+
if (rematch && rematch.cause == token + "," + j2) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
var patternObj = patterns[j2];
|
|
955
|
+
var inside = patternObj.inside;
|
|
956
|
+
var lookbehind = !!patternObj.lookbehind;
|
|
957
|
+
var greedy = !!patternObj.greedy;
|
|
958
|
+
var alias = patternObj.alias;
|
|
959
|
+
if (greedy && !patternObj.pattern.global) {
|
|
960
|
+
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
|
961
|
+
patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g");
|
|
962
|
+
}
|
|
963
|
+
var pattern = patternObj.pattern || patternObj;
|
|
964
|
+
for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) {
|
|
965
|
+
if (rematch && pos >= rematch.reach) {
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
var str = currentNode.value;
|
|
969
|
+
if (tokenList.length > text.length) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (str instanceof Token) {
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
var removeCount = 1;
|
|
976
|
+
var match;
|
|
977
|
+
if (greedy) {
|
|
978
|
+
match = matchPattern(pattern, pos, text, lookbehind);
|
|
979
|
+
if (!match || match.index >= text.length) {
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
var from = match.index;
|
|
983
|
+
var to = match.index + match[0].length;
|
|
984
|
+
var p = pos;
|
|
985
|
+
p += currentNode.value.length;
|
|
986
|
+
while (from >= p) {
|
|
987
|
+
currentNode = currentNode.next;
|
|
988
|
+
p += currentNode.value.length;
|
|
989
|
+
}
|
|
990
|
+
p -= currentNode.value.length;
|
|
991
|
+
pos = p;
|
|
992
|
+
if (currentNode.value instanceof Token) {
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === "string"); k = k.next) {
|
|
996
|
+
removeCount++;
|
|
997
|
+
p += k.value.length;
|
|
998
|
+
}
|
|
999
|
+
removeCount--;
|
|
1000
|
+
str = text.slice(pos, p);
|
|
1001
|
+
match.index -= pos;
|
|
1002
|
+
} else {
|
|
1003
|
+
match = matchPattern(pattern, 0, str, lookbehind);
|
|
1004
|
+
if (!match) {
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
var from = match.index;
|
|
1009
|
+
var matchStr = match[0];
|
|
1010
|
+
var before = str.slice(0, from);
|
|
1011
|
+
var after = str.slice(from + matchStr.length);
|
|
1012
|
+
var reach = pos + str.length;
|
|
1013
|
+
if (rematch && reach > rematch.reach) {
|
|
1014
|
+
rematch.reach = reach;
|
|
1015
|
+
}
|
|
1016
|
+
var removeFrom = currentNode.prev;
|
|
1017
|
+
if (before) {
|
|
1018
|
+
removeFrom = addAfter(tokenList, removeFrom, before);
|
|
1019
|
+
pos += before.length;
|
|
1020
|
+
}
|
|
1021
|
+
removeRange(tokenList, removeFrom, removeCount);
|
|
1022
|
+
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
|
1023
|
+
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
|
1024
|
+
if (after) {
|
|
1025
|
+
addAfter(tokenList, currentNode, after);
|
|
1026
|
+
}
|
|
1027
|
+
if (removeCount > 1) {
|
|
1028
|
+
var nestedRematch = {
|
|
1029
|
+
cause: token + "," + j2,
|
|
1030
|
+
reach
|
|
1031
|
+
};
|
|
1032
|
+
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
|
1033
|
+
if (rematch && nestedRematch.reach > rematch.reach) {
|
|
1034
|
+
rematch.reach = nestedRematch.reach;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
function LinkedList() {
|
|
1042
|
+
var head = { value: null, prev: null, next: null };
|
|
1043
|
+
var tail = { value: null, prev: head, next: null };
|
|
1044
|
+
head.next = tail;
|
|
1045
|
+
this.head = head;
|
|
1046
|
+
this.tail = tail;
|
|
1047
|
+
this.length = 0;
|
|
1048
|
+
}
|
|
1049
|
+
function addAfter(list, node, value) {
|
|
1050
|
+
var next = node.next;
|
|
1051
|
+
var newNode = { value, prev: node, next };
|
|
1052
|
+
node.next = newNode;
|
|
1053
|
+
next.prev = newNode;
|
|
1054
|
+
list.length++;
|
|
1055
|
+
return newNode;
|
|
1056
|
+
}
|
|
1057
|
+
function removeRange(list, node, count) {
|
|
1058
|
+
var next = node.next;
|
|
1059
|
+
for (var i = 0; i < count && next !== list.tail; i++) {
|
|
1060
|
+
next = next.next;
|
|
1061
|
+
}
|
|
1062
|
+
node.next = next;
|
|
1063
|
+
next.prev = node;
|
|
1064
|
+
list.length -= i;
|
|
1065
|
+
}
|
|
1066
|
+
function toArray(list) {
|
|
1067
|
+
var array = [];
|
|
1068
|
+
var node = list.head.next;
|
|
1069
|
+
while (node !== list.tail) {
|
|
1070
|
+
array.push(node.value);
|
|
1071
|
+
node = node.next;
|
|
1072
|
+
}
|
|
1073
|
+
return array;
|
|
1074
|
+
}
|
|
1075
|
+
if (!_self2.document) {
|
|
1076
|
+
if (!_self2.addEventListener) {
|
|
1077
|
+
return _;
|
|
1078
|
+
}
|
|
1079
|
+
if (!_.disableWorkerMessageHandler) {
|
|
1080
|
+
_self2.addEventListener("message", function(evt) {
|
|
1081
|
+
var message = JSON.parse(evt.data);
|
|
1082
|
+
var lang2 = message.language;
|
|
1083
|
+
var code = message.code;
|
|
1084
|
+
var immediateClose = message.immediateClose;
|
|
1085
|
+
_self2.postMessage(_.highlight(code, _.languages[lang2], lang2));
|
|
1086
|
+
if (immediateClose) {
|
|
1087
|
+
_self2.close();
|
|
1088
|
+
}
|
|
1089
|
+
}, false);
|
|
1090
|
+
}
|
|
1091
|
+
return _;
|
|
1092
|
+
}
|
|
1093
|
+
var script = _.util.currentScript();
|
|
1094
|
+
if (script) {
|
|
1095
|
+
_.filename = script.src;
|
|
1096
|
+
if (script.hasAttribute("data-manual")) {
|
|
1097
|
+
_.manual = true;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function highlightAutomaticallyCallback() {
|
|
1101
|
+
if (!_.manual) {
|
|
1102
|
+
_.highlightAll();
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (!_.manual) {
|
|
1106
|
+
var readyState = document.readyState;
|
|
1107
|
+
if (readyState === "loading" || readyState === "interactive" && script && script.defer) {
|
|
1108
|
+
document.addEventListener("DOMContentLoaded", highlightAutomaticallyCallback);
|
|
1109
|
+
} else {
|
|
1110
|
+
if (window.requestAnimationFrame) {
|
|
1111
|
+
window.requestAnimationFrame(highlightAutomaticallyCallback);
|
|
1112
|
+
} else {
|
|
1113
|
+
window.setTimeout(highlightAutomaticallyCallback, 16);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return _;
|
|
1118
|
+
}(_self);
|
|
1119
|
+
if (module.exports) {
|
|
1120
|
+
module.exports = Prism2;
|
|
1121
|
+
}
|
|
1122
|
+
if (typeof commonjsGlobal !== "undefined") {
|
|
1123
|
+
commonjsGlobal.Prism = Prism2;
|
|
1124
|
+
}
|
|
1125
|
+
Prism2.languages.markup = {
|
|
1126
|
+
"comment": {
|
|
1127
|
+
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
|
1128
|
+
greedy: true
|
|
1129
|
+
},
|
|
1130
|
+
"prolog": {
|
|
1131
|
+
pattern: /<\?[\s\S]+?\?>/,
|
|
1132
|
+
greedy: true
|
|
1133
|
+
},
|
|
1134
|
+
"doctype": {
|
|
1135
|
+
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
1136
|
+
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
|
1137
|
+
greedy: true,
|
|
1138
|
+
inside: {
|
|
1139
|
+
"internal-subset": {
|
|
1140
|
+
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
|
1141
|
+
lookbehind: true,
|
|
1142
|
+
greedy: true,
|
|
1143
|
+
inside: null
|
|
1144
|
+
// see below
|
|
1145
|
+
},
|
|
1146
|
+
"string": {
|
|
1147
|
+
pattern: /"[^"]*"|'[^']*'/,
|
|
1148
|
+
greedy: true
|
|
1149
|
+
},
|
|
1150
|
+
"punctuation": /^<!|>$|[[\]]/,
|
|
1151
|
+
"doctype-tag": /^DOCTYPE/i,
|
|
1152
|
+
"name": /[^\s<>'"]+/
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
"cdata": {
|
|
1156
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
1157
|
+
greedy: true
|
|
1158
|
+
},
|
|
1159
|
+
"tag": {
|
|
1160
|
+
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
|
1161
|
+
greedy: true,
|
|
1162
|
+
inside: {
|
|
1163
|
+
"tag": {
|
|
1164
|
+
pattern: /^<\/?[^\s>\/]+/,
|
|
1165
|
+
inside: {
|
|
1166
|
+
"punctuation": /^<\/?/,
|
|
1167
|
+
"namespace": /^[^\s>\/:]+:/
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
"special-attr": [],
|
|
1171
|
+
"attr-value": {
|
|
1172
|
+
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
|
1173
|
+
inside: {
|
|
1174
|
+
"punctuation": [
|
|
1175
|
+
{
|
|
1176
|
+
pattern: /^=/,
|
|
1177
|
+
alias: "attr-equals"
|
|
1178
|
+
},
|
|
1179
|
+
{
|
|
1180
|
+
pattern: /^(\s*)["']|["']$/,
|
|
1181
|
+
lookbehind: true
|
|
1182
|
+
}
|
|
1183
|
+
]
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
"punctuation": /\/?>/,
|
|
1187
|
+
"attr-name": {
|
|
1188
|
+
pattern: /[^\s>\/]+/,
|
|
1189
|
+
inside: {
|
|
1190
|
+
"namespace": /^[^\s>\/:]+:/
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
},
|
|
1195
|
+
"entity": [
|
|
1196
|
+
{
|
|
1197
|
+
pattern: /&[\da-z]{1,8};/i,
|
|
1198
|
+
alias: "named-entity"
|
|
1199
|
+
},
|
|
1200
|
+
/&#x?[\da-f]{1,8};/i
|
|
1201
|
+
]
|
|
1202
|
+
};
|
|
1203
|
+
Prism2.languages.markup["tag"].inside["attr-value"].inside["entity"] = Prism2.languages.markup["entity"];
|
|
1204
|
+
Prism2.languages.markup["doctype"].inside["internal-subset"].inside = Prism2.languages.markup;
|
|
1205
|
+
Prism2.hooks.add("wrap", function(env) {
|
|
1206
|
+
if (env.type === "entity") {
|
|
1207
|
+
env.attributes["title"] = env.content.replace(/&/, "&");
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
Object.defineProperty(Prism2.languages.markup.tag, "addInlined", {
|
|
1211
|
+
/**
|
|
1212
|
+
* Adds an inlined language to markup.
|
|
1213
|
+
*
|
|
1214
|
+
* An example of an inlined language is CSS with `<style>` tags.
|
|
1215
|
+
*
|
|
1216
|
+
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
|
1217
|
+
* case insensitive.
|
|
1218
|
+
* @param {string} lang The language key.
|
|
1219
|
+
* @example
|
|
1220
|
+
* addInlined('style', 'css');
|
|
1221
|
+
*/
|
|
1222
|
+
value: function addInlined(tagName, lang) {
|
|
1223
|
+
var includedCdataInside = {};
|
|
1224
|
+
includedCdataInside["language-" + lang] = {
|
|
1225
|
+
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
|
1226
|
+
lookbehind: true,
|
|
1227
|
+
inside: Prism2.languages[lang]
|
|
1228
|
+
};
|
|
1229
|
+
includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i;
|
|
1230
|
+
var inside = {
|
|
1231
|
+
"included-cdata": {
|
|
1232
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
1233
|
+
inside: includedCdataInside
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
inside["language-" + lang] = {
|
|
1237
|
+
pattern: /[\s\S]+/,
|
|
1238
|
+
inside: Prism2.languages[lang]
|
|
1239
|
+
};
|
|
1240
|
+
var def = {};
|
|
1241
|
+
def[tagName] = {
|
|
1242
|
+
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function() {
|
|
1243
|
+
return tagName;
|
|
1244
|
+
}), "i"),
|
|
1245
|
+
lookbehind: true,
|
|
1246
|
+
greedy: true,
|
|
1247
|
+
inside
|
|
1248
|
+
};
|
|
1249
|
+
Prism2.languages.insertBefore("markup", "cdata", def);
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
Object.defineProperty(Prism2.languages.markup.tag, "addAttribute", {
|
|
1253
|
+
/**
|
|
1254
|
+
* Adds an pattern to highlight languages embedded in HTML attributes.
|
|
1255
|
+
*
|
|
1256
|
+
* An example of an inlined language is CSS with `style` attributes.
|
|
1257
|
+
*
|
|
1258
|
+
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
|
1259
|
+
* case insensitive.
|
|
1260
|
+
* @param {string} lang The language key.
|
|
1261
|
+
* @example
|
|
1262
|
+
* addAttribute('style', 'css');
|
|
1263
|
+
*/
|
|
1264
|
+
value: function(attrName, lang) {
|
|
1265
|
+
Prism2.languages.markup.tag.inside["special-attr"].push({
|
|
1266
|
+
pattern: RegExp(
|
|
1267
|
+
/(^|["'\s])/.source + "(?:" + attrName + ")" + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
|
1268
|
+
"i"
|
|
1269
|
+
),
|
|
1270
|
+
lookbehind: true,
|
|
1271
|
+
inside: {
|
|
1272
|
+
"attr-name": /^[^\s=]+/,
|
|
1273
|
+
"attr-value": {
|
|
1274
|
+
pattern: /=[\s\S]+/,
|
|
1275
|
+
inside: {
|
|
1276
|
+
"value": {
|
|
1277
|
+
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
|
1278
|
+
lookbehind: true,
|
|
1279
|
+
alias: [lang, "language-" + lang],
|
|
1280
|
+
inside: Prism2.languages[lang]
|
|
1281
|
+
},
|
|
1282
|
+
"punctuation": [
|
|
1283
|
+
{
|
|
1284
|
+
pattern: /^=/,
|
|
1285
|
+
alias: "attr-equals"
|
|
1286
|
+
},
|
|
1287
|
+
/"|'/
|
|
1288
|
+
]
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
Prism2.languages.html = Prism2.languages.markup;
|
|
1296
|
+
Prism2.languages.mathml = Prism2.languages.markup;
|
|
1297
|
+
Prism2.languages.svg = Prism2.languages.markup;
|
|
1298
|
+
Prism2.languages.xml = Prism2.languages.extend("markup", {});
|
|
1299
|
+
Prism2.languages.ssml = Prism2.languages.xml;
|
|
1300
|
+
Prism2.languages.atom = Prism2.languages.xml;
|
|
1301
|
+
Prism2.languages.rss = Prism2.languages.xml;
|
|
1302
|
+
(function(Prism3) {
|
|
1303
|
+
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
|
1304
|
+
Prism3.languages.css = {
|
|
1305
|
+
"comment": /\/\*[\s\S]*?\*\//,
|
|
1306
|
+
"atrule": {
|
|
1307
|
+
pattern: RegExp("@[\\w-](?:" + /[^;{\s"']|\s+(?!\s)/.source + "|" + string.source + ")*?" + /(?:;|(?=\s*\{))/.source),
|
|
1308
|
+
inside: {
|
|
1309
|
+
"rule": /^@[\w-]+/,
|
|
1310
|
+
"selector-function-argument": {
|
|
1311
|
+
pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
|
1312
|
+
lookbehind: true,
|
|
1313
|
+
alias: "selector"
|
|
1314
|
+
},
|
|
1315
|
+
"keyword": {
|
|
1316
|
+
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
|
1317
|
+
lookbehind: true
|
|
1318
|
+
}
|
|
1319
|
+
// See rest below
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
"url": {
|
|
1323
|
+
// https://drafts.csswg.org/css-values-3/#urls
|
|
1324
|
+
pattern: RegExp("\\burl\\((?:" + string.source + "|" + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ")\\)", "i"),
|
|
1325
|
+
greedy: true,
|
|
1326
|
+
inside: {
|
|
1327
|
+
"function": /^url/i,
|
|
1328
|
+
"punctuation": /^\(|\)$/,
|
|
1329
|
+
"string": {
|
|
1330
|
+
pattern: RegExp("^" + string.source + "$"),
|
|
1331
|
+
alias: "url"
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
},
|
|
1335
|
+
"selector": {
|
|
1336
|
+
pattern: RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|` + string.source + ")*(?=\\s*\\{)"),
|
|
1337
|
+
lookbehind: true
|
|
1338
|
+
},
|
|
1339
|
+
"string": {
|
|
1340
|
+
pattern: string,
|
|
1341
|
+
greedy: true
|
|
1342
|
+
},
|
|
1343
|
+
"property": {
|
|
1344
|
+
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
|
1345
|
+
lookbehind: true
|
|
1346
|
+
},
|
|
1347
|
+
"important": /!important\b/i,
|
|
1348
|
+
"function": {
|
|
1349
|
+
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
|
1350
|
+
lookbehind: true
|
|
1351
|
+
},
|
|
1352
|
+
"punctuation": /[(){};:,]/
|
|
1353
|
+
};
|
|
1354
|
+
Prism3.languages.css["atrule"].inside.rest = Prism3.languages.css;
|
|
1355
|
+
var markup = Prism3.languages.markup;
|
|
1356
|
+
if (markup) {
|
|
1357
|
+
markup.tag.addInlined("style", "css");
|
|
1358
|
+
markup.tag.addAttribute("style", "css");
|
|
1359
|
+
}
|
|
1360
|
+
})(Prism2);
|
|
1361
|
+
Prism2.languages.clike = {
|
|
1362
|
+
"comment": [
|
|
1363
|
+
{
|
|
1364
|
+
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
1365
|
+
lookbehind: true,
|
|
1366
|
+
greedy: true
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
pattern: /(^|[^\\:])\/\/.*/,
|
|
1370
|
+
lookbehind: true,
|
|
1371
|
+
greedy: true
|
|
1372
|
+
}
|
|
1373
|
+
],
|
|
1374
|
+
"string": {
|
|
1375
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
1376
|
+
greedy: true
|
|
1377
|
+
},
|
|
1378
|
+
"class-name": {
|
|
1379
|
+
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
1380
|
+
lookbehind: true,
|
|
1381
|
+
inside: {
|
|
1382
|
+
"punctuation": /[.\\]/
|
|
1383
|
+
}
|
|
1384
|
+
},
|
|
1385
|
+
"keyword": /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
1386
|
+
"boolean": /\b(?:false|true)\b/,
|
|
1387
|
+
"function": /\b\w+(?=\()/,
|
|
1388
|
+
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
1389
|
+
"operator": /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
1390
|
+
"punctuation": /[{}[\];(),.:]/
|
|
1391
|
+
};
|
|
1392
|
+
Prism2.languages.javascript = Prism2.languages.extend("clike", {
|
|
1393
|
+
"class-name": [
|
|
1394
|
+
Prism2.languages.clike["class-name"],
|
|
1395
|
+
{
|
|
1396
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
1397
|
+
lookbehind: true
|
|
1398
|
+
}
|
|
1399
|
+
],
|
|
1400
|
+
"keyword": [
|
|
1401
|
+
{
|
|
1402
|
+
pattern: /((?:^|\})\s*)catch\b/,
|
|
1403
|
+
lookbehind: true
|
|
1404
|
+
},
|
|
1405
|
+
{
|
|
1406
|
+
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
|
1407
|
+
lookbehind: true
|
|
1408
|
+
}
|
|
1409
|
+
],
|
|
1410
|
+
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
1411
|
+
"function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
1412
|
+
"number": {
|
|
1413
|
+
pattern: RegExp(
|
|
1414
|
+
/(^|[^\w$])/.source + "(?:" + // constant
|
|
1415
|
+
(/NaN|Infinity/.source + "|" + // binary integer
|
|
1416
|
+
/0[bB][01]+(?:_[01]+)*n?/.source + "|" + // octal integer
|
|
1417
|
+
/0[oO][0-7]+(?:_[0-7]+)*n?/.source + "|" + // hexadecimal integer
|
|
1418
|
+
/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + "|" + // decimal bigint
|
|
1419
|
+
/\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
|
|
1420
|
+
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
|
|
1421
|
+
),
|
|
1422
|
+
lookbehind: true
|
|
1423
|
+
},
|
|
1424
|
+
"operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
1425
|
+
});
|
|
1426
|
+
Prism2.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
1427
|
+
Prism2.languages.insertBefore("javascript", "keyword", {
|
|
1428
|
+
"regex": {
|
|
1429
|
+
pattern: RegExp(
|
|
1430
|
+
// lookbehind
|
|
1431
|
+
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
1432
|
+
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + // Regex pattern:
|
|
1433
|
+
// There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
|
|
1434
|
+
// classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
|
|
1435
|
+
// with the only syntax, so we have to define 2 different regex patterns.
|
|
1436
|
+
/\//.source + "(?:" + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + "|" + // `v` flag syntax. This supports 3 levels of nested character classes.
|
|
1437
|
+
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
|
|
1438
|
+
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
1439
|
+
),
|
|
1440
|
+
lookbehind: true,
|
|
1441
|
+
greedy: true,
|
|
1442
|
+
inside: {
|
|
1443
|
+
"regex-source": {
|
|
1444
|
+
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
1445
|
+
lookbehind: true,
|
|
1446
|
+
alias: "language-regex",
|
|
1447
|
+
inside: Prism2.languages.regex
|
|
1448
|
+
},
|
|
1449
|
+
"regex-delimiter": /^\/|\/$/,
|
|
1450
|
+
"regex-flags": /^[a-z]+$/
|
|
1451
|
+
}
|
|
1452
|
+
},
|
|
1453
|
+
// This must be declared before keyword because we use "function" inside the look-forward
|
|
1454
|
+
"function-variable": {
|
|
1455
|
+
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
|
1456
|
+
alias: "function"
|
|
1457
|
+
},
|
|
1458
|
+
"parameter": [
|
|
1459
|
+
{
|
|
1460
|
+
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
1461
|
+
lookbehind: true,
|
|
1462
|
+
inside: Prism2.languages.javascript
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
1466
|
+
lookbehind: true,
|
|
1467
|
+
inside: Prism2.languages.javascript
|
|
1468
|
+
},
|
|
1469
|
+
{
|
|
1470
|
+
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
1471
|
+
lookbehind: true,
|
|
1472
|
+
inside: Prism2.languages.javascript
|
|
1473
|
+
},
|
|
1474
|
+
{
|
|
1475
|
+
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
|
1476
|
+
lookbehind: true,
|
|
1477
|
+
inside: Prism2.languages.javascript
|
|
1478
|
+
}
|
|
1479
|
+
],
|
|
1480
|
+
"constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
1481
|
+
});
|
|
1482
|
+
Prism2.languages.insertBefore("javascript", "string", {
|
|
1483
|
+
"hashbang": {
|
|
1484
|
+
pattern: /^#!.*/,
|
|
1485
|
+
greedy: true,
|
|
1486
|
+
alias: "comment"
|
|
1487
|
+
},
|
|
1488
|
+
"template-string": {
|
|
1489
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
1490
|
+
greedy: true,
|
|
1491
|
+
inside: {
|
|
1492
|
+
"template-punctuation": {
|
|
1493
|
+
pattern: /^`|`$/,
|
|
1494
|
+
alias: "string"
|
|
1495
|
+
},
|
|
1496
|
+
"interpolation": {
|
|
1497
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
1498
|
+
lookbehind: true,
|
|
1499
|
+
inside: {
|
|
1500
|
+
"interpolation-punctuation": {
|
|
1501
|
+
pattern: /^\$\{|\}$/,
|
|
1502
|
+
alias: "punctuation"
|
|
1503
|
+
},
|
|
1504
|
+
rest: Prism2.languages.javascript
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
"string": /[\s\S]+/
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
"string-property": {
|
|
1511
|
+
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
1512
|
+
lookbehind: true,
|
|
1513
|
+
greedy: true,
|
|
1514
|
+
alias: "property"
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
Prism2.languages.insertBefore("javascript", "operator", {
|
|
1518
|
+
"literal-property": {
|
|
1519
|
+
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
1520
|
+
lookbehind: true,
|
|
1521
|
+
alias: "property"
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
if (Prism2.languages.markup) {
|
|
1525
|
+
Prism2.languages.markup.tag.addInlined("script", "javascript");
|
|
1526
|
+
Prism2.languages.markup.tag.addAttribute(
|
|
1527
|
+
/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
|
1528
|
+
"javascript"
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
Prism2.languages.js = Prism2.languages.javascript;
|
|
1532
|
+
(function() {
|
|
1533
|
+
if (typeof Prism2 === "undefined" || typeof document === "undefined") {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
if (!Element.prototype.matches) {
|
|
1537
|
+
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
1538
|
+
}
|
|
1539
|
+
var LOADING_MESSAGE = "Loading…";
|
|
1540
|
+
var FAILURE_MESSAGE = function(status, message) {
|
|
1541
|
+
return "✖ Error " + status + " while fetching file: " + message;
|
|
1542
|
+
};
|
|
1543
|
+
var FAILURE_EMPTY_MESSAGE = "✖ Error: File does not exist or is empty";
|
|
1544
|
+
var EXTENSIONS = {
|
|
1545
|
+
"js": "javascript",
|
|
1546
|
+
"py": "python",
|
|
1547
|
+
"rb": "ruby",
|
|
1548
|
+
"ps1": "powershell",
|
|
1549
|
+
"psm1": "powershell",
|
|
1550
|
+
"sh": "bash",
|
|
1551
|
+
"bat": "batch",
|
|
1552
|
+
"h": "c",
|
|
1553
|
+
"tex": "latex"
|
|
1554
|
+
};
|
|
1555
|
+
var STATUS_ATTR = "data-src-status";
|
|
1556
|
+
var STATUS_LOADING = "loading";
|
|
1557
|
+
var STATUS_LOADED = "loaded";
|
|
1558
|
+
var STATUS_FAILED = "failed";
|
|
1559
|
+
var SELECTOR = "pre[data-src]:not([" + STATUS_ATTR + '="' + STATUS_LOADED + '"]):not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
|
|
1560
|
+
function loadFile(src, success, error) {
|
|
1561
|
+
var xhr = new XMLHttpRequest();
|
|
1562
|
+
xhr.open("GET", src, true);
|
|
1563
|
+
xhr.onreadystatechange = function() {
|
|
1564
|
+
if (xhr.readyState == 4) {
|
|
1565
|
+
if (xhr.status < 400 && xhr.responseText) {
|
|
1566
|
+
success(xhr.responseText);
|
|
1567
|
+
} else {
|
|
1568
|
+
if (xhr.status >= 400) {
|
|
1569
|
+
error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
|
|
1570
|
+
} else {
|
|
1571
|
+
error(FAILURE_EMPTY_MESSAGE);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
xhr.send(null);
|
|
1577
|
+
}
|
|
1578
|
+
function parseRange(range) {
|
|
1579
|
+
var m2 = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || "");
|
|
1580
|
+
if (m2) {
|
|
1581
|
+
var start = Number(m2[1]);
|
|
1582
|
+
var comma = m2[2];
|
|
1583
|
+
var end = m2[3];
|
|
1584
|
+
if (!comma) {
|
|
1585
|
+
return [start, start];
|
|
1586
|
+
}
|
|
1587
|
+
if (!end) {
|
|
1588
|
+
return [start, void 0];
|
|
1589
|
+
}
|
|
1590
|
+
return [start, Number(end)];
|
|
1591
|
+
}
|
|
1592
|
+
return void 0;
|
|
1593
|
+
}
|
|
1594
|
+
Prism2.hooks.add("before-highlightall", function(env) {
|
|
1595
|
+
env.selector += ", " + SELECTOR;
|
|
1596
|
+
});
|
|
1597
|
+
Prism2.hooks.add("before-sanity-check", function(env) {
|
|
1598
|
+
var pre = (
|
|
1599
|
+
/** @type {HTMLPreElement} */
|
|
1600
|
+
env.element
|
|
1601
|
+
);
|
|
1602
|
+
if (pre.matches(SELECTOR)) {
|
|
1603
|
+
env.code = "";
|
|
1604
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADING);
|
|
1605
|
+
var code = pre.appendChild(document.createElement("CODE"));
|
|
1606
|
+
code.textContent = LOADING_MESSAGE;
|
|
1607
|
+
var src = pre.getAttribute("data-src");
|
|
1608
|
+
var language = env.language;
|
|
1609
|
+
if (language === "none") {
|
|
1610
|
+
var extension = (/\.(\w+)$/.exec(src) || [, "none"])[1];
|
|
1611
|
+
language = EXTENSIONS[extension] || extension;
|
|
1612
|
+
}
|
|
1613
|
+
Prism2.util.setLanguage(code, language);
|
|
1614
|
+
Prism2.util.setLanguage(pre, language);
|
|
1615
|
+
var autoloader = Prism2.plugins.autoloader;
|
|
1616
|
+
if (autoloader) {
|
|
1617
|
+
autoloader.loadLanguages(language);
|
|
1618
|
+
}
|
|
1619
|
+
loadFile(
|
|
1620
|
+
src,
|
|
1621
|
+
function(text) {
|
|
1622
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
|
|
1623
|
+
var range = parseRange(pre.getAttribute("data-range"));
|
|
1624
|
+
if (range) {
|
|
1625
|
+
var lines = text.split(/\r\n?|\n/g);
|
|
1626
|
+
var start = range[0];
|
|
1627
|
+
var end = range[1] == null ? lines.length : range[1];
|
|
1628
|
+
if (start < 0) {
|
|
1629
|
+
start += lines.length;
|
|
1630
|
+
}
|
|
1631
|
+
start = Math.max(0, Math.min(start - 1, lines.length));
|
|
1632
|
+
if (end < 0) {
|
|
1633
|
+
end += lines.length;
|
|
1634
|
+
}
|
|
1635
|
+
end = Math.max(0, Math.min(end, lines.length));
|
|
1636
|
+
text = lines.slice(start, end).join("\n");
|
|
1637
|
+
if (!pre.hasAttribute("data-start")) {
|
|
1638
|
+
pre.setAttribute("data-start", String(start + 1));
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
code.textContent = text;
|
|
1642
|
+
Prism2.highlightElement(code);
|
|
1643
|
+
},
|
|
1644
|
+
function(error) {
|
|
1645
|
+
pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
|
|
1646
|
+
code.textContent = error;
|
|
1647
|
+
}
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
Prism2.plugins.fileHighlight = {
|
|
1652
|
+
/**
|
|
1653
|
+
* Executes the File Highlight plugin for all matching `pre` elements under the given container.
|
|
1654
|
+
*
|
|
1655
|
+
* Note: Elements which are already loaded or currently loading will not be touched by this method.
|
|
1656
|
+
*
|
|
1657
|
+
* @param {ParentNode} [container=document]
|
|
1658
|
+
*/
|
|
1659
|
+
highlight: function highlight(container) {
|
|
1660
|
+
var elements = (container || document).querySelectorAll(SELECTOR);
|
|
1661
|
+
for (var i = 0, element; element = elements[i++]; ) {
|
|
1662
|
+
Prism2.highlightElement(element);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
var logged = false;
|
|
1667
|
+
Prism2.fileHighlight = function() {
|
|
1668
|
+
if (!logged) {
|
|
1669
|
+
console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.");
|
|
1670
|
+
logged = true;
|
|
1671
|
+
}
|
|
1672
|
+
Prism2.plugins.fileHighlight.highlight.apply(this, arguments);
|
|
1673
|
+
};
|
|
1674
|
+
})();
|
|
1675
|
+
})(prism);
|
|
1676
|
+
var prismExports = prism.exports;
|
|
1677
|
+
const Prism$1 = /* @__PURE__ */ getDefaultExportFromCjs(prismExports);
|
|
3
1678
|
Prism.languages.clike = {
|
|
4
|
-
comment: [
|
|
1679
|
+
"comment": [
|
|
5
1680
|
{
|
|
6
1681
|
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
7
|
-
lookbehind:
|
|
8
|
-
greedy:
|
|
1682
|
+
lookbehind: true,
|
|
1683
|
+
greedy: true
|
|
9
1684
|
},
|
|
10
1685
|
{
|
|
11
1686
|
pattern: /(^|[^\\:])\/\/.*/,
|
|
12
|
-
lookbehind:
|
|
13
|
-
greedy:
|
|
1687
|
+
lookbehind: true,
|
|
1688
|
+
greedy: true
|
|
14
1689
|
}
|
|
15
1690
|
],
|
|
16
|
-
string: {
|
|
1691
|
+
"string": {
|
|
17
1692
|
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
18
|
-
greedy:
|
|
1693
|
+
greedy: true
|
|
19
1694
|
},
|
|
20
1695
|
"class-name": {
|
|
21
1696
|
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
22
|
-
lookbehind:
|
|
1697
|
+
lookbehind: true,
|
|
23
1698
|
inside: {
|
|
24
|
-
punctuation: /[.\\]/
|
|
1699
|
+
"punctuation": /[.\\]/
|
|
25
1700
|
}
|
|
26
1701
|
},
|
|
27
|
-
keyword: /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
28
|
-
boolean: /\b(?:false|true)\b/,
|
|
29
|
-
function: /\b\w+(?=\()/,
|
|
30
|
-
number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
31
|
-
operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
32
|
-
punctuation: /[{}[\];(),.:]/
|
|
1702
|
+
"keyword": /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
1703
|
+
"boolean": /\b(?:false|true)\b/,
|
|
1704
|
+
"function": /\b\w+(?=\()/,
|
|
1705
|
+
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
1706
|
+
"operator": /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
1707
|
+
"punctuation": /[{}[\];(),.:]/
|
|
33
1708
|
};
|
|
34
1709
|
Prism.languages.javascript = Prism.languages.extend("clike", {
|
|
35
1710
|
"class-name": [
|
|
36
1711
|
Prism.languages.clike["class-name"],
|
|
37
1712
|
{
|
|
38
1713
|
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
39
|
-
lookbehind:
|
|
1714
|
+
lookbehind: true
|
|
40
1715
|
}
|
|
41
1716
|
],
|
|
42
|
-
keyword: [
|
|
1717
|
+
"keyword": [
|
|
43
1718
|
{
|
|
44
1719
|
pattern: /((?:^|\})\s*)catch\b/,
|
|
45
|
-
lookbehind:
|
|
1720
|
+
lookbehind: true
|
|
46
1721
|
},
|
|
47
1722
|
{
|
|
48
1723
|
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
|
49
|
-
lookbehind:
|
|
1724
|
+
lookbehind: true
|
|
50
1725
|
}
|
|
51
1726
|
],
|
|
52
1727
|
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
53
|
-
function: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
54
|
-
number: {
|
|
1728
|
+
"function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
1729
|
+
"number": {
|
|
55
1730
|
pattern: RegExp(
|
|
56
1731
|
/(^|[^\w$])/.source + "(?:" + // constant
|
|
57
1732
|
(/NaN|Infinity/.source + "|" + // binary integer
|
|
@@ -61,13 +1736,13 @@ Prism.languages.javascript = Prism.languages.extend("clike", {
|
|
|
61
1736
|
/\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
|
|
62
1737
|
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
|
|
63
1738
|
),
|
|
64
|
-
lookbehind:
|
|
1739
|
+
lookbehind: true
|
|
65
1740
|
},
|
|
66
|
-
operator: /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
1741
|
+
"operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
67
1742
|
});
|
|
68
1743
|
Prism.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
69
1744
|
Prism.languages.insertBefore("javascript", "keyword", {
|
|
70
|
-
regex: {
|
|
1745
|
+
"regex": {
|
|
71
1746
|
pattern: RegExp(
|
|
72
1747
|
// lookbehind
|
|
73
1748
|
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
@@ -79,12 +1754,12 @@ Prism.languages.insertBefore("javascript", "keyword", {
|
|
|
79
1754
|
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
|
|
80
1755
|
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
81
1756
|
),
|
|
82
|
-
lookbehind:
|
|
83
|
-
greedy:
|
|
1757
|
+
lookbehind: true,
|
|
1758
|
+
greedy: true,
|
|
84
1759
|
inside: {
|
|
85
1760
|
"regex-source": {
|
|
86
1761
|
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
87
|
-
lookbehind:
|
|
1762
|
+
lookbehind: true,
|
|
88
1763
|
alias: "language-regex",
|
|
89
1764
|
inside: Prism.languages.regex
|
|
90
1765
|
},
|
|
@@ -97,47 +1772,47 @@ Prism.languages.insertBefore("javascript", "keyword", {
|
|
|
97
1772
|
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
|
98
1773
|
alias: "function"
|
|
99
1774
|
},
|
|
100
|
-
parameter: [
|
|
1775
|
+
"parameter": [
|
|
101
1776
|
{
|
|
102
1777
|
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
103
|
-
lookbehind:
|
|
1778
|
+
lookbehind: true,
|
|
104
1779
|
inside: Prism.languages.javascript
|
|
105
1780
|
},
|
|
106
1781
|
{
|
|
107
1782
|
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
108
|
-
lookbehind:
|
|
1783
|
+
lookbehind: true,
|
|
109
1784
|
inside: Prism.languages.javascript
|
|
110
1785
|
},
|
|
111
1786
|
{
|
|
112
1787
|
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
113
|
-
lookbehind:
|
|
1788
|
+
lookbehind: true,
|
|
114
1789
|
inside: Prism.languages.javascript
|
|
115
1790
|
},
|
|
116
1791
|
{
|
|
117
1792
|
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
|
118
|
-
lookbehind:
|
|
1793
|
+
lookbehind: true,
|
|
119
1794
|
inside: Prism.languages.javascript
|
|
120
1795
|
}
|
|
121
1796
|
],
|
|
122
|
-
constant: /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
1797
|
+
"constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
123
1798
|
});
|
|
124
1799
|
Prism.languages.insertBefore("javascript", "string", {
|
|
125
|
-
hashbang: {
|
|
1800
|
+
"hashbang": {
|
|
126
1801
|
pattern: /^#!.*/,
|
|
127
|
-
greedy:
|
|
1802
|
+
greedy: true,
|
|
128
1803
|
alias: "comment"
|
|
129
1804
|
},
|
|
130
1805
|
"template-string": {
|
|
131
1806
|
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
132
|
-
greedy:
|
|
1807
|
+
greedy: true,
|
|
133
1808
|
inside: {
|
|
134
1809
|
"template-punctuation": {
|
|
135
1810
|
pattern: /^`|`$/,
|
|
136
1811
|
alias: "string"
|
|
137
1812
|
},
|
|
138
|
-
interpolation: {
|
|
1813
|
+
"interpolation": {
|
|
139
1814
|
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
140
|
-
lookbehind:
|
|
1815
|
+
lookbehind: true,
|
|
141
1816
|
inside: {
|
|
142
1817
|
"interpolation-punctuation": {
|
|
143
1818
|
pattern: /^\$\{|\}$/,
|
|
@@ -146,46 +1821,49 @@ Prism.languages.insertBefore("javascript", "string", {
|
|
|
146
1821
|
rest: Prism.languages.javascript
|
|
147
1822
|
}
|
|
148
1823
|
},
|
|
149
|
-
string: /[\s\S]+/
|
|
1824
|
+
"string": /[\s\S]+/
|
|
150
1825
|
}
|
|
151
1826
|
},
|
|
152
1827
|
"string-property": {
|
|
153
1828
|
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
154
|
-
lookbehind:
|
|
155
|
-
greedy:
|
|
1829
|
+
lookbehind: true,
|
|
1830
|
+
greedy: true,
|
|
156
1831
|
alias: "property"
|
|
157
1832
|
}
|
|
158
1833
|
});
|
|
159
1834
|
Prism.languages.insertBefore("javascript", "operator", {
|
|
160
1835
|
"literal-property": {
|
|
161
1836
|
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
162
|
-
lookbehind:
|
|
1837
|
+
lookbehind: true,
|
|
163
1838
|
alias: "property"
|
|
164
1839
|
}
|
|
165
1840
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
))
|
|
1841
|
+
if (Prism.languages.markup) {
|
|
1842
|
+
Prism.languages.markup.tag.addInlined("script", "javascript");
|
|
1843
|
+
Prism.languages.markup.tag.addAttribute(
|
|
1844
|
+
/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
|
1845
|
+
"javascript"
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
170
1848
|
Prism.languages.js = Prism.languages.javascript;
|
|
171
1849
|
Prism.languages.python = {
|
|
172
|
-
comment: {
|
|
1850
|
+
"comment": {
|
|
173
1851
|
pattern: /(^|[^\\])#.*/,
|
|
174
|
-
lookbehind:
|
|
175
|
-
greedy:
|
|
1852
|
+
lookbehind: true,
|
|
1853
|
+
greedy: true
|
|
176
1854
|
},
|
|
177
1855
|
"string-interpolation": {
|
|
178
1856
|
pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
|
|
179
|
-
greedy:
|
|
1857
|
+
greedy: true,
|
|
180
1858
|
inside: {
|
|
181
|
-
interpolation: {
|
|
1859
|
+
"interpolation": {
|
|
182
1860
|
// "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
|
|
183
1861
|
pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
|
|
184
|
-
lookbehind:
|
|
1862
|
+
lookbehind: true,
|
|
185
1863
|
inside: {
|
|
186
1864
|
"format-spec": {
|
|
187
1865
|
pattern: /(:)[^:(){}]+(?=\}$)/,
|
|
188
|
-
lookbehind:
|
|
1866
|
+
lookbehind: true
|
|
189
1867
|
},
|
|
190
1868
|
"conversion-option": {
|
|
191
1869
|
pattern: //,
|
|
@@ -194,52 +1872,52 @@ Prism.languages.python = {
|
|
|
194
1872
|
rest: null
|
|
195
1873
|
}
|
|
196
1874
|
},
|
|
197
|
-
string: /[\s\S]+/
|
|
1875
|
+
"string": /[\s\S]+/
|
|
198
1876
|
}
|
|
199
1877
|
},
|
|
200
1878
|
"triple-quoted-string": {
|
|
201
1879
|
pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
|
|
202
|
-
greedy:
|
|
1880
|
+
greedy: true,
|
|
203
1881
|
alias: "string"
|
|
204
1882
|
},
|
|
205
|
-
string: {
|
|
1883
|
+
"string": {
|
|
206
1884
|
pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
|
|
207
|
-
greedy:
|
|
1885
|
+
greedy: true
|
|
208
1886
|
},
|
|
209
|
-
function: {
|
|
1887
|
+
"function": {
|
|
210
1888
|
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
|
|
211
|
-
lookbehind:
|
|
1889
|
+
lookbehind: true
|
|
212
1890
|
},
|
|
213
1891
|
"class-name": {
|
|
214
1892
|
pattern: /(\bclass\s+)\w+/i,
|
|
215
|
-
lookbehind:
|
|
1893
|
+
lookbehind: true
|
|
216
1894
|
},
|
|
217
|
-
decorator: {
|
|
1895
|
+
"decorator": {
|
|
218
1896
|
pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
|
|
219
|
-
lookbehind:
|
|
1897
|
+
lookbehind: true,
|
|
220
1898
|
alias: ["annotation", "punctuation"],
|
|
221
1899
|
inside: {
|
|
222
|
-
punctuation: /\./
|
|
1900
|
+
"punctuation": /\./
|
|
223
1901
|
}
|
|
224
1902
|
},
|
|
225
|
-
keyword: /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
|
|
226
|
-
builtin: /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
|
|
227
|
-
boolean: /\b(?:False|None|True)\b/,
|
|
228
|
-
number: /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
|
|
229
|
-
operator: /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
|
230
|
-
punctuation: /[{}[\];(),.:]/
|
|
1903
|
+
"keyword": /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
|
|
1904
|
+
"builtin": /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
|
|
1905
|
+
"boolean": /\b(?:False|None|True)\b/,
|
|
1906
|
+
"number": /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
|
|
1907
|
+
"operator": /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
|
1908
|
+
"punctuation": /[{}[\];(),.:]/
|
|
231
1909
|
};
|
|
232
|
-
Prism.languages.python["string-interpolation"].inside
|
|
1910
|
+
Prism.languages.python["string-interpolation"].inside["interpolation"].inside.rest = Prism.languages.python;
|
|
233
1911
|
Prism.languages.py = Prism.languages.python;
|
|
234
1912
|
Prism.languages.go = Prism.languages.extend("clike", {
|
|
235
|
-
string: {
|
|
1913
|
+
"string": {
|
|
236
1914
|
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
|
|
237
|
-
lookbehind:
|
|
238
|
-
greedy:
|
|
1915
|
+
lookbehind: true,
|
|
1916
|
+
greedy: true
|
|
239
1917
|
},
|
|
240
|
-
keyword: /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
|
|
241
|
-
boolean: /\b(?:_|false|iota|nil|true)\b/,
|
|
242
|
-
number: [
|
|
1918
|
+
"keyword": /\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,
|
|
1919
|
+
"boolean": /\b(?:_|false|iota|nil|true)\b/,
|
|
1920
|
+
"number": [
|
|
243
1921
|
// binary and octal integers
|
|
244
1922
|
/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
|
|
245
1923
|
// hexadecimal integers and floats
|
|
@@ -247,195 +1925,199 @@ Prism.languages.go = Prism.languages.extend("clike", {
|
|
|
247
1925
|
// decimal integers and floats
|
|
248
1926
|
/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
|
|
249
1927
|
],
|
|
250
|
-
operator: /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
|
|
251
|
-
builtin: /\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/
|
|
1928
|
+
"operator": /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
|
|
1929
|
+
"builtin": /\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/
|
|
252
1930
|
});
|
|
253
1931
|
Prism.languages.insertBefore("go", "string", {
|
|
254
|
-
char: {
|
|
1932
|
+
"char": {
|
|
255
1933
|
pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
|
|
256
|
-
greedy:
|
|
1934
|
+
greedy: true
|
|
257
1935
|
}
|
|
258
1936
|
});
|
|
259
1937
|
delete Prism.languages.go["class-name"];
|
|
260
|
-
(function(
|
|
261
|
-
var
|
|
262
|
-
|
|
263
|
-
|
|
1938
|
+
(function(Prism2) {
|
|
1939
|
+
var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
|
|
1940
|
+
var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
|
|
1941
|
+
var className = {
|
|
1942
|
+
pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
|
|
1943
|
+
lookbehind: true,
|
|
264
1944
|
inside: {
|
|
265
|
-
namespace: {
|
|
1945
|
+
"namespace": {
|
|
266
1946
|
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
|
|
267
1947
|
inside: {
|
|
268
|
-
punctuation: /\./
|
|
1948
|
+
"punctuation": /\./
|
|
269
1949
|
}
|
|
270
1950
|
},
|
|
271
|
-
punctuation: /\./
|
|
1951
|
+
"punctuation": /\./
|
|
272
1952
|
}
|
|
273
1953
|
};
|
|
274
|
-
|
|
275
|
-
string: {
|
|
1954
|
+
Prism2.languages.java = Prism2.languages.extend("clike", {
|
|
1955
|
+
"string": {
|
|
276
1956
|
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
|
|
277
|
-
lookbehind:
|
|
278
|
-
greedy:
|
|
1957
|
+
lookbehind: true,
|
|
1958
|
+
greedy: true
|
|
279
1959
|
},
|
|
280
1960
|
"class-name": [
|
|
281
|
-
|
|
1961
|
+
className,
|
|
282
1962
|
{
|
|
283
1963
|
// variables, parameters, and constructor references
|
|
284
1964
|
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
|
285
|
-
pattern: RegExp(/(^|[^\w.])/.source +
|
|
286
|
-
lookbehind:
|
|
287
|
-
inside:
|
|
1965
|
+
pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
|
|
1966
|
+
lookbehind: true,
|
|
1967
|
+
inside: className.inside
|
|
288
1968
|
},
|
|
289
1969
|
{
|
|
290
1970
|
// class names based on keyword
|
|
291
1971
|
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
|
292
|
-
pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source +
|
|
293
|
-
lookbehind:
|
|
294
|
-
inside:
|
|
1972
|
+
pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
|
|
1973
|
+
lookbehind: true,
|
|
1974
|
+
inside: className.inside
|
|
295
1975
|
}
|
|
296
1976
|
],
|
|
297
|
-
keyword:
|
|
298
|
-
function: [
|
|
299
|
-
|
|
1977
|
+
"keyword": keywords,
|
|
1978
|
+
"function": [
|
|
1979
|
+
Prism2.languages.clike.function,
|
|
300
1980
|
{
|
|
301
1981
|
pattern: /(::\s*)[a-z_]\w*/,
|
|
302
|
-
lookbehind:
|
|
1982
|
+
lookbehind: true
|
|
303
1983
|
}
|
|
304
1984
|
],
|
|
305
|
-
number: /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
|
|
306
|
-
operator: {
|
|
1985
|
+
"number": /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
|
|
1986
|
+
"operator": {
|
|
307
1987
|
pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
|
|
308
|
-
lookbehind:
|
|
1988
|
+
lookbehind: true
|
|
309
1989
|
},
|
|
310
|
-
constant: /\b[A-Z][A-Z_\d]+\b/
|
|
311
|
-
})
|
|
1990
|
+
"constant": /\b[A-Z][A-Z_\d]+\b/
|
|
1991
|
+
});
|
|
1992
|
+
Prism2.languages.insertBefore("java", "string", {
|
|
312
1993
|
"triple-quoted-string": {
|
|
313
1994
|
// http://openjdk.java.net/jeps/355#Description
|
|
314
1995
|
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
|
|
315
|
-
greedy:
|
|
1996
|
+
greedy: true,
|
|
316
1997
|
alias: "string"
|
|
317
1998
|
},
|
|
318
|
-
char: {
|
|
1999
|
+
"char": {
|
|
319
2000
|
pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
|
|
320
|
-
greedy:
|
|
2001
|
+
greedy: true
|
|
321
2002
|
}
|
|
322
|
-
})
|
|
323
|
-
|
|
2003
|
+
});
|
|
2004
|
+
Prism2.languages.insertBefore("java", "class-name", {
|
|
2005
|
+
"annotation": {
|
|
324
2006
|
pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
|
|
325
|
-
lookbehind:
|
|
2007
|
+
lookbehind: true,
|
|
326
2008
|
alias: "punctuation"
|
|
327
2009
|
},
|
|
328
|
-
generics: {
|
|
2010
|
+
"generics": {
|
|
329
2011
|
pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
|
|
330
2012
|
inside: {
|
|
331
|
-
"class-name":
|
|
332
|
-
keyword:
|
|
333
|
-
punctuation: /[<>(),.:]/,
|
|
334
|
-
operator: /[?&|]/
|
|
2013
|
+
"class-name": className,
|
|
2014
|
+
"keyword": keywords,
|
|
2015
|
+
"punctuation": /[<>(),.:]/,
|
|
2016
|
+
"operator": /[?&|]/
|
|
335
2017
|
}
|
|
336
2018
|
},
|
|
337
|
-
import: [
|
|
2019
|
+
"import": [
|
|
338
2020
|
{
|
|
339
|
-
pattern: RegExp(/(\bimport\s+)/.source +
|
|
340
|
-
lookbehind:
|
|
2021
|
+
pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
|
|
2022
|
+
lookbehind: true,
|
|
341
2023
|
inside: {
|
|
342
|
-
namespace:
|
|
343
|
-
punctuation: /\./,
|
|
344
|
-
operator: /\*/,
|
|
2024
|
+
"namespace": className.inside.namespace,
|
|
2025
|
+
"punctuation": /\./,
|
|
2026
|
+
"operator": /\*/,
|
|
345
2027
|
"class-name": /\w+/
|
|
346
2028
|
}
|
|
347
2029
|
},
|
|
348
2030
|
{
|
|
349
|
-
pattern: RegExp(/(\bimport\s+static\s+)/.source +
|
|
350
|
-
lookbehind:
|
|
2031
|
+
pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
|
|
2032
|
+
lookbehind: true,
|
|
351
2033
|
alias: "static",
|
|
352
2034
|
inside: {
|
|
353
|
-
namespace:
|
|
354
|
-
static: /\b\w+$/,
|
|
355
|
-
punctuation: /\./,
|
|
356
|
-
operator: /\*/,
|
|
2035
|
+
"namespace": className.inside.namespace,
|
|
2036
|
+
"static": /\b\w+$/,
|
|
2037
|
+
"punctuation": /\./,
|
|
2038
|
+
"operator": /\*/,
|
|
357
2039
|
"class-name": /\w+/
|
|
358
2040
|
}
|
|
359
2041
|
}
|
|
360
2042
|
],
|
|
361
|
-
namespace: {
|
|
2043
|
+
"namespace": {
|
|
362
2044
|
pattern: RegExp(
|
|
363
2045
|
/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/.source.replace(/<keyword>/g, function() {
|
|
364
|
-
return
|
|
2046
|
+
return keywords.source;
|
|
365
2047
|
})
|
|
366
2048
|
),
|
|
367
|
-
lookbehind:
|
|
2049
|
+
lookbehind: true,
|
|
368
2050
|
inside: {
|
|
369
|
-
punctuation: /\./
|
|
2051
|
+
"punctuation": /\./
|
|
370
2052
|
}
|
|
371
2053
|
}
|
|
372
2054
|
});
|
|
373
2055
|
})(Prism);
|
|
374
2056
|
Prism.languages.c = Prism.languages.extend("clike", {
|
|
375
|
-
comment: {
|
|
2057
|
+
"comment": {
|
|
376
2058
|
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
|
|
377
|
-
greedy:
|
|
2059
|
+
greedy: true
|
|
378
2060
|
},
|
|
379
|
-
string: {
|
|
2061
|
+
"string": {
|
|
380
2062
|
// https://en.cppreference.com/w/c/language/string_literal
|
|
381
2063
|
pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
|
|
382
|
-
greedy:
|
|
2064
|
+
greedy: true
|
|
383
2065
|
},
|
|
384
2066
|
"class-name": {
|
|
385
2067
|
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
|
|
386
|
-
lookbehind:
|
|
2068
|
+
lookbehind: true
|
|
387
2069
|
},
|
|
388
|
-
keyword: /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
|
|
389
|
-
function: /\b[a-z_]\w*(?=\s*\()/i,
|
|
390
|
-
number: /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
|
391
|
-
operator: />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
|
2070
|
+
"keyword": /\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,
|
|
2071
|
+
"function": /\b[a-z_]\w*(?=\s*\()/i,
|
|
2072
|
+
"number": /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
|
2073
|
+
"operator": />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
|
392
2074
|
});
|
|
393
2075
|
Prism.languages.insertBefore("c", "string", {
|
|
394
|
-
char: {
|
|
2076
|
+
"char": {
|
|
395
2077
|
// https://en.cppreference.com/w/c/language/character_constant
|
|
396
2078
|
pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
|
|
397
|
-
greedy:
|
|
2079
|
+
greedy: true
|
|
398
2080
|
}
|
|
399
2081
|
});
|
|
400
2082
|
Prism.languages.insertBefore("c", "string", {
|
|
401
|
-
macro: {
|
|
2083
|
+
"macro": {
|
|
402
2084
|
// allow for multiline macro definitions
|
|
403
2085
|
// spaces after the # character compile fine with gcc
|
|
404
2086
|
pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
|
|
405
|
-
lookbehind:
|
|
406
|
-
greedy:
|
|
2087
|
+
lookbehind: true,
|
|
2088
|
+
greedy: true,
|
|
407
2089
|
alias: "property",
|
|
408
2090
|
inside: {
|
|
409
|
-
string: [
|
|
2091
|
+
"string": [
|
|
410
2092
|
{
|
|
411
2093
|
// highlight the path of the include statement as a string
|
|
412
2094
|
pattern: /^(#\s*include\s*)<[^>]+>/,
|
|
413
|
-
lookbehind:
|
|
2095
|
+
lookbehind: true
|
|
414
2096
|
},
|
|
415
|
-
Prism.languages.c
|
|
2097
|
+
Prism.languages.c["string"]
|
|
416
2098
|
],
|
|
417
|
-
char: Prism.languages.c
|
|
418
|
-
comment: Prism.languages.c
|
|
2099
|
+
"char": Prism.languages.c["char"],
|
|
2100
|
+
"comment": Prism.languages.c["comment"],
|
|
419
2101
|
"macro-name": [
|
|
420
2102
|
{
|
|
421
2103
|
pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
|
|
422
|
-
lookbehind:
|
|
2104
|
+
lookbehind: true
|
|
423
2105
|
},
|
|
424
2106
|
{
|
|
425
2107
|
pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
|
|
426
|
-
lookbehind:
|
|
2108
|
+
lookbehind: true,
|
|
427
2109
|
alias: "function"
|
|
428
2110
|
}
|
|
429
2111
|
],
|
|
430
2112
|
// highlight macro directives as keywords
|
|
431
|
-
directive: {
|
|
2113
|
+
"directive": {
|
|
432
2114
|
pattern: /^(#\s*)[a-z]+/,
|
|
433
|
-
lookbehind:
|
|
2115
|
+
lookbehind: true,
|
|
434
2116
|
alias: "keyword"
|
|
435
2117
|
},
|
|
436
2118
|
"directive-hash": /^#/,
|
|
437
|
-
punctuation: /##|\\(?=[\r\n])/,
|
|
438
|
-
expression: {
|
|
2119
|
+
"punctuation": /##|\\(?=[\r\n])/,
|
|
2120
|
+
"expression": {
|
|
439
2121
|
pattern: /\S[\s\S]*/,
|
|
440
2122
|
inside: Prism.languages.c
|
|
441
2123
|
}
|
|
@@ -444,51 +2126,54 @@ Prism.languages.insertBefore("c", "string", {
|
|
|
444
2126
|
});
|
|
445
2127
|
Prism.languages.insertBefore("c", "function", {
|
|
446
2128
|
// highlight predefined macros as constants
|
|
447
|
-
constant: /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
|
2129
|
+
"constant": /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
|
448
2130
|
});
|
|
449
|
-
delete Prism.languages.c
|
|
450
|
-
(function(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
2131
|
+
delete Prism.languages.c["boolean"];
|
|
2132
|
+
(function(Prism2) {
|
|
2133
|
+
var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
|
|
2134
|
+
for (var i = 0; i < 2; i++) {
|
|
2135
|
+
multilineComment = multilineComment.replace(/<self>/g, function() {
|
|
2136
|
+
return multilineComment;
|
|
454
2137
|
});
|
|
455
|
-
|
|
2138
|
+
}
|
|
2139
|
+
multilineComment = multilineComment.replace(/<self>/g, function() {
|
|
456
2140
|
return /[^\s\S]/.source;
|
|
457
|
-
})
|
|
458
|
-
|
|
2141
|
+
});
|
|
2142
|
+
Prism2.languages.rust = {
|
|
2143
|
+
"comment": [
|
|
459
2144
|
{
|
|
460
|
-
pattern: RegExp(/(^|[^\\])/.source +
|
|
461
|
-
lookbehind:
|
|
462
|
-
greedy:
|
|
2145
|
+
pattern: RegExp(/(^|[^\\])/.source + multilineComment),
|
|
2146
|
+
lookbehind: true,
|
|
2147
|
+
greedy: true
|
|
463
2148
|
},
|
|
464
2149
|
{
|
|
465
2150
|
pattern: /(^|[^\\:])\/\/.*/,
|
|
466
|
-
lookbehind:
|
|
467
|
-
greedy:
|
|
2151
|
+
lookbehind: true,
|
|
2152
|
+
greedy: true
|
|
468
2153
|
}
|
|
469
2154
|
],
|
|
470
|
-
string: {
|
|
2155
|
+
"string": {
|
|
471
2156
|
pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
|
|
472
|
-
greedy:
|
|
2157
|
+
greedy: true
|
|
473
2158
|
},
|
|
474
|
-
char: {
|
|
2159
|
+
"char": {
|
|
475
2160
|
pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
|
|
476
|
-
greedy:
|
|
2161
|
+
greedy: true
|
|
477
2162
|
},
|
|
478
|
-
attribute: {
|
|
2163
|
+
"attribute": {
|
|
479
2164
|
pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
|
|
480
|
-
greedy:
|
|
2165
|
+
greedy: true,
|
|
481
2166
|
alias: "attr-name",
|
|
482
2167
|
inside: {
|
|
483
|
-
string: null
|
|
2168
|
+
"string": null
|
|
484
2169
|
// see below
|
|
485
2170
|
}
|
|
486
2171
|
},
|
|
487
2172
|
// Closure params should not be confused with bitwise OR |
|
|
488
2173
|
"closure-params": {
|
|
489
2174
|
pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
|
|
490
|
-
lookbehind:
|
|
491
|
-
greedy:
|
|
2175
|
+
lookbehind: true,
|
|
2176
|
+
greedy: true,
|
|
492
2177
|
inside: {
|
|
493
2178
|
"closure-punctuation": {
|
|
494
2179
|
pattern: /^\||\|$/,
|
|
@@ -504,36 +2189,36 @@ delete Prism.languages.c.boolean;
|
|
|
504
2189
|
},
|
|
505
2190
|
"fragment-specifier": {
|
|
506
2191
|
pattern: /(\$\w+:)[a-z]+/,
|
|
507
|
-
lookbehind:
|
|
2192
|
+
lookbehind: true,
|
|
508
2193
|
alias: "punctuation"
|
|
509
2194
|
},
|
|
510
|
-
variable: /\$\w+/,
|
|
2195
|
+
"variable": /\$\w+/,
|
|
511
2196
|
"function-definition": {
|
|
512
2197
|
pattern: /(\bfn\s+)\w+/,
|
|
513
|
-
lookbehind:
|
|
2198
|
+
lookbehind: true,
|
|
514
2199
|
alias: "function"
|
|
515
2200
|
},
|
|
516
2201
|
"type-definition": {
|
|
517
2202
|
pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
|
|
518
|
-
lookbehind:
|
|
2203
|
+
lookbehind: true,
|
|
519
2204
|
alias: "class-name"
|
|
520
2205
|
},
|
|
521
2206
|
"module-declaration": [
|
|
522
2207
|
{
|
|
523
2208
|
pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
|
|
524
|
-
lookbehind:
|
|
2209
|
+
lookbehind: true,
|
|
525
2210
|
alias: "namespace"
|
|
526
2211
|
},
|
|
527
2212
|
{
|
|
528
2213
|
pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
|
|
529
|
-
lookbehind:
|
|
2214
|
+
lookbehind: true,
|
|
530
2215
|
alias: "namespace",
|
|
531
2216
|
inside: {
|
|
532
|
-
punctuation: /::/
|
|
2217
|
+
"punctuation": /::/
|
|
533
2218
|
}
|
|
534
2219
|
}
|
|
535
2220
|
],
|
|
536
|
-
keyword: [
|
|
2221
|
+
"keyword": [
|
|
537
2222
|
// https://github.com/rust-lang/reference/blob/master/src/keywords.md
|
|
538
2223
|
/\b(?:Self|abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
|
|
539
2224
|
// primitives and str
|
|
@@ -543,112 +2228,116 @@ delete Prism.languages.c.boolean;
|
|
|
543
2228
|
// functions can technically start with an upper-case letter, but this will introduce a lot of false positives
|
|
544
2229
|
// and Rust's naming conventions recommend snake_case anyway.
|
|
545
2230
|
// https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
|
|
546
|
-
function: /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
|
|
547
|
-
macro: {
|
|
2231
|
+
"function": /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
|
|
2232
|
+
"macro": {
|
|
548
2233
|
pattern: /\b\w+!/,
|
|
549
2234
|
alias: "property"
|
|
550
2235
|
},
|
|
551
|
-
constant: /\b[A-Z_][A-Z_\d]+\b/,
|
|
2236
|
+
"constant": /\b[A-Z_][A-Z_\d]+\b/,
|
|
552
2237
|
"class-name": /\b[A-Z]\w*\b/,
|
|
553
|
-
namespace: {
|
|
2238
|
+
"namespace": {
|
|
554
2239
|
pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
|
|
555
2240
|
inside: {
|
|
556
|
-
punctuation: /::/
|
|
2241
|
+
"punctuation": /::/
|
|
557
2242
|
}
|
|
558
2243
|
},
|
|
559
2244
|
// Hex, oct, bin, dec numbers with visual separators and type suffix
|
|
560
|
-
number: /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,
|
|
561
|
-
boolean: /\b(?:false|true)\b/,
|
|
562
|
-
punctuation: /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
|
|
563
|
-
operator: /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
|
|
564
|
-
}
|
|
2245
|
+
"number": /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,
|
|
2246
|
+
"boolean": /\b(?:false|true)\b/,
|
|
2247
|
+
"punctuation": /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
|
|
2248
|
+
"operator": /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
|
|
2249
|
+
};
|
|
2250
|
+
Prism2.languages.rust["closure-params"].inside.rest = Prism2.languages.rust;
|
|
2251
|
+
Prism2.languages.rust["attribute"].inside["string"] = Prism2.languages.rust["string"];
|
|
565
2252
|
})(Prism);
|
|
566
2253
|
Prism.languages.sql = {
|
|
567
|
-
comment: {
|
|
2254
|
+
"comment": {
|
|
568
2255
|
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
|
|
569
|
-
lookbehind:
|
|
2256
|
+
lookbehind: true
|
|
570
2257
|
},
|
|
571
|
-
variable: [
|
|
2258
|
+
"variable": [
|
|
572
2259
|
{
|
|
573
2260
|
pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
|
|
574
|
-
greedy:
|
|
2261
|
+
greedy: true
|
|
575
2262
|
},
|
|
576
2263
|
/@[\w.$]+/
|
|
577
2264
|
],
|
|
578
|
-
string: {
|
|
2265
|
+
"string": {
|
|
579
2266
|
pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
|
|
580
|
-
greedy:
|
|
581
|
-
lookbehind:
|
|
2267
|
+
greedy: true,
|
|
2268
|
+
lookbehind: true
|
|
582
2269
|
},
|
|
583
|
-
identifier: {
|
|
2270
|
+
"identifier": {
|
|
584
2271
|
pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
|
|
585
|
-
greedy:
|
|
586
|
-
lookbehind:
|
|
2272
|
+
greedy: true,
|
|
2273
|
+
lookbehind: true,
|
|
587
2274
|
inside: {
|
|
588
|
-
punctuation: /^`|`$/
|
|
2275
|
+
"punctuation": /^`|`$/
|
|
589
2276
|
}
|
|
590
2277
|
},
|
|
591
|
-
function: /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,
|
|
2278
|
+
"function": /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,
|
|
592
2279
|
// Should we highlight user defined functions too?
|
|
593
|
-
keyword: /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
|
|
594
|
-
boolean: /\b(?:FALSE|NULL|TRUE)\b/i,
|
|
595
|
-
number: /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
|
|
596
|
-
operator: /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
|
|
597
|
-
punctuation: /[;[\]()`,.]/
|
|
2280
|
+
"keyword": /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
|
|
2281
|
+
"boolean": /\b(?:FALSE|NULL|TRUE)\b/i,
|
|
2282
|
+
"number": /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
|
|
2283
|
+
"operator": /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
|
|
2284
|
+
"punctuation": /[;[\]()`,.]/
|
|
598
2285
|
};
|
|
599
|
-
(function(
|
|
600
|
-
var
|
|
2286
|
+
(function(Prism2) {
|
|
2287
|
+
var envVars = "\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b";
|
|
2288
|
+
var commandAfterHeredoc = {
|
|
601
2289
|
pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
|
|
602
|
-
lookbehind:
|
|
2290
|
+
lookbehind: true,
|
|
603
2291
|
alias: "punctuation",
|
|
604
2292
|
// this looks reasonably well in all themes
|
|
605
2293
|
inside: null
|
|
606
2294
|
// see below
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
2295
|
+
};
|
|
2296
|
+
var insideString = {
|
|
2297
|
+
"bash": commandAfterHeredoc,
|
|
2298
|
+
"environment": {
|
|
2299
|
+
pattern: RegExp("\\$" + envVars),
|
|
611
2300
|
alias: "constant"
|
|
612
2301
|
},
|
|
613
|
-
variable: [
|
|
2302
|
+
"variable": [
|
|
614
2303
|
// [0]: Arithmetic Environment
|
|
615
2304
|
{
|
|
616
2305
|
pattern: /\$?\(\([\s\S]+?\)\)/,
|
|
617
|
-
greedy:
|
|
2306
|
+
greedy: true,
|
|
618
2307
|
inside: {
|
|
619
2308
|
// If there is a $ sign at the beginning highlight $(( and )) as variable
|
|
620
|
-
variable: [
|
|
2309
|
+
"variable": [
|
|
621
2310
|
{
|
|
622
2311
|
pattern: /(^\$\(\([\s\S]+)\)\)/,
|
|
623
|
-
lookbehind:
|
|
2312
|
+
lookbehind: true
|
|
624
2313
|
},
|
|
625
2314
|
/^\$\(\(/
|
|
626
2315
|
],
|
|
627
|
-
number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
|
|
2316
|
+
"number": /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
|
|
628
2317
|
// Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
|
|
629
|
-
operator: /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
|
|
2318
|
+
"operator": /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
|
|
630
2319
|
// If there is no $ sign at the beginning highlight (( and )) as punctuation
|
|
631
|
-
punctuation: /\(\(?|\)\)?|,|;/
|
|
2320
|
+
"punctuation": /\(\(?|\)\)?|,|;/
|
|
632
2321
|
}
|
|
633
2322
|
},
|
|
634
2323
|
// [1]: Command Substitution
|
|
635
2324
|
{
|
|
636
2325
|
pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
|
|
637
|
-
greedy:
|
|
2326
|
+
greedy: true,
|
|
638
2327
|
inside: {
|
|
639
|
-
variable: /^\$\(|^`|\)$|`$/
|
|
2328
|
+
"variable": /^\$\(|^`|\)$|`$/
|
|
640
2329
|
}
|
|
641
2330
|
},
|
|
642
2331
|
// [2]: Brace expansion
|
|
643
2332
|
{
|
|
644
2333
|
pattern: /\$\{[^}]+\}/,
|
|
645
|
-
greedy:
|
|
2334
|
+
greedy: true,
|
|
646
2335
|
inside: {
|
|
647
|
-
operator: /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
|
|
648
|
-
punctuation: /[\[\]]/,
|
|
649
|
-
environment: {
|
|
650
|
-
pattern: RegExp("(\\{)" +
|
|
651
|
-
lookbehind:
|
|
2336
|
+
"operator": /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
|
|
2337
|
+
"punctuation": /[\[\]]/,
|
|
2338
|
+
"environment": {
|
|
2339
|
+
pattern: RegExp("(\\{)" + envVars),
|
|
2340
|
+
lookbehind: true,
|
|
652
2341
|
alias: "constant"
|
|
653
2342
|
}
|
|
654
2343
|
}
|
|
@@ -656,16 +2345,16 @@ Prism.languages.sql = {
|
|
|
656
2345
|
/\$(?:\w+|[#?*!@$])/
|
|
657
2346
|
],
|
|
658
2347
|
// Escape sequences from echo and printf's manuals, and escaped quotes.
|
|
659
|
-
entity: /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/
|
|
2348
|
+
"entity": /\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|U[0-9a-fA-F]{8}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{1,2})/
|
|
660
2349
|
};
|
|
661
|
-
|
|
662
|
-
shebang: {
|
|
2350
|
+
Prism2.languages.bash = {
|
|
2351
|
+
"shebang": {
|
|
663
2352
|
pattern: /^#!\s*\/.*/,
|
|
664
2353
|
alias: "important"
|
|
665
2354
|
},
|
|
666
|
-
comment: {
|
|
2355
|
+
"comment": {
|
|
667
2356
|
pattern: /(^|[^"{\\$])#.*/,
|
|
668
|
-
lookbehind:
|
|
2357
|
+
lookbehind: true
|
|
669
2358
|
},
|
|
670
2359
|
"function-name": [
|
|
671
2360
|
// a) function foo {
|
|
@@ -675,7 +2364,7 @@ Prism.languages.sql = {
|
|
|
675
2364
|
{
|
|
676
2365
|
// a) and c)
|
|
677
2366
|
pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
|
|
678
|
-
lookbehind:
|
|
2367
|
+
lookbehind: true,
|
|
679
2368
|
alias: "function"
|
|
680
2369
|
},
|
|
681
2370
|
{
|
|
@@ -688,98 +2377,98 @@ Prism.languages.sql = {
|
|
|
688
2377
|
"for-or-select": {
|
|
689
2378
|
pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
|
|
690
2379
|
alias: "variable",
|
|
691
|
-
lookbehind:
|
|
2380
|
+
lookbehind: true
|
|
692
2381
|
},
|
|
693
2382
|
// Highlight variable names as variables in the left-hand part
|
|
694
2383
|
// of assignments (“=” and “+=”).
|
|
695
2384
|
"assign-left": {
|
|
696
2385
|
pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,
|
|
697
2386
|
inside: {
|
|
698
|
-
environment: {
|
|
699
|
-
pattern: RegExp("(^|[\\s;|&]|[<>]\\()" +
|
|
700
|
-
lookbehind:
|
|
2387
|
+
"environment": {
|
|
2388
|
+
pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars),
|
|
2389
|
+
lookbehind: true,
|
|
701
2390
|
alias: "constant"
|
|
702
2391
|
}
|
|
703
2392
|
},
|
|
704
2393
|
alias: "variable",
|
|
705
|
-
lookbehind:
|
|
2394
|
+
lookbehind: true
|
|
706
2395
|
},
|
|
707
2396
|
// Highlight parameter names as variables
|
|
708
|
-
parameter: {
|
|
2397
|
+
"parameter": {
|
|
709
2398
|
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
|
|
710
2399
|
alias: "variable",
|
|
711
|
-
lookbehind:
|
|
2400
|
+
lookbehind: true
|
|
712
2401
|
},
|
|
713
|
-
string: [
|
|
2402
|
+
"string": [
|
|
714
2403
|
// Support for Here-documents https://en.wikipedia.org/wiki/Here_document
|
|
715
2404
|
{
|
|
716
2405
|
pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
|
|
717
|
-
lookbehind:
|
|
718
|
-
greedy:
|
|
719
|
-
inside:
|
|
2406
|
+
lookbehind: true,
|
|
2407
|
+
greedy: true,
|
|
2408
|
+
inside: insideString
|
|
720
2409
|
},
|
|
721
2410
|
// Here-document with quotes around the tag
|
|
722
2411
|
// → No expansion (so no “inside”).
|
|
723
2412
|
{
|
|
724
2413
|
pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
|
|
725
|
-
lookbehind:
|
|
726
|
-
greedy:
|
|
2414
|
+
lookbehind: true,
|
|
2415
|
+
greedy: true,
|
|
727
2416
|
inside: {
|
|
728
|
-
bash:
|
|
2417
|
+
"bash": commandAfterHeredoc
|
|
729
2418
|
}
|
|
730
2419
|
},
|
|
731
2420
|
// “Normal” string
|
|
732
2421
|
{
|
|
733
2422
|
// https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
|
|
734
2423
|
pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
|
|
735
|
-
lookbehind:
|
|
736
|
-
greedy:
|
|
737
|
-
inside:
|
|
2424
|
+
lookbehind: true,
|
|
2425
|
+
greedy: true,
|
|
2426
|
+
inside: insideString
|
|
738
2427
|
},
|
|
739
2428
|
{
|
|
740
2429
|
// https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
|
|
741
2430
|
pattern: /(^|[^$\\])'[^']*'/,
|
|
742
|
-
lookbehind:
|
|
743
|
-
greedy:
|
|
2431
|
+
lookbehind: true,
|
|
2432
|
+
greedy: true
|
|
744
2433
|
},
|
|
745
2434
|
{
|
|
746
2435
|
// https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
|
|
747
2436
|
pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
|
|
748
|
-
greedy:
|
|
2437
|
+
greedy: true,
|
|
749
2438
|
inside: {
|
|
750
|
-
entity:
|
|
2439
|
+
"entity": insideString.entity
|
|
751
2440
|
}
|
|
752
2441
|
}
|
|
753
2442
|
],
|
|
754
|
-
environment: {
|
|
755
|
-
pattern: RegExp("\\$?" +
|
|
2443
|
+
"environment": {
|
|
2444
|
+
pattern: RegExp("\\$?" + envVars),
|
|
756
2445
|
alias: "constant"
|
|
757
2446
|
},
|
|
758
|
-
variable:
|
|
759
|
-
function: {
|
|
2447
|
+
"variable": insideString.variable,
|
|
2448
|
+
"function": {
|
|
760
2449
|
pattern: /(^|[\s;|&]|[<>]\()(?:add|apropos|apt|apt-cache|apt-get|aptitude|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cargo|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|docker|docker-compose|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|java|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|node|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|podman|podman-compose|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|sysctl|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vcpkg|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,
|
|
761
|
-
lookbehind:
|
|
2450
|
+
lookbehind: true
|
|
762
2451
|
},
|
|
763
|
-
keyword: {
|
|
2452
|
+
"keyword": {
|
|
764
2453
|
pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,
|
|
765
|
-
lookbehind:
|
|
2454
|
+
lookbehind: true
|
|
766
2455
|
},
|
|
767
2456
|
// https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
|
|
768
|
-
builtin: {
|
|
2457
|
+
"builtin": {
|
|
769
2458
|
pattern: /(^|[\s;|&]|[<>]\()(?:\.|:|alias|bind|break|builtin|caller|cd|command|continue|declare|echo|enable|eval|exec|exit|export|getopts|hash|help|let|local|logout|mapfile|printf|pwd|read|readarray|readonly|return|set|shift|shopt|source|test|times|trap|type|typeset|ulimit|umask|unalias|unset)(?=$|[)\s;|&])/,
|
|
770
|
-
lookbehind:
|
|
2459
|
+
lookbehind: true,
|
|
771
2460
|
// Alias added to make those easier to distinguish from strings.
|
|
772
2461
|
alias: "class-name"
|
|
773
2462
|
},
|
|
774
|
-
boolean: {
|
|
2463
|
+
"boolean": {
|
|
775
2464
|
pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,
|
|
776
|
-
lookbehind:
|
|
2465
|
+
lookbehind: true
|
|
777
2466
|
},
|
|
778
2467
|
"file-descriptor": {
|
|
779
2468
|
pattern: /\B&\d\b/,
|
|
780
2469
|
alias: "important"
|
|
781
2470
|
},
|
|
782
|
-
operator: {
|
|
2471
|
+
"operator": {
|
|
783
2472
|
// Lots of redirections here, but not just that.
|
|
784
2473
|
pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
|
|
785
2474
|
inside: {
|
|
@@ -789,13 +2478,14 @@ Prism.languages.sql = {
|
|
|
789
2478
|
}
|
|
790
2479
|
}
|
|
791
2480
|
},
|
|
792
|
-
punctuation: /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
|
|
793
|
-
number: {
|
|
2481
|
+
"punctuation": /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
|
|
2482
|
+
"number": {
|
|
794
2483
|
pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
|
|
795
|
-
lookbehind:
|
|
2484
|
+
lookbehind: true
|
|
796
2485
|
}
|
|
797
|
-
}
|
|
798
|
-
|
|
2486
|
+
};
|
|
2487
|
+
commandAfterHeredoc.inside = Prism2.languages.bash;
|
|
2488
|
+
var toBeCopied = [
|
|
799
2489
|
"comment",
|
|
800
2490
|
"function-name",
|
|
801
2491
|
"for-or-select",
|
|
@@ -811,36 +2501,40 @@ Prism.languages.sql = {
|
|
|
811
2501
|
"operator",
|
|
812
2502
|
"punctuation",
|
|
813
2503
|
"number"
|
|
814
|
-
]
|
|
815
|
-
|
|
816
|
-
|
|
2504
|
+
];
|
|
2505
|
+
var inside = insideString.variable[1].inside;
|
|
2506
|
+
for (var i = 0; i < toBeCopied.length; i++) {
|
|
2507
|
+
inside[toBeCopied[i]] = Prism2.languages.bash[toBeCopied[i]];
|
|
2508
|
+
}
|
|
2509
|
+
Prism2.languages.sh = Prism2.languages.bash;
|
|
2510
|
+
Prism2.languages.shell = Prism2.languages.bash;
|
|
817
2511
|
})(Prism);
|
|
818
2512
|
Prism.languages.json = {
|
|
819
|
-
property: {
|
|
2513
|
+
"property": {
|
|
820
2514
|
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
|
|
821
|
-
lookbehind:
|
|
822
|
-
greedy:
|
|
2515
|
+
lookbehind: true,
|
|
2516
|
+
greedy: true
|
|
823
2517
|
},
|
|
824
|
-
string: {
|
|
2518
|
+
"string": {
|
|
825
2519
|
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
|
|
826
|
-
lookbehind:
|
|
827
|
-
greedy:
|
|
2520
|
+
lookbehind: true,
|
|
2521
|
+
greedy: true
|
|
828
2522
|
},
|
|
829
|
-
comment: {
|
|
2523
|
+
"comment": {
|
|
830
2524
|
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
|
|
831
|
-
greedy:
|
|
2525
|
+
greedy: true
|
|
832
2526
|
},
|
|
833
|
-
number: /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
|
|
834
|
-
punctuation: /[{}[\],]/,
|
|
835
|
-
operator: /:/,
|
|
836
|
-
boolean: /\b(?:false|true)\b/,
|
|
837
|
-
null: {
|
|
2527
|
+
"number": /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
|
|
2528
|
+
"punctuation": /[{}[\],]/,
|
|
2529
|
+
"operator": /:/,
|
|
2530
|
+
"boolean": /\b(?:false|true)\b/,
|
|
2531
|
+
"null": {
|
|
838
2532
|
pattern: /\bnull\b/,
|
|
839
2533
|
alias: "keyword"
|
|
840
2534
|
}
|
|
841
2535
|
};
|
|
842
2536
|
Prism.languages.webmanifest = Prism.languages.json;
|
|
843
|
-
const
|
|
2537
|
+
const prismDarkTheme = `
|
|
844
2538
|
/* 默认代码颜色 */
|
|
845
2539
|
.hep-cr-editor .hep-cr-highlight code,
|
|
846
2540
|
.hep-cr-editor .hep-cr-highlight pre {
|
|
@@ -924,7 +2618,8 @@ const b = `
|
|
|
924
2618
|
.hep-cr-editor .token.console {
|
|
925
2619
|
color: #f8f8f2 !important;
|
|
926
2620
|
}
|
|
927
|
-
|
|
2621
|
+
`;
|
|
2622
|
+
const prismLightTheme = `
|
|
928
2623
|
/* 默认代码颜色 */
|
|
929
2624
|
.hep-cr-editor .hep-cr-highlight code,
|
|
930
2625
|
.hep-cr-editor .hep-cr-highlight pre {
|
|
@@ -1002,15 +2697,25 @@ const b = `
|
|
|
1002
2697
|
color: #333 !important;
|
|
1003
2698
|
}
|
|
1004
2699
|
`;
|
|
1005
|
-
function
|
|
1006
|
-
var
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
options
|
|
2700
|
+
function normalizeComponent(scriptExports, render4, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
|
2701
|
+
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
|
|
2702
|
+
if (render4) {
|
|
2703
|
+
options.render = render4;
|
|
2704
|
+
options.staticRenderFns = staticRenderFns;
|
|
2705
|
+
options._compiled = true;
|
|
2706
|
+
}
|
|
2707
|
+
if (scopeId) {
|
|
2708
|
+
options._scopeId = "data-v-" + scopeId;
|
|
2709
|
+
}
|
|
2710
|
+
return {
|
|
2711
|
+
exports: scriptExports,
|
|
2712
|
+
options
|
|
1010
2713
|
};
|
|
1011
2714
|
}
|
|
1012
|
-
typeof window
|
|
1013
|
-
|
|
2715
|
+
if (typeof window !== "undefined") {
|
|
2716
|
+
window.Prism = Prism$1;
|
|
2717
|
+
}
|
|
2718
|
+
const _sfc_main$2 = {
|
|
1014
2719
|
name: "CodeEditor",
|
|
1015
2720
|
props: {
|
|
1016
2721
|
value: {
|
|
@@ -1027,7 +2732,7 @@ const T = {
|
|
|
1027
2732
|
},
|
|
1028
2733
|
disabled: {
|
|
1029
2734
|
type: Boolean,
|
|
1030
|
-
default:
|
|
2735
|
+
default: false
|
|
1031
2736
|
}
|
|
1032
2737
|
},
|
|
1033
2738
|
data: function() {
|
|
@@ -1040,8 +2745,8 @@ const T = {
|
|
|
1040
2745
|
this.loadPrismTheme(this.theme);
|
|
1041
2746
|
},
|
|
1042
2747
|
watch: {
|
|
1043
|
-
theme(
|
|
1044
|
-
this.loadPrismTheme(
|
|
2748
|
+
theme(newTheme) {
|
|
2749
|
+
this.loadPrismTheme(newTheme);
|
|
1045
2750
|
}
|
|
1046
2751
|
},
|
|
1047
2752
|
computed: {
|
|
@@ -1087,69 +2792,97 @@ const T = {
|
|
|
1087
2792
|
},
|
|
1088
2793
|
highlightedCode: function() {
|
|
1089
2794
|
try {
|
|
1090
|
-
var
|
|
1091
|
-
if (
|
|
1092
|
-
return
|
|
2795
|
+
var grammar = Prism$1.languages[this.prismLanguage];
|
|
2796
|
+
if (grammar) {
|
|
2797
|
+
return Prism$1.highlight(
|
|
1093
2798
|
this.value || "",
|
|
1094
|
-
|
|
2799
|
+
grammar,
|
|
1095
2800
|
this.prismLanguage
|
|
1096
2801
|
);
|
|
1097
|
-
|
|
2802
|
+
}
|
|
2803
|
+
} catch (e) {
|
|
1098
2804
|
}
|
|
1099
2805
|
return this.escapeHtml(this.value || "");
|
|
1100
2806
|
}
|
|
1101
2807
|
},
|
|
1102
2808
|
methods: {
|
|
1103
|
-
loadPrismTheme(
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
},
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
2809
|
+
loadPrismTheme(theme) {
|
|
2810
|
+
const styleId = "hep-cr-prism-styles";
|
|
2811
|
+
const oldStyleEl = document.getElementById(styleId);
|
|
2812
|
+
const themeContent = theme === "dark" ? prismDarkTheme : prismLightTheme;
|
|
2813
|
+
if (oldStyleEl) {
|
|
2814
|
+
oldStyleEl.remove();
|
|
2815
|
+
}
|
|
2816
|
+
const styleEl = document.createElement("style");
|
|
2817
|
+
styleEl.id = styleId;
|
|
2818
|
+
styleEl.textContent = themeContent;
|
|
2819
|
+
document.head.appendChild(styleEl);
|
|
2820
|
+
},
|
|
2821
|
+
escapeHtml: function(text) {
|
|
2822
|
+
var div = document.createElement("div");
|
|
2823
|
+
div.textContent = text;
|
|
2824
|
+
return div.innerHTML;
|
|
2825
|
+
},
|
|
2826
|
+
handleInput: function(e) {
|
|
2827
|
+
this.$emit("input", e.target.value);
|
|
2828
|
+
this.$emit("update:value", e.target.value);
|
|
2829
|
+
this.emitChange(e.target.value);
|
|
2830
|
+
},
|
|
2831
|
+
handleScroll: function(e) {
|
|
2832
|
+
var highlight = this.$refs.highlightRef;
|
|
2833
|
+
if (highlight) {
|
|
2834
|
+
highlight.scrollTop = e.target.scrollTop;
|
|
2835
|
+
highlight.scrollLeft = e.target.scrollLeft;
|
|
2836
|
+
}
|
|
2837
|
+
},
|
|
2838
|
+
handleKeydown: function(e) {
|
|
2839
|
+
if (e.key === "Tab") {
|
|
2840
|
+
e.preventDefault();
|
|
2841
|
+
var target = e.target;
|
|
2842
|
+
var start = target.selectionStart;
|
|
2843
|
+
var end = target.selectionEnd;
|
|
2844
|
+
var value = target.value;
|
|
2845
|
+
target.value = value.substring(0, start) + " " + value.substring(end);
|
|
2846
|
+
target.selectionStart = target.selectionEnd = start + 2;
|
|
2847
|
+
this.$emit("input", target.value);
|
|
2848
|
+
this.$emit("update:value", target.value);
|
|
2849
|
+
this.emitChange(target.value);
|
|
1125
2850
|
}
|
|
1126
2851
|
},
|
|
1127
|
-
emitChange: function(
|
|
1128
|
-
var
|
|
1129
|
-
|
|
1130
|
-
|
|
2852
|
+
emitChange: function(value) {
|
|
2853
|
+
var self2 = this;
|
|
2854
|
+
if (self2.changeTimer) {
|
|
2855
|
+
clearTimeout(self2.changeTimer);
|
|
2856
|
+
}
|
|
2857
|
+
self2.changeTimer = setTimeout(function() {
|
|
2858
|
+
self2.$emit("change", value);
|
|
1131
2859
|
}, 500);
|
|
1132
2860
|
}
|
|
1133
2861
|
},
|
|
1134
2862
|
beforeDestroy: function() {
|
|
1135
|
-
|
|
2863
|
+
if (this.changeTimer) {
|
|
2864
|
+
clearTimeout(this.changeTimer);
|
|
2865
|
+
}
|
|
1136
2866
|
}
|
|
1137
2867
|
};
|
|
1138
|
-
var
|
|
1139
|
-
var
|
|
1140
|
-
return
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
2868
|
+
var _sfc_render$2 = function render() {
|
|
2869
|
+
var _vm = this, _c = _vm._self._c;
|
|
2870
|
+
return _c("div", { staticClass: "hep-cr-editor", class: "hep-cr-theme-" + _vm.theme, style: { background: _vm.editorBackground } }, [_c("pre", { ref: "highlightRef", staticClass: "hep-cr-highlight", class: "language-" + _vm.prismLanguage, attrs: { "aria-hidden": "true" } }, [_c("code", { domProps: { "innerHTML": _vm._s(_vm.highlightedCode) } })]), _c("textarea", { staticClass: "hep-cr-input", attrs: { "disabled": _vm.disabled, "spellcheck": "false", "placeholder": "Write your code here..." }, domProps: { "value": _vm.value }, on: { "input": _vm.handleInput, "scroll": _vm.handleScroll, "keydown": _vm.handleKeydown } })]);
|
|
2871
|
+
};
|
|
2872
|
+
var _sfc_staticRenderFns$2 = [];
|
|
2873
|
+
var __component__$2 = /* @__PURE__ */ normalizeComponent(
|
|
2874
|
+
_sfc_main$2,
|
|
2875
|
+
_sfc_render$2,
|
|
2876
|
+
_sfc_staticRenderFns$2,
|
|
2877
|
+
false,
|
|
1146
2878
|
null,
|
|
1147
2879
|
"525880d3"
|
|
1148
2880
|
);
|
|
1149
|
-
const
|
|
2881
|
+
const CodeEditor = __component__$2.exports;
|
|
2882
|
+
const _sfc_main$1 = {
|
|
1150
2883
|
name: "CodeRunner",
|
|
1151
2884
|
components: {
|
|
1152
|
-
CodeEditor
|
|
2885
|
+
CodeEditor
|
|
1153
2886
|
},
|
|
1154
2887
|
props: {
|
|
1155
2888
|
pistonUrl: {
|
|
@@ -1163,8 +2896,8 @@ const k = A.exports, y = {
|
|
|
1163
2896
|
theme: {
|
|
1164
2897
|
type: String,
|
|
1165
2898
|
default: "light",
|
|
1166
|
-
validator: function(
|
|
1167
|
-
return ["light", "dark"].indexOf(
|
|
2899
|
+
validator: function(val) {
|
|
2900
|
+
return ["light", "dark"].indexOf(val) !== -1;
|
|
1168
2901
|
}
|
|
1169
2902
|
},
|
|
1170
2903
|
themeColor: {
|
|
@@ -1173,15 +2906,15 @@ const k = A.exports, y = {
|
|
|
1173
2906
|
},
|
|
1174
2907
|
showLanguageSelector: {
|
|
1175
2908
|
type: Boolean,
|
|
1176
|
-
default:
|
|
2909
|
+
default: true
|
|
1177
2910
|
},
|
|
1178
2911
|
showEditor: {
|
|
1179
2912
|
type: Boolean,
|
|
1180
|
-
default:
|
|
2913
|
+
default: true
|
|
1181
2914
|
},
|
|
1182
2915
|
editable: {
|
|
1183
2916
|
type: Boolean,
|
|
1184
|
-
default:
|
|
2917
|
+
default: true
|
|
1185
2918
|
},
|
|
1186
2919
|
defaultCode: {
|
|
1187
2920
|
type: String,
|
|
@@ -1193,23 +2926,25 @@ const k = A.exports, y = {
|
|
|
1193
2926
|
}
|
|
1194
2927
|
},
|
|
1195
2928
|
data: function() {
|
|
1196
|
-
var
|
|
2929
|
+
var self2 = this;
|
|
2930
|
+
var storedLang = typeof window !== "undefined" ? localStorage.getItem("hep-cr-default-language") || null : null;
|
|
2931
|
+
var defaultLang = storedLang || self2.language || "javascript";
|
|
1197
2932
|
return {
|
|
1198
2933
|
runtimes: [],
|
|
1199
|
-
currentLanguage:
|
|
1200
|
-
currentTheme:
|
|
1201
|
-
code:
|
|
2934
|
+
currentLanguage: defaultLang,
|
|
2935
|
+
currentTheme: self2.theme,
|
|
2936
|
+
code: self2.defaultCode || j(defaultLang.split(":")[0]),
|
|
1202
2937
|
output: "",
|
|
1203
2938
|
stderr: "",
|
|
1204
|
-
isRunning:
|
|
2939
|
+
isRunning: false,
|
|
1205
2940
|
executionTime: null,
|
|
1206
2941
|
activeTab: "stdout",
|
|
1207
2942
|
error: null,
|
|
1208
|
-
runtimesLoading:
|
|
2943
|
+
runtimesLoading: false,
|
|
1209
2944
|
client: null,
|
|
1210
2945
|
editorWidth: 60,
|
|
1211
|
-
copiedEditor:
|
|
1212
|
-
copiedOutput:
|
|
2946
|
+
copiedEditor: false,
|
|
2947
|
+
copiedOutput: false
|
|
1213
2948
|
};
|
|
1214
2949
|
},
|
|
1215
2950
|
computed: {
|
|
@@ -1218,147 +2953,205 @@ const k = A.exports, y = {
|
|
|
1218
2953
|
},
|
|
1219
2954
|
themeStyle: function() {
|
|
1220
2955
|
if (!this.themeColor) return {};
|
|
1221
|
-
var
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
var
|
|
1226
|
-
|
|
1227
|
-
|
|
2956
|
+
var isDark = this.currentTheme === "dark";
|
|
2957
|
+
var color = this.themeColor;
|
|
2958
|
+
var adjustColor = function(hex, percent) {
|
|
2959
|
+
var num = parseInt(hex.replace("#", ""), 16);
|
|
2960
|
+
var amt = Math.round(2.55 * percent);
|
|
2961
|
+
var R = Math.min(255, Math.max(0, (num >> 16) + amt));
|
|
2962
|
+
var G = Math.min(255, Math.max(0, (num >> 8 & 255) + amt));
|
|
2963
|
+
var B = Math.min(255, Math.max(0, (num & 255) + amt));
|
|
2964
|
+
return "#" + (16777216 + R * 65536 + G * 256 + B).toString(16).slice(1);
|
|
2965
|
+
};
|
|
2966
|
+
var isColorLight = function(hex) {
|
|
2967
|
+
var num = parseInt(hex.replace("#", ""), 16);
|
|
2968
|
+
var r = num >> 16 & 255;
|
|
2969
|
+
var g = num >> 8 & 255;
|
|
2970
|
+
var b = num & 255;
|
|
2971
|
+
var luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
2972
|
+
return luminance > 0.5;
|
|
2973
|
+
};
|
|
2974
|
+
var isLightColor = isColorLight(color);
|
|
2975
|
+
var textColor = isLightColor ? "#000" : "#fff";
|
|
1228
2976
|
return {
|
|
1229
|
-
"--hep-cr-theme-color":
|
|
1230
|
-
"--hep-cr-theme-color-hover":
|
|
1231
|
-
"--hep-cr-tab-active-color":
|
|
2977
|
+
"--hep-cr-theme-color": color,
|
|
2978
|
+
"--hep-cr-theme-color-hover": isDark ? adjustColor(color, 20) : adjustColor(color, -20),
|
|
2979
|
+
"--hep-cr-tab-active-color": textColor
|
|
1232
2980
|
};
|
|
1233
2981
|
},
|
|
1234
2982
|
languageOptions: function() {
|
|
1235
|
-
return this.runtimes.map(function(
|
|
2983
|
+
return this.runtimes.map(function(r) {
|
|
1236
2984
|
return {
|
|
1237
|
-
value:
|
|
1238
|
-
label:
|
|
2985
|
+
value: r.language + ":" + r.version,
|
|
2986
|
+
label: r.language.charAt(0).toUpperCase() + r.language.slice(1) + " " + r.version
|
|
1239
2987
|
};
|
|
1240
2988
|
});
|
|
1241
2989
|
},
|
|
1242
2990
|
languageName: function() {
|
|
1243
|
-
var
|
|
1244
|
-
return
|
|
2991
|
+
var lang = this.currentLanguage;
|
|
2992
|
+
return lang.includes(":") ? lang.split(":")[0] : lang;
|
|
1245
2993
|
}
|
|
1246
2994
|
},
|
|
1247
2995
|
watch: {
|
|
1248
|
-
currentLanguage: function(
|
|
1249
|
-
var
|
|
1250
|
-
this.code =
|
|
2996
|
+
currentLanguage: function(newLang) {
|
|
2997
|
+
var langName = newLang.includes(":") ? newLang.split(":")[0] : newLang;
|
|
2998
|
+
this.code = j(langName);
|
|
2999
|
+
this.$emit("language-change", langName, this.code);
|
|
3000
|
+
if (typeof window !== "undefined") {
|
|
3001
|
+
localStorage.setItem("hep-cr-default-language", newLang);
|
|
3002
|
+
}
|
|
1251
3003
|
}
|
|
1252
3004
|
},
|
|
1253
3005
|
mounted: function() {
|
|
1254
|
-
this.client = new
|
|
3006
|
+
this.client = new W({ pistonUrl: this.pistonUrl });
|
|
3007
|
+
this.loadRuntimes();
|
|
3008
|
+
this.$emit("change", this.code);
|
|
1255
3009
|
},
|
|
1256
3010
|
methods: {
|
|
1257
3011
|
getStoredLanguage: function() {
|
|
1258
|
-
|
|
3012
|
+
if (typeof window === "undefined") return this.language;
|
|
3013
|
+
return localStorage.getItem("hep-cr-default-language") || this.language;
|
|
1259
3014
|
},
|
|
1260
3015
|
loadRuntimes: function() {
|
|
1261
|
-
var
|
|
1262
|
-
this.runtimesLoading =
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
3016
|
+
var self2 = this;
|
|
3017
|
+
this.runtimesLoading = true;
|
|
3018
|
+
this.error = null;
|
|
3019
|
+
this.client.getRuntimes().then(function(runtimes) {
|
|
3020
|
+
self2.runtimes = runtimes;
|
|
3021
|
+
var langName = self2.currentLanguage.split(":")[0];
|
|
3022
|
+
var defaultRuntime = runtimes.find(function(r) {
|
|
3023
|
+
return r.language === langName;
|
|
1266
3024
|
});
|
|
1267
|
-
|
|
3025
|
+
if (defaultRuntime && !self2.currentLanguage.includes(":")) {
|
|
3026
|
+
self2.currentLanguage = langName + ":" + defaultRuntime.version;
|
|
3027
|
+
}
|
|
3028
|
+
self2.$emit("language-change", langName, self2.code);
|
|
1268
3029
|
}).catch(function(e) {
|
|
1269
|
-
|
|
3030
|
+
self2.error = e.message || "Failed to load runtimes";
|
|
1270
3031
|
}).finally(function() {
|
|
1271
|
-
|
|
3032
|
+
self2.runtimesLoading = false;
|
|
1272
3033
|
});
|
|
1273
3034
|
},
|
|
1274
3035
|
execute: function() {
|
|
1275
|
-
var
|
|
1276
|
-
|
|
1277
|
-
|
|
3036
|
+
var self2 = this;
|
|
3037
|
+
if (this.isRunning) return;
|
|
3038
|
+
this.isRunning = true;
|
|
3039
|
+
this.output = "";
|
|
3040
|
+
this.stderr = "";
|
|
3041
|
+
this.executionTime = null;
|
|
3042
|
+
this.error = null;
|
|
3043
|
+
this.activeTab = "stdout";
|
|
3044
|
+
this.$emit("execute-start");
|
|
3045
|
+
this.client.execute(this.languageName, this.code).then(function(result) {
|
|
3046
|
+
self2.output = result.output;
|
|
3047
|
+
self2.stderr = result.stderr;
|
|
3048
|
+
self2.executionTime = result.executionTime || null;
|
|
3049
|
+
self2.activeTab = result.stderr ? "stderr" : "stdout";
|
|
3050
|
+
self2.$emit("execute-end", result);
|
|
1278
3051
|
}).catch(function(e) {
|
|
1279
|
-
|
|
1280
|
-
|
|
3052
|
+
self2.error = e.message || "Execution failed";
|
|
3053
|
+
self2.$emit("execute-end", {
|
|
3054
|
+
success: false,
|
|
1281
3055
|
output: "",
|
|
1282
|
-
stderr:
|
|
3056
|
+
stderr: self2.error,
|
|
1283
3057
|
code: -1
|
|
1284
3058
|
});
|
|
1285
3059
|
}).finally(function() {
|
|
1286
|
-
|
|
1287
|
-
})
|
|
3060
|
+
self2.isRunning = false;
|
|
3061
|
+
});
|
|
1288
3062
|
},
|
|
1289
3063
|
clearOutput: function() {
|
|
1290
|
-
this.output = ""
|
|
3064
|
+
this.output = "";
|
|
3065
|
+
this.stderr = "";
|
|
3066
|
+
this.executionTime = null;
|
|
3067
|
+
this.error = null;
|
|
1291
3068
|
},
|
|
1292
3069
|
copyCode: function() {
|
|
1293
|
-
var
|
|
1294
|
-
navigator.clipboard.writeText(this.code)
|
|
1295
|
-
|
|
3070
|
+
var self2 = this;
|
|
3071
|
+
navigator.clipboard.writeText(this.code);
|
|
3072
|
+
this.copiedEditor = true;
|
|
3073
|
+
setTimeout(function() {
|
|
3074
|
+
self2.copiedEditor = false;
|
|
1296
3075
|
}, 2e3);
|
|
1297
3076
|
},
|
|
1298
3077
|
copyOutput: function() {
|
|
1299
|
-
var
|
|
1300
|
-
|
|
1301
|
-
|
|
3078
|
+
var self2 = this;
|
|
3079
|
+
var text = this.activeTab === "stdout" ? this.output : this.stderr;
|
|
3080
|
+
navigator.clipboard.writeText(text);
|
|
3081
|
+
this.copiedOutput = true;
|
|
3082
|
+
setTimeout(function() {
|
|
3083
|
+
self2.copiedOutput = false;
|
|
1302
3084
|
}, 2e3);
|
|
1303
3085
|
},
|
|
1304
3086
|
resetCode: function() {
|
|
1305
|
-
this.code =
|
|
3087
|
+
this.code = j(this.languageName);
|
|
1306
3088
|
},
|
|
1307
3089
|
toggleTheme: function() {
|
|
1308
3090
|
this.currentTheme = this.currentTheme === "light" ? "dark" : "light";
|
|
1309
3091
|
},
|
|
1310
|
-
startDrag: function(
|
|
1311
|
-
var
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
3092
|
+
startDrag: function(e) {
|
|
3093
|
+
var self2 = this;
|
|
3094
|
+
var container = document.querySelector(".hep-cr-runner-main");
|
|
3095
|
+
if (!container) return;
|
|
3096
|
+
var onDrag = function(e2) {
|
|
3097
|
+
var rect = container.getBoundingClientRect();
|
|
3098
|
+
var newWidth = (e2.clientX - rect.left) / rect.width * 100;
|
|
3099
|
+
self2.editorWidth = Math.max(20, Math.min(80, newWidth));
|
|
3100
|
+
};
|
|
3101
|
+
var stopDrag = function() {
|
|
3102
|
+
document.removeEventListener("mousemove", onDrag);
|
|
3103
|
+
document.removeEventListener("mouseup", stopDrag);
|
|
3104
|
+
document.body.style.cursor = "";
|
|
3105
|
+
document.body.style.userSelect = "";
|
|
3106
|
+
};
|
|
3107
|
+
document.addEventListener("mousemove", onDrag);
|
|
3108
|
+
document.addEventListener("mouseup", stopDrag);
|
|
3109
|
+
document.body.style.cursor = "col-resize";
|
|
3110
|
+
document.body.style.userSelect = "none";
|
|
1321
3111
|
}
|
|
1322
3112
|
}
|
|
1323
3113
|
};
|
|
1324
|
-
var
|
|
1325
|
-
var
|
|
1326
|
-
return
|
|
1327
|
-
var
|
|
1328
|
-
return
|
|
1329
|
-
}).map(function(
|
|
1330
|
-
var
|
|
1331
|
-
return
|
|
3114
|
+
var _sfc_render$1 = function render2() {
|
|
3115
|
+
var _vm = this, _c = _vm._self._c;
|
|
3116
|
+
return _c("div", { class: ["hep-cr-runner", _vm.themeClass], style: _vm.themeStyle }, [_c("div", { staticClass: "hep-cr-runner-header" }, [_c("div", { staticClass: "hep-cr-runner-controls" }, [_vm.showLanguageSelector ? _c("select", { directives: [{ name: "model", rawName: "v-model", value: _vm.currentLanguage, expression: "currentLanguage" }], staticClass: "hep-cr-language-select", attrs: { "disabled": _vm.isRunning }, on: { "change": function($event) {
|
|
3117
|
+
var $$selectedVal = Array.prototype.filter.call($event.target.options, function(o) {
|
|
3118
|
+
return o.selected;
|
|
3119
|
+
}).map(function(o) {
|
|
3120
|
+
var val = "_value" in o ? o._value : o.value;
|
|
3121
|
+
return val;
|
|
1332
3122
|
});
|
|
1333
|
-
|
|
1334
|
-
} } }, [
|
|
1335
|
-
return
|
|
1336
|
-
})], 2) :
|
|
1337
|
-
|
|
1338
|
-
}, change: function(
|
|
1339
|
-
return
|
|
1340
|
-
} } })], 1) :
|
|
1341
|
-
|
|
1342
|
-
} } }, [
|
|
1343
|
-
|
|
1344
|
-
} } }, [
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
3123
|
+
_vm.currentLanguage = $event.target.multiple ? $$selectedVal : $$selectedVal[0];
|
|
3124
|
+
} } }, [_vm.runtimesLoading ? _c("option", { attrs: { "value": "" } }, [_vm._v("加载中...")]) : _vm._e(), _vm._l(_vm.languageOptions, function(option) {
|
|
3125
|
+
return _c("option", { key: option.value, domProps: { "value": option.value } }, [_vm._v(" " + _vm._s(option.label) + " ")]);
|
|
3126
|
+
})], 2) : _vm._e()]), _c("div", { staticClass: "hep-cr-runner-actions" }, [_c("button", { staticClass: "hep-cr-btn hep-cr-btn-run", attrs: { "disabled": _vm.isRunning || _vm.runtimesLoading }, on: { "click": _vm.execute } }, [_vm.isRunning ? _c("span", { staticClass: "hep-cr-spinner" }) : _c("span", { staticClass: "hep-cr-run-icon" }, [_vm._v("▶")]), _vm._v(" " + _vm._s(_vm.isRunning ? "运行中..." : _vm.executorLabel) + " ")]), _vm.showEditor && _vm.editable ? _c("button", { staticClass: "hep-cr-btn hep-cr-btn-reset", on: { "click": _vm.resetCode } }, [_vm._v(" 重置 ")]) : _vm._e(), _c("button", { staticClass: "hep-cr-btn hep-cr-btn-theme", attrs: { "title": _vm.currentTheme === "light" ? "Switch to dark mode" : "Switch to light mode" }, on: { "click": _vm.toggleTheme } }, [_vm.currentTheme === "light" ? _c("svg", { attrs: { "width": "16", "height": "16", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" } }, [_c("path", { attrs: { "d": "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" } })]) : _c("svg", { attrs: { "width": "16", "height": "16", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" } }, [_c("circle", { attrs: { "cx": "12", "cy": "12", "r": "5" } }), _c("line", { attrs: { "x1": "12", "y1": "1", "x2": "12", "y2": "3" } }), _c("line", { attrs: { "x1": "12", "y1": "21", "x2": "12", "y2": "23" } }), _c("line", { attrs: { "x1": "4.22", "y1": "4.22", "x2": "5.64", "y2": "5.64" } }), _c("line", { attrs: { "x1": "18.36", "y1": "18.36", "x2": "19.78", "y2": "19.78" } }), _c("line", { attrs: { "x1": "1", "y1": "12", "x2": "3", "y2": "12" } }), _c("line", { attrs: { "x1": "21", "y1": "12", "x2": "23", "y2": "12" } }), _c("line", { attrs: { "x1": "4.22", "y1": "19.78", "x2": "5.64", "y2": "18.36" } }), _c("line", { attrs: { "x1": "18.36", "y1": "5.64", "x2": "19.78", "y2": "4.22" } })])])])]), _vm.error ? _c("div", { staticClass: "hep-cr-error-message" }, [_vm._v(" " + _vm._s(_vm.error) + " ")]) : _vm._e(), _c("div", { staticClass: "hep-cr-runner-main" }, [_vm.showEditor ? _c("div", { staticClass: "hep-cr-editor-panel", style: { width: _vm.editorWidth + "%" } }, [_c("div", { staticClass: "hep-cr-panel-header" }, [_c("span", { staticClass: "hep-cr-panel-title" }, [_vm._v("编辑器")]), _c("div", { staticClass: "hep-cr-output-actions" }, [_c("span", { staticClass: "hep-cr-language-badge" }, [_vm._v(_vm._s(_vm.languageName))]), _c("button", { staticClass: "hep-cr-btn-icon", class: { "hep-cr-btn-copied": _vm.copiedEditor }, attrs: { "disabled": _vm.copiedEditor, "title": _vm.copiedEditor ? "已复制" : "复制" }, on: { "click": _vm.copyCode } }, [!_vm.copiedEditor ? _c("svg", { attrs: { "width": "14", "height": "14", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" } }, [_c("rect", { attrs: { "x": "9", "y": "9", "width": "13", "height": "13", "rx": "2", "ry": "2" } }), _c("path", { attrs: { "d": "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" } })]) : _c("span", { staticClass: "hep-cr-copied-text" }, [_vm._v("已复制")])])])]), _c("CodeEditor", { attrs: { "value": _vm.code, "language": _vm.languageName, "theme": _vm.currentTheme, "disabled": !_vm.editable || _vm.isRunning }, on: { "input": function($event) {
|
|
3127
|
+
_vm.code = $event;
|
|
3128
|
+
}, "change": function($event) {
|
|
3129
|
+
return _vm.$emit("change", $event);
|
|
3130
|
+
} } })], 1) : _vm._e(), _vm.showEditor ? _c("div", { staticClass: "hep-cr-resize-handle", on: { "mousedown": _vm.startDrag } }, [_c("div", { staticClass: "hep-cr-resize-line" })]) : _vm._e(), _c("div", { staticClass: "hep-cr-output-panel", style: { width: _vm.showEditor ? 100 - _vm.editorWidth + "%" : "100%" } }, [_c("div", { staticClass: "hep-cr-panel-header" }, [_c("div", { staticClass: "hep-cr-output-tabs" }, [_c("button", { class: ["hep-cr-tab", { active: _vm.activeTab === "stdout" }], on: { "click": function($event) {
|
|
3131
|
+
_vm.activeTab = "stdout";
|
|
3132
|
+
} } }, [_vm._v(" 输出 ")]), _vm.stderr ? _c("button", { class: ["hep-cr-tab", "hep-cr-tab-error", { active: _vm.activeTab === "stderr" }], on: { "click": function($event) {
|
|
3133
|
+
_vm.activeTab = "stderr";
|
|
3134
|
+
} } }, [_vm._v(" 错误 ")]) : _vm._e()]), _c("div", { staticClass: "hep-cr-output-actions" }, [_vm.executionTime !== null ? _c("span", { staticClass: "hep-cr-execution-time" }, [_vm._v(" " + _vm._s(_vm.executionTime) + "ms ")]) : _vm._e(), _c("button", { staticClass: "hep-cr-btn-icon", class: { "hep-cr-btn-copied": _vm.copiedOutput }, attrs: { "disabled": _vm.copiedOutput, "title": _vm.copiedOutput ? "已复制" : "复制" }, on: { "click": _vm.copyOutput } }, [!_vm.copiedOutput ? _c("svg", { attrs: { "width": "14", "height": "14", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" } }, [_c("rect", { attrs: { "x": "9", "y": "9", "width": "13", "height": "13", "rx": "2", "ry": "2" } }), _c("path", { attrs: { "d": "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" } })]) : _c("span", { staticClass: "hep-cr-copied-text" }, [_vm._v("已复制")])])])]), _c("div", { staticClass: "hep-cr-output-content" }, [_vm.activeTab === "stdout" ? _c("pre", [_vm._v(_vm._s(_vm.isRunning ? "代码执行中..." : _vm.output || '点击"运行"执行代码'))]) : _c("pre", { staticClass: "hep-cr-stderr" }, [_vm._v(_vm._s(_vm.stderr))])])])])]);
|
|
3135
|
+
};
|
|
3136
|
+
var _sfc_staticRenderFns$1 = [];
|
|
3137
|
+
var __component__$1 = /* @__PURE__ */ normalizeComponent(
|
|
3138
|
+
_sfc_main$1,
|
|
3139
|
+
_sfc_render$1,
|
|
3140
|
+
_sfc_staticRenderFns$1,
|
|
3141
|
+
false,
|
|
1350
3142
|
null,
|
|
1351
3143
|
"b9693b7c"
|
|
1352
3144
|
);
|
|
1353
|
-
const
|
|
3145
|
+
const CodeRunner = __component__$1.exports;
|
|
3146
|
+
const _sfc_main = {
|
|
1354
3147
|
name: "CodeRunnerDialog",
|
|
1355
3148
|
components: {
|
|
1356
|
-
CodeRunner
|
|
3149
|
+
CodeRunner
|
|
1357
3150
|
},
|
|
1358
3151
|
props: {
|
|
1359
3152
|
value: {
|
|
1360
3153
|
type: Boolean,
|
|
1361
|
-
default:
|
|
3154
|
+
default: false
|
|
1362
3155
|
},
|
|
1363
3156
|
title: {
|
|
1364
3157
|
type: String,
|
|
@@ -1380,46 +3173,53 @@ const u = N.exports, C = {
|
|
|
1380
3173
|
},
|
|
1381
3174
|
computed: {
|
|
1382
3175
|
dialogWidth() {
|
|
1383
|
-
return typeof this.width
|
|
3176
|
+
return typeof this.width === "number" ? this.width + "px" : this.width;
|
|
1384
3177
|
}
|
|
1385
3178
|
},
|
|
1386
3179
|
watch: {
|
|
1387
|
-
value(
|
|
1388
|
-
this.localVisible =
|
|
3180
|
+
value(val) {
|
|
3181
|
+
this.localVisible = val;
|
|
1389
3182
|
}
|
|
1390
3183
|
},
|
|
1391
3184
|
methods: {
|
|
1392
3185
|
close() {
|
|
1393
|
-
this.localVisible =
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
3186
|
+
this.localVisible = false;
|
|
3187
|
+
this.$emit("input", false);
|
|
3188
|
+
this.$emit("update:value", false);
|
|
3189
|
+
this.$emit("close");
|
|
3190
|
+
},
|
|
3191
|
+
handleOverlayClick(e) {
|
|
3192
|
+
if (e.target === e.currentTarget) {
|
|
3193
|
+
this.close();
|
|
3194
|
+
}
|
|
1397
3195
|
}
|
|
1398
3196
|
},
|
|
1399
3197
|
expose: ["close"]
|
|
1400
3198
|
};
|
|
1401
|
-
var
|
|
1402
|
-
var
|
|
1403
|
-
return
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
3199
|
+
var _sfc_render = function render3() {
|
|
3200
|
+
var _vm = this, _c = _vm._self._c;
|
|
3201
|
+
return _vm.localVisible ? _c("div", { staticClass: "hep-cr-dialog-overlay", on: { "click": _vm.handleOverlayClick } }, [_c("div", { staticClass: "hep-cr-dialog-container", style: { width: _vm.dialogWidth } }, [_c("div", { staticClass: "hep-cr-dialog-header" }, [_c("h3", { staticClass: "hep-cr-dialog-title" }, [_vm._v(_vm._s(_vm.title))]), _c("button", { staticClass: "hep-cr-dialog-close", on: { "click": _vm.close } }, [_c("svg", { attrs: { "width": "16", "height": "16", "viewBox": "0 0 24 24", "fill": "none", "stroke": "currentColor", "stroke-width": "2" } }, [_c("line", { attrs: { "x1": "18", "y1": "6", "x2": "6", "y2": "18" } }), _c("line", { attrs: { "x1": "6", "y1": "6", "x2": "18", "y2": "18" } })])])]), _c("div", { staticClass: "hep-cr-dialog-body" }, [_c("CodeRunner", _vm._g(_vm._b({}, "CodeRunner", _vm.$attrs, false), _vm.$listeners))], 1), _c("div", { staticClass: "hep-cr-dialog-footer" }, [_vm._t("footer", null, { "close": _vm.close })], 2)])]) : _vm._e();
|
|
3202
|
+
};
|
|
3203
|
+
var _sfc_staticRenderFns = [];
|
|
3204
|
+
var __component__ = /* @__PURE__ */ normalizeComponent(
|
|
3205
|
+
_sfc_main,
|
|
3206
|
+
_sfc_render,
|
|
3207
|
+
_sfc_staticRenderFns,
|
|
3208
|
+
false,
|
|
1409
3209
|
null,
|
|
1410
3210
|
"518c34f1"
|
|
1411
3211
|
);
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
3212
|
+
const CodeRunnerDialog = __component__.exports;
|
|
3213
|
+
CodeRunner.install = (app) => {
|
|
3214
|
+
app.component("CodeRunner", CodeRunner);
|
|
1415
3215
|
};
|
|
1416
|
-
const
|
|
1417
|
-
install(
|
|
1418
|
-
|
|
3216
|
+
const index = {
|
|
3217
|
+
install(app) {
|
|
3218
|
+
app.component("CodeRunner", CodeRunner);
|
|
1419
3219
|
}
|
|
1420
3220
|
};
|
|
1421
3221
|
export {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
3222
|
+
CodeRunner,
|
|
3223
|
+
CodeRunnerDialog,
|
|
3224
|
+
index as default
|
|
1425
3225
|
};
|