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