@uiw/react-md-editor 3.12.2 → 3.14.0
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/README.md +9 -7
- package/dist/mdeditor.css +16 -11
- package/dist/mdeditor.js +1320 -1718
- package/dist/mdeditor.min.css +1 -1
- package/dist/mdeditor.min.js +1 -1
- package/dist/mdeditor.min.js.LICENSE.txt +1 -15
- package/esm/Editor.d.ts +5 -3
- package/esm/Editor.js +12 -5
- package/esm/Editor.js.map +4 -3
- package/esm/components/TextArea/index.css +8 -1
- package/esm/components/TextArea/index.less +8 -1
- package/esm/components/Toolbar/index.css +5 -0
- package/esm/components/Toolbar/index.d.ts +1 -0
- package/esm/components/Toolbar/index.js +3 -1
- package/esm/components/Toolbar/index.js.map +5 -3
- package/esm/components/Toolbar/index.less +5 -0
- package/esm/index.css +3 -0
- package/esm/index.less +3 -0
- package/lib/Context.js.map +1 -1
- package/lib/Editor.d.ts +5 -3
- package/lib/Editor.js +14 -6
- package/lib/Editor.js.map +11 -3
- package/lib/commands/bold.js.map +2 -1
- package/lib/commands/code.js.map +4 -1
- package/lib/commands/comment.js.map +2 -1
- package/lib/commands/image.js.map +2 -1
- package/lib/commands/index.js.map +2 -1
- package/lib/commands/italic.js.map +2 -1
- package/lib/commands/link.js.map +2 -1
- package/lib/commands/list.js.map +4 -1
- package/lib/commands/quote.js.map +4 -1
- package/lib/commands/strikeThrough.js.map +2 -1
- package/lib/commands/title1.js.map +2 -1
- package/lib/commands/title2.js.map +2 -1
- package/lib/commands/title3.js.map +2 -1
- package/lib/commands/title4.js.map +2 -1
- package/lib/commands/title5.js.map +2 -1
- package/lib/commands/title6.js.map +2 -1
- package/lib/components/DragBar/index.js.map +5 -2
- package/lib/components/TextArea/Markdown.js.map +5 -1
- package/lib/components/TextArea/Textarea.js.map +5 -1
- package/lib/components/TextArea/handleKeyDown.js.map +3 -1
- package/lib/components/TextArea/index.js.map +3 -2
- package/lib/components/TextArea/index.less +8 -1
- package/lib/components/Toolbar/Child.js.map +3 -1
- package/lib/components/Toolbar/index.d.ts +1 -0
- package/lib/components/Toolbar/index.js +3 -1
- package/lib/components/Toolbar/index.js.map +8 -3
- package/lib/components/Toolbar/index.less +5 -0
- package/lib/index.less +3 -0
- package/markdown-editor.css +16 -1
- package/package.json +12 -12
- package/src/Editor.tsx +14 -6
- package/src/__test__/editor.test.tsx +1 -1
- package/src/components/TextArea/index.less +8 -1
- package/src/components/Toolbar/index.less +5 -0
- package/src/components/Toolbar/index.tsx +4 -2
- package/src/index.less +3 -0
package/dist/mdeditor.js
CHANGED
|
@@ -1367,294 +1367,6 @@ encode.componentChars = "-_.!~*'()";
|
|
|
1367
1367
|
module.exports = encode;
|
|
1368
1368
|
|
|
1369
1369
|
|
|
1370
|
-
/***/ }),
|
|
1371
|
-
|
|
1372
|
-
/***/ 770:
|
|
1373
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1374
|
-
|
|
1375
|
-
"use strict";
|
|
1376
|
-
|
|
1377
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1378
|
-
exports.compile = void 0;
|
|
1379
|
-
var boolbase_1 = __webpack_require__(407);
|
|
1380
|
-
/**
|
|
1381
|
-
* Returns a function that checks if an elements index matches the given rule
|
|
1382
|
-
* highly optimized to return the fastest solution.
|
|
1383
|
-
*
|
|
1384
|
-
* @param parsed A tuple [a, b], as returned by `parse`.
|
|
1385
|
-
* @returns A highly optimized function that returns whether an index matches the nth-check.
|
|
1386
|
-
* @example
|
|
1387
|
-
* const check = nthCheck.compile([2, 3]);
|
|
1388
|
-
*
|
|
1389
|
-
* check(0); // `false`
|
|
1390
|
-
* check(1); // `false`
|
|
1391
|
-
* check(2); // `true`
|
|
1392
|
-
* check(3); // `false`
|
|
1393
|
-
* check(4); // `true`
|
|
1394
|
-
* check(5); // `false`
|
|
1395
|
-
* check(6); // `true`
|
|
1396
|
-
*/
|
|
1397
|
-
function compile(parsed) {
|
|
1398
|
-
var a = parsed[0];
|
|
1399
|
-
// Subtract 1 from `b`, to convert from one- to zero-indexed.
|
|
1400
|
-
var b = parsed[1] - 1;
|
|
1401
|
-
/*
|
|
1402
|
-
* When `b <= 0`, `a * n` won't be lead to any matches for `a < 0`.
|
|
1403
|
-
* Besides, the specification states that no elements are
|
|
1404
|
-
* matched when `a` and `b` are 0.
|
|
1405
|
-
*
|
|
1406
|
-
* `b < 0` here as we subtracted 1 from `b` above.
|
|
1407
|
-
*/
|
|
1408
|
-
if (b < 0 && a <= 0)
|
|
1409
|
-
return boolbase_1.falseFunc;
|
|
1410
|
-
// When `a` is in the range -1..1, it matches any element (so only `b` is checked).
|
|
1411
|
-
if (a === -1)
|
|
1412
|
-
return function (index) { return index <= b; };
|
|
1413
|
-
if (a === 0)
|
|
1414
|
-
return function (index) { return index === b; };
|
|
1415
|
-
// When `b <= 0` and `a === 1`, they match any element.
|
|
1416
|
-
if (a === 1)
|
|
1417
|
-
return b < 0 ? boolbase_1.trueFunc : function (index) { return index >= b; };
|
|
1418
|
-
/*
|
|
1419
|
-
* Otherwise, modulo can be used to check if there is a match.
|
|
1420
|
-
*
|
|
1421
|
-
* Modulo doesn't care about the sign, so let's use `a`s absolute value.
|
|
1422
|
-
*/
|
|
1423
|
-
var absA = Math.abs(a);
|
|
1424
|
-
// Get `b mod a`, + a if this is negative.
|
|
1425
|
-
var bMod = ((b % absA) + absA) % absA;
|
|
1426
|
-
return a > 1
|
|
1427
|
-
? function (index) { return index >= b && index % absA === bMod; }
|
|
1428
|
-
: function (index) { return index <= b && index % absA === bMod; };
|
|
1429
|
-
}
|
|
1430
|
-
exports.compile = compile;
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
/***/ }),
|
|
1434
|
-
|
|
1435
|
-
/***/ 483:
|
|
1436
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1437
|
-
|
|
1438
|
-
"use strict";
|
|
1439
|
-
var __webpack_unused_export__;
|
|
1440
|
-
|
|
1441
|
-
__webpack_unused_export__ = ({ value: true });
|
|
1442
|
-
__webpack_unused_export__ = __webpack_unused_export__ = void 0;
|
|
1443
|
-
var parse_1 = __webpack_require__(711);
|
|
1444
|
-
__webpack_unused_export__ = ({ enumerable: true, get: function () { return parse_1.parse; } });
|
|
1445
|
-
var compile_1 = __webpack_require__(770);
|
|
1446
|
-
__webpack_unused_export__ = ({ enumerable: true, get: function () { return compile_1.compile; } });
|
|
1447
|
-
/**
|
|
1448
|
-
* Parses and compiles a formula to a highly optimized function.
|
|
1449
|
-
* Combination of `parse` and `compile`.
|
|
1450
|
-
*
|
|
1451
|
-
* If the formula doesn't match any elements,
|
|
1452
|
-
* it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
|
|
1453
|
-
* Otherwise, a function accepting an _index_ is returned, which returns
|
|
1454
|
-
* whether or not the passed _index_ matches the formula.
|
|
1455
|
-
*
|
|
1456
|
-
* Note: The nth-rule starts counting at `1`, the returned function at `0`.
|
|
1457
|
-
*
|
|
1458
|
-
* @param formula The formula to compile.
|
|
1459
|
-
* @example
|
|
1460
|
-
* const check = nthCheck("2n+3");
|
|
1461
|
-
*
|
|
1462
|
-
* check(0); // `false`
|
|
1463
|
-
* check(1); // `false`
|
|
1464
|
-
* check(2); // `true`
|
|
1465
|
-
* check(3); // `false`
|
|
1466
|
-
* check(4); // `true`
|
|
1467
|
-
* check(5); // `false`
|
|
1468
|
-
* check(6); // `true`
|
|
1469
|
-
*/
|
|
1470
|
-
function nthCheck(formula) {
|
|
1471
|
-
return (0, compile_1.compile)((0, parse_1.parse)(formula));
|
|
1472
|
-
}
|
|
1473
|
-
exports.ZP = nthCheck;
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
/***/ }),
|
|
1477
|
-
|
|
1478
|
-
/***/ 711:
|
|
1479
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
1480
|
-
|
|
1481
|
-
"use strict";
|
|
1482
|
-
|
|
1483
|
-
// Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
|
|
1484
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1485
|
-
exports.parse = void 0;
|
|
1486
|
-
// Whitespace as per https://www.w3.org/TR/selectors-3/#lex is " \t\r\n\f"
|
|
1487
|
-
var whitespace = new Set([9, 10, 12, 13, 32]);
|
|
1488
|
-
var ZERO = "0".charCodeAt(0);
|
|
1489
|
-
var NINE = "9".charCodeAt(0);
|
|
1490
|
-
/**
|
|
1491
|
-
* Parses an expression.
|
|
1492
|
-
*
|
|
1493
|
-
* @throws An `Error` if parsing fails.
|
|
1494
|
-
* @returns An array containing the integer step size and the integer offset of the nth rule.
|
|
1495
|
-
* @example nthCheck.parse("2n+3"); // returns [2, 3]
|
|
1496
|
-
*/
|
|
1497
|
-
function parse(formula) {
|
|
1498
|
-
formula = formula.trim().toLowerCase();
|
|
1499
|
-
if (formula === "even") {
|
|
1500
|
-
return [2, 0];
|
|
1501
|
-
}
|
|
1502
|
-
else if (formula === "odd") {
|
|
1503
|
-
return [2, 1];
|
|
1504
|
-
}
|
|
1505
|
-
// Parse [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
|
|
1506
|
-
var idx = 0;
|
|
1507
|
-
var a = 0;
|
|
1508
|
-
var sign = readSign();
|
|
1509
|
-
var number = readNumber();
|
|
1510
|
-
if (idx < formula.length && formula.charAt(idx) === "n") {
|
|
1511
|
-
idx++;
|
|
1512
|
-
a = sign * (number !== null && number !== void 0 ? number : 1);
|
|
1513
|
-
skipWhitespace();
|
|
1514
|
-
if (idx < formula.length) {
|
|
1515
|
-
sign = readSign();
|
|
1516
|
-
skipWhitespace();
|
|
1517
|
-
number = readNumber();
|
|
1518
|
-
}
|
|
1519
|
-
else {
|
|
1520
|
-
sign = number = 0;
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
// Throw if there is anything else
|
|
1524
|
-
if (number === null || idx < formula.length) {
|
|
1525
|
-
throw new Error("n-th rule couldn't be parsed ('" + formula + "')");
|
|
1526
|
-
}
|
|
1527
|
-
return [a, sign * number];
|
|
1528
|
-
function readSign() {
|
|
1529
|
-
if (formula.charAt(idx) === "-") {
|
|
1530
|
-
idx++;
|
|
1531
|
-
return -1;
|
|
1532
|
-
}
|
|
1533
|
-
if (formula.charAt(idx) === "+") {
|
|
1534
|
-
idx++;
|
|
1535
|
-
}
|
|
1536
|
-
return 1;
|
|
1537
|
-
}
|
|
1538
|
-
function readNumber() {
|
|
1539
|
-
var start = idx;
|
|
1540
|
-
var value = 0;
|
|
1541
|
-
while (idx < formula.length &&
|
|
1542
|
-
formula.charCodeAt(idx) >= ZERO &&
|
|
1543
|
-
formula.charCodeAt(idx) <= NINE) {
|
|
1544
|
-
value = value * 10 + (formula.charCodeAt(idx) - ZERO);
|
|
1545
|
-
idx++;
|
|
1546
|
-
}
|
|
1547
|
-
// Return `null` if we didn't read anything.
|
|
1548
|
-
return idx === start ? null : value;
|
|
1549
|
-
}
|
|
1550
|
-
function skipWhitespace() {
|
|
1551
|
-
while (idx < formula.length &&
|
|
1552
|
-
whitespace.has(formula.charCodeAt(idx))) {
|
|
1553
|
-
idx++;
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
exports.parse = parse;
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
/***/ }),
|
|
1561
|
-
|
|
1562
|
-
/***/ 323:
|
|
1563
|
-
/***/ ((module) => {
|
|
1564
|
-
|
|
1565
|
-
"use strict";
|
|
1566
|
-
/*
|
|
1567
|
-
object-assign
|
|
1568
|
-
(c) Sindre Sorhus
|
|
1569
|
-
@license MIT
|
|
1570
|
-
*/
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
/* eslint-disable no-unused-vars */
|
|
1574
|
-
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
1575
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1576
|
-
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
1577
|
-
|
|
1578
|
-
function toObject(val) {
|
|
1579
|
-
if (val === null || val === undefined) {
|
|
1580
|
-
throw new TypeError('Object.assign cannot be called with null or undefined');
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
return Object(val);
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
function shouldUseNative() {
|
|
1587
|
-
try {
|
|
1588
|
-
if (!Object.assign) {
|
|
1589
|
-
return false;
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
// Detect buggy property enumeration order in older V8 versions.
|
|
1593
|
-
|
|
1594
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
|
|
1595
|
-
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
|
|
1596
|
-
test1[5] = 'de';
|
|
1597
|
-
if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
|
1598
|
-
return false;
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
1602
|
-
var test2 = {};
|
|
1603
|
-
for (var i = 0; i < 10; i++) {
|
|
1604
|
-
test2['_' + String.fromCharCode(i)] = i;
|
|
1605
|
-
}
|
|
1606
|
-
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
|
1607
|
-
return test2[n];
|
|
1608
|
-
});
|
|
1609
|
-
if (order2.join('') !== '0123456789') {
|
|
1610
|
-
return false;
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
|
|
1614
|
-
var test3 = {};
|
|
1615
|
-
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
|
1616
|
-
test3[letter] = letter;
|
|
1617
|
-
});
|
|
1618
|
-
if (Object.keys(Object.assign({}, test3)).join('') !==
|
|
1619
|
-
'abcdefghijklmnopqrst') {
|
|
1620
|
-
return false;
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
return true;
|
|
1624
|
-
} catch (err) {
|
|
1625
|
-
// We don't expect any of the above to throw, but better to be safe.
|
|
1626
|
-
return false;
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
|
1631
|
-
var from;
|
|
1632
|
-
var to = toObject(target);
|
|
1633
|
-
var symbols;
|
|
1634
|
-
|
|
1635
|
-
for (var s = 1; s < arguments.length; s++) {
|
|
1636
|
-
from = Object(arguments[s]);
|
|
1637
|
-
|
|
1638
|
-
for (var key in from) {
|
|
1639
|
-
if (hasOwnProperty.call(from, key)) {
|
|
1640
|
-
to[key] = from[key];
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
if (getOwnPropertySymbols) {
|
|
1645
|
-
symbols = getOwnPropertySymbols(from);
|
|
1646
|
-
for (var i = 0; i < symbols.length; i++) {
|
|
1647
|
-
if (propIsEnumerable.call(from, symbols[i])) {
|
|
1648
|
-
to[symbols[i]] = from[symbols[i]];
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
return to;
|
|
1655
|
-
};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
1370
|
/***/ }),
|
|
1659
1371
|
|
|
1660
1372
|
/***/ 977:
|
|
@@ -9602,1276 +9314,6 @@ Mixin.install = function(host, Ctor, opts) {
|
|
|
9602
9314
|
module.exports = Mixin;
|
|
9603
9315
|
|
|
9604
9316
|
|
|
9605
|
-
/***/ }),
|
|
9606
|
-
|
|
9607
|
-
/***/ 975:
|
|
9608
|
-
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
9609
|
-
|
|
9610
|
-
/// <reference lib="WebWorker"/>
|
|
9611
|
-
|
|
9612
|
-
var _self = (typeof window !== 'undefined')
|
|
9613
|
-
? window // if in browser
|
|
9614
|
-
: (
|
|
9615
|
-
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
|
9616
|
-
? self // if in worker
|
|
9617
|
-
: {} // if in node js
|
|
9618
|
-
);
|
|
9619
|
-
|
|
9620
|
-
/**
|
|
9621
|
-
* Prism: Lightweight, robust, elegant syntax highlighting
|
|
9622
|
-
*
|
|
9623
|
-
* @license MIT <https://opensource.org/licenses/MIT>
|
|
9624
|
-
* @author Lea Verou <https://lea.verou.me>
|
|
9625
|
-
* @namespace
|
|
9626
|
-
* @public
|
|
9627
|
-
*/
|
|
9628
|
-
var Prism = (function (_self) {
|
|
9629
|
-
|
|
9630
|
-
// Private helper vars
|
|
9631
|
-
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
|
9632
|
-
var uniqueId = 0;
|
|
9633
|
-
|
|
9634
|
-
// The grammar object for plaintext
|
|
9635
|
-
var plainTextGrammar = {};
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
var _ = {
|
|
9639
|
-
/**
|
|
9640
|
-
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
|
9641
|
-
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
|
9642
|
-
* additional languages or plugins yourself.
|
|
9643
|
-
*
|
|
9644
|
-
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
|
9645
|
-
*
|
|
9646
|
-
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
|
9647
|
-
* empty Prism object into the global scope before loading the Prism script like this:
|
|
9648
|
-
*
|
|
9649
|
-
* ```js
|
|
9650
|
-
* window.Prism = window.Prism || {};
|
|
9651
|
-
* Prism.manual = true;
|
|
9652
|
-
* // add a new <script> to load Prism's script
|
|
9653
|
-
* ```
|
|
9654
|
-
*
|
|
9655
|
-
* @default false
|
|
9656
|
-
* @type {boolean}
|
|
9657
|
-
* @memberof Prism
|
|
9658
|
-
* @public
|
|
9659
|
-
*/
|
|
9660
|
-
manual: _self.Prism && _self.Prism.manual,
|
|
9661
|
-
/**
|
|
9662
|
-
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
|
9663
|
-
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
|
9664
|
-
* own worker, you don't want it to do this.
|
|
9665
|
-
*
|
|
9666
|
-
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
|
9667
|
-
*
|
|
9668
|
-
* You obviously have to change this value before Prism executes. To do this, you can add an
|
|
9669
|
-
* empty Prism object into the global scope before loading the Prism script like this:
|
|
9670
|
-
*
|
|
9671
|
-
* ```js
|
|
9672
|
-
* window.Prism = window.Prism || {};
|
|
9673
|
-
* Prism.disableWorkerMessageHandler = true;
|
|
9674
|
-
* // Load Prism's script
|
|
9675
|
-
* ```
|
|
9676
|
-
*
|
|
9677
|
-
* @default false
|
|
9678
|
-
* @type {boolean}
|
|
9679
|
-
* @memberof Prism
|
|
9680
|
-
* @public
|
|
9681
|
-
*/
|
|
9682
|
-
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
|
|
9683
|
-
|
|
9684
|
-
/**
|
|
9685
|
-
* A namespace for utility methods.
|
|
9686
|
-
*
|
|
9687
|
-
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
9688
|
-
* change or disappear at any time.
|
|
9689
|
-
*
|
|
9690
|
-
* @namespace
|
|
9691
|
-
* @memberof Prism
|
|
9692
|
-
*/
|
|
9693
|
-
util: {
|
|
9694
|
-
encode: function encode(tokens) {
|
|
9695
|
-
if (tokens instanceof Token) {
|
|
9696
|
-
return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
|
9697
|
-
} else if (Array.isArray(tokens)) {
|
|
9698
|
-
return tokens.map(encode);
|
|
9699
|
-
} else {
|
|
9700
|
-
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
|
9701
|
-
}
|
|
9702
|
-
},
|
|
9703
|
-
|
|
9704
|
-
/**
|
|
9705
|
-
* Returns the name of the type of the given value.
|
|
9706
|
-
*
|
|
9707
|
-
* @param {any} o
|
|
9708
|
-
* @returns {string}
|
|
9709
|
-
* @example
|
|
9710
|
-
* type(null) === 'Null'
|
|
9711
|
-
* type(undefined) === 'Undefined'
|
|
9712
|
-
* type(123) === 'Number'
|
|
9713
|
-
* type('foo') === 'String'
|
|
9714
|
-
* type(true) === 'Boolean'
|
|
9715
|
-
* type([1, 2]) === 'Array'
|
|
9716
|
-
* type({}) === 'Object'
|
|
9717
|
-
* type(String) === 'Function'
|
|
9718
|
-
* type(/abc+/) === 'RegExp'
|
|
9719
|
-
*/
|
|
9720
|
-
type: function (o) {
|
|
9721
|
-
return Object.prototype.toString.call(o).slice(8, -1);
|
|
9722
|
-
},
|
|
9723
|
-
|
|
9724
|
-
/**
|
|
9725
|
-
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
9726
|
-
*
|
|
9727
|
-
* @param {Object} obj
|
|
9728
|
-
* @returns {number}
|
|
9729
|
-
*/
|
|
9730
|
-
objId: function (obj) {
|
|
9731
|
-
if (!obj['__id']) {
|
|
9732
|
-
Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
|
9733
|
-
}
|
|
9734
|
-
return obj['__id'];
|
|
9735
|
-
},
|
|
9736
|
-
|
|
9737
|
-
/**
|
|
9738
|
-
* Creates a deep clone of the given object.
|
|
9739
|
-
*
|
|
9740
|
-
* The main intended use of this function is to clone language definitions.
|
|
9741
|
-
*
|
|
9742
|
-
* @param {T} o
|
|
9743
|
-
* @param {Record<number, any>} [visited]
|
|
9744
|
-
* @returns {T}
|
|
9745
|
-
* @template T
|
|
9746
|
-
*/
|
|
9747
|
-
clone: function deepClone(o, visited) {
|
|
9748
|
-
visited = visited || {};
|
|
9749
|
-
|
|
9750
|
-
var clone; var id;
|
|
9751
|
-
switch (_.util.type(o)) {
|
|
9752
|
-
case 'Object':
|
|
9753
|
-
id = _.util.objId(o);
|
|
9754
|
-
if (visited[id]) {
|
|
9755
|
-
return visited[id];
|
|
9756
|
-
}
|
|
9757
|
-
clone = /** @type {Record<string, any>} */ ({});
|
|
9758
|
-
visited[id] = clone;
|
|
9759
|
-
|
|
9760
|
-
for (var key in o) {
|
|
9761
|
-
if (o.hasOwnProperty(key)) {
|
|
9762
|
-
clone[key] = deepClone(o[key], visited);
|
|
9763
|
-
}
|
|
9764
|
-
}
|
|
9765
|
-
|
|
9766
|
-
return /** @type {any} */ (clone);
|
|
9767
|
-
|
|
9768
|
-
case 'Array':
|
|
9769
|
-
id = _.util.objId(o);
|
|
9770
|
-
if (visited[id]) {
|
|
9771
|
-
return visited[id];
|
|
9772
|
-
}
|
|
9773
|
-
clone = [];
|
|
9774
|
-
visited[id] = clone;
|
|
9775
|
-
|
|
9776
|
-
(/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
|
|
9777
|
-
clone[i] = deepClone(v, visited);
|
|
9778
|
-
});
|
|
9779
|
-
|
|
9780
|
-
return /** @type {any} */ (clone);
|
|
9781
|
-
|
|
9782
|
-
default:
|
|
9783
|
-
return o;
|
|
9784
|
-
}
|
|
9785
|
-
},
|
|
9786
|
-
|
|
9787
|
-
/**
|
|
9788
|
-
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
|
9789
|
-
*
|
|
9790
|
-
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
|
9791
|
-
*
|
|
9792
|
-
* @param {Element} element
|
|
9793
|
-
* @returns {string}
|
|
9794
|
-
*/
|
|
9795
|
-
getLanguage: function (element) {
|
|
9796
|
-
while (element) {
|
|
9797
|
-
var m = lang.exec(element.className);
|
|
9798
|
-
if (m) {
|
|
9799
|
-
return m[1].toLowerCase();
|
|
9800
|
-
}
|
|
9801
|
-
element = element.parentElement;
|
|
9802
|
-
}
|
|
9803
|
-
return 'none';
|
|
9804
|
-
},
|
|
9805
|
-
|
|
9806
|
-
/**
|
|
9807
|
-
* Sets the Prism `language-xxxx` class of the given element.
|
|
9808
|
-
*
|
|
9809
|
-
* @param {Element} element
|
|
9810
|
-
* @param {string} language
|
|
9811
|
-
* @returns {void}
|
|
9812
|
-
*/
|
|
9813
|
-
setLanguage: function (element, language) {
|
|
9814
|
-
// remove all `language-xxxx` classes
|
|
9815
|
-
// (this might leave behind a leading space)
|
|
9816
|
-
element.className = element.className.replace(RegExp(lang, 'gi'), '');
|
|
9817
|
-
|
|
9818
|
-
// add the new `language-xxxx` class
|
|
9819
|
-
// (using `classList` will automatically clean up spaces for us)
|
|
9820
|
-
element.classList.add('language-' + language);
|
|
9821
|
-
},
|
|
9822
|
-
|
|
9823
|
-
/**
|
|
9824
|
-
* Returns the script element that is currently executing.
|
|
9825
|
-
*
|
|
9826
|
-
* This does __not__ work for line script element.
|
|
9827
|
-
*
|
|
9828
|
-
* @returns {HTMLScriptElement | null}
|
|
9829
|
-
*/
|
|
9830
|
-
currentScript: function () {
|
|
9831
|
-
if (typeof document === 'undefined') {
|
|
9832
|
-
return null;
|
|
9833
|
-
}
|
|
9834
|
-
if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
|
|
9835
|
-
return /** @type {any} */ (document.currentScript);
|
|
9836
|
-
}
|
|
9837
|
-
|
|
9838
|
-
// IE11 workaround
|
|
9839
|
-
// we'll get the src of the current script by parsing IE11's error stack trace
|
|
9840
|
-
// this will not work for inline scripts
|
|
9841
|
-
|
|
9842
|
-
try {
|
|
9843
|
-
throw new Error();
|
|
9844
|
-
} catch (err) {
|
|
9845
|
-
// Get file src url from stack. Specifically works with the format of stack traces in IE.
|
|
9846
|
-
// A stack will look like this:
|
|
9847
|
-
//
|
|
9848
|
-
// Error
|
|
9849
|
-
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
|
|
9850
|
-
// at Global code (http://localhost/components/prism-core.js:606:1)
|
|
9851
|
-
|
|
9852
|
-
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
|
9853
|
-
if (src) {
|
|
9854
|
-
var scripts = document.getElementsByTagName('script');
|
|
9855
|
-
for (var i in scripts) {
|
|
9856
|
-
if (scripts[i].src == src) {
|
|
9857
|
-
return scripts[i];
|
|
9858
|
-
}
|
|
9859
|
-
}
|
|
9860
|
-
}
|
|
9861
|
-
return null;
|
|
9862
|
-
}
|
|
9863
|
-
},
|
|
9864
|
-
|
|
9865
|
-
/**
|
|
9866
|
-
* Returns whether a given class is active for `element`.
|
|
9867
|
-
*
|
|
9868
|
-
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
|
9869
|
-
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
|
9870
|
-
* given class is just the given class with a `no-` prefix.
|
|
9871
|
-
*
|
|
9872
|
-
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
|
9873
|
-
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
|
9874
|
-
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
|
9875
|
-
*
|
|
9876
|
-
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
|
9877
|
-
* version of it, the class is considered active.
|
|
9878
|
-
*
|
|
9879
|
-
* @param {Element} element
|
|
9880
|
-
* @param {string} className
|
|
9881
|
-
* @param {boolean} [defaultActivation=false]
|
|
9882
|
-
* @returns {boolean}
|
|
9883
|
-
*/
|
|
9884
|
-
isActive: function (element, className, defaultActivation) {
|
|
9885
|
-
var no = 'no-' + className;
|
|
9886
|
-
|
|
9887
|
-
while (element) {
|
|
9888
|
-
var classList = element.classList;
|
|
9889
|
-
if (classList.contains(className)) {
|
|
9890
|
-
return true;
|
|
9891
|
-
}
|
|
9892
|
-
if (classList.contains(no)) {
|
|
9893
|
-
return false;
|
|
9894
|
-
}
|
|
9895
|
-
element = element.parentElement;
|
|
9896
|
-
}
|
|
9897
|
-
return !!defaultActivation;
|
|
9898
|
-
}
|
|
9899
|
-
},
|
|
9900
|
-
|
|
9901
|
-
/**
|
|
9902
|
-
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
9903
|
-
*
|
|
9904
|
-
* @namespace
|
|
9905
|
-
* @memberof Prism
|
|
9906
|
-
* @public
|
|
9907
|
-
*/
|
|
9908
|
-
languages: {
|
|
9909
|
-
/**
|
|
9910
|
-
* The grammar for plain, unformatted text.
|
|
9911
|
-
*/
|
|
9912
|
-
plain: plainTextGrammar,
|
|
9913
|
-
plaintext: plainTextGrammar,
|
|
9914
|
-
text: plainTextGrammar,
|
|
9915
|
-
txt: plainTextGrammar,
|
|
9916
|
-
|
|
9917
|
-
/**
|
|
9918
|
-
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
9919
|
-
*
|
|
9920
|
-
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
9921
|
-
* will be overwritten at its original position.
|
|
9922
|
-
*
|
|
9923
|
-
* ## Best practices
|
|
9924
|
-
*
|
|
9925
|
-
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
9926
|
-
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
9927
|
-
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
9928
|
-
*
|
|
9929
|
-
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
9930
|
-
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
9931
|
-
*
|
|
9932
|
-
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
9933
|
-
* @param {Grammar} redef The new tokens to append.
|
|
9934
|
-
* @returns {Grammar} The new language created.
|
|
9935
|
-
* @public
|
|
9936
|
-
* @example
|
|
9937
|
-
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
9938
|
-
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
9939
|
-
* // at its original position
|
|
9940
|
-
* 'comment': { ... },
|
|
9941
|
-
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
9942
|
-
* 'color': /\b(?:red|green|blue)\b/
|
|
9943
|
-
* });
|
|
9944
|
-
*/
|
|
9945
|
-
extend: function (id, redef) {
|
|
9946
|
-
var lang = _.util.clone(_.languages[id]);
|
|
9947
|
-
|
|
9948
|
-
for (var key in redef) {
|
|
9949
|
-
lang[key] = redef[key];
|
|
9950
|
-
}
|
|
9951
|
-
|
|
9952
|
-
return lang;
|
|
9953
|
-
},
|
|
9954
|
-
|
|
9955
|
-
/**
|
|
9956
|
-
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
9957
|
-
*
|
|
9958
|
-
* ## Usage
|
|
9959
|
-
*
|
|
9960
|
-
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
9961
|
-
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
9962
|
-
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
9963
|
-
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
9964
|
-
* this:
|
|
9965
|
-
*
|
|
9966
|
-
* ```js
|
|
9967
|
-
* Prism.languages.markup.style = {
|
|
9968
|
-
* // token
|
|
9969
|
-
* };
|
|
9970
|
-
* ```
|
|
9971
|
-
*
|
|
9972
|
-
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
9973
|
-
* before existing tokens. For the CSS example above, you would use it like this:
|
|
9974
|
-
*
|
|
9975
|
-
* ```js
|
|
9976
|
-
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
9977
|
-
* 'style': {
|
|
9978
|
-
* // token
|
|
9979
|
-
* }
|
|
9980
|
-
* });
|
|
9981
|
-
* ```
|
|
9982
|
-
*
|
|
9983
|
-
* ## Special cases
|
|
9984
|
-
*
|
|
9985
|
-
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
9986
|
-
* will be ignored.
|
|
9987
|
-
*
|
|
9988
|
-
* This behavior can be used to insert tokens after `before`:
|
|
9989
|
-
*
|
|
9990
|
-
* ```js
|
|
9991
|
-
* Prism.languages.insertBefore('markup', 'comment', {
|
|
9992
|
-
* 'comment': Prism.languages.markup.comment,
|
|
9993
|
-
* // tokens after 'comment'
|
|
9994
|
-
* });
|
|
9995
|
-
* ```
|
|
9996
|
-
*
|
|
9997
|
-
* ## Limitations
|
|
9998
|
-
*
|
|
9999
|
-
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
10000
|
-
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
10001
|
-
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
10002
|
-
* deleting properties which is necessary to insert at arbitrary positions.
|
|
10003
|
-
*
|
|
10004
|
-
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
10005
|
-
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
10006
|
-
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
10007
|
-
*
|
|
10008
|
-
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
10009
|
-
* you hold the target object in a variable, then the value of the variable will not change.
|
|
10010
|
-
*
|
|
10011
|
-
* ```js
|
|
10012
|
-
* var oldMarkup = Prism.languages.markup;
|
|
10013
|
-
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
10014
|
-
*
|
|
10015
|
-
* assert(oldMarkup !== Prism.languages.markup);
|
|
10016
|
-
* assert(newMarkup === Prism.languages.markup);
|
|
10017
|
-
* ```
|
|
10018
|
-
*
|
|
10019
|
-
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
10020
|
-
* object to be modified.
|
|
10021
|
-
* @param {string} before The key to insert before.
|
|
10022
|
-
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
10023
|
-
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
10024
|
-
* object to be modified.
|
|
10025
|
-
*
|
|
10026
|
-
* Defaults to `Prism.languages`.
|
|
10027
|
-
* @returns {Grammar} The new grammar object.
|
|
10028
|
-
* @public
|
|
10029
|
-
*/
|
|
10030
|
-
insertBefore: function (inside, before, insert, root) {
|
|
10031
|
-
root = root || /** @type {any} */ (_.languages);
|
|
10032
|
-
var grammar = root[inside];
|
|
10033
|
-
/** @type {Grammar} */
|
|
10034
|
-
var ret = {};
|
|
10035
|
-
|
|
10036
|
-
for (var token in grammar) {
|
|
10037
|
-
if (grammar.hasOwnProperty(token)) {
|
|
10038
|
-
|
|
10039
|
-
if (token == before) {
|
|
10040
|
-
for (var newToken in insert) {
|
|
10041
|
-
if (insert.hasOwnProperty(newToken)) {
|
|
10042
|
-
ret[newToken] = insert[newToken];
|
|
10043
|
-
}
|
|
10044
|
-
}
|
|
10045
|
-
}
|
|
10046
|
-
|
|
10047
|
-
// Do not insert token which also occur in insert. See #1525
|
|
10048
|
-
if (!insert.hasOwnProperty(token)) {
|
|
10049
|
-
ret[token] = grammar[token];
|
|
10050
|
-
}
|
|
10051
|
-
}
|
|
10052
|
-
}
|
|
10053
|
-
|
|
10054
|
-
var old = root[inside];
|
|
10055
|
-
root[inside] = ret;
|
|
10056
|
-
|
|
10057
|
-
// Update references in other language definitions
|
|
10058
|
-
_.languages.DFS(_.languages, function (key, value) {
|
|
10059
|
-
if (value === old && key != inside) {
|
|
10060
|
-
this[key] = ret;
|
|
10061
|
-
}
|
|
10062
|
-
});
|
|
10063
|
-
|
|
10064
|
-
return ret;
|
|
10065
|
-
},
|
|
10066
|
-
|
|
10067
|
-
// Traverse a language definition with Depth First Search
|
|
10068
|
-
DFS: function DFS(o, callback, type, visited) {
|
|
10069
|
-
visited = visited || {};
|
|
10070
|
-
|
|
10071
|
-
var objId = _.util.objId;
|
|
10072
|
-
|
|
10073
|
-
for (var i in o) {
|
|
10074
|
-
if (o.hasOwnProperty(i)) {
|
|
10075
|
-
callback.call(o, i, o[i], type || i);
|
|
10076
|
-
|
|
10077
|
-
var property = o[i];
|
|
10078
|
-
var propertyType = _.util.type(property);
|
|
10079
|
-
|
|
10080
|
-
if (propertyType === 'Object' && !visited[objId(property)]) {
|
|
10081
|
-
visited[objId(property)] = true;
|
|
10082
|
-
DFS(property, callback, null, visited);
|
|
10083
|
-
} else if (propertyType === 'Array' && !visited[objId(property)]) {
|
|
10084
|
-
visited[objId(property)] = true;
|
|
10085
|
-
DFS(property, callback, i, visited);
|
|
10086
|
-
}
|
|
10087
|
-
}
|
|
10088
|
-
}
|
|
10089
|
-
}
|
|
10090
|
-
},
|
|
10091
|
-
|
|
10092
|
-
plugins: {},
|
|
10093
|
-
|
|
10094
|
-
/**
|
|
10095
|
-
* This is the most high-level function in Prism’s API.
|
|
10096
|
-
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
|
10097
|
-
* each one of them.
|
|
10098
|
-
*
|
|
10099
|
-
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
|
10100
|
-
*
|
|
10101
|
-
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
|
10102
|
-
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
|
10103
|
-
* @memberof Prism
|
|
10104
|
-
* @public
|
|
10105
|
-
*/
|
|
10106
|
-
highlightAll: function (async, callback) {
|
|
10107
|
-
_.highlightAllUnder(document, async, callback);
|
|
10108
|
-
},
|
|
10109
|
-
|
|
10110
|
-
/**
|
|
10111
|
-
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
|
10112
|
-
* {@link Prism.highlightElement} on each one of them.
|
|
10113
|
-
*
|
|
10114
|
-
* The following hooks will be run:
|
|
10115
|
-
* 1. `before-highlightall`
|
|
10116
|
-
* 2. `before-all-elements-highlight`
|
|
10117
|
-
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
|
10118
|
-
*
|
|
10119
|
-
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
|
10120
|
-
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
|
10121
|
-
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
|
10122
|
-
* @memberof Prism
|
|
10123
|
-
* @public
|
|
10124
|
-
*/
|
|
10125
|
-
highlightAllUnder: function (container, async, callback) {
|
|
10126
|
-
var env = {
|
|
10127
|
-
callback: callback,
|
|
10128
|
-
container: container,
|
|
10129
|
-
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
|
10130
|
-
};
|
|
10131
|
-
|
|
10132
|
-
_.hooks.run('before-highlightall', env);
|
|
10133
|
-
|
|
10134
|
-
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
|
10135
|
-
|
|
10136
|
-
_.hooks.run('before-all-elements-highlight', env);
|
|
10137
|
-
|
|
10138
|
-
for (var i = 0, element; (element = env.elements[i++]);) {
|
|
10139
|
-
_.highlightElement(element, async === true, env.callback);
|
|
10140
|
-
}
|
|
10141
|
-
},
|
|
10142
|
-
|
|
10143
|
-
/**
|
|
10144
|
-
* Highlights the code inside a single element.
|
|
10145
|
-
*
|
|
10146
|
-
* The following hooks will be run:
|
|
10147
|
-
* 1. `before-sanity-check`
|
|
10148
|
-
* 2. `before-highlight`
|
|
10149
|
-
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
|
10150
|
-
* 4. `before-insert`
|
|
10151
|
-
* 5. `after-highlight`
|
|
10152
|
-
* 6. `complete`
|
|
10153
|
-
*
|
|
10154
|
-
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
|
10155
|
-
* the element's language.
|
|
10156
|
-
*
|
|
10157
|
-
* @param {Element} element The element containing the code.
|
|
10158
|
-
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
|
10159
|
-
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
|
10160
|
-
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
|
10161
|
-
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
|
10162
|
-
*
|
|
10163
|
-
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
|
10164
|
-
* asynchronous highlighting to work. You can build your own bundle on the
|
|
10165
|
-
* [Download page](https://prismjs.com/download.html).
|
|
10166
|
-
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
|
10167
|
-
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
|
10168
|
-
* @memberof Prism
|
|
10169
|
-
* @public
|
|
10170
|
-
*/
|
|
10171
|
-
highlightElement: function (element, async, callback) {
|
|
10172
|
-
// Find language
|
|
10173
|
-
var language = _.util.getLanguage(element);
|
|
10174
|
-
var grammar = _.languages[language];
|
|
10175
|
-
|
|
10176
|
-
// Set language on the element, if not present
|
|
10177
|
-
_.util.setLanguage(element, language);
|
|
10178
|
-
|
|
10179
|
-
// Set language on the parent, for styling
|
|
10180
|
-
var parent = element.parentElement;
|
|
10181
|
-
if (parent && parent.nodeName.toLowerCase() === 'pre') {
|
|
10182
|
-
_.util.setLanguage(parent, language);
|
|
10183
|
-
}
|
|
10184
|
-
|
|
10185
|
-
var code = element.textContent;
|
|
10186
|
-
|
|
10187
|
-
var env = {
|
|
10188
|
-
element: element,
|
|
10189
|
-
language: language,
|
|
10190
|
-
grammar: grammar,
|
|
10191
|
-
code: code
|
|
10192
|
-
};
|
|
10193
|
-
|
|
10194
|
-
function insertHighlightedCode(highlightedCode) {
|
|
10195
|
-
env.highlightedCode = highlightedCode;
|
|
10196
|
-
|
|
10197
|
-
_.hooks.run('before-insert', env);
|
|
10198
|
-
|
|
10199
|
-
env.element.innerHTML = env.highlightedCode;
|
|
10200
|
-
|
|
10201
|
-
_.hooks.run('after-highlight', env);
|
|
10202
|
-
_.hooks.run('complete', env);
|
|
10203
|
-
callback && callback.call(env.element);
|
|
10204
|
-
}
|
|
10205
|
-
|
|
10206
|
-
_.hooks.run('before-sanity-check', env);
|
|
10207
|
-
|
|
10208
|
-
// plugins may change/add the parent/element
|
|
10209
|
-
parent = env.element.parentElement;
|
|
10210
|
-
if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
|
|
10211
|
-
parent.setAttribute('tabindex', '0');
|
|
10212
|
-
}
|
|
10213
|
-
|
|
10214
|
-
if (!env.code) {
|
|
10215
|
-
_.hooks.run('complete', env);
|
|
10216
|
-
callback && callback.call(env.element);
|
|
10217
|
-
return;
|
|
10218
|
-
}
|
|
10219
|
-
|
|
10220
|
-
_.hooks.run('before-highlight', env);
|
|
10221
|
-
|
|
10222
|
-
if (!env.grammar) {
|
|
10223
|
-
insertHighlightedCode(_.util.encode(env.code));
|
|
10224
|
-
return;
|
|
10225
|
-
}
|
|
10226
|
-
|
|
10227
|
-
if (async && _self.Worker) {
|
|
10228
|
-
var worker = new Worker(_.filename);
|
|
10229
|
-
|
|
10230
|
-
worker.onmessage = function (evt) {
|
|
10231
|
-
insertHighlightedCode(evt.data);
|
|
10232
|
-
};
|
|
10233
|
-
|
|
10234
|
-
worker.postMessage(JSON.stringify({
|
|
10235
|
-
language: env.language,
|
|
10236
|
-
code: env.code,
|
|
10237
|
-
immediateClose: true
|
|
10238
|
-
}));
|
|
10239
|
-
} else {
|
|
10240
|
-
insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
|
10241
|
-
}
|
|
10242
|
-
},
|
|
10243
|
-
|
|
10244
|
-
/**
|
|
10245
|
-
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
10246
|
-
* and the language definitions to use, and returns a string with the HTML produced.
|
|
10247
|
-
*
|
|
10248
|
-
* The following hooks will be run:
|
|
10249
|
-
* 1. `before-tokenize`
|
|
10250
|
-
* 2. `after-tokenize`
|
|
10251
|
-
* 3. `wrap`: On each {@link Token}.
|
|
10252
|
-
*
|
|
10253
|
-
* @param {string} text A string with the code to be highlighted.
|
|
10254
|
-
* @param {Grammar} grammar An object containing the tokens to use.
|
|
10255
|
-
*
|
|
10256
|
-
* Usually a language definition like `Prism.languages.markup`.
|
|
10257
|
-
* @param {string} language The name of the language definition passed to `grammar`.
|
|
10258
|
-
* @returns {string} The highlighted HTML.
|
|
10259
|
-
* @memberof Prism
|
|
10260
|
-
* @public
|
|
10261
|
-
* @example
|
|
10262
|
-
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
10263
|
-
*/
|
|
10264
|
-
highlight: function (text, grammar, language) {
|
|
10265
|
-
var env = {
|
|
10266
|
-
code: text,
|
|
10267
|
-
grammar: grammar,
|
|
10268
|
-
language: language
|
|
10269
|
-
};
|
|
10270
|
-
_.hooks.run('before-tokenize', env);
|
|
10271
|
-
if (!env.grammar) {
|
|
10272
|
-
throw new Error('The language "' + env.language + '" has no grammar.');
|
|
10273
|
-
}
|
|
10274
|
-
env.tokens = _.tokenize(env.code, env.grammar);
|
|
10275
|
-
_.hooks.run('after-tokenize', env);
|
|
10276
|
-
return Token.stringify(_.util.encode(env.tokens), env.language);
|
|
10277
|
-
},
|
|
10278
|
-
|
|
10279
|
-
/**
|
|
10280
|
-
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
10281
|
-
* and the language definitions to use, and returns an array with the tokenized code.
|
|
10282
|
-
*
|
|
10283
|
-
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
10284
|
-
*
|
|
10285
|
-
* This method could be useful in other contexts as well, as a very crude parser.
|
|
10286
|
-
*
|
|
10287
|
-
* @param {string} text A string with the code to be highlighted.
|
|
10288
|
-
* @param {Grammar} grammar An object containing the tokens to use.
|
|
10289
|
-
*
|
|
10290
|
-
* Usually a language definition like `Prism.languages.markup`.
|
|
10291
|
-
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
10292
|
-
* @memberof Prism
|
|
10293
|
-
* @public
|
|
10294
|
-
* @example
|
|
10295
|
-
* let code = `var foo = 0;`;
|
|
10296
|
-
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
10297
|
-
* tokens.forEach(token => {
|
|
10298
|
-
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
10299
|
-
* console.log(`Found numeric literal: ${token.content}`);
|
|
10300
|
-
* }
|
|
10301
|
-
* });
|
|
10302
|
-
*/
|
|
10303
|
-
tokenize: function (text, grammar) {
|
|
10304
|
-
var rest = grammar.rest;
|
|
10305
|
-
if (rest) {
|
|
10306
|
-
for (var token in rest) {
|
|
10307
|
-
grammar[token] = rest[token];
|
|
10308
|
-
}
|
|
10309
|
-
|
|
10310
|
-
delete grammar.rest;
|
|
10311
|
-
}
|
|
10312
|
-
|
|
10313
|
-
var tokenList = new LinkedList();
|
|
10314
|
-
addAfter(tokenList, tokenList.head, text);
|
|
10315
|
-
|
|
10316
|
-
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
|
10317
|
-
|
|
10318
|
-
return toArray(tokenList);
|
|
10319
|
-
},
|
|
10320
|
-
|
|
10321
|
-
/**
|
|
10322
|
-
* @namespace
|
|
10323
|
-
* @memberof Prism
|
|
10324
|
-
* @public
|
|
10325
|
-
*/
|
|
10326
|
-
hooks: {
|
|
10327
|
-
all: {},
|
|
10328
|
-
|
|
10329
|
-
/**
|
|
10330
|
-
* Adds the given callback to the list of callbacks for the given hook.
|
|
10331
|
-
*
|
|
10332
|
-
* The callback will be invoked when the hook it is registered for is run.
|
|
10333
|
-
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
10334
|
-
*
|
|
10335
|
-
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
10336
|
-
*
|
|
10337
|
-
* @param {string} name The name of the hook.
|
|
10338
|
-
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
10339
|
-
* @public
|
|
10340
|
-
*/
|
|
10341
|
-
add: function (name, callback) {
|
|
10342
|
-
var hooks = _.hooks.all;
|
|
10343
|
-
|
|
10344
|
-
hooks[name] = hooks[name] || [];
|
|
10345
|
-
|
|
10346
|
-
hooks[name].push(callback);
|
|
10347
|
-
},
|
|
10348
|
-
|
|
10349
|
-
/**
|
|
10350
|
-
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
10351
|
-
*
|
|
10352
|
-
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
10353
|
-
*
|
|
10354
|
-
* @param {string} name The name of the hook.
|
|
10355
|
-
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
10356
|
-
* @public
|
|
10357
|
-
*/
|
|
10358
|
-
run: function (name, env) {
|
|
10359
|
-
var callbacks = _.hooks.all[name];
|
|
10360
|
-
|
|
10361
|
-
if (!callbacks || !callbacks.length) {
|
|
10362
|
-
return;
|
|
10363
|
-
}
|
|
10364
|
-
|
|
10365
|
-
for (var i = 0, callback; (callback = callbacks[i++]);) {
|
|
10366
|
-
callback(env);
|
|
10367
|
-
}
|
|
10368
|
-
}
|
|
10369
|
-
},
|
|
10370
|
-
|
|
10371
|
-
Token: Token
|
|
10372
|
-
};
|
|
10373
|
-
_self.Prism = _;
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
// Typescript note:
|
|
10377
|
-
// The following can be used to import the Token type in JSDoc:
|
|
10378
|
-
//
|
|
10379
|
-
// @typedef {InstanceType<import("./prism-core")["Token"]>} Token
|
|
10380
|
-
|
|
10381
|
-
/**
|
|
10382
|
-
* Creates a new token.
|
|
10383
|
-
*
|
|
10384
|
-
* @param {string} type See {@link Token#type type}
|
|
10385
|
-
* @param {string | TokenStream} content See {@link Token#content content}
|
|
10386
|
-
* @param {string|string[]} [alias] The alias(es) of the token.
|
|
10387
|
-
* @param {string} [matchedStr=""] A copy of the full string this token was created from.
|
|
10388
|
-
* @class
|
|
10389
|
-
* @global
|
|
10390
|
-
* @public
|
|
10391
|
-
*/
|
|
10392
|
-
function Token(type, content, alias, matchedStr) {
|
|
10393
|
-
/**
|
|
10394
|
-
* The type of the token.
|
|
10395
|
-
*
|
|
10396
|
-
* This is usually the key of a pattern in a {@link Grammar}.
|
|
10397
|
-
*
|
|
10398
|
-
* @type {string}
|
|
10399
|
-
* @see GrammarToken
|
|
10400
|
-
* @public
|
|
10401
|
-
*/
|
|
10402
|
-
this.type = type;
|
|
10403
|
-
/**
|
|
10404
|
-
* The strings or tokens contained by this token.
|
|
10405
|
-
*
|
|
10406
|
-
* This will be a token stream if the pattern matched also defined an `inside` grammar.
|
|
10407
|
-
*
|
|
10408
|
-
* @type {string | TokenStream}
|
|
10409
|
-
* @public
|
|
10410
|
-
*/
|
|
10411
|
-
this.content = content;
|
|
10412
|
-
/**
|
|
10413
|
-
* The alias(es) of the token.
|
|
10414
|
-
*
|
|
10415
|
-
* @type {string|string[]}
|
|
10416
|
-
* @see GrammarToken
|
|
10417
|
-
* @public
|
|
10418
|
-
*/
|
|
10419
|
-
this.alias = alias;
|
|
10420
|
-
// Copy of the full string this token was created from
|
|
10421
|
-
this.length = (matchedStr || '').length | 0;
|
|
10422
|
-
}
|
|
10423
|
-
|
|
10424
|
-
/**
|
|
10425
|
-
* A token stream is an array of strings and {@link Token Token} objects.
|
|
10426
|
-
*
|
|
10427
|
-
* Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
|
|
10428
|
-
* them.
|
|
10429
|
-
*
|
|
10430
|
-
* 1. No adjacent strings.
|
|
10431
|
-
* 2. No empty strings.
|
|
10432
|
-
*
|
|
10433
|
-
* The only exception here is the token stream that only contains the empty string and nothing else.
|
|
10434
|
-
*
|
|
10435
|
-
* @typedef {Array<string | Token>} TokenStream
|
|
10436
|
-
* @global
|
|
10437
|
-
* @public
|
|
10438
|
-
*/
|
|
10439
|
-
|
|
10440
|
-
/**
|
|
10441
|
-
* Converts the given token or token stream to an HTML representation.
|
|
10442
|
-
*
|
|
10443
|
-
* The following hooks will be run:
|
|
10444
|
-
* 1. `wrap`: On each {@link Token}.
|
|
10445
|
-
*
|
|
10446
|
-
* @param {string | Token | TokenStream} o The token or token stream to be converted.
|
|
10447
|
-
* @param {string} language The name of current language.
|
|
10448
|
-
* @returns {string} The HTML representation of the token or token stream.
|
|
10449
|
-
* @memberof Token
|
|
10450
|
-
* @static
|
|
10451
|
-
*/
|
|
10452
|
-
Token.stringify = function stringify(o, language) {
|
|
10453
|
-
if (typeof o == 'string') {
|
|
10454
|
-
return o;
|
|
10455
|
-
}
|
|
10456
|
-
if (Array.isArray(o)) {
|
|
10457
|
-
var s = '';
|
|
10458
|
-
o.forEach(function (e) {
|
|
10459
|
-
s += stringify(e, language);
|
|
10460
|
-
});
|
|
10461
|
-
return s;
|
|
10462
|
-
}
|
|
10463
|
-
|
|
10464
|
-
var env = {
|
|
10465
|
-
type: o.type,
|
|
10466
|
-
content: stringify(o.content, language),
|
|
10467
|
-
tag: 'span',
|
|
10468
|
-
classes: ['token', o.type],
|
|
10469
|
-
attributes: {},
|
|
10470
|
-
language: language
|
|
10471
|
-
};
|
|
10472
|
-
|
|
10473
|
-
var aliases = o.alias;
|
|
10474
|
-
if (aliases) {
|
|
10475
|
-
if (Array.isArray(aliases)) {
|
|
10476
|
-
Array.prototype.push.apply(env.classes, aliases);
|
|
10477
|
-
} else {
|
|
10478
|
-
env.classes.push(aliases);
|
|
10479
|
-
}
|
|
10480
|
-
}
|
|
10481
|
-
|
|
10482
|
-
_.hooks.run('wrap', env);
|
|
10483
|
-
|
|
10484
|
-
var attributes = '';
|
|
10485
|
-
for (var name in env.attributes) {
|
|
10486
|
-
attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
|
10487
|
-
}
|
|
10488
|
-
|
|
10489
|
-
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
|
|
10490
|
-
};
|
|
10491
|
-
|
|
10492
|
-
/**
|
|
10493
|
-
* @param {RegExp} pattern
|
|
10494
|
-
* @param {number} pos
|
|
10495
|
-
* @param {string} text
|
|
10496
|
-
* @param {boolean} lookbehind
|
|
10497
|
-
* @returns {RegExpExecArray | null}
|
|
10498
|
-
*/
|
|
10499
|
-
function matchPattern(pattern, pos, text, lookbehind) {
|
|
10500
|
-
pattern.lastIndex = pos;
|
|
10501
|
-
var match = pattern.exec(text);
|
|
10502
|
-
if (match && lookbehind && match[1]) {
|
|
10503
|
-
// change the match to remove the text matched by the Prism lookbehind group
|
|
10504
|
-
var lookbehindLength = match[1].length;
|
|
10505
|
-
match.index += lookbehindLength;
|
|
10506
|
-
match[0] = match[0].slice(lookbehindLength);
|
|
10507
|
-
}
|
|
10508
|
-
return match;
|
|
10509
|
-
}
|
|
10510
|
-
|
|
10511
|
-
/**
|
|
10512
|
-
* @param {string} text
|
|
10513
|
-
* @param {LinkedList<string | Token>} tokenList
|
|
10514
|
-
* @param {any} grammar
|
|
10515
|
-
* @param {LinkedListNode<string | Token>} startNode
|
|
10516
|
-
* @param {number} startPos
|
|
10517
|
-
* @param {RematchOptions} [rematch]
|
|
10518
|
-
* @returns {void}
|
|
10519
|
-
* @private
|
|
10520
|
-
*
|
|
10521
|
-
* @typedef RematchOptions
|
|
10522
|
-
* @property {string} cause
|
|
10523
|
-
* @property {number} reach
|
|
10524
|
-
*/
|
|
10525
|
-
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
10526
|
-
for (var token in grammar) {
|
|
10527
|
-
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|
10528
|
-
continue;
|
|
10529
|
-
}
|
|
10530
|
-
|
|
10531
|
-
var patterns = grammar[token];
|
|
10532
|
-
patterns = Array.isArray(patterns) ? patterns : [patterns];
|
|
10533
|
-
|
|
10534
|
-
for (var j = 0; j < patterns.length; ++j) {
|
|
10535
|
-
if (rematch && rematch.cause == token + ',' + j) {
|
|
10536
|
-
return;
|
|
10537
|
-
}
|
|
10538
|
-
|
|
10539
|
-
var patternObj = patterns[j];
|
|
10540
|
-
var inside = patternObj.inside;
|
|
10541
|
-
var lookbehind = !!patternObj.lookbehind;
|
|
10542
|
-
var greedy = !!patternObj.greedy;
|
|
10543
|
-
var alias = patternObj.alias;
|
|
10544
|
-
|
|
10545
|
-
if (greedy && !patternObj.pattern.global) {
|
|
10546
|
-
// Without the global flag, lastIndex won't work
|
|
10547
|
-
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
|
10548
|
-
patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
|
|
10549
|
-
}
|
|
10550
|
-
|
|
10551
|
-
/** @type {RegExp} */
|
|
10552
|
-
var pattern = patternObj.pattern || patternObj;
|
|
10553
|
-
|
|
10554
|
-
for ( // iterate the token list and keep track of the current token/string position
|
|
10555
|
-
var currentNode = startNode.next, pos = startPos;
|
|
10556
|
-
currentNode !== tokenList.tail;
|
|
10557
|
-
pos += currentNode.value.length, currentNode = currentNode.next
|
|
10558
|
-
) {
|
|
10559
|
-
|
|
10560
|
-
if (rematch && pos >= rematch.reach) {
|
|
10561
|
-
break;
|
|
10562
|
-
}
|
|
10563
|
-
|
|
10564
|
-
var str = currentNode.value;
|
|
10565
|
-
|
|
10566
|
-
if (tokenList.length > text.length) {
|
|
10567
|
-
// Something went terribly wrong, ABORT, ABORT!
|
|
10568
|
-
return;
|
|
10569
|
-
}
|
|
10570
|
-
|
|
10571
|
-
if (str instanceof Token) {
|
|
10572
|
-
continue;
|
|
10573
|
-
}
|
|
10574
|
-
|
|
10575
|
-
var removeCount = 1; // this is the to parameter of removeBetween
|
|
10576
|
-
var match;
|
|
10577
|
-
|
|
10578
|
-
if (greedy) {
|
|
10579
|
-
match = matchPattern(pattern, pos, text, lookbehind);
|
|
10580
|
-
if (!match || match.index >= text.length) {
|
|
10581
|
-
break;
|
|
10582
|
-
}
|
|
10583
|
-
|
|
10584
|
-
var from = match.index;
|
|
10585
|
-
var to = match.index + match[0].length;
|
|
10586
|
-
var p = pos;
|
|
10587
|
-
|
|
10588
|
-
// find the node that contains the match
|
|
10589
|
-
p += currentNode.value.length;
|
|
10590
|
-
while (from >= p) {
|
|
10591
|
-
currentNode = currentNode.next;
|
|
10592
|
-
p += currentNode.value.length;
|
|
10593
|
-
}
|
|
10594
|
-
// adjust pos (and p)
|
|
10595
|
-
p -= currentNode.value.length;
|
|
10596
|
-
pos = p;
|
|
10597
|
-
|
|
10598
|
-
// the current node is a Token, then the match starts inside another Token, which is invalid
|
|
10599
|
-
if (currentNode.value instanceof Token) {
|
|
10600
|
-
continue;
|
|
10601
|
-
}
|
|
10602
|
-
|
|
10603
|
-
// find the last node which is affected by this match
|
|
10604
|
-
for (
|
|
10605
|
-
var k = currentNode;
|
|
10606
|
-
k !== tokenList.tail && (p < to || typeof k.value === 'string');
|
|
10607
|
-
k = k.next
|
|
10608
|
-
) {
|
|
10609
|
-
removeCount++;
|
|
10610
|
-
p += k.value.length;
|
|
10611
|
-
}
|
|
10612
|
-
removeCount--;
|
|
10613
|
-
|
|
10614
|
-
// replace with the new match
|
|
10615
|
-
str = text.slice(pos, p);
|
|
10616
|
-
match.index -= pos;
|
|
10617
|
-
} else {
|
|
10618
|
-
match = matchPattern(pattern, 0, str, lookbehind);
|
|
10619
|
-
if (!match) {
|
|
10620
|
-
continue;
|
|
10621
|
-
}
|
|
10622
|
-
}
|
|
10623
|
-
|
|
10624
|
-
// eslint-disable-next-line no-redeclare
|
|
10625
|
-
var from = match.index;
|
|
10626
|
-
var matchStr = match[0];
|
|
10627
|
-
var before = str.slice(0, from);
|
|
10628
|
-
var after = str.slice(from + matchStr.length);
|
|
10629
|
-
|
|
10630
|
-
var reach = pos + str.length;
|
|
10631
|
-
if (rematch && reach > rematch.reach) {
|
|
10632
|
-
rematch.reach = reach;
|
|
10633
|
-
}
|
|
10634
|
-
|
|
10635
|
-
var removeFrom = currentNode.prev;
|
|
10636
|
-
|
|
10637
|
-
if (before) {
|
|
10638
|
-
removeFrom = addAfter(tokenList, removeFrom, before);
|
|
10639
|
-
pos += before.length;
|
|
10640
|
-
}
|
|
10641
|
-
|
|
10642
|
-
removeRange(tokenList, removeFrom, removeCount);
|
|
10643
|
-
|
|
10644
|
-
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
|
10645
|
-
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
|
10646
|
-
|
|
10647
|
-
if (after) {
|
|
10648
|
-
addAfter(tokenList, currentNode, after);
|
|
10649
|
-
}
|
|
10650
|
-
|
|
10651
|
-
if (removeCount > 1) {
|
|
10652
|
-
// at least one Token object was removed, so we have to do some rematching
|
|
10653
|
-
// this can only happen if the current pattern is greedy
|
|
10654
|
-
|
|
10655
|
-
/** @type {RematchOptions} */
|
|
10656
|
-
var nestedRematch = {
|
|
10657
|
-
cause: token + ',' + j,
|
|
10658
|
-
reach: reach
|
|
10659
|
-
};
|
|
10660
|
-
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
|
10661
|
-
|
|
10662
|
-
// the reach might have been extended because of the rematching
|
|
10663
|
-
if (rematch && nestedRematch.reach > rematch.reach) {
|
|
10664
|
-
rematch.reach = nestedRematch.reach;
|
|
10665
|
-
}
|
|
10666
|
-
}
|
|
10667
|
-
}
|
|
10668
|
-
}
|
|
10669
|
-
}
|
|
10670
|
-
}
|
|
10671
|
-
|
|
10672
|
-
/**
|
|
10673
|
-
* @typedef LinkedListNode
|
|
10674
|
-
* @property {T} value
|
|
10675
|
-
* @property {LinkedListNode<T> | null} prev The previous node.
|
|
10676
|
-
* @property {LinkedListNode<T> | null} next The next node.
|
|
10677
|
-
* @template T
|
|
10678
|
-
* @private
|
|
10679
|
-
*/
|
|
10680
|
-
|
|
10681
|
-
/**
|
|
10682
|
-
* @template T
|
|
10683
|
-
* @private
|
|
10684
|
-
*/
|
|
10685
|
-
function LinkedList() {
|
|
10686
|
-
/** @type {LinkedListNode<T>} */
|
|
10687
|
-
var head = { value: null, prev: null, next: null };
|
|
10688
|
-
/** @type {LinkedListNode<T>} */
|
|
10689
|
-
var tail = { value: null, prev: head, next: null };
|
|
10690
|
-
head.next = tail;
|
|
10691
|
-
|
|
10692
|
-
/** @type {LinkedListNode<T>} */
|
|
10693
|
-
this.head = head;
|
|
10694
|
-
/** @type {LinkedListNode<T>} */
|
|
10695
|
-
this.tail = tail;
|
|
10696
|
-
this.length = 0;
|
|
10697
|
-
}
|
|
10698
|
-
|
|
10699
|
-
/**
|
|
10700
|
-
* Adds a new node with the given value to the list.
|
|
10701
|
-
*
|
|
10702
|
-
* @param {LinkedList<T>} list
|
|
10703
|
-
* @param {LinkedListNode<T>} node
|
|
10704
|
-
* @param {T} value
|
|
10705
|
-
* @returns {LinkedListNode<T>} The added node.
|
|
10706
|
-
* @template T
|
|
10707
|
-
*/
|
|
10708
|
-
function addAfter(list, node, value) {
|
|
10709
|
-
// assumes that node != list.tail && values.length >= 0
|
|
10710
|
-
var next = node.next;
|
|
10711
|
-
|
|
10712
|
-
var newNode = { value: value, prev: node, next: next };
|
|
10713
|
-
node.next = newNode;
|
|
10714
|
-
next.prev = newNode;
|
|
10715
|
-
list.length++;
|
|
10716
|
-
|
|
10717
|
-
return newNode;
|
|
10718
|
-
}
|
|
10719
|
-
/**
|
|
10720
|
-
* Removes `count` nodes after the given node. The given node will not be removed.
|
|
10721
|
-
*
|
|
10722
|
-
* @param {LinkedList<T>} list
|
|
10723
|
-
* @param {LinkedListNode<T>} node
|
|
10724
|
-
* @param {number} count
|
|
10725
|
-
* @template T
|
|
10726
|
-
*/
|
|
10727
|
-
function removeRange(list, node, count) {
|
|
10728
|
-
var next = node.next;
|
|
10729
|
-
for (var i = 0; i < count && next !== list.tail; i++) {
|
|
10730
|
-
next = next.next;
|
|
10731
|
-
}
|
|
10732
|
-
node.next = next;
|
|
10733
|
-
next.prev = node;
|
|
10734
|
-
list.length -= i;
|
|
10735
|
-
}
|
|
10736
|
-
/**
|
|
10737
|
-
* @param {LinkedList<T>} list
|
|
10738
|
-
* @returns {T[]}
|
|
10739
|
-
* @template T
|
|
10740
|
-
*/
|
|
10741
|
-
function toArray(list) {
|
|
10742
|
-
var array = [];
|
|
10743
|
-
var node = list.head.next;
|
|
10744
|
-
while (node !== list.tail) {
|
|
10745
|
-
array.push(node.value);
|
|
10746
|
-
node = node.next;
|
|
10747
|
-
}
|
|
10748
|
-
return array;
|
|
10749
|
-
}
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
if (!_self.document) {
|
|
10753
|
-
if (!_self.addEventListener) {
|
|
10754
|
-
// in Node.js
|
|
10755
|
-
return _;
|
|
10756
|
-
}
|
|
10757
|
-
|
|
10758
|
-
if (!_.disableWorkerMessageHandler) {
|
|
10759
|
-
// In worker
|
|
10760
|
-
_self.addEventListener('message', function (evt) {
|
|
10761
|
-
var message = JSON.parse(evt.data);
|
|
10762
|
-
var lang = message.language;
|
|
10763
|
-
var code = message.code;
|
|
10764
|
-
var immediateClose = message.immediateClose;
|
|
10765
|
-
|
|
10766
|
-
_self.postMessage(_.highlight(code, _.languages[lang], lang));
|
|
10767
|
-
if (immediateClose) {
|
|
10768
|
-
_self.close();
|
|
10769
|
-
}
|
|
10770
|
-
}, false);
|
|
10771
|
-
}
|
|
10772
|
-
|
|
10773
|
-
return _;
|
|
10774
|
-
}
|
|
10775
|
-
|
|
10776
|
-
// Get current script and highlight
|
|
10777
|
-
var script = _.util.currentScript();
|
|
10778
|
-
|
|
10779
|
-
if (script) {
|
|
10780
|
-
_.filename = script.src;
|
|
10781
|
-
|
|
10782
|
-
if (script.hasAttribute('data-manual')) {
|
|
10783
|
-
_.manual = true;
|
|
10784
|
-
}
|
|
10785
|
-
}
|
|
10786
|
-
|
|
10787
|
-
function highlightAutomaticallyCallback() {
|
|
10788
|
-
if (!_.manual) {
|
|
10789
|
-
_.highlightAll();
|
|
10790
|
-
}
|
|
10791
|
-
}
|
|
10792
|
-
|
|
10793
|
-
if (!_.manual) {
|
|
10794
|
-
// If the document state is "loading", then we'll use DOMContentLoaded.
|
|
10795
|
-
// If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
|
|
10796
|
-
// DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
|
|
10797
|
-
// might take longer one animation frame to execute which can create a race condition where only some plugins have
|
|
10798
|
-
// been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
|
|
10799
|
-
// See https://github.com/PrismJS/prism/issues/2102
|
|
10800
|
-
var readyState = document.readyState;
|
|
10801
|
-
if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
|
|
10802
|
-
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
|
|
10803
|
-
} else {
|
|
10804
|
-
if (window.requestAnimationFrame) {
|
|
10805
|
-
window.requestAnimationFrame(highlightAutomaticallyCallback);
|
|
10806
|
-
} else {
|
|
10807
|
-
window.setTimeout(highlightAutomaticallyCallback, 16);
|
|
10808
|
-
}
|
|
10809
|
-
}
|
|
10810
|
-
}
|
|
10811
|
-
|
|
10812
|
-
return _;
|
|
10813
|
-
|
|
10814
|
-
}(_self));
|
|
10815
|
-
|
|
10816
|
-
if ( true && module.exports) {
|
|
10817
|
-
module.exports = Prism;
|
|
10818
|
-
}
|
|
10819
|
-
|
|
10820
|
-
// hack for components to work correctly in node.js
|
|
10821
|
-
if (typeof __webpack_require__.g !== 'undefined') {
|
|
10822
|
-
__webpack_require__.g.Prism = Prism;
|
|
10823
|
-
}
|
|
10824
|
-
|
|
10825
|
-
// some additional documentation/types
|
|
10826
|
-
|
|
10827
|
-
/**
|
|
10828
|
-
* The expansion of a simple `RegExp` literal to support additional properties.
|
|
10829
|
-
*
|
|
10830
|
-
* @typedef GrammarToken
|
|
10831
|
-
* @property {RegExp} pattern The regular expression of the token.
|
|
10832
|
-
* @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
|
|
10833
|
-
* behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
|
|
10834
|
-
* @property {boolean} [greedy=false] Whether the token is greedy.
|
|
10835
|
-
* @property {string|string[]} [alias] An optional alias or list of aliases.
|
|
10836
|
-
* @property {Grammar} [inside] The nested grammar of this token.
|
|
10837
|
-
*
|
|
10838
|
-
* The `inside` grammar will be used to tokenize the text value of each token of this kind.
|
|
10839
|
-
*
|
|
10840
|
-
* This can be used to make nested and even recursive language definitions.
|
|
10841
|
-
*
|
|
10842
|
-
* Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
|
|
10843
|
-
* each another.
|
|
10844
|
-
* @global
|
|
10845
|
-
* @public
|
|
10846
|
-
*/
|
|
10847
|
-
|
|
10848
|
-
/**
|
|
10849
|
-
* @typedef Grammar
|
|
10850
|
-
* @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
|
|
10851
|
-
* @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
|
|
10852
|
-
* @global
|
|
10853
|
-
* @public
|
|
10854
|
-
*/
|
|
10855
|
-
|
|
10856
|
-
/**
|
|
10857
|
-
* A function which will invoked after an element was successfully highlighted.
|
|
10858
|
-
*
|
|
10859
|
-
* @callback HighlightCallback
|
|
10860
|
-
* @param {Element} element The element successfully highlighted.
|
|
10861
|
-
* @returns {void}
|
|
10862
|
-
* @global
|
|
10863
|
-
* @public
|
|
10864
|
-
*/
|
|
10865
|
-
|
|
10866
|
-
/**
|
|
10867
|
-
* @callback HookCallback
|
|
10868
|
-
* @param {Object<string, any>} env The environment variables of the hook.
|
|
10869
|
-
* @returns {void}
|
|
10870
|
-
* @global
|
|
10871
|
-
* @public
|
|
10872
|
-
*/
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
9317
|
/***/ }),
|
|
10876
9318
|
|
|
10877
9319
|
/***/ 59:
|
|
@@ -11026,7 +9468,8 @@ if (true) {
|
|
|
11026
9468
|
|
|
11027
9469
|
"use strict";
|
|
11028
9470
|
var __webpack_unused_export__;
|
|
11029
|
-
/**
|
|
9471
|
+
/**
|
|
9472
|
+
* @license React
|
|
11030
9473
|
* react-jsx-runtime.production.min.js
|
|
11031
9474
|
*
|
|
11032
9475
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
@@ -11034,8 +9477,8 @@ var __webpack_unused_export__;
|
|
|
11034
9477
|
* This source code is licensed under the MIT license found in the
|
|
11035
9478
|
* LICENSE file in the root directory of this source tree.
|
|
11036
9479
|
*/
|
|
11037
|
-
|
|
11038
|
-
function q(c,a,
|
|
9480
|
+
var f=__webpack_require__(787),k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
|
|
9481
|
+
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__webpack_unused_export__=l;exports.jsx=q;exports.jsxs=q;
|
|
11039
9482
|
|
|
11040
9483
|
|
|
11041
9484
|
/***/ }),
|
|
@@ -11161,18 +9604,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__787__;
|
|
|
11161
9604
|
/******/ };
|
|
11162
9605
|
/******/ })();
|
|
11163
9606
|
/******/
|
|
11164
|
-
/******/ /* webpack/runtime/global */
|
|
11165
|
-
/******/ (() => {
|
|
11166
|
-
/******/ __webpack_require__.g = (function() {
|
|
11167
|
-
/******/ if (typeof globalThis === 'object') return globalThis;
|
|
11168
|
-
/******/ try {
|
|
11169
|
-
/******/ return this || new Function('return this')();
|
|
11170
|
-
/******/ } catch (e) {
|
|
11171
|
-
/******/ if (typeof window === 'object') return window;
|
|
11172
|
-
/******/ }
|
|
11173
|
-
/******/ })();
|
|
11174
|
-
/******/ })();
|
|
11175
|
-
/******/
|
|
11176
9607
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
11177
9608
|
/******/ (() => {
|
|
11178
9609
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
@@ -11463,7 +9894,7 @@ var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_re
|
|
|
11463
9894
|
var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_);
|
|
11464
9895
|
;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
|
|
11465
9896
|
function _extends() {
|
|
11466
|
-
_extends = Object.assign
|
|
9897
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
11467
9898
|
for (var i = 1; i < arguments.length; i++) {
|
|
11468
9899
|
var source = arguments[i];
|
|
11469
9900
|
|
|
@@ -11476,7 +9907,6 @@ function _extends() {
|
|
|
11476
9907
|
|
|
11477
9908
|
return target;
|
|
11478
9909
|
};
|
|
11479
|
-
|
|
11480
9910
|
return _extends.apply(this, arguments);
|
|
11481
9911
|
}
|
|
11482
9912
|
// EXTERNAL MODULE: ./node_modules/is-buffer/index.js
|
|
@@ -17031,7 +15461,7 @@ function tokenizeSetextUnderline(effects, ok, nok) {
|
|
|
17031
15461
|
* to detect whether the HTML-like syntax is seen as HTML (flow) or not.
|
|
17032
15462
|
*
|
|
17033
15463
|
* This is copied from:
|
|
17034
|
-
* <https://spec.commonmark.org/0.
|
|
15464
|
+
* <https://spec.commonmark.org/0.30/#html-blocks>.
|
|
17035
15465
|
*/
|
|
17036
15466
|
const htmlBlockNames = [
|
|
17037
15467
|
'address',
|
|
@@ -17084,7 +15514,6 @@ const htmlBlockNames = [
|
|
|
17084
15514
|
'p',
|
|
17085
15515
|
'param',
|
|
17086
15516
|
'section',
|
|
17087
|
-
'source',
|
|
17088
15517
|
'summary',
|
|
17089
15518
|
'table',
|
|
17090
15519
|
'tbody',
|
|
@@ -17104,11 +15533,9 @@ const htmlBlockNames = [
|
|
|
17104
15533
|
* list is found (condition 1).
|
|
17105
15534
|
*
|
|
17106
15535
|
* This module is copied from:
|
|
17107
|
-
* <https://spec.commonmark.org/0.
|
|
15536
|
+
* <https://spec.commonmark.org/0.30/#html-blocks>.
|
|
17108
15537
|
*
|
|
17109
|
-
* Note that `textarea`
|
|
17110
|
-
* merged to the primary branch and is slated to be released in the next release
|
|
17111
|
-
* of CommonMark.
|
|
15538
|
+
* Note that `textarea` was added in `CommonMark@0.30`.
|
|
17112
15539
|
*/
|
|
17113
15540
|
const htmlRawNames = ['pre', 'script', 'style', 'textarea']
|
|
17114
15541
|
|
|
@@ -27953,17 +26380,182 @@ function escapeStringRegexp(string) {
|
|
|
27953
26380
|
.replace(/-/g, '\\x2d');
|
|
27954
26381
|
}
|
|
27955
26382
|
|
|
27956
|
-
;// CONCATENATED MODULE: ./node_modules/mdast-util-find-and-replace/
|
|
26383
|
+
;// CONCATENATED MODULE: ./node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/color.browser.js
|
|
26384
|
+
/**
|
|
26385
|
+
* @param {string} d
|
|
26386
|
+
* @returns {string}
|
|
26387
|
+
*/
|
|
26388
|
+
function unist_util_visit_parents_color_browser_color(d) {
|
|
26389
|
+
return d
|
|
26390
|
+
}
|
|
26391
|
+
|
|
26392
|
+
;// CONCATENATED MODULE: ./node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents/index.js
|
|
26393
|
+
/**
|
|
26394
|
+
* @typedef {import('unist').Node} Node
|
|
26395
|
+
* @typedef {import('unist').Parent} Parent
|
|
26396
|
+
* @typedef {import('unist-util-is').Test} Test
|
|
26397
|
+
* @typedef {import('./complex-types').Action} Action
|
|
26398
|
+
* @typedef {import('./complex-types').Index} Index
|
|
26399
|
+
* @typedef {import('./complex-types').ActionTuple} ActionTuple
|
|
26400
|
+
* @typedef {import('./complex-types').VisitorResult} VisitorResult
|
|
26401
|
+
* @typedef {import('./complex-types').Visitor} Visitor
|
|
26402
|
+
*/
|
|
26403
|
+
|
|
26404
|
+
|
|
26405
|
+
|
|
26406
|
+
|
|
26407
|
+
/**
|
|
26408
|
+
* Continue traversing as normal
|
|
26409
|
+
*/
|
|
26410
|
+
const node_modules_unist_util_visit_parents_CONTINUE = true
|
|
26411
|
+
/**
|
|
26412
|
+
* Do not traverse this node’s children
|
|
26413
|
+
*/
|
|
26414
|
+
const node_modules_unist_util_visit_parents_SKIP = 'skip'
|
|
26415
|
+
/**
|
|
26416
|
+
* Stop traversing immediately
|
|
26417
|
+
*/
|
|
26418
|
+
const node_modules_unist_util_visit_parents_EXIT = false
|
|
26419
|
+
|
|
26420
|
+
/**
|
|
26421
|
+
* Visit children of tree which pass a test
|
|
26422
|
+
*
|
|
26423
|
+
* @param tree Abstract syntax tree to walk
|
|
26424
|
+
* @param test Test node, optional
|
|
26425
|
+
* @param visitor Function to run for each node
|
|
26426
|
+
* @param reverse Visit the tree in reverse order, defaults to false
|
|
26427
|
+
*/
|
|
26428
|
+
const node_modules_unist_util_visit_parents_visitParents =
|
|
26429
|
+
/**
|
|
26430
|
+
* @type {(
|
|
26431
|
+
* (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: import('./complex-types').BuildVisitor<Tree, Check>, reverse?: boolean) => void) &
|
|
26432
|
+
* (<Tree extends Node>(tree: Tree, visitor: import('./complex-types').BuildVisitor<Tree>, reverse?: boolean) => void)
|
|
26433
|
+
* )}
|
|
26434
|
+
*/
|
|
26435
|
+
(
|
|
26436
|
+
/**
|
|
26437
|
+
* @param {Node} tree
|
|
26438
|
+
* @param {Test} test
|
|
26439
|
+
* @param {import('./complex-types').Visitor<Node>} visitor
|
|
26440
|
+
* @param {boolean} [reverse]
|
|
26441
|
+
*/
|
|
26442
|
+
function (tree, test, visitor, reverse) {
|
|
26443
|
+
if (typeof test === 'function' && typeof visitor !== 'function') {
|
|
26444
|
+
reverse = visitor
|
|
26445
|
+
// @ts-expect-error no visitor given, so `visitor` is test.
|
|
26446
|
+
visitor = test
|
|
26447
|
+
test = null
|
|
26448
|
+
}
|
|
26449
|
+
|
|
26450
|
+
const is = convert(test)
|
|
26451
|
+
const step = reverse ? -1 : 1
|
|
26452
|
+
|
|
26453
|
+
factory(tree, null, [])()
|
|
26454
|
+
|
|
26455
|
+
/**
|
|
26456
|
+
* @param {Node} node
|
|
26457
|
+
* @param {number?} index
|
|
26458
|
+
* @param {Array.<Parent>} parents
|
|
26459
|
+
*/
|
|
26460
|
+
function factory(node, index, parents) {
|
|
26461
|
+
/** @type {Object.<string, unknown>} */
|
|
26462
|
+
// @ts-expect-error: hush
|
|
26463
|
+
const value = typeof node === 'object' && node !== null ? node : {}
|
|
26464
|
+
/** @type {string|undefined} */
|
|
26465
|
+
let name
|
|
26466
|
+
|
|
26467
|
+
if (typeof value.type === 'string') {
|
|
26468
|
+
name =
|
|
26469
|
+
typeof value.tagName === 'string'
|
|
26470
|
+
? value.tagName
|
|
26471
|
+
: typeof value.name === 'string'
|
|
26472
|
+
? value.name
|
|
26473
|
+
: undefined
|
|
26474
|
+
|
|
26475
|
+
Object.defineProperty(visit, 'name', {
|
|
26476
|
+
value:
|
|
26477
|
+
'node (' +
|
|
26478
|
+
unist_util_visit_parents_color_browser_color(value.type + (name ? '<' + name + '>' : '')) +
|
|
26479
|
+
')'
|
|
26480
|
+
})
|
|
26481
|
+
}
|
|
26482
|
+
|
|
26483
|
+
return visit
|
|
26484
|
+
|
|
26485
|
+
function visit() {
|
|
26486
|
+
/** @type {ActionTuple} */
|
|
26487
|
+
let result = []
|
|
26488
|
+
/** @type {ActionTuple} */
|
|
26489
|
+
let subresult
|
|
26490
|
+
/** @type {number} */
|
|
26491
|
+
let offset
|
|
26492
|
+
/** @type {Array.<Parent>} */
|
|
26493
|
+
let grandparents
|
|
26494
|
+
|
|
26495
|
+
if (!test || is(node, index, parents[parents.length - 1] || null)) {
|
|
26496
|
+
result = node_modules_unist_util_visit_parents_toResult(visitor(node, parents))
|
|
26497
|
+
|
|
26498
|
+
if (result[0] === node_modules_unist_util_visit_parents_EXIT) {
|
|
26499
|
+
return result
|
|
26500
|
+
}
|
|
26501
|
+
}
|
|
26502
|
+
|
|
26503
|
+
// @ts-expect-error looks like a parent.
|
|
26504
|
+
if (node.children && result[0] !== node_modules_unist_util_visit_parents_SKIP) {
|
|
26505
|
+
// @ts-expect-error looks like a parent.
|
|
26506
|
+
offset = (reverse ? node.children.length : -1) + step
|
|
26507
|
+
// @ts-expect-error looks like a parent.
|
|
26508
|
+
grandparents = parents.concat(node)
|
|
26509
|
+
|
|
26510
|
+
// @ts-expect-error looks like a parent.
|
|
26511
|
+
while (offset > -1 && offset < node.children.length) {
|
|
26512
|
+
// @ts-expect-error looks like a parent.
|
|
26513
|
+
subresult = factory(node.children[offset], offset, grandparents)()
|
|
26514
|
+
|
|
26515
|
+
if (subresult[0] === node_modules_unist_util_visit_parents_EXIT) {
|
|
26516
|
+
return subresult
|
|
26517
|
+
}
|
|
26518
|
+
|
|
26519
|
+
offset =
|
|
26520
|
+
typeof subresult[1] === 'number' ? subresult[1] : offset + step
|
|
26521
|
+
}
|
|
26522
|
+
}
|
|
26523
|
+
|
|
26524
|
+
return result
|
|
26525
|
+
}
|
|
26526
|
+
}
|
|
26527
|
+
}
|
|
26528
|
+
)
|
|
26529
|
+
|
|
26530
|
+
/**
|
|
26531
|
+
* @param {VisitorResult} value
|
|
26532
|
+
* @returns {ActionTuple}
|
|
26533
|
+
*/
|
|
26534
|
+
function node_modules_unist_util_visit_parents_toResult(value) {
|
|
26535
|
+
if (Array.isArray(value)) {
|
|
26536
|
+
return value
|
|
26537
|
+
}
|
|
26538
|
+
|
|
26539
|
+
if (typeof value === 'number') {
|
|
26540
|
+
return [node_modules_unist_util_visit_parents_CONTINUE, value]
|
|
26541
|
+
}
|
|
26542
|
+
|
|
26543
|
+
return [value]
|
|
26544
|
+
}
|
|
26545
|
+
|
|
26546
|
+
;// CONCATENATED MODULE: ./node_modules/mdast-util-find-and-replace/lib/index.js
|
|
27957
26547
|
/**
|
|
27958
|
-
* @typedef Options
|
|
27959
|
-
*
|
|
26548
|
+
* @typedef Options
|
|
26549
|
+
* Configuration (optional).
|
|
26550
|
+
* @property {Test} [ignore]
|
|
26551
|
+
* `unist-util-is` test used to assert parents
|
|
27960
26552
|
*
|
|
27961
26553
|
* @typedef {import('mdast').Root} Root
|
|
27962
26554
|
* @typedef {import('mdast').Content} Content
|
|
27963
26555
|
* @typedef {import('mdast').PhrasingContent} PhrasingContent
|
|
27964
26556
|
* @typedef {import('mdast').Text} Text
|
|
27965
26557
|
* @typedef {Content|Root} Node
|
|
27966
|
-
* @typedef {Extract<Node, import('mdast').Parent>} Parent
|
|
26558
|
+
* @typedef {Exclude<Extract<Node, import('mdast').Parent>, Root>} Parent
|
|
27967
26559
|
*
|
|
27968
26560
|
* @typedef {import('unist-util-visit-parents').Test} Test
|
|
27969
26561
|
* @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
|
|
@@ -27971,29 +26563,30 @@ function escapeStringRegexp(string) {
|
|
|
27971
26563
|
* @typedef RegExpMatchObject
|
|
27972
26564
|
* @property {number} index
|
|
27973
26565
|
* @property {string} input
|
|
26566
|
+
* @property {[Root, ...Array<Parent>, Text]} stack
|
|
27974
26567
|
*
|
|
27975
26568
|
* @typedef {string|RegExp} Find
|
|
27976
26569
|
* @typedef {string|ReplaceFunction} Replace
|
|
27977
26570
|
*
|
|
27978
26571
|
* @typedef {[Find, Replace]} FindAndReplaceTuple
|
|
27979
|
-
* @typedef {
|
|
27980
|
-
* @typedef {Array
|
|
26572
|
+
* @typedef {Record<string, Replace>} FindAndReplaceSchema
|
|
26573
|
+
* @typedef {Array<FindAndReplaceTuple>} FindAndReplaceList
|
|
27981
26574
|
*
|
|
27982
26575
|
* @typedef {[RegExp, ReplaceFunction]} Pair
|
|
27983
|
-
* @typedef {Array
|
|
26576
|
+
* @typedef {Array<Pair>} Pairs
|
|
27984
26577
|
*/
|
|
27985
26578
|
|
|
27986
26579
|
/**
|
|
27987
26580
|
* @callback ReplaceFunction
|
|
27988
26581
|
* @param {...any} parameters
|
|
27989
|
-
* @returns {Array
|
|
26582
|
+
* @returns {Array<PhrasingContent>|PhrasingContent|string|false|undefined|null}
|
|
27990
26583
|
*/
|
|
27991
26584
|
|
|
27992
26585
|
|
|
27993
26586
|
|
|
27994
26587
|
|
|
27995
26588
|
|
|
27996
|
-
const
|
|
26589
|
+
const mdast_util_find_and_replace_lib_own = {}.hasOwnProperty
|
|
27997
26590
|
|
|
27998
26591
|
/**
|
|
27999
26592
|
* @param tree mdast tree
|
|
@@ -28044,12 +26637,12 @@ const findAndReplace =
|
|
|
28044
26637
|
let pairIndex = -1
|
|
28045
26638
|
|
|
28046
26639
|
while (++pairIndex < pairs.length) {
|
|
28047
|
-
|
|
26640
|
+
node_modules_unist_util_visit_parents_visitParents(tree, 'text', visitor)
|
|
28048
26641
|
}
|
|
28049
26642
|
|
|
28050
26643
|
return tree
|
|
28051
26644
|
|
|
28052
|
-
/** @type {import('unist-util-visit-parents').
|
|
26645
|
+
/** @type {import('unist-util-visit-parents/complex-types').BuildVisitor<Root, 'text'>} */
|
|
28053
26646
|
function visitor(node, parents) {
|
|
28054
26647
|
let index = -1
|
|
28055
26648
|
/** @type {Parent|undefined} */
|
|
@@ -28073,22 +26666,24 @@ const findAndReplace =
|
|
|
28073
26666
|
}
|
|
28074
26667
|
|
|
28075
26668
|
if (grandparent) {
|
|
28076
|
-
|
|
26669
|
+
// @ts-expect-error: stack is fine.
|
|
26670
|
+
return handler(node, parents)
|
|
28077
26671
|
}
|
|
28078
26672
|
}
|
|
28079
26673
|
|
|
28080
26674
|
/**
|
|
28081
26675
|
* @param {Text} node
|
|
28082
|
-
* @param {Parent}
|
|
26676
|
+
* @param {[Root, ...Array<Parent>]} parents
|
|
28083
26677
|
* @returns {VisitorResult}
|
|
28084
26678
|
*/
|
|
28085
|
-
function handler(node,
|
|
26679
|
+
function handler(node, parents) {
|
|
26680
|
+
const parent = parents[parents.length - 1]
|
|
28086
26681
|
const find = pairs[pairIndex][0]
|
|
28087
26682
|
const replace = pairs[pairIndex][1]
|
|
28088
26683
|
let start = 0
|
|
28089
26684
|
// @ts-expect-error: TS is wrong, some of these children can be text.
|
|
28090
|
-
|
|
28091
|
-
/** @type {Array
|
|
26685
|
+
const index = parent.children.indexOf(node)
|
|
26686
|
+
/** @type {Array<PhrasingContent>} */
|
|
28092
26687
|
let nodes = []
|
|
28093
26688
|
/** @type {number|undefined} */
|
|
28094
26689
|
let position
|
|
@@ -28099,17 +26694,21 @@ const findAndReplace =
|
|
|
28099
26694
|
|
|
28100
26695
|
while (match) {
|
|
28101
26696
|
position = match.index
|
|
28102
|
-
|
|
28103
|
-
|
|
26697
|
+
/** @type {RegExpMatchObject} */
|
|
26698
|
+
const matchObject = {
|
|
28104
26699
|
index: match.index,
|
|
28105
|
-
input: match.input
|
|
28106
|
-
|
|
26700
|
+
input: match.input,
|
|
26701
|
+
stack: [...parents, node]
|
|
26702
|
+
}
|
|
26703
|
+
let value = replace(...match, matchObject)
|
|
28107
26704
|
|
|
28108
26705
|
if (typeof value === 'string') {
|
|
28109
26706
|
value = value.length > 0 ? {type: 'text', value} : undefined
|
|
28110
26707
|
}
|
|
28111
26708
|
|
|
28112
|
-
if (value
|
|
26709
|
+
if (value === false) {
|
|
26710
|
+
position = undefined
|
|
26711
|
+
} else {
|
|
28113
26712
|
if (start !== position) {
|
|
28114
26713
|
nodes.push({
|
|
28115
26714
|
type: 'text',
|
|
@@ -28135,7 +26734,6 @@ const findAndReplace =
|
|
|
28135
26734
|
|
|
28136
26735
|
if (position === undefined) {
|
|
28137
26736
|
nodes = [node]
|
|
28138
|
-
index--
|
|
28139
26737
|
} else {
|
|
28140
26738
|
if (start < node.value.length) {
|
|
28141
26739
|
nodes.push({type: 'text', value: node.value.slice(start)})
|
|
@@ -28144,7 +26742,7 @@ const findAndReplace =
|
|
|
28144
26742
|
parent.children.splice(index, 1, ...nodes)
|
|
28145
26743
|
}
|
|
28146
26744
|
|
|
28147
|
-
return index + nodes.length
|
|
26745
|
+
return index + nodes.length
|
|
28148
26746
|
}
|
|
28149
26747
|
}
|
|
28150
26748
|
)
|
|
@@ -28175,7 +26773,7 @@ function toPairs(schema) {
|
|
|
28175
26773
|
let key
|
|
28176
26774
|
|
|
28177
26775
|
for (key in schema) {
|
|
28178
|
-
if (
|
|
26776
|
+
if (mdast_util_find_and_replace_lib_own.call(schema, key)) {
|
|
28179
26777
|
result.push([toExpression(key), toFunction(schema[key])])
|
|
28180
26778
|
}
|
|
28181
26779
|
}
|
|
@@ -38089,8 +36687,823 @@ function disallowed(code) {
|
|
|
38089
36687
|
)
|
|
38090
36688
|
}
|
|
38091
36689
|
|
|
38092
|
-
|
|
38093
|
-
|
|
36690
|
+
;// CONCATENATED MODULE: ./node_modules/refractor/lib/prism-core.js
|
|
36691
|
+
// @ts-nocheck
|
|
36692
|
+
|
|
36693
|
+
// This is a slimmed down version of `prism-core.js`, to remove globals,
|
|
36694
|
+
// document, workers, `util.encode`, `Token.stringify`
|
|
36695
|
+
|
|
36696
|
+
// Private helper vars
|
|
36697
|
+
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i
|
|
36698
|
+
var uniqueId = 0
|
|
36699
|
+
|
|
36700
|
+
// The grammar object for plaintext
|
|
36701
|
+
var plainTextGrammar = {}
|
|
36702
|
+
|
|
36703
|
+
var _ = {
|
|
36704
|
+
/**
|
|
36705
|
+
* A namespace for utility methods.
|
|
36706
|
+
*
|
|
36707
|
+
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
|
36708
|
+
* change or disappear at any time.
|
|
36709
|
+
*
|
|
36710
|
+
* @namespace
|
|
36711
|
+
* @memberof Prism
|
|
36712
|
+
*/
|
|
36713
|
+
util: {
|
|
36714
|
+
/**
|
|
36715
|
+
* Returns the name of the type of the given value.
|
|
36716
|
+
*
|
|
36717
|
+
* @param {any} o
|
|
36718
|
+
* @returns {string}
|
|
36719
|
+
* @example
|
|
36720
|
+
* type(null) === 'Null'
|
|
36721
|
+
* type(undefined) === 'Undefined'
|
|
36722
|
+
* type(123) === 'Number'
|
|
36723
|
+
* type('foo') === 'String'
|
|
36724
|
+
* type(true) === 'Boolean'
|
|
36725
|
+
* type([1, 2]) === 'Array'
|
|
36726
|
+
* type({}) === 'Object'
|
|
36727
|
+
* type(String) === 'Function'
|
|
36728
|
+
* type(/abc+/) === 'RegExp'
|
|
36729
|
+
*/
|
|
36730
|
+
type: function (o) {
|
|
36731
|
+
return Object.prototype.toString.call(o).slice(8, -1)
|
|
36732
|
+
},
|
|
36733
|
+
|
|
36734
|
+
/**
|
|
36735
|
+
* Returns a unique number for the given object. Later calls will still return the same number.
|
|
36736
|
+
*
|
|
36737
|
+
* @param {Object} obj
|
|
36738
|
+
* @returns {number}
|
|
36739
|
+
*/
|
|
36740
|
+
objId: function (obj) {
|
|
36741
|
+
if (!obj['__id']) {
|
|
36742
|
+
Object.defineProperty(obj, '__id', {value: ++uniqueId})
|
|
36743
|
+
}
|
|
36744
|
+
return obj['__id']
|
|
36745
|
+
},
|
|
36746
|
+
|
|
36747
|
+
/**
|
|
36748
|
+
* Creates a deep clone of the given object.
|
|
36749
|
+
*
|
|
36750
|
+
* The main intended use of this function is to clone language definitions.
|
|
36751
|
+
*
|
|
36752
|
+
* @param {T} o
|
|
36753
|
+
* @param {Record<number, any>} [visited]
|
|
36754
|
+
* @returns {T}
|
|
36755
|
+
* @template T
|
|
36756
|
+
*/
|
|
36757
|
+
clone: function deepClone(o, visited) {
|
|
36758
|
+
visited = visited || {}
|
|
36759
|
+
|
|
36760
|
+
var clone
|
|
36761
|
+
var id
|
|
36762
|
+
switch (_.util.type(o)) {
|
|
36763
|
+
case 'Object':
|
|
36764
|
+
id = _.util.objId(o)
|
|
36765
|
+
if (visited[id]) {
|
|
36766
|
+
return visited[id]
|
|
36767
|
+
}
|
|
36768
|
+
clone = /** @type {Record<string, any>} */ ({})
|
|
36769
|
+
visited[id] = clone
|
|
36770
|
+
|
|
36771
|
+
for (var key in o) {
|
|
36772
|
+
if (o.hasOwnProperty(key)) {
|
|
36773
|
+
clone[key] = deepClone(o[key], visited)
|
|
36774
|
+
}
|
|
36775
|
+
}
|
|
36776
|
+
|
|
36777
|
+
return /** @type {any} */ (clone)
|
|
36778
|
+
|
|
36779
|
+
case 'Array':
|
|
36780
|
+
id = _.util.objId(o)
|
|
36781
|
+
if (visited[id]) {
|
|
36782
|
+
return visited[id]
|
|
36783
|
+
}
|
|
36784
|
+
clone = []
|
|
36785
|
+
visited[id] = clone
|
|
36786
|
+
|
|
36787
|
+
o.forEach(function (v, i) {
|
|
36788
|
+
clone[i] = deepClone(v, visited)
|
|
36789
|
+
})
|
|
36790
|
+
|
|
36791
|
+
return /** @type {any} */ (clone)
|
|
36792
|
+
|
|
36793
|
+
default:
|
|
36794
|
+
return o
|
|
36795
|
+
}
|
|
36796
|
+
}
|
|
36797
|
+
},
|
|
36798
|
+
|
|
36799
|
+
/**
|
|
36800
|
+
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
|
36801
|
+
*
|
|
36802
|
+
* @namespace
|
|
36803
|
+
* @memberof Prism
|
|
36804
|
+
* @public
|
|
36805
|
+
*/
|
|
36806
|
+
languages: {
|
|
36807
|
+
/**
|
|
36808
|
+
* The grammar for plain, unformatted text.
|
|
36809
|
+
*/
|
|
36810
|
+
plain: plainTextGrammar,
|
|
36811
|
+
plaintext: plainTextGrammar,
|
|
36812
|
+
text: plainTextGrammar,
|
|
36813
|
+
txt: plainTextGrammar,
|
|
36814
|
+
|
|
36815
|
+
/**
|
|
36816
|
+
* Creates a deep copy of the language with the given id and appends the given tokens.
|
|
36817
|
+
*
|
|
36818
|
+
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
|
36819
|
+
* will be overwritten at its original position.
|
|
36820
|
+
*
|
|
36821
|
+
* ## Best practices
|
|
36822
|
+
*
|
|
36823
|
+
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
|
36824
|
+
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
|
36825
|
+
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
|
36826
|
+
*
|
|
36827
|
+
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
|
36828
|
+
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
|
36829
|
+
*
|
|
36830
|
+
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
|
36831
|
+
* @param {Grammar} redef The new tokens to append.
|
|
36832
|
+
* @returns {Grammar} The new language created.
|
|
36833
|
+
* @public
|
|
36834
|
+
* @example
|
|
36835
|
+
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
|
36836
|
+
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
|
36837
|
+
* // at its original position
|
|
36838
|
+
* 'comment': { ... },
|
|
36839
|
+
* // CSS doesn't have a 'color' token, so this token will be appended
|
|
36840
|
+
* 'color': /\b(?:red|green|blue)\b/
|
|
36841
|
+
* });
|
|
36842
|
+
*/
|
|
36843
|
+
extend: function (id, redef) {
|
|
36844
|
+
var lang = _.util.clone(_.languages[id])
|
|
36845
|
+
|
|
36846
|
+
for (var key in redef) {
|
|
36847
|
+
lang[key] = redef[key]
|
|
36848
|
+
}
|
|
36849
|
+
|
|
36850
|
+
return lang
|
|
36851
|
+
},
|
|
36852
|
+
|
|
36853
|
+
/**
|
|
36854
|
+
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
|
36855
|
+
*
|
|
36856
|
+
* ## Usage
|
|
36857
|
+
*
|
|
36858
|
+
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
|
36859
|
+
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
|
36860
|
+
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
|
36861
|
+
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
|
36862
|
+
* this:
|
|
36863
|
+
*
|
|
36864
|
+
* ```js
|
|
36865
|
+
* Prism.languages.markup.style = {
|
|
36866
|
+
* // token
|
|
36867
|
+
* };
|
|
36868
|
+
* ```
|
|
36869
|
+
*
|
|
36870
|
+
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
|
36871
|
+
* before existing tokens. For the CSS example above, you would use it like this:
|
|
36872
|
+
*
|
|
36873
|
+
* ```js
|
|
36874
|
+
* Prism.languages.insertBefore('markup', 'cdata', {
|
|
36875
|
+
* 'style': {
|
|
36876
|
+
* // token
|
|
36877
|
+
* }
|
|
36878
|
+
* });
|
|
36879
|
+
* ```
|
|
36880
|
+
*
|
|
36881
|
+
* ## Special cases
|
|
36882
|
+
*
|
|
36883
|
+
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
|
36884
|
+
* will be ignored.
|
|
36885
|
+
*
|
|
36886
|
+
* This behavior can be used to insert tokens after `before`:
|
|
36887
|
+
*
|
|
36888
|
+
* ```js
|
|
36889
|
+
* Prism.languages.insertBefore('markup', 'comment', {
|
|
36890
|
+
* 'comment': Prism.languages.markup.comment,
|
|
36891
|
+
* // tokens after 'comment'
|
|
36892
|
+
* });
|
|
36893
|
+
* ```
|
|
36894
|
+
*
|
|
36895
|
+
* ## Limitations
|
|
36896
|
+
*
|
|
36897
|
+
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
|
36898
|
+
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
|
36899
|
+
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
|
36900
|
+
* deleting properties which is necessary to insert at arbitrary positions.
|
|
36901
|
+
*
|
|
36902
|
+
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
|
36903
|
+
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
|
36904
|
+
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
|
36905
|
+
*
|
|
36906
|
+
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
|
36907
|
+
* you hold the target object in a variable, then the value of the variable will not change.
|
|
36908
|
+
*
|
|
36909
|
+
* ```js
|
|
36910
|
+
* var oldMarkup = Prism.languages.markup;
|
|
36911
|
+
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
|
36912
|
+
*
|
|
36913
|
+
* assert(oldMarkup !== Prism.languages.markup);
|
|
36914
|
+
* assert(newMarkup === Prism.languages.markup);
|
|
36915
|
+
* ```
|
|
36916
|
+
*
|
|
36917
|
+
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
|
36918
|
+
* object to be modified.
|
|
36919
|
+
* @param {string} before The key to insert before.
|
|
36920
|
+
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
|
36921
|
+
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
|
36922
|
+
* object to be modified.
|
|
36923
|
+
*
|
|
36924
|
+
* Defaults to `Prism.languages`.
|
|
36925
|
+
* @returns {Grammar} The new grammar object.
|
|
36926
|
+
* @public
|
|
36927
|
+
*/
|
|
36928
|
+
insertBefore: function (inside, before, insert, root) {
|
|
36929
|
+
root = root || /** @type {any} */ (_.languages)
|
|
36930
|
+
var grammar = root[inside]
|
|
36931
|
+
/** @type {Grammar} */
|
|
36932
|
+
var ret = {}
|
|
36933
|
+
|
|
36934
|
+
for (var token in grammar) {
|
|
36935
|
+
if (grammar.hasOwnProperty(token)) {
|
|
36936
|
+
if (token == before) {
|
|
36937
|
+
for (var newToken in insert) {
|
|
36938
|
+
if (insert.hasOwnProperty(newToken)) {
|
|
36939
|
+
ret[newToken] = insert[newToken]
|
|
36940
|
+
}
|
|
36941
|
+
}
|
|
36942
|
+
}
|
|
36943
|
+
|
|
36944
|
+
// Do not insert token which also occur in insert. See #1525
|
|
36945
|
+
if (!insert.hasOwnProperty(token)) {
|
|
36946
|
+
ret[token] = grammar[token]
|
|
36947
|
+
}
|
|
36948
|
+
}
|
|
36949
|
+
}
|
|
36950
|
+
|
|
36951
|
+
var old = root[inside]
|
|
36952
|
+
root[inside] = ret
|
|
36953
|
+
|
|
36954
|
+
// Update references in other language definitions
|
|
36955
|
+
_.languages.DFS(_.languages, function (key, value) {
|
|
36956
|
+
if (value === old && key != inside) {
|
|
36957
|
+
this[key] = ret
|
|
36958
|
+
}
|
|
36959
|
+
})
|
|
36960
|
+
|
|
36961
|
+
return ret
|
|
36962
|
+
},
|
|
36963
|
+
|
|
36964
|
+
// Traverse a language definition with Depth First Search
|
|
36965
|
+
DFS: function DFS(o, callback, type, visited) {
|
|
36966
|
+
visited = visited || {}
|
|
36967
|
+
|
|
36968
|
+
var objId = _.util.objId
|
|
36969
|
+
|
|
36970
|
+
for (var i in o) {
|
|
36971
|
+
if (o.hasOwnProperty(i)) {
|
|
36972
|
+
callback.call(o, i, o[i], type || i)
|
|
36973
|
+
|
|
36974
|
+
var property = o[i]
|
|
36975
|
+
var propertyType = _.util.type(property)
|
|
36976
|
+
|
|
36977
|
+
if (propertyType === 'Object' && !visited[objId(property)]) {
|
|
36978
|
+
visited[objId(property)] = true
|
|
36979
|
+
DFS(property, callback, null, visited)
|
|
36980
|
+
} else if (propertyType === 'Array' && !visited[objId(property)]) {
|
|
36981
|
+
visited[objId(property)] = true
|
|
36982
|
+
DFS(property, callback, i, visited)
|
|
36983
|
+
}
|
|
36984
|
+
}
|
|
36985
|
+
}
|
|
36986
|
+
}
|
|
36987
|
+
},
|
|
36988
|
+
|
|
36989
|
+
plugins: {},
|
|
36990
|
+
|
|
36991
|
+
/**
|
|
36992
|
+
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
|
36993
|
+
* and the language definitions to use, and returns a string with the HTML produced.
|
|
36994
|
+
*
|
|
36995
|
+
* The following hooks will be run:
|
|
36996
|
+
* 1. `before-tokenize`
|
|
36997
|
+
* 2. `after-tokenize`
|
|
36998
|
+
* 3. `wrap`: On each {@link Token}.
|
|
36999
|
+
*
|
|
37000
|
+
* @param {string} text A string with the code to be highlighted.
|
|
37001
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
37002
|
+
*
|
|
37003
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
37004
|
+
* @param {string} language The name of the language definition passed to `grammar`.
|
|
37005
|
+
* @returns {string} The highlighted HTML.
|
|
37006
|
+
* @memberof Prism
|
|
37007
|
+
* @public
|
|
37008
|
+
* @example
|
|
37009
|
+
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
|
37010
|
+
*/
|
|
37011
|
+
highlight: function (text, grammar, language) {
|
|
37012
|
+
var env = {
|
|
37013
|
+
code: text,
|
|
37014
|
+
grammar: grammar,
|
|
37015
|
+
language: language
|
|
37016
|
+
}
|
|
37017
|
+
_.hooks.run('before-tokenize', env)
|
|
37018
|
+
if (!env.grammar) {
|
|
37019
|
+
throw new Error('The language "' + env.language + '" has no grammar.')
|
|
37020
|
+
}
|
|
37021
|
+
env.tokens = _.tokenize(env.code, env.grammar)
|
|
37022
|
+
_.hooks.run('after-tokenize', env)
|
|
37023
|
+
return Token.stringify(_.util.encode(env.tokens), env.language)
|
|
37024
|
+
},
|
|
37025
|
+
|
|
37026
|
+
/**
|
|
37027
|
+
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
|
37028
|
+
* and the language definitions to use, and returns an array with the tokenized code.
|
|
37029
|
+
*
|
|
37030
|
+
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
|
37031
|
+
*
|
|
37032
|
+
* This method could be useful in other contexts as well, as a very crude parser.
|
|
37033
|
+
*
|
|
37034
|
+
* @param {string} text A string with the code to be highlighted.
|
|
37035
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
|
37036
|
+
*
|
|
37037
|
+
* Usually a language definition like `Prism.languages.markup`.
|
|
37038
|
+
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
|
37039
|
+
* @memberof Prism
|
|
37040
|
+
* @public
|
|
37041
|
+
* @example
|
|
37042
|
+
* let code = `var foo = 0;`;
|
|
37043
|
+
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
|
37044
|
+
* tokens.forEach(token => {
|
|
37045
|
+
* if (token instanceof Prism.Token && token.type === 'number') {
|
|
37046
|
+
* console.log(`Found numeric literal: ${token.content}`);
|
|
37047
|
+
* }
|
|
37048
|
+
* });
|
|
37049
|
+
*/
|
|
37050
|
+
tokenize: function (text, grammar) {
|
|
37051
|
+
var rest = grammar.rest
|
|
37052
|
+
if (rest) {
|
|
37053
|
+
for (var token in rest) {
|
|
37054
|
+
grammar[token] = rest[token]
|
|
37055
|
+
}
|
|
37056
|
+
|
|
37057
|
+
delete grammar.rest
|
|
37058
|
+
}
|
|
37059
|
+
|
|
37060
|
+
var tokenList = new LinkedList()
|
|
37061
|
+
addAfter(tokenList, tokenList.head, text)
|
|
37062
|
+
|
|
37063
|
+
matchGrammar(text, tokenList, grammar, tokenList.head, 0)
|
|
37064
|
+
|
|
37065
|
+
return toArray(tokenList)
|
|
37066
|
+
},
|
|
37067
|
+
|
|
37068
|
+
/**
|
|
37069
|
+
* @namespace
|
|
37070
|
+
* @memberof Prism
|
|
37071
|
+
* @public
|
|
37072
|
+
*/
|
|
37073
|
+
hooks: {
|
|
37074
|
+
all: {},
|
|
37075
|
+
|
|
37076
|
+
/**
|
|
37077
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
|
37078
|
+
*
|
|
37079
|
+
* The callback will be invoked when the hook it is registered for is run.
|
|
37080
|
+
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
|
37081
|
+
*
|
|
37082
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
|
37083
|
+
*
|
|
37084
|
+
* @param {string} name The name of the hook.
|
|
37085
|
+
* @param {HookCallback} callback The callback function which is given environment variables.
|
|
37086
|
+
* @public
|
|
37087
|
+
*/
|
|
37088
|
+
add: function (name, callback) {
|
|
37089
|
+
var hooks = _.hooks.all
|
|
37090
|
+
|
|
37091
|
+
hooks[name] = hooks[name] || []
|
|
37092
|
+
|
|
37093
|
+
hooks[name].push(callback)
|
|
37094
|
+
},
|
|
37095
|
+
|
|
37096
|
+
/**
|
|
37097
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
|
37098
|
+
*
|
|
37099
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
|
37100
|
+
*
|
|
37101
|
+
* @param {string} name The name of the hook.
|
|
37102
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
|
37103
|
+
* @public
|
|
37104
|
+
*/
|
|
37105
|
+
run: function (name, env) {
|
|
37106
|
+
var callbacks = _.hooks.all[name]
|
|
37107
|
+
|
|
37108
|
+
if (!callbacks || !callbacks.length) {
|
|
37109
|
+
return
|
|
37110
|
+
}
|
|
37111
|
+
|
|
37112
|
+
for (var i = 0, callback; (callback = callbacks[i++]); ) {
|
|
37113
|
+
callback(env)
|
|
37114
|
+
}
|
|
37115
|
+
}
|
|
37116
|
+
},
|
|
37117
|
+
|
|
37118
|
+
Token: Token
|
|
37119
|
+
}
|
|
37120
|
+
|
|
37121
|
+
// Typescript note:
|
|
37122
|
+
// The following can be used to import the Token type in JSDoc:
|
|
37123
|
+
//
|
|
37124
|
+
// @typedef {InstanceType<import("./prism-core")["Token"]>} Token
|
|
37125
|
+
|
|
37126
|
+
/**
|
|
37127
|
+
* Creates a new token.
|
|
37128
|
+
*
|
|
37129
|
+
* @param {string} type See {@link Token#type type}
|
|
37130
|
+
* @param {string | TokenStream} content See {@link Token#content content}
|
|
37131
|
+
* @param {string|string[]} [alias] The alias(es) of the token.
|
|
37132
|
+
* @param {string} [matchedStr=""] A copy of the full string this token was created from.
|
|
37133
|
+
* @class
|
|
37134
|
+
* @global
|
|
37135
|
+
* @public
|
|
37136
|
+
*/
|
|
37137
|
+
function Token(type, content, alias, matchedStr) {
|
|
37138
|
+
/**
|
|
37139
|
+
* The type of the token.
|
|
37140
|
+
*
|
|
37141
|
+
* This is usually the key of a pattern in a {@link Grammar}.
|
|
37142
|
+
*
|
|
37143
|
+
* @type {string}
|
|
37144
|
+
* @see GrammarToken
|
|
37145
|
+
* @public
|
|
37146
|
+
*/
|
|
37147
|
+
this.type = type
|
|
37148
|
+
/**
|
|
37149
|
+
* The strings or tokens contained by this token.
|
|
37150
|
+
*
|
|
37151
|
+
* This will be a token stream if the pattern matched also defined an `inside` grammar.
|
|
37152
|
+
*
|
|
37153
|
+
* @type {string | TokenStream}
|
|
37154
|
+
* @public
|
|
37155
|
+
*/
|
|
37156
|
+
this.content = content
|
|
37157
|
+
/**
|
|
37158
|
+
* The alias(es) of the token.
|
|
37159
|
+
*
|
|
37160
|
+
* @type {string|string[]}
|
|
37161
|
+
* @see GrammarToken
|
|
37162
|
+
* @public
|
|
37163
|
+
*/
|
|
37164
|
+
this.alias = alias
|
|
37165
|
+
// Copy of the full string this token was created from
|
|
37166
|
+
this.length = (matchedStr || '').length | 0
|
|
37167
|
+
}
|
|
37168
|
+
|
|
37169
|
+
/**
|
|
37170
|
+
* A token stream is an array of strings and {@link Token Token} objects.
|
|
37171
|
+
*
|
|
37172
|
+
* Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
|
|
37173
|
+
* them.
|
|
37174
|
+
*
|
|
37175
|
+
* 1. No adjacent strings.
|
|
37176
|
+
* 2. No empty strings.
|
|
37177
|
+
*
|
|
37178
|
+
* The only exception here is the token stream that only contains the empty string and nothing else.
|
|
37179
|
+
*
|
|
37180
|
+
* @typedef {Array<string | Token>} TokenStream
|
|
37181
|
+
* @global
|
|
37182
|
+
* @public
|
|
37183
|
+
*/
|
|
37184
|
+
|
|
37185
|
+
/**
|
|
37186
|
+
* @param {RegExp} pattern
|
|
37187
|
+
* @param {number} pos
|
|
37188
|
+
* @param {string} text
|
|
37189
|
+
* @param {boolean} lookbehind
|
|
37190
|
+
* @returns {RegExpExecArray | null}
|
|
37191
|
+
*/
|
|
37192
|
+
function matchPattern(pattern, pos, text, lookbehind) {
|
|
37193
|
+
pattern.lastIndex = pos
|
|
37194
|
+
var match = pattern.exec(text)
|
|
37195
|
+
if (match && lookbehind && match[1]) {
|
|
37196
|
+
// change the match to remove the text matched by the Prism lookbehind group
|
|
37197
|
+
var lookbehindLength = match[1].length
|
|
37198
|
+
match.index += lookbehindLength
|
|
37199
|
+
match[0] = match[0].slice(lookbehindLength)
|
|
37200
|
+
}
|
|
37201
|
+
return match
|
|
37202
|
+
}
|
|
37203
|
+
|
|
37204
|
+
/**
|
|
37205
|
+
* @param {string} text
|
|
37206
|
+
* @param {LinkedList<string | Token>} tokenList
|
|
37207
|
+
* @param {any} grammar
|
|
37208
|
+
* @param {LinkedListNode<string | Token>} startNode
|
|
37209
|
+
* @param {number} startPos
|
|
37210
|
+
* @param {RematchOptions} [rematch]
|
|
37211
|
+
* @returns {void}
|
|
37212
|
+
* @private
|
|
37213
|
+
*
|
|
37214
|
+
* @typedef RematchOptions
|
|
37215
|
+
* @property {string} cause
|
|
37216
|
+
* @property {number} reach
|
|
37217
|
+
*/
|
|
37218
|
+
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
|
37219
|
+
for (var token in grammar) {
|
|
37220
|
+
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
|
37221
|
+
continue
|
|
37222
|
+
}
|
|
37223
|
+
|
|
37224
|
+
var patterns = grammar[token]
|
|
37225
|
+
patterns = Array.isArray(patterns) ? patterns : [patterns]
|
|
37226
|
+
|
|
37227
|
+
for (var j = 0; j < patterns.length; ++j) {
|
|
37228
|
+
if (rematch && rematch.cause == token + ',' + j) {
|
|
37229
|
+
return
|
|
37230
|
+
}
|
|
37231
|
+
|
|
37232
|
+
var patternObj = patterns[j]
|
|
37233
|
+
var inside = patternObj.inside
|
|
37234
|
+
var lookbehind = !!patternObj.lookbehind
|
|
37235
|
+
var greedy = !!patternObj.greedy
|
|
37236
|
+
var alias = patternObj.alias
|
|
37237
|
+
|
|
37238
|
+
if (greedy && !patternObj.pattern.global) {
|
|
37239
|
+
// Without the global flag, lastIndex won't work
|
|
37240
|
+
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0]
|
|
37241
|
+
patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g')
|
|
37242
|
+
}
|
|
37243
|
+
|
|
37244
|
+
/** @type {RegExp} */
|
|
37245
|
+
var pattern = patternObj.pattern || patternObj
|
|
37246
|
+
|
|
37247
|
+
for (
|
|
37248
|
+
// iterate the token list and keep track of the current token/string position
|
|
37249
|
+
var currentNode = startNode.next, pos = startPos;
|
|
37250
|
+
currentNode !== tokenList.tail;
|
|
37251
|
+
pos += currentNode.value.length, currentNode = currentNode.next
|
|
37252
|
+
) {
|
|
37253
|
+
if (rematch && pos >= rematch.reach) {
|
|
37254
|
+
break
|
|
37255
|
+
}
|
|
37256
|
+
|
|
37257
|
+
var str = currentNode.value
|
|
37258
|
+
|
|
37259
|
+
if (tokenList.length > text.length) {
|
|
37260
|
+
// Something went terribly wrong, ABORT, ABORT!
|
|
37261
|
+
return
|
|
37262
|
+
}
|
|
37263
|
+
|
|
37264
|
+
if (str instanceof Token) {
|
|
37265
|
+
continue
|
|
37266
|
+
}
|
|
37267
|
+
|
|
37268
|
+
var removeCount = 1 // this is the to parameter of removeBetween
|
|
37269
|
+
var match
|
|
37270
|
+
|
|
37271
|
+
if (greedy) {
|
|
37272
|
+
match = matchPattern(pattern, pos, text, lookbehind)
|
|
37273
|
+
if (!match || match.index >= text.length) {
|
|
37274
|
+
break
|
|
37275
|
+
}
|
|
37276
|
+
|
|
37277
|
+
var from = match.index
|
|
37278
|
+
var to = match.index + match[0].length
|
|
37279
|
+
var p = pos
|
|
37280
|
+
|
|
37281
|
+
// find the node that contains the match
|
|
37282
|
+
p += currentNode.value.length
|
|
37283
|
+
while (from >= p) {
|
|
37284
|
+
currentNode = currentNode.next
|
|
37285
|
+
p += currentNode.value.length
|
|
37286
|
+
}
|
|
37287
|
+
// adjust pos (and p)
|
|
37288
|
+
p -= currentNode.value.length
|
|
37289
|
+
pos = p
|
|
37290
|
+
|
|
37291
|
+
// the current node is a Token, then the match starts inside another Token, which is invalid
|
|
37292
|
+
if (currentNode.value instanceof Token) {
|
|
37293
|
+
continue
|
|
37294
|
+
}
|
|
37295
|
+
|
|
37296
|
+
// find the last node which is affected by this match
|
|
37297
|
+
for (
|
|
37298
|
+
var k = currentNode;
|
|
37299
|
+
k !== tokenList.tail && (p < to || typeof k.value === 'string');
|
|
37300
|
+
k = k.next
|
|
37301
|
+
) {
|
|
37302
|
+
removeCount++
|
|
37303
|
+
p += k.value.length
|
|
37304
|
+
}
|
|
37305
|
+
removeCount--
|
|
37306
|
+
|
|
37307
|
+
// replace with the new match
|
|
37308
|
+
str = text.slice(pos, p)
|
|
37309
|
+
match.index -= pos
|
|
37310
|
+
} else {
|
|
37311
|
+
match = matchPattern(pattern, 0, str, lookbehind)
|
|
37312
|
+
if (!match) {
|
|
37313
|
+
continue
|
|
37314
|
+
}
|
|
37315
|
+
}
|
|
37316
|
+
|
|
37317
|
+
// eslint-disable-next-line no-redeclare
|
|
37318
|
+
var from = match.index
|
|
37319
|
+
var matchStr = match[0]
|
|
37320
|
+
var before = str.slice(0, from)
|
|
37321
|
+
var after = str.slice(from + matchStr.length)
|
|
37322
|
+
|
|
37323
|
+
var reach = pos + str.length
|
|
37324
|
+
if (rematch && reach > rematch.reach) {
|
|
37325
|
+
rematch.reach = reach
|
|
37326
|
+
}
|
|
37327
|
+
|
|
37328
|
+
var removeFrom = currentNode.prev
|
|
37329
|
+
|
|
37330
|
+
if (before) {
|
|
37331
|
+
removeFrom = addAfter(tokenList, removeFrom, before)
|
|
37332
|
+
pos += before.length
|
|
37333
|
+
}
|
|
37334
|
+
|
|
37335
|
+
removeRange(tokenList, removeFrom, removeCount)
|
|
37336
|
+
|
|
37337
|
+
var wrapped = new Token(
|
|
37338
|
+
token,
|
|
37339
|
+
inside ? _.tokenize(matchStr, inside) : matchStr,
|
|
37340
|
+
alias,
|
|
37341
|
+
matchStr
|
|
37342
|
+
)
|
|
37343
|
+
currentNode = addAfter(tokenList, removeFrom, wrapped)
|
|
37344
|
+
|
|
37345
|
+
if (after) {
|
|
37346
|
+
addAfter(tokenList, currentNode, after)
|
|
37347
|
+
}
|
|
37348
|
+
|
|
37349
|
+
if (removeCount > 1) {
|
|
37350
|
+
// at least one Token object was removed, so we have to do some rematching
|
|
37351
|
+
// this can only happen if the current pattern is greedy
|
|
37352
|
+
|
|
37353
|
+
/** @type {RematchOptions} */
|
|
37354
|
+
var nestedRematch = {
|
|
37355
|
+
cause: token + ',' + j,
|
|
37356
|
+
reach: reach
|
|
37357
|
+
}
|
|
37358
|
+
matchGrammar(
|
|
37359
|
+
text,
|
|
37360
|
+
tokenList,
|
|
37361
|
+
grammar,
|
|
37362
|
+
currentNode.prev,
|
|
37363
|
+
pos,
|
|
37364
|
+
nestedRematch
|
|
37365
|
+
)
|
|
37366
|
+
|
|
37367
|
+
// the reach might have been extended because of the rematching
|
|
37368
|
+
if (rematch && nestedRematch.reach > rematch.reach) {
|
|
37369
|
+
rematch.reach = nestedRematch.reach
|
|
37370
|
+
}
|
|
37371
|
+
}
|
|
37372
|
+
}
|
|
37373
|
+
}
|
|
37374
|
+
}
|
|
37375
|
+
}
|
|
37376
|
+
|
|
37377
|
+
/**
|
|
37378
|
+
* @typedef LinkedListNode
|
|
37379
|
+
* @property {T} value
|
|
37380
|
+
* @property {LinkedListNode<T> | null} prev The previous node.
|
|
37381
|
+
* @property {LinkedListNode<T> | null} next The next node.
|
|
37382
|
+
* @template T
|
|
37383
|
+
* @private
|
|
37384
|
+
*/
|
|
37385
|
+
|
|
37386
|
+
/**
|
|
37387
|
+
* @template T
|
|
37388
|
+
* @private
|
|
37389
|
+
*/
|
|
37390
|
+
function LinkedList() {
|
|
37391
|
+
/** @type {LinkedListNode<T>} */
|
|
37392
|
+
var head = {value: null, prev: null, next: null}
|
|
37393
|
+
/** @type {LinkedListNode<T>} */
|
|
37394
|
+
var tail = {value: null, prev: head, next: null}
|
|
37395
|
+
head.next = tail
|
|
37396
|
+
|
|
37397
|
+
/** @type {LinkedListNode<T>} */
|
|
37398
|
+
this.head = head
|
|
37399
|
+
/** @type {LinkedListNode<T>} */
|
|
37400
|
+
this.tail = tail
|
|
37401
|
+
this.length = 0
|
|
37402
|
+
}
|
|
37403
|
+
|
|
37404
|
+
/**
|
|
37405
|
+
* Adds a new node with the given value to the list.
|
|
37406
|
+
*
|
|
37407
|
+
* @param {LinkedList<T>} list
|
|
37408
|
+
* @param {LinkedListNode<T>} node
|
|
37409
|
+
* @param {T} value
|
|
37410
|
+
* @returns {LinkedListNode<T>} The added node.
|
|
37411
|
+
* @template T
|
|
37412
|
+
*/
|
|
37413
|
+
function addAfter(list, node, value) {
|
|
37414
|
+
// assumes that node != list.tail && values.length >= 0
|
|
37415
|
+
var next = node.next
|
|
37416
|
+
|
|
37417
|
+
var newNode = {value: value, prev: node, next: next}
|
|
37418
|
+
node.next = newNode
|
|
37419
|
+
next.prev = newNode
|
|
37420
|
+
list.length++
|
|
37421
|
+
|
|
37422
|
+
return newNode
|
|
37423
|
+
}
|
|
37424
|
+
/**
|
|
37425
|
+
* Removes `count` nodes after the given node. The given node will not be removed.
|
|
37426
|
+
*
|
|
37427
|
+
* @param {LinkedList<T>} list
|
|
37428
|
+
* @param {LinkedListNode<T>} node
|
|
37429
|
+
* @param {number} count
|
|
37430
|
+
* @template T
|
|
37431
|
+
*/
|
|
37432
|
+
function removeRange(list, node, count) {
|
|
37433
|
+
var next = node.next
|
|
37434
|
+
for (var i = 0; i < count && next !== list.tail; i++) {
|
|
37435
|
+
next = next.next
|
|
37436
|
+
}
|
|
37437
|
+
node.next = next
|
|
37438
|
+
next.prev = node
|
|
37439
|
+
list.length -= i
|
|
37440
|
+
}
|
|
37441
|
+
/**
|
|
37442
|
+
* @param {LinkedList<T>} list
|
|
37443
|
+
* @returns {T[]}
|
|
37444
|
+
* @template T
|
|
37445
|
+
*/
|
|
37446
|
+
function toArray(list) {
|
|
37447
|
+
var array = []
|
|
37448
|
+
var node = list.head.next
|
|
37449
|
+
while (node !== list.tail) {
|
|
37450
|
+
array.push(node.value)
|
|
37451
|
+
node = node.next
|
|
37452
|
+
}
|
|
37453
|
+
return array
|
|
37454
|
+
}
|
|
37455
|
+
|
|
37456
|
+
const Prism = _
|
|
37457
|
+
|
|
37458
|
+
// some additional documentation/types
|
|
37459
|
+
|
|
37460
|
+
/**
|
|
37461
|
+
* The expansion of a simple `RegExp` literal to support additional properties.
|
|
37462
|
+
*
|
|
37463
|
+
* @typedef GrammarToken
|
|
37464
|
+
* @property {RegExp} pattern The regular expression of the token.
|
|
37465
|
+
* @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
|
|
37466
|
+
* behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
|
|
37467
|
+
* @property {boolean} [greedy=false] Whether the token is greedy.
|
|
37468
|
+
* @property {string|string[]} [alias] An optional alias or list of aliases.
|
|
37469
|
+
* @property {Grammar} [inside] The nested grammar of this token.
|
|
37470
|
+
*
|
|
37471
|
+
* The `inside` grammar will be used to tokenize the text value of each token of this kind.
|
|
37472
|
+
*
|
|
37473
|
+
* This can be used to make nested and even recursive language definitions.
|
|
37474
|
+
*
|
|
37475
|
+
* Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
|
|
37476
|
+
* each another.
|
|
37477
|
+
* @global
|
|
37478
|
+
* @public
|
|
37479
|
+
*/
|
|
37480
|
+
|
|
37481
|
+
/**
|
|
37482
|
+
* @typedef Grammar
|
|
37483
|
+
* @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
|
|
37484
|
+
* @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
|
|
37485
|
+
* @global
|
|
37486
|
+
* @public
|
|
37487
|
+
*/
|
|
37488
|
+
|
|
37489
|
+
/**
|
|
37490
|
+
* A function which will invoked after an element was successfully highlighted.
|
|
37491
|
+
*
|
|
37492
|
+
* @callback HighlightCallback
|
|
37493
|
+
* @param {Element} element The element successfully highlighted.
|
|
37494
|
+
* @returns {void}
|
|
37495
|
+
* @global
|
|
37496
|
+
* @public
|
|
37497
|
+
*/
|
|
37498
|
+
|
|
37499
|
+
/**
|
|
37500
|
+
* @callback HookCallback
|
|
37501
|
+
* @param {Object<string, any>} env The environment variables of the hook.
|
|
37502
|
+
* @returns {void}
|
|
37503
|
+
* @global
|
|
37504
|
+
* @public
|
|
37505
|
+
*/
|
|
37506
|
+
|
|
38094
37507
|
;// CONCATENATED MODULE: ./node_modules/refractor/lib/core.js
|
|
38095
37508
|
/**
|
|
38096
37509
|
* @typedef _Token A hidden Prism token
|
|
@@ -38126,53 +37539,18 @@ var prism_core = __webpack_require__(975);
|
|
|
38126
37539
|
* @property {Languages} languages
|
|
38127
37540
|
*/
|
|
38128
37541
|
|
|
38129
|
-
/* eslint-disable no-undef */
|
|
38130
|
-
// Don’t allow Prism to run on page load in browser or to start messaging from
|
|
38131
|
-
// workers.
|
|
38132
|
-
/* c8 ignore next 15 */
|
|
38133
|
-
/** @type {typeof globalThis} */
|
|
38134
|
-
const ctx =
|
|
38135
|
-
typeof globalThis === 'object'
|
|
38136
|
-
? globalThis
|
|
38137
|
-
: // @ts-expect-error
|
|
38138
|
-
typeof self === 'object'
|
|
38139
|
-
? // @ts-expect-error
|
|
38140
|
-
self
|
|
38141
|
-
: // @ts-expect-error
|
|
38142
|
-
typeof window === 'object'
|
|
38143
|
-
? // @ts-expect-error
|
|
38144
|
-
window
|
|
38145
|
-
: typeof global === 'object'
|
|
38146
|
-
? global
|
|
38147
|
-
: {}
|
|
38148
|
-
/* eslint-enable no-undef */
|
|
38149
|
-
|
|
38150
|
-
const restore = capture()
|
|
38151
|
-
|
|
38152
|
-
/* c8 ignore next 5 */
|
|
38153
|
-
ctx.Prism = ctx.Prism || {}
|
|
38154
|
-
ctx.Prism.manual = true
|
|
38155
|
-
ctx.Prism.disableWorkerMessageHandler = true
|
|
38156
|
-
|
|
38157
|
-
/* eslint-disable import/first */
|
|
38158
|
-
|
|
38159
37542
|
// Load all stuff in `prism.js` itself, except for `prism-file-highlight.js`.
|
|
38160
37543
|
// The wrapped non-leaky grammars are loaded instead of Prism’s originals.
|
|
38161
|
-
;
|
|
38162
|
-
|
|
38163
|
-
// @ts-expect-error: untyped.
|
|
38164
37544
|
|
|
38165
37545
|
|
|
38166
|
-
/* eslint-enable import/first */
|
|
38167
37546
|
|
|
38168
|
-
restore()
|
|
38169
37547
|
|
|
38170
37548
|
const lib_core_own = {}.hasOwnProperty
|
|
38171
37549
|
|
|
38172
37550
|
// Inherit.
|
|
38173
37551
|
function Refractor() {}
|
|
38174
37552
|
|
|
38175
|
-
Refractor.prototype =
|
|
37553
|
+
Refractor.prototype = Prism
|
|
38176
37554
|
|
|
38177
37555
|
/** @type {Refractor} */
|
|
38178
37556
|
// @ts-expect-error: TS is wrong.
|
|
@@ -38231,7 +37609,8 @@ function highlight(value, language) {
|
|
|
38231
37609
|
|
|
38232
37610
|
return {
|
|
38233
37611
|
type: 'root',
|
|
38234
|
-
|
|
37612
|
+
// @ts-expect-error: we hacked Prism to accept and return the things we want.
|
|
37613
|
+
children: Prism.highlight.call(refractor, value, grammar, name)
|
|
38235
37614
|
}
|
|
38236
37615
|
}
|
|
38237
37616
|
|
|
@@ -38412,36 +37791,6 @@ function core_attributes(attrs) {
|
|
|
38412
37791
|
return attrs
|
|
38413
37792
|
}
|
|
38414
37793
|
|
|
38415
|
-
/**
|
|
38416
|
-
* @returns {() => void}
|
|
38417
|
-
*/
|
|
38418
|
-
function capture() {
|
|
38419
|
-
/** @type {boolean|undefined} */
|
|
38420
|
-
let defined = 'Prism' in ctx
|
|
38421
|
-
/* c8 ignore next */
|
|
38422
|
-
let current = defined ? ctx.Prism : undefined
|
|
38423
|
-
|
|
38424
|
-
return restore
|
|
38425
|
-
|
|
38426
|
-
/**
|
|
38427
|
-
* @returns {void}
|
|
38428
|
-
*/
|
|
38429
|
-
function restore() {
|
|
38430
|
-
/* istanbul ignore else - Clean leaks after Prism. */
|
|
38431
|
-
if (defined) {
|
|
38432
|
-
// @ts-expect-error: hush.
|
|
38433
|
-
ctx.Prism = current
|
|
38434
|
-
/* c8 ignore next 4 */
|
|
38435
|
-
} else {
|
|
38436
|
-
// @ts-expect-error: hush.
|
|
38437
|
-
delete ctx.Prism
|
|
38438
|
-
}
|
|
38439
|
-
|
|
38440
|
-
defined = undefined
|
|
38441
|
-
current = undefined
|
|
38442
|
-
}
|
|
38443
|
-
}
|
|
38444
|
-
|
|
38445
37794
|
;// CONCATENATED MODULE: ./node_modules/refractor/lib/common.js
|
|
38446
37795
|
/**
|
|
38447
37796
|
* @typedef {import('./core.js').RefractorRoot} RefractorRoot
|
|
@@ -58440,7 +57789,7 @@ const util_element = convertElement()
|
|
|
58440
57789
|
* @typedef {import('./types.js').HastNode} HastNode
|
|
58441
57790
|
* @typedef {import('./types.js').ElementChild} ElementChild
|
|
58442
57791
|
* @typedef {import('./types.js').Direction} Direction
|
|
58443
|
-
* @typedef {import('unist-util-visit').Visitor<ElementChild>} Visitor
|
|
57792
|
+
* @typedef {import('unist-util-visit/complex-types').Visitor<ElementChild>} Visitor
|
|
58444
57793
|
*/
|
|
58445
57794
|
|
|
58446
57795
|
|
|
@@ -58716,9 +58065,9 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
|
|
|
58716
58065
|
const children = parent.children
|
|
58717
58066
|
let elements = 0
|
|
58718
58067
|
let index = -1
|
|
58719
|
-
/** @type {
|
|
58068
|
+
/** @type {Record<string, number>} */
|
|
58720
58069
|
const types = {}
|
|
58721
|
-
/** @type {Array
|
|
58070
|
+
/** @type {Array<Function>} */
|
|
58722
58071
|
const delayed = []
|
|
58723
58072
|
|
|
58724
58073
|
// Start looking at `from`
|
|
@@ -59051,7 +58400,7 @@ const pseudo_handle = zwitch('name', {
|
|
|
59051
58400
|
// @ts-expect-error: hush.
|
|
59052
58401
|
has,
|
|
59053
58402
|
// @ts-expect-error: hush.
|
|
59054
|
-
lang,
|
|
58403
|
+
lang: pseudo_lang,
|
|
59055
58404
|
// @ts-expect-error: hush.
|
|
59056
58405
|
'last-child': lastChild,
|
|
59057
58406
|
// @ts-expect-error: hush.
|
|
@@ -59365,7 +58714,7 @@ function firstChild(query, _1, _2, _3, state) {
|
|
|
59365
58714
|
* @param {SelectState} state
|
|
59366
58715
|
* @returns {boolean}
|
|
59367
58716
|
*/
|
|
59368
|
-
function
|
|
58717
|
+
function pseudo_lang(query, _1, _2, _3, state) {
|
|
59369
58718
|
return (
|
|
59370
58719
|
state.language !== '' &&
|
|
59371
58720
|
state.language !== undefined &&
|
|
@@ -59840,7 +59189,7 @@ function normalizeValue(value, info) {
|
|
|
59840
59189
|
* @returns {boolean}
|
|
59841
59190
|
*/
|
|
59842
59191
|
function className(query, element) {
|
|
59843
|
-
/** @type {Array
|
|
59192
|
+
/** @type {Array<string>} */
|
|
59844
59193
|
// @ts-expect-error Assume array.
|
|
59845
59194
|
const value = element.properties.className || []
|
|
59846
59195
|
let index = -1
|
|
@@ -59951,7 +59300,7 @@ const type = zwitch('type', {
|
|
|
59951
59300
|
* @param {Selectors|RuleSet|Rule} query
|
|
59952
59301
|
* @param {HastNode|undefined} node
|
|
59953
59302
|
* @param {SelectState} state
|
|
59954
|
-
* @returns {Array
|
|
59303
|
+
* @returns {Array<Element>}
|
|
59955
59304
|
*/
|
|
59956
59305
|
function any_any(query, node, state) {
|
|
59957
59306
|
// @ts-expect-error zwitch types are off.
|
|
@@ -59962,7 +59311,7 @@ function any_any(query, node, state) {
|
|
|
59962
59311
|
* @param {Selectors} query
|
|
59963
59312
|
* @param {HastNode} node
|
|
59964
59313
|
* @param {SelectState} state
|
|
59965
|
-
* @returns {Array
|
|
59314
|
+
* @returns {Array<Element>}
|
|
59966
59315
|
*/
|
|
59967
59316
|
function selectors(query, node, state) {
|
|
59968
59317
|
const collector = new Collector(state.one)
|
|
@@ -59979,7 +59328,7 @@ function selectors(query, node, state) {
|
|
|
59979
59328
|
* @param {RuleSet} query
|
|
59980
59329
|
* @param {HastNode} node
|
|
59981
59330
|
* @param {SelectState} state
|
|
59982
|
-
* @returns {Array
|
|
59331
|
+
* @returns {Array<Element>}
|
|
59983
59332
|
*/
|
|
59984
59333
|
function ruleSet(query, node, state) {
|
|
59985
59334
|
return rule(query.rule, node, state)
|
|
@@ -59989,7 +59338,7 @@ function ruleSet(query, node, state) {
|
|
|
59989
59338
|
* @param {Rule} query
|
|
59990
59339
|
* @param {HastNode} tree
|
|
59991
59340
|
* @param {SelectState} state
|
|
59992
|
-
* @returns {Array
|
|
59341
|
+
* @returns {Array<Element>}
|
|
59993
59342
|
*/
|
|
59994
59343
|
function rule(query, tree, state) {
|
|
59995
59344
|
const collector = new Collector(state.one)
|
|
@@ -60076,7 +59425,7 @@ class Collector {
|
|
|
60076
59425
|
* @param {boolean|undefined} [one]
|
|
60077
59426
|
*/
|
|
60078
59427
|
constructor(one) {
|
|
60079
|
-
/** @type {Array
|
|
59428
|
+
/** @type {Array<Element>} */
|
|
60080
59429
|
this.result = []
|
|
60081
59430
|
/** @type {boolean|undefined} */
|
|
60082
59431
|
this.one = one
|
|
@@ -60087,7 +59436,7 @@ class Collector {
|
|
|
60087
59436
|
/**
|
|
60088
59437
|
* Append nodes to array, filtering out duplicates.
|
|
60089
59438
|
*
|
|
60090
|
-
* @param {Array
|
|
59439
|
+
* @param {Array<Element>} elements
|
|
60091
59440
|
*/
|
|
60092
59441
|
collectAll(elements) {
|
|
60093
59442
|
let index = -1
|
|
@@ -60116,8 +59465,260 @@ class Collector {
|
|
|
60116
59465
|
|
|
60117
59466
|
// EXTERNAL MODULE: ./node_modules/css-selector-parser/lib/index.js
|
|
60118
59467
|
var css_selector_parser_lib = __webpack_require__(733);
|
|
60119
|
-
|
|
60120
|
-
|
|
59468
|
+
;// CONCATENATED MODULE: ./node_modules/nth-check/lib/esm/parse.js
|
|
59469
|
+
// Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
|
|
59470
|
+
// Whitespace as per https://www.w3.org/TR/selectors-3/#lex is " \t\r\n\f"
|
|
59471
|
+
const parse_whitespace = new Set([9, 10, 12, 13, 32]);
|
|
59472
|
+
const ZERO = "0".charCodeAt(0);
|
|
59473
|
+
const NINE = "9".charCodeAt(0);
|
|
59474
|
+
/**
|
|
59475
|
+
* Parses an expression.
|
|
59476
|
+
*
|
|
59477
|
+
* @throws An `Error` if parsing fails.
|
|
59478
|
+
* @returns An array containing the integer step size and the integer offset of the nth rule.
|
|
59479
|
+
* @example nthCheck.parse("2n+3"); // returns [2, 3]
|
|
59480
|
+
*/
|
|
59481
|
+
function esm_parse_parse(formula) {
|
|
59482
|
+
formula = formula.trim().toLowerCase();
|
|
59483
|
+
if (formula === "even") {
|
|
59484
|
+
return [2, 0];
|
|
59485
|
+
}
|
|
59486
|
+
else if (formula === "odd") {
|
|
59487
|
+
return [2, 1];
|
|
59488
|
+
}
|
|
59489
|
+
// Parse [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
|
|
59490
|
+
let idx = 0;
|
|
59491
|
+
let a = 0;
|
|
59492
|
+
let sign = readSign();
|
|
59493
|
+
let number = readNumber();
|
|
59494
|
+
if (idx < formula.length && formula.charAt(idx) === "n") {
|
|
59495
|
+
idx++;
|
|
59496
|
+
a = sign * (number !== null && number !== void 0 ? number : 1);
|
|
59497
|
+
skipWhitespace();
|
|
59498
|
+
if (idx < formula.length) {
|
|
59499
|
+
sign = readSign();
|
|
59500
|
+
skipWhitespace();
|
|
59501
|
+
number = readNumber();
|
|
59502
|
+
}
|
|
59503
|
+
else {
|
|
59504
|
+
sign = number = 0;
|
|
59505
|
+
}
|
|
59506
|
+
}
|
|
59507
|
+
// Throw if there is anything else
|
|
59508
|
+
if (number === null || idx < formula.length) {
|
|
59509
|
+
throw new Error(`n-th rule couldn't be parsed ('${formula}')`);
|
|
59510
|
+
}
|
|
59511
|
+
return [a, sign * number];
|
|
59512
|
+
function readSign() {
|
|
59513
|
+
if (formula.charAt(idx) === "-") {
|
|
59514
|
+
idx++;
|
|
59515
|
+
return -1;
|
|
59516
|
+
}
|
|
59517
|
+
if (formula.charAt(idx) === "+") {
|
|
59518
|
+
idx++;
|
|
59519
|
+
}
|
|
59520
|
+
return 1;
|
|
59521
|
+
}
|
|
59522
|
+
function readNumber() {
|
|
59523
|
+
const start = idx;
|
|
59524
|
+
let value = 0;
|
|
59525
|
+
while (idx < formula.length &&
|
|
59526
|
+
formula.charCodeAt(idx) >= ZERO &&
|
|
59527
|
+
formula.charCodeAt(idx) <= NINE) {
|
|
59528
|
+
value = value * 10 + (formula.charCodeAt(idx) - ZERO);
|
|
59529
|
+
idx++;
|
|
59530
|
+
}
|
|
59531
|
+
// Return `null` if we didn't read anything.
|
|
59532
|
+
return idx === start ? null : value;
|
|
59533
|
+
}
|
|
59534
|
+
function skipWhitespace() {
|
|
59535
|
+
while (idx < formula.length &&
|
|
59536
|
+
parse_whitespace.has(formula.charCodeAt(idx))) {
|
|
59537
|
+
idx++;
|
|
59538
|
+
}
|
|
59539
|
+
}
|
|
59540
|
+
}
|
|
59541
|
+
//# sourceMappingURL=parse.js.map
|
|
59542
|
+
// EXTERNAL MODULE: ./node_modules/boolbase/index.js
|
|
59543
|
+
var boolbase = __webpack_require__(407);
|
|
59544
|
+
;// CONCATENATED MODULE: ./node_modules/nth-check/lib/esm/compile.js
|
|
59545
|
+
|
|
59546
|
+
/**
|
|
59547
|
+
* Returns a function that checks if an elements index matches the given rule
|
|
59548
|
+
* highly optimized to return the fastest solution.
|
|
59549
|
+
*
|
|
59550
|
+
* @param parsed A tuple [a, b], as returned by `parse`.
|
|
59551
|
+
* @returns A highly optimized function that returns whether an index matches the nth-check.
|
|
59552
|
+
* @example
|
|
59553
|
+
*
|
|
59554
|
+
* ```js
|
|
59555
|
+
* const check = nthCheck.compile([2, 3]);
|
|
59556
|
+
*
|
|
59557
|
+
* check(0); // `false`
|
|
59558
|
+
* check(1); // `false`
|
|
59559
|
+
* check(2); // `true`
|
|
59560
|
+
* check(3); // `false`
|
|
59561
|
+
* check(4); // `true`
|
|
59562
|
+
* check(5); // `false`
|
|
59563
|
+
* check(6); // `true`
|
|
59564
|
+
* ```
|
|
59565
|
+
*/
|
|
59566
|
+
function compile(parsed) {
|
|
59567
|
+
const a = parsed[0];
|
|
59568
|
+
// Subtract 1 from `b`, to convert from one- to zero-indexed.
|
|
59569
|
+
const b = parsed[1] - 1;
|
|
59570
|
+
/*
|
|
59571
|
+
* When `b <= 0`, `a * n` won't be lead to any matches for `a < 0`.
|
|
59572
|
+
* Besides, the specification states that no elements are
|
|
59573
|
+
* matched when `a` and `b` are 0.
|
|
59574
|
+
*
|
|
59575
|
+
* `b < 0` here as we subtracted 1 from `b` above.
|
|
59576
|
+
*/
|
|
59577
|
+
if (b < 0 && a <= 0)
|
|
59578
|
+
return boolbase.falseFunc;
|
|
59579
|
+
// When `a` is in the range -1..1, it matches any element (so only `b` is checked).
|
|
59580
|
+
if (a === -1)
|
|
59581
|
+
return (index) => index <= b;
|
|
59582
|
+
if (a === 0)
|
|
59583
|
+
return (index) => index === b;
|
|
59584
|
+
// When `b <= 0` and `a === 1`, they match any element.
|
|
59585
|
+
if (a === 1)
|
|
59586
|
+
return b < 0 ? boolbase.trueFunc : (index) => index >= b;
|
|
59587
|
+
/*
|
|
59588
|
+
* Otherwise, modulo can be used to check if there is a match.
|
|
59589
|
+
*
|
|
59590
|
+
* Modulo doesn't care about the sign, so let's use `a`s absolute value.
|
|
59591
|
+
*/
|
|
59592
|
+
const absA = Math.abs(a);
|
|
59593
|
+
// Get `b mod a`, + a if this is negative.
|
|
59594
|
+
const bMod = ((b % absA) + absA) % absA;
|
|
59595
|
+
return a > 1
|
|
59596
|
+
? (index) => index >= b && index % absA === bMod
|
|
59597
|
+
: (index) => index <= b && index % absA === bMod;
|
|
59598
|
+
}
|
|
59599
|
+
/**
|
|
59600
|
+
* Returns a function that produces a monotonously increasing sequence of indices.
|
|
59601
|
+
*
|
|
59602
|
+
* If the sequence has an end, the returned function will return `null` after
|
|
59603
|
+
* the last index in the sequence.
|
|
59604
|
+
*
|
|
59605
|
+
* @param parsed A tuple [a, b], as returned by `parse`.
|
|
59606
|
+
* @returns A function that produces a sequence of indices.
|
|
59607
|
+
* @example <caption>Always increasing (2n+3)</caption>
|
|
59608
|
+
*
|
|
59609
|
+
* ```js
|
|
59610
|
+
* const gen = nthCheck.generate([2, 3])
|
|
59611
|
+
*
|
|
59612
|
+
* gen() // `1`
|
|
59613
|
+
* gen() // `3`
|
|
59614
|
+
* gen() // `5`
|
|
59615
|
+
* gen() // `8`
|
|
59616
|
+
* gen() // `11`
|
|
59617
|
+
* ```
|
|
59618
|
+
*
|
|
59619
|
+
* @example <caption>With end value (-2n+10)</caption>
|
|
59620
|
+
*
|
|
59621
|
+
* ```js
|
|
59622
|
+
*
|
|
59623
|
+
* const gen = nthCheck.generate([-2, 5]);
|
|
59624
|
+
*
|
|
59625
|
+
* gen() // 0
|
|
59626
|
+
* gen() // 2
|
|
59627
|
+
* gen() // 4
|
|
59628
|
+
* gen() // null
|
|
59629
|
+
* ```
|
|
59630
|
+
*/
|
|
59631
|
+
function compile_generate(parsed) {
|
|
59632
|
+
const a = parsed[0];
|
|
59633
|
+
// Subtract 1 from `b`, to convert from one- to zero-indexed.
|
|
59634
|
+
let b = parsed[1] - 1;
|
|
59635
|
+
let n = 0;
|
|
59636
|
+
// Make sure to always return an increasing sequence
|
|
59637
|
+
if (a < 0) {
|
|
59638
|
+
const aPos = -a;
|
|
59639
|
+
// Get `b mod a`
|
|
59640
|
+
const minValue = ((b % aPos) + aPos) % aPos;
|
|
59641
|
+
return () => {
|
|
59642
|
+
const val = minValue + aPos * n++;
|
|
59643
|
+
return val > b ? null : val;
|
|
59644
|
+
};
|
|
59645
|
+
}
|
|
59646
|
+
if (a === 0)
|
|
59647
|
+
return b < 0
|
|
59648
|
+
? // There are no result — always return `null`
|
|
59649
|
+
() => null
|
|
59650
|
+
: // Return `b` exactly once
|
|
59651
|
+
() => (n++ === 0 ? b : null);
|
|
59652
|
+
if (b < 0) {
|
|
59653
|
+
b += a * Math.ceil(-b / a);
|
|
59654
|
+
}
|
|
59655
|
+
return () => a * n++ + b;
|
|
59656
|
+
}
|
|
59657
|
+
//# sourceMappingURL=compile.js.map
|
|
59658
|
+
;// CONCATENATED MODULE: ./node_modules/nth-check/lib/esm/index.js
|
|
59659
|
+
|
|
59660
|
+
|
|
59661
|
+
|
|
59662
|
+
/**
|
|
59663
|
+
* Parses and compiles a formula to a highly optimized function.
|
|
59664
|
+
* Combination of {@link parse} and {@link compile}.
|
|
59665
|
+
*
|
|
59666
|
+
* If the formula doesn't match any elements,
|
|
59667
|
+
* it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
|
|
59668
|
+
* Otherwise, a function accepting an _index_ is returned, which returns
|
|
59669
|
+
* whether or not the passed _index_ matches the formula.
|
|
59670
|
+
*
|
|
59671
|
+
* Note: The nth-rule starts counting at `1`, the returned function at `0`.
|
|
59672
|
+
*
|
|
59673
|
+
* @param formula The formula to compile.
|
|
59674
|
+
* @example
|
|
59675
|
+
* const check = nthCheck("2n+3");
|
|
59676
|
+
*
|
|
59677
|
+
* check(0); // `false`
|
|
59678
|
+
* check(1); // `false`
|
|
59679
|
+
* check(2); // `true`
|
|
59680
|
+
* check(3); // `false`
|
|
59681
|
+
* check(4); // `true`
|
|
59682
|
+
* check(5); // `false`
|
|
59683
|
+
* check(6); // `true`
|
|
59684
|
+
*/
|
|
59685
|
+
function nthCheck(formula) {
|
|
59686
|
+
return compile(esm_parse_parse(formula));
|
|
59687
|
+
}
|
|
59688
|
+
/**
|
|
59689
|
+
* Parses and compiles a formula to a generator that produces a sequence of indices.
|
|
59690
|
+
* Combination of {@link parse} and {@link generate}.
|
|
59691
|
+
*
|
|
59692
|
+
* @param formula The formula to compile.
|
|
59693
|
+
* @returns A function that produces a sequence of indices.
|
|
59694
|
+
* @example <caption>Always increasing</caption>
|
|
59695
|
+
*
|
|
59696
|
+
* ```js
|
|
59697
|
+
* const gen = nthCheck.sequence('2n+3')
|
|
59698
|
+
*
|
|
59699
|
+
* gen() // `1`
|
|
59700
|
+
* gen() // `3`
|
|
59701
|
+
* gen() // `5`
|
|
59702
|
+
* gen() // `8`
|
|
59703
|
+
* gen() // `11`
|
|
59704
|
+
* ```
|
|
59705
|
+
*
|
|
59706
|
+
* @example <caption>With end value</caption>
|
|
59707
|
+
*
|
|
59708
|
+
* ```js
|
|
59709
|
+
*
|
|
59710
|
+
* const gen = nthCheck.sequence('-2n+5');
|
|
59711
|
+
*
|
|
59712
|
+
* gen() // 0
|
|
59713
|
+
* gen() // 2
|
|
59714
|
+
* gen() // 4
|
|
59715
|
+
* gen() // null
|
|
59716
|
+
* ```
|
|
59717
|
+
*/
|
|
59718
|
+
function sequence(formula) {
|
|
59719
|
+
return generate(parse(formula));
|
|
59720
|
+
}
|
|
59721
|
+
//# sourceMappingURL=index.js.map
|
|
60121
59722
|
;// CONCATENATED MODULE: ./node_modules/hast-util-select/lib/parse.js
|
|
60122
59723
|
/**
|
|
60123
59724
|
* @typedef {import('./types.js').Selector} Selector
|
|
@@ -60134,7 +59735,7 @@ var nth_check_lib = __webpack_require__(483);
|
|
|
60134
59735
|
|
|
60135
59736
|
/** @type {import('nth-check').default} */
|
|
60136
59737
|
// @ts-expect-error
|
|
60137
|
-
const
|
|
59738
|
+
const parse_nthCheck = nthCheck["default"] || nthCheck
|
|
60138
59739
|
|
|
60139
59740
|
const nth = new Set([
|
|
60140
59741
|
'nth-child',
|
|
@@ -60146,7 +59747,7 @@ const nth = new Set([
|
|
|
60146
59747
|
const parse_parser = new css_selector_parser_lib/* CssSelectorParser */.N()
|
|
60147
59748
|
|
|
60148
59749
|
// @ts-expect-error: hush.
|
|
60149
|
-
const
|
|
59750
|
+
const parse_compile = zwitch('type', {handlers: {selectors: parse_selectors, ruleSet: parse_ruleSet, rule: parse_rule}})
|
|
60150
59751
|
|
|
60151
59752
|
parse_parser.registerAttrEqualityMods('~', '|', '^', '$', '*')
|
|
60152
59753
|
parse_parser.registerSelectorPseudos('any', 'matches', 'not', 'has')
|
|
@@ -60162,7 +59763,7 @@ function lib_parse_parse(selector) {
|
|
|
60162
59763
|
}
|
|
60163
59764
|
|
|
60164
59765
|
// @ts-expect-error types are wrong.
|
|
60165
|
-
return
|
|
59766
|
+
return parse_compile(parse_parser.parse(selector))
|
|
60166
59767
|
}
|
|
60167
59768
|
|
|
60168
59769
|
/**
|
|
@@ -60173,7 +59774,7 @@ function parse_selectors(query) {
|
|
|
60173
59774
|
let index = -1
|
|
60174
59775
|
|
|
60175
59776
|
while (++index < query.selectors.length) {
|
|
60176
|
-
|
|
59777
|
+
parse_compile(query.selectors[index])
|
|
60177
59778
|
}
|
|
60178
59779
|
|
|
60179
59780
|
return query
|
|
@@ -60200,13 +59801,13 @@ function parse_rule(query) {
|
|
|
60200
59801
|
|
|
60201
59802
|
if (nth.has(pseudo.name)) {
|
|
60202
59803
|
// @ts-expect-error Patch a non-primitive type.
|
|
60203
|
-
pseudo.value =
|
|
59804
|
+
pseudo.value = parse_nthCheck(pseudo.value)
|
|
60204
59805
|
// @ts-expect-error Patch a non-primitive type.
|
|
60205
59806
|
pseudo.valueType = 'function'
|
|
60206
59807
|
}
|
|
60207
59808
|
}
|
|
60208
59809
|
|
|
60209
|
-
|
|
59810
|
+
parse_compile(query.rule)
|
|
60210
59811
|
|
|
60211
59812
|
return query
|
|
60212
59813
|
}
|
|
@@ -60247,7 +59848,7 @@ function hast_util_select_select(selector, node, space) {
|
|
|
60247
59848
|
* @param {string} selector
|
|
60248
59849
|
* @param {HastNode} [node]
|
|
60249
59850
|
* @param {Space} [space]
|
|
60250
|
-
* @returns {Array
|
|
59851
|
+
* @returns {Array<Element>}
|
|
60251
59852
|
*/
|
|
60252
59853
|
function selectAll(selector, node, space) {
|
|
60253
59854
|
return any_any(lib_parse_parse(selector), node, {space})
|
|
@@ -60418,8 +60019,7 @@ var jsx_runtime = __webpack_require__(724);
|
|
|
60418
60019
|
;// CONCATENATED MODULE: ./node_modules/@uiw/react-markdown-preview/esm/index.js
|
|
60419
60020
|
|
|
60420
60021
|
|
|
60421
|
-
var _excluded = ["prefixCls", "className", "source", "style", "onScroll", "onMouseOver", "pluginsFilter", "warpperElement"];
|
|
60422
|
-
|
|
60022
|
+
var _excluded = ["prefixCls", "className", "source", "style", "disableCopy", "onScroll", "onMouseOver", "pluginsFilter", "warpperElement"];
|
|
60423
60023
|
|
|
60424
60024
|
|
|
60425
60025
|
|
|
@@ -60434,30 +60034,13 @@ var _excluded = ["prefixCls", "className", "source", "style", "onScroll", "onMou
|
|
|
60434
60034
|
|
|
60435
60035
|
|
|
60436
60036
|
|
|
60437
|
-
var rehypeRewriteHandle = (node, index, parent) => {
|
|
60438
|
-
if (node.type === 'element' && parent && parent.type === 'root' && /h(1|2|3|4|5|6)/.test(node.tagName)) {
|
|
60439
|
-
var child = node.children && node.children[0];
|
|
60440
|
-
|
|
60441
|
-
if (child && child.properties && child.properties.ariaHidden === 'true') {
|
|
60442
|
-
child.properties = _extends({
|
|
60443
|
-
class: 'anchor'
|
|
60444
|
-
}, child.properties);
|
|
60445
|
-
child.children = [octiconLink];
|
|
60446
|
-
}
|
|
60447
|
-
}
|
|
60448
|
-
|
|
60449
|
-
if (node.type === 'element' && node.tagName === 'pre') {
|
|
60450
|
-
var code = getCodeString(node.children);
|
|
60451
|
-
node.children.push(copyElement(code));
|
|
60452
|
-
}
|
|
60453
|
-
};
|
|
60454
|
-
|
|
60455
60037
|
/* harmony default export */ const esm = (/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().forwardRef((props, ref) => {
|
|
60456
60038
|
var {
|
|
60457
60039
|
prefixCls = 'wmde-markdown wmde-markdown-color',
|
|
60458
60040
|
className,
|
|
60459
60041
|
source,
|
|
60460
60042
|
style,
|
|
60043
|
+
disableCopy = false,
|
|
60461
60044
|
onScroll,
|
|
60462
60045
|
onMouseOver,
|
|
60463
60046
|
pluginsFilter,
|
|
@@ -60470,6 +60053,25 @@ var rehypeRewriteHandle = (node, index, parent) => {
|
|
|
60470
60053
|
mdp
|
|
60471
60054
|
}), [mdp, props]);
|
|
60472
60055
|
var cls = (prefixCls || '') + " " + (className || '');
|
|
60056
|
+
|
|
60057
|
+
var rehypeRewriteHandle = (node, index, parent) => {
|
|
60058
|
+
if (node.type === 'element' && parent && parent.type === 'root' && /h(1|2|3|4|5|6)/.test(node.tagName)) {
|
|
60059
|
+
var child = node.children && node.children[0];
|
|
60060
|
+
|
|
60061
|
+
if (child && child.properties && child.properties.ariaHidden === 'true') {
|
|
60062
|
+
child.properties = _extends({
|
|
60063
|
+
class: 'anchor'
|
|
60064
|
+
}, child.properties);
|
|
60065
|
+
child.children = [octiconLink];
|
|
60066
|
+
}
|
|
60067
|
+
}
|
|
60068
|
+
|
|
60069
|
+
if (node.type === 'element' && node.tagName === 'pre' && !disableCopy) {
|
|
60070
|
+
var code = getCodeString(node.children);
|
|
60071
|
+
node.children.push(copyElement(code));
|
|
60072
|
+
}
|
|
60073
|
+
};
|
|
60074
|
+
|
|
60473
60075
|
var rehypePlugins = [reservedMeta, [m, {
|
|
60474
60076
|
ignoreMissing: true
|
|
60475
60077
|
}], rehypeRaw, rehypeSlug, rehypeAutolinkHeadings, [rehype_rewrite_lib, {
|
|
@@ -62653,7 +62255,7 @@ function Child_Child(props){var _ref=props||{},prefixCls=_ref.prefixCls,groupNam
|
|
|
62653
62255
|
function ToolbarItems(props){var prefixCls=props.prefixCls,overflow=props.overflow;var _useContext=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),fullscreen=_useContext.fullscreen,preview=_useContext.preview,_useContext$barPopup=_useContext.barPopup,barPopup=_useContext$barPopup===void 0?{}:_useContext$barPopup,commandOrchestrator=_useContext.commandOrchestrator,dispatch=_useContext.dispatch;var originalOverflow=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('');function handleClick(command,name){if(!dispatch)return;var state={barPopup:_objectSpread2({},barPopup)};if(command.keyCommand==='preview'){state.preview=command.value;}if(command.keyCommand==='fullscreen'){state.fullscreen=!fullscreen;}if(props.commands&&command.keyCommand==='group'){props.commands.forEach(function(item){if(name===item.groupName){state.barPopup[name]=true;}else if(item.keyCommand){state.barPopup[item.groupName]=false;}});}else if(name||command.parent){Object.keys(state.barPopup||{}).forEach(function(keyName){state.barPopup[keyName]=false;});}if(Object.keys(state).length){dispatch(_objectSpread2({},state));}commandOrchestrator&&commandOrchestrator.executeCommand(command);}(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){if(document&&overflow){if(fullscreen){// prevent scroll on fullscreen
|
|
62654
62256
|
document.body.style.overflow='hidden';}else{// get the original overflow only the first time
|
|
62655
62257
|
if(!originalOverflow.current){originalOverflow.current=window.getComputedStyle(document.body,null).overflow;}// reset to the original overflow
|
|
62656
|
-
document.body.style.overflow=originalOverflow.current;}}},[fullscreen,originalOverflow,overflow]);return/*#__PURE__*/(0,jsx_runtime.jsx)("ul",{children:(props.commands||[]).map(function(item,idx){if(item.keyCommand==='divider'){return/*#__PURE__*/(0,jsx_runtime.jsx)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:"".concat(prefixCls,"-toolbar-divider")}),idx);}if(!item.keyCommand)return/*#__PURE__*/(0,jsx_runtime.jsx)(external_root_React_commonjs2_react_commonjs_react_amd_react_.Fragment,{},idx);var activeBtn=fullscreen&&item.keyCommand==='fullscreen'||item.keyCommand==='preview'&&preview===item.value;var childNode=item.children&&typeof item.children==='function'?item.children({getState:function getState(){return commandOrchestrator.getState();},textApi:commandOrchestrator?commandOrchestrator.textApi:undefined,close:function close(){return handleClick({},item.groupName);},execute:function execute(){return handleClick({execute:item.execute});}}):undefined;var disabled=barPopup&&preview&&preview==='preview'&&!/(preview|fullscreen)/.test(item.keyCommand);return/*#__PURE__*/(0,jsx_runtime.jsxs)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:activeBtn?"active":'',children:[!item.buttonProps&&item.icon,item.buttonProps&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement('button',_objectSpread2(_objectSpread2({type:'button',key:idx,disabled:disabled,'data-name':item.name},item.buttonProps),{},{onClick:function onClick(evn){evn.stopPropagation();handleClick(item,item.groupName);}}),item.icon),item.children&&/*#__PURE__*/(0,jsx_runtime.jsx)(Child_Child,{overflow:overflow,groupName:item.groupName,prefixCls:prefixCls,children:childNode,commands:Array.isArray(item.children)?item.children:undefined})]}),idx);})});}function Toolbar_Toolbar(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var prefixCls=props.prefixCls,_props$height=props.height,height=_props$height===void 0?29:_props$height,isChild=props.isChild;var _useContext2=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),commands=_useContext2.commands,extraCommands=_useContext2.extraCommands;return/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-toolbar"),style:{height:height},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:props.commands||commands||[]})),!isChild&&/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:extraCommands||[]}))]});}
|
|
62258
|
+
document.body.style.overflow=originalOverflow.current;}}},[fullscreen,originalOverflow,overflow]);return/*#__PURE__*/(0,jsx_runtime.jsx)("ul",{children:(props.commands||[]).map(function(item,idx){if(item.keyCommand==='divider'){return/*#__PURE__*/(0,jsx_runtime.jsx)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:"".concat(prefixCls,"-toolbar-divider")}),idx);}if(!item.keyCommand)return/*#__PURE__*/(0,jsx_runtime.jsx)(external_root_React_commonjs2_react_commonjs_react_amd_react_.Fragment,{},idx);var activeBtn=fullscreen&&item.keyCommand==='fullscreen'||item.keyCommand==='preview'&&preview===item.value;var childNode=item.children&&typeof item.children==='function'?item.children({getState:function getState(){return commandOrchestrator.getState();},textApi:commandOrchestrator?commandOrchestrator.textApi:undefined,close:function close(){return handleClick({},item.groupName);},execute:function execute(){return handleClick({execute:item.execute});}}):undefined;var disabled=barPopup&&preview&&preview==='preview'&&!/(preview|fullscreen)/.test(item.keyCommand);return/*#__PURE__*/(0,jsx_runtime.jsxs)("li",_objectSpread2(_objectSpread2({},item.liProps),{},{className:activeBtn?"active":'',children:[!item.buttonProps&&item.icon,item.buttonProps&&/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().createElement('button',_objectSpread2(_objectSpread2({type:'button',key:idx,disabled:disabled,'data-name':item.name},item.buttonProps),{},{onClick:function onClick(evn){evn.stopPropagation();handleClick(item,item.groupName);}}),item.icon),item.children&&/*#__PURE__*/(0,jsx_runtime.jsx)(Child_Child,{overflow:overflow,groupName:item.groupName,prefixCls:prefixCls,children:childNode,commands:Array.isArray(item.children)?item.children:undefined})]}),idx);})});}function Toolbar_Toolbar(){var props=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var prefixCls=props.prefixCls,_props$height=props.height,height=_props$height===void 0?29:_props$height,toolbarBottom=props.toolbarBottom,isChild=props.isChild;var _useContext2=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useContext)(EditorContext),commands=_useContext2.commands,extraCommands=_useContext2.extraCommands;var bottomClassName=toolbarBottom?'bottom':'';return/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-toolbar ").concat(bottomClassName),style:{height:height},children:[/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:props.commands||commands||[]})),!isChild&&/*#__PURE__*/(0,jsx_runtime.jsx)(ToolbarItems,_objectSpread2(_objectSpread2({},props),{},{commands:extraCommands||[]}))]});}
|
|
62657
62259
|
;// CONCATENATED MODULE: ./src/components/DragBar/index.less
|
|
62658
62260
|
// extracted by mini-css-extract-plugin
|
|
62659
62261
|
/* harmony default export */ const DragBar = ({});
|
|
@@ -62664,14 +62266,14 @@ var DragBar_DragBar=function DragBar(props){var _ref=props||{},prefixCls=_ref.pr
|
|
|
62664
62266
|
// extracted by mini-css-extract-plugin
|
|
62665
62267
|
/* harmony default export */ const src = ({});
|
|
62666
62268
|
;// CONCATENATED MODULE: ./src/Editor.tsx
|
|
62667
|
-
var Editor_excluded=["prefixCls","className","value","commands","commandsFilter","extraCommands","height","toolbarHeight","enableScroll","
|
|
62269
|
+
var Editor_excluded=["prefixCls","className","value","commands","commandsFilter","extraCommands","height","toolbarHeight","enableScroll","visibleDragbar","highlightEnable","preview","fullscreen","overflow","previewOptions","textareaProps","maxHeight","minHeight","autoFocus","tabSize","defaultTabEnable","onChange","onHeightChange","hideToolbar","toolbarBottom","renderTextarea"];function setGroupPopFalse(){var data=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};Object.keys(data).forEach(function(keyname){data[keyname]=false;});return data;}var InternalMDEditor=function InternalMDEditor(props,ref){var _ref=props||{},_ref$prefixCls=_ref.prefixCls,prefixCls=_ref$prefixCls===void 0?'w-md-editor':_ref$prefixCls,className=_ref.className,propsValue=_ref.value,_ref$commands=_ref.commands,commands=_ref$commands===void 0?commands_getCommands():_ref$commands,commandsFilter=_ref.commandsFilter,_ref$extraCommands=_ref.extraCommands,extraCommands=_ref$extraCommands===void 0?getExtraCommands():_ref$extraCommands,_ref$height=_ref.height,height=_ref$height===void 0?200:_ref$height,_ref$toolbarHeight=_ref.toolbarHeight,toolbarHeight=_ref$toolbarHeight===void 0?29:_ref$toolbarHeight,_ref$enableScroll=_ref.enableScroll,enableScroll=_ref$enableScroll===void 0?true:_ref$enableScroll,_ref$visibleDragbar=_ref.visibleDragbar,visibleDragbar=_ref$visibleDragbar===void 0?true:_ref$visibleDragbar,_ref$highlightEnable=_ref.highlightEnable,highlightEnable=_ref$highlightEnable===void 0?true:_ref$highlightEnable,_ref$preview=_ref.preview,previewType=_ref$preview===void 0?'live':_ref$preview,_ref$fullscreen=_ref.fullscreen,fullscreen=_ref$fullscreen===void 0?false:_ref$fullscreen,_ref$overflow=_ref.overflow,overflow=_ref$overflow===void 0?true:_ref$overflow,_ref$previewOptions=_ref.previewOptions,previewOptions=_ref$previewOptions===void 0?{}:_ref$previewOptions,textareaProps=_ref.textareaProps,_ref$maxHeight=_ref.maxHeight,maxHeight=_ref$maxHeight===void 0?1200:_ref$maxHeight,_ref$minHeight=_ref.minHeight,minHeight=_ref$minHeight===void 0?100:_ref$minHeight,autoFocus=_ref.autoFocus,_ref$tabSize=_ref.tabSize,tabSize=_ref$tabSize===void 0?2:_ref$tabSize,_ref$defaultTabEnable=_ref.defaultTabEnable,defaultTabEnable=_ref$defaultTabEnable===void 0?false:_ref$defaultTabEnable,_onChange=_ref.onChange,onHeightChange=_ref.onHeightChange,hideToolbar=_ref.hideToolbar,_ref$toolbarBottom=_ref.toolbarBottom,toolbarBottom=_ref$toolbarBottom===void 0?false:_ref$toolbarBottom,renderTextarea=_ref.renderTextarea,other=_objectWithoutProperties(_ref,Editor_excluded);var cmds=commands.map(function(item){return commandsFilter?commandsFilter(item,false):item;}).filter(Boolean);var extraCmds=extraCommands.map(function(item){return commandsFilter?commandsFilter(item,true):item;}).filter(Boolean);var _useReducer=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useReducer)(reducer,{markdown:propsValue,preview:previewType,height:height,highlightEnable:highlightEnable,tabSize:tabSize,defaultTabEnable:defaultTabEnable,scrollTop:0,scrollTopPreview:0,commands:cmds,extraCommands:extraCmds,fullscreen:fullscreen,barPopup:{}}),_useReducer2=_slicedToArray(_useReducer,2),state=_useReducer2[0],dispatch=_useReducer2[1];var container=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var previewRef=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);var enableScrollRef=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(enableScroll);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useImperativeHandle)(ref,function(){return _objectSpread2({},state);});(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return enableScrollRef.current=enableScroll;},[enableScroll]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function(){var stateInit={};if(container.current){stateInit.container=container.current||undefined;}stateInit.markdown=propsValue||'';stateInit.barPopup={};if(dispatch){dispatch(_objectSpread2(_objectSpread2({},state),stateInit));}// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62668
62270
|
},[]);var cls=[className,'wmde-markdown-var',prefixCls,state.preview?"".concat(prefixCls,"-show-").concat(state.preview):null,state.fullscreen?"".concat(prefixCls,"-fullscreen"):null].filter(Boolean).join(' ').trim();(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return propsValue!==state.markdown&&dispatch({markdown:propsValue||''});},[propsValue,state.markdown]);// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62669
62271
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return previewType!==state.preview&&dispatch({preview:previewType});},[previewType]);// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62670
62272
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return tabSize!==state.tabSize&&dispatch({tabSize:tabSize});},[tabSize]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return highlightEnable!==state.highlightEnable&&dispatch({highlightEnable:highlightEnable});},// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62671
62273
|
[highlightEnable]);// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62672
62274
|
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return autoFocus!==state.autoFocus&&dispatch({autoFocus:autoFocus});},[autoFocus]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return fullscreen!==state.fullscreen&&dispatch({fullscreen:fullscreen});},// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62673
62275
|
[fullscreen]);// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62674
|
-
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return height!==state.height&&dispatch({height:height});},[height]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return height!==state.height&&onHeightChange&&onHeightChange(state.height,height,state);},[height,onHeightChange,state]);var textareaDomRef=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)();var active=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('preview');var initScroll=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(false);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){textareaDomRef.current=state.textareaWarp;if(state.textareaWarp){state.textareaWarp.addEventListener('mouseover',function(){active.current='text';});state.textareaWarp.addEventListener('mouseleave',function(){active.current='preview';});}},[state.textareaWarp]);var handleScroll=function handleScroll(e,type){if(!enableScrollRef.current)return;var textareaDom=textareaDomRef.current;var previewDom=previewRef.current?previewRef.current.mdp.current:undefined;if(!initScroll.current){active.current=type;initScroll.current=true;}if(textareaDom&&previewDom){var scale=(textareaDom.scrollHeight-textareaDom.offsetHeight)/(previewDom.scrollHeight-previewDom.offsetHeight);if(e.target===textareaDom&&active.current==='text'){previewDom.scrollTop=textareaDom.scrollTop/scale;}if(e.target===previewDom&&active.current==='preview'){textareaDom.scrollTop=previewDom.scrollTop*scale;}var scrollTop=0;if(active.current==='text'){scrollTop=textareaDom.scrollTop||0;}else if(active.current==='preview'){scrollTop=previewDom.scrollTop||0;}dispatch({scrollTop:scrollTop});}};var mdPreview=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return/*#__PURE__*/(0,jsx_runtime.jsx)(esm,_objectSpread2(_objectSpread2({},previewOptions),{},{onScroll:function onScroll(e){return handleScroll(e,'preview');},ref:previewRef,source:state.markdown||'',className:"".concat(prefixCls,"-preview ").concat(previewOptions.className||'')}));},[prefixCls,previewOptions,state.markdown]);return/*#__PURE__*/(0,jsx_runtime.jsx)(EditorContext.Provider,{value:_objectSpread2(_objectSpread2({},state),{},{dispatch:dispatch}),children:/*#__PURE__*/(0,jsx_runtime.jsxs)("div",_objectSpread2(_objectSpread2({ref:container,className:cls},other),{},{onClick:function onClick(){dispatch({barPopup:_objectSpread2({},setGroupPopFalse(state.barPopup))});},style:_objectSpread2(_objectSpread2({},other.style),{},{height:state.fullscreen?'100%':hideToolbar?Number(state.height)-toolbarHeight:state.height}),children:[!hideToolbar&&/*#__PURE__*/(0,jsx_runtime.jsx)(Toolbar_Toolbar,{prefixCls:prefixCls,height:toolbarHeight,overflow:overflow}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-content"),style:{height:state.fullscreen?"calc(100% - ".concat(toolbarHeight,"px)"):Number(state.height)-toolbarHeight},children:[/(edit|live)/.test(state.preview||'')&&/*#__PURE__*/(0,jsx_runtime.jsx)(TextArea_TextArea,_objectSpread2(_objectSpread2({className:"".concat(prefixCls,"-input"),prefixCls:prefixCls,autoFocus:autoFocus},textareaProps),{},{onChange:function onChange(evn){_onChange&&_onChange(evn.target.value,evn,state);if(textareaProps&&textareaProps.onChange){textareaProps.onChange(evn);}},renderTextarea:renderTextarea,onScroll:function onScroll(e){return handleScroll(e,'text');}})),/(live|preview)/.test(state.preview||'')&&mdPreview]}),
|
|
62276
|
+
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return height!==state.height&&dispatch({height:height});},[height]);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return height!==state.height&&onHeightChange&&onHeightChange(state.height,height,state);},[height,onHeightChange,state]);var textareaDomRef=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)();var active=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('preview');var initScroll=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(false);(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){textareaDomRef.current=state.textareaWarp;if(state.textareaWarp){state.textareaWarp.addEventListener('mouseover',function(){active.current='text';});state.textareaWarp.addEventListener('mouseleave',function(){active.current='preview';});}},[state.textareaWarp]);var handleScroll=function handleScroll(e,type){if(!enableScrollRef.current)return;var textareaDom=textareaDomRef.current;var previewDom=previewRef.current?previewRef.current.mdp.current:undefined;if(!initScroll.current){active.current=type;initScroll.current=true;}if(textareaDom&&previewDom){var scale=(textareaDom.scrollHeight-textareaDom.offsetHeight)/(previewDom.scrollHeight-previewDom.offsetHeight);if(e.target===textareaDom&&active.current==='text'){previewDom.scrollTop=textareaDom.scrollTop/scale;}if(e.target===previewDom&&active.current==='preview'){textareaDom.scrollTop=previewDom.scrollTop*scale;}var scrollTop=0;if(active.current==='text'){scrollTop=textareaDom.scrollTop||0;}else if(active.current==='preview'){scrollTop=previewDom.scrollTop||0;}dispatch({scrollTop:scrollTop});}};var mdPreview=(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useMemo)(function(){return/*#__PURE__*/(0,jsx_runtime.jsx)(esm,_objectSpread2(_objectSpread2({},previewOptions),{},{onScroll:function onScroll(e){return handleScroll(e,'preview');},ref:previewRef,source:state.markdown||'',className:"".concat(prefixCls,"-preview ").concat(previewOptions.className||'')}));},[prefixCls,previewOptions,state.markdown]);return/*#__PURE__*/(0,jsx_runtime.jsx)(EditorContext.Provider,{value:_objectSpread2(_objectSpread2({},state),{},{dispatch:dispatch}),children:/*#__PURE__*/(0,jsx_runtime.jsxs)("div",_objectSpread2(_objectSpread2({ref:container,className:cls},other),{},{onClick:function onClick(){dispatch({barPopup:_objectSpread2({},setGroupPopFalse(state.barPopup))});},style:_objectSpread2(_objectSpread2({},other.style),{},{height:state.fullscreen?'100%':hideToolbar?Number(state.height)-toolbarHeight:state.height}),children:[!hideToolbar&&!toolbarBottom&&/*#__PURE__*/(0,jsx_runtime.jsx)(Toolbar_Toolbar,{prefixCls:prefixCls,height:toolbarHeight,overflow:overflow,toolbarBottom:toolbarBottom}),/*#__PURE__*/(0,jsx_runtime.jsxs)("div",{className:"".concat(prefixCls,"-content"),style:{height:state.fullscreen?"calc(100% - ".concat(toolbarHeight,"px)"):Number(state.height)-toolbarHeight},children:[/(edit|live)/.test(state.preview||'')&&/*#__PURE__*/(0,jsx_runtime.jsx)(TextArea_TextArea,_objectSpread2(_objectSpread2({className:"".concat(prefixCls,"-input"),prefixCls:prefixCls,autoFocus:autoFocus},textareaProps),{},{onChange:function onChange(evn){_onChange&&_onChange(evn.target.value,evn,state);if(textareaProps&&textareaProps.onChange){textareaProps.onChange(evn);}},renderTextarea:renderTextarea,onScroll:function onScroll(e){return handleScroll(e,'text');}})),/(live|preview)/.test(state.preview||'')&&mdPreview]}),visibleDragbar&&!state.fullscreen&&/*#__PURE__*/(0,jsx_runtime.jsx)(components_DragBar,{prefixCls:prefixCls,height:state.height,maxHeight:maxHeight,minHeight:minHeight,onChange:function onChange(newHeight){dispatch({height:newHeight});}}),!hideToolbar&&toolbarBottom&&/*#__PURE__*/(0,jsx_runtime.jsx)(Toolbar_Toolbar,{prefixCls:prefixCls,height:toolbarHeight,overflow:overflow,toolbarBottom:toolbarBottom})]}))});};var mdEditor=/*#__PURE__*/external_root_React_commonjs2_react_commonjs_react_amd_react_default().forwardRef(InternalMDEditor);mdEditor.Markdown=esm;/* harmony default export */ const Editor = (mdEditor);
|
|
62675
62277
|
;// CONCATENATED MODULE: ./src/index.tsx
|
|
62676
62278
|
/* harmony default export */ const src_0 = (Editor);
|
|
62677
62279
|
})();
|