react-markdown-table-ts 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2710 -208
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +17 -9
- package/dist/index.esm.js +2712 -209
- package/dist/index.esm.js.map +1 -1
- package/package.json +7 -3
package/dist/index.cjs.js
CHANGED
@@ -8,6 +8,58 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
8
8
|
|
9
9
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
10
10
|
|
11
|
+
/******************************************************************************
|
12
|
+
Copyright (c) Microsoft Corporation.
|
13
|
+
|
14
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
15
|
+
purpose with or without fee is hereby granted.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
18
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
19
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
20
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
21
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
22
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
23
|
+
PERFORMANCE OF THIS SOFTWARE.
|
24
|
+
***************************************************************************** */
|
25
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
26
|
+
|
27
|
+
var extendStatics = function(d, b) {
|
28
|
+
extendStatics = Object.setPrototypeOf ||
|
29
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
30
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
31
|
+
return extendStatics(d, b);
|
32
|
+
};
|
33
|
+
|
34
|
+
function __extends(d, b) {
|
35
|
+
if (typeof b !== "function" && b !== null)
|
36
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
37
|
+
extendStatics(d, b);
|
38
|
+
function __() { this.constructor = d; }
|
39
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
40
|
+
}
|
41
|
+
|
42
|
+
function __spreadArray(to, from, pack) {
|
43
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
44
|
+
if (ar || !(i in from)) {
|
45
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
46
|
+
ar[i] = from[i];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
50
|
+
}
|
51
|
+
|
52
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
53
|
+
var e = new Error(message);
|
54
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
55
|
+
};
|
56
|
+
|
57
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
58
|
+
|
59
|
+
function getDefaultExportFromCjs (x) {
|
60
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
61
|
+
}
|
62
|
+
|
11
63
|
var jsxRuntime = {exports: {}};
|
12
64
|
|
13
65
|
var reactJsxRuntime_production_min = {};
|
@@ -1381,61 +1433,2643 @@ if (process.env.NODE_ENV === 'production') {
|
|
1381
1433
|
|
1382
1434
|
var jsxRuntimeExports = jsxRuntime.exports;
|
1383
1435
|
|
1384
|
-
|
1385
|
-
Copyright (c) Microsoft Corporation.
|
1386
|
-
|
1387
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
1388
|
-
purpose with or without fee is hereby granted.
|
1389
|
-
|
1390
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
1391
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
1392
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
1393
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
1394
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
1395
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
1396
|
-
PERFORMANCE OF THIS SOFTWARE.
|
1397
|
-
***************************************************************************** */
|
1398
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
1399
|
-
|
1400
|
-
var extendStatics = function(d, b) {
|
1401
|
-
extendStatics = Object.setPrototypeOf ||
|
1402
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
1403
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
1404
|
-
return extendStatics(d, b);
|
1405
|
-
};
|
1406
|
-
|
1407
|
-
function __extends(d, b) {
|
1408
|
-
if (typeof b !== "function" && b !== null)
|
1409
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
1410
|
-
extendStatics(d, b);
|
1411
|
-
function __() { this.constructor = d; }
|
1412
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
1413
|
-
}
|
1414
|
-
|
1415
|
-
function __spreadArray(to, from, pack) {
|
1416
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
1417
|
-
if (ar || !(i in from)) {
|
1418
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
1419
|
-
ar[i] = from[i];
|
1420
|
-
}
|
1421
|
-
}
|
1422
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
1423
|
-
}
|
1424
|
-
|
1425
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
1426
|
-
var e = new Error(message);
|
1427
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
1428
|
-
};
|
1436
|
+
var prism = {exports: {}};
|
1429
1437
|
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1438
|
+
prism.exports;
|
1439
|
+
|
1440
|
+
(function (module) {
|
1441
|
+
/* **********************************************
|
1442
|
+
Begin prism-core.js
|
1443
|
+
********************************************** */
|
1444
|
+
|
1445
|
+
/// <reference lib="WebWorker"/>
|
1446
|
+
|
1447
|
+
var _self = (typeof window !== 'undefined')
|
1448
|
+
? window // if in browser
|
1449
|
+
: (
|
1450
|
+
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
1451
|
+
? self // if in worker
|
1452
|
+
: {} // if in node js
|
1453
|
+
);
|
1454
|
+
|
1455
|
+
/**
|
1456
|
+
* Prism: Lightweight, robust, elegant syntax highlighting
|
1457
|
+
*
|
1458
|
+
* @license MIT <https://opensource.org/licenses/MIT>
|
1459
|
+
* @author Lea Verou <https://lea.verou.me>
|
1460
|
+
* @namespace
|
1461
|
+
* @public
|
1462
|
+
*/
|
1463
|
+
var Prism = (function (_self) {
|
1464
|
+
|
1465
|
+
// Private helper vars
|
1466
|
+
var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
|
1467
|
+
var uniqueId = 0;
|
1468
|
+
|
1469
|
+
// The grammar object for plaintext
|
1470
|
+
var plainTextGrammar = {};
|
1471
|
+
|
1472
|
+
|
1473
|
+
var _ = {
|
1474
|
+
/**
|
1475
|
+
* By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
|
1476
|
+
* current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
|
1477
|
+
* additional languages or plugins yourself.
|
1478
|
+
*
|
1479
|
+
* By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
|
1480
|
+
*
|
1481
|
+
* You obviously have to change this value before the automatic highlighting started. To do this, you can add an
|
1482
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
1483
|
+
*
|
1484
|
+
* ```js
|
1485
|
+
* window.Prism = window.Prism || {};
|
1486
|
+
* Prism.manual = true;
|
1487
|
+
* // add a new <script> to load Prism's script
|
1488
|
+
* ```
|
1489
|
+
*
|
1490
|
+
* @default false
|
1491
|
+
* @type {boolean}
|
1492
|
+
* @memberof Prism
|
1493
|
+
* @public
|
1494
|
+
*/
|
1495
|
+
manual: _self.Prism && _self.Prism.manual,
|
1496
|
+
/**
|
1497
|
+
* By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
|
1498
|
+
* `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
|
1499
|
+
* own worker, you don't want it to do this.
|
1500
|
+
*
|
1501
|
+
* By setting this value to `true`, Prism will not add its own listeners to the worker.
|
1502
|
+
*
|
1503
|
+
* You obviously have to change this value before Prism executes. To do this, you can add an
|
1504
|
+
* empty Prism object into the global scope before loading the Prism script like this:
|
1505
|
+
*
|
1506
|
+
* ```js
|
1507
|
+
* window.Prism = window.Prism || {};
|
1508
|
+
* Prism.disableWorkerMessageHandler = true;
|
1509
|
+
* // Load Prism's script
|
1510
|
+
* ```
|
1511
|
+
*
|
1512
|
+
* @default false
|
1513
|
+
* @type {boolean}
|
1514
|
+
* @memberof Prism
|
1515
|
+
* @public
|
1516
|
+
*/
|
1517
|
+
disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
|
1518
|
+
|
1519
|
+
/**
|
1520
|
+
* A namespace for utility methods.
|
1521
|
+
*
|
1522
|
+
* All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
|
1523
|
+
* change or disappear at any time.
|
1524
|
+
*
|
1525
|
+
* @namespace
|
1526
|
+
* @memberof Prism
|
1527
|
+
*/
|
1528
|
+
util: {
|
1529
|
+
encode: function encode(tokens) {
|
1530
|
+
if (tokens instanceof Token) {
|
1531
|
+
return new Token(tokens.type, encode(tokens.content), tokens.alias);
|
1532
|
+
} else if (Array.isArray(tokens)) {
|
1533
|
+
return tokens.map(encode);
|
1534
|
+
} else {
|
1535
|
+
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
1536
|
+
}
|
1537
|
+
},
|
1538
|
+
|
1539
|
+
/**
|
1540
|
+
* Returns the name of the type of the given value.
|
1541
|
+
*
|
1542
|
+
* @param {any} o
|
1543
|
+
* @returns {string}
|
1544
|
+
* @example
|
1545
|
+
* type(null) === 'Null'
|
1546
|
+
* type(undefined) === 'Undefined'
|
1547
|
+
* type(123) === 'Number'
|
1548
|
+
* type('foo') === 'String'
|
1549
|
+
* type(true) === 'Boolean'
|
1550
|
+
* type([1, 2]) === 'Array'
|
1551
|
+
* type({}) === 'Object'
|
1552
|
+
* type(String) === 'Function'
|
1553
|
+
* type(/abc+/) === 'RegExp'
|
1554
|
+
*/
|
1555
|
+
type: function (o) {
|
1556
|
+
return Object.prototype.toString.call(o).slice(8, -1);
|
1557
|
+
},
|
1558
|
+
|
1559
|
+
/**
|
1560
|
+
* Returns a unique number for the given object. Later calls will still return the same number.
|
1561
|
+
*
|
1562
|
+
* @param {Object} obj
|
1563
|
+
* @returns {number}
|
1564
|
+
*/
|
1565
|
+
objId: function (obj) {
|
1566
|
+
if (!obj['__id']) {
|
1567
|
+
Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
1568
|
+
}
|
1569
|
+
return obj['__id'];
|
1570
|
+
},
|
1571
|
+
|
1572
|
+
/**
|
1573
|
+
* Creates a deep clone of the given object.
|
1574
|
+
*
|
1575
|
+
* The main intended use of this function is to clone language definitions.
|
1576
|
+
*
|
1577
|
+
* @param {T} o
|
1578
|
+
* @param {Record<number, any>} [visited]
|
1579
|
+
* @returns {T}
|
1580
|
+
* @template T
|
1581
|
+
*/
|
1582
|
+
clone: function deepClone(o, visited) {
|
1583
|
+
visited = visited || {};
|
1584
|
+
|
1585
|
+
var clone; var id;
|
1586
|
+
switch (_.util.type(o)) {
|
1587
|
+
case 'Object':
|
1588
|
+
id = _.util.objId(o);
|
1589
|
+
if (visited[id]) {
|
1590
|
+
return visited[id];
|
1591
|
+
}
|
1592
|
+
clone = /** @type {Record<string, any>} */ ({});
|
1593
|
+
visited[id] = clone;
|
1594
|
+
|
1595
|
+
for (var key in o) {
|
1596
|
+
if (o.hasOwnProperty(key)) {
|
1597
|
+
clone[key] = deepClone(o[key], visited);
|
1598
|
+
}
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
return /** @type {any} */ (clone);
|
1602
|
+
|
1603
|
+
case 'Array':
|
1604
|
+
id = _.util.objId(o);
|
1605
|
+
if (visited[id]) {
|
1606
|
+
return visited[id];
|
1607
|
+
}
|
1608
|
+
clone = [];
|
1609
|
+
visited[id] = clone;
|
1610
|
+
|
1611
|
+
(/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
|
1612
|
+
clone[i] = deepClone(v, visited);
|
1613
|
+
});
|
1614
|
+
|
1615
|
+
return /** @type {any} */ (clone);
|
1616
|
+
|
1617
|
+
default:
|
1618
|
+
return o;
|
1619
|
+
}
|
1620
|
+
},
|
1621
|
+
|
1622
|
+
/**
|
1623
|
+
* Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
|
1624
|
+
*
|
1625
|
+
* If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
|
1626
|
+
*
|
1627
|
+
* @param {Element} element
|
1628
|
+
* @returns {string}
|
1629
|
+
*/
|
1630
|
+
getLanguage: function (element) {
|
1631
|
+
while (element) {
|
1632
|
+
var m = lang.exec(element.className);
|
1633
|
+
if (m) {
|
1634
|
+
return m[1].toLowerCase();
|
1635
|
+
}
|
1636
|
+
element = element.parentElement;
|
1637
|
+
}
|
1638
|
+
return 'none';
|
1639
|
+
},
|
1640
|
+
|
1641
|
+
/**
|
1642
|
+
* Sets the Prism `language-xxxx` class of the given element.
|
1643
|
+
*
|
1644
|
+
* @param {Element} element
|
1645
|
+
* @param {string} language
|
1646
|
+
* @returns {void}
|
1647
|
+
*/
|
1648
|
+
setLanguage: function (element, language) {
|
1649
|
+
// remove all `language-xxxx` classes
|
1650
|
+
// (this might leave behind a leading space)
|
1651
|
+
element.className = element.className.replace(RegExp(lang, 'gi'), '');
|
1652
|
+
|
1653
|
+
// add the new `language-xxxx` class
|
1654
|
+
// (using `classList` will automatically clean up spaces for us)
|
1655
|
+
element.classList.add('language-' + language);
|
1656
|
+
},
|
1657
|
+
|
1658
|
+
/**
|
1659
|
+
* Returns the script element that is currently executing.
|
1660
|
+
*
|
1661
|
+
* This does __not__ work for line script element.
|
1662
|
+
*
|
1663
|
+
* @returns {HTMLScriptElement | null}
|
1664
|
+
*/
|
1665
|
+
currentScript: function () {
|
1666
|
+
if (typeof document === 'undefined') {
|
1667
|
+
return null;
|
1668
|
+
}
|
1669
|
+
if ('currentScript' in document && 1 < 2 /* hack to trip TS' flow analysis */) {
|
1670
|
+
return /** @type {any} */ (document.currentScript);
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
// IE11 workaround
|
1674
|
+
// we'll get the src of the current script by parsing IE11's error stack trace
|
1675
|
+
// this will not work for inline scripts
|
1676
|
+
|
1677
|
+
try {
|
1678
|
+
throw new Error();
|
1679
|
+
} catch (err) {
|
1680
|
+
// Get file src url from stack. Specifically works with the format of stack traces in IE.
|
1681
|
+
// A stack will look like this:
|
1682
|
+
//
|
1683
|
+
// Error
|
1684
|
+
// at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
|
1685
|
+
// at Global code (http://localhost/components/prism-core.js:606:1)
|
1686
|
+
|
1687
|
+
var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
|
1688
|
+
if (src) {
|
1689
|
+
var scripts = document.getElementsByTagName('script');
|
1690
|
+
for (var i in scripts) {
|
1691
|
+
if (scripts[i].src == src) {
|
1692
|
+
return scripts[i];
|
1693
|
+
}
|
1694
|
+
}
|
1695
|
+
}
|
1696
|
+
return null;
|
1697
|
+
}
|
1698
|
+
},
|
1699
|
+
|
1700
|
+
/**
|
1701
|
+
* Returns whether a given class is active for `element`.
|
1702
|
+
*
|
1703
|
+
* The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
|
1704
|
+
* if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
|
1705
|
+
* given class is just the given class with a `no-` prefix.
|
1706
|
+
*
|
1707
|
+
* Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
|
1708
|
+
* closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
|
1709
|
+
* ancestors have the given class or the negated version of it, then the default activation will be returned.
|
1710
|
+
*
|
1711
|
+
* In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
|
1712
|
+
* version of it, the class is considered active.
|
1713
|
+
*
|
1714
|
+
* @param {Element} element
|
1715
|
+
* @param {string} className
|
1716
|
+
* @param {boolean} [defaultActivation=false]
|
1717
|
+
* @returns {boolean}
|
1718
|
+
*/
|
1719
|
+
isActive: function (element, className, defaultActivation) {
|
1720
|
+
var no = 'no-' + className;
|
1721
|
+
|
1722
|
+
while (element) {
|
1723
|
+
var classList = element.classList;
|
1724
|
+
if (classList.contains(className)) {
|
1725
|
+
return true;
|
1726
|
+
}
|
1727
|
+
if (classList.contains(no)) {
|
1728
|
+
return false;
|
1729
|
+
}
|
1730
|
+
element = element.parentElement;
|
1731
|
+
}
|
1732
|
+
return !!defaultActivation;
|
1733
|
+
}
|
1734
|
+
},
|
1735
|
+
|
1736
|
+
/**
|
1737
|
+
* This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
|
1738
|
+
*
|
1739
|
+
* @namespace
|
1740
|
+
* @memberof Prism
|
1741
|
+
* @public
|
1742
|
+
*/
|
1743
|
+
languages: {
|
1744
|
+
/**
|
1745
|
+
* The grammar for plain, unformatted text.
|
1746
|
+
*/
|
1747
|
+
plain: plainTextGrammar,
|
1748
|
+
plaintext: plainTextGrammar,
|
1749
|
+
text: plainTextGrammar,
|
1750
|
+
txt: plainTextGrammar,
|
1751
|
+
|
1752
|
+
/**
|
1753
|
+
* Creates a deep copy of the language with the given id and appends the given tokens.
|
1754
|
+
*
|
1755
|
+
* If a token in `redef` also appears in the copied language, then the existing token in the copied language
|
1756
|
+
* will be overwritten at its original position.
|
1757
|
+
*
|
1758
|
+
* ## Best practices
|
1759
|
+
*
|
1760
|
+
* Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
|
1761
|
+
* doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
|
1762
|
+
* understand the language definition because, normally, the order of tokens matters in Prism grammars.
|
1763
|
+
*
|
1764
|
+
* Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
|
1765
|
+
* Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
|
1766
|
+
*
|
1767
|
+
* @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
|
1768
|
+
* @param {Grammar} redef The new tokens to append.
|
1769
|
+
* @returns {Grammar} The new language created.
|
1770
|
+
* @public
|
1771
|
+
* @example
|
1772
|
+
* Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
|
1773
|
+
* // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
|
1774
|
+
* // at its original position
|
1775
|
+
* 'comment': { ... },
|
1776
|
+
* // CSS doesn't have a 'color' token, so this token will be appended
|
1777
|
+
* 'color': /\b(?:red|green|blue)\b/
|
1778
|
+
* });
|
1779
|
+
*/
|
1780
|
+
extend: function (id, redef) {
|
1781
|
+
var lang = _.util.clone(_.languages[id]);
|
1782
|
+
|
1783
|
+
for (var key in redef) {
|
1784
|
+
lang[key] = redef[key];
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
return lang;
|
1788
|
+
},
|
1789
|
+
|
1790
|
+
/**
|
1791
|
+
* Inserts tokens _before_ another token in a language definition or any other grammar.
|
1792
|
+
*
|
1793
|
+
* ## Usage
|
1794
|
+
*
|
1795
|
+
* This helper method makes it easy to modify existing languages. For example, the CSS language definition
|
1796
|
+
* not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
|
1797
|
+
* in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
|
1798
|
+
* appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
|
1799
|
+
* this:
|
1800
|
+
*
|
1801
|
+
* ```js
|
1802
|
+
* Prism.languages.markup.style = {
|
1803
|
+
* // token
|
1804
|
+
* };
|
1805
|
+
* ```
|
1806
|
+
*
|
1807
|
+
* then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
|
1808
|
+
* before existing tokens. For the CSS example above, you would use it like this:
|
1809
|
+
*
|
1810
|
+
* ```js
|
1811
|
+
* Prism.languages.insertBefore('markup', 'cdata', {
|
1812
|
+
* 'style': {
|
1813
|
+
* // token
|
1814
|
+
* }
|
1815
|
+
* });
|
1816
|
+
* ```
|
1817
|
+
*
|
1818
|
+
* ## Special cases
|
1819
|
+
*
|
1820
|
+
* If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
|
1821
|
+
* will be ignored.
|
1822
|
+
*
|
1823
|
+
* This behavior can be used to insert tokens after `before`:
|
1824
|
+
*
|
1825
|
+
* ```js
|
1826
|
+
* Prism.languages.insertBefore('markup', 'comment', {
|
1827
|
+
* 'comment': Prism.languages.markup.comment,
|
1828
|
+
* // tokens after 'comment'
|
1829
|
+
* });
|
1830
|
+
* ```
|
1831
|
+
*
|
1832
|
+
* ## Limitations
|
1833
|
+
*
|
1834
|
+
* The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
|
1835
|
+
* properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
|
1836
|
+
* differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
|
1837
|
+
* deleting properties which is necessary to insert at arbitrary positions.
|
1838
|
+
*
|
1839
|
+
* To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
|
1840
|
+
* Instead, it will create a new object and replace all references to the target object with the new one. This
|
1841
|
+
* can be done without temporarily deleting properties, so the iteration order is well-defined.
|
1842
|
+
*
|
1843
|
+
* However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
|
1844
|
+
* you hold the target object in a variable, then the value of the variable will not change.
|
1845
|
+
*
|
1846
|
+
* ```js
|
1847
|
+
* var oldMarkup = Prism.languages.markup;
|
1848
|
+
* var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
|
1849
|
+
*
|
1850
|
+
* assert(oldMarkup !== Prism.languages.markup);
|
1851
|
+
* assert(newMarkup === Prism.languages.markup);
|
1852
|
+
* ```
|
1853
|
+
*
|
1854
|
+
* @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
|
1855
|
+
* object to be modified.
|
1856
|
+
* @param {string} before The key to insert before.
|
1857
|
+
* @param {Grammar} insert An object containing the key-value pairs to be inserted.
|
1858
|
+
* @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
|
1859
|
+
* object to be modified.
|
1860
|
+
*
|
1861
|
+
* Defaults to `Prism.languages`.
|
1862
|
+
* @returns {Grammar} The new grammar object.
|
1863
|
+
* @public
|
1864
|
+
*/
|
1865
|
+
insertBefore: function (inside, before, insert, root) {
|
1866
|
+
root = root || /** @type {any} */ (_.languages);
|
1867
|
+
var grammar = root[inside];
|
1868
|
+
/** @type {Grammar} */
|
1869
|
+
var ret = {};
|
1870
|
+
|
1871
|
+
for (var token in grammar) {
|
1872
|
+
if (grammar.hasOwnProperty(token)) {
|
1873
|
+
|
1874
|
+
if (token == before) {
|
1875
|
+
for (var newToken in insert) {
|
1876
|
+
if (insert.hasOwnProperty(newToken)) {
|
1877
|
+
ret[newToken] = insert[newToken];
|
1878
|
+
}
|
1879
|
+
}
|
1880
|
+
}
|
1881
|
+
|
1882
|
+
// Do not insert token which also occur in insert. See #1525
|
1883
|
+
if (!insert.hasOwnProperty(token)) {
|
1884
|
+
ret[token] = grammar[token];
|
1885
|
+
}
|
1886
|
+
}
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
var old = root[inside];
|
1890
|
+
root[inside] = ret;
|
1891
|
+
|
1892
|
+
// Update references in other language definitions
|
1893
|
+
_.languages.DFS(_.languages, function (key, value) {
|
1894
|
+
if (value === old && key != inside) {
|
1895
|
+
this[key] = ret;
|
1896
|
+
}
|
1897
|
+
});
|
1898
|
+
|
1899
|
+
return ret;
|
1900
|
+
},
|
1901
|
+
|
1902
|
+
// Traverse a language definition with Depth First Search
|
1903
|
+
DFS: function DFS(o, callback, type, visited) {
|
1904
|
+
visited = visited || {};
|
1905
|
+
|
1906
|
+
var objId = _.util.objId;
|
1907
|
+
|
1908
|
+
for (var i in o) {
|
1909
|
+
if (o.hasOwnProperty(i)) {
|
1910
|
+
callback.call(o, i, o[i], type || i);
|
1911
|
+
|
1912
|
+
var property = o[i];
|
1913
|
+
var propertyType = _.util.type(property);
|
1914
|
+
|
1915
|
+
if (propertyType === 'Object' && !visited[objId(property)]) {
|
1916
|
+
visited[objId(property)] = true;
|
1917
|
+
DFS(property, callback, null, visited);
|
1918
|
+
} else if (propertyType === 'Array' && !visited[objId(property)]) {
|
1919
|
+
visited[objId(property)] = true;
|
1920
|
+
DFS(property, callback, i, visited);
|
1921
|
+
}
|
1922
|
+
}
|
1923
|
+
}
|
1924
|
+
}
|
1925
|
+
},
|
1926
|
+
|
1927
|
+
plugins: {},
|
1928
|
+
|
1929
|
+
/**
|
1930
|
+
* This is the most high-level function in Prism’s API.
|
1931
|
+
* It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
|
1932
|
+
* each one of them.
|
1933
|
+
*
|
1934
|
+
* This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
|
1935
|
+
*
|
1936
|
+
* @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
|
1937
|
+
* @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
|
1938
|
+
* @memberof Prism
|
1939
|
+
* @public
|
1940
|
+
*/
|
1941
|
+
highlightAll: function (async, callback) {
|
1942
|
+
_.highlightAllUnder(document, async, callback);
|
1943
|
+
},
|
1944
|
+
|
1945
|
+
/**
|
1946
|
+
* Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
|
1947
|
+
* {@link Prism.highlightElement} on each one of them.
|
1948
|
+
*
|
1949
|
+
* The following hooks will be run:
|
1950
|
+
* 1. `before-highlightall`
|
1951
|
+
* 2. `before-all-elements-highlight`
|
1952
|
+
* 3. All hooks of {@link Prism.highlightElement} for each element.
|
1953
|
+
*
|
1954
|
+
* @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
|
1955
|
+
* @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
|
1956
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
|
1957
|
+
* @memberof Prism
|
1958
|
+
* @public
|
1959
|
+
*/
|
1960
|
+
highlightAllUnder: function (container, async, callback) {
|
1961
|
+
var env = {
|
1962
|
+
callback: callback,
|
1963
|
+
container: container,
|
1964
|
+
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
1965
|
+
};
|
1966
|
+
|
1967
|
+
_.hooks.run('before-highlightall', env);
|
1968
|
+
|
1969
|
+
env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
|
1970
|
+
|
1971
|
+
_.hooks.run('before-all-elements-highlight', env);
|
1972
|
+
|
1973
|
+
for (var i = 0, element; (element = env.elements[i++]);) {
|
1974
|
+
_.highlightElement(element, async === true, env.callback);
|
1975
|
+
}
|
1976
|
+
},
|
1977
|
+
|
1978
|
+
/**
|
1979
|
+
* Highlights the code inside a single element.
|
1980
|
+
*
|
1981
|
+
* The following hooks will be run:
|
1982
|
+
* 1. `before-sanity-check`
|
1983
|
+
* 2. `before-highlight`
|
1984
|
+
* 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
|
1985
|
+
* 4. `before-insert`
|
1986
|
+
* 5. `after-highlight`
|
1987
|
+
* 6. `complete`
|
1988
|
+
*
|
1989
|
+
* Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
|
1990
|
+
* the element's language.
|
1991
|
+
*
|
1992
|
+
* @param {Element} element The element containing the code.
|
1993
|
+
* It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
|
1994
|
+
* @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
|
1995
|
+
* to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
|
1996
|
+
* [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
|
1997
|
+
*
|
1998
|
+
* Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
|
1999
|
+
* asynchronous highlighting to work. You can build your own bundle on the
|
2000
|
+
* [Download page](https://prismjs.com/download.html).
|
2001
|
+
* @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
|
2002
|
+
* Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
|
2003
|
+
* @memberof Prism
|
2004
|
+
* @public
|
2005
|
+
*/
|
2006
|
+
highlightElement: function (element, async, callback) {
|
2007
|
+
// Find language
|
2008
|
+
var language = _.util.getLanguage(element);
|
2009
|
+
var grammar = _.languages[language];
|
2010
|
+
|
2011
|
+
// Set language on the element, if not present
|
2012
|
+
_.util.setLanguage(element, language);
|
2013
|
+
|
2014
|
+
// Set language on the parent, for styling
|
2015
|
+
var parent = element.parentElement;
|
2016
|
+
if (parent && parent.nodeName.toLowerCase() === 'pre') {
|
2017
|
+
_.util.setLanguage(parent, language);
|
2018
|
+
}
|
2019
|
+
|
2020
|
+
var code = element.textContent;
|
2021
|
+
|
2022
|
+
var env = {
|
2023
|
+
element: element,
|
2024
|
+
language: language,
|
2025
|
+
grammar: grammar,
|
2026
|
+
code: code
|
2027
|
+
};
|
2028
|
+
|
2029
|
+
function insertHighlightedCode(highlightedCode) {
|
2030
|
+
env.highlightedCode = highlightedCode;
|
2031
|
+
|
2032
|
+
_.hooks.run('before-insert', env);
|
2033
|
+
|
2034
|
+
env.element.innerHTML = env.highlightedCode;
|
2035
|
+
|
2036
|
+
_.hooks.run('after-highlight', env);
|
2037
|
+
_.hooks.run('complete', env);
|
2038
|
+
callback && callback.call(env.element);
|
2039
|
+
}
|
2040
|
+
|
2041
|
+
_.hooks.run('before-sanity-check', env);
|
2042
|
+
|
2043
|
+
// plugins may change/add the parent/element
|
2044
|
+
parent = env.element.parentElement;
|
2045
|
+
if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
|
2046
|
+
parent.setAttribute('tabindex', '0');
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
if (!env.code) {
|
2050
|
+
_.hooks.run('complete', env);
|
2051
|
+
callback && callback.call(env.element);
|
2052
|
+
return;
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
_.hooks.run('before-highlight', env);
|
2056
|
+
|
2057
|
+
if (!env.grammar) {
|
2058
|
+
insertHighlightedCode(_.util.encode(env.code));
|
2059
|
+
return;
|
2060
|
+
}
|
2061
|
+
|
2062
|
+
if (async && _self.Worker) {
|
2063
|
+
var worker = new Worker(_.filename);
|
2064
|
+
|
2065
|
+
worker.onmessage = function (evt) {
|
2066
|
+
insertHighlightedCode(evt.data);
|
2067
|
+
};
|
2068
|
+
|
2069
|
+
worker.postMessage(JSON.stringify({
|
2070
|
+
language: env.language,
|
2071
|
+
code: env.code,
|
2072
|
+
immediateClose: true
|
2073
|
+
}));
|
2074
|
+
} else {
|
2075
|
+
insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
|
2076
|
+
}
|
2077
|
+
},
|
2078
|
+
|
2079
|
+
/**
|
2080
|
+
* Low-level function, only use if you know what you’re doing. It accepts a string of text as input
|
2081
|
+
* and the language definitions to use, and returns a string with the HTML produced.
|
2082
|
+
*
|
2083
|
+
* The following hooks will be run:
|
2084
|
+
* 1. `before-tokenize`
|
2085
|
+
* 2. `after-tokenize`
|
2086
|
+
* 3. `wrap`: On each {@link Token}.
|
2087
|
+
*
|
2088
|
+
* @param {string} text A string with the code to be highlighted.
|
2089
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
2090
|
+
*
|
2091
|
+
* Usually a language definition like `Prism.languages.markup`.
|
2092
|
+
* @param {string} language The name of the language definition passed to `grammar`.
|
2093
|
+
* @returns {string} The highlighted HTML.
|
2094
|
+
* @memberof Prism
|
2095
|
+
* @public
|
2096
|
+
* @example
|
2097
|
+
* Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
|
2098
|
+
*/
|
2099
|
+
highlight: function (text, grammar, language) {
|
2100
|
+
var env = {
|
2101
|
+
code: text,
|
2102
|
+
grammar: grammar,
|
2103
|
+
language: language
|
2104
|
+
};
|
2105
|
+
_.hooks.run('before-tokenize', env);
|
2106
|
+
if (!env.grammar) {
|
2107
|
+
throw new Error('The language "' + env.language + '" has no grammar.');
|
2108
|
+
}
|
2109
|
+
env.tokens = _.tokenize(env.code, env.grammar);
|
2110
|
+
_.hooks.run('after-tokenize', env);
|
2111
|
+
return Token.stringify(_.util.encode(env.tokens), env.language);
|
2112
|
+
},
|
2113
|
+
|
2114
|
+
/**
|
2115
|
+
* This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
|
2116
|
+
* and the language definitions to use, and returns an array with the tokenized code.
|
2117
|
+
*
|
2118
|
+
* When the language definition includes nested tokens, the function is called recursively on each of these tokens.
|
2119
|
+
*
|
2120
|
+
* This method could be useful in other contexts as well, as a very crude parser.
|
2121
|
+
*
|
2122
|
+
* @param {string} text A string with the code to be highlighted.
|
2123
|
+
* @param {Grammar} grammar An object containing the tokens to use.
|
2124
|
+
*
|
2125
|
+
* Usually a language definition like `Prism.languages.markup`.
|
2126
|
+
* @returns {TokenStream} An array of strings and tokens, a token stream.
|
2127
|
+
* @memberof Prism
|
2128
|
+
* @public
|
2129
|
+
* @example
|
2130
|
+
* let code = `var foo = 0;`;
|
2131
|
+
* let tokens = Prism.tokenize(code, Prism.languages.javascript);
|
2132
|
+
* tokens.forEach(token => {
|
2133
|
+
* if (token instanceof Prism.Token && token.type === 'number') {
|
2134
|
+
* console.log(`Found numeric literal: ${token.content}`);
|
2135
|
+
* }
|
2136
|
+
* });
|
2137
|
+
*/
|
2138
|
+
tokenize: function (text, grammar) {
|
2139
|
+
var rest = grammar.rest;
|
2140
|
+
if (rest) {
|
2141
|
+
for (var token in rest) {
|
2142
|
+
grammar[token] = rest[token];
|
2143
|
+
}
|
2144
|
+
|
2145
|
+
delete grammar.rest;
|
2146
|
+
}
|
2147
|
+
|
2148
|
+
var tokenList = new LinkedList();
|
2149
|
+
addAfter(tokenList, tokenList.head, text);
|
2150
|
+
|
2151
|
+
matchGrammar(text, tokenList, grammar, tokenList.head, 0);
|
2152
|
+
|
2153
|
+
return toArray(tokenList);
|
2154
|
+
},
|
2155
|
+
|
2156
|
+
/**
|
2157
|
+
* @namespace
|
2158
|
+
* @memberof Prism
|
2159
|
+
* @public
|
2160
|
+
*/
|
2161
|
+
hooks: {
|
2162
|
+
all: {},
|
2163
|
+
|
2164
|
+
/**
|
2165
|
+
* Adds the given callback to the list of callbacks for the given hook.
|
2166
|
+
*
|
2167
|
+
* The callback will be invoked when the hook it is registered for is run.
|
2168
|
+
* Hooks are usually directly run by a highlight function but you can also run hooks yourself.
|
2169
|
+
*
|
2170
|
+
* One callback function can be registered to multiple hooks and the same hook multiple times.
|
2171
|
+
*
|
2172
|
+
* @param {string} name The name of the hook.
|
2173
|
+
* @param {HookCallback} callback The callback function which is given environment variables.
|
2174
|
+
* @public
|
2175
|
+
*/
|
2176
|
+
add: function (name, callback) {
|
2177
|
+
var hooks = _.hooks.all;
|
2178
|
+
|
2179
|
+
hooks[name] = hooks[name] || [];
|
2180
|
+
|
2181
|
+
hooks[name].push(callback);
|
2182
|
+
},
|
2183
|
+
|
2184
|
+
/**
|
2185
|
+
* Runs a hook invoking all registered callbacks with the given environment variables.
|
2186
|
+
*
|
2187
|
+
* Callbacks will be invoked synchronously and in the order in which they were registered.
|
2188
|
+
*
|
2189
|
+
* @param {string} name The name of the hook.
|
2190
|
+
* @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
|
2191
|
+
* @public
|
2192
|
+
*/
|
2193
|
+
run: function (name, env) {
|
2194
|
+
var callbacks = _.hooks.all[name];
|
2195
|
+
|
2196
|
+
if (!callbacks || !callbacks.length) {
|
2197
|
+
return;
|
2198
|
+
}
|
2199
|
+
|
2200
|
+
for (var i = 0, callback; (callback = callbacks[i++]);) {
|
2201
|
+
callback(env);
|
2202
|
+
}
|
2203
|
+
}
|
2204
|
+
},
|
2205
|
+
|
2206
|
+
Token: Token
|
2207
|
+
};
|
2208
|
+
_self.Prism = _;
|
2209
|
+
|
2210
|
+
|
2211
|
+
// Typescript note:
|
2212
|
+
// The following can be used to import the Token type in JSDoc:
|
2213
|
+
//
|
2214
|
+
// @typedef {InstanceType<import("./prism-core")["Token"]>} Token
|
2215
|
+
|
2216
|
+
/**
|
2217
|
+
* Creates a new token.
|
2218
|
+
*
|
2219
|
+
* @param {string} type See {@link Token#type type}
|
2220
|
+
* @param {string | TokenStream} content See {@link Token#content content}
|
2221
|
+
* @param {string|string[]} [alias] The alias(es) of the token.
|
2222
|
+
* @param {string} [matchedStr=""] A copy of the full string this token was created from.
|
2223
|
+
* @class
|
2224
|
+
* @global
|
2225
|
+
* @public
|
2226
|
+
*/
|
2227
|
+
function Token(type, content, alias, matchedStr) {
|
2228
|
+
/**
|
2229
|
+
* The type of the token.
|
2230
|
+
*
|
2231
|
+
* This is usually the key of a pattern in a {@link Grammar}.
|
2232
|
+
*
|
2233
|
+
* @type {string}
|
2234
|
+
* @see GrammarToken
|
2235
|
+
* @public
|
2236
|
+
*/
|
2237
|
+
this.type = type;
|
2238
|
+
/**
|
2239
|
+
* The strings or tokens contained by this token.
|
2240
|
+
*
|
2241
|
+
* This will be a token stream if the pattern matched also defined an `inside` grammar.
|
2242
|
+
*
|
2243
|
+
* @type {string | TokenStream}
|
2244
|
+
* @public
|
2245
|
+
*/
|
2246
|
+
this.content = content;
|
2247
|
+
/**
|
2248
|
+
* The alias(es) of the token.
|
2249
|
+
*
|
2250
|
+
* @type {string|string[]}
|
2251
|
+
* @see GrammarToken
|
2252
|
+
* @public
|
2253
|
+
*/
|
2254
|
+
this.alias = alias;
|
2255
|
+
// Copy of the full string this token was created from
|
2256
|
+
this.length = (matchedStr || '').length | 0;
|
2257
|
+
}
|
2258
|
+
|
2259
|
+
/**
|
2260
|
+
* A token stream is an array of strings and {@link Token Token} objects.
|
2261
|
+
*
|
2262
|
+
* Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
|
2263
|
+
* them.
|
2264
|
+
*
|
2265
|
+
* 1. No adjacent strings.
|
2266
|
+
* 2. No empty strings.
|
2267
|
+
*
|
2268
|
+
* The only exception here is the token stream that only contains the empty string and nothing else.
|
2269
|
+
*
|
2270
|
+
* @typedef {Array<string | Token>} TokenStream
|
2271
|
+
* @global
|
2272
|
+
* @public
|
2273
|
+
*/
|
2274
|
+
|
2275
|
+
/**
|
2276
|
+
* Converts the given token or token stream to an HTML representation.
|
2277
|
+
*
|
2278
|
+
* The following hooks will be run:
|
2279
|
+
* 1. `wrap`: On each {@link Token}.
|
2280
|
+
*
|
2281
|
+
* @param {string | Token | TokenStream} o The token or token stream to be converted.
|
2282
|
+
* @param {string} language The name of current language.
|
2283
|
+
* @returns {string} The HTML representation of the token or token stream.
|
2284
|
+
* @memberof Token
|
2285
|
+
* @static
|
2286
|
+
*/
|
2287
|
+
Token.stringify = function stringify(o, language) {
|
2288
|
+
if (typeof o == 'string') {
|
2289
|
+
return o;
|
2290
|
+
}
|
2291
|
+
if (Array.isArray(o)) {
|
2292
|
+
var s = '';
|
2293
|
+
o.forEach(function (e) {
|
2294
|
+
s += stringify(e, language);
|
2295
|
+
});
|
2296
|
+
return s;
|
2297
|
+
}
|
2298
|
+
|
2299
|
+
var env = {
|
2300
|
+
type: o.type,
|
2301
|
+
content: stringify(o.content, language),
|
2302
|
+
tag: 'span',
|
2303
|
+
classes: ['token', o.type],
|
2304
|
+
attributes: {},
|
2305
|
+
language: language
|
2306
|
+
};
|
2307
|
+
|
2308
|
+
var aliases = o.alias;
|
2309
|
+
if (aliases) {
|
2310
|
+
if (Array.isArray(aliases)) {
|
2311
|
+
Array.prototype.push.apply(env.classes, aliases);
|
2312
|
+
} else {
|
2313
|
+
env.classes.push(aliases);
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
|
2317
|
+
_.hooks.run('wrap', env);
|
2318
|
+
|
2319
|
+
var attributes = '';
|
2320
|
+
for (var name in env.attributes) {
|
2321
|
+
attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
2322
|
+
}
|
2323
|
+
|
2324
|
+
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
|
2325
|
+
};
|
2326
|
+
|
2327
|
+
/**
|
2328
|
+
* @param {RegExp} pattern
|
2329
|
+
* @param {number} pos
|
2330
|
+
* @param {string} text
|
2331
|
+
* @param {boolean} lookbehind
|
2332
|
+
* @returns {RegExpExecArray | null}
|
2333
|
+
*/
|
2334
|
+
function matchPattern(pattern, pos, text, lookbehind) {
|
2335
|
+
pattern.lastIndex = pos;
|
2336
|
+
var match = pattern.exec(text);
|
2337
|
+
if (match && lookbehind && match[1]) {
|
2338
|
+
// change the match to remove the text matched by the Prism lookbehind group
|
2339
|
+
var lookbehindLength = match[1].length;
|
2340
|
+
match.index += lookbehindLength;
|
2341
|
+
match[0] = match[0].slice(lookbehindLength);
|
2342
|
+
}
|
2343
|
+
return match;
|
2344
|
+
}
|
2345
|
+
|
2346
|
+
/**
|
2347
|
+
* @param {string} text
|
2348
|
+
* @param {LinkedList<string | Token>} tokenList
|
2349
|
+
* @param {any} grammar
|
2350
|
+
* @param {LinkedListNode<string | Token>} startNode
|
2351
|
+
* @param {number} startPos
|
2352
|
+
* @param {RematchOptions} [rematch]
|
2353
|
+
* @returns {void}
|
2354
|
+
* @private
|
2355
|
+
*
|
2356
|
+
* @typedef RematchOptions
|
2357
|
+
* @property {string} cause
|
2358
|
+
* @property {number} reach
|
2359
|
+
*/
|
2360
|
+
function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
|
2361
|
+
for (var token in grammar) {
|
2362
|
+
if (!grammar.hasOwnProperty(token) || !grammar[token]) {
|
2363
|
+
continue;
|
2364
|
+
}
|
2365
|
+
|
2366
|
+
var patterns = grammar[token];
|
2367
|
+
patterns = Array.isArray(patterns) ? patterns : [patterns];
|
2368
|
+
|
2369
|
+
for (var j = 0; j < patterns.length; ++j) {
|
2370
|
+
if (rematch && rematch.cause == token + ',' + j) {
|
2371
|
+
return;
|
2372
|
+
}
|
2373
|
+
|
2374
|
+
var patternObj = patterns[j];
|
2375
|
+
var inside = patternObj.inside;
|
2376
|
+
var lookbehind = !!patternObj.lookbehind;
|
2377
|
+
var greedy = !!patternObj.greedy;
|
2378
|
+
var alias = patternObj.alias;
|
2379
|
+
|
2380
|
+
if (greedy && !patternObj.pattern.global) {
|
2381
|
+
// Without the global flag, lastIndex won't work
|
2382
|
+
var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
|
2383
|
+
patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
|
2384
|
+
}
|
2385
|
+
|
2386
|
+
/** @type {RegExp} */
|
2387
|
+
var pattern = patternObj.pattern || patternObj;
|
2388
|
+
|
2389
|
+
for ( // iterate the token list and keep track of the current token/string position
|
2390
|
+
var currentNode = startNode.next, pos = startPos;
|
2391
|
+
currentNode !== tokenList.tail;
|
2392
|
+
pos += currentNode.value.length, currentNode = currentNode.next
|
2393
|
+
) {
|
2394
|
+
|
2395
|
+
if (rematch && pos >= rematch.reach) {
|
2396
|
+
break;
|
2397
|
+
}
|
2398
|
+
|
2399
|
+
var str = currentNode.value;
|
2400
|
+
|
2401
|
+
if (tokenList.length > text.length) {
|
2402
|
+
// Something went terribly wrong, ABORT, ABORT!
|
2403
|
+
return;
|
2404
|
+
}
|
2405
|
+
|
2406
|
+
if (str instanceof Token) {
|
2407
|
+
continue;
|
2408
|
+
}
|
2409
|
+
|
2410
|
+
var removeCount = 1; // this is the to parameter of removeBetween
|
2411
|
+
var match;
|
2412
|
+
|
2413
|
+
if (greedy) {
|
2414
|
+
match = matchPattern(pattern, pos, text, lookbehind);
|
2415
|
+
if (!match || match.index >= text.length) {
|
2416
|
+
break;
|
2417
|
+
}
|
2418
|
+
|
2419
|
+
var from = match.index;
|
2420
|
+
var to = match.index + match[0].length;
|
2421
|
+
var p = pos;
|
2422
|
+
|
2423
|
+
// find the node that contains the match
|
2424
|
+
p += currentNode.value.length;
|
2425
|
+
while (from >= p) {
|
2426
|
+
currentNode = currentNode.next;
|
2427
|
+
p += currentNode.value.length;
|
2428
|
+
}
|
2429
|
+
// adjust pos (and p)
|
2430
|
+
p -= currentNode.value.length;
|
2431
|
+
pos = p;
|
2432
|
+
|
2433
|
+
// the current node is a Token, then the match starts inside another Token, which is invalid
|
2434
|
+
if (currentNode.value instanceof Token) {
|
2435
|
+
continue;
|
2436
|
+
}
|
2437
|
+
|
2438
|
+
// find the last node which is affected by this match
|
2439
|
+
for (
|
2440
|
+
var k = currentNode;
|
2441
|
+
k !== tokenList.tail && (p < to || typeof k.value === 'string');
|
2442
|
+
k = k.next
|
2443
|
+
) {
|
2444
|
+
removeCount++;
|
2445
|
+
p += k.value.length;
|
2446
|
+
}
|
2447
|
+
removeCount--;
|
2448
|
+
|
2449
|
+
// replace with the new match
|
2450
|
+
str = text.slice(pos, p);
|
2451
|
+
match.index -= pos;
|
2452
|
+
} else {
|
2453
|
+
match = matchPattern(pattern, 0, str, lookbehind);
|
2454
|
+
if (!match) {
|
2455
|
+
continue;
|
2456
|
+
}
|
2457
|
+
}
|
2458
|
+
|
2459
|
+
// eslint-disable-next-line no-redeclare
|
2460
|
+
var from = match.index;
|
2461
|
+
var matchStr = match[0];
|
2462
|
+
var before = str.slice(0, from);
|
2463
|
+
var after = str.slice(from + matchStr.length);
|
2464
|
+
|
2465
|
+
var reach = pos + str.length;
|
2466
|
+
if (rematch && reach > rematch.reach) {
|
2467
|
+
rematch.reach = reach;
|
2468
|
+
}
|
2469
|
+
|
2470
|
+
var removeFrom = currentNode.prev;
|
2471
|
+
|
2472
|
+
if (before) {
|
2473
|
+
removeFrom = addAfter(tokenList, removeFrom, before);
|
2474
|
+
pos += before.length;
|
2475
|
+
}
|
2476
|
+
|
2477
|
+
removeRange(tokenList, removeFrom, removeCount);
|
2478
|
+
|
2479
|
+
var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
|
2480
|
+
currentNode = addAfter(tokenList, removeFrom, wrapped);
|
2481
|
+
|
2482
|
+
if (after) {
|
2483
|
+
addAfter(tokenList, currentNode, after);
|
2484
|
+
}
|
2485
|
+
|
2486
|
+
if (removeCount > 1) {
|
2487
|
+
// at least one Token object was removed, so we have to do some rematching
|
2488
|
+
// this can only happen if the current pattern is greedy
|
2489
|
+
|
2490
|
+
/** @type {RematchOptions} */
|
2491
|
+
var nestedRematch = {
|
2492
|
+
cause: token + ',' + j,
|
2493
|
+
reach: reach
|
2494
|
+
};
|
2495
|
+
matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
|
2496
|
+
|
2497
|
+
// the reach might have been extended because of the rematching
|
2498
|
+
if (rematch && nestedRematch.reach > rematch.reach) {
|
2499
|
+
rematch.reach = nestedRematch.reach;
|
2500
|
+
}
|
2501
|
+
}
|
2502
|
+
}
|
2503
|
+
}
|
2504
|
+
}
|
2505
|
+
}
|
2506
|
+
|
2507
|
+
/**
|
2508
|
+
* @typedef LinkedListNode
|
2509
|
+
* @property {T} value
|
2510
|
+
* @property {LinkedListNode<T> | null} prev The previous node.
|
2511
|
+
* @property {LinkedListNode<T> | null} next The next node.
|
2512
|
+
* @template T
|
2513
|
+
* @private
|
2514
|
+
*/
|
2515
|
+
|
2516
|
+
/**
|
2517
|
+
* @template T
|
2518
|
+
* @private
|
2519
|
+
*/
|
2520
|
+
function LinkedList() {
|
2521
|
+
/** @type {LinkedListNode<T>} */
|
2522
|
+
var head = { value: null, prev: null, next: null };
|
2523
|
+
/** @type {LinkedListNode<T>} */
|
2524
|
+
var tail = { value: null, prev: head, next: null };
|
2525
|
+
head.next = tail;
|
2526
|
+
|
2527
|
+
/** @type {LinkedListNode<T>} */
|
2528
|
+
this.head = head;
|
2529
|
+
/** @type {LinkedListNode<T>} */
|
2530
|
+
this.tail = tail;
|
2531
|
+
this.length = 0;
|
2532
|
+
}
|
2533
|
+
|
2534
|
+
/**
|
2535
|
+
* Adds a new node with the given value to the list.
|
2536
|
+
*
|
2537
|
+
* @param {LinkedList<T>} list
|
2538
|
+
* @param {LinkedListNode<T>} node
|
2539
|
+
* @param {T} value
|
2540
|
+
* @returns {LinkedListNode<T>} The added node.
|
2541
|
+
* @template T
|
2542
|
+
*/
|
2543
|
+
function addAfter(list, node, value) {
|
2544
|
+
// assumes that node != list.tail && values.length >= 0
|
2545
|
+
var next = node.next;
|
2546
|
+
|
2547
|
+
var newNode = { value: value, prev: node, next: next };
|
2548
|
+
node.next = newNode;
|
2549
|
+
next.prev = newNode;
|
2550
|
+
list.length++;
|
2551
|
+
|
2552
|
+
return newNode;
|
2553
|
+
}
|
2554
|
+
/**
|
2555
|
+
* Removes `count` nodes after the given node. The given node will not be removed.
|
2556
|
+
*
|
2557
|
+
* @param {LinkedList<T>} list
|
2558
|
+
* @param {LinkedListNode<T>} node
|
2559
|
+
* @param {number} count
|
2560
|
+
* @template T
|
2561
|
+
*/
|
2562
|
+
function removeRange(list, node, count) {
|
2563
|
+
var next = node.next;
|
2564
|
+
for (var i = 0; i < count && next !== list.tail; i++) {
|
2565
|
+
next = next.next;
|
2566
|
+
}
|
2567
|
+
node.next = next;
|
2568
|
+
next.prev = node;
|
2569
|
+
list.length -= i;
|
2570
|
+
}
|
2571
|
+
/**
|
2572
|
+
* @param {LinkedList<T>} list
|
2573
|
+
* @returns {T[]}
|
2574
|
+
* @template T
|
2575
|
+
*/
|
2576
|
+
function toArray(list) {
|
2577
|
+
var array = [];
|
2578
|
+
var node = list.head.next;
|
2579
|
+
while (node !== list.tail) {
|
2580
|
+
array.push(node.value);
|
2581
|
+
node = node.next;
|
2582
|
+
}
|
2583
|
+
return array;
|
2584
|
+
}
|
2585
|
+
|
2586
|
+
|
2587
|
+
if (!_self.document) {
|
2588
|
+
if (!_self.addEventListener) {
|
2589
|
+
// in Node.js
|
2590
|
+
return _;
|
2591
|
+
}
|
2592
|
+
|
2593
|
+
if (!_.disableWorkerMessageHandler) {
|
2594
|
+
// In worker
|
2595
|
+
_self.addEventListener('message', function (evt) {
|
2596
|
+
var message = JSON.parse(evt.data);
|
2597
|
+
var lang = message.language;
|
2598
|
+
var code = message.code;
|
2599
|
+
var immediateClose = message.immediateClose;
|
2600
|
+
|
2601
|
+
_self.postMessage(_.highlight(code, _.languages[lang], lang));
|
2602
|
+
if (immediateClose) {
|
2603
|
+
_self.close();
|
2604
|
+
}
|
2605
|
+
}, false);
|
2606
|
+
}
|
2607
|
+
|
2608
|
+
return _;
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
// Get current script and highlight
|
2612
|
+
var script = _.util.currentScript();
|
2613
|
+
|
2614
|
+
if (script) {
|
2615
|
+
_.filename = script.src;
|
2616
|
+
|
2617
|
+
if (script.hasAttribute('data-manual')) {
|
2618
|
+
_.manual = true;
|
2619
|
+
}
|
2620
|
+
}
|
2621
|
+
|
2622
|
+
function highlightAutomaticallyCallback() {
|
2623
|
+
if (!_.manual) {
|
2624
|
+
_.highlightAll();
|
2625
|
+
}
|
2626
|
+
}
|
2627
|
+
|
2628
|
+
if (!_.manual) {
|
2629
|
+
// If the document state is "loading", then we'll use DOMContentLoaded.
|
2630
|
+
// If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
|
2631
|
+
// DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
|
2632
|
+
// might take longer one animation frame to execute which can create a race condition where only some plugins have
|
2633
|
+
// been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
|
2634
|
+
// See https://github.com/PrismJS/prism/issues/2102
|
2635
|
+
var readyState = document.readyState;
|
2636
|
+
if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
|
2637
|
+
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
|
2638
|
+
} else {
|
2639
|
+
if (window.requestAnimationFrame) {
|
2640
|
+
window.requestAnimationFrame(highlightAutomaticallyCallback);
|
2641
|
+
} else {
|
2642
|
+
window.setTimeout(highlightAutomaticallyCallback, 16);
|
2643
|
+
}
|
2644
|
+
}
|
2645
|
+
}
|
2646
|
+
|
2647
|
+
return _;
|
2648
|
+
|
2649
|
+
}(_self));
|
2650
|
+
|
2651
|
+
if (module.exports) {
|
2652
|
+
module.exports = Prism;
|
2653
|
+
}
|
2654
|
+
|
2655
|
+
// hack for components to work correctly in node.js
|
2656
|
+
if (typeof commonjsGlobal !== 'undefined') {
|
2657
|
+
commonjsGlobal.Prism = Prism;
|
2658
|
+
}
|
2659
|
+
|
2660
|
+
// some additional documentation/types
|
2661
|
+
|
2662
|
+
/**
|
2663
|
+
* The expansion of a simple `RegExp` literal to support additional properties.
|
2664
|
+
*
|
2665
|
+
* @typedef GrammarToken
|
2666
|
+
* @property {RegExp} pattern The regular expression of the token.
|
2667
|
+
* @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
|
2668
|
+
* behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
|
2669
|
+
* @property {boolean} [greedy=false] Whether the token is greedy.
|
2670
|
+
* @property {string|string[]} [alias] An optional alias or list of aliases.
|
2671
|
+
* @property {Grammar} [inside] The nested grammar of this token.
|
2672
|
+
*
|
2673
|
+
* The `inside` grammar will be used to tokenize the text value of each token of this kind.
|
2674
|
+
*
|
2675
|
+
* This can be used to make nested and even recursive language definitions.
|
2676
|
+
*
|
2677
|
+
* Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
|
2678
|
+
* each another.
|
2679
|
+
* @global
|
2680
|
+
* @public
|
2681
|
+
*/
|
2682
|
+
|
2683
|
+
/**
|
2684
|
+
* @typedef Grammar
|
2685
|
+
* @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
|
2686
|
+
* @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
|
2687
|
+
* @global
|
2688
|
+
* @public
|
2689
|
+
*/
|
2690
|
+
|
2691
|
+
/**
|
2692
|
+
* A function which will invoked after an element was successfully highlighted.
|
2693
|
+
*
|
2694
|
+
* @callback HighlightCallback
|
2695
|
+
* @param {Element} element The element successfully highlighted.
|
2696
|
+
* @returns {void}
|
2697
|
+
* @global
|
2698
|
+
* @public
|
2699
|
+
*/
|
2700
|
+
|
2701
|
+
/**
|
2702
|
+
* @callback HookCallback
|
2703
|
+
* @param {Object<string, any>} env The environment variables of the hook.
|
2704
|
+
* @returns {void}
|
2705
|
+
* @global
|
2706
|
+
* @public
|
2707
|
+
*/
|
2708
|
+
|
2709
|
+
|
2710
|
+
/* **********************************************
|
2711
|
+
Begin prism-markup.js
|
2712
|
+
********************************************** */
|
2713
|
+
|
2714
|
+
Prism.languages.markup = {
|
2715
|
+
'comment': {
|
2716
|
+
pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
|
2717
|
+
greedy: true
|
2718
|
+
},
|
2719
|
+
'prolog': {
|
2720
|
+
pattern: /<\?[\s\S]+?\?>/,
|
2721
|
+
greedy: true
|
2722
|
+
},
|
2723
|
+
'doctype': {
|
2724
|
+
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
2725
|
+
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
2726
|
+
greedy: true,
|
2727
|
+
inside: {
|
2728
|
+
'internal-subset': {
|
2729
|
+
pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
|
2730
|
+
lookbehind: true,
|
2731
|
+
greedy: true,
|
2732
|
+
inside: null // see below
|
2733
|
+
},
|
2734
|
+
'string': {
|
2735
|
+
pattern: /"[^"]*"|'[^']*'/,
|
2736
|
+
greedy: true
|
2737
|
+
},
|
2738
|
+
'punctuation': /^<!|>$|[[\]]/,
|
2739
|
+
'doctype-tag': /^DOCTYPE/i,
|
2740
|
+
'name': /[^\s<>'"]+/
|
2741
|
+
}
|
2742
|
+
},
|
2743
|
+
'cdata': {
|
2744
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
2745
|
+
greedy: true
|
2746
|
+
},
|
2747
|
+
'tag': {
|
2748
|
+
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
2749
|
+
greedy: true,
|
2750
|
+
inside: {
|
2751
|
+
'tag': {
|
2752
|
+
pattern: /^<\/?[^\s>\/]+/,
|
2753
|
+
inside: {
|
2754
|
+
'punctuation': /^<\/?/,
|
2755
|
+
'namespace': /^[^\s>\/:]+:/
|
2756
|
+
}
|
2757
|
+
},
|
2758
|
+
'special-attr': [],
|
2759
|
+
'attr-value': {
|
2760
|
+
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
2761
|
+
inside: {
|
2762
|
+
'punctuation': [
|
2763
|
+
{
|
2764
|
+
pattern: /^=/,
|
2765
|
+
alias: 'attr-equals'
|
2766
|
+
},
|
2767
|
+
{
|
2768
|
+
pattern: /^(\s*)["']|["']$/,
|
2769
|
+
lookbehind: true
|
2770
|
+
}
|
2771
|
+
]
|
2772
|
+
}
|
2773
|
+
},
|
2774
|
+
'punctuation': /\/?>/,
|
2775
|
+
'attr-name': {
|
2776
|
+
pattern: /[^\s>\/]+/,
|
2777
|
+
inside: {
|
2778
|
+
'namespace': /^[^\s>\/:]+:/
|
2779
|
+
}
|
2780
|
+
}
|
2781
|
+
|
2782
|
+
}
|
2783
|
+
},
|
2784
|
+
'entity': [
|
2785
|
+
{
|
2786
|
+
pattern: /&[\da-z]{1,8};/i,
|
2787
|
+
alias: 'named-entity'
|
2788
|
+
},
|
2789
|
+
/&#x?[\da-f]{1,8};/i
|
2790
|
+
]
|
2791
|
+
};
|
2792
|
+
|
2793
|
+
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
2794
|
+
Prism.languages.markup['entity'];
|
2795
|
+
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
|
2796
|
+
|
2797
|
+
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
2798
|
+
Prism.hooks.add('wrap', function (env) {
|
2799
|
+
|
2800
|
+
if (env.type === 'entity') {
|
2801
|
+
env.attributes['title'] = env.content.replace(/&/, '&');
|
2802
|
+
}
|
2803
|
+
});
|
2804
|
+
|
2805
|
+
Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
|
2806
|
+
/**
|
2807
|
+
* Adds an inlined language to markup.
|
2808
|
+
*
|
2809
|
+
* An example of an inlined language is CSS with `<style>` tags.
|
2810
|
+
*
|
2811
|
+
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
2812
|
+
* case insensitive.
|
2813
|
+
* @param {string} lang The language key.
|
2814
|
+
* @example
|
2815
|
+
* addInlined('style', 'css');
|
2816
|
+
*/
|
2817
|
+
value: function addInlined(tagName, lang) {
|
2818
|
+
var includedCdataInside = {};
|
2819
|
+
includedCdataInside['language-' + lang] = {
|
2820
|
+
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
2821
|
+
lookbehind: true,
|
2822
|
+
inside: Prism.languages[lang]
|
2823
|
+
};
|
2824
|
+
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
|
2825
|
+
|
2826
|
+
var inside = {
|
2827
|
+
'included-cdata': {
|
2828
|
+
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
2829
|
+
inside: includedCdataInside
|
2830
|
+
}
|
2831
|
+
};
|
2832
|
+
inside['language-' + lang] = {
|
2833
|
+
pattern: /[\s\S]+/,
|
2834
|
+
inside: Prism.languages[lang]
|
2835
|
+
};
|
2836
|
+
|
2837
|
+
var def = {};
|
2838
|
+
def[tagName] = {
|
2839
|
+
pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
|
2840
|
+
lookbehind: true,
|
2841
|
+
greedy: true,
|
2842
|
+
inside: inside
|
2843
|
+
};
|
2844
|
+
|
2845
|
+
Prism.languages.insertBefore('markup', 'cdata', def);
|
2846
|
+
}
|
2847
|
+
});
|
2848
|
+
Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
|
2849
|
+
/**
|
2850
|
+
* Adds an pattern to highlight languages embedded in HTML attributes.
|
2851
|
+
*
|
2852
|
+
* An example of an inlined language is CSS with `style` attributes.
|
2853
|
+
*
|
2854
|
+
* @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
|
2855
|
+
* case insensitive.
|
2856
|
+
* @param {string} lang The language key.
|
2857
|
+
* @example
|
2858
|
+
* addAttribute('style', 'css');
|
2859
|
+
*/
|
2860
|
+
value: function (attrName, lang) {
|
2861
|
+
Prism.languages.markup.tag.inside['special-attr'].push({
|
2862
|
+
pattern: RegExp(
|
2863
|
+
/(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
|
2864
|
+
'i'
|
2865
|
+
),
|
2866
|
+
lookbehind: true,
|
2867
|
+
inside: {
|
2868
|
+
'attr-name': /^[^\s=]+/,
|
2869
|
+
'attr-value': {
|
2870
|
+
pattern: /=[\s\S]+/,
|
2871
|
+
inside: {
|
2872
|
+
'value': {
|
2873
|
+
pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
|
2874
|
+
lookbehind: true,
|
2875
|
+
alias: [lang, 'language-' + lang],
|
2876
|
+
inside: Prism.languages[lang]
|
2877
|
+
},
|
2878
|
+
'punctuation': [
|
2879
|
+
{
|
2880
|
+
pattern: /^=/,
|
2881
|
+
alias: 'attr-equals'
|
2882
|
+
},
|
2883
|
+
/"|'/
|
2884
|
+
]
|
2885
|
+
}
|
2886
|
+
}
|
2887
|
+
}
|
2888
|
+
});
|
2889
|
+
}
|
2890
|
+
});
|
2891
|
+
|
2892
|
+
Prism.languages.html = Prism.languages.markup;
|
2893
|
+
Prism.languages.mathml = Prism.languages.markup;
|
2894
|
+
Prism.languages.svg = Prism.languages.markup;
|
2895
|
+
|
2896
|
+
Prism.languages.xml = Prism.languages.extend('markup', {});
|
2897
|
+
Prism.languages.ssml = Prism.languages.xml;
|
2898
|
+
Prism.languages.atom = Prism.languages.xml;
|
2899
|
+
Prism.languages.rss = Prism.languages.xml;
|
2900
|
+
|
2901
|
+
|
2902
|
+
/* **********************************************
|
2903
|
+
Begin prism-css.js
|
2904
|
+
********************************************** */
|
2905
|
+
|
2906
|
+
(function (Prism) {
|
2907
|
+
|
2908
|
+
var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
|
2909
|
+
|
2910
|
+
Prism.languages.css = {
|
2911
|
+
'comment': /\/\*[\s\S]*?\*\//,
|
2912
|
+
'atrule': {
|
2913
|
+
pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
|
2914
|
+
inside: {
|
2915
|
+
'rule': /^@[\w-]+/,
|
2916
|
+
'selector-function-argument': {
|
2917
|
+
pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
|
2918
|
+
lookbehind: true,
|
2919
|
+
alias: 'selector'
|
2920
|
+
},
|
2921
|
+
'keyword': {
|
2922
|
+
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
|
2923
|
+
lookbehind: true
|
2924
|
+
}
|
2925
|
+
// See rest below
|
2926
|
+
}
|
2927
|
+
},
|
2928
|
+
'url': {
|
2929
|
+
// https://drafts.csswg.org/css-values-3/#urls
|
2930
|
+
pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
|
2931
|
+
greedy: true,
|
2932
|
+
inside: {
|
2933
|
+
'function': /^url/i,
|
2934
|
+
'punctuation': /^\(|\)$/,
|
2935
|
+
'string': {
|
2936
|
+
pattern: RegExp('^' + string.source + '$'),
|
2937
|
+
alias: 'url'
|
2938
|
+
}
|
2939
|
+
}
|
2940
|
+
},
|
2941
|
+
'selector': {
|
2942
|
+
pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
|
2943
|
+
lookbehind: true
|
2944
|
+
},
|
2945
|
+
'string': {
|
2946
|
+
pattern: string,
|
2947
|
+
greedy: true
|
2948
|
+
},
|
2949
|
+
'property': {
|
2950
|
+
pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
|
2951
|
+
lookbehind: true
|
2952
|
+
},
|
2953
|
+
'important': /!important\b/i,
|
2954
|
+
'function': {
|
2955
|
+
pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
|
2956
|
+
lookbehind: true
|
2957
|
+
},
|
2958
|
+
'punctuation': /[(){};:,]/
|
2959
|
+
};
|
2960
|
+
|
2961
|
+
Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
|
2962
|
+
|
2963
|
+
var markup = Prism.languages.markup;
|
2964
|
+
if (markup) {
|
2965
|
+
markup.tag.addInlined('style', 'css');
|
2966
|
+
markup.tag.addAttribute('style', 'css');
|
2967
|
+
}
|
2968
|
+
|
2969
|
+
}(Prism));
|
2970
|
+
|
2971
|
+
|
2972
|
+
/* **********************************************
|
2973
|
+
Begin prism-clike.js
|
2974
|
+
********************************************** */
|
2975
|
+
|
2976
|
+
Prism.languages.clike = {
|
2977
|
+
'comment': [
|
2978
|
+
{
|
2979
|
+
pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
|
2980
|
+
lookbehind: true,
|
2981
|
+
greedy: true
|
2982
|
+
},
|
2983
|
+
{
|
2984
|
+
pattern: /(^|[^\\:])\/\/.*/,
|
2985
|
+
lookbehind: true,
|
2986
|
+
greedy: true
|
2987
|
+
}
|
2988
|
+
],
|
2989
|
+
'string': {
|
2990
|
+
pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
2991
|
+
greedy: true
|
2992
|
+
},
|
2993
|
+
'class-name': {
|
2994
|
+
pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
|
2995
|
+
lookbehind: true,
|
2996
|
+
inside: {
|
2997
|
+
'punctuation': /[.\\]/
|
2998
|
+
}
|
2999
|
+
},
|
3000
|
+
'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
|
3001
|
+
'boolean': /\b(?:false|true)\b/,
|
3002
|
+
'function': /\b\w+(?=\()/,
|
3003
|
+
'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
|
3004
|
+
'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
|
3005
|
+
'punctuation': /[{}[\];(),.:]/
|
3006
|
+
};
|
3007
|
+
|
3008
|
+
|
3009
|
+
/* **********************************************
|
3010
|
+
Begin prism-javascript.js
|
3011
|
+
********************************************** */
|
3012
|
+
|
3013
|
+
Prism.languages.javascript = Prism.languages.extend('clike', {
|
3014
|
+
'class-name': [
|
3015
|
+
Prism.languages.clike['class-name'],
|
3016
|
+
{
|
3017
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
|
3018
|
+
lookbehind: true
|
3019
|
+
}
|
3020
|
+
],
|
3021
|
+
'keyword': [
|
3022
|
+
{
|
3023
|
+
pattern: /((?:^|\})\s*)catch\b/,
|
3024
|
+
lookbehind: true
|
3025
|
+
},
|
3026
|
+
{
|
3027
|
+
pattern: /(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,
|
3028
|
+
lookbehind: true
|
3029
|
+
},
|
3030
|
+
],
|
3031
|
+
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
3032
|
+
'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
|
3033
|
+
'number': {
|
3034
|
+
pattern: RegExp(
|
3035
|
+
/(^|[^\w$])/.source +
|
3036
|
+
'(?:' +
|
3037
|
+
(
|
3038
|
+
// constant
|
3039
|
+
/NaN|Infinity/.source +
|
3040
|
+
'|' +
|
3041
|
+
// binary integer
|
3042
|
+
/0[bB][01]+(?:_[01]+)*n?/.source +
|
3043
|
+
'|' +
|
3044
|
+
// octal integer
|
3045
|
+
/0[oO][0-7]+(?:_[0-7]+)*n?/.source +
|
3046
|
+
'|' +
|
3047
|
+
// hexadecimal integer
|
3048
|
+
/0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
|
3049
|
+
'|' +
|
3050
|
+
// decimal bigint
|
3051
|
+
/\d+(?:_\d+)*n/.source +
|
3052
|
+
'|' +
|
3053
|
+
// decimal number (integer or float) but no bigint
|
3054
|
+
/(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
|
3055
|
+
) +
|
3056
|
+
')' +
|
3057
|
+
/(?![\w$])/.source
|
3058
|
+
),
|
3059
|
+
lookbehind: true
|
3060
|
+
},
|
3061
|
+
'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
|
3062
|
+
});
|
3063
|
+
|
3064
|
+
Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
|
3065
|
+
|
3066
|
+
Prism.languages.insertBefore('javascript', 'keyword', {
|
3067
|
+
'regex': {
|
3068
|
+
pattern: RegExp(
|
3069
|
+
// lookbehind
|
3070
|
+
// eslint-disable-next-line regexp/no-dupe-characters-character-class
|
3071
|
+
/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
|
3072
|
+
// Regex pattern:
|
3073
|
+
// There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
|
3074
|
+
// classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
|
3075
|
+
// with the only syntax, so we have to define 2 different regex patterns.
|
3076
|
+
/\//.source +
|
3077
|
+
'(?:' +
|
3078
|
+
/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
|
3079
|
+
'|' +
|
3080
|
+
// `v` flag syntax. This supports 3 levels of nested character classes.
|
3081
|
+
/(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
|
3082
|
+
')' +
|
3083
|
+
// lookahead
|
3084
|
+
/(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
|
3085
|
+
),
|
3086
|
+
lookbehind: true,
|
3087
|
+
greedy: true,
|
3088
|
+
inside: {
|
3089
|
+
'regex-source': {
|
3090
|
+
pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
|
3091
|
+
lookbehind: true,
|
3092
|
+
alias: 'language-regex',
|
3093
|
+
inside: Prism.languages.regex
|
3094
|
+
},
|
3095
|
+
'regex-delimiter': /^\/|\/$/,
|
3096
|
+
'regex-flags': /^[a-z]+$/,
|
3097
|
+
}
|
3098
|
+
},
|
3099
|
+
// This must be declared before keyword because we use "function" inside the look-forward
|
3100
|
+
'function-variable': {
|
3101
|
+
pattern: /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,
|
3102
|
+
alias: 'function'
|
3103
|
+
},
|
3104
|
+
'parameter': [
|
3105
|
+
{
|
3106
|
+
pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
|
3107
|
+
lookbehind: true,
|
3108
|
+
inside: Prism.languages.javascript
|
3109
|
+
},
|
3110
|
+
{
|
3111
|
+
pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
|
3112
|
+
lookbehind: true,
|
3113
|
+
inside: Prism.languages.javascript
|
3114
|
+
},
|
3115
|
+
{
|
3116
|
+
pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
|
3117
|
+
lookbehind: true,
|
3118
|
+
inside: Prism.languages.javascript
|
3119
|
+
},
|
3120
|
+
{
|
3121
|
+
pattern: /((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,
|
3122
|
+
lookbehind: true,
|
3123
|
+
inside: Prism.languages.javascript
|
3124
|
+
}
|
3125
|
+
],
|
3126
|
+
'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
|
3127
|
+
});
|
3128
|
+
|
3129
|
+
Prism.languages.insertBefore('javascript', 'string', {
|
3130
|
+
'hashbang': {
|
3131
|
+
pattern: /^#!.*/,
|
3132
|
+
greedy: true,
|
3133
|
+
alias: 'comment'
|
3134
|
+
},
|
3135
|
+
'template-string': {
|
3136
|
+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
|
3137
|
+
greedy: true,
|
3138
|
+
inside: {
|
3139
|
+
'template-punctuation': {
|
3140
|
+
pattern: /^`|`$/,
|
3141
|
+
alias: 'string'
|
3142
|
+
},
|
3143
|
+
'interpolation': {
|
3144
|
+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
|
3145
|
+
lookbehind: true,
|
3146
|
+
inside: {
|
3147
|
+
'interpolation-punctuation': {
|
3148
|
+
pattern: /^\$\{|\}$/,
|
3149
|
+
alias: 'punctuation'
|
3150
|
+
},
|
3151
|
+
rest: Prism.languages.javascript
|
3152
|
+
}
|
3153
|
+
},
|
3154
|
+
'string': /[\s\S]+/
|
3155
|
+
}
|
3156
|
+
},
|
3157
|
+
'string-property': {
|
3158
|
+
pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
|
3159
|
+
lookbehind: true,
|
3160
|
+
greedy: true,
|
3161
|
+
alias: 'property'
|
3162
|
+
}
|
3163
|
+
});
|
3164
|
+
|
3165
|
+
Prism.languages.insertBefore('javascript', 'operator', {
|
3166
|
+
'literal-property': {
|
3167
|
+
pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
|
3168
|
+
lookbehind: true,
|
3169
|
+
alias: 'property'
|
3170
|
+
},
|
3171
|
+
});
|
3172
|
+
|
3173
|
+
if (Prism.languages.markup) {
|
3174
|
+
Prism.languages.markup.tag.addInlined('script', 'javascript');
|
3175
|
+
|
3176
|
+
// add attribute support for all DOM events.
|
3177
|
+
// https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
|
3178
|
+
Prism.languages.markup.tag.addAttribute(
|
3179
|
+
/on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)/.source,
|
3180
|
+
'javascript'
|
3181
|
+
);
|
3182
|
+
}
|
3183
|
+
|
3184
|
+
Prism.languages.js = Prism.languages.javascript;
|
3185
|
+
|
3186
|
+
|
3187
|
+
/* **********************************************
|
3188
|
+
Begin prism-file-highlight.js
|
3189
|
+
********************************************** */
|
3190
|
+
|
3191
|
+
(function () {
|
3192
|
+
|
3193
|
+
if (typeof Prism === 'undefined' || typeof document === 'undefined') {
|
3194
|
+
return;
|
3195
|
+
}
|
3196
|
+
|
3197
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
|
3198
|
+
if (!Element.prototype.matches) {
|
3199
|
+
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
3200
|
+
}
|
3201
|
+
|
3202
|
+
var LOADING_MESSAGE = 'Loading…';
|
3203
|
+
var FAILURE_MESSAGE = function (status, message) {
|
3204
|
+
return '✖ Error ' + status + ' while fetching file: ' + message;
|
3205
|
+
};
|
3206
|
+
var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
|
3207
|
+
|
3208
|
+
var EXTENSIONS = {
|
3209
|
+
'js': 'javascript',
|
3210
|
+
'py': 'python',
|
3211
|
+
'rb': 'ruby',
|
3212
|
+
'ps1': 'powershell',
|
3213
|
+
'psm1': 'powershell',
|
3214
|
+
'sh': 'bash',
|
3215
|
+
'bat': 'batch',
|
3216
|
+
'h': 'c',
|
3217
|
+
'tex': 'latex'
|
3218
|
+
};
|
3219
|
+
|
3220
|
+
var STATUS_ATTR = 'data-src-status';
|
3221
|
+
var STATUS_LOADING = 'loading';
|
3222
|
+
var STATUS_LOADED = 'loaded';
|
3223
|
+
var STATUS_FAILED = 'failed';
|
3224
|
+
|
3225
|
+
var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
|
3226
|
+
+ ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
|
3227
|
+
|
3228
|
+
/**
|
3229
|
+
* Loads the given file.
|
3230
|
+
*
|
3231
|
+
* @param {string} src The URL or path of the source file to load.
|
3232
|
+
* @param {(result: string) => void} success
|
3233
|
+
* @param {(reason: string) => void} error
|
3234
|
+
*/
|
3235
|
+
function loadFile(src, success, error) {
|
3236
|
+
var xhr = new XMLHttpRequest();
|
3237
|
+
xhr.open('GET', src, true);
|
3238
|
+
xhr.onreadystatechange = function () {
|
3239
|
+
if (xhr.readyState == 4) {
|
3240
|
+
if (xhr.status < 400 && xhr.responseText) {
|
3241
|
+
success(xhr.responseText);
|
3242
|
+
} else {
|
3243
|
+
if (xhr.status >= 400) {
|
3244
|
+
error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
|
3245
|
+
} else {
|
3246
|
+
error(FAILURE_EMPTY_MESSAGE);
|
3247
|
+
}
|
3248
|
+
}
|
3249
|
+
}
|
3250
|
+
};
|
3251
|
+
xhr.send(null);
|
3252
|
+
}
|
3253
|
+
|
3254
|
+
/**
|
3255
|
+
* Parses the given range.
|
3256
|
+
*
|
3257
|
+
* This returns a range with inclusive ends.
|
3258
|
+
*
|
3259
|
+
* @param {string | null | undefined} range
|
3260
|
+
* @returns {[number, number | undefined] | undefined}
|
3261
|
+
*/
|
3262
|
+
function parseRange(range) {
|
3263
|
+
var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
|
3264
|
+
if (m) {
|
3265
|
+
var start = Number(m[1]);
|
3266
|
+
var comma = m[2];
|
3267
|
+
var end = m[3];
|
3268
|
+
|
3269
|
+
if (!comma) {
|
3270
|
+
return [start, start];
|
3271
|
+
}
|
3272
|
+
if (!end) {
|
3273
|
+
return [start, undefined];
|
3274
|
+
}
|
3275
|
+
return [start, Number(end)];
|
3276
|
+
}
|
3277
|
+
return undefined;
|
3278
|
+
}
|
3279
|
+
|
3280
|
+
Prism.hooks.add('before-highlightall', function (env) {
|
3281
|
+
env.selector += ', ' + SELECTOR;
|
3282
|
+
});
|
3283
|
+
|
3284
|
+
Prism.hooks.add('before-sanity-check', function (env) {
|
3285
|
+
var pre = /** @type {HTMLPreElement} */ (env.element);
|
3286
|
+
if (pre.matches(SELECTOR)) {
|
3287
|
+
env.code = ''; // fast-path the whole thing and go to complete
|
3288
|
+
|
3289
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
|
3290
|
+
|
3291
|
+
// add code element with loading message
|
3292
|
+
var code = pre.appendChild(document.createElement('CODE'));
|
3293
|
+
code.textContent = LOADING_MESSAGE;
|
3294
|
+
|
3295
|
+
var src = pre.getAttribute('data-src');
|
3296
|
+
|
3297
|
+
var language = env.language;
|
3298
|
+
if (language === 'none') {
|
3299
|
+
// the language might be 'none' because there is no language set;
|
3300
|
+
// in this case, we want to use the extension as the language
|
3301
|
+
var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
|
3302
|
+
language = EXTENSIONS[extension] || extension;
|
3303
|
+
}
|
3304
|
+
|
3305
|
+
// set language classes
|
3306
|
+
Prism.util.setLanguage(code, language);
|
3307
|
+
Prism.util.setLanguage(pre, language);
|
3308
|
+
|
3309
|
+
// preload the language
|
3310
|
+
var autoloader = Prism.plugins.autoloader;
|
3311
|
+
if (autoloader) {
|
3312
|
+
autoloader.loadLanguages(language);
|
3313
|
+
}
|
3314
|
+
|
3315
|
+
// load file
|
3316
|
+
loadFile(
|
3317
|
+
src,
|
3318
|
+
function (text) {
|
3319
|
+
// mark as loaded
|
3320
|
+
pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
|
3321
|
+
|
3322
|
+
// handle data-range
|
3323
|
+
var range = parseRange(pre.getAttribute('data-range'));
|
3324
|
+
if (range) {
|
3325
|
+
var lines = text.split(/\r\n?|\n/g);
|
3326
|
+
|
3327
|
+
// the range is one-based and inclusive on both ends
|
3328
|
+
var start = range[0];
|
3329
|
+
var end = range[1] == null ? lines.length : range[1];
|
3330
|
+
|
3331
|
+
if (start < 0) { start += lines.length; }
|
3332
|
+
start = Math.max(0, Math.min(start - 1, lines.length));
|
3333
|
+
if (end < 0) { end += lines.length; }
|
3334
|
+
end = Math.max(0, Math.min(end, lines.length));
|
3335
|
+
|
3336
|
+
text = lines.slice(start, end).join('\n');
|
3337
|
+
|
3338
|
+
// add data-start for line numbers
|
3339
|
+
if (!pre.hasAttribute('data-start')) {
|
3340
|
+
pre.setAttribute('data-start', String(start + 1));
|
3341
|
+
}
|
3342
|
+
}
|
3343
|
+
|
3344
|
+
// highlight code
|
3345
|
+
code.textContent = text;
|
3346
|
+
Prism.highlightElement(code);
|
3347
|
+
},
|
3348
|
+
function (error) {
|
3349
|
+
// mark as failed
|
3350
|
+
pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
|
3351
|
+
|
3352
|
+
code.textContent = error;
|
3353
|
+
}
|
3354
|
+
);
|
3355
|
+
}
|
3356
|
+
});
|
3357
|
+
|
3358
|
+
Prism.plugins.fileHighlight = {
|
3359
|
+
/**
|
3360
|
+
* Executes the File Highlight plugin for all matching `pre` elements under the given container.
|
3361
|
+
*
|
3362
|
+
* Note: Elements which are already loaded or currently loading will not be touched by this method.
|
3363
|
+
*
|
3364
|
+
* @param {ParentNode} [container=document]
|
3365
|
+
*/
|
3366
|
+
highlight: function highlight(container) {
|
3367
|
+
var elements = (container || document).querySelectorAll(SELECTOR);
|
3368
|
+
|
3369
|
+
for (var i = 0, element; (element = elements[i++]);) {
|
3370
|
+
Prism.highlightElement(element);
|
3371
|
+
}
|
3372
|
+
}
|
3373
|
+
};
|
3374
|
+
|
3375
|
+
var logged = false;
|
3376
|
+
/** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
|
3377
|
+
Prism.fileHighlight = function () {
|
3378
|
+
if (!logged) {
|
3379
|
+
console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
|
3380
|
+
logged = true;
|
3381
|
+
}
|
3382
|
+
Prism.plugins.fileHighlight.highlight.apply(this, arguments);
|
3383
|
+
};
|
3384
|
+
|
3385
|
+
}());
|
3386
|
+
} (prism));
|
3387
|
+
|
3388
|
+
var prismExports = prism.exports;
|
3389
|
+
var Prism$1 = /*@__PURE__*/getDefaultExportFromCjs(prismExports);
|
3390
|
+
|
3391
|
+
(function (Prism) {
|
3392
|
+
|
3393
|
+
// Allow only one line break
|
3394
|
+
var inner = /(?:\\.|[^\\\n\r]|(?:\n|\r\n?)(?![\r\n]))/.source;
|
3395
|
+
|
3396
|
+
/**
|
3397
|
+
* This function is intended for the creation of the bold or italic pattern.
|
3398
|
+
*
|
3399
|
+
* This also adds a lookbehind group to the given pattern to ensure that the pattern is not backslash-escaped.
|
3400
|
+
*
|
3401
|
+
* _Note:_ Keep in mind that this adds a capturing group.
|
3402
|
+
*
|
3403
|
+
* @param {string} pattern
|
3404
|
+
* @returns {RegExp}
|
3405
|
+
*/
|
3406
|
+
function createInline(pattern) {
|
3407
|
+
pattern = pattern.replace(/<inner>/g, function () { return inner; });
|
3408
|
+
return RegExp(/((?:^|[^\\])(?:\\{2})*)/.source + '(?:' + pattern + ')');
|
3409
|
+
}
|
3410
|
+
|
3411
|
+
|
3412
|
+
var tableCell = /(?:\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\|\r\n`])+/.source;
|
3413
|
+
var tableRow = /\|?__(?:\|__)+\|?(?:(?:\n|\r\n?)|(?![\s\S]))/.source.replace(/__/g, function () { return tableCell; });
|
3414
|
+
var tableLine = /\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)+\|?(?:\n|\r\n?)/.source;
|
3415
|
+
|
3416
|
+
|
3417
|
+
Prism.languages.markdown = Prism.languages.extend('markup', {});
|
3418
|
+
Prism.languages.insertBefore('markdown', 'prolog', {
|
3419
|
+
'front-matter-block': {
|
3420
|
+
pattern: /(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,
|
3421
|
+
lookbehind: true,
|
3422
|
+
greedy: true,
|
3423
|
+
inside: {
|
3424
|
+
'punctuation': /^---|---$/,
|
3425
|
+
'front-matter': {
|
3426
|
+
pattern: /\S+(?:\s+\S+)*/,
|
3427
|
+
alias: ['yaml', 'language-yaml'],
|
3428
|
+
inside: Prism.languages.yaml
|
3429
|
+
}
|
3430
|
+
}
|
3431
|
+
},
|
3432
|
+
'blockquote': {
|
3433
|
+
// > ...
|
3434
|
+
pattern: /^>(?:[\t ]*>)*/m,
|
3435
|
+
alias: 'punctuation'
|
3436
|
+
},
|
3437
|
+
'table': {
|
3438
|
+
pattern: RegExp('^' + tableRow + tableLine + '(?:' + tableRow + ')*', 'm'),
|
3439
|
+
inside: {
|
3440
|
+
'table-data-rows': {
|
3441
|
+
pattern: RegExp('^(' + tableRow + tableLine + ')(?:' + tableRow + ')*$'),
|
3442
|
+
lookbehind: true,
|
3443
|
+
inside: {
|
3444
|
+
'table-data': {
|
3445
|
+
pattern: RegExp(tableCell),
|
3446
|
+
inside: Prism.languages.markdown
|
3447
|
+
},
|
3448
|
+
'punctuation': /\|/
|
3449
|
+
}
|
3450
|
+
},
|
3451
|
+
'table-line': {
|
3452
|
+
pattern: RegExp('^(' + tableRow + ')' + tableLine + '$'),
|
3453
|
+
lookbehind: true,
|
3454
|
+
inside: {
|
3455
|
+
'punctuation': /\||:?-{3,}:?/
|
3456
|
+
}
|
3457
|
+
},
|
3458
|
+
'table-header-row': {
|
3459
|
+
pattern: RegExp('^' + tableRow + '$'),
|
3460
|
+
inside: {
|
3461
|
+
'table-header': {
|
3462
|
+
pattern: RegExp(tableCell),
|
3463
|
+
alias: 'important',
|
3464
|
+
inside: Prism.languages.markdown
|
3465
|
+
},
|
3466
|
+
'punctuation': /\|/
|
3467
|
+
}
|
3468
|
+
}
|
3469
|
+
}
|
3470
|
+
},
|
3471
|
+
'code': [
|
3472
|
+
{
|
3473
|
+
// Prefixed by 4 spaces or 1 tab and preceded by an empty line
|
3474
|
+
pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,
|
3475
|
+
lookbehind: true,
|
3476
|
+
alias: 'keyword'
|
3477
|
+
},
|
3478
|
+
{
|
3479
|
+
// ```optional language
|
3480
|
+
// code block
|
3481
|
+
// ```
|
3482
|
+
pattern: /^```[\s\S]*?^```$/m,
|
3483
|
+
greedy: true,
|
3484
|
+
inside: {
|
3485
|
+
'code-block': {
|
3486
|
+
pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,
|
3487
|
+
lookbehind: true
|
3488
|
+
},
|
3489
|
+
'code-language': {
|
3490
|
+
pattern: /^(```).+/,
|
3491
|
+
lookbehind: true
|
3492
|
+
},
|
3493
|
+
'punctuation': /```/
|
3494
|
+
}
|
3495
|
+
}
|
3496
|
+
],
|
3497
|
+
'title': [
|
3498
|
+
{
|
3499
|
+
// title 1
|
3500
|
+
// =======
|
3501
|
+
|
3502
|
+
// title 2
|
3503
|
+
// -------
|
3504
|
+
pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,
|
3505
|
+
alias: 'important',
|
3506
|
+
inside: {
|
3507
|
+
punctuation: /==+$|--+$/
|
3508
|
+
}
|
3509
|
+
},
|
3510
|
+
{
|
3511
|
+
// # title 1
|
3512
|
+
// ###### title 6
|
3513
|
+
pattern: /(^\s*)#.+/m,
|
3514
|
+
lookbehind: true,
|
3515
|
+
alias: 'important',
|
3516
|
+
inside: {
|
3517
|
+
punctuation: /^#+|#+$/
|
3518
|
+
}
|
3519
|
+
}
|
3520
|
+
],
|
3521
|
+
'hr': {
|
3522
|
+
// ***
|
3523
|
+
// ---
|
3524
|
+
// * * *
|
3525
|
+
// -----------
|
3526
|
+
pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,
|
3527
|
+
lookbehind: true,
|
3528
|
+
alias: 'punctuation'
|
3529
|
+
},
|
3530
|
+
'list': {
|
3531
|
+
// * item
|
3532
|
+
// + item
|
3533
|
+
// - item
|
3534
|
+
// 1. item
|
3535
|
+
pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,
|
3536
|
+
lookbehind: true,
|
3537
|
+
alias: 'punctuation'
|
3538
|
+
},
|
3539
|
+
'url-reference': {
|
3540
|
+
// [id]: http://example.com "Optional title"
|
3541
|
+
// [id]: http://example.com 'Optional title'
|
3542
|
+
// [id]: http://example.com (Optional title)
|
3543
|
+
// [id]: <http://example.com> "Optional title"
|
3544
|
+
pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,
|
3545
|
+
inside: {
|
3546
|
+
'variable': {
|
3547
|
+
pattern: /^(!?\[)[^\]]+/,
|
3548
|
+
lookbehind: true
|
3549
|
+
},
|
3550
|
+
'string': /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,
|
3551
|
+
'punctuation': /^[\[\]!:]|[<>]/
|
3552
|
+
},
|
3553
|
+
alias: 'url'
|
3554
|
+
},
|
3555
|
+
'bold': {
|
3556
|
+
// **strong**
|
3557
|
+
// __strong__
|
3558
|
+
|
3559
|
+
// allow one nested instance of italic text using the same delimiter
|
3560
|
+
pattern: createInline(/\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\b|\*\*(?:(?!\*)<inner>|\*(?:(?!\*)<inner>)+\*)+\*\*/.source),
|
3561
|
+
lookbehind: true,
|
3562
|
+
greedy: true,
|
3563
|
+
inside: {
|
3564
|
+
'content': {
|
3565
|
+
pattern: /(^..)[\s\S]+(?=..$)/,
|
3566
|
+
lookbehind: true,
|
3567
|
+
inside: {} // see below
|
3568
|
+
},
|
3569
|
+
'punctuation': /\*\*|__/
|
3570
|
+
}
|
3571
|
+
},
|
3572
|
+
'italic': {
|
3573
|
+
// *em*
|
3574
|
+
// _em_
|
3575
|
+
|
3576
|
+
// allow one nested instance of bold text using the same delimiter
|
3577
|
+
pattern: createInline(/\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\b|\*(?:(?!\*)<inner>|\*\*(?:(?!\*)<inner>)+\*\*)+\*/.source),
|
3578
|
+
lookbehind: true,
|
3579
|
+
greedy: true,
|
3580
|
+
inside: {
|
3581
|
+
'content': {
|
3582
|
+
pattern: /(^.)[\s\S]+(?=.$)/,
|
3583
|
+
lookbehind: true,
|
3584
|
+
inside: {} // see below
|
3585
|
+
},
|
3586
|
+
'punctuation': /[*_]/
|
3587
|
+
}
|
3588
|
+
},
|
3589
|
+
'strike': {
|
3590
|
+
// ~~strike through~~
|
3591
|
+
// ~strike~
|
3592
|
+
// eslint-disable-next-line regexp/strict
|
3593
|
+
pattern: createInline(/(~~?)(?:(?!~)<inner>)+\2/.source),
|
3594
|
+
lookbehind: true,
|
3595
|
+
greedy: true,
|
3596
|
+
inside: {
|
3597
|
+
'content': {
|
3598
|
+
pattern: /(^~~?)[\s\S]+(?=\1$)/,
|
3599
|
+
lookbehind: true,
|
3600
|
+
inside: {} // see below
|
3601
|
+
},
|
3602
|
+
'punctuation': /~~?/
|
3603
|
+
}
|
3604
|
+
},
|
3605
|
+
'code-snippet': {
|
3606
|
+
// `code`
|
3607
|
+
// ``code``
|
3608
|
+
pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/,
|
3609
|
+
lookbehind: true,
|
3610
|
+
greedy: true,
|
3611
|
+
alias: ['code', 'keyword']
|
3612
|
+
},
|
3613
|
+
'url': {
|
3614
|
+
// [example](http://example.com "Optional title")
|
3615
|
+
// [example][id]
|
3616
|
+
// [example] [id]
|
3617
|
+
pattern: createInline(/!?\[(?:(?!\])<inner>)+\](?:\([^\s)]+(?:[\t ]+"(?:\\.|[^"\\])*")?\)|[ \t]?\[(?:(?!\])<inner>)+\])/.source),
|
3618
|
+
lookbehind: true,
|
3619
|
+
greedy: true,
|
3620
|
+
inside: {
|
3621
|
+
'operator': /^!/,
|
3622
|
+
'content': {
|
3623
|
+
pattern: /(^\[)[^\]]+(?=\])/,
|
3624
|
+
lookbehind: true,
|
3625
|
+
inside: {} // see below
|
3626
|
+
},
|
3627
|
+
'variable': {
|
3628
|
+
pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/,
|
3629
|
+
lookbehind: true
|
3630
|
+
},
|
3631
|
+
'url': {
|
3632
|
+
pattern: /(^\]\()[^\s)]+/,
|
3633
|
+
lookbehind: true
|
3634
|
+
},
|
3635
|
+
'string': {
|
3636
|
+
pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,
|
3637
|
+
lookbehind: true
|
3638
|
+
}
|
3639
|
+
}
|
3640
|
+
}
|
3641
|
+
});
|
3642
|
+
|
3643
|
+
['url', 'bold', 'italic', 'strike'].forEach(function (token) {
|
3644
|
+
['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (inside) {
|
3645
|
+
if (token !== inside) {
|
3646
|
+
Prism.languages.markdown[token].inside.content.inside[inside] = Prism.languages.markdown[inside];
|
3647
|
+
}
|
3648
|
+
});
|
3649
|
+
});
|
3650
|
+
|
3651
|
+
Prism.hooks.add('after-tokenize', function (env) {
|
3652
|
+
if (env.language !== 'markdown' && env.language !== 'md') {
|
3653
|
+
return;
|
3654
|
+
}
|
3655
|
+
|
3656
|
+
function walkTokens(tokens) {
|
3657
|
+
if (!tokens || typeof tokens === 'string') {
|
3658
|
+
return;
|
3659
|
+
}
|
3660
|
+
|
3661
|
+
for (var i = 0, l = tokens.length; i < l; i++) {
|
3662
|
+
var token = tokens[i];
|
3663
|
+
|
3664
|
+
if (token.type !== 'code') {
|
3665
|
+
walkTokens(token.content);
|
3666
|
+
continue;
|
3667
|
+
}
|
3668
|
+
|
3669
|
+
/*
|
3670
|
+
* Add the correct `language-xxxx` class to this code block. Keep in mind that the `code-language` token
|
3671
|
+
* is optional. But the grammar is defined so that there is only one case we have to handle:
|
3672
|
+
*
|
3673
|
+
* token.content = [
|
3674
|
+
* <span class="punctuation">```</span>,
|
3675
|
+
* <span class="code-language">xxxx</span>,
|
3676
|
+
* '\n', // exactly one new lines (\r or \n or \r\n)
|
3677
|
+
* <span class="code-block">...</span>,
|
3678
|
+
* '\n', // exactly one new lines again
|
3679
|
+
* <span class="punctuation">```</span>
|
3680
|
+
* ];
|
3681
|
+
*/
|
3682
|
+
|
3683
|
+
var codeLang = token.content[1];
|
3684
|
+
var codeBlock = token.content[3];
|
3685
|
+
|
3686
|
+
if (codeLang && codeBlock &&
|
3687
|
+
codeLang.type === 'code-language' && codeBlock.type === 'code-block' &&
|
3688
|
+
typeof codeLang.content === 'string') {
|
3689
|
+
|
3690
|
+
// this might be a language that Prism does not support
|
3691
|
+
|
3692
|
+
// do some replacements to support C++, C#, and F#
|
3693
|
+
var lang = codeLang.content.replace(/\b#/g, 'sharp').replace(/\b\+\+/g, 'pp');
|
3694
|
+
// only use the first word
|
3695
|
+
lang = (/[a-z][\w-]*/i.exec(lang) || [''])[0].toLowerCase();
|
3696
|
+
var alias = 'language-' + lang;
|
3697
|
+
|
3698
|
+
// add alias
|
3699
|
+
if (!codeBlock.alias) {
|
3700
|
+
codeBlock.alias = [alias];
|
3701
|
+
} else if (typeof codeBlock.alias === 'string') {
|
3702
|
+
codeBlock.alias = [codeBlock.alias, alias];
|
3703
|
+
} else {
|
3704
|
+
codeBlock.alias.push(alias);
|
3705
|
+
}
|
3706
|
+
}
|
3707
|
+
}
|
3708
|
+
}
|
3709
|
+
|
3710
|
+
walkTokens(env.tokens);
|
3711
|
+
});
|
3712
|
+
|
3713
|
+
Prism.hooks.add('wrap', function (env) {
|
3714
|
+
if (env.type !== 'code-block') {
|
3715
|
+
return;
|
3716
|
+
}
|
3717
|
+
|
3718
|
+
var codeLang = '';
|
3719
|
+
for (var i = 0, l = env.classes.length; i < l; i++) {
|
3720
|
+
var cls = env.classes[i];
|
3721
|
+
var match = /language-(.+)/.exec(cls);
|
3722
|
+
if (match) {
|
3723
|
+
codeLang = match[1];
|
3724
|
+
break;
|
3725
|
+
}
|
3726
|
+
}
|
3727
|
+
|
3728
|
+
var grammar = Prism.languages[codeLang];
|
3729
|
+
|
3730
|
+
if (!grammar) {
|
3731
|
+
if (codeLang && codeLang !== 'none' && Prism.plugins.autoloader) {
|
3732
|
+
var id = 'md-' + new Date().valueOf() + '-' + Math.floor(Math.random() * 1e16);
|
3733
|
+
env.attributes['id'] = id;
|
3734
|
+
|
3735
|
+
Prism.plugins.autoloader.loadLanguages(codeLang, function () {
|
3736
|
+
var ele = document.getElementById(id);
|
3737
|
+
if (ele) {
|
3738
|
+
ele.innerHTML = Prism.highlight(ele.textContent, Prism.languages[codeLang], codeLang);
|
3739
|
+
}
|
3740
|
+
});
|
3741
|
+
}
|
3742
|
+
} else {
|
3743
|
+
env.content = Prism.highlight(textContent(env.content), grammar, codeLang);
|
3744
|
+
}
|
3745
|
+
});
|
3746
|
+
|
3747
|
+
var tagPattern = RegExp(Prism.languages.markup.tag.pattern.source, 'gi');
|
3748
|
+
|
3749
|
+
/**
|
3750
|
+
* A list of known entity names.
|
3751
|
+
*
|
3752
|
+
* This will always be incomplete to save space. The current list is the one used by lowdash's unescape function.
|
3753
|
+
*
|
3754
|
+
* @see {@link https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/unescape.js#L2}
|
3755
|
+
*/
|
3756
|
+
var KNOWN_ENTITY_NAMES = {
|
3757
|
+
'amp': '&',
|
3758
|
+
'lt': '<',
|
3759
|
+
'gt': '>',
|
3760
|
+
'quot': '"',
|
3761
|
+
};
|
3762
|
+
|
3763
|
+
// IE 11 doesn't support `String.fromCodePoint`
|
3764
|
+
var fromCodePoint = String.fromCodePoint || String.fromCharCode;
|
3765
|
+
|
3766
|
+
/**
|
3767
|
+
* Returns the text content of a given HTML source code string.
|
3768
|
+
*
|
3769
|
+
* @param {string} html
|
3770
|
+
* @returns {string}
|
3771
|
+
*/
|
3772
|
+
function textContent(html) {
|
3773
|
+
// remove all tags
|
3774
|
+
var text = html.replace(tagPattern, '');
|
3775
|
+
|
3776
|
+
// decode known entities
|
3777
|
+
text = text.replace(/&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (m, code) {
|
3778
|
+
code = code.toLowerCase();
|
3779
|
+
|
3780
|
+
if (code[0] === '#') {
|
3781
|
+
var value;
|
3782
|
+
if (code[1] === 'x') {
|
3783
|
+
value = parseInt(code.slice(2), 16);
|
3784
|
+
} else {
|
3785
|
+
value = Number(code.slice(1));
|
3786
|
+
}
|
3787
|
+
|
3788
|
+
return fromCodePoint(value);
|
3789
|
+
} else {
|
3790
|
+
var known = KNOWN_ENTITY_NAMES[code];
|
3791
|
+
if (known) {
|
3792
|
+
return known;
|
3793
|
+
}
|
3794
|
+
|
3795
|
+
// unable to decode
|
3796
|
+
return m;
|
3797
|
+
}
|
3798
|
+
});
|
3799
|
+
|
3800
|
+
return text;
|
3801
|
+
}
|
3802
|
+
|
3803
|
+
Prism.languages.md = Prism.languages.markdown;
|
3804
|
+
|
3805
|
+
}(Prism));
|
3806
|
+
|
3807
|
+
(function () {
|
3808
|
+
|
3809
|
+
if (typeof Prism === 'undefined' || typeof document === 'undefined') {
|
3810
|
+
return;
|
3811
|
+
}
|
3812
|
+
|
3813
|
+
/**
|
3814
|
+
* Plugin name which is used as a class name for <pre> which is activating the plugin
|
3815
|
+
*
|
3816
|
+
* @type {string}
|
3817
|
+
*/
|
3818
|
+
var PLUGIN_NAME = 'line-numbers';
|
3819
|
+
|
3820
|
+
/**
|
3821
|
+
* Regular expression used for determining line breaks
|
3822
|
+
*
|
3823
|
+
* @type {RegExp}
|
3824
|
+
*/
|
3825
|
+
var NEW_LINE_EXP = /\n(?!$)/g;
|
3826
|
+
|
3827
|
+
|
3828
|
+
/**
|
3829
|
+
* Global exports
|
3830
|
+
*/
|
3831
|
+
var config = Prism.plugins.lineNumbers = {
|
3832
|
+
/**
|
3833
|
+
* Get node for provided line number
|
3834
|
+
*
|
3835
|
+
* @param {Element} element pre element
|
3836
|
+
* @param {number} number line number
|
3837
|
+
* @returns {Element|undefined}
|
3838
|
+
*/
|
3839
|
+
getLine: function (element, number) {
|
3840
|
+
if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
|
3841
|
+
return;
|
3842
|
+
}
|
3843
|
+
|
3844
|
+
var lineNumberRows = element.querySelector('.line-numbers-rows');
|
3845
|
+
if (!lineNumberRows) {
|
3846
|
+
return;
|
3847
|
+
}
|
3848
|
+
var lineNumberStart = parseInt(element.getAttribute('data-start'), 10) || 1;
|
3849
|
+
var lineNumberEnd = lineNumberStart + (lineNumberRows.children.length - 1);
|
3850
|
+
|
3851
|
+
if (number < lineNumberStart) {
|
3852
|
+
number = lineNumberStart;
|
3853
|
+
}
|
3854
|
+
if (number > lineNumberEnd) {
|
3855
|
+
number = lineNumberEnd;
|
3856
|
+
}
|
3857
|
+
|
3858
|
+
var lineIndex = number - lineNumberStart;
|
3859
|
+
|
3860
|
+
return lineNumberRows.children[lineIndex];
|
3861
|
+
},
|
3862
|
+
|
3863
|
+
/**
|
3864
|
+
* Resizes the line numbers of the given element.
|
3865
|
+
*
|
3866
|
+
* This function will not add line numbers. It will only resize existing ones.
|
3867
|
+
*
|
3868
|
+
* @param {HTMLElement} element A `<pre>` element with line numbers.
|
3869
|
+
* @returns {void}
|
3870
|
+
*/
|
3871
|
+
resize: function (element) {
|
3872
|
+
resizeElements([element]);
|
3873
|
+
},
|
3874
|
+
|
3875
|
+
/**
|
3876
|
+
* Whether the plugin can assume that the units font sizes and margins are not depended on the size of
|
3877
|
+
* the current viewport.
|
3878
|
+
*
|
3879
|
+
* Setting this to `true` will allow the plugin to do certain optimizations for better performance.
|
3880
|
+
*
|
3881
|
+
* Set this to `false` if you use any of the following CSS units: `vh`, `vw`, `vmin`, `vmax`.
|
3882
|
+
*
|
3883
|
+
* @type {boolean}
|
3884
|
+
*/
|
3885
|
+
assumeViewportIndependence: true
|
3886
|
+
};
|
3887
|
+
|
3888
|
+
/**
|
3889
|
+
* Resizes the given elements.
|
3890
|
+
*
|
3891
|
+
* @param {HTMLElement[]} elements
|
3892
|
+
*/
|
3893
|
+
function resizeElements(elements) {
|
3894
|
+
elements = elements.filter(function (e) {
|
3895
|
+
var codeStyles = getStyles(e);
|
3896
|
+
var whiteSpace = codeStyles['white-space'];
|
3897
|
+
return whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line';
|
3898
|
+
});
|
3899
|
+
|
3900
|
+
if (elements.length == 0) {
|
3901
|
+
return;
|
3902
|
+
}
|
3903
|
+
|
3904
|
+
var infos = elements.map(function (element) {
|
3905
|
+
var codeElement = element.querySelector('code');
|
3906
|
+
var lineNumbersWrapper = element.querySelector('.line-numbers-rows');
|
3907
|
+
if (!codeElement || !lineNumbersWrapper) {
|
3908
|
+
return undefined;
|
3909
|
+
}
|
3910
|
+
|
3911
|
+
/** @type {HTMLElement} */
|
3912
|
+
var lineNumberSizer = element.querySelector('.line-numbers-sizer');
|
3913
|
+
var codeLines = codeElement.textContent.split(NEW_LINE_EXP);
|
3914
|
+
|
3915
|
+
if (!lineNumberSizer) {
|
3916
|
+
lineNumberSizer = document.createElement('span');
|
3917
|
+
lineNumberSizer.className = 'line-numbers-sizer';
|
3918
|
+
|
3919
|
+
codeElement.appendChild(lineNumberSizer);
|
3920
|
+
}
|
3921
|
+
|
3922
|
+
lineNumberSizer.innerHTML = '0';
|
3923
|
+
lineNumberSizer.style.display = 'block';
|
3924
|
+
|
3925
|
+
var oneLinerHeight = lineNumberSizer.getBoundingClientRect().height;
|
3926
|
+
lineNumberSizer.innerHTML = '';
|
3927
|
+
|
3928
|
+
return {
|
3929
|
+
element: element,
|
3930
|
+
lines: codeLines,
|
3931
|
+
lineHeights: [],
|
3932
|
+
oneLinerHeight: oneLinerHeight,
|
3933
|
+
sizer: lineNumberSizer,
|
3934
|
+
};
|
3935
|
+
}).filter(Boolean);
|
3936
|
+
|
3937
|
+
infos.forEach(function (info) {
|
3938
|
+
var lineNumberSizer = info.sizer;
|
3939
|
+
var lines = info.lines;
|
3940
|
+
var lineHeights = info.lineHeights;
|
3941
|
+
var oneLinerHeight = info.oneLinerHeight;
|
3942
|
+
|
3943
|
+
lineHeights[lines.length - 1] = undefined;
|
3944
|
+
lines.forEach(function (line, index) {
|
3945
|
+
if (line && line.length > 1) {
|
3946
|
+
var e = lineNumberSizer.appendChild(document.createElement('span'));
|
3947
|
+
e.style.display = 'block';
|
3948
|
+
e.textContent = line;
|
3949
|
+
} else {
|
3950
|
+
lineHeights[index] = oneLinerHeight;
|
3951
|
+
}
|
3952
|
+
});
|
3953
|
+
});
|
3954
|
+
|
3955
|
+
infos.forEach(function (info) {
|
3956
|
+
var lineNumberSizer = info.sizer;
|
3957
|
+
var lineHeights = info.lineHeights;
|
3958
|
+
|
3959
|
+
var childIndex = 0;
|
3960
|
+
for (var i = 0; i < lineHeights.length; i++) {
|
3961
|
+
if (lineHeights[i] === undefined) {
|
3962
|
+
lineHeights[i] = lineNumberSizer.children[childIndex++].getBoundingClientRect().height;
|
3963
|
+
}
|
3964
|
+
}
|
3965
|
+
});
|
3966
|
+
|
3967
|
+
infos.forEach(function (info) {
|
3968
|
+
var lineNumberSizer = info.sizer;
|
3969
|
+
var wrapper = info.element.querySelector('.line-numbers-rows');
|
3970
|
+
|
3971
|
+
lineNumberSizer.style.display = 'none';
|
3972
|
+
lineNumberSizer.innerHTML = '';
|
3973
|
+
|
3974
|
+
info.lineHeights.forEach(function (height, lineNumber) {
|
3975
|
+
wrapper.children[lineNumber].style.height = height + 'px';
|
3976
|
+
});
|
3977
|
+
});
|
3978
|
+
}
|
3979
|
+
|
3980
|
+
/**
|
3981
|
+
* Returns style declarations for the element
|
3982
|
+
*
|
3983
|
+
* @param {Element} element
|
3984
|
+
*/
|
3985
|
+
function getStyles(element) {
|
3986
|
+
if (!element) {
|
3987
|
+
return null;
|
3988
|
+
}
|
3989
|
+
|
3990
|
+
return window.getComputedStyle ? getComputedStyle(element) : (element.currentStyle || null);
|
3991
|
+
}
|
3992
|
+
|
3993
|
+
var lastWidth = undefined;
|
3994
|
+
window.addEventListener('resize', function () {
|
3995
|
+
if (config.assumeViewportIndependence && lastWidth === window.innerWidth) {
|
3996
|
+
return;
|
3997
|
+
}
|
3998
|
+
lastWidth = window.innerWidth;
|
3999
|
+
|
4000
|
+
resizeElements(Array.prototype.slice.call(document.querySelectorAll('pre.' + PLUGIN_NAME)));
|
4001
|
+
});
|
4002
|
+
|
4003
|
+
Prism.hooks.add('complete', function (env) {
|
4004
|
+
if (!env.code) {
|
4005
|
+
return;
|
4006
|
+
}
|
4007
|
+
|
4008
|
+
var code = /** @type {Element} */ (env.element);
|
4009
|
+
var pre = /** @type {HTMLElement} */ (code.parentNode);
|
4010
|
+
|
4011
|
+
// works only for <code> wrapped inside <pre> (not inline)
|
4012
|
+
if (!pre || !/pre/i.test(pre.nodeName)) {
|
4013
|
+
return;
|
4014
|
+
}
|
4015
|
+
|
4016
|
+
// Abort if line numbers already exists
|
4017
|
+
if (code.querySelector('.line-numbers-rows')) {
|
4018
|
+
return;
|
4019
|
+
}
|
4020
|
+
|
4021
|
+
// only add line numbers if <code> or one of its ancestors has the `line-numbers` class
|
4022
|
+
if (!Prism.util.isActive(code, PLUGIN_NAME)) {
|
4023
|
+
return;
|
4024
|
+
}
|
4025
|
+
|
4026
|
+
// Remove the class 'line-numbers' from the <code>
|
4027
|
+
code.classList.remove(PLUGIN_NAME);
|
4028
|
+
// Add the class 'line-numbers' to the <pre>
|
4029
|
+
pre.classList.add(PLUGIN_NAME);
|
4030
|
+
|
4031
|
+
var match = env.code.match(NEW_LINE_EXP);
|
4032
|
+
var linesNum = match ? match.length + 1 : 1;
|
4033
|
+
var lineNumbersWrapper;
|
4034
|
+
|
4035
|
+
var lines = new Array(linesNum + 1).join('<span></span>');
|
4036
|
+
|
4037
|
+
lineNumbersWrapper = document.createElement('span');
|
4038
|
+
lineNumbersWrapper.setAttribute('aria-hidden', 'true');
|
4039
|
+
lineNumbersWrapper.className = 'line-numbers-rows';
|
4040
|
+
lineNumbersWrapper.innerHTML = lines;
|
4041
|
+
|
4042
|
+
if (pre.hasAttribute('data-start')) {
|
4043
|
+
pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
|
4044
|
+
}
|
4045
|
+
|
4046
|
+
env.element.appendChild(lineNumbersWrapper);
|
4047
|
+
|
4048
|
+
resizeElements([pre]);
|
4049
|
+
|
4050
|
+
Prism.hooks.run('line-numbers', env);
|
4051
|
+
});
|
4052
|
+
|
4053
|
+
Prism.hooks.add('line-numbers', function (env) {
|
4054
|
+
env.plugins = env.plugins || {};
|
4055
|
+
env.plugins.lineNumbers = true;
|
4056
|
+
});
|
4057
|
+
|
4058
|
+
}());
|
4059
|
+
|
4060
|
+
// CSS styles
|
4061
|
+
var prismStyles = "\n code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}\n code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}\n code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}\n @media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}\n pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}\n :not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}\n :not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}\n .token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}\n .token.punctuation{color:#999}\n .token.namespace{opacity:.7}\n .token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}\n .token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}\n .language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}\n .token.atrule,.token.attr-value,.token.keyword{color:#07a}\n .token.class-name,.token.function{color:#dd4a68}\n .token.important,.token.regex,.token.variable{color:#e90}\n .token.bold,.token.important{font-weight:700}\n .token.italic{font-style:italic}\n .token.entity{cursor:help}\n \n /* Line Numbers */\n pre[class*=\"language-\"].line-numbers {\n position: relative;\n padding-left: 3.8em;\n counter-reset: linenumber;\n }\n\n pre[class*=\"language-\"].line-numbers > code {\n position: relative;\n white-space: inherit;\n }\n\n .line-numbers .line-numbers-rows {\n position: absolute;\n pointer-events: none;\n top: 0;\n font-size: 100%;\n left: -3.8em;\n width: 3em; /* works for line-numbers below 1000 lines */\n letter-spacing: -1px;\n border-right: 1px solid #999;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n }\n\n .line-numbers-rows > span {\n display: block;\n counter-increment: linenumber;\n }\n\n .line-numbers-rows > span:before {\n content: counter(linenumber);\n color: #999;\n display: block;\n padding-right: 0.8em;\n text-align: right;\n }\n";
|
4062
|
+
var MarkdownTableError = /** @class */ (function (_super) {
|
4063
|
+
__extends(MarkdownTableError, _super);
|
4064
|
+
function MarkdownTableError(message) {
|
4065
|
+
var _this = _super.call(this, message) || this;
|
4066
|
+
_this.name = 'MarkdownTableError';
|
4067
|
+
return _this;
|
4068
|
+
}
|
4069
|
+
return MarkdownTableError;
|
4070
|
+
}(Error));
|
1437
4071
|
function calculateColumnWidths(allRows, maxColumnCount) {
|
1438
|
-
var widths = new Array(maxColumnCount).fill(3);
|
4072
|
+
var widths = new Array(maxColumnCount).fill(3);
|
1439
4073
|
allRows.forEach(function (row) {
|
1440
4074
|
var _a;
|
1441
4075
|
for (var i = 0; i < maxColumnCount; i++) {
|
@@ -1445,24 +4079,9 @@ function calculateColumnWidths(allRows, maxColumnCount) {
|
|
1445
4079
|
});
|
1446
4080
|
return widths;
|
1447
4081
|
}
|
1448
|
-
/**
|
1449
|
-
* Replaces newline characters in a string with <br> tags.
|
1450
|
-
* @param cell - The cell content to process.
|
1451
|
-
* @returns The processed cell content with newlines replaced.
|
1452
|
-
*/
|
1453
4082
|
function replaceNewlinesInCell(cell) {
|
1454
4083
|
return cell.replace(/\n/g, '<br>');
|
1455
4084
|
}
|
1456
|
-
/**
|
1457
|
-
* Formats a single row into a Markdown-formatted string.
|
1458
|
-
* @param columnCount - The number of columns in the table.
|
1459
|
-
* @param row - The data of the current row.
|
1460
|
-
* @param columnAlignments - Alignment settings for each column.
|
1461
|
-
* @param columnWidths - Widths of each column.
|
1462
|
-
* @param useTabs - Flag to use tabs between columns.
|
1463
|
-
* @param replaceNewlines - Flag to replace newlines with <br> tags.
|
1464
|
-
* @returns The Markdown string for the row.
|
1465
|
-
*/
|
1466
4085
|
function formatMarkdownRow(columnCount, row, columnAlignments, columnWidths, useTabs, replaceNewlines) {
|
1467
4086
|
var _a, _b;
|
1468
4087
|
if (useTabs === void 0) { useTabs = false; }
|
@@ -1488,20 +4107,11 @@ function formatMarkdownRow(columnCount, row, columnAlignments, columnWidths, use
|
|
1488
4107
|
markdownRow += "".concat(useTabs ? '\t' : ' ').concat(' '.repeat(paddingLeft)).concat(cell).concat(' '.repeat(paddingRight)).concat(useTabs ? '\t' : ' ', "|");
|
1489
4108
|
}
|
1490
4109
|
else {
|
1491
|
-
// Left alignment or default
|
1492
4110
|
markdownRow += "".concat(useTabs ? '\t' : ' ').concat(cell.padEnd(targetWidth)).concat(useTabs ? '\t' : ' ', "|");
|
1493
4111
|
}
|
1494
4112
|
}
|
1495
4113
|
return markdownRow;
|
1496
4114
|
}
|
1497
|
-
/**
|
1498
|
-
* Generates the alignment row for the Markdown table syntax.
|
1499
|
-
* @param columnCount - The number of columns in the table.
|
1500
|
-
* @param columnAlignments - Alignment settings for each column.
|
1501
|
-
* @param columnWidths - Widths of each column.
|
1502
|
-
* @param useTabs - Flag to use tabs between columns.
|
1503
|
-
* @returns The Markdown string for the alignment row.
|
1504
|
-
*/
|
1505
4115
|
function formatAlignmentRow(columnCount, columnAlignments, columnWidths, useTabs) {
|
1506
4116
|
var _a;
|
1507
4117
|
if (useTabs === void 0) { useTabs = false; }
|
@@ -1531,15 +4141,6 @@ function formatAlignmentRow(columnCount, columnAlignments, columnWidths, useTabs
|
|
1531
4141
|
}
|
1532
4142
|
return alignmentRow;
|
1533
4143
|
}
|
1534
|
-
/**
|
1535
|
-
* Generates a complete Markdown table string from the provided data.
|
1536
|
-
* @param tableData - The table data including headers and rows.
|
1537
|
-
* @param columnAlignments - Alignment settings for each column.
|
1538
|
-
* @param adjustColumnWidths - Flag to adjust column widths based on content.
|
1539
|
-
* @param useTabs - Flag to use tabs between columns.
|
1540
|
-
* @param replaceNewlines - Flag to replace newlines with <br> tags.
|
1541
|
-
* @returns The complete Markdown table string.
|
1542
|
-
*/
|
1543
4144
|
function generateMarkdownTableString(tableData, columnAlignments, adjustColumnWidths, useTabs, replaceNewlines) {
|
1544
4145
|
if (adjustColumnWidths === void 0) { adjustColumnWidths = true; }
|
1545
4146
|
if (useTabs === void 0) { useTabs = false; }
|
@@ -1559,110 +4160,34 @@ function generateMarkdownTableString(tableData, columnAlignments, adjustColumnWi
|
|
1559
4160
|
.join('\n');
|
1560
4161
|
return "".concat(markdownHeaderRow, "\n").concat(markdownAlignmentRow, "\n").concat(markdownBodyRows).trimEnd();
|
1561
4162
|
}
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
*/
|
1567
|
-
var MarkdownTableError = /** @class */ (function (_super) {
|
1568
|
-
__extends(MarkdownTableError, _super);
|
1569
|
-
function MarkdownTableError(message) {
|
1570
|
-
var _this = _super.call(this, message) || this;
|
1571
|
-
_this.name = 'MarkdownTableError';
|
1572
|
-
Object.setPrototypeOf(_this, MarkdownTableError.prototype);
|
1573
|
-
return _this;
|
1574
|
-
}
|
1575
|
-
return MarkdownTableError;
|
1576
|
-
}(Error));
|
1577
|
-
|
1578
|
-
// src/validation.ts
|
1579
|
-
/**
|
1580
|
-
* Validates the structure of the table data based on the `hasHeader` flag.
|
1581
|
-
* Throws an error if validation fails.
|
1582
|
-
* @param props - The props to validate.
|
1583
|
-
*/
|
1584
|
-
function validateMarkdownTableProps(props) {
|
1585
|
-
var data = props.data, _a = props.hasHeader, hasHeader = _a === void 0 ? true : _a, columnAlignments = props.columnAlignments, _b = props.isCompact, isCompact = _b === void 0 ? false : _b, _c = props.hasTabs, hasTabs = _c === void 0 ? false : _c, _d = props.canReplaceNewlines, canReplaceNewlines = _d === void 0 ? false : _d;
|
1586
|
-
if (!Array.isArray(data)) {
|
1587
|
-
throw new MarkdownTableError("The 'data' prop must be a two-dimensional array.");
|
1588
|
-
}
|
1589
|
-
if (data.length === 0) {
|
1590
|
-
throw new MarkdownTableError("The 'data' array must contain at least one row.");
|
1591
|
-
}
|
1592
|
-
// If hasHeader is true, ensure the first row exists and is valid
|
1593
|
-
if (hasHeader) {
|
1594
|
-
var header = data[0];
|
1595
|
-
if (!Array.isArray(header) || header.length === 0) {
|
1596
|
-
throw new MarkdownTableError("The first row of 'data' must be a non-empty array representing the header.");
|
1597
|
-
}
|
1598
|
-
// Validate each header cell is a string
|
1599
|
-
header.forEach(function (cell, index) {
|
1600
|
-
if (typeof cell !== 'string') {
|
1601
|
-
throw new MarkdownTableError("Header cell at index ".concat(index, " must be a string."));
|
1602
|
-
}
|
1603
|
-
});
|
1604
|
-
}
|
1605
|
-
// Validate each row
|
1606
|
-
data.forEach(function (row, rowIndex) {
|
1607
|
-
if (!Array.isArray(row)) {
|
1608
|
-
throw new MarkdownTableError("Row ".concat(rowIndex + 1, " in 'data' must be an array of strings."));
|
1609
|
-
}
|
1610
|
-
row.forEach(function (cell, cellIndex) {
|
1611
|
-
if (typeof cell !== 'string') {
|
1612
|
-
throw new MarkdownTableError("Cell at row ".concat(rowIndex + 1, ", column ").concat(cellIndex + 1, " must be a string."));
|
1613
|
-
}
|
1614
|
-
});
|
1615
|
-
});
|
1616
|
-
// Validate columnAlignments if provided
|
1617
|
-
if (columnAlignments) {
|
1618
|
-
if (!Array.isArray(columnAlignments)) {
|
1619
|
-
throw new MarkdownTableError("'columnAlignments' must be an array of alignment strings.");
|
1620
|
-
}
|
1621
|
-
var validAlignments_1 = ['left', 'center', 'right', 'none'];
|
1622
|
-
columnAlignments.forEach(function (alignment, index) {
|
1623
|
-
if (!validAlignments_1.includes(alignment)) {
|
1624
|
-
throw new MarkdownTableError("Invalid alignment '".concat(alignment, "' at index ").concat(index, ". Valid options are 'left', 'center', 'right', 'none'."));
|
1625
|
-
}
|
1626
|
-
});
|
1627
|
-
}
|
1628
|
-
// Validate isCompact
|
1629
|
-
if (typeof isCompact !== 'boolean') {
|
1630
|
-
throw new MarkdownTableError("'isCompact' must be a boolean.");
|
1631
|
-
}
|
1632
|
-
// Validate hasTabs
|
1633
|
-
if (typeof hasTabs !== 'boolean') {
|
1634
|
-
throw new MarkdownTableError("'hasTabs' must be a boolean.");
|
4163
|
+
function generateAlphabetHeaders(columnCount) {
|
4164
|
+
var headers = [];
|
4165
|
+
for (var i = 0; i < columnCount; i++) {
|
4166
|
+
headers.push(getColumnName(i));
|
1635
4167
|
}
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
4168
|
+
return headers;
|
4169
|
+
}
|
4170
|
+
function getColumnName(index) {
|
4171
|
+
var name = '';
|
4172
|
+
var currentIndex = index;
|
4173
|
+
while (currentIndex >= 0) {
|
4174
|
+
name = String.fromCharCode((currentIndex % 26) + 65) + name;
|
4175
|
+
currentIndex = Math.floor(currentIndex / 26) - 1;
|
1639
4176
|
}
|
4177
|
+
return name;
|
1640
4178
|
}
|
1641
|
-
|
1642
|
-
/**
|
1643
|
-
* React component that generates and displays Markdown table syntax.
|
1644
|
-
* @param props - The input parameters for table generation.
|
1645
|
-
* @returns A <pre> element containing the Markdown table syntax or an error message.
|
1646
|
-
*/
|
1647
4179
|
var MarkdownTable = function (_a) {
|
1648
4180
|
var _b = _a.data, data = _b === void 0 ? null : _b, _c = _a.hasHeader, hasHeader = _c === void 0 ? true : _c, _d = _a.columnAlignments, columnAlignments = _d === void 0 ? [] : _d, _e = _a.isCompact, isCompact = _e === void 0 ? false : _e, _f = _a.hasTabs, hasTabs = _f === void 0 ? false : _f, _g = _a.canReplaceNewlines, canReplaceNewlines = _g === void 0 ? false : _g, className = _a.className, onTableCreate = _a.onTableCreate;
|
1649
|
-
// Invert isCompact to get adjustColumnWidths
|
1650
4181
|
var adjustColumnWidths = !isCompact;
|
1651
|
-
|
4182
|
+
var preRef = require$$0.useRef(null);
|
1652
4183
|
var markdownSyntax = require$$0.useMemo(function () {
|
1653
4184
|
if (data === null) {
|
1654
4185
|
return 'Error: No data provided for the table.';
|
1655
4186
|
}
|
1656
4187
|
try {
|
1657
|
-
|
1658
|
-
data
|
1659
|
-
|
1660
|
-
columnAlignments: columnAlignments,
|
1661
|
-
isCompact: isCompact,
|
1662
|
-
hasTabs: hasTabs,
|
1663
|
-
canReplaceNewlines: canReplaceNewlines,
|
1664
|
-
});
|
1665
|
-
// Determine header and rows based on hasHeader
|
4188
|
+
if (!Array.isArray(data) || data.length === 0) {
|
4189
|
+
throw new MarkdownTableError("The 'data' prop must be a non-empty two-dimensional array.");
|
4190
|
+
}
|
1666
4191
|
var tableData = hasHeader
|
1667
4192
|
? {
|
1668
4193
|
header: data[0],
|
@@ -1695,36 +4220,13 @@ var MarkdownTable = function (_a) {
|
|
1695
4220
|
onTableCreate(markdownSyntax);
|
1696
4221
|
}
|
1697
4222
|
}, [markdownSyntax, onTableCreate]);
|
1698
|
-
|
4223
|
+
require$$0.useEffect(function () {
|
4224
|
+
if (preRef.current) {
|
4225
|
+
Prism$1.highlightElement(preRef.current.querySelector('code'));
|
4226
|
+
}
|
4227
|
+
}, [markdownSyntax]);
|
4228
|
+
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: prismStyles }), jsxRuntimeExports.jsx("pre", { ref: preRef, className: "".concat(className, " language-markdown line-numbers"), children: jsxRuntimeExports.jsx("code", { children: markdownSyntax }) })] }));
|
1699
4229
|
};
|
1700
|
-
/**
|
1701
|
-
* Generates alphabetical headers (A, B, C, ...) based on the number of columns.
|
1702
|
-
* @param columnCount - The number of columns.
|
1703
|
-
* @returns An array of alphabetical headers.
|
1704
|
-
*/
|
1705
|
-
function generateAlphabetHeaders(columnCount) {
|
1706
|
-
var headers = [];
|
1707
|
-
for (var i = 0; i < columnCount; i++) {
|
1708
|
-
headers.push(getColumnName(i));
|
1709
|
-
}
|
1710
|
-
return headers;
|
1711
|
-
}
|
1712
|
-
/**
|
1713
|
-
* Converts a zero-based column index to its corresponding alphabetical representation.
|
1714
|
-
* For example, 0 -> 'A', 1 -> 'B', ..., 25 -> 'Z', 26 -> 'AA', etc.
|
1715
|
-
* @param index - The zero-based column index.
|
1716
|
-
* @returns The alphabetical column name.
|
1717
|
-
*/
|
1718
|
-
function getColumnName(index) {
|
1719
|
-
var name = '';
|
1720
|
-
var currentIndex = index;
|
1721
|
-
while (currentIndex >= 0) {
|
1722
|
-
name = String.fromCharCode((currentIndex % 26) + 65) + name;
|
1723
|
-
currentIndex = Math.floor(currentIndex / 26) - 1;
|
1724
|
-
}
|
1725
|
-
return name;
|
1726
|
-
}
|
1727
4230
|
|
1728
4231
|
exports.MarkdownTable = MarkdownTable;
|
1729
|
-
exports.MarkdownTableError = MarkdownTableError;
|
1730
4232
|
//# sourceMappingURL=index.cjs.js.map
|