@hep-code-runner/vue3 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 -164
- package/dist/index.mjs +2554 -681
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1,58 +1,1733 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { defineComponent, useCssVars, ref, computed, onMounted, watch, onUnmounted, openBlock, createElementBlock, normalizeClass, createElementVNode, normalizeStyle, withDirectives, createCommentVNode, Fragment, renderList, toDisplayString, vModelSelect, createTextVNode, createStaticVNode, createVNode, createBlock, Teleport, Transition, withCtx, mergeProps, toHandlers, renderSlot } from "vue";
|
|
2
|
+
var w = Object.defineProperty;
|
|
3
|
+
var y = (o, e, t) => e in o ? w(o, e, { enumerable: true, configurable: true, writable: true, value: t }) : o[e] = t;
|
|
4
|
+
var c = (o, e, t) => y(o, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
let u = null;
|
|
6
|
+
class W {
|
|
7
|
+
constructor(e = {}) {
|
|
8
|
+
c(this, "baseUrl");
|
|
9
|
+
c(this, "timeout");
|
|
10
|
+
this.baseUrl = e.pistonUrl || "/api/piston", this.timeout = e.timeout || 3e3;
|
|
11
|
+
}
|
|
12
|
+
async getRuntimes(e = false) {
|
|
13
|
+
if (u && !e)
|
|
14
|
+
return u;
|
|
15
|
+
try {
|
|
16
|
+
const t = await fetch(`${this.baseUrl}/runtimes`, {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (!t.ok)
|
|
23
|
+
throw new Error(`Failed to fetch runtimes: ${t.statusText}`);
|
|
24
|
+
const n = await t.json();
|
|
25
|
+
return u = n, n;
|
|
26
|
+
} catch (t) {
|
|
27
|
+
throw console.error("Failed to fetch runtimes:", t), t;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async execute(e, t, n = {}) {
|
|
31
|
+
const l = (await this.getRuntimes()).find(
|
|
32
|
+
(a) => {
|
|
33
|
+
var r;
|
|
34
|
+
return a.language.toLowerCase() === e.toLowerCase() || ((r = a.aliases) == null ? void 0 : r.some((i) => i.toLowerCase() === e.toLowerCase()));
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
if (!l)
|
|
38
|
+
throw new Error(`Language '${e}' is not supported`);
|
|
39
|
+
const p = this.getFileName(e), h = {
|
|
40
|
+
language: l.language,
|
|
41
|
+
version: n.version || l.version,
|
|
42
|
+
files: [
|
|
43
|
+
{
|
|
44
|
+
name: p,
|
|
45
|
+
content: t
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
stdin: n.stdin || "",
|
|
49
|
+
args: n.args || [],
|
|
50
|
+
run_timeout: n.runTimeout || this.timeout,
|
|
51
|
+
compile_timeout: this.timeout
|
|
52
|
+
}, d = Date.now();
|
|
53
|
+
try {
|
|
54
|
+
const a = await fetch(`${this.baseUrl}/execute`, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
"Content-Type": "application/json"
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(h)
|
|
60
|
+
});
|
|
61
|
+
if (!a.ok)
|
|
62
|
+
throw new Error(`Execute failed: ${a.statusText}`);
|
|
63
|
+
const r = await a.json(), i = Date.now() - d, g = r.run.stdout || "", f = r.run.stderr || "";
|
|
64
|
+
return {
|
|
65
|
+
success: r.run.code === 0,
|
|
66
|
+
output: g,
|
|
67
|
+
stderr: f,
|
|
68
|
+
code: r.run.code,
|
|
69
|
+
executionTime: i,
|
|
70
|
+
compile: r.compile ? {
|
|
71
|
+
stdout: r.compile.stdout || "",
|
|
72
|
+
stderr: r.compile.stderr || "",
|
|
73
|
+
code: r.compile.code
|
|
74
|
+
} : void 0
|
|
75
|
+
};
|
|
76
|
+
} catch (a) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
output: "",
|
|
80
|
+
stderr: a instanceof Error ? a.message : "Unknown error",
|
|
81
|
+
code: -1,
|
|
82
|
+
executionTime: Date.now() - d
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
getFileName(e) {
|
|
87
|
+
return {
|
|
88
|
+
javascript: "main.js",
|
|
89
|
+
typescript: "main.ts",
|
|
90
|
+
python: "main.py",
|
|
91
|
+
python3: "main.py",
|
|
92
|
+
go: "main.go",
|
|
93
|
+
rust: "main.rs",
|
|
94
|
+
java: "Main.java",
|
|
95
|
+
c: "main.c",
|
|
96
|
+
cpp: "main.cpp",
|
|
97
|
+
csharp: "Main.cs",
|
|
98
|
+
ruby: "main.rb",
|
|
99
|
+
php: "main.php",
|
|
100
|
+
bash: "main.sh",
|
|
101
|
+
shell: "main.sh",
|
|
102
|
+
perl: "main.pl",
|
|
103
|
+
lua: "main.lua",
|
|
104
|
+
swift: "main.swift",
|
|
105
|
+
kotlin: "Main.kt",
|
|
106
|
+
scala: "Main.scala",
|
|
107
|
+
haskell: "main.hs",
|
|
108
|
+
dart: "main.dart",
|
|
109
|
+
html: "index.html",
|
|
110
|
+
css: "style.css",
|
|
111
|
+
sql: "query.sql",
|
|
112
|
+
markdown: "readme.md"
|
|
113
|
+
}[e.toLowerCase()] || `main.${e}`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const m = {
|
|
117
|
+
javascript: 'console.log("Hello, World!");',
|
|
118
|
+
typescript: 'console.log("Hello, World!");',
|
|
119
|
+
python: 'print("Hello, World!")',
|
|
120
|
+
python3: 'print("Hello, World!")',
|
|
121
|
+
go: `package main
|
|
122
|
+
|
|
123
|
+
import "fmt"
|
|
124
|
+
|
|
125
|
+
func main() {
|
|
126
|
+
fmt.Println("Hello, World!")
|
|
127
|
+
}`,
|
|
128
|
+
rust: `fn main() {
|
|
129
|
+
println!("Hello, World!");
|
|
130
|
+
}`,
|
|
131
|
+
java: `public class Main {
|
|
132
|
+
public static void main(String[] args) {
|
|
133
|
+
System.out.println("Hello, World!");
|
|
134
|
+
}
|
|
135
|
+
}`,
|
|
136
|
+
c: `#include <stdio.h>
|
|
137
|
+
|
|
138
|
+
int main() {
|
|
139
|
+
printf("Hello, World!\\n");
|
|
140
|
+
return 0;
|
|
141
|
+
}`,
|
|
142
|
+
cpp: `#include <iostream>
|
|
143
|
+
|
|
144
|
+
int main() {
|
|
145
|
+
std::cout << "Hello, World!" << std::endl;
|
|
146
|
+
return 0;
|
|
147
|
+
}`,
|
|
148
|
+
csharp: `using System;
|
|
149
|
+
|
|
150
|
+
class Main {
|
|
151
|
+
static void Main() {
|
|
152
|
+
Console.WriteLine("Hello, World!");
|
|
153
|
+
}
|
|
154
|
+
}`,
|
|
155
|
+
ruby: 'puts "Hello, World!"',
|
|
156
|
+
php: `<?php
|
|
157
|
+
echo "Hello, World!";
|
|
158
|
+
?>`,
|
|
159
|
+
bash: 'echo "Hello, World!"',
|
|
160
|
+
shell: 'echo "Hello, World!"',
|
|
161
|
+
perl: 'print "Hello, World!\\n";',
|
|
162
|
+
lua: 'print("Hello, World!")',
|
|
163
|
+
r: 'print("Hello, World!")',
|
|
164
|
+
swift: 'print("Hello, World!")',
|
|
165
|
+
kotlin: `fun main() {
|
|
166
|
+
println("Hello, World!")
|
|
167
|
+
}`,
|
|
168
|
+
scala: `object Main extends App {
|
|
169
|
+
println("Hello, World!")
|
|
170
|
+
}`,
|
|
171
|
+
haskell: 'main = putStrLn "Hello, World!"',
|
|
172
|
+
elixir: 'IO.puts "Hello, World!"',
|
|
173
|
+
erlang: 'main() -> io:fwrite("Hello, World!~n").',
|
|
174
|
+
clojure: '(println "Hello, World!")',
|
|
175
|
+
fsharp: 'printfn "Hello, World!"',
|
|
176
|
+
dart: `void main() {
|
|
177
|
+
print("Hello, World!");
|
|
178
|
+
}`,
|
|
179
|
+
assembly: `section .data
|
|
180
|
+
msg db 'Hello, World!', 0
|
|
181
|
+
section .text
|
|
182
|
+
global _start
|
|
183
|
+
_start:
|
|
184
|
+
mov rax, 1
|
|
185
|
+
mov rdi, 1
|
|
186
|
+
mov rsi, msg
|
|
187
|
+
mov rdx, 13
|
|
188
|
+
syscall
|
|
189
|
+
mov rax, 60
|
|
190
|
+
xor rdi, rdi
|
|
191
|
+
syscall`,
|
|
192
|
+
html: `<!DOCTYPE html>
|
|
193
|
+
<html>
|
|
194
|
+
<head>
|
|
195
|
+
<title>Hello</title>
|
|
196
|
+
</head>
|
|
197
|
+
<body>
|
|
198
|
+
<h1>Hello, World!</h1>
|
|
199
|
+
</body>
|
|
200
|
+
</html>`,
|
|
201
|
+
css: `body {
|
|
202
|
+
background-color: #f0f0f0;
|
|
203
|
+
font-family: Arial, sans-serif;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
h1 {
|
|
207
|
+
color: #333;
|
|
208
|
+
}`,
|
|
209
|
+
sql: "SELECT 'Hello, World!' AS message;",
|
|
210
|
+
markdown: `# Hello, World!
|
|
211
|
+
|
|
212
|
+
This is a sample markdown document.`
|
|
213
|
+
};
|
|
214
|
+
function j(o) {
|
|
215
|
+
const e = o.toLowerCase();
|
|
216
|
+
return m[e] || `// ${o}
|
|
217
|
+
// Write your code here`;
|
|
218
|
+
}
|
|
219
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
220
|
+
function getDefaultExportFromCjs(x) {
|
|
221
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
222
|
+
}
|
|
223
|
+
var prism = { exports: {} };
|
|
224
|
+
(function(module) {
|
|
225
|
+
var _self = typeof window !== "undefined" ? window : typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope ? self : {};
|
|
226
|
+
/**
|
|
227
|
+
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
228
|
+
*
|
|
229
|
+
* @license MIT <https://opensource.org/licenses/MIT>
|
|
230
|
+
* @author Lea Verou <https://lea.verou.me>
|
|
231
|
+
* @namespace
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
var Prism2 = function(_self2) {
|
|
235
|
+
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
|
236
|
+
var uniqueId = 0;
|
|
237
|
+
var plainTextGrammar = {};
|
|
238
|
+
var _ = {
|
|
239
|
+
/**
|
|
240
|
+
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
|
241
|
+
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
|
242
|
+
* additional languages or plugins yourself.
|
|
243
|
+
*
|
|
244
|
+
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
|
245
|
+
*
|
|
246
|
+
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
|
247
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
|
248
|
+
*
|
|
249
|
+
* ```js
|
|
250
|
+
* window.Prism = window.Prism || {};
|
|
251
|
+
* Prism.manual = true;
|
|
252
|
+
* // add a new <script> to load Prism's script
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @default false
|
|
256
|
+
* @type {boolean}
|
|
257
|
+
* @memberof Prism
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
manual: _self2.Prism && _self2.Prism.manual,
|
|
261
|
+
/**
|
|
262
|
+
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
|
263
|
+
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
|
264
|
+
* own worker, you don't want it to do this.
|
|
265
|
+
*
|
|
266
|
+
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
|
267
|
+
*
|
|
268
|
+
* You obviously have to change this value before Prism executes. To do this, you can add an
|
|
269
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
|
270
|
+
*
|
|
271
|
+
* ```js
|
|
272
|
+
* window.Prism = window.Prism || {};
|
|
273
|
+
* Prism.disableWorkerMessageHandler = true;
|
|
274
|
+
* // Load Prism's script
|
|
275
|
+
* ```
|
|
276
|
+
*
|
|
277
|
+
* @default false
|
|
278
|
+
* @type {boolean}
|
|
279
|
+
* @memberof Prism
|
|
280
|
+
* @public
|
|
281
|
+
*/
|
|
282
|
+
disableWorkerMessageHandler: _self2.Prism && _self2.Prism.disableWorkerMessageHandler,
|
|
283
|
+
/**
|
|
284
|
+
* A namespace for utility methods.
|
|
285
|
+
*
|
|
286
|
+
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
287
|
+
* change or disappear at any time.
|
|
288
|
+
*
|
|
289
|
+
* @namespace
|
|
290
|
+
* @memberof Prism
|
|
291
|
+
*/
|
|
292
|
+
util: {
|
|
293
|
+
encode: function encode(tokens) {
|
|
294
|
+
if (tokens instanceof Token) {
|
|
295
|
+
return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
|
296
|
+
} else if (Array.isArray(tokens)) {
|
|
297
|
+
return tokens.map(encode);
|
|
298
|
+
} else {
|
|
299
|
+
return tokens.replace(/&/g, "&").replace(/</g, "<").replace(/\u00a0/g, " ");
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* Returns the name of the type of the given value.
|
|
304
|
+
*
|
|
305
|
+
* @param {any} o
|
|
306
|
+
* @returns {string}
|
|
307
|
+
* @example
|
|
308
|
+
* type(null) === 'Null'
|
|
309
|
+
* type(undefined) === 'Undefined'
|
|
310
|
+
* type(123) === 'Number'
|
|
311
|
+
* type('foo') === 'String'
|
|
312
|
+
* type(true) === 'Boolean'
|
|
313
|
+
* type([1, 2]) === 'Array'
|
|
314
|
+
* type({}) === 'Object'
|
|
315
|
+
* type(String) === 'Function'
|
|
316
|
+
* type(/abc+/) === 'RegExp'
|
|
317
|
+
*/
|
|
318
|
+
type: function(o) {
|
|
319
|
+
return Object.prototype.toString.call(o).slice(8, -1);
|
|
320
|
+
},
|
|
321
|
+
/**
|
|
322
|
+
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
323
|
+
*
|
|
324
|
+
* @param {Object} obj
|
|
325
|
+
* @returns {number}
|
|
326
|
+
*/
|
|
327
|
+
objId: function(obj) {
|
|
328
|
+
if (!obj["__id"]) {
|
|
329
|
+
Object.defineProperty(obj, "__id", { value: ++uniqueId });
|
|
330
|
+
}
|
|
331
|
+
return obj["__id"];
|
|
332
|
+
},
|
|
333
|
+
/**
|
|
334
|
+
* Creates a deep clone of the given object.
|
|
335
|
+
*
|
|
336
|
+
* The main intended use of this function is to clone language definitions.
|
|
337
|
+
*
|
|
338
|
+
* @param {T} o
|
|
339
|
+
* @param {Record<number, any>} [visited]
|
|
340
|
+
* @returns {T}
|
|
341
|
+
* @template T
|
|
342
|
+
*/
|
|
343
|
+
clone: function deepClone(o, visited) {
|
|
344
|
+
visited = visited || {};
|
|
345
|
+
var clone;
|
|
346
|
+
var id;
|
|
347
|
+
switch (_.util.type(o)) {
|
|
348
|
+
case "Object":
|
|
349
|
+
id = _.util.objId(o);
|
|
350
|
+
if (visited[id]) {
|
|
351
|
+
return visited[id];
|
|
352
|
+
}
|
|
353
|
+
clone = /** @type {Record<string, any>} */
|
|
354
|
+
{};
|
|
355
|
+
visited[id] = clone;
|
|
356
|
+
for (var key in o) {
|
|
357
|
+
if (o.hasOwnProperty(key)) {
|
|
358
|
+
clone[key] = deepClone(o[key], visited);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return (
|
|
362
|
+
/** @type {any} */
|
|
363
|
+
clone
|
|
364
|
+
);
|
|
365
|
+
case "Array":
|
|
366
|
+
id = _.util.objId(o);
|
|
367
|
+
if (visited[id]) {
|
|
368
|
+
return visited[id];
|
|
369
|
+
}
|
|
370
|
+
clone = [];
|
|
371
|
+
visited[id] = clone;
|
|
372
|
+
/** @type {Array} */
|
|
373
|
+
/** @type {any} */
|
|
374
|
+
o.forEach(function(v, i) {
|
|
375
|
+
clone[i] = deepClone(v, visited);
|
|
376
|
+
});
|
|
377
|
+
return (
|
|
378
|
+
/** @type {any} */
|
|
379
|
+
clone
|
|
380
|
+
);
|
|
381
|
+
default:
|
|
382
|
+
return o;
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
/**
|
|
386
|
+
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
|
387
|
+
*
|
|
388
|
+
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
|
389
|
+
*
|
|
390
|
+
* @param {Element} element
|
|
391
|
+
* @returns {string}
|
|
392
|
+
*/
|
|
393
|
+
getLanguage: function(element) {
|
|
394
|
+
while (element) {
|
|
395
|
+
var m2 = lang.exec(element.className);
|
|
396
|
+
if (m2) {
|
|
397
|
+
return m2[1].toLowerCase();
|
|
398
|
+
}
|
|
399
|
+
element = element.parentElement;
|
|
400
|
+
}
|
|
401
|
+
return "none";
|
|
402
|
+
},
|
|
403
|
+
/**
|
|
404
|
+
* Sets the Prism `language-xxxx` class of the given element.
|
|
405
|
+
*
|
|
406
|
+
* @param {Element} element
|
|
407
|
+
* @param {string} language
|
|
408
|
+
* @returns {void}
|
|
409
|
+
*/
|
|
410
|
+
setLanguage: function(element, language) {
|
|
411
|
+
element.className = element.className.replace(RegExp(lang, "gi"), "");
|
|
412
|
+
element.classList.add("language-" + language);
|
|
413
|
+
},
|
|
414
|
+
/**
|
|
415
|
+
* Returns the script element that is currently executing.
|
|
416
|
+
*
|
|
417
|
+
* This does __not__ work for line script element.
|
|
418
|
+
*
|
|
419
|
+
* @returns {HTMLScriptElement | null}
|
|
420
|
+
*/
|
|
421
|
+
currentScript: function() {
|
|
422
|
+
if (typeof document === "undefined") {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
if (document.currentScript && document.currentScript.tagName === "SCRIPT" && 1 < 2) {
|
|
426
|
+
return (
|
|
427
|
+
/** @type {any} */
|
|
428
|
+
document.currentScript
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
try {
|
|
432
|
+
throw new Error();
|
|
433
|
+
} catch (err) {
|
|
434
|
+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
|
435
|
+
if (src) {
|
|
436
|
+
var scripts = document.getElementsByTagName("script");
|
|
437
|
+
for (var i in scripts) {
|
|
438
|
+
if (scripts[i].src == src) {
|
|
439
|
+
return scripts[i];
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
/**
|
|
447
|
+
* Returns whether a given class is active for `element`.
|
|
448
|
+
*
|
|
449
|
+
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
|
450
|
+
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
|
451
|
+
* given class is just the given class with a `no-` prefix.
|
|
452
|
+
*
|
|
453
|
+
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
|
454
|
+
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
|
455
|
+
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
|
456
|
+
*
|
|
457
|
+
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
|
458
|
+
* version of it, the class is considered active.
|
|
459
|
+
*
|
|
460
|
+
* @param {Element} element
|
|
461
|
+
* @param {string} className
|
|
462
|
+
* @param {boolean} [defaultActivation=false]
|
|
463
|
+
* @returns {boolean}
|
|
464
|
+
*/
|
|
465
|
+
isActive: function(element, className, defaultActivation) {
|
|
466
|
+
var no = "no-" + className;
|
|
467
|
+
while (element) {
|
|
468
|
+
var classList = element.classList;
|
|
469
|
+
if (classList.contains(className)) {
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
if (classList.contains(no)) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
element = element.parentElement;
|
|
476
|
+
}
|
|
477
|
+
return !!defaultActivation;
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
/**
|
|
481
|
+
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
482
|
+
*
|
|
483
|
+
* @namespace
|
|
484
|
+
* @memberof Prism
|
|
485
|
+
* @public
|
|
486
|
+
*/
|
|
487
|
+
languages: {
|
|
488
|
+
/**
|
|
489
|
+
* The grammar for plain, unformatted text.
|
|
490
|
+
*/
|
|
491
|
+
plain: plainTextGrammar,
|
|
492
|
+
plaintext: plainTextGrammar,
|
|
493
|
+
text: plainTextGrammar,
|
|
494
|
+
txt: plainTextGrammar,
|
|
495
|
+
/**
|
|
496
|
+
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
497
|
+
*
|
|
498
|
+
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
499
|
+
* will be overwritten at its original position.
|
|
500
|
+
*
|
|
501
|
+
* ## Best practices
|
|
502
|
+
*
|
|
503
|
+
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
504
|
+
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
505
|
+
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
506
|
+
*
|
|
507
|
+
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
508
|
+
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
509
|
+
*
|
|
510
|
+
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
511
|
+
* @param {Grammar} redef The new tokens to append.
|
|
512
|
+
* @returns {Grammar} The new language created.
|
|
513
|
+
* @public
|
|
514
|
+
* @example
|
|
515
|
+
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
516
|
+
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
517
|
+
* // at its original position
|
|
518
|
+
* 'comment': { ... },
|
|
519
|
+
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
520
|
+
* 'color': /\b(?:red|green|blue)\b/
|
|
521
|
+
* });
|
|
522
|
+
*/
|
|
523
|
+
extend: function(id, redef) {
|
|
524
|
+
var lang2 = _.util.clone(_.languages[id]);
|
|
525
|
+
for (var key in redef) {
|
|
526
|
+
lang2[key] = redef[key];
|
|
527
|
+
}
|
|
528
|
+
return lang2;
|
|
529
|
+
},
|
|
530
|
+
/**
|
|
531
|
+
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
532
|
+
*
|
|
533
|
+
* ## Usage
|
|
534
|
+
*
|
|
535
|
+
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
536
|
+
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
537
|
+
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
538
|
+
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
539
|
+
* this:
|
|
540
|
+
*
|
|
541
|
+
* ```js
|
|
542
|
+
* Prism.languages.markup.style = {
|
|
543
|
+
* // token
|
|
544
|
+
* };
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
548
|
+
* before existing tokens. For the CSS example above, you would use it like this:
|
|
549
|
+
*
|
|
550
|
+
* ```js
|
|
551
|
+
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
552
|
+
* 'style': {
|
|
553
|
+
* // token
|
|
554
|
+
* }
|
|
555
|
+
* });
|
|
556
|
+
* ```
|
|
557
|
+
*
|
|
558
|
+
* ## Special cases
|
|
559
|
+
*
|
|
560
|
+
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
561
|
+
* will be ignored.
|
|
562
|
+
*
|
|
563
|
+
* This behavior can be used to insert tokens after `before`:
|
|
564
|
+
*
|
|
565
|
+
* ```js
|
|
566
|
+
* Prism.languages.insertBefore('markup', 'comment', {
|
|
567
|
+
* 'comment': Prism.languages.markup.comment,
|
|
568
|
+
* // tokens after 'comment'
|
|
569
|
+
* });
|
|
570
|
+
* ```
|
|
571
|
+
*
|
|
572
|
+
* ## Limitations
|
|
573
|
+
*
|
|
574
|
+
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
575
|
+
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
576
|
+
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
577
|
+
* deleting properties which is necessary to insert at arbitrary positions.
|
|
578
|
+
*
|
|
579
|
+
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
580
|
+
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
581
|
+
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
582
|
+
*
|
|
583
|
+
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
584
|
+
* you hold the target object in a variable, then the value of the variable will not change.
|
|
585
|
+
*
|
|
586
|
+
* ```js
|
|
587
|
+
* var oldMarkup = Prism.languages.markup;
|
|
588
|
+
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
589
|
+
*
|
|
590
|
+
* assert(oldMarkup !== Prism.languages.markup);
|
|
591
|
+
* assert(newMarkup === Prism.languages.markup);
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
595
|
+
* object to be modified.
|
|
596
|
+
* @param {string} before The key to insert before.
|
|
597
|
+
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
598
|
+
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
599
|
+
* object to be modified.
|
|
600
|
+
*
|
|
601
|
+
* Defaults to `Prism.languages`.
|
|
602
|
+
* @returns {Grammar} The new grammar object.
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
insertBefore: function(inside, before, insert, root) {
|
|
606
|
+
root = root || /** @type {any} */
|
|
607
|
+
_.languages;
|
|
608
|
+
var grammar = root[inside];
|
|
609
|
+
var ret = {};
|
|
610
|
+
for (var token in grammar) {
|
|
611
|
+
if (grammar.hasOwnProperty(token)) {
|
|
612
|
+
if (token == before) {
|
|
613
|
+
for (var newToken in insert) {
|
|
614
|
+
if (insert.hasOwnProperty(newToken)) {
|
|
615
|
+
ret[newToken] = insert[newToken];
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (!insert.hasOwnProperty(token)) {
|
|
620
|
+
ret[token] = grammar[token];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
var old = root[inside];
|
|
625
|
+
root[inside] = ret;
|
|
626
|
+
_.languages.DFS(_.languages, function(key, value) {
|
|
627
|
+
if (value === old && key != inside) {
|
|
628
|
+
this[key] = ret;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
return ret;
|
|
632
|
+
},
|
|
633
|
+
// Traverse a language definition with Depth First Search
|
|
634
|
+
DFS: function DFS(o, callback, type, visited) {
|
|
635
|
+
visited = visited || {};
|
|
636
|
+
var objId = _.util.objId;
|
|
637
|
+
for (var i in o) {
|
|
638
|
+
if (o.hasOwnProperty(i)) {
|
|
639
|
+
callback.call(o, i, o[i], type || i);
|
|
640
|
+
var property = o[i];
|
|
641
|
+
var propertyType = _.util.type(property);
|
|
642
|
+
if (propertyType === "Object" && !visited[objId(property)]) {
|
|
643
|
+
visited[objId(property)] = true;
|
|
644
|
+
DFS(property, callback, null, visited);
|
|
645
|
+
} else if (propertyType === "Array" && !visited[objId(property)]) {
|
|
646
|
+
visited[objId(property)] = true;
|
|
647
|
+
DFS(property, callback, i, visited);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
plugins: {},
|
|
654
|
+
/**
|
|
655
|
+
* This is the most high-level function in Prism’s API.
|
|
656
|
+
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
|
657
|
+
* each one of them.
|
|
658
|
+
*
|
|
659
|
+
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
|
660
|
+
*
|
|
661
|
+
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
|
662
|
+
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
|
663
|
+
* @memberof Prism
|
|
664
|
+
* @public
|
|
665
|
+
*/
|
|
666
|
+
highlightAll: function(async, callback) {
|
|
667
|
+
_.highlightAllUnder(document, async, callback);
|
|
668
|
+
},
|
|
669
|
+
/**
|
|
670
|
+
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
|
671
|
+
* {@link Prism.highlightElement} on each one of them.
|
|
672
|
+
*
|
|
673
|
+
* The following hooks will be run:
|
|
674
|
+
* 1. `before-highlightall`
|
|
675
|
+
* 2. `before-all-elements-highlight`
|
|
676
|
+
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
|
677
|
+
*
|
|
678
|
+
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
|
679
|
+
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
|
680
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
|
681
|
+
* @memberof Prism
|
|
682
|
+
* @public
|
|
683
|
+
*/
|
|
684
|
+
highlightAllUnder: function(container, async, callback) {
|
|
685
|
+
var env = {
|
|
686
|
+
callback,
|
|
687
|
+
container,
|
|
688
|
+
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
|
689
|
+
};
|
|
690
|
+
_.hooks.run("before-highlightall", env);
|
|
691
|
+
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
|
692
|
+
_.hooks.run("before-all-elements-highlight", env);
|
|
693
|
+
for (var i = 0, element; element = env.elements[i++]; ) {
|
|
694
|
+
_.highlightElement(element, async === true, env.callback);
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
/**
|
|
698
|
+
* Highlights the code inside a single element.
|
|
699
|
+
*
|
|
700
|
+
* The following hooks will be run:
|
|
701
|
+
* 1. `before-sanity-check`
|
|
702
|
+
* 2. `before-highlight`
|
|
703
|
+
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
|
704
|
+
* 4. `before-insert`
|
|
705
|
+
* 5. `after-highlight`
|
|
706
|
+
* 6. `complete`
|
|
707
|
+
*
|
|
708
|
+
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
|
709
|
+
* the element's language.
|
|
710
|
+
*
|
|
711
|
+
* @param {Element} element The element containing the code.
|
|
712
|
+
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
|
713
|
+
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
|
714
|
+
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
|
715
|
+
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
|
716
|
+
*
|
|
717
|
+
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
|
718
|
+
* asynchronous highlighting to work. You can build your own bundle on the
|
|
719
|
+
* [Download page](https://prismjs.com/download.html).
|
|
720
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
|
721
|
+
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
|
722
|
+
* @memberof Prism
|
|
723
|
+
* @public
|
|
724
|
+
*/
|
|
725
|
+
highlightElement: function(element, async, callback) {
|
|
726
|
+
var language = _.util.getLanguage(element);
|
|
727
|
+
var grammar = _.languages[language];
|
|
728
|
+
_.util.setLanguage(element, language);
|
|
729
|
+
var parent = element.parentElement;
|
|
730
|
+
if (parent && parent.nodeName.toLowerCase() === "pre") {
|
|
731
|
+
_.util.setLanguage(parent, language);
|
|
732
|
+
}
|
|
733
|
+
var code = element.textContent;
|
|
734
|
+
var env = {
|
|
735
|
+
element,
|
|
736
|
+
language,
|
|
737
|
+
grammar,
|
|
738
|
+
code
|
|
739
|
+
};
|
|
740
|
+
function insertHighlightedCode(highlightedCode) {
|
|
741
|
+
env.highlightedCode = highlightedCode;
|
|
742
|
+
_.hooks.run("before-insert", env);
|
|
743
|
+
env.element.innerHTML = env.highlightedCode;
|
|
744
|
+
_.hooks.run("after-highlight", env);
|
|
745
|
+
_.hooks.run("complete", env);
|
|
746
|
+
callback && callback.call(env.element);
|
|
747
|
+
}
|
|
748
|
+
_.hooks.run("before-sanity-check", env);
|
|
749
|
+
parent = env.element.parentElement;
|
|
750
|
+
if (parent && parent.nodeName.toLowerCase() === "pre" && !parent.hasAttribute("tabindex")) {
|
|
751
|
+
parent.setAttribute("tabindex", "0");
|
|
752
|
+
}
|
|
753
|
+
if (!env.code) {
|
|
754
|
+
_.hooks.run("complete", env);
|
|
755
|
+
callback && callback.call(env.element);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
_.hooks.run("before-highlight", env);
|
|
759
|
+
if (!env.grammar) {
|
|
760
|
+
insertHighlightedCode(_.util.encode(env.code));
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (async && _self2.Worker) {
|
|
764
|
+
var worker = new Worker(_.filename);
|
|
765
|
+
worker.onmessage = function(evt) {
|
|
766
|
+
insertHighlightedCode(evt.data);
|
|
767
|
+
};
|
|
768
|
+
worker.postMessage(JSON.stringify({
|
|
769
|
+
language: env.language,
|
|
770
|
+
code: env.code,
|
|
771
|
+
immediateClose: true
|
|
772
|
+
}));
|
|
773
|
+
} else {
|
|
774
|
+
insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
/**
|
|
778
|
+
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
779
|
+
* and the language definitions to use, and returns a string with the HTML produced.
|
|
780
|
+
*
|
|
781
|
+
* The following hooks will be run:
|
|
782
|
+
* 1. `before-tokenize`
|
|
783
|
+
* 2. `after-tokenize`
|
|
784
|
+
* 3. `wrap`: On each {@link Token}.
|
|
785
|
+
*
|
|
786
|
+
* @param {string} text A string with the code to be highlighted.
|
|
787
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
788
|
+
*
|
|
789
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
790
|
+
* @param {string} language The name of the language definition passed to `grammar`.
|
|
791
|
+
* @returns {string} The highlighted HTML.
|
|
792
|
+
* @memberof Prism
|
|
793
|
+
* @public
|
|
794
|
+
* @example
|
|
795
|
+
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
796
|
+
*/
|
|
797
|
+
highlight: function(text, grammar, language) {
|
|
798
|
+
var env = {
|
|
799
|
+
code: text,
|
|
800
|
+
grammar,
|
|
801
|
+
language
|
|
802
|
+
};
|
|
803
|
+
_.hooks.run("before-tokenize", env);
|
|
804
|
+
if (!env.grammar) {
|
|
805
|
+
throw new Error('The language "' + env.language + '" has no grammar.');
|
|
806
|
+
}
|
|
807
|
+
env.tokens = _.tokenize(env.code, env.grammar);
|
|
808
|
+
_.hooks.run("after-tokenize", env);
|
|
809
|
+
return Token.stringify(_.util.encode(env.tokens), env.language);
|
|
810
|
+
},
|
|
811
|
+
/**
|
|
812
|
+
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
813
|
+
* and the language definitions to use, and returns an array with the tokenized code.
|
|
814
|
+
*
|
|
815
|
+
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
816
|
+
*
|
|
817
|
+
* This method could be useful in other contexts as well, as a very crude parser.
|
|
818
|
+
*
|
|
819
|
+
* @param {string} text A string with the code to be highlighted.
|
|
820
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
821
|
+
*
|
|
822
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
823
|
+
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
824
|
+
* @memberof Prism
|
|
825
|
+
* @public
|
|
826
|
+
* @example
|
|
827
|
+
* let code = `var foo = 0;`;
|
|
828
|
+
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
829
|
+
* tokens.forEach(token => {
|
|
830
|
+
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
831
|
+
* console.log(`Found numeric literal: ${token.content}`);
|
|
832
|
+
* }
|
|
833
|
+
* });
|
|
834
|
+
*/
|
|
835
|
+
tokenize: function(text, grammar) {
|
|
836
|
+
var rest = grammar.rest;
|
|
837
|
+
if (rest) {
|
|
838
|
+
for (var token in rest) {
|
|
839
|
+
grammar[token] = rest[token];
|
|
840
|
+
}
|
|
841
|
+
delete grammar.rest;
|
|
842
|
+
}
|
|
843
|
+
var tokenList = new LinkedList();
|
|
844
|
+
addAfter(tokenList, tokenList.head, text);
|
|
845
|
+
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
|
846
|
+
return toArray(tokenList);
|
|
847
|
+
},
|
|
848
|
+
/**
|
|
849
|
+
* @namespace
|
|
850
|
+
* @memberof Prism
|
|
851
|
+
* @public
|
|
852
|
+
*/
|
|
853
|
+
hooks: {
|
|
854
|
+
all: {},
|
|
855
|
+
/**
|
|
856
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
857
|
+
*
|
|
858
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
859
|
+
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
860
|
+
*
|
|
861
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
862
|
+
*
|
|
863
|
+
* @param {string} name The name of the hook.
|
|
864
|
+
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
865
|
+
* @public
|
|
866
|
+
*/
|
|
867
|
+
add: function(name, callback) {
|
|
868
|
+
var hooks = _.hooks.all;
|
|
869
|
+
hooks[name] = hooks[name] || [];
|
|
870
|
+
hooks[name].push(callback);
|
|
871
|
+
},
|
|
872
|
+
/**
|
|
873
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
874
|
+
*
|
|
875
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
876
|
+
*
|
|
877
|
+
* @param {string} name The name of the hook.
|
|
878
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
879
|
+
* @public
|
|
880
|
+
*/
|
|
881
|
+
run: function(name, env) {
|
|
882
|
+
var callbacks = _.hooks.all[name];
|
|
883
|
+
if (!callbacks || !callbacks.length) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
for (var i = 0, callback; callback = callbacks[i++]; ) {
|
|
887
|
+
callback(env);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
Token
|
|
892
|
+
};
|
|
893
|
+
_self2.Prism = _;
|
|
894
|
+
function Token(type, content, alias, matchedStr) {
|
|
895
|
+
this.type = type;
|
|
896
|
+
this.content = content;
|
|
897
|
+
this.alias = alias;
|
|
898
|
+
this.length = (matchedStr || "").length | 0;
|
|
899
|
+
}
|
|
900
|
+
Token.stringify = function stringify(o, language) {
|
|
901
|
+
if (typeof o == "string") {
|
|
902
|
+
return o;
|
|
903
|
+
}
|
|
904
|
+
if (Array.isArray(o)) {
|
|
905
|
+
var s = "";
|
|
906
|
+
o.forEach(function(e) {
|
|
907
|
+
s += stringify(e, language);
|
|
908
|
+
});
|
|
909
|
+
return s;
|
|
910
|
+
}
|
|
911
|
+
var env = {
|
|
912
|
+
type: o.type,
|
|
913
|
+
content: stringify(o.content, language),
|
|
914
|
+
tag: "span",
|
|
915
|
+
classes: ["token", o.type],
|
|
916
|
+
attributes: {},
|
|
917
|
+
language
|
|
918
|
+
};
|
|
919
|
+
var aliases = o.alias;
|
|
920
|
+
if (aliases) {
|
|
921
|
+
if (Array.isArray(aliases)) {
|
|
922
|
+
Array.prototype.push.apply(env.classes, aliases);
|
|
923
|
+
} else {
|
|
924
|
+
env.classes.push(aliases);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
_.hooks.run("wrap", env);
|
|
928
|
+
var attributes = "";
|
|
929
|
+
for (var name in env.attributes) {
|
|
930
|
+
attributes += " " + name + '="' + (env.attributes[name] || "").replace(/"/g, """) + '"';
|
|
931
|
+
}
|
|
932
|
+
return "<" + env.tag + ' class="' + env.classes.join(" ") + '"' + attributes + ">" + env.content + "</" + env.tag + ">";
|
|
933
|
+
};
|
|
934
|
+
function matchPattern(pattern, pos, text, lookbehind) {
|
|
935
|
+
pattern.lastIndex = pos;
|
|
936
|
+
var match = pattern.exec(text);
|
|
937
|
+
if (match && lookbehind && match[1]) {
|
|
938
|
+
var lookbehindLength = match[1].length;
|
|
939
|
+
match.index += lookbehindLength;
|
|
940
|
+
match[0] = match[0].slice(lookbehindLength);
|
|
941
|
+
}
|
|
942
|
+
return match;
|
|
943
|
+
}
|
|
944
|
+
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
945
|
+
for (var token in grammar) {
|
|
946
|
+
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
var patterns = grammar[token];
|
|
950
|
+
patterns = Array.isArray(patterns) ? patterns : [patterns];
|
|
951
|
+
for (var j2 = 0; j2 < patterns.length; ++j2) {
|
|
952
|
+
if (rematch && rematch.cause == token + "," + j2) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
var patternObj = patterns[j2];
|
|
956
|
+
var inside = patternObj.inside;
|
|
957
|
+
var lookbehind = !!patternObj.lookbehind;
|
|
958
|
+
var greedy = !!patternObj.greedy;
|
|
959
|
+
var alias = patternObj.alias;
|
|
960
|
+
if (greedy && !patternObj.pattern.global) {
|
|
961
|
+
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
|
962
|
+
patternObj.pattern = RegExp(patternObj.pattern.source, flags + "g");
|
|
963
|
+
}
|
|
964
|
+
var pattern = patternObj.pattern || patternObj;
|
|
965
|
+
for (var currentNode = startNode.next, pos = startPos; currentNode !== tokenList.tail; pos += currentNode.value.length, currentNode = currentNode.next) {
|
|
966
|
+
if (rematch && pos >= rematch.reach) {
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
var str = currentNode.value;
|
|
970
|
+
if (tokenList.length > text.length) {
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
if (str instanceof Token) {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
var removeCount = 1;
|
|
977
|
+
var match;
|
|
978
|
+
if (greedy) {
|
|
979
|
+
match = matchPattern(pattern, pos, text, lookbehind);
|
|
980
|
+
if (!match || match.index >= text.length) {
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
var from = match.index;
|
|
984
|
+
var to = match.index + match[0].length;
|
|
985
|
+
var p = pos;
|
|
986
|
+
p += currentNode.value.length;
|
|
987
|
+
while (from >= p) {
|
|
988
|
+
currentNode = currentNode.next;
|
|
989
|
+
p += currentNode.value.length;
|
|
990
|
+
}
|
|
991
|
+
p -= currentNode.value.length;
|
|
992
|
+
pos = p;
|
|
993
|
+
if (currentNode.value instanceof Token) {
|
|
994
|
+
continue;
|
|
995
|
+
}
|
|
996
|
+
for (var k = currentNode; k !== tokenList.tail && (p < to || typeof k.value === "string"); k = k.next) {
|
|
997
|
+
removeCount++;
|
|
998
|
+
p += k.value.length;
|
|
999
|
+
}
|
|
1000
|
+
removeCount--;
|
|
1001
|
+
str = text.slice(pos, p);
|
|
1002
|
+
match.index -= pos;
|
|
1003
|
+
} else {
|
|
1004
|
+
match = matchPattern(pattern, 0, str, lookbehind);
|
|
1005
|
+
if (!match) {
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
var from = match.index;
|
|
1010
|
+
var matchStr = match[0];
|
|
1011
|
+
var before = str.slice(0, from);
|
|
1012
|
+
var after = str.slice(from + matchStr.length);
|
|
1013
|
+
var reach = pos + str.length;
|
|
1014
|
+
if (rematch && reach > rematch.reach) {
|
|
1015
|
+
rematch.reach = reach;
|
|
1016
|
+
}
|
|
1017
|
+
var removeFrom = currentNode.prev;
|
|
1018
|
+
if (before) {
|
|
1019
|
+
removeFrom = addAfter(tokenList, removeFrom, before);
|
|
1020
|
+
pos += before.length;
|
|
1021
|
+
}
|
|
1022
|
+
removeRange(tokenList, removeFrom, removeCount);
|
|
1023
|
+
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
|
1024
|
+
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
|
1025
|
+
if (after) {
|
|
1026
|
+
addAfter(tokenList, currentNode, after);
|
|
1027
|
+
}
|
|
1028
|
+
if (removeCount > 1) {
|
|
1029
|
+
var nestedRematch = {
|
|
1030
|
+
cause: token + "," + j2,
|
|
1031
|
+
reach
|
|
1032
|
+
};
|
|
1033
|
+
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
|
1034
|
+
if (rematch && nestedRematch.reach > rematch.reach) {
|
|
1035
|
+
rematch.reach = nestedRematch.reach;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function LinkedList() {
|
|
1043
|
+
var head = { value: null, prev: null, next: null };
|
|
1044
|
+
var tail = { value: null, prev: head, next: null };
|
|
1045
|
+
head.next = tail;
|
|
1046
|
+
this.head = head;
|
|
1047
|
+
this.tail = tail;
|
|
1048
|
+
this.length = 0;
|
|
1049
|
+
}
|
|
1050
|
+
function addAfter(list, node, value) {
|
|
1051
|
+
var next = node.next;
|
|
1052
|
+
var newNode = { value, prev: node, next };
|
|
1053
|
+
node.next = newNode;
|
|
1054
|
+
next.prev = newNode;
|
|
1055
|
+
list.length++;
|
|
1056
|
+
return newNode;
|
|
1057
|
+
}
|
|
1058
|
+
function removeRange(list, node, count) {
|
|
1059
|
+
var next = node.next;
|
|
1060
|
+
for (var i = 0; i < count && next !== list.tail; i++) {
|
|
1061
|
+
next = next.next;
|
|
1062
|
+
}
|
|
1063
|
+
node.next = next;
|
|
1064
|
+
next.prev = node;
|
|
1065
|
+
list.length -= i;
|
|
1066
|
+
}
|
|
1067
|
+
function toArray(list) {
|
|
1068
|
+
var array = [];
|
|
1069
|
+
var node = list.head.next;
|
|
1070
|
+
while (node !== list.tail) {
|
|
1071
|
+
array.push(node.value);
|
|
1072
|
+
node = node.next;
|
|
1073
|
+
}
|
|
1074
|
+
return array;
|
|
1075
|
+
}
|
|
1076
|
+
if (!_self2.document) {
|
|
1077
|
+
if (!_self2.addEventListener) {
|
|
1078
|
+
return _;
|
|
1079
|
+
}
|
|
1080
|
+
if (!_.disableWorkerMessageHandler) {
|
|
1081
|
+
_self2.addEventListener("message", function(evt) {
|
|
1082
|
+
var message = JSON.parse(evt.data);
|
|
1083
|
+
var lang2 = message.language;
|
|
1084
|
+
var code = message.code;
|
|
1085
|
+
var immediateClose = message.immediateClose;
|
|
1086
|
+
_self2.postMessage(_.highlight(code, _.languages[lang2], lang2));
|
|
1087
|
+
if (immediateClose) {
|
|
1088
|
+
_self2.close();
|
|
1089
|
+
}
|
|
1090
|
+
}, false);
|
|
1091
|
+
}
|
|
1092
|
+
return _;
|
|
1093
|
+
}
|
|
1094
|
+
var script = _.util.currentScript();
|
|
1095
|
+
if (script) {
|
|
1096
|
+
_.filename = script.src;
|
|
1097
|
+
if (script.hasAttribute("data-manual")) {
|
|
1098
|
+
_.manual = true;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
function highlightAutomaticallyCallback() {
|
|
1102
|
+
if (!_.manual) {
|
|
1103
|
+
_.highlightAll();
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (!_.manual) {
|
|
1107
|
+
var readyState = document.readyState;
|
|
1108
|
+
if (readyState === "loading" || readyState === "interactive" && script && script.defer) {
|
|
1109
|
+
document.addEventListener("DOMContentLoaded", highlightAutomaticallyCallback);
|
|
1110
|
+
} else {
|
|
1111
|
+
if (window.requestAnimationFrame) {
|
|
1112
|
+
window.requestAnimationFrame(highlightAutomaticallyCallback);
|
|
1113
|
+
} else {
|
|
1114
|
+
window.setTimeout(highlightAutomaticallyCallback, 16);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return _;
|
|
1119
|
+
}(_self);
|
|
1120
|
+
if (module.exports) {
|
|
1121
|
+
module.exports = Prism2;
|
|
1122
|
+
}
|
|
1123
|
+
if (typeof commonjsGlobal !== "undefined") {
|
|
1124
|
+
commonjsGlobal.Prism = Prism2;
|
|
1125
|
+
}
|
|
1126
|
+
Prism2.languages.markup = {
|
|
1127
|
+
"comment": {
|
|
1128
|
+
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
|
1129
|
+
greedy: true
|
|
1130
|
+
},
|
|
1131
|
+
"prolog": {
|
|
1132
|
+
pattern: /<\?[\s\S]+?\?>/,
|
|
1133
|
+
greedy: true
|
|
1134
|
+
},
|
|
1135
|
+
"doctype": {
|
|
1136
|
+
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
|
1137
|
+
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
|
1138
|
+
greedy: true,
|
|
1139
|
+
inside: {
|
|
1140
|
+
"internal-subset": {
|
|
1141
|
+
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
|
1142
|
+
lookbehind: true,
|
|
1143
|
+
greedy: true,
|
|
1144
|
+
inside: null
|
|
1145
|
+
// see below
|
|
1146
|
+
},
|
|
1147
|
+
"string": {
|
|
1148
|
+
pattern: /"[^"]*"|'[^']*'/,
|
|
1149
|
+
greedy: true
|
|
1150
|
+
},
|
|
1151
|
+
"punctuation": /^<!|>$|[[\]]/,
|
|
1152
|
+
"doctype-tag": /^DOCTYPE/i,
|
|
1153
|
+
"name": /[^\s<>'"]+/
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
"cdata": {
|
|
1157
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
1158
|
+
greedy: true
|
|
1159
|
+
},
|
|
1160
|
+
"tag": {
|
|
1161
|
+
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
|
1162
|
+
greedy: true,
|
|
1163
|
+
inside: {
|
|
1164
|
+
"tag": {
|
|
1165
|
+
pattern: /^<\/?[^\s>\/]+/,
|
|
1166
|
+
inside: {
|
|
1167
|
+
"punctuation": /^<\/?/,
|
|
1168
|
+
"namespace": /^[^\s>\/:]+:/
|
|
1169
|
+
}
|
|
1170
|
+
},
|
|
1171
|
+
"special-attr": [],
|
|
1172
|
+
"attr-value": {
|
|
1173
|
+
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
|
1174
|
+
inside: {
|
|
1175
|
+
"punctuation": [
|
|
1176
|
+
{
|
|
1177
|
+
pattern: /^=/,
|
|
1178
|
+
alias: "attr-equals"
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
pattern: /^(\s*)["']|["']$/,
|
|
1182
|
+
lookbehind: true
|
|
1183
|
+
}
|
|
1184
|
+
]
|
|
1185
|
+
}
|
|
1186
|
+
},
|
|
1187
|
+
"punctuation": /\/?>/,
|
|
1188
|
+
"attr-name": {
|
|
1189
|
+
pattern: /[^\s>\/]+/,
|
|
1190
|
+
inside: {
|
|
1191
|
+
"namespace": /^[^\s>\/:]+:/
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
"entity": [
|
|
1197
|
+
{
|
|
1198
|
+
pattern: /&[\da-z]{1,8};/i,
|
|
1199
|
+
alias: "named-entity"
|
|
1200
|
+
},
|
|
1201
|
+
/&#x?[\da-f]{1,8};/i
|
|
1202
|
+
]
|
|
1203
|
+
};
|
|
1204
|
+
Prism2.languages.markup["tag"].inside["attr-value"].inside["entity"] = Prism2.languages.markup["entity"];
|
|
1205
|
+
Prism2.languages.markup["doctype"].inside["internal-subset"].inside = Prism2.languages.markup;
|
|
1206
|
+
Prism2.hooks.add("wrap", function(env) {
|
|
1207
|
+
if (env.type === "entity") {
|
|
1208
|
+
env.attributes["title"] = env.content.replace(/&/, "&");
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
Object.defineProperty(Prism2.languages.markup.tag, "addInlined", {
|
|
1212
|
+
/**
|
|
1213
|
+
* Adds an inlined language to markup.
|
|
1214
|
+
*
|
|
1215
|
+
* An example of an inlined language is CSS with `<style>` tags.
|
|
1216
|
+
*
|
|
1217
|
+
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
|
1218
|
+
* case insensitive.
|
|
1219
|
+
* @param {string} lang The language key.
|
|
1220
|
+
* @example
|
|
1221
|
+
* addInlined('style', 'css');
|
|
1222
|
+
*/
|
|
1223
|
+
value: function addInlined(tagName, lang) {
|
|
1224
|
+
var includedCdataInside = {};
|
|
1225
|
+
includedCdataInside["language-" + lang] = {
|
|
1226
|
+
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
|
1227
|
+
lookbehind: true,
|
|
1228
|
+
inside: Prism2.languages[lang]
|
|
1229
|
+
};
|
|
1230
|
+
includedCdataInside["cdata"] = /^<!\[CDATA\[|\]\]>$/i;
|
|
1231
|
+
var inside = {
|
|
1232
|
+
"included-cdata": {
|
|
1233
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
|
1234
|
+
inside: includedCdataInside
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
inside["language-" + lang] = {
|
|
1238
|
+
pattern: /[\s\S]+/,
|
|
1239
|
+
inside: Prism2.languages[lang]
|
|
1240
|
+
};
|
|
1241
|
+
var def = {};
|
|
1242
|
+
def[tagName] = {
|
|
1243
|
+
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function() {
|
|
1244
|
+
return tagName;
|
|
1245
|
+
}), "i"),
|
|
1246
|
+
lookbehind: true,
|
|
1247
|
+
greedy: true,
|
|
1248
|
+
inside
|
|
1249
|
+
};
|
|
1250
|
+
Prism2.languages.insertBefore("markup", "cdata", def);
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
Object.defineProperty(Prism2.languages.markup.tag, "addAttribute", {
|
|
1254
|
+
/**
|
|
1255
|
+
* Adds an pattern to highlight languages embedded in HTML attributes.
|
|
1256
|
+
*
|
|
1257
|
+
* An example of an inlined language is CSS with `style` attributes.
|
|
1258
|
+
*
|
|
1259
|
+
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
|
1260
|
+
* case insensitive.
|
|
1261
|
+
* @param {string} lang The language key.
|
|
1262
|
+
* @example
|
|
1263
|
+
* addAttribute('style', 'css');
|
|
1264
|
+
*/
|
|
1265
|
+
value: function(attrName, lang) {
|
|
1266
|
+
Prism2.languages.markup.tag.inside["special-attr"].push({
|
|
1267
|
+
pattern: RegExp(
|
|
1268
|
+
/(^|["'\s])/.source + "(?:" + attrName + ")" + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
|
1269
|
+
"i"
|
|
1270
|
+
),
|
|
1271
|
+
lookbehind: true,
|
|
1272
|
+
inside: {
|
|
1273
|
+
"attr-name": /^[^\s=]+/,
|
|
1274
|
+
"attr-value": {
|
|
1275
|
+
pattern: /=[\s\S]+/,
|
|
1276
|
+
inside: {
|
|
1277
|
+
"value": {
|
|
1278
|
+
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
|
1279
|
+
lookbehind: true,
|
|
1280
|
+
alias: [lang, "language-" + lang],
|
|
1281
|
+
inside: Prism2.languages[lang]
|
|
1282
|
+
},
|
|
1283
|
+
"punctuation": [
|
|
1284
|
+
{
|
|
1285
|
+
pattern: /^=/,
|
|
1286
|
+
alias: "attr-equals"
|
|
1287
|
+
},
|
|
1288
|
+
/"|'/
|
|
1289
|
+
]
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
Prism2.languages.html = Prism2.languages.markup;
|
|
1297
|
+
Prism2.languages.mathml = Prism2.languages.markup;
|
|
1298
|
+
Prism2.languages.svg = Prism2.languages.markup;
|
|
1299
|
+
Prism2.languages.xml = Prism2.languages.extend("markup", {});
|
|
1300
|
+
Prism2.languages.ssml = Prism2.languages.xml;
|
|
1301
|
+
Prism2.languages.atom = Prism2.languages.xml;
|
|
1302
|
+
Prism2.languages.rss = Prism2.languages.xml;
|
|
1303
|
+
(function(Prism3) {
|
|
1304
|
+
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
|
1305
|
+
Prism3.languages.css = {
|
|
1306
|
+
"comment": /\/\*[\s\S]*?\*\//,
|
|
1307
|
+
"atrule": {
|
|
1308
|
+
pattern: RegExp("@[\\w-](?:" + /[^;{\s"']|\s+(?!\s)/.source + "|" + string.source + ")*?" + /(?:;|(?=\s*\{))/.source),
|
|
1309
|
+
inside: {
|
|
1310
|
+
"rule": /^@[\w-]+/,
|
|
1311
|
+
"selector-function-argument": {
|
|
1312
|
+
pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
|
1313
|
+
lookbehind: true,
|
|
1314
|
+
alias: "selector"
|
|
1315
|
+
},
|
|
1316
|
+
"keyword": {
|
|
1317
|
+
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
|
1318
|
+
lookbehind: true
|
|
1319
|
+
}
|
|
1320
|
+
// See rest below
|
|
1321
|
+
}
|
|
1322
|
+
},
|
|
1323
|
+
"url": {
|
|
1324
|
+
// https://drafts.csswg.org/css-values-3/#urls
|
|
1325
|
+
pattern: RegExp("\\burl\\((?:" + string.source + "|" + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ")\\)", "i"),
|
|
1326
|
+
greedy: true,
|
|
1327
|
+
inside: {
|
|
1328
|
+
"function": /^url/i,
|
|
1329
|
+
"punctuation": /^\(|\)$/,
|
|
1330
|
+
"string": {
|
|
1331
|
+
pattern: RegExp("^" + string.source + "$"),
|
|
1332
|
+
alias: "url"
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
},
|
|
1336
|
+
"selector": {
|
|
1337
|
+
pattern: RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|` + string.source + ")*(?=\\s*\\{)"),
|
|
1338
|
+
lookbehind: true
|
|
1339
|
+
},
|
|
1340
|
+
"string": {
|
|
1341
|
+
pattern: string,
|
|
1342
|
+
greedy: true
|
|
1343
|
+
},
|
|
1344
|
+
"property": {
|
|
1345
|
+
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
|
1346
|
+
lookbehind: true
|
|
1347
|
+
},
|
|
1348
|
+
"important": /!important\b/i,
|
|
1349
|
+
"function": {
|
|
1350
|
+
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
|
1351
|
+
lookbehind: true
|
|
1352
|
+
},
|
|
1353
|
+
"punctuation": /[(){};:,]/
|
|
1354
|
+
};
|
|
1355
|
+
Prism3.languages.css["atrule"].inside.rest = Prism3.languages.css;
|
|
1356
|
+
var markup = Prism3.languages.markup;
|
|
1357
|
+
if (markup) {
|
|
1358
|
+
markup.tag.addInlined("style", "css");
|
|
1359
|
+
markup.tag.addAttribute("style", "css");
|
|
1360
|
+
}
|
|
1361
|
+
})(Prism2);
|
|
1362
|
+
Prism2.languages.clike = {
|
|
1363
|
+
"comment": [
|
|
1364
|
+
{
|
|
1365
|
+
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
1366
|
+
lookbehind: true,
|
|
1367
|
+
greedy: true
|
|
1368
|
+
},
|
|
1369
|
+
{
|
|
1370
|
+
pattern: /(^|[^\\:])\/\/.*/,
|
|
1371
|
+
lookbehind: true,
|
|
1372
|
+
greedy: true
|
|
1373
|
+
}
|
|
1374
|
+
],
|
|
1375
|
+
"string": {
|
|
1376
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
1377
|
+
greedy: true
|
|
1378
|
+
},
|
|
1379
|
+
"class-name": {
|
|
1380
|
+
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
1381
|
+
lookbehind: true,
|
|
1382
|
+
inside: {
|
|
1383
|
+
"punctuation": /[.\\]/
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
"keyword": /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
1387
|
+
"boolean": /\b(?:false|true)\b/,
|
|
1388
|
+
"function": /\b\w+(?=\()/,
|
|
1389
|
+
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
1390
|
+
"operator": /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
1391
|
+
"punctuation": /[{}[\];(),.:]/
|
|
1392
|
+
};
|
|
1393
|
+
Prism2.languages.javascript = Prism2.languages.extend("clike", {
|
|
1394
|
+
"class-name": [
|
|
1395
|
+
Prism2.languages.clike["class-name"],
|
|
1396
|
+
{
|
|
1397
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
1398
|
+
lookbehind: true
|
|
1399
|
+
}
|
|
1400
|
+
],
|
|
1401
|
+
"keyword": [
|
|
1402
|
+
{
|
|
1403
|
+
pattern: /((?:^|\})\s*)catch\b/,
|
|
1404
|
+
lookbehind: true
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
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/,
|
|
1408
|
+
lookbehind: true
|
|
1409
|
+
}
|
|
1410
|
+
],
|
|
1411
|
+
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
1412
|
+
"function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
1413
|
+
"number": {
|
|
1414
|
+
pattern: RegExp(
|
|
1415
|
+
/(^|[^\w$])/.source + "(?:" + // constant
|
|
1416
|
+
(/NaN|Infinity/.source + "|" + // binary integer
|
|
1417
|
+
/0[bB][01]+(?:_[01]+)*n?/.source + "|" + // octal integer
|
|
1418
|
+
/0[oO][0-7]+(?:_[0-7]+)*n?/.source + "|" + // hexadecimal integer
|
|
1419
|
+
/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source + "|" + // decimal bigint
|
|
1420
|
+
/\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
|
|
1421
|
+
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
|
|
1422
|
+
),
|
|
1423
|
+
lookbehind: true
|
|
1424
|
+
},
|
|
1425
|
+
"operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
1426
|
+
});
|
|
1427
|
+
Prism2.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
1428
|
+
Prism2.languages.insertBefore("javascript", "keyword", {
|
|
1429
|
+
"regex": {
|
|
1430
|
+
pattern: RegExp(
|
|
1431
|
+
// lookbehind
|
|
1432
|
+
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
1433
|
+
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source + // Regex pattern:
|
|
1434
|
+
// There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
|
|
1435
|
+
// classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
|
|
1436
|
+
// with the only syntax, so we have to define 2 different regex patterns.
|
|
1437
|
+
/\//.source + "(?:" + /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source + "|" + // `v` flag syntax. This supports 3 levels of nested character classes.
|
|
1438
|
+
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
|
|
1439
|
+
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
1440
|
+
),
|
|
1441
|
+
lookbehind: true,
|
|
1442
|
+
greedy: true,
|
|
1443
|
+
inside: {
|
|
1444
|
+
"regex-source": {
|
|
1445
|
+
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
1446
|
+
lookbehind: true,
|
|
1447
|
+
alias: "language-regex",
|
|
1448
|
+
inside: Prism2.languages.regex
|
|
1449
|
+
},
|
|
1450
|
+
"regex-delimiter": /^\/|\/$/,
|
|
1451
|
+
"regex-flags": /^[a-z]+$/
|
|
1452
|
+
}
|
|
1453
|
+
},
|
|
1454
|
+
// This must be declared before keyword because we use "function" inside the look-forward
|
|
1455
|
+
"function-variable": {
|
|
1456
|
+
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*=>))/,
|
|
1457
|
+
alias: "function"
|
|
1458
|
+
},
|
|
1459
|
+
"parameter": [
|
|
1460
|
+
{
|
|
1461
|
+
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
1462
|
+
lookbehind: true,
|
|
1463
|
+
inside: Prism2.languages.javascript
|
|
1464
|
+
},
|
|
1465
|
+
{
|
|
1466
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
1467
|
+
lookbehind: true,
|
|
1468
|
+
inside: Prism2.languages.javascript
|
|
1469
|
+
},
|
|
1470
|
+
{
|
|
1471
|
+
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
1472
|
+
lookbehind: true,
|
|
1473
|
+
inside: Prism2.languages.javascript
|
|
1474
|
+
},
|
|
1475
|
+
{
|
|
1476
|
+
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*\{)/,
|
|
1477
|
+
lookbehind: true,
|
|
1478
|
+
inside: Prism2.languages.javascript
|
|
1479
|
+
}
|
|
1480
|
+
],
|
|
1481
|
+
"constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
1482
|
+
});
|
|
1483
|
+
Prism2.languages.insertBefore("javascript", "string", {
|
|
1484
|
+
"hashbang": {
|
|
1485
|
+
pattern: /^#!.*/,
|
|
1486
|
+
greedy: true,
|
|
1487
|
+
alias: "comment"
|
|
1488
|
+
},
|
|
1489
|
+
"template-string": {
|
|
1490
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
1491
|
+
greedy: true,
|
|
1492
|
+
inside: {
|
|
1493
|
+
"template-punctuation": {
|
|
1494
|
+
pattern: /^`|`$/,
|
|
1495
|
+
alias: "string"
|
|
1496
|
+
},
|
|
1497
|
+
"interpolation": {
|
|
1498
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
1499
|
+
lookbehind: true,
|
|
1500
|
+
inside: {
|
|
1501
|
+
"interpolation-punctuation": {
|
|
1502
|
+
pattern: /^\$\{|\}$/,
|
|
1503
|
+
alias: "punctuation"
|
|
1504
|
+
},
|
|
1505
|
+
rest: Prism2.languages.javascript
|
|
1506
|
+
}
|
|
1507
|
+
},
|
|
1508
|
+
"string": /[\s\S]+/
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
"string-property": {
|
|
1512
|
+
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
1513
|
+
lookbehind: true,
|
|
1514
|
+
greedy: true,
|
|
1515
|
+
alias: "property"
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
Prism2.languages.insertBefore("javascript", "operator", {
|
|
1519
|
+
"literal-property": {
|
|
1520
|
+
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
1521
|
+
lookbehind: true,
|
|
1522
|
+
alias: "property"
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
if (Prism2.languages.markup) {
|
|
1526
|
+
Prism2.languages.markup.tag.addInlined("script", "javascript");
|
|
1527
|
+
Prism2.languages.markup.tag.addAttribute(
|
|
1528
|
+
/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,
|
|
1529
|
+
"javascript"
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
Prism2.languages.js = Prism2.languages.javascript;
|
|
1533
|
+
(function() {
|
|
1534
|
+
if (typeof Prism2 === "undefined" || typeof document === "undefined") {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (!Element.prototype.matches) {
|
|
1538
|
+
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
1539
|
+
}
|
|
1540
|
+
var LOADING_MESSAGE = "Loading…";
|
|
1541
|
+
var FAILURE_MESSAGE = function(status, message) {
|
|
1542
|
+
return "✖ Error " + status + " while fetching file: " + message;
|
|
1543
|
+
};
|
|
1544
|
+
var FAILURE_EMPTY_MESSAGE = "✖ Error: File does not exist or is empty";
|
|
1545
|
+
var EXTENSIONS = {
|
|
1546
|
+
"js": "javascript",
|
|
1547
|
+
"py": "python",
|
|
1548
|
+
"rb": "ruby",
|
|
1549
|
+
"ps1": "powershell",
|
|
1550
|
+
"psm1": "powershell",
|
|
1551
|
+
"sh": "bash",
|
|
1552
|
+
"bat": "batch",
|
|
1553
|
+
"h": "c",
|
|
1554
|
+
"tex": "latex"
|
|
1555
|
+
};
|
|
1556
|
+
var STATUS_ATTR = "data-src-status";
|
|
1557
|
+
var STATUS_LOADING = "loading";
|
|
1558
|
+
var STATUS_LOADED = "loaded";
|
|
1559
|
+
var STATUS_FAILED = "failed";
|
|
1560
|
+
var SELECTOR = "pre[data-src]:not([" + STATUS_ATTR + '="' + STATUS_LOADED + '"]):not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
|
|
1561
|
+
function loadFile(src, success, error) {
|
|
1562
|
+
var xhr = new XMLHttpRequest();
|
|
1563
|
+
xhr.open("GET", src, true);
|
|
1564
|
+
xhr.onreadystatechange = function() {
|
|
1565
|
+
if (xhr.readyState == 4) {
|
|
1566
|
+
if (xhr.status < 400 && xhr.responseText) {
|
|
1567
|
+
success(xhr.responseText);
|
|
1568
|
+
} else {
|
|
1569
|
+
if (xhr.status >= 400) {
|
|
1570
|
+
error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
|
|
1571
|
+
} else {
|
|
1572
|
+
error(FAILURE_EMPTY_MESSAGE);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
xhr.send(null);
|
|
1578
|
+
}
|
|
1579
|
+
function parseRange(range) {
|
|
1580
|
+
var m2 = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || "");
|
|
1581
|
+
if (m2) {
|
|
1582
|
+
var start = Number(m2[1]);
|
|
1583
|
+
var comma = m2[2];
|
|
1584
|
+
var end = m2[3];
|
|
1585
|
+
if (!comma) {
|
|
1586
|
+
return [start, start];
|
|
1587
|
+
}
|
|
1588
|
+
if (!end) {
|
|
1589
|
+
return [start, void 0];
|
|
1590
|
+
}
|
|
1591
|
+
return [start, Number(end)];
|
|
1592
|
+
}
|
|
1593
|
+
return void 0;
|
|
1594
|
+
}
|
|
1595
|
+
Prism2.hooks.add("before-highlightall", function(env) {
|
|
1596
|
+
env.selector += ", " + SELECTOR;
|
|
1597
|
+
});
|
|
1598
|
+
Prism2.hooks.add("before-sanity-check", function(env) {
|
|
1599
|
+
var pre = (
|
|
1600
|
+
/** @type {HTMLPreElement} */
|
|
1601
|
+
env.element
|
|
1602
|
+
);
|
|
1603
|
+
if (pre.matches(SELECTOR)) {
|
|
1604
|
+
env.code = "";
|
|
1605
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADING);
|
|
1606
|
+
var code = pre.appendChild(document.createElement("CODE"));
|
|
1607
|
+
code.textContent = LOADING_MESSAGE;
|
|
1608
|
+
var src = pre.getAttribute("data-src");
|
|
1609
|
+
var language = env.language;
|
|
1610
|
+
if (language === "none") {
|
|
1611
|
+
var extension = (/\.(\w+)$/.exec(src) || [, "none"])[1];
|
|
1612
|
+
language = EXTENSIONS[extension] || extension;
|
|
1613
|
+
}
|
|
1614
|
+
Prism2.util.setLanguage(code, language);
|
|
1615
|
+
Prism2.util.setLanguage(pre, language);
|
|
1616
|
+
var autoloader = Prism2.plugins.autoloader;
|
|
1617
|
+
if (autoloader) {
|
|
1618
|
+
autoloader.loadLanguages(language);
|
|
1619
|
+
}
|
|
1620
|
+
loadFile(
|
|
1621
|
+
src,
|
|
1622
|
+
function(text) {
|
|
1623
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
|
|
1624
|
+
var range = parseRange(pre.getAttribute("data-range"));
|
|
1625
|
+
if (range) {
|
|
1626
|
+
var lines = text.split(/\r\n?|\n/g);
|
|
1627
|
+
var start = range[0];
|
|
1628
|
+
var end = range[1] == null ? lines.length : range[1];
|
|
1629
|
+
if (start < 0) {
|
|
1630
|
+
start += lines.length;
|
|
1631
|
+
}
|
|
1632
|
+
start = Math.max(0, Math.min(start - 1, lines.length));
|
|
1633
|
+
if (end < 0) {
|
|
1634
|
+
end += lines.length;
|
|
1635
|
+
}
|
|
1636
|
+
end = Math.max(0, Math.min(end, lines.length));
|
|
1637
|
+
text = lines.slice(start, end).join("\n");
|
|
1638
|
+
if (!pre.hasAttribute("data-start")) {
|
|
1639
|
+
pre.setAttribute("data-start", String(start + 1));
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
code.textContent = text;
|
|
1643
|
+
Prism2.highlightElement(code);
|
|
1644
|
+
},
|
|
1645
|
+
function(error) {
|
|
1646
|
+
pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
|
|
1647
|
+
code.textContent = error;
|
|
1648
|
+
}
|
|
1649
|
+
);
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
Prism2.plugins.fileHighlight = {
|
|
1653
|
+
/**
|
|
1654
|
+
* Executes the File Highlight plugin for all matching `pre` elements under the given container.
|
|
1655
|
+
*
|
|
1656
|
+
* Note: Elements which are already loaded or currently loading will not be touched by this method.
|
|
1657
|
+
*
|
|
1658
|
+
* @param {ParentNode} [container=document]
|
|
1659
|
+
*/
|
|
1660
|
+
highlight: function highlight(container) {
|
|
1661
|
+
var elements = (container || document).querySelectorAll(SELECTOR);
|
|
1662
|
+
for (var i = 0, element; element = elements[i++]; ) {
|
|
1663
|
+
Prism2.highlightElement(element);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1667
|
+
var logged = false;
|
|
1668
|
+
Prism2.fileHighlight = function() {
|
|
1669
|
+
if (!logged) {
|
|
1670
|
+
console.warn("Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.");
|
|
1671
|
+
logged = true;
|
|
1672
|
+
}
|
|
1673
|
+
Prism2.plugins.fileHighlight.highlight.apply(this, arguments);
|
|
1674
|
+
};
|
|
1675
|
+
})();
|
|
1676
|
+
})(prism);
|
|
1677
|
+
var prismExports = prism.exports;
|
|
1678
|
+
const Prism$1 = /* @__PURE__ */ getDefaultExportFromCjs(prismExports);
|
|
4
1679
|
Prism.languages.clike = {
|
|
5
|
-
comment: [
|
|
1680
|
+
"comment": [
|
|
6
1681
|
{
|
|
7
1682
|
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
|
8
|
-
lookbehind:
|
|
9
|
-
greedy:
|
|
1683
|
+
lookbehind: true,
|
|
1684
|
+
greedy: true
|
|
10
1685
|
},
|
|
11
1686
|
{
|
|
12
1687
|
pattern: /(^|[^\\:])\/\/.*/,
|
|
13
|
-
lookbehind:
|
|
14
|
-
greedy:
|
|
1688
|
+
lookbehind: true,
|
|
1689
|
+
greedy: true
|
|
15
1690
|
}
|
|
16
1691
|
],
|
|
17
|
-
string: {
|
|
1692
|
+
"string": {
|
|
18
1693
|
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
|
19
|
-
greedy:
|
|
1694
|
+
greedy: true
|
|
20
1695
|
},
|
|
21
1696
|
"class-name": {
|
|
22
1697
|
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
|
23
|
-
lookbehind:
|
|
1698
|
+
lookbehind: true,
|
|
24
1699
|
inside: {
|
|
25
|
-
punctuation: /[.\\]/
|
|
1700
|
+
"punctuation": /[.\\]/
|
|
26
1701
|
}
|
|
27
1702
|
},
|
|
28
|
-
keyword: /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
29
|
-
boolean: /\b(?:false|true)\b/,
|
|
30
|
-
function: /\b\w+(?=\()/,
|
|
31
|
-
number: /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
32
|
-
operator: /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
33
|
-
punctuation: /[{}[\];(),.:]/
|
|
1703
|
+
"keyword": /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
|
1704
|
+
"boolean": /\b(?:false|true)\b/,
|
|
1705
|
+
"function": /\b\w+(?=\()/,
|
|
1706
|
+
"number": /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
|
1707
|
+
"operator": /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
|
1708
|
+
"punctuation": /[{}[\];(),.:]/
|
|
34
1709
|
};
|
|
35
1710
|
Prism.languages.javascript = Prism.languages.extend("clike", {
|
|
36
1711
|
"class-name": [
|
|
37
1712
|
Prism.languages.clike["class-name"],
|
|
38
1713
|
{
|
|
39
1714
|
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
|
40
|
-
lookbehind:
|
|
1715
|
+
lookbehind: true
|
|
41
1716
|
}
|
|
42
1717
|
],
|
|
43
|
-
keyword: [
|
|
1718
|
+
"keyword": [
|
|
44
1719
|
{
|
|
45
1720
|
pattern: /((?:^|\})\s*)catch\b/,
|
|
46
|
-
lookbehind:
|
|
1721
|
+
lookbehind: true
|
|
47
1722
|
},
|
|
48
1723
|
{
|
|
49
1724
|
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/,
|
|
50
|
-
lookbehind:
|
|
1725
|
+
lookbehind: true
|
|
51
1726
|
}
|
|
52
1727
|
],
|
|
53
1728
|
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
|
54
|
-
function: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
55
|
-
number: {
|
|
1729
|
+
"function": /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
|
1730
|
+
"number": {
|
|
56
1731
|
pattern: RegExp(
|
|
57
1732
|
/(^|[^\w$])/.source + "(?:" + // constant
|
|
58
1733
|
(/NaN|Infinity/.source + "|" + // binary integer
|
|
@@ -62,13 +1737,13 @@ Prism.languages.javascript = Prism.languages.extend("clike", {
|
|
|
62
1737
|
/\d+(?:_\d+)*n/.source + "|" + // decimal number (integer or float) but no bigint
|
|
63
1738
|
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source) + ")" + /(?![\w$])/.source
|
|
64
1739
|
),
|
|
65
|
-
lookbehind:
|
|
1740
|
+
lookbehind: true
|
|
66
1741
|
},
|
|
67
|
-
operator: /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
1742
|
+
"operator": /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
|
68
1743
|
});
|
|
69
1744
|
Prism.languages.javascript["class-name"][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
|
70
1745
|
Prism.languages.insertBefore("javascript", "keyword", {
|
|
71
|
-
regex: {
|
|
1746
|
+
"regex": {
|
|
72
1747
|
pattern: RegExp(
|
|
73
1748
|
// lookbehind
|
|
74
1749
|
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
|
@@ -80,12 +1755,12 @@ Prism.languages.insertBefore("javascript", "keyword", {
|
|
|
80
1755
|
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source + ")" + // lookahead
|
|
81
1756
|
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
|
82
1757
|
),
|
|
83
|
-
lookbehind:
|
|
84
|
-
greedy:
|
|
1758
|
+
lookbehind: true,
|
|
1759
|
+
greedy: true,
|
|
85
1760
|
inside: {
|
|
86
1761
|
"regex-source": {
|
|
87
1762
|
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
|
88
|
-
lookbehind:
|
|
1763
|
+
lookbehind: true,
|
|
89
1764
|
alias: "language-regex",
|
|
90
1765
|
inside: Prism.languages.regex
|
|
91
1766
|
},
|
|
@@ -98,47 +1773,47 @@ Prism.languages.insertBefore("javascript", "keyword", {
|
|
|
98
1773
|
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*=>))/,
|
|
99
1774
|
alias: "function"
|
|
100
1775
|
},
|
|
101
|
-
parameter: [
|
|
1776
|
+
"parameter": [
|
|
102
1777
|
{
|
|
103
1778
|
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
|
104
|
-
lookbehind:
|
|
1779
|
+
lookbehind: true,
|
|
105
1780
|
inside: Prism.languages.javascript
|
|
106
1781
|
},
|
|
107
1782
|
{
|
|
108
1783
|
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
|
109
|
-
lookbehind:
|
|
1784
|
+
lookbehind: true,
|
|
110
1785
|
inside: Prism.languages.javascript
|
|
111
1786
|
},
|
|
112
1787
|
{
|
|
113
1788
|
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
|
114
|
-
lookbehind:
|
|
1789
|
+
lookbehind: true,
|
|
115
1790
|
inside: Prism.languages.javascript
|
|
116
1791
|
},
|
|
117
1792
|
{
|
|
118
1793
|
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*\{)/,
|
|
119
|
-
lookbehind:
|
|
1794
|
+
lookbehind: true,
|
|
120
1795
|
inside: Prism.languages.javascript
|
|
121
1796
|
}
|
|
122
1797
|
],
|
|
123
|
-
constant: /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
1798
|
+
"constant": /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
|
124
1799
|
});
|
|
125
1800
|
Prism.languages.insertBefore("javascript", "string", {
|
|
126
|
-
hashbang: {
|
|
1801
|
+
"hashbang": {
|
|
127
1802
|
pattern: /^#!.*/,
|
|
128
|
-
greedy:
|
|
1803
|
+
greedy: true,
|
|
129
1804
|
alias: "comment"
|
|
130
1805
|
},
|
|
131
1806
|
"template-string": {
|
|
132
1807
|
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
|
133
|
-
greedy:
|
|
1808
|
+
greedy: true,
|
|
134
1809
|
inside: {
|
|
135
1810
|
"template-punctuation": {
|
|
136
1811
|
pattern: /^`|`$/,
|
|
137
1812
|
alias: "string"
|
|
138
1813
|
},
|
|
139
|
-
interpolation: {
|
|
1814
|
+
"interpolation": {
|
|
140
1815
|
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
|
141
|
-
lookbehind:
|
|
1816
|
+
lookbehind: true,
|
|
142
1817
|
inside: {
|
|
143
1818
|
"interpolation-punctuation": {
|
|
144
1819
|
pattern: /^\$\{|\}$/,
|
|
@@ -147,46 +1822,49 @@ Prism.languages.insertBefore("javascript", "string", {
|
|
|
147
1822
|
rest: Prism.languages.javascript
|
|
148
1823
|
}
|
|
149
1824
|
},
|
|
150
|
-
string: /[\s\S]+/
|
|
1825
|
+
"string": /[\s\S]+/
|
|
151
1826
|
}
|
|
152
1827
|
},
|
|
153
1828
|
"string-property": {
|
|
154
1829
|
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
|
155
|
-
lookbehind:
|
|
156
|
-
greedy:
|
|
1830
|
+
lookbehind: true,
|
|
1831
|
+
greedy: true,
|
|
157
1832
|
alias: "property"
|
|
158
1833
|
}
|
|
159
1834
|
});
|
|
160
1835
|
Prism.languages.insertBefore("javascript", "operator", {
|
|
161
1836
|
"literal-property": {
|
|
162
1837
|
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
|
163
|
-
lookbehind:
|
|
1838
|
+
lookbehind: true,
|
|
164
1839
|
alias: "property"
|
|
165
1840
|
}
|
|
166
1841
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
))
|
|
1842
|
+
if (Prism.languages.markup) {
|
|
1843
|
+
Prism.languages.markup.tag.addInlined("script", "javascript");
|
|
1844
|
+
Prism.languages.markup.tag.addAttribute(
|
|
1845
|
+
/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,
|
|
1846
|
+
"javascript"
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
171
1849
|
Prism.languages.js = Prism.languages.javascript;
|
|
172
1850
|
Prism.languages.python = {
|
|
173
|
-
comment: {
|
|
1851
|
+
"comment": {
|
|
174
1852
|
pattern: /(^|[^\\])#.*/,
|
|
175
|
-
lookbehind:
|
|
176
|
-
greedy:
|
|
1853
|
+
lookbehind: true,
|
|
1854
|
+
greedy: true
|
|
177
1855
|
},
|
|
178
1856
|
"string-interpolation": {
|
|
179
1857
|
pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
|
|
180
|
-
greedy:
|
|
1858
|
+
greedy: true,
|
|
181
1859
|
inside: {
|
|
182
|
-
interpolation: {
|
|
1860
|
+
"interpolation": {
|
|
183
1861
|
// "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
|
|
184
1862
|
pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
|
|
185
|
-
lookbehind:
|
|
1863
|
+
lookbehind: true,
|
|
186
1864
|
inside: {
|
|
187
1865
|
"format-spec": {
|
|
188
1866
|
pattern: /(:)[^:(){}]+(?=\}$)/,
|
|
189
|
-
lookbehind:
|
|
1867
|
+
lookbehind: true
|
|
190
1868
|
},
|
|
191
1869
|
"conversion-option": {
|
|
192
1870
|
pattern: //,
|
|
@@ -195,52 +1873,52 @@ Prism.languages.python = {
|
|
|
195
1873
|
rest: null
|
|
196
1874
|
}
|
|
197
1875
|
},
|
|
198
|
-
string: /[\s\S]+/
|
|
1876
|
+
"string": /[\s\S]+/
|
|
199
1877
|
}
|
|
200
1878
|
},
|
|
201
1879
|
"triple-quoted-string": {
|
|
202
1880
|
pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
|
|
203
|
-
greedy:
|
|
1881
|
+
greedy: true,
|
|
204
1882
|
alias: "string"
|
|
205
1883
|
},
|
|
206
|
-
string: {
|
|
1884
|
+
"string": {
|
|
207
1885
|
pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
|
|
208
|
-
greedy:
|
|
1886
|
+
greedy: true
|
|
209
1887
|
},
|
|
210
|
-
function: {
|
|
1888
|
+
"function": {
|
|
211
1889
|
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
|
|
212
|
-
lookbehind:
|
|
1890
|
+
lookbehind: true
|
|
213
1891
|
},
|
|
214
1892
|
"class-name": {
|
|
215
1893
|
pattern: /(\bclass\s+)\w+/i,
|
|
216
|
-
lookbehind:
|
|
1894
|
+
lookbehind: true
|
|
217
1895
|
},
|
|
218
|
-
decorator: {
|
|
1896
|
+
"decorator": {
|
|
219
1897
|
pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
|
|
220
|
-
lookbehind:
|
|
1898
|
+
lookbehind: true,
|
|
221
1899
|
alias: ["annotation", "punctuation"],
|
|
222
1900
|
inside: {
|
|
223
|
-
punctuation: /\./
|
|
1901
|
+
"punctuation": /\./
|
|
224
1902
|
}
|
|
225
1903
|
},
|
|
226
|
-
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/,
|
|
227
|
-
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/,
|
|
228
|
-
boolean: /\b(?:False|None|True)\b/,
|
|
229
|
-
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,
|
|
230
|
-
operator: /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
|
231
|
-
punctuation: /[{}[\];(),.:]/
|
|
1904
|
+
"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/,
|
|
1905
|
+
"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/,
|
|
1906
|
+
"boolean": /\b(?:False|None|True)\b/,
|
|
1907
|
+
"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,
|
|
1908
|
+
"operator": /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
|
|
1909
|
+
"punctuation": /[{}[\];(),.:]/
|
|
232
1910
|
};
|
|
233
|
-
Prism.languages.python["string-interpolation"].inside
|
|
1911
|
+
Prism.languages.python["string-interpolation"].inside["interpolation"].inside.rest = Prism.languages.python;
|
|
234
1912
|
Prism.languages.py = Prism.languages.python;
|
|
235
1913
|
Prism.languages.go = Prism.languages.extend("clike", {
|
|
236
|
-
string: {
|
|
1914
|
+
"string": {
|
|
237
1915
|
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,
|
|
238
|
-
lookbehind:
|
|
239
|
-
greedy:
|
|
1916
|
+
lookbehind: true,
|
|
1917
|
+
greedy: true
|
|
240
1918
|
},
|
|
241
|
-
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/,
|
|
242
|
-
boolean: /\b(?:_|false|iota|nil|true)\b/,
|
|
243
|
-
number: [
|
|
1919
|
+
"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/,
|
|
1920
|
+
"boolean": /\b(?:_|false|iota|nil|true)\b/,
|
|
1921
|
+
"number": [
|
|
244
1922
|
// binary and octal integers
|
|
245
1923
|
/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,
|
|
246
1924
|
// hexadecimal integers and floats
|
|
@@ -248,195 +1926,199 @@ Prism.languages.go = Prism.languages.extend("clike", {
|
|
|
248
1926
|
// decimal integers and floats
|
|
249
1927
|
/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i
|
|
250
1928
|
],
|
|
251
|
-
operator: /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
|
|
252
|
-
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/
|
|
1929
|
+
"operator": /[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,
|
|
1930
|
+
"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/
|
|
253
1931
|
});
|
|
254
1932
|
Prism.languages.insertBefore("go", "string", {
|
|
255
|
-
char: {
|
|
1933
|
+
"char": {
|
|
256
1934
|
pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/,
|
|
257
|
-
greedy:
|
|
1935
|
+
greedy: true
|
|
258
1936
|
}
|
|
259
1937
|
});
|
|
260
1938
|
delete Prism.languages.go["class-name"];
|
|
261
|
-
(function(
|
|
262
|
-
var
|
|
263
|
-
|
|
264
|
-
|
|
1939
|
+
(function(Prism2) {
|
|
1940
|
+
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/;
|
|
1941
|
+
var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
|
|
1942
|
+
var className = {
|
|
1943
|
+
pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
|
|
1944
|
+
lookbehind: true,
|
|
265
1945
|
inside: {
|
|
266
|
-
namespace: {
|
|
1946
|
+
"namespace": {
|
|
267
1947
|
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
|
|
268
1948
|
inside: {
|
|
269
|
-
punctuation: /\./
|
|
1949
|
+
"punctuation": /\./
|
|
270
1950
|
}
|
|
271
1951
|
},
|
|
272
|
-
punctuation: /\./
|
|
1952
|
+
"punctuation": /\./
|
|
273
1953
|
}
|
|
274
1954
|
};
|
|
275
|
-
|
|
276
|
-
string: {
|
|
1955
|
+
Prism2.languages.java = Prism2.languages.extend("clike", {
|
|
1956
|
+
"string": {
|
|
277
1957
|
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
|
|
278
|
-
lookbehind:
|
|
279
|
-
greedy:
|
|
1958
|
+
lookbehind: true,
|
|
1959
|
+
greedy: true
|
|
280
1960
|
},
|
|
281
1961
|
"class-name": [
|
|
282
|
-
|
|
1962
|
+
className,
|
|
283
1963
|
{
|
|
284
1964
|
// variables, parameters, and constructor references
|
|
285
1965
|
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
|
286
|
-
pattern: RegExp(/(^|[^\w.])/.source +
|
|
287
|
-
lookbehind:
|
|
288
|
-
inside:
|
|
1966
|
+
pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
|
|
1967
|
+
lookbehind: true,
|
|
1968
|
+
inside: className.inside
|
|
289
1969
|
},
|
|
290
1970
|
{
|
|
291
1971
|
// class names based on keyword
|
|
292
1972
|
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
|
|
293
|
-
pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source +
|
|
294
|
-
lookbehind:
|
|
295
|
-
inside:
|
|
1973
|
+
pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
|
|
1974
|
+
lookbehind: true,
|
|
1975
|
+
inside: className.inside
|
|
296
1976
|
}
|
|
297
1977
|
],
|
|
298
|
-
keyword:
|
|
299
|
-
function: [
|
|
300
|
-
|
|
1978
|
+
"keyword": keywords,
|
|
1979
|
+
"function": [
|
|
1980
|
+
Prism2.languages.clike.function,
|
|
301
1981
|
{
|
|
302
1982
|
pattern: /(::\s*)[a-z_]\w*/,
|
|
303
|
-
lookbehind:
|
|
1983
|
+
lookbehind: true
|
|
304
1984
|
}
|
|
305
1985
|
],
|
|
306
|
-
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,
|
|
307
|
-
operator: {
|
|
1986
|
+
"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,
|
|
1987
|
+
"operator": {
|
|
308
1988
|
pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
|
|
309
|
-
lookbehind:
|
|
1989
|
+
lookbehind: true
|
|
310
1990
|
},
|
|
311
|
-
constant: /\b[A-Z][A-Z_\d]+\b/
|
|
312
|
-
})
|
|
1991
|
+
"constant": /\b[A-Z][A-Z_\d]+\b/
|
|
1992
|
+
});
|
|
1993
|
+
Prism2.languages.insertBefore("java", "string", {
|
|
313
1994
|
"triple-quoted-string": {
|
|
314
1995
|
// http://openjdk.java.net/jeps/355#Description
|
|
315
1996
|
pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
|
|
316
|
-
greedy:
|
|
1997
|
+
greedy: true,
|
|
317
1998
|
alias: "string"
|
|
318
1999
|
},
|
|
319
|
-
char: {
|
|
2000
|
+
"char": {
|
|
320
2001
|
pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
|
|
321
|
-
greedy:
|
|
2002
|
+
greedy: true
|
|
322
2003
|
}
|
|
323
|
-
})
|
|
324
|
-
|
|
2004
|
+
});
|
|
2005
|
+
Prism2.languages.insertBefore("java", "class-name", {
|
|
2006
|
+
"annotation": {
|
|
325
2007
|
pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
|
|
326
|
-
lookbehind:
|
|
2008
|
+
lookbehind: true,
|
|
327
2009
|
alias: "punctuation"
|
|
328
2010
|
},
|
|
329
|
-
generics: {
|
|
2011
|
+
"generics": {
|
|
330
2012
|
pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
|
|
331
2013
|
inside: {
|
|
332
|
-
"class-name":
|
|
333
|
-
keyword:
|
|
334
|
-
punctuation: /[<>(),.:]/,
|
|
335
|
-
operator: /[?&|]/
|
|
2014
|
+
"class-name": className,
|
|
2015
|
+
"keyword": keywords,
|
|
2016
|
+
"punctuation": /[<>(),.:]/,
|
|
2017
|
+
"operator": /[?&|]/
|
|
336
2018
|
}
|
|
337
2019
|
},
|
|
338
|
-
import: [
|
|
2020
|
+
"import": [
|
|
339
2021
|
{
|
|
340
|
-
pattern: RegExp(/(\bimport\s+)/.source +
|
|
341
|
-
lookbehind:
|
|
2022
|
+
pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
|
|
2023
|
+
lookbehind: true,
|
|
342
2024
|
inside: {
|
|
343
|
-
namespace:
|
|
344
|
-
punctuation: /\./,
|
|
345
|
-
operator: /\*/,
|
|
2025
|
+
"namespace": className.inside.namespace,
|
|
2026
|
+
"punctuation": /\./,
|
|
2027
|
+
"operator": /\*/,
|
|
346
2028
|
"class-name": /\w+/
|
|
347
2029
|
}
|
|
348
2030
|
},
|
|
349
2031
|
{
|
|
350
|
-
pattern: RegExp(/(\bimport\s+static\s+)/.source +
|
|
351
|
-
lookbehind:
|
|
2032
|
+
pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
|
|
2033
|
+
lookbehind: true,
|
|
352
2034
|
alias: "static",
|
|
353
2035
|
inside: {
|
|
354
|
-
namespace:
|
|
355
|
-
static: /\b\w+$/,
|
|
356
|
-
punctuation: /\./,
|
|
357
|
-
operator: /\*/,
|
|
2036
|
+
"namespace": className.inside.namespace,
|
|
2037
|
+
"static": /\b\w+$/,
|
|
2038
|
+
"punctuation": /\./,
|
|
2039
|
+
"operator": /\*/,
|
|
358
2040
|
"class-name": /\w+/
|
|
359
2041
|
}
|
|
360
2042
|
}
|
|
361
2043
|
],
|
|
362
|
-
namespace: {
|
|
2044
|
+
"namespace": {
|
|
363
2045
|
pattern: RegExp(
|
|
364
2046
|
/(\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() {
|
|
365
|
-
return
|
|
2047
|
+
return keywords.source;
|
|
366
2048
|
})
|
|
367
2049
|
),
|
|
368
|
-
lookbehind:
|
|
2050
|
+
lookbehind: true,
|
|
369
2051
|
inside: {
|
|
370
|
-
punctuation: /\./
|
|
2052
|
+
"punctuation": /\./
|
|
371
2053
|
}
|
|
372
2054
|
}
|
|
373
2055
|
});
|
|
374
2056
|
})(Prism);
|
|
375
2057
|
Prism.languages.c = Prism.languages.extend("clike", {
|
|
376
|
-
comment: {
|
|
2058
|
+
"comment": {
|
|
377
2059
|
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
|
|
378
|
-
greedy:
|
|
2060
|
+
greedy: true
|
|
379
2061
|
},
|
|
380
|
-
string: {
|
|
2062
|
+
"string": {
|
|
381
2063
|
// https://en.cppreference.com/w/c/language/string_literal
|
|
382
2064
|
pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,
|
|
383
|
-
greedy:
|
|
2065
|
+
greedy: true
|
|
384
2066
|
},
|
|
385
2067
|
"class-name": {
|
|
386
2068
|
pattern: /(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,
|
|
387
|
-
lookbehind:
|
|
2069
|
+
lookbehind: true
|
|
388
2070
|
},
|
|
389
|
-
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/,
|
|
390
|
-
function: /\b[a-z_]\w*(?=\s*\()/i,
|
|
391
|
-
number: /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
|
392
|
-
operator: />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
|
2071
|
+
"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/,
|
|
2072
|
+
"function": /\b[a-z_]\w*(?=\s*\()/i,
|
|
2073
|
+
"number": /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
|
|
2074
|
+
"operator": />>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/
|
|
393
2075
|
});
|
|
394
2076
|
Prism.languages.insertBefore("c", "string", {
|
|
395
|
-
char: {
|
|
2077
|
+
"char": {
|
|
396
2078
|
// https://en.cppreference.com/w/c/language/character_constant
|
|
397
2079
|
pattern: /'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,
|
|
398
|
-
greedy:
|
|
2080
|
+
greedy: true
|
|
399
2081
|
}
|
|
400
2082
|
});
|
|
401
2083
|
Prism.languages.insertBefore("c", "string", {
|
|
402
|
-
macro: {
|
|
2084
|
+
"macro": {
|
|
403
2085
|
// allow for multiline macro definitions
|
|
404
2086
|
// spaces after the # character compile fine with gcc
|
|
405
2087
|
pattern: /(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,
|
|
406
|
-
lookbehind:
|
|
407
|
-
greedy:
|
|
2088
|
+
lookbehind: true,
|
|
2089
|
+
greedy: true,
|
|
408
2090
|
alias: "property",
|
|
409
2091
|
inside: {
|
|
410
|
-
string: [
|
|
2092
|
+
"string": [
|
|
411
2093
|
{
|
|
412
2094
|
// highlight the path of the include statement as a string
|
|
413
2095
|
pattern: /^(#\s*include\s*)<[^>]+>/,
|
|
414
|
-
lookbehind:
|
|
2096
|
+
lookbehind: true
|
|
415
2097
|
},
|
|
416
|
-
Prism.languages.c
|
|
2098
|
+
Prism.languages.c["string"]
|
|
417
2099
|
],
|
|
418
|
-
char: Prism.languages.c
|
|
419
|
-
comment: Prism.languages.c
|
|
2100
|
+
"char": Prism.languages.c["char"],
|
|
2101
|
+
"comment": Prism.languages.c["comment"],
|
|
420
2102
|
"macro-name": [
|
|
421
2103
|
{
|
|
422
2104
|
pattern: /(^#\s*define\s+)\w+\b(?!\()/i,
|
|
423
|
-
lookbehind:
|
|
2105
|
+
lookbehind: true
|
|
424
2106
|
},
|
|
425
2107
|
{
|
|
426
2108
|
pattern: /(^#\s*define\s+)\w+\b(?=\()/i,
|
|
427
|
-
lookbehind:
|
|
2109
|
+
lookbehind: true,
|
|
428
2110
|
alias: "function"
|
|
429
2111
|
}
|
|
430
2112
|
],
|
|
431
2113
|
// highlight macro directives as keywords
|
|
432
|
-
directive: {
|
|
2114
|
+
"directive": {
|
|
433
2115
|
pattern: /^(#\s*)[a-z]+/,
|
|
434
|
-
lookbehind:
|
|
2116
|
+
lookbehind: true,
|
|
435
2117
|
alias: "keyword"
|
|
436
2118
|
},
|
|
437
2119
|
"directive-hash": /^#/,
|
|
438
|
-
punctuation: /##|\\(?=[\r\n])/,
|
|
439
|
-
expression: {
|
|
2120
|
+
"punctuation": /##|\\(?=[\r\n])/,
|
|
2121
|
+
"expression": {
|
|
440
2122
|
pattern: /\S[\s\S]*/,
|
|
441
2123
|
inside: Prism.languages.c
|
|
442
2124
|
}
|
|
@@ -445,51 +2127,54 @@ Prism.languages.insertBefore("c", "string", {
|
|
|
445
2127
|
});
|
|
446
2128
|
Prism.languages.insertBefore("c", "function", {
|
|
447
2129
|
// highlight predefined macros as constants
|
|
448
|
-
constant: /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
|
2130
|
+
"constant": /\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/
|
|
449
2131
|
});
|
|
450
|
-
delete Prism.languages.c
|
|
451
|
-
(function(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
2132
|
+
delete Prism.languages.c["boolean"];
|
|
2133
|
+
(function(Prism2) {
|
|
2134
|
+
var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
|
|
2135
|
+
for (var i = 0; i < 2; i++) {
|
|
2136
|
+
multilineComment = multilineComment.replace(/<self>/g, function() {
|
|
2137
|
+
return multilineComment;
|
|
455
2138
|
});
|
|
456
|
-
|
|
2139
|
+
}
|
|
2140
|
+
multilineComment = multilineComment.replace(/<self>/g, function() {
|
|
457
2141
|
return /[^\s\S]/.source;
|
|
458
|
-
})
|
|
459
|
-
|
|
2142
|
+
});
|
|
2143
|
+
Prism2.languages.rust = {
|
|
2144
|
+
"comment": [
|
|
460
2145
|
{
|
|
461
|
-
pattern: RegExp(/(^|[^\\])/.source +
|
|
462
|
-
lookbehind:
|
|
463
|
-
greedy:
|
|
2146
|
+
pattern: RegExp(/(^|[^\\])/.source + multilineComment),
|
|
2147
|
+
lookbehind: true,
|
|
2148
|
+
greedy: true
|
|
464
2149
|
},
|
|
465
2150
|
{
|
|
466
2151
|
pattern: /(^|[^\\:])\/\/.*/,
|
|
467
|
-
lookbehind:
|
|
468
|
-
greedy:
|
|
2152
|
+
lookbehind: true,
|
|
2153
|
+
greedy: true
|
|
469
2154
|
}
|
|
470
2155
|
],
|
|
471
|
-
string: {
|
|
2156
|
+
"string": {
|
|
472
2157
|
pattern: /b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,
|
|
473
|
-
greedy:
|
|
2158
|
+
greedy: true
|
|
474
2159
|
},
|
|
475
|
-
char: {
|
|
2160
|
+
"char": {
|
|
476
2161
|
pattern: /b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,
|
|
477
|
-
greedy:
|
|
2162
|
+
greedy: true
|
|
478
2163
|
},
|
|
479
|
-
attribute: {
|
|
2164
|
+
"attribute": {
|
|
480
2165
|
pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,
|
|
481
|
-
greedy:
|
|
2166
|
+
greedy: true,
|
|
482
2167
|
alias: "attr-name",
|
|
483
2168
|
inside: {
|
|
484
|
-
string: null
|
|
2169
|
+
"string": null
|
|
485
2170
|
// see below
|
|
486
2171
|
}
|
|
487
2172
|
},
|
|
488
2173
|
// Closure params should not be confused with bitwise OR |
|
|
489
2174
|
"closure-params": {
|
|
490
2175
|
pattern: /([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,
|
|
491
|
-
lookbehind:
|
|
492
|
-
greedy:
|
|
2176
|
+
lookbehind: true,
|
|
2177
|
+
greedy: true,
|
|
493
2178
|
inside: {
|
|
494
2179
|
"closure-punctuation": {
|
|
495
2180
|
pattern: /^\||\|$/,
|
|
@@ -505,36 +2190,36 @@ delete Prism.languages.c.boolean;
|
|
|
505
2190
|
},
|
|
506
2191
|
"fragment-specifier": {
|
|
507
2192
|
pattern: /(\$\w+:)[a-z]+/,
|
|
508
|
-
lookbehind:
|
|
2193
|
+
lookbehind: true,
|
|
509
2194
|
alias: "punctuation"
|
|
510
2195
|
},
|
|
511
|
-
variable: /\$\w+/,
|
|
2196
|
+
"variable": /\$\w+/,
|
|
512
2197
|
"function-definition": {
|
|
513
2198
|
pattern: /(\bfn\s+)\w+/,
|
|
514
|
-
lookbehind:
|
|
2199
|
+
lookbehind: true,
|
|
515
2200
|
alias: "function"
|
|
516
2201
|
},
|
|
517
2202
|
"type-definition": {
|
|
518
2203
|
pattern: /(\b(?:enum|struct|trait|type|union)\s+)\w+/,
|
|
519
|
-
lookbehind:
|
|
2204
|
+
lookbehind: true,
|
|
520
2205
|
alias: "class-name"
|
|
521
2206
|
},
|
|
522
2207
|
"module-declaration": [
|
|
523
2208
|
{
|
|
524
2209
|
pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,
|
|
525
|
-
lookbehind:
|
|
2210
|
+
lookbehind: true,
|
|
526
2211
|
alias: "namespace"
|
|
527
2212
|
},
|
|
528
2213
|
{
|
|
529
2214
|
pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,
|
|
530
|
-
lookbehind:
|
|
2215
|
+
lookbehind: true,
|
|
531
2216
|
alias: "namespace",
|
|
532
2217
|
inside: {
|
|
533
|
-
punctuation: /::/
|
|
2218
|
+
"punctuation": /::/
|
|
534
2219
|
}
|
|
535
2220
|
}
|
|
536
2221
|
],
|
|
537
|
-
keyword: [
|
|
2222
|
+
"keyword": [
|
|
538
2223
|
// https://github.com/rust-lang/reference/blob/master/src/keywords.md
|
|
539
2224
|
/\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/,
|
|
540
2225
|
// primitives and str
|
|
@@ -544,112 +2229,116 @@ delete Prism.languages.c.boolean;
|
|
|
544
2229
|
// functions can technically start with an upper-case letter, but this will introduce a lot of false positives
|
|
545
2230
|
// and Rust's naming conventions recommend snake_case anyway.
|
|
546
2231
|
// https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
|
|
547
|
-
function: /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
|
|
548
|
-
macro: {
|
|
2232
|
+
"function": /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,
|
|
2233
|
+
"macro": {
|
|
549
2234
|
pattern: /\b\w+!/,
|
|
550
2235
|
alias: "property"
|
|
551
2236
|
},
|
|
552
|
-
constant: /\b[A-Z_][A-Z_\d]+\b/,
|
|
2237
|
+
"constant": /\b[A-Z_][A-Z_\d]+\b/,
|
|
553
2238
|
"class-name": /\b[A-Z]\w*\b/,
|
|
554
|
-
namespace: {
|
|
2239
|
+
"namespace": {
|
|
555
2240
|
pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,
|
|
556
2241
|
inside: {
|
|
557
|
-
punctuation: /::/
|
|
2242
|
+
"punctuation": /::/
|
|
558
2243
|
}
|
|
559
2244
|
},
|
|
560
2245
|
// Hex, oct, bin, dec numbers with visual separators and type suffix
|
|
561
|
-
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/,
|
|
562
|
-
boolean: /\b(?:false|true)\b/,
|
|
563
|
-
punctuation: /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
|
|
564
|
-
operator: /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
|
|
565
|
-
}
|
|
2246
|
+
"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/,
|
|
2247
|
+
"boolean": /\b(?:false|true)\b/,
|
|
2248
|
+
"punctuation": /->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,
|
|
2249
|
+
"operator": /[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/
|
|
2250
|
+
};
|
|
2251
|
+
Prism2.languages.rust["closure-params"].inside.rest = Prism2.languages.rust;
|
|
2252
|
+
Prism2.languages.rust["attribute"].inside["string"] = Prism2.languages.rust["string"];
|
|
566
2253
|
})(Prism);
|
|
567
2254
|
Prism.languages.sql = {
|
|
568
|
-
comment: {
|
|
2255
|
+
"comment": {
|
|
569
2256
|
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
|
|
570
|
-
lookbehind:
|
|
2257
|
+
lookbehind: true
|
|
571
2258
|
},
|
|
572
|
-
variable: [
|
|
2259
|
+
"variable": [
|
|
573
2260
|
{
|
|
574
2261
|
pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
|
|
575
|
-
greedy:
|
|
2262
|
+
greedy: true
|
|
576
2263
|
},
|
|
577
2264
|
/@[\w.$]+/
|
|
578
2265
|
],
|
|
579
|
-
string: {
|
|
2266
|
+
"string": {
|
|
580
2267
|
pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
|
|
581
|
-
greedy:
|
|
582
|
-
lookbehind:
|
|
2268
|
+
greedy: true,
|
|
2269
|
+
lookbehind: true
|
|
583
2270
|
},
|
|
584
|
-
identifier: {
|
|
2271
|
+
"identifier": {
|
|
585
2272
|
pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
|
|
586
|
-
greedy:
|
|
587
|
-
lookbehind:
|
|
2273
|
+
greedy: true,
|
|
2274
|
+
lookbehind: true,
|
|
588
2275
|
inside: {
|
|
589
|
-
punctuation: /^`|`$/
|
|
2276
|
+
"punctuation": /^`|`$/
|
|
590
2277
|
}
|
|
591
2278
|
},
|
|
592
|
-
function: /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,
|
|
2279
|
+
"function": /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i,
|
|
593
2280
|
// Should we highlight user defined functions too?
|
|
594
|
-
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,
|
|
595
|
-
boolean: /\b(?:FALSE|NULL|TRUE)\b/i,
|
|
596
|
-
number: /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
|
|
597
|
-
operator: /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
|
|
598
|
-
punctuation: /[;[\]()`,.]/
|
|
2281
|
+
"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,
|
|
2282
|
+
"boolean": /\b(?:FALSE|NULL|TRUE)\b/i,
|
|
2283
|
+
"number": /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
|
|
2284
|
+
"operator": /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
|
|
2285
|
+
"punctuation": /[;[\]()`,.]/
|
|
599
2286
|
};
|
|
600
|
-
(function(
|
|
601
|
-
var
|
|
2287
|
+
(function(Prism2) {
|
|
2288
|
+
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";
|
|
2289
|
+
var commandAfterHeredoc = {
|
|
602
2290
|
pattern: /(^(["']?)\w+\2)[ \t]+\S.*/,
|
|
603
|
-
lookbehind:
|
|
2291
|
+
lookbehind: true,
|
|
604
2292
|
alias: "punctuation",
|
|
605
2293
|
// this looks reasonably well in all themes
|
|
606
2294
|
inside: null
|
|
607
2295
|
// see below
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
2296
|
+
};
|
|
2297
|
+
var insideString = {
|
|
2298
|
+
"bash": commandAfterHeredoc,
|
|
2299
|
+
"environment": {
|
|
2300
|
+
pattern: RegExp("\\$" + envVars),
|
|
612
2301
|
alias: "constant"
|
|
613
2302
|
},
|
|
614
|
-
variable: [
|
|
2303
|
+
"variable": [
|
|
615
2304
|
// [0]: Arithmetic Environment
|
|
616
2305
|
{
|
|
617
2306
|
pattern: /\$?\(\([\s\S]+?\)\)/,
|
|
618
|
-
greedy:
|
|
2307
|
+
greedy: true,
|
|
619
2308
|
inside: {
|
|
620
2309
|
// If there is a $ sign at the beginning highlight $(( and )) as variable
|
|
621
|
-
variable: [
|
|
2310
|
+
"variable": [
|
|
622
2311
|
{
|
|
623
2312
|
pattern: /(^\$\(\([\s\S]+)\)\)/,
|
|
624
|
-
lookbehind:
|
|
2313
|
+
lookbehind: true
|
|
625
2314
|
},
|
|
626
2315
|
/^\$\(\(/
|
|
627
2316
|
],
|
|
628
|
-
number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
|
|
2317
|
+
"number": /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,
|
|
629
2318
|
// Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
|
|
630
|
-
operator: /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
|
|
2319
|
+
"operator": /--|\+\+|\*\*=?|<<=?|>>=?|&&|\|\||[=!+\-*/%<>^&|]=?|[?~:]/,
|
|
631
2320
|
// If there is no $ sign at the beginning highlight (( and )) as punctuation
|
|
632
|
-
punctuation: /\(\(?|\)\)?|,|;/
|
|
2321
|
+
"punctuation": /\(\(?|\)\)?|,|;/
|
|
633
2322
|
}
|
|
634
2323
|
},
|
|
635
2324
|
// [1]: Command Substitution
|
|
636
2325
|
{
|
|
637
2326
|
pattern: /\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,
|
|
638
|
-
greedy:
|
|
2327
|
+
greedy: true,
|
|
639
2328
|
inside: {
|
|
640
|
-
variable: /^\$\(|^`|\)$|`$/
|
|
2329
|
+
"variable": /^\$\(|^`|\)$|`$/
|
|
641
2330
|
}
|
|
642
2331
|
},
|
|
643
2332
|
// [2]: Brace expansion
|
|
644
2333
|
{
|
|
645
2334
|
pattern: /\$\{[^}]+\}/,
|
|
646
|
-
greedy:
|
|
2335
|
+
greedy: true,
|
|
647
2336
|
inside: {
|
|
648
|
-
operator: /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
|
|
649
|
-
punctuation: /[\[\]]/,
|
|
650
|
-
environment: {
|
|
651
|
-
pattern: RegExp("(\\{)" +
|
|
652
|
-
lookbehind:
|
|
2337
|
+
"operator": /:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,
|
|
2338
|
+
"punctuation": /[\[\]]/,
|
|
2339
|
+
"environment": {
|
|
2340
|
+
pattern: RegExp("(\\{)" + envVars),
|
|
2341
|
+
lookbehind: true,
|
|
653
2342
|
alias: "constant"
|
|
654
2343
|
}
|
|
655
2344
|
}
|
|
@@ -657,16 +2346,16 @@ Prism.languages.sql = {
|
|
|
657
2346
|
/\$(?:\w+|[#?*!@$])/
|
|
658
2347
|
],
|
|
659
2348
|
// Escape sequences from echo and printf's manuals, and escaped quotes.
|
|
660
|
-
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})/
|
|
2349
|
+
"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})/
|
|
661
2350
|
};
|
|
662
|
-
|
|
663
|
-
shebang: {
|
|
2351
|
+
Prism2.languages.bash = {
|
|
2352
|
+
"shebang": {
|
|
664
2353
|
pattern: /^#!\s*\/.*/,
|
|
665
2354
|
alias: "important"
|
|
666
2355
|
},
|
|
667
|
-
comment: {
|
|
2356
|
+
"comment": {
|
|
668
2357
|
pattern: /(^|[^"{\\$])#.*/,
|
|
669
|
-
lookbehind:
|
|
2358
|
+
lookbehind: true
|
|
670
2359
|
},
|
|
671
2360
|
"function-name": [
|
|
672
2361
|
// a) function foo {
|
|
@@ -676,7 +2365,7 @@ Prism.languages.sql = {
|
|
|
676
2365
|
{
|
|
677
2366
|
// a) and c)
|
|
678
2367
|
pattern: /(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,
|
|
679
|
-
lookbehind:
|
|
2368
|
+
lookbehind: true,
|
|
680
2369
|
alias: "function"
|
|
681
2370
|
},
|
|
682
2371
|
{
|
|
@@ -689,98 +2378,98 @@ Prism.languages.sql = {
|
|
|
689
2378
|
"for-or-select": {
|
|
690
2379
|
pattern: /(\b(?:for|select)\s+)\w+(?=\s+in\s)/,
|
|
691
2380
|
alias: "variable",
|
|
692
|
-
lookbehind:
|
|
2381
|
+
lookbehind: true
|
|
693
2382
|
},
|
|
694
2383
|
// Highlight variable names as variables in the left-hand part
|
|
695
2384
|
// of assignments (“=” and “+=”).
|
|
696
2385
|
"assign-left": {
|
|
697
2386
|
pattern: /(^|[\s;|&]|[<>]\()\w+(?:\.\w+)*(?=\+?=)/,
|
|
698
2387
|
inside: {
|
|
699
|
-
environment: {
|
|
700
|
-
pattern: RegExp("(^|[\\s;|&]|[<>]\\()" +
|
|
701
|
-
lookbehind:
|
|
2388
|
+
"environment": {
|
|
2389
|
+
pattern: RegExp("(^|[\\s;|&]|[<>]\\()" + envVars),
|
|
2390
|
+
lookbehind: true,
|
|
702
2391
|
alias: "constant"
|
|
703
2392
|
}
|
|
704
2393
|
},
|
|
705
2394
|
alias: "variable",
|
|
706
|
-
lookbehind:
|
|
2395
|
+
lookbehind: true
|
|
707
2396
|
},
|
|
708
2397
|
// Highlight parameter names as variables
|
|
709
|
-
parameter: {
|
|
2398
|
+
"parameter": {
|
|
710
2399
|
pattern: /(^|\s)-{1,2}(?:\w+:[+-]?)?\w+(?:\.\w+)*(?=[=\s]|$)/,
|
|
711
2400
|
alias: "variable",
|
|
712
|
-
lookbehind:
|
|
2401
|
+
lookbehind: true
|
|
713
2402
|
},
|
|
714
|
-
string: [
|
|
2403
|
+
"string": [
|
|
715
2404
|
// Support for Here-documents https://en.wikipedia.org/wiki/Here_document
|
|
716
2405
|
{
|
|
717
2406
|
pattern: /((?:^|[^<])<<-?\s*)(\w+)\s[\s\S]*?(?:\r?\n|\r)\2/,
|
|
718
|
-
lookbehind:
|
|
719
|
-
greedy:
|
|
720
|
-
inside:
|
|
2407
|
+
lookbehind: true,
|
|
2408
|
+
greedy: true,
|
|
2409
|
+
inside: insideString
|
|
721
2410
|
},
|
|
722
2411
|
// Here-document with quotes around the tag
|
|
723
2412
|
// → No expansion (so no “inside”).
|
|
724
2413
|
{
|
|
725
2414
|
pattern: /((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,
|
|
726
|
-
lookbehind:
|
|
727
|
-
greedy:
|
|
2415
|
+
lookbehind: true,
|
|
2416
|
+
greedy: true,
|
|
728
2417
|
inside: {
|
|
729
|
-
bash:
|
|
2418
|
+
"bash": commandAfterHeredoc
|
|
730
2419
|
}
|
|
731
2420
|
},
|
|
732
2421
|
// “Normal” string
|
|
733
2422
|
{
|
|
734
2423
|
// https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
|
|
735
2424
|
pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,
|
|
736
|
-
lookbehind:
|
|
737
|
-
greedy:
|
|
738
|
-
inside:
|
|
2425
|
+
lookbehind: true,
|
|
2426
|
+
greedy: true,
|
|
2427
|
+
inside: insideString
|
|
739
2428
|
},
|
|
740
2429
|
{
|
|
741
2430
|
// https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html
|
|
742
2431
|
pattern: /(^|[^$\\])'[^']*'/,
|
|
743
|
-
lookbehind:
|
|
744
|
-
greedy:
|
|
2432
|
+
lookbehind: true,
|
|
2433
|
+
greedy: true
|
|
745
2434
|
},
|
|
746
2435
|
{
|
|
747
2436
|
// https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
|
|
748
2437
|
pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
|
|
749
|
-
greedy:
|
|
2438
|
+
greedy: true,
|
|
750
2439
|
inside: {
|
|
751
|
-
entity:
|
|
2440
|
+
"entity": insideString.entity
|
|
752
2441
|
}
|
|
753
2442
|
}
|
|
754
2443
|
],
|
|
755
|
-
environment: {
|
|
756
|
-
pattern: RegExp("\\$?" +
|
|
2444
|
+
"environment": {
|
|
2445
|
+
pattern: RegExp("\\$?" + envVars),
|
|
757
2446
|
alias: "constant"
|
|
758
2447
|
},
|
|
759
|
-
variable:
|
|
760
|
-
function: {
|
|
2448
|
+
"variable": insideString.variable,
|
|
2449
|
+
"function": {
|
|
761
2450
|
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;|&])/,
|
|
762
|
-
lookbehind:
|
|
2451
|
+
lookbehind: true
|
|
763
2452
|
},
|
|
764
|
-
keyword: {
|
|
2453
|
+
"keyword": {
|
|
765
2454
|
pattern: /(^|[\s;|&]|[<>]\()(?:case|do|done|elif|else|esac|fi|for|function|if|in|select|then|until|while)(?=$|[)\s;|&])/,
|
|
766
|
-
lookbehind:
|
|
2455
|
+
lookbehind: true
|
|
767
2456
|
},
|
|
768
2457
|
// https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html
|
|
769
|
-
builtin: {
|
|
2458
|
+
"builtin": {
|
|
770
2459
|
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;|&])/,
|
|
771
|
-
lookbehind:
|
|
2460
|
+
lookbehind: true,
|
|
772
2461
|
// Alias added to make those easier to distinguish from strings.
|
|
773
2462
|
alias: "class-name"
|
|
774
2463
|
},
|
|
775
|
-
boolean: {
|
|
2464
|
+
"boolean": {
|
|
776
2465
|
pattern: /(^|[\s;|&]|[<>]\()(?:false|true)(?=$|[)\s;|&])/,
|
|
777
|
-
lookbehind:
|
|
2466
|
+
lookbehind: true
|
|
778
2467
|
},
|
|
779
2468
|
"file-descriptor": {
|
|
780
2469
|
pattern: /\B&\d\b/,
|
|
781
2470
|
alias: "important"
|
|
782
2471
|
},
|
|
783
|
-
operator: {
|
|
2472
|
+
"operator": {
|
|
784
2473
|
// Lots of redirections here, but not just that.
|
|
785
2474
|
pattern: /\d?<>|>\||\+=|=[=~]?|!=?|<<[<-]?|[&\d]?>>|\d[<>]&?|[<>][&=]?|&[>&]?|\|[&|]?/,
|
|
786
2475
|
inside: {
|
|
@@ -790,13 +2479,14 @@ Prism.languages.sql = {
|
|
|
790
2479
|
}
|
|
791
2480
|
}
|
|
792
2481
|
},
|
|
793
|
-
punctuation: /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
|
|
794
|
-
number: {
|
|
2482
|
+
"punctuation": /\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,
|
|
2483
|
+
"number": {
|
|
795
2484
|
pattern: /(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,
|
|
796
|
-
lookbehind:
|
|
2485
|
+
lookbehind: true
|
|
797
2486
|
}
|
|
798
|
-
}
|
|
799
|
-
|
|
2487
|
+
};
|
|
2488
|
+
commandAfterHeredoc.inside = Prism2.languages.bash;
|
|
2489
|
+
var toBeCopied = [
|
|
800
2490
|
"comment",
|
|
801
2491
|
"function-name",
|
|
802
2492
|
"for-or-select",
|
|
@@ -812,36 +2502,40 @@ Prism.languages.sql = {
|
|
|
812
2502
|
"operator",
|
|
813
2503
|
"punctuation",
|
|
814
2504
|
"number"
|
|
815
|
-
]
|
|
816
|
-
|
|
817
|
-
|
|
2505
|
+
];
|
|
2506
|
+
var inside = insideString.variable[1].inside;
|
|
2507
|
+
for (var i = 0; i < toBeCopied.length; i++) {
|
|
2508
|
+
inside[toBeCopied[i]] = Prism2.languages.bash[toBeCopied[i]];
|
|
2509
|
+
}
|
|
2510
|
+
Prism2.languages.sh = Prism2.languages.bash;
|
|
2511
|
+
Prism2.languages.shell = Prism2.languages.bash;
|
|
818
2512
|
})(Prism);
|
|
819
2513
|
Prism.languages.json = {
|
|
820
|
-
property: {
|
|
2514
|
+
"property": {
|
|
821
2515
|
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
|
|
822
|
-
lookbehind:
|
|
823
|
-
greedy:
|
|
2516
|
+
lookbehind: true,
|
|
2517
|
+
greedy: true
|
|
824
2518
|
},
|
|
825
|
-
string: {
|
|
2519
|
+
"string": {
|
|
826
2520
|
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
|
|
827
|
-
lookbehind:
|
|
828
|
-
greedy:
|
|
2521
|
+
lookbehind: true,
|
|
2522
|
+
greedy: true
|
|
829
2523
|
},
|
|
830
|
-
comment: {
|
|
2524
|
+
"comment": {
|
|
831
2525
|
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
|
|
832
|
-
greedy:
|
|
2526
|
+
greedy: true
|
|
833
2527
|
},
|
|
834
|
-
number: /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
|
|
835
|
-
punctuation: /[{}[\],]/,
|
|
836
|
-
operator: /:/,
|
|
837
|
-
boolean: /\b(?:false|true)\b/,
|
|
838
|
-
null: {
|
|
2528
|
+
"number": /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
|
|
2529
|
+
"punctuation": /[{}[\],]/,
|
|
2530
|
+
"operator": /:/,
|
|
2531
|
+
"boolean": /\b(?:false|true)\b/,
|
|
2532
|
+
"null": {
|
|
839
2533
|
pattern: /\bnull\b/,
|
|
840
2534
|
alias: "keyword"
|
|
841
2535
|
}
|
|
842
2536
|
};
|
|
843
2537
|
Prism.languages.webmanifest = Prism.languages.json;
|
|
844
|
-
const
|
|
2538
|
+
const prismDarkTheme = `
|
|
845
2539
|
/* 默认代码颜色 */
|
|
846
2540
|
.hep-cr-editor .hep-cr-highlight code,
|
|
847
2541
|
.hep-cr-editor .hep-cr-highlight pre {
|
|
@@ -927,7 +2621,8 @@ const ye = `
|
|
|
927
2621
|
.hep-cr-editor .token.console {
|
|
928
2622
|
color: #f8f8f2 !important;
|
|
929
2623
|
}
|
|
930
|
-
|
|
2624
|
+
`;
|
|
2625
|
+
const prismLightTheme = `
|
|
931
2626
|
/* 默认代码颜色 */
|
|
932
2627
|
.hep-cr-editor .hep-cr-highlight code,
|
|
933
2628
|
.hep-cr-editor .hep-cr-highlight pre {
|
|
@@ -1004,34 +2699,53 @@ const ye = `
|
|
|
1004
2699
|
.hep-cr-editor .token.console {
|
|
1005
2700
|
color: #333 !important;
|
|
1006
2701
|
}
|
|
1007
|
-
|
|
2702
|
+
`;
|
|
2703
|
+
const _hoisted_1$2 = ["innerHTML"];
|
|
2704
|
+
const _hoisted_2$2 = ["value", "disabled"];
|
|
2705
|
+
const CHANGE_DEBOUNCE_MS = 500;
|
|
2706
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
1008
2707
|
__name: "CodeEditor",
|
|
1009
2708
|
props: {
|
|
1010
2709
|
modelValue: {},
|
|
1011
2710
|
language: {},
|
|
1012
2711
|
theme: { default: "dark" },
|
|
1013
|
-
disabled: { type: Boolean, default:
|
|
2712
|
+
disabled: { type: Boolean, default: false }
|
|
1014
2713
|
},
|
|
1015
2714
|
emits: ["update:modelValue", "change"],
|
|
1016
|
-
setup(
|
|
1017
|
-
|
|
1018
|
-
v2b19bab6:
|
|
1019
|
-
}))
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
const d = "hep-cr-prism-styles", w = document.getElementById(d), F = l === "dark" ? ye : Ae;
|
|
1023
|
-
w && w.remove();
|
|
1024
|
-
const A = document.createElement("style");
|
|
1025
|
-
A.id = d, A.textContent = F, document.head.appendChild(A);
|
|
2715
|
+
setup(__props, { emit: __emit }) {
|
|
2716
|
+
useCssVars((_ctx) => ({
|
|
2717
|
+
"v2b19bab6": editorBackground.value
|
|
2718
|
+
}));
|
|
2719
|
+
if (typeof window !== "undefined") {
|
|
2720
|
+
window.Prism = Prism$1;
|
|
1026
2721
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
2722
|
+
function loadPrismTheme(theme) {
|
|
2723
|
+
if (typeof document === "undefined") return;
|
|
2724
|
+
const styleId = "hep-cr-prism-styles";
|
|
2725
|
+
const oldStyleEl = document.getElementById(styleId);
|
|
2726
|
+
const themeContent = theme === "dark" ? prismDarkTheme : prismLightTheme;
|
|
2727
|
+
if (oldStyleEl) {
|
|
2728
|
+
oldStyleEl.remove();
|
|
2729
|
+
}
|
|
2730
|
+
const styleEl = document.createElement("style");
|
|
2731
|
+
styleEl.id = styleId;
|
|
2732
|
+
styleEl.textContent = themeContent;
|
|
2733
|
+
document.head.appendChild(styleEl);
|
|
1033
2734
|
}
|
|
1034
|
-
const
|
|
2735
|
+
const props = __props;
|
|
2736
|
+
const emit = __emit;
|
|
2737
|
+
const codeRef = ref(null);
|
|
2738
|
+
const highlightRef = ref(null);
|
|
2739
|
+
let changeTimer = null;
|
|
2740
|
+
function emitChange(value) {
|
|
2741
|
+
if (changeTimer) {
|
|
2742
|
+
clearTimeout(changeTimer);
|
|
2743
|
+
}
|
|
2744
|
+
changeTimer = setTimeout(() => {
|
|
2745
|
+
emit("change", value);
|
|
2746
|
+
}, CHANGE_DEBOUNCE_MS);
|
|
2747
|
+
}
|
|
2748
|
+
const languageMap = {
|
|
1035
2749
|
javascript: "javascript",
|
|
1036
2750
|
js: "javascript",
|
|
1037
2751
|
typescript: "typescript",
|
|
@@ -1062,79 +2776,119 @@ const ye = `
|
|
|
1062
2776
|
yml: "yaml",
|
|
1063
2777
|
markdown: "markdown",
|
|
1064
2778
|
md: "markdown"
|
|
1065
|
-
}
|
|
2779
|
+
};
|
|
2780
|
+
const prismLanguage = computed(() => {
|
|
2781
|
+
return languageMap[props.language.toLowerCase()] || "javascript";
|
|
2782
|
+
});
|
|
2783
|
+
const editorBackground = computed(() => {
|
|
2784
|
+
return props.theme === "dark" ? "#1e1e1e" : "#fafafa";
|
|
2785
|
+
});
|
|
2786
|
+
const highlightedCode = computed(() => {
|
|
1066
2787
|
try {
|
|
1067
|
-
const
|
|
1068
|
-
if (
|
|
1069
|
-
return
|
|
1070
|
-
|
|
2788
|
+
const grammar = Prism$1.languages[prismLanguage.value];
|
|
2789
|
+
if (grammar) {
|
|
2790
|
+
return Prism$1.highlight(props.modelValue || "", grammar, prismLanguage.value);
|
|
2791
|
+
}
|
|
2792
|
+
} catch (e) {
|
|
1071
2793
|
}
|
|
1072
|
-
return
|
|
2794
|
+
return escapeHtml(props.modelValue || "");
|
|
1073
2795
|
});
|
|
1074
|
-
function
|
|
1075
|
-
const
|
|
1076
|
-
|
|
2796
|
+
function escapeHtml(text) {
|
|
2797
|
+
const div = document.createElement("div");
|
|
2798
|
+
div.textContent = text;
|
|
2799
|
+
return div.innerHTML;
|
|
1077
2800
|
}
|
|
1078
|
-
function
|
|
1079
|
-
const
|
|
1080
|
-
|
|
2801
|
+
function handleInput(e) {
|
|
2802
|
+
const target = e.target;
|
|
2803
|
+
emit("update:modelValue", target.value);
|
|
2804
|
+
emitChange(target.value);
|
|
1081
2805
|
}
|
|
1082
|
-
function
|
|
1083
|
-
|
|
2806
|
+
function handleScroll() {
|
|
2807
|
+
if (codeRef.value && highlightRef.value) {
|
|
2808
|
+
highlightRef.value.scrollTop = codeRef.value.scrollTop;
|
|
2809
|
+
highlightRef.value.scrollLeft = codeRef.value.scrollLeft;
|
|
2810
|
+
}
|
|
1084
2811
|
}
|
|
1085
|
-
function
|
|
1086
|
-
if (
|
|
1087
|
-
|
|
1088
|
-
const
|
|
1089
|
-
|
|
2812
|
+
function handleKeydown(e) {
|
|
2813
|
+
if (e.key === "Tab") {
|
|
2814
|
+
e.preventDefault();
|
|
2815
|
+
const target = e.target;
|
|
2816
|
+
const start = target.selectionStart;
|
|
2817
|
+
const end = target.selectionEnd;
|
|
2818
|
+
const value = target.value;
|
|
2819
|
+
target.value = value.substring(0, start) + " " + value.substring(end);
|
|
2820
|
+
target.selectionStart = target.selectionEnd = start + 2;
|
|
2821
|
+
emit("update:modelValue", target.value);
|
|
2822
|
+
emitChange(target.value);
|
|
1090
2823
|
}
|
|
1091
2824
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
})
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
"
|
|
2825
|
+
onMounted(() => {
|
|
2826
|
+
loadPrismTheme(props.theme);
|
|
2827
|
+
});
|
|
2828
|
+
watch(() => props.theme, (newTheme) => {
|
|
2829
|
+
loadPrismTheme(newTheme);
|
|
2830
|
+
});
|
|
2831
|
+
onUnmounted(() => {
|
|
2832
|
+
if (changeTimer) {
|
|
2833
|
+
clearTimeout(changeTimer);
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
return (_ctx, _cache) => {
|
|
2837
|
+
return openBlock(), createElementBlock("div", {
|
|
2838
|
+
class: normalizeClass(["hep-cr-editor", `hep-cr-theme-${__props.theme}`])
|
|
1106
2839
|
}, [
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
2840
|
+
createElementVNode("pre", {
|
|
2841
|
+
ref_key: "highlightRef",
|
|
2842
|
+
ref: highlightRef,
|
|
2843
|
+
class: normalizeClass(["hep-cr-highlight", [`language-${prismLanguage.value}`, `hep-cr-prism-${__props.theme}`]]),
|
|
2844
|
+
"aria-hidden": "true"
|
|
2845
|
+
}, [
|
|
2846
|
+
createElementVNode("code", { innerHTML: highlightedCode.value }, null, 8, _hoisted_1$2)
|
|
2847
|
+
], 2),
|
|
2848
|
+
createElementVNode("textarea", {
|
|
2849
|
+
ref_key: "codeRef",
|
|
2850
|
+
ref: codeRef,
|
|
2851
|
+
class: "hep-cr-input",
|
|
2852
|
+
value: __props.modelValue,
|
|
2853
|
+
disabled: __props.disabled,
|
|
2854
|
+
onInput: handleInput,
|
|
2855
|
+
onScroll: handleScroll,
|
|
2856
|
+
onKeydown: handleKeydown,
|
|
2857
|
+
spellcheck: "false",
|
|
2858
|
+
placeholder: "Write your code here..."
|
|
2859
|
+
}, null, 40, _hoisted_2$2)
|
|
2860
|
+
], 2);
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
});
|
|
2864
|
+
const _export_sfc = (sfc, props) => {
|
|
2865
|
+
const target = sfc.__vccOpts || sfc;
|
|
2866
|
+
for (const [key, val] of props) {
|
|
2867
|
+
target[key] = val;
|
|
1122
2868
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
2869
|
+
return target;
|
|
2870
|
+
};
|
|
2871
|
+
const CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-a988ca2a"]]);
|
|
2872
|
+
const _hoisted_1$1 = { class: "hep-cr-header" };
|
|
2873
|
+
const _hoisted_2$1 = { class: "hep-cr-controls" };
|
|
2874
|
+
const _hoisted_3$1 = ["disabled"];
|
|
2875
|
+
const _hoisted_4$1 = {
|
|
1129
2876
|
key: 0,
|
|
1130
2877
|
value: ""
|
|
1131
|
-
}
|
|
2878
|
+
};
|
|
2879
|
+
const _hoisted_5 = ["value"];
|
|
2880
|
+
const _hoisted_6 = { class: "hep-cr-actions" };
|
|
2881
|
+
const _hoisted_7 = ["disabled"];
|
|
2882
|
+
const _hoisted_8 = {
|
|
1132
2883
|
key: 0,
|
|
1133
2884
|
class: "hep-cr-spinner"
|
|
1134
|
-
}
|
|
2885
|
+
};
|
|
2886
|
+
const _hoisted_9 = {
|
|
1135
2887
|
key: 1,
|
|
1136
2888
|
class: "hep-cr-run-icon"
|
|
1137
|
-
}
|
|
2889
|
+
};
|
|
2890
|
+
const _hoisted_10 = ["title"];
|
|
2891
|
+
const _hoisted_11 = {
|
|
1138
2892
|
key: 0,
|
|
1139
2893
|
width: "16",
|
|
1140
2894
|
height: "16",
|
|
@@ -1142,7 +2896,8 @@ const ye = `
|
|
|
1142
2896
|
fill: "none",
|
|
1143
2897
|
stroke: "currentColor",
|
|
1144
2898
|
"stroke-width": "2"
|
|
1145
|
-
}
|
|
2899
|
+
};
|
|
2900
|
+
const _hoisted_12 = {
|
|
1146
2901
|
key: 1,
|
|
1147
2902
|
width: "16",
|
|
1148
2903
|
height: "16",
|
|
@@ -1150,10 +2905,17 @@ const ye = `
|
|
|
1150
2905
|
fill: "none",
|
|
1151
2906
|
stroke: "currentColor",
|
|
1152
2907
|
"stroke-width": "2"
|
|
1153
|
-
}
|
|
2908
|
+
};
|
|
2909
|
+
const _hoisted_13 = {
|
|
1154
2910
|
key: 0,
|
|
1155
2911
|
class: "hep-cr-error"
|
|
1156
|
-
}
|
|
2912
|
+
};
|
|
2913
|
+
const _hoisted_14 = { class: "hep-cr-main" };
|
|
2914
|
+
const _hoisted_15 = { class: "hep-cr-panel-header" };
|
|
2915
|
+
const _hoisted_16 = { class: "hep-cr-output-actions" };
|
|
2916
|
+
const _hoisted_17 = { class: "hep-cr-language-badge" };
|
|
2917
|
+
const _hoisted_18 = ["disabled", "title"];
|
|
2918
|
+
const _hoisted_19 = {
|
|
1157
2919
|
key: 0,
|
|
1158
2920
|
width: "14",
|
|
1159
2921
|
height: "14",
|
|
@@ -1161,13 +2923,20 @@ const ye = `
|
|
|
1161
2923
|
fill: "none",
|
|
1162
2924
|
stroke: "currentColor",
|
|
1163
2925
|
"stroke-width": "2"
|
|
1164
|
-
}
|
|
2926
|
+
};
|
|
2927
|
+
const _hoisted_20 = {
|
|
1165
2928
|
key: 1,
|
|
1166
2929
|
class: "hep-cr-copied-text"
|
|
1167
|
-
}
|
|
2930
|
+
};
|
|
2931
|
+
const _hoisted_21 = { class: "hep-cr-panel-header" };
|
|
2932
|
+
const _hoisted_22 = { class: "hep-cr-output-tabs" };
|
|
2933
|
+
const _hoisted_23 = { class: "hep-cr-output-actions" };
|
|
2934
|
+
const _hoisted_24 = {
|
|
1168
2935
|
key: 0,
|
|
1169
2936
|
class: "hep-cr-execution-time"
|
|
1170
|
-
}
|
|
2937
|
+
};
|
|
2938
|
+
const _hoisted_25 = ["disabled", "title"];
|
|
2939
|
+
const _hoisted_26 = {
|
|
1171
2940
|
key: 0,
|
|
1172
2941
|
width: "14",
|
|
1173
2942
|
height: "14",
|
|
@@ -1175,370 +2944,474 @@ const ye = `
|
|
|
1175
2944
|
fill: "none",
|
|
1176
2945
|
stroke: "currentColor",
|
|
1177
2946
|
"stroke-width": "2"
|
|
1178
|
-
}
|
|
2947
|
+
};
|
|
2948
|
+
const _hoisted_27 = {
|
|
1179
2949
|
key: 1,
|
|
1180
2950
|
class: "hep-cr-copied-text"
|
|
1181
|
-
}
|
|
2951
|
+
};
|
|
2952
|
+
const _hoisted_28 = { class: "hep-cr-output-content" };
|
|
2953
|
+
const _hoisted_29 = { key: 0 };
|
|
2954
|
+
const _hoisted_30 = {
|
|
1182
2955
|
key: 1,
|
|
1183
2956
|
class: "hep-cr-stderr"
|
|
1184
|
-
}
|
|
2957
|
+
};
|
|
2958
|
+
const STORAGE_KEY = "hep-cr-default-language";
|
|
2959
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
1185
2960
|
__name: "CodeRunner",
|
|
1186
2961
|
props: {
|
|
1187
2962
|
pistonUrl: { default: "/api/piston" },
|
|
1188
2963
|
language: { default: "javascript" },
|
|
1189
2964
|
theme: { default: "light" },
|
|
1190
2965
|
themeColor: { default: "" },
|
|
1191
|
-
showLanguageSelector: { type: Boolean, default:
|
|
1192
|
-
showEditor: { type: Boolean, default:
|
|
1193
|
-
editable: { type: Boolean, default:
|
|
2966
|
+
showLanguageSelector: { type: Boolean, default: true },
|
|
2967
|
+
showEditor: { type: Boolean, default: true },
|
|
2968
|
+
editable: { type: Boolean, default: true },
|
|
1194
2969
|
defaultCode: {},
|
|
1195
2970
|
executorLabel: { default: "运行" }
|
|
1196
2971
|
},
|
|
1197
2972
|
emits: ["execute-start", "execute-end", "language-change", "change"],
|
|
1198
|
-
setup(
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
|
|
2973
|
+
setup(__props, { emit: __emit }) {
|
|
2974
|
+
const props = __props;
|
|
2975
|
+
const themeStyle = computed(() => {
|
|
2976
|
+
if (!props.themeColor) return {};
|
|
2977
|
+
const isDark = props.theme === "dark";
|
|
2978
|
+
const color = props.themeColor;
|
|
2979
|
+
const isLightColor = isColorLight(color);
|
|
2980
|
+
const textColor = isLightColor ? "#000" : "#fff";
|
|
1202
2981
|
return {
|
|
1203
|
-
"--hep-cr-theme-color":
|
|
1204
|
-
"--hep-cr-theme-color-hover":
|
|
1205
|
-
"--hep-cr-tab-active-color":
|
|
2982
|
+
"--hep-cr-theme-color": color,
|
|
2983
|
+
"--hep-cr-theme-color-hover": isDark ? adjustColorBrightness(color, 20) : adjustColorBrightness(color, -20),
|
|
2984
|
+
"--hep-cr-tab-active-color": textColor
|
|
1206
2985
|
};
|
|
1207
2986
|
});
|
|
1208
|
-
function
|
|
1209
|
-
const
|
|
1210
|
-
|
|
2987
|
+
function isColorLight(hex) {
|
|
2988
|
+
const num = parseInt(hex.replace("#", ""), 16);
|
|
2989
|
+
const r = num >> 16 & 255;
|
|
2990
|
+
const g = num >> 8 & 255;
|
|
2991
|
+
const b = num & 255;
|
|
2992
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
2993
|
+
return luminance > 0.5;
|
|
1211
2994
|
}
|
|
1212
|
-
function
|
|
1213
|
-
const
|
|
1214
|
-
|
|
2995
|
+
function adjustColorBrightness(hex, percent) {
|
|
2996
|
+
const num = parseInt(hex.replace("#", ""), 16);
|
|
2997
|
+
const amt = Math.round(2.55 * percent);
|
|
2998
|
+
const R = Math.min(255, Math.max(0, (num >> 16) + amt));
|
|
2999
|
+
const G = Math.min(255, Math.max(0, (num >> 8 & 255) + amt));
|
|
3000
|
+
const B = Math.min(255, Math.max(0, (num & 255) + amt));
|
|
3001
|
+
return "#" + (16777216 + R * 65536 + G * 256 + B).toString(16).slice(1);
|
|
1215
3002
|
}
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
3003
|
+
const emit = __emit;
|
|
3004
|
+
const runtimes = ref([]);
|
|
3005
|
+
const currentLanguage = ref(getStoredLanguage());
|
|
3006
|
+
const currentTheme = ref(props.theme);
|
|
3007
|
+
const code = ref("");
|
|
3008
|
+
const output = ref("");
|
|
3009
|
+
const stderr = ref("");
|
|
3010
|
+
const isRunning = ref(false);
|
|
3011
|
+
const executionTime = ref(null);
|
|
3012
|
+
const activeTab = ref("stdout");
|
|
3013
|
+
const error = ref(null);
|
|
3014
|
+
const runtimesLoading = ref(false);
|
|
3015
|
+
const editorWidth = ref(60);
|
|
3016
|
+
function getStoredLanguage() {
|
|
3017
|
+
if (typeof window === "undefined") return props.language;
|
|
3018
|
+
return localStorage.getItem(STORAGE_KEY) || props.language;
|
|
1219
3019
|
}
|
|
1220
|
-
function
|
|
1221
|
-
|
|
3020
|
+
function toggleTheme() {
|
|
3021
|
+
currentTheme.value = currentTheme.value === "light" ? "dark" : "light";
|
|
1222
3022
|
}
|
|
1223
|
-
const
|
|
1224
|
-
() => new
|
|
1225
|
-
)
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
3023
|
+
const client = computed(
|
|
3024
|
+
() => new W({ pistonUrl: props.pistonUrl })
|
|
3025
|
+
);
|
|
3026
|
+
const languageOptions = computed(() => {
|
|
3027
|
+
return runtimes.value.map((r) => ({
|
|
3028
|
+
value: `${r.language}:${r.version}`,
|
|
3029
|
+
label: `${r.language.charAt(0).toUpperCase() + r.language.slice(1)} ${r.version}`
|
|
3030
|
+
}));
|
|
3031
|
+
});
|
|
3032
|
+
const languageName = computed(() => {
|
|
3033
|
+
const lang = currentLanguage.value;
|
|
3034
|
+
return lang.includes(":") ? lang.split(":")[0] : lang;
|
|
1231
3035
|
});
|
|
1232
|
-
async function
|
|
1233
|
-
|
|
3036
|
+
async function loadRuntimes() {
|
|
3037
|
+
runtimesLoading.value = true;
|
|
3038
|
+
error.value = null;
|
|
1234
3039
|
try {
|
|
1235
|
-
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
3040
|
+
runtimes.value = await client.value.getRuntimes();
|
|
3041
|
+
const langName = currentLanguage.value.split(":")[0];
|
|
3042
|
+
const defaultRuntime = runtimes.value.find((r) => r.language === langName);
|
|
3043
|
+
if (defaultRuntime && !currentLanguage.value.includes(":")) {
|
|
3044
|
+
currentLanguage.value = `${langName}:${defaultRuntime.version}`;
|
|
3045
|
+
}
|
|
3046
|
+
if (!code.value) {
|
|
3047
|
+
code.value = props.defaultCode || j(langName);
|
|
3048
|
+
emit("change", code.value);
|
|
3049
|
+
}
|
|
3050
|
+
emit("language-change", langName, code.value);
|
|
3051
|
+
} catch (e) {
|
|
3052
|
+
error.value = e instanceof Error ? e.message : "Failed to load runtimes";
|
|
1240
3053
|
} finally {
|
|
1241
|
-
|
|
3054
|
+
runtimesLoading.value = false;
|
|
1242
3055
|
}
|
|
1243
3056
|
}
|
|
1244
|
-
|
|
1245
|
-
const
|
|
1246
|
-
|
|
3057
|
+
watch(currentLanguage, (newLang) => {
|
|
3058
|
+
const langName = newLang.includes(":") ? newLang.split(":")[0] : newLang;
|
|
3059
|
+
const newCode = j(langName);
|
|
3060
|
+
code.value = newCode;
|
|
3061
|
+
emit("language-change", langName, newCode);
|
|
3062
|
+
if (typeof window !== "undefined") {
|
|
3063
|
+
localStorage.setItem(STORAGE_KEY, newLang);
|
|
3064
|
+
}
|
|
1247
3065
|
});
|
|
1248
|
-
async function
|
|
1249
|
-
if (
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
3066
|
+
async function execute() {
|
|
3067
|
+
if (isRunning.value) return;
|
|
3068
|
+
isRunning.value = true;
|
|
3069
|
+
output.value = "";
|
|
3070
|
+
stderr.value = "";
|
|
3071
|
+
executionTime.value = null;
|
|
3072
|
+
error.value = null;
|
|
3073
|
+
activeTab.value = "stdout";
|
|
3074
|
+
emit("execute-start");
|
|
3075
|
+
try {
|
|
3076
|
+
const result = await client.value.execute(languageName.value, code.value);
|
|
3077
|
+
output.value = result.output;
|
|
3078
|
+
stderr.value = result.stderr;
|
|
3079
|
+
executionTime.value = result.executionTime || null;
|
|
3080
|
+
activeTab.value = result.stderr ? "stderr" : "stdout";
|
|
3081
|
+
emit("execute-end", result);
|
|
3082
|
+
} catch (e) {
|
|
3083
|
+
error.value = e instanceof Error ? e.message : "Execution failed";
|
|
3084
|
+
emit("execute-end", {
|
|
3085
|
+
success: false,
|
|
3086
|
+
output: "",
|
|
3087
|
+
stderr: error.value,
|
|
3088
|
+
code: -1
|
|
3089
|
+
});
|
|
3090
|
+
} finally {
|
|
3091
|
+
isRunning.value = false;
|
|
1264
3092
|
}
|
|
1265
3093
|
}
|
|
1266
|
-
const
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
3094
|
+
const copiedEditor = ref(false);
|
|
3095
|
+
const copiedOutput = ref(false);
|
|
3096
|
+
async function copyCode() {
|
|
3097
|
+
await navigator.clipboard.writeText(code.value);
|
|
3098
|
+
copiedEditor.value = true;
|
|
3099
|
+
setTimeout(() => {
|
|
3100
|
+
copiedEditor.value = false;
|
|
1270
3101
|
}, 2e3);
|
|
1271
3102
|
}
|
|
1272
|
-
async function
|
|
1273
|
-
const
|
|
1274
|
-
await navigator.clipboard.writeText(
|
|
1275
|
-
|
|
3103
|
+
async function copyOutput() {
|
|
3104
|
+
const text = activeTab.value === "stdout" ? output.value : stderr.value;
|
|
3105
|
+
await navigator.clipboard.writeText(text);
|
|
3106
|
+
copiedOutput.value = true;
|
|
3107
|
+
setTimeout(() => {
|
|
3108
|
+
copiedOutput.value = false;
|
|
1276
3109
|
}, 2e3);
|
|
1277
3110
|
}
|
|
1278
|
-
function
|
|
1279
|
-
|
|
3111
|
+
function resetCode() {
|
|
3112
|
+
code.value = j(languageName.value);
|
|
1280
3113
|
}
|
|
1281
|
-
let
|
|
1282
|
-
function
|
|
1283
|
-
|
|
3114
|
+
let isDragging = false;
|
|
3115
|
+
function startDrag(e) {
|
|
3116
|
+
isDragging = true;
|
|
3117
|
+
document.addEventListener("mousemove", onDrag);
|
|
3118
|
+
document.addEventListener("mouseup", stopDrag);
|
|
3119
|
+
document.body.style.cursor = "col-resize";
|
|
3120
|
+
document.body.style.userSelect = "none";
|
|
1284
3121
|
}
|
|
1285
|
-
function
|
|
1286
|
-
if (
|
|
1287
|
-
const
|
|
3122
|
+
function onDrag(e) {
|
|
3123
|
+
if (!isDragging) return;
|
|
3124
|
+
const container = document.querySelector(
|
|
1288
3125
|
".hep-cr-main"
|
|
1289
3126
|
);
|
|
1290
|
-
if (!
|
|
1291
|
-
const
|
|
1292
|
-
|
|
3127
|
+
if (!container) return;
|
|
3128
|
+
const rect = container.getBoundingClientRect();
|
|
3129
|
+
const newWidth = (e.clientX - rect.left) / rect.width * 100;
|
|
3130
|
+
editorWidth.value = Math.max(20, Math.min(80, newWidth));
|
|
1293
3131
|
}
|
|
1294
|
-
function
|
|
1295
|
-
|
|
3132
|
+
function stopDrag() {
|
|
3133
|
+
isDragging = false;
|
|
3134
|
+
document.removeEventListener("mousemove", onDrag);
|
|
3135
|
+
document.removeEventListener("mouseup", stopDrag);
|
|
3136
|
+
document.body.style.cursor = "";
|
|
3137
|
+
document.body.style.userSelect = "";
|
|
1296
3138
|
}
|
|
1297
|
-
|
|
1298
|
-
await
|
|
3139
|
+
onMounted(async () => {
|
|
3140
|
+
await loadRuntimes();
|
|
3141
|
+
if (!code.value) {
|
|
3142
|
+
code.value = props.defaultCode || j(currentLanguage.value);
|
|
3143
|
+
emit("change", code.value);
|
|
3144
|
+
}
|
|
1299
3145
|
});
|
|
1300
|
-
const
|
|
1301
|
-
return (
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
3146
|
+
const themeClass = computed(() => `hep-cr-runner-${currentTheme.value}`);
|
|
3147
|
+
return (_ctx, _cache) => {
|
|
3148
|
+
return openBlock(), createElementBlock("div", {
|
|
3149
|
+
class: normalizeClass(["hep-cr-runner", themeClass.value]),
|
|
3150
|
+
style: normalizeStyle(themeStyle.value)
|
|
3151
|
+
}, [
|
|
3152
|
+
createElementVNode("div", _hoisted_1$1, [
|
|
3153
|
+
createElementVNode("div", _hoisted_2$1, [
|
|
3154
|
+
__props.showLanguageSelector ? withDirectives((openBlock(), createElementBlock("select", {
|
|
3155
|
+
key: 0,
|
|
3156
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => currentLanguage.value = $event),
|
|
3157
|
+
class: "hep-cr-language-select",
|
|
3158
|
+
disabled: isRunning.value
|
|
3159
|
+
}, [
|
|
3160
|
+
runtimesLoading.value ? (openBlock(), createElementBlock("option", _hoisted_4$1, "加载中...")) : createCommentVNode("", true),
|
|
3161
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(languageOptions.value, (option) => {
|
|
3162
|
+
return openBlock(), createElementBlock("option", {
|
|
3163
|
+
key: option.value,
|
|
3164
|
+
value: option.value
|
|
3165
|
+
}, toDisplayString(option.label), 9, _hoisted_5);
|
|
3166
|
+
}), 128))
|
|
3167
|
+
], 8, _hoisted_3$1)), [
|
|
3168
|
+
[vModelSelect, currentLanguage.value]
|
|
3169
|
+
]) : createCommentVNode("", true)
|
|
3170
|
+
]),
|
|
3171
|
+
createElementVNode("div", _hoisted_6, [
|
|
3172
|
+
createElementVNode("button", {
|
|
3173
|
+
class: "hep-cr-btn hep-cr-btn-run",
|
|
3174
|
+
disabled: isRunning.value || runtimesLoading.value,
|
|
3175
|
+
onClick: execute
|
|
3176
|
+
}, [
|
|
3177
|
+
isRunning.value ? (openBlock(), createElementBlock("span", _hoisted_8)) : (openBlock(), createElementBlock("span", _hoisted_9, "▶")),
|
|
3178
|
+
createTextVNode(" " + toDisplayString(isRunning.value ? "运行中..." : __props.executorLabel), 1)
|
|
3179
|
+
], 8, _hoisted_7),
|
|
3180
|
+
__props.showEditor && __props.editable ? (openBlock(), createElementBlock("button", {
|
|
3181
|
+
key: 0,
|
|
3182
|
+
class: "hep-cr-btn hep-cr-btn-reset",
|
|
3183
|
+
onClick: resetCode
|
|
3184
|
+
}, " 重置 ")) : createCommentVNode("", true),
|
|
3185
|
+
createElementVNode("button", {
|
|
3186
|
+
class: "hep-cr-btn hep-cr-btn-theme",
|
|
3187
|
+
onClick: toggleTheme,
|
|
3188
|
+
title: currentTheme.value === "light" ? "Switch to dark mode" : "Switch to light mode"
|
|
3189
|
+
}, [
|
|
3190
|
+
currentTheme.value === "light" ? (openBlock(), createElementBlock("svg", _hoisted_11, [..._cache[5] || (_cache[5] = [
|
|
3191
|
+
createElementVNode("path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" }, null, -1)
|
|
3192
|
+
])])) : (openBlock(), createElementBlock("svg", _hoisted_12, [..._cache[6] || (_cache[6] = [
|
|
3193
|
+
createStaticVNode('<circle cx="12" cy="12" r="5" data-v-41977f3b></circle><line x1="12" y1="1" x2="12" y2="3" data-v-41977f3b></line><line x1="12" y1="21" x2="12" y2="23" data-v-41977f3b></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64" data-v-41977f3b></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78" data-v-41977f3b></line><line x1="1" y1="12" x2="3" y2="12" data-v-41977f3b></line><line x1="21" y1="12" x2="23" y2="12" data-v-41977f3b></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36" data-v-41977f3b></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22" data-v-41977f3b></line>', 9)
|
|
3194
|
+
])]))
|
|
3195
|
+
], 8, _hoisted_10)
|
|
3196
|
+
])
|
|
1321
3197
|
]),
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
disabled: S.value || l.value,
|
|
1326
|
-
onClick: ee
|
|
1327
|
-
}, [
|
|
1328
|
-
S.value ? (i(), c("span", Ue)) : (i(), c("span", Me, "▶")),
|
|
1329
|
-
he(" " + R(S.value ? "运行中..." : e.executorLabel), 1)
|
|
1330
|
-
], 8, Pe),
|
|
1331
|
-
e.showEditor && e.editable ? (i(), c("button", {
|
|
3198
|
+
error.value ? (openBlock(), createElementBlock("div", _hoisted_13, toDisplayString(error.value), 1)) : createCommentVNode("", true),
|
|
3199
|
+
createElementVNode("div", _hoisted_14, [
|
|
3200
|
+
__props.showEditor ? (openBlock(), createElementBlock("div", {
|
|
1332
3201
|
key: 0,
|
|
1333
|
-
class: "hep-cr-
|
|
1334
|
-
|
|
1335
|
-
}, " 重置 ")) : k("", !0),
|
|
1336
|
-
r("button", {
|
|
1337
|
-
class: "hep-cr-btn hep-cr-btn-theme",
|
|
1338
|
-
onClick: F,
|
|
1339
|
-
title: g.value === "light" ? "Switch to dark mode" : "Switch to light mode"
|
|
3202
|
+
class: "hep-cr-editor-panel",
|
|
3203
|
+
style: normalizeStyle({ width: editorWidth.value + "%" })
|
|
1340
3204
|
}, [
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
title: x.value ? "已复制" : "复制"
|
|
1365
|
-
}, [
|
|
1366
|
-
x.value ? (i(), c("span", Ze, "已复制")) : (i(), c("svg", Ke, [...n[7] || (n[7] = [
|
|
1367
|
-
r("rect", {
|
|
1368
|
-
x: "9",
|
|
1369
|
-
y: "9",
|
|
1370
|
-
width: "13",
|
|
1371
|
-
height: "13",
|
|
1372
|
-
rx: "2",
|
|
1373
|
-
ry: "2"
|
|
1374
|
-
}, null, -1),
|
|
1375
|
-
r("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }, null, -1)
|
|
1376
|
-
])]))
|
|
1377
|
-
], 10, je)
|
|
1378
|
-
])
|
|
1379
|
-
]),
|
|
1380
|
-
z(we, {
|
|
1381
|
-
modelValue: h.value,
|
|
1382
|
-
"onUpdate:modelValue": n[1] || (n[1] = (s) => h.value = s),
|
|
1383
|
-
language: P.value,
|
|
1384
|
-
theme: g.value,
|
|
1385
|
-
disabled: !e.editable || S.value,
|
|
1386
|
-
onChange: n[2] || (n[2] = (s) => p("change", s))
|
|
1387
|
-
}, null, 8, ["modelValue", "language", "theme", "disabled"])
|
|
1388
|
-
], 4)) : k("", !0),
|
|
1389
|
-
e.showEditor ? (i(), c("div", {
|
|
1390
|
-
key: 1,
|
|
1391
|
-
class: "hep-cr-resize-handle",
|
|
1392
|
-
onMousedown: ae
|
|
1393
|
-
}, [...n[9] || (n[9] = [
|
|
1394
|
-
r("div", { class: "hep-cr-resize-line" }, null, -1)
|
|
1395
|
-
])], 32)) : k("", !0),
|
|
1396
|
-
r("div", {
|
|
1397
|
-
class: "hep-cr-output-panel",
|
|
1398
|
-
style: M({ width: e.showEditor ? 100 - d.value + "%" : "100%" })
|
|
1399
|
-
}, [
|
|
1400
|
-
r("div", We, [
|
|
1401
|
-
r("div", qe, [
|
|
1402
|
-
r("button", {
|
|
1403
|
-
class: O(["hep-cr-tab", { active: T.value === "stdout" }]),
|
|
1404
|
-
onClick: n[3] || (n[3] = (s) => T.value = "stdout")
|
|
1405
|
-
}, " 输出 ", 2),
|
|
1406
|
-
N.value ? (i(), c("button", {
|
|
1407
|
-
key: 0,
|
|
1408
|
-
class: O(["hep-cr-tab", "hep-cr-tab-error", { active: T.value === "stderr" }]),
|
|
1409
|
-
onClick: n[4] || (n[4] = (s) => T.value = "stderr")
|
|
1410
|
-
}, " 错误 ", 2)) : k("", !0)
|
|
3205
|
+
createElementVNode("div", _hoisted_15, [
|
|
3206
|
+
_cache[8] || (_cache[8] = createElementVNode("span", { class: "hep-cr-panel-title" }, "编辑器", -1)),
|
|
3207
|
+
createElementVNode("div", _hoisted_16, [
|
|
3208
|
+
createElementVNode("span", _hoisted_17, toDisplayString(languageName.value), 1),
|
|
3209
|
+
createElementVNode("button", {
|
|
3210
|
+
class: normalizeClass(["hep-cr-btn-icon", { "hep-cr-btn-copied": copiedEditor.value }]),
|
|
3211
|
+
disabled: copiedEditor.value,
|
|
3212
|
+
onClick: copyCode,
|
|
3213
|
+
title: copiedEditor.value ? "已复制" : "复制"
|
|
3214
|
+
}, [
|
|
3215
|
+
!copiedEditor.value ? (openBlock(), createElementBlock("svg", _hoisted_19, [..._cache[7] || (_cache[7] = [
|
|
3216
|
+
createElementVNode("rect", {
|
|
3217
|
+
x: "9",
|
|
3218
|
+
y: "9",
|
|
3219
|
+
width: "13",
|
|
3220
|
+
height: "13",
|
|
3221
|
+
rx: "2",
|
|
3222
|
+
ry: "2"
|
|
3223
|
+
}, null, -1),
|
|
3224
|
+
createElementVNode("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }, null, -1)
|
|
3225
|
+
])])) : (openBlock(), createElementBlock("span", _hoisted_20, "已复制"))
|
|
3226
|
+
], 10, _hoisted_18)
|
|
3227
|
+
])
|
|
1411
3228
|
]),
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
3229
|
+
createVNode(CodeEditor, {
|
|
3230
|
+
modelValue: code.value,
|
|
3231
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => code.value = $event),
|
|
3232
|
+
language: languageName.value,
|
|
3233
|
+
theme: currentTheme.value,
|
|
3234
|
+
disabled: !__props.editable || isRunning.value,
|
|
3235
|
+
onChange: _cache[2] || (_cache[2] = (val) => emit("change", val))
|
|
3236
|
+
}, null, 8, ["modelValue", "language", "theme", "disabled"])
|
|
3237
|
+
], 4)) : createCommentVNode("", true),
|
|
3238
|
+
__props.showEditor ? (openBlock(), createElementBlock("div", {
|
|
3239
|
+
key: 1,
|
|
3240
|
+
class: "hep-cr-resize-handle",
|
|
3241
|
+
onMousedown: startDrag
|
|
3242
|
+
}, [..._cache[9] || (_cache[9] = [
|
|
3243
|
+
createElementVNode("div", { class: "hep-cr-resize-line" }, null, -1)
|
|
3244
|
+
])], 32)) : createCommentVNode("", true),
|
|
3245
|
+
createElementVNode("div", {
|
|
3246
|
+
class: "hep-cr-output-panel",
|
|
3247
|
+
style: normalizeStyle({ width: __props.showEditor ? 100 - editorWidth.value + "%" : "100%" })
|
|
3248
|
+
}, [
|
|
3249
|
+
createElementVNode("div", _hoisted_21, [
|
|
3250
|
+
createElementVNode("div", _hoisted_22, [
|
|
3251
|
+
createElementVNode("button", {
|
|
3252
|
+
class: normalizeClass(["hep-cr-tab", { active: activeTab.value === "stdout" }]),
|
|
3253
|
+
onClick: _cache[3] || (_cache[3] = ($event) => activeTab.value = "stdout")
|
|
3254
|
+
}, " 输出 ", 2),
|
|
3255
|
+
stderr.value ? (openBlock(), createElementBlock("button", {
|
|
3256
|
+
key: 0,
|
|
3257
|
+
class: normalizeClass(["hep-cr-tab", "hep-cr-tab-error", { active: activeTab.value === "stderr" }]),
|
|
3258
|
+
onClick: _cache[4] || (_cache[4] = ($event) => activeTab.value = "stderr")
|
|
3259
|
+
}, " 错误 ", 2)) : createCommentVNode("", true)
|
|
3260
|
+
]),
|
|
3261
|
+
createElementVNode("div", _hoisted_23, [
|
|
3262
|
+
executionTime.value !== null ? (openBlock(), createElementBlock("span", _hoisted_24, toDisplayString(executionTime.value) + "ms ", 1)) : createCommentVNode("", true),
|
|
3263
|
+
createElementVNode("button", {
|
|
3264
|
+
class: normalizeClass(["hep-cr-btn-icon", { "hep-cr-btn-copied": copiedOutput.value }]),
|
|
3265
|
+
disabled: copiedOutput.value,
|
|
3266
|
+
onClick: copyOutput,
|
|
3267
|
+
title: copiedOutput.value ? "已复制" : "复制"
|
|
3268
|
+
}, [
|
|
3269
|
+
!copiedOutput.value ? (openBlock(), createElementBlock("svg", _hoisted_26, [..._cache[10] || (_cache[10] = [
|
|
3270
|
+
createElementVNode("rect", {
|
|
3271
|
+
x: "9",
|
|
3272
|
+
y: "9",
|
|
3273
|
+
width: "13",
|
|
3274
|
+
height: "13",
|
|
3275
|
+
rx: "2",
|
|
3276
|
+
ry: "2"
|
|
3277
|
+
}, null, -1),
|
|
3278
|
+
createElementVNode("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }, null, -1)
|
|
3279
|
+
])])) : (openBlock(), createElementBlock("span", _hoisted_27, "已复制"))
|
|
3280
|
+
], 10, _hoisted_25)
|
|
3281
|
+
])
|
|
3282
|
+
]),
|
|
3283
|
+
createElementVNode("div", _hoisted_28, [
|
|
3284
|
+
activeTab.value === "stdout" ? (openBlock(), createElementBlock("pre", _hoisted_29, toDisplayString(isRunning.value ? "代码执行中..." : output.value || '点击"运行"执行代码'), 1)) : (openBlock(), createElementBlock("pre", _hoisted_30, toDisplayString(stderr.value), 1))
|
|
1432
3285
|
])
|
|
1433
|
-
])
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
], 4)
|
|
1438
|
-
])
|
|
1439
|
-
], 6));
|
|
3286
|
+
], 4)
|
|
3287
|
+
])
|
|
3288
|
+
], 6);
|
|
3289
|
+
};
|
|
1440
3290
|
}
|
|
1441
|
-
})
|
|
3291
|
+
});
|
|
3292
|
+
const CodeRunner = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-41977f3b"]]);
|
|
3293
|
+
const _hoisted_1 = { class: "hep-cr-dialog-header" };
|
|
3294
|
+
const _hoisted_2 = { class: "hep-cr-dialog-title" };
|
|
3295
|
+
const _hoisted_3 = { class: "hep-cr-dialog-body" };
|
|
3296
|
+
const _hoisted_4 = {
|
|
1442
3297
|
key: 0,
|
|
1443
3298
|
class: "hep-cr-dialog-footer"
|
|
1444
|
-
}
|
|
3299
|
+
};
|
|
3300
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1445
3301
|
__name: "CodeRunnerDialog",
|
|
1446
3302
|
props: {
|
|
1447
|
-
modelValue: { type: Boolean, default:
|
|
3303
|
+
modelValue: { type: Boolean, default: false },
|
|
1448
3304
|
title: { default: "代码执行器" },
|
|
1449
3305
|
width: { default: 800 },
|
|
1450
3306
|
pistonUrl: { default: "/api/piston" },
|
|
1451
3307
|
language: { default: "javascript" },
|
|
1452
3308
|
theme: { default: "light" },
|
|
1453
3309
|
themeColor: { default: "" },
|
|
1454
|
-
showLanguageSelector: { type: Boolean, default:
|
|
1455
|
-
showEditor: { type: Boolean, default:
|
|
1456
|
-
editable: { type: Boolean, default:
|
|
3310
|
+
showLanguageSelector: { type: Boolean, default: true },
|
|
3311
|
+
showEditor: { type: Boolean, default: true },
|
|
3312
|
+
editable: { type: Boolean, default: true },
|
|
1457
3313
|
defaultCode: {},
|
|
1458
3314
|
executorLabel: { default: "运行" }
|
|
1459
3315
|
},
|
|
1460
3316
|
emits: ["update:modelValue", "close", "change"],
|
|
1461
|
-
setup(
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
3317
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
3318
|
+
const props = __props;
|
|
3319
|
+
const emit = __emit;
|
|
3320
|
+
const localVisible = ref(props.modelValue);
|
|
3321
|
+
const isVisible = computed(() => {
|
|
3322
|
+
if (props.modelValue !== void 0) {
|
|
3323
|
+
return props.modelValue;
|
|
3324
|
+
}
|
|
3325
|
+
return localVisible.value;
|
|
3326
|
+
});
|
|
3327
|
+
watch(
|
|
3328
|
+
() => props.modelValue,
|
|
3329
|
+
(val) => {
|
|
3330
|
+
if (val !== void 0) {
|
|
3331
|
+
localVisible.value = val;
|
|
3332
|
+
}
|
|
1467
3333
|
}
|
|
1468
3334
|
);
|
|
1469
|
-
function
|
|
1470
|
-
|
|
3335
|
+
function close() {
|
|
3336
|
+
localVisible.value = false;
|
|
3337
|
+
emit("update:modelValue", false);
|
|
3338
|
+
emit("close");
|
|
1471
3339
|
}
|
|
1472
|
-
function
|
|
1473
|
-
|
|
3340
|
+
function handleOverlayClick(e) {
|
|
3341
|
+
if (e.target === e.currentTarget) {
|
|
3342
|
+
close();
|
|
3343
|
+
}
|
|
1474
3344
|
}
|
|
1475
|
-
|
|
1476
|
-
close
|
|
1477
|
-
})
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
class: "hep-cr-dialog-container",
|
|
1487
|
-
style: M({ width: typeof e.width == "number" ? e.width + "px" : e.width })
|
|
3345
|
+
__expose({
|
|
3346
|
+
close
|
|
3347
|
+
});
|
|
3348
|
+
return (_ctx, _cache) => {
|
|
3349
|
+
return openBlock(), createBlock(Teleport, { to: "body" }, [
|
|
3350
|
+
createVNode(Transition, { name: "hep-cr-dialog-fade" }, {
|
|
3351
|
+
default: withCtx(() => [
|
|
3352
|
+
isVisible.value ? (openBlock(), createElementBlock("div", {
|
|
3353
|
+
key: 0,
|
|
3354
|
+
class: "hep-cr-dialog-overlay",
|
|
3355
|
+
onClick: handleOverlayClick
|
|
1488
3356
|
}, [
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
3357
|
+
createElementVNode("div", {
|
|
3358
|
+
class: "hep-cr-dialog-container",
|
|
3359
|
+
style: normalizeStyle({ width: typeof __props.width === "number" ? __props.width + "px" : __props.width })
|
|
3360
|
+
}, [
|
|
3361
|
+
createElementVNode("div", _hoisted_1, [
|
|
3362
|
+
createElementVNode("h3", _hoisted_2, toDisplayString(__props.title), 1),
|
|
3363
|
+
createElementVNode("button", {
|
|
3364
|
+
class: "hep-cr-dialog-close",
|
|
3365
|
+
onClick: close
|
|
3366
|
+
}, [..._cache[0] || (_cache[0] = [
|
|
3367
|
+
createElementVNode("svg", {
|
|
3368
|
+
width: "16",
|
|
3369
|
+
height: "16",
|
|
3370
|
+
viewBox: "0 0 24 24",
|
|
3371
|
+
fill: "none",
|
|
3372
|
+
stroke: "currentColor",
|
|
3373
|
+
"stroke-width": "2"
|
|
3374
|
+
}, [
|
|
3375
|
+
createElementVNode("line", {
|
|
3376
|
+
x1: "18",
|
|
3377
|
+
y1: "6",
|
|
3378
|
+
x2: "6",
|
|
3379
|
+
y2: "18"
|
|
3380
|
+
}),
|
|
3381
|
+
createElementVNode("line", {
|
|
3382
|
+
x1: "6",
|
|
3383
|
+
y1: "6",
|
|
3384
|
+
x2: "18",
|
|
3385
|
+
y2: "18"
|
|
3386
|
+
})
|
|
3387
|
+
], -1)
|
|
3388
|
+
])])
|
|
3389
|
+
]),
|
|
3390
|
+
createElementVNode("div", _hoisted_3, [
|
|
3391
|
+
createVNode(CodeRunner, mergeProps(_ctx.$attrs, toHandlers(_ctx.$attrs)), null, 16)
|
|
3392
|
+
]),
|
|
3393
|
+
_ctx.$slots.footer ? (openBlock(), createElementBlock("div", _hoisted_4, [
|
|
3394
|
+
renderSlot(_ctx.$slots, "footer", { close })
|
|
3395
|
+
])) : createCommentVNode("", true)
|
|
3396
|
+
], 4)
|
|
3397
|
+
])) : createCommentVNode("", true)
|
|
3398
|
+
]),
|
|
3399
|
+
_: 3
|
|
3400
|
+
})
|
|
3401
|
+
]);
|
|
3402
|
+
};
|
|
1530
3403
|
}
|
|
1531
3404
|
});
|
|
1532
|
-
|
|
1533
|
-
|
|
3405
|
+
CodeRunner.install = (app) => {
|
|
3406
|
+
app.component("CodeRunner", CodeRunner);
|
|
1534
3407
|
};
|
|
1535
|
-
const
|
|
1536
|
-
install(
|
|
1537
|
-
|
|
3408
|
+
const index = {
|
|
3409
|
+
install(app) {
|
|
3410
|
+
app.component("CodeRunner", CodeRunner);
|
|
1538
3411
|
}
|
|
1539
3412
|
};
|
|
1540
3413
|
export {
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
3414
|
+
CodeRunner,
|
|
3415
|
+
_sfc_main as CodeRunnerDialog,
|
|
3416
|
+
index as default
|
|
1544
3417
|
};
|