code-battles 1.7.0 → 1.7.2

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.
Files changed (52) hide show
  1. package/dist/cjs/index.js +2153 -1954
  2. package/dist/cjs/styles.css +2 -1
  3. package/dist/cjs/types/components/DataTable.d.ts +21 -0
  4. package/dist/cjs/types/components/ResultStaticsTable.d.ts +3 -0
  5. package/dist/cjs/types/configuration.d.ts +0 -1
  6. package/dist/code_battles/battles.py +22 -9
  7. package/dist/code_battles/utilities.py +5 -1
  8. package/dist/esm/index.js +2154 -1955
  9. package/dist/esm/styles.css +2 -1
  10. package/dist/esm/types/components/DataTable.d.ts +21 -0
  11. package/dist/esm/types/components/ResultStaticsTable.d.ts +3 -0
  12. package/dist/esm/types/configuration.d.ts +0 -1
  13. package/dist/index.d.ts +0 -1
  14. package/dist/pyscript/codemirror-eKulCBrd.js +2 -0
  15. package/dist/pyscript/codemirror-eKulCBrd.js.map +1 -0
  16. package/dist/pyscript/codemirror_commands-BVu_0Pnj.js +2 -0
  17. package/dist/pyscript/codemirror_commands-BVu_0Pnj.js.map +1 -0
  18. package/dist/pyscript/codemirror_lang-python-a2LxSo5G.js +2 -0
  19. package/dist/pyscript/codemirror_lang-python-a2LxSo5G.js.map +1 -0
  20. package/dist/pyscript/codemirror_language-_2pXlKJ9.js +2 -0
  21. package/dist/pyscript/codemirror_language-_2pXlKJ9.js.map +1 -0
  22. package/dist/pyscript/codemirror_view-DMW9kQlJ.js +2 -0
  23. package/dist/pyscript/codemirror_view-DMW9kQlJ.js.map +1 -0
  24. package/dist/pyscript/core-DezwbZpG.js +4 -0
  25. package/dist/pyscript/core-DezwbZpG.js.map +1 -0
  26. package/dist/pyscript/core.js +1 -1
  27. package/dist/pyscript/deprecations-manager-B1bDno27.js +2 -0
  28. package/dist/pyscript/deprecations-manager-B1bDno27.js.map +1 -0
  29. package/dist/pyscript/donkey-DNl0ASkM.js +2 -0
  30. package/dist/pyscript/donkey-DNl0ASkM.js.map +1 -0
  31. package/dist/pyscript/error-DmRE4Y-7.js +2 -0
  32. package/dist/pyscript/error-DmRE4Y-7.js.map +1 -0
  33. package/dist/pyscript/index-DkgvWIf-.js +2 -0
  34. package/dist/pyscript/index-DkgvWIf-.js.map +1 -0
  35. package/dist/pyscript/mpy-BoY0tVRD.js +2 -0
  36. package/dist/pyscript/mpy-BoY0tVRD.js.map +1 -0
  37. package/dist/pyscript/py-DsQqgZuM.js +2 -0
  38. package/dist/pyscript/py-DsQqgZuM.js.map +1 -0
  39. package/dist/pyscript/py-editor-DZkG_or6.js +2 -0
  40. package/dist/pyscript/py-editor-DZkG_or6.js.map +1 -0
  41. package/dist/pyscript/py-game-D0Z4YnzZ.js +2 -0
  42. package/dist/pyscript/py-game-D0Z4YnzZ.js.map +1 -0
  43. package/dist/pyscript/py-terminal-DYHK7LJ0.js +2 -0
  44. package/dist/pyscript/py-terminal-DYHK7LJ0.js.map +1 -0
  45. package/dist/pyscript/service-worker.js +1 -0
  46. package/dist/pyscript/storage.js +1 -1
  47. package/dist/pyscript/storage.js.map +1 -1
  48. package/dist/pyscript/xterm-CVv2fC4I.js +2 -0
  49. package/dist/pyscript/xterm-CVv2fC4I.js.map +1 -0
  50. package/dist/pyscript/zip-D13-hp9W.js +2 -0
  51. package/dist/pyscript/zip-D13-hp9W.js.map +1 -0
  52. package/package.json +14 -14
package/dist/cjs/index.js CHANGED
@@ -376,8 +376,8 @@ const updatePointModifier = () => {
376
376
  if (results[round.players.join(", ")] &&
377
377
  results[round.players.join(", ")][JSON.stringify(round.parameters)]) {
378
378
  for (const result of results[round.players.join(", ")][JSON.stringify(round.parameters)]) {
379
- const first = round.players[result[0]];
380
- const second = round.players[result[1]];
379
+ const first = round.players[result.places[0]];
380
+ const second = round.players[result.places[1]];
381
381
  if (!pointModifier[first]) {
382
382
  pointModifier[first] = 0;
383
383
  }
@@ -886,9 +886,9 @@ function requireCheckPropTypes () {
886
886
  var printWarning = function() {};
887
887
 
888
888
  if (process.env.NODE_ENV !== 'production') {
889
- var ReactPropTypesSecret = requireReactPropTypesSecret();
889
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
890
890
  var loggedTypeFailures = {};
891
- var has = requireHas();
891
+ var has = /*@__PURE__*/ requireHas();
892
892
 
893
893
  printWarning = function(text) {
894
894
  var message = 'Warning: ' + text;
@@ -997,9 +997,9 @@ function requireFactoryWithTypeCheckers () {
997
997
  var ReactIs = requireReactIs();
998
998
  var assign = requireObjectAssign();
999
999
 
1000
- var ReactPropTypesSecret = requireReactPropTypesSecret();
1001
- var has = requireHas();
1002
- var checkPropTypes = requireCheckPropTypes();
1000
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
1001
+ var has = /*@__PURE__*/ requireHas();
1002
+ var checkPropTypes = /*@__PURE__*/ requireCheckPropTypes();
1003
1003
 
1004
1004
  var printWarning = function() {};
1005
1005
 
@@ -1612,7 +1612,7 @@ function requireFactoryWithThrowingShims () {
1612
1612
  if (hasRequiredFactoryWithThrowingShims) return factoryWithThrowingShims;
1613
1613
  hasRequiredFactoryWithThrowingShims = 1;
1614
1614
 
1615
- var ReactPropTypesSecret = requireReactPropTypesSecret();
1615
+ var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
1616
1616
 
1617
1617
  function emptyFunction() {}
1618
1618
  function emptyFunctionWithReset() {}
@@ -1676,20 +1676,27 @@ function requireFactoryWithThrowingShims () {
1676
1676
  * LICENSE file in the root directory of this source tree.
1677
1677
  */
1678
1678
 
1679
- if (process.env.NODE_ENV !== 'production') {
1680
- var ReactIs = requireReactIs();
1681
-
1682
- // By explicitly using `prop-types` you are opting into new development behavior.
1683
- // http://fb.me/prop-types-in-prod
1684
- var throwOnDirectAccess = true;
1685
- propTypes.exports = requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1686
- } else {
1687
- // By explicitly using `prop-types` you are opting into new production behavior.
1688
- // http://fb.me/prop-types-in-prod
1689
- propTypes.exports = requireFactoryWithThrowingShims()();
1679
+ var hasRequiredPropTypes;
1680
+
1681
+ function requirePropTypes () {
1682
+ if (hasRequiredPropTypes) return propTypes.exports;
1683
+ hasRequiredPropTypes = 1;
1684
+ if (process.env.NODE_ENV !== 'production') {
1685
+ var ReactIs = requireReactIs();
1686
+
1687
+ // By explicitly using `prop-types` you are opting into new development behavior.
1688
+ // http://fb.me/prop-types-in-prod
1689
+ var throwOnDirectAccess = true;
1690
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1691
+ } else {
1692
+ // By explicitly using `prop-types` you are opting into new production behavior.
1693
+ // http://fb.me/prop-types-in-prod
1694
+ propTypes.exports = /*@__PURE__*/ requireFactoryWithThrowingShims()();
1695
+ }
1696
+ return propTypes.exports;
1690
1697
  }
1691
1698
 
1692
- var propTypesExports = propTypes.exports;
1699
+ var propTypesExports = /*@__PURE__*/ requirePropTypes();
1693
1700
 
1694
1701
  function _classCallCheck(instance, Constructor) {
1695
1702
  if (!(instance instanceof Constructor)) {
@@ -2530,7 +2537,7 @@ const RunSimulationBlock = () => {
2530
2537
  };
2531
2538
  const startRunNoUI = () => {
2532
2539
  setRunningNoUI(true);
2533
- runNoUI(getFullParameters(), apis, playerBots, seed.toString(), false);
2540
+ runNoUI(getFullParameters(), apis, playerBots, seed.toString(), true);
2534
2541
  };
2535
2542
  const startRunNoUIN = (n) => {
2536
2543
  setLocalStorage("Results", {});
@@ -2567,7 +2574,7 @@ const RunSimulationBlock = () => {
2567
2574
  const currentResults = results[playerBots.join(", ")][JSON.stringify(getFullParameters())];
2568
2575
  const winCounts = {};
2569
2576
  for (const result of currentResults) {
2570
- const winner = playerBots[result[0]];
2577
+ const winner = playerBots[result.places[0]];
2571
2578
  if (!winCounts[winner]) {
2572
2579
  winCounts[winner] = 1;
2573
2580
  }
@@ -2788,6 +2795,155 @@ const NotFoundPage = () => {
2788
2795
  React.createElement("p", null, "Make sure the URL is correct.")));
2789
2796
  };
2790
2797
 
2798
+ const DataTable = ({ tableName, data, renderValue, renderHead, disableSort, hideIfEmpty, selectable, selectedRows, setSelectedRows, defaultSort, defaultReversed, stickyFirstColumn, }) => {
2799
+ var _a, _b;
2800
+ const [sortByColumn, setSortByColumn] = React.useState(defaultSort !== null && defaultSort !== void 0 ? defaultSort : 0);
2801
+ const [reversed, setReversed] = React.useState(defaultReversed !== null && defaultReversed !== void 0 ? defaultReversed : false);
2802
+ const [search, setSearch] = React.useState("");
2803
+ const theme = core.useMantineTheme();
2804
+ const colorScheme = hooks.useColorScheme();
2805
+ if (hideIfEmpty && data.body.length === 0) {
2806
+ return React.createElement(React.Fragment, null);
2807
+ }
2808
+ const reverseValue = reversed ? -1 : 1;
2809
+ const id = (_, __, value) => value;
2810
+ renderValue = renderValue !== null && renderValue !== void 0 ? renderValue : id;
2811
+ const headId = (value) => value;
2812
+ renderHead = renderHead !== null && renderHead !== void 0 ? renderHead : headId;
2813
+ const bodyIndices = [];
2814
+ for (let i = 0; i < data.body.length; i++) {
2815
+ bodyIndices.push(i);
2816
+ }
2817
+ const sortedIndices = bodyIndices
2818
+ .filter((i) => data.body[i].some((x, j) => {
2819
+ var _a;
2820
+ return (x === null || x === void 0 ? void 0 : x.includes(search)) ||
2821
+ ((_a = renderValue(i, data.head[j], x)) === null || _a === void 0 ? void 0 : _a.toString().includes(search));
2822
+ }))
2823
+ .sort((a, b) => {
2824
+ var _a, _b;
2825
+ if (disableSort) {
2826
+ return 1;
2827
+ }
2828
+ const aValue = (_a = data.body[a][sortByColumn]) !== null && _a !== void 0 ? _a : "";
2829
+ const bValue = (_b = data.body[b][sortByColumn]) !== null && _b !== void 0 ? _b : "";
2830
+ let difference = parseInt(bValue) - parseInt(aValue);
2831
+ if (isNaN(difference)) {
2832
+ return reverseValue * (aValue === null || aValue === void 0 ? void 0 : aValue.localeCompare(bValue));
2833
+ }
2834
+ return reverseValue * difference;
2835
+ });
2836
+ const displayData = {
2837
+ head: data.head.map(renderHead),
2838
+ body: sortedIndices.map((rowIndex) => data.body[rowIndex].map((value, columnIndex) => renderValue(rowIndex, data.head[columnIndex], value))),
2839
+ };
2840
+ return (React.createElement(React.Fragment, null,
2841
+ React.createElement(core.TextInput, { mb: "xs", w: 400, maw: "100%", placeholder: "Search", leftSection: React.createElement("i", { className: "fa-solid fa-magnifying-glass" }), rightSection: search !== "" ? (React.createElement(core.ActionIcon, { onClick: () => setSearch(""), variant: "transparent", color: "default", size: 15 },
2842
+ React.createElement("i", { className: "fa-solid fa-xmark" }))) : undefined, value: search, onChange: (e) => setSearch(e.currentTarget.value) }),
2843
+ React.createElement("div", { style: { maxWidth: "100%", overflow: "auto", maxHeight: 500 } },
2844
+ React.createElement(core.Table, { horizontalSpacing: 7.5, verticalSpacing: 7.5 },
2845
+ React.createElement(core.Table.Thead, { style: {
2846
+ position: "sticky",
2847
+ top: 0,
2848
+ backgroundColor: colorScheme === "dark" ? theme.colors.dark[7] : "white",
2849
+ zIndex: 101,
2850
+ } },
2851
+ React.createElement(core.Table.Tr, { h: 1 },
2852
+ selectable && React.createElement(core.Table.Th, null), (_a = displayData.head) === null || _a === void 0 ? void 0 :
2853
+ _a.map((element, columnIndex) => (React.createElement(core.Table.Th, { key: columnIndex, style: {
2854
+ padding: 0,
2855
+ verticalAlign: "top",
2856
+ height: "inherit",
2857
+ } }, element !== "" && (React.createElement(core.UnstyledButton, { h: "100%", className: "control", style: {
2858
+ display: "flex",
2859
+ flexDirection: "column",
2860
+ minWidth: 100,
2861
+ }, onClick: disableSort
2862
+ ? undefined
2863
+ : () => {
2864
+ if (sortByColumn === columnIndex) {
2865
+ setReversed((r) => !r);
2866
+ }
2867
+ else {
2868
+ setSortByColumn(columnIndex);
2869
+ }
2870
+ } },
2871
+ disableSort || (React.createElement("i", { style: { fontSize: 14, marginBottom: 5 }, className: sortByColumn === columnIndex
2872
+ ? reversed
2873
+ ? "fa-solid fa-sort-up"
2874
+ : "fa-solid fa-sort-down"
2875
+ : "fa-solid fa-sort" })),
2876
+ element))))))),
2877
+ React.createElement(core.Table.Tbody, null, (_b = displayData.body) === null || _b === void 0 ? void 0 : _b.map((row, rowIndex) => {
2878
+ const realIndex = sortedIndices[rowIndex];
2879
+ return (React.createElement(core.Table.Tr, { key: rowIndex },
2880
+ selectable && (React.createElement(core.Table.Td, null,
2881
+ React.createElement(core.Checkbox, { checked: selectedRows === null || selectedRows === void 0 ? void 0 : selectedRows.includes(realIndex), onChange: (e) => {
2882
+ if (setSelectedRows) {
2883
+ if (e.currentTarget.checked) {
2884
+ setSelectedRows((s) => [...s, realIndex]);
2885
+ }
2886
+ else {
2887
+ setSelectedRows((s) => s.filter((x) => x !== realIndex));
2888
+ }
2889
+ }
2890
+ } }))),
2891
+ row.map((value, valueIndex) => (React.createElement(core.Table.Td, { key: valueIndex, style: Object.assign({ whiteSpace: "nowrap" }, (stickyFirstColumn && valueIndex === 0
2892
+ ? {
2893
+ position: "sticky",
2894
+ right: 0,
2895
+ backgroundColor: colorScheme === "dark"
2896
+ ? theme.colors.dark[7]
2897
+ : "white",
2898
+ zIndex: 100,
2899
+ }
2900
+ : {})) }, value)))));
2901
+ }))))));
2902
+ };
2903
+
2904
+ const ResultStatisticsTable = () => {
2905
+ var _a, _b, _c, _d, _e;
2906
+ const [results] = useLocalStorage({
2907
+ key: "Results",
2908
+ defaultValue: {},
2909
+ });
2910
+ const [rounds] = useLocalStorage({
2911
+ key: "Rounds",
2912
+ defaultValue: [],
2913
+ });
2914
+ const [currentRound] = useLocalStorage({
2915
+ key: "Current Round",
2916
+ defaultValue: 0,
2917
+ });
2918
+ const navigate = reactRouterDom.useNavigate();
2919
+ const round = rounds[currentRound];
2920
+ if (!round) {
2921
+ return React.createElement(React.Fragment, null);
2922
+ }
2923
+ const statistics = Object.keys((_d = (_c = ((_b = Object.values((_a = Object.values(results !== null && results !== void 0 ? results : {})[0]) !== null && _a !== void 0 ? _a : {})[0]) !== null && _b !== void 0 ? _b : [])[0]) === null || _c === void 0 ? void 0 : _c.statistics) !== null && _d !== void 0 ? _d : {});
2924
+ const roundResults = ((_e = (results !== null && results !== void 0 ? results : {})[round.players.join(", ")]) !== null && _e !== void 0 ? _e : {})[JSON.stringify(round.parameters)];
2925
+ if (!roundResults) {
2926
+ return React.createElement(React.Fragment, null);
2927
+ }
2928
+ return (React.createElement("div", { style: {
2929
+ display: "flex",
2930
+ flexDirection: "column",
2931
+ alignItems: "center",
2932
+ marginTop: 10,
2933
+ } },
2934
+ React.createElement(DataTable, { tableName: "Results", data: {
2935
+ head: ["Seed"].concat(statistics),
2936
+ body: roundResults.map((result) => [result.seed].concat(statistics.map((statistic) => { var _a; return ((_a = result === null || result === void 0 ? void 0 : result.statistics) !== null && _a !== void 0 ? _a : {})[statistic].toString(); }))),
2937
+ }, renderValue: (rowIndex, columnName, value) => {
2938
+ if (columnName === "Seed") {
2939
+ return (React.createElement(core.Button, { leftSection: React.createElement("i", { className: "fa-solid fa-play" }), onClick: () => navigate(`/simulation/${round.players.map(encodeURIComponent).join(",")}?seed=${value}&${Object.keys(round.parameters)
2940
+ .map((p) => `${p}=${encodeURIComponent(round.parameters[p])}`)
2941
+ .join("&")}`) }, "Play"));
2942
+ }
2943
+ return React.createElement(React.Fragment, { key: rowIndex }, value);
2944
+ } })));
2945
+ };
2946
+
2791
2947
  let currentParameters;
2792
2948
  let currentPlayers;
2793
2949
  const Round = () => {
@@ -2877,11 +3033,12 @@ const Round = () => {
2877
3033
  roundIterations !== 1 && (React.createElement("th", { style: { width: "35%" } }, "Results")),
2878
3034
  React.createElement("th", null))),
2879
3035
  React.createElement("tbody", null, rounds.map((round, index) => {
3036
+ var _a, _b;
2880
3037
  const winCounts = {};
2881
3038
  if (results[round.players.join(", ")] !== undefined) {
2882
3039
  const currentResults = results[round.players.join(", ")][JSON.stringify(round.parameters)];
2883
3040
  for (const result of currentResults) {
2884
- const winner = round.players[result[0]];
3041
+ const winner = round.players[result.places[0]];
2885
3042
  if (!winCounts[winner]) {
2886
3043
  winCounts[winner] = 1;
2887
3044
  }
@@ -2899,15 +3056,18 @@ const Round = () => {
2899
3056
  React.createElement("td", null, round.players.map((player, index) => (React.createElement("img", { key: index, src: `/images/teams/${player.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } })))),
2900
3057
  roundIterations === 1 && (React.createElement(React.Fragment, null,
2901
3058
  React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
2902
- results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
3059
+ results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_a = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]]) === null || _a === void 0 ? void 0 : _a.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
2903
3060
  React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
2904
- results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
3061
+ results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_b = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]]) === null || _b === void 0 ? void 0 : _b.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
2905
3062
  roundIterations !== 1 && (React.createElement("td", null, winners.map((winner, index) => (React.createElement("p", { key: index },
2906
3063
  winner,
2907
3064
  ": ",
2908
3065
  winCounts[winner]))))),
2909
3066
  React.createElement("td", null,
2910
3067
  React.createElement(core.Button.Group, { orientation: "vertical" },
3068
+ React.createElement(core.Button, { leftSection: React.createElement("i", { className: "fa-solid fa-hand-pointer" }), size: "xs", onClick: () => {
3069
+ setLocalStorage("Current Round", index);
3070
+ } }, "Select"),
2911
3071
  React.createElement(core.Button, { leftSection: React.createElement("i", { className: "fa-solid fa-play" }), size: "xs", onClick: () => navigate(`/simulation/${round.players.map(encodeURIComponent).join(",")}?showcase=true&${Object.keys(round.parameters)
2912
3072
  .map((p) => `${p}=${encodeURIComponent(round.parameters[p])}`)
2913
3073
  .join("&")}`) }, "Simulate"),
@@ -2981,7 +3141,8 @@ const Round = () => {
2981
3141
  flexDirection: clientWidth >= 700 ? "row" : "column",
2982
3142
  } },
2983
3143
  React.createElement(TournamentBlock, { title: "Before", inline: true }),
2984
- React.createElement(TournamentBlock, { title: "After", inline: true, pointModifier: pointModifier }))))));
3144
+ React.createElement(TournamentBlock, { title: "After", inline: true, pointModifier: pointModifier }))),
3145
+ React.createElement(ResultStatisticsTable, null))));
2985
3146
  };
2986
3147
 
2987
3148
  const SettingsPage = () => {
@@ -3417,7 +3578,7 @@ const TopPane = () => {
3417
3578
  };
3418
3579
 
3419
3580
  const CodeBattles = ({ configuration, routes, blocks }) => {
3420
- var _a, _b, _c, _d, _e, _f, _g, _h;
3581
+ var _a, _b, _c, _d, _e, _f;
3421
3582
  const colorScheme = hooks.useColorScheme();
3422
3583
  const firebase = app.initializeApp(configuration.firebase);
3423
3584
  const firestore$1 = firestore.getFirestore(firebase);
@@ -3428,7 +3589,6 @@ const CodeBattles = ({ configuration, routes, blocks }) => {
3428
3589
  locale: (_b = (_a = configuration.dates) === null || _a === void 0 ? void 0 : _a.locale) !== null && _b !== void 0 ? _b : "en",
3429
3590
  firstDayOfWeek: (_d = (_c = configuration.dates) === null || _c === void 0 ? void 0 : _c.firstDayOfWeek) !== null && _d !== void 0 ? _d : 0,
3430
3591
  weekendDays: (_f = (_e = configuration.dates) === null || _e === void 0 ? void 0 : _e.weekendDays) !== null && _f !== void 0 ? _f : [],
3431
- timezone: (_h = (_g = configuration.dates) === null || _g === void 0 ? void 0 : _g.timezone) !== null && _h !== void 0 ? _h : "UTC",
3432
3592
  } },
3433
3593
  React.createElement(reactRouterDom.BrowserRouter, null,
3434
3594
  React.createElement(notifications.Notifications, null),
@@ -3465,2272 +3625,2303 @@ const CodeBattles = ({ configuration, routes, blocks }) => {
3465
3625
 
3466
3626
  var prism = {exports: {}};
3467
3627
 
3468
- (function (module) {
3469
- /* **********************************************
3470
- Begin prism-core.js
3471
- ********************************************** */
3472
-
3473
- /// <reference lib="WebWorker"/>
3628
+ var hasRequiredPrism;
3474
3629
 
3475
- var _self = (typeof window !== 'undefined')
3476
- ? window // if in browser
3477
- : (
3478
- (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
3479
- ? self // if in worker
3480
- : {} // if in node js
3481
- );
3630
+ function requirePrism () {
3631
+ if (hasRequiredPrism) return prism.exports;
3632
+ hasRequiredPrism = 1;
3633
+ (function (module) {
3634
+ /* **********************************************
3635
+ Begin prism-core.js
3636
+ ********************************************** */
3482
3637
 
3483
- /**
3484
- * Prism: Lightweight, robust, elegant syntax highlighting
3485
- *
3486
- * @license MIT <https://opensource.org/licenses/MIT>
3487
- * @author Lea Verou <https://lea.verou.me>
3488
- * @namespace
3489
- * @public
3490
- */
3491
- var Prism = (function (_self) {
3638
+ /// <reference lib="WebWorker"/>
3492
3639
 
3493
- // Private helper vars
3494
- var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
3495
- var uniqueId = 0;
3640
+ var _self = (typeof window !== 'undefined')
3641
+ ? window // if in browser
3642
+ : (
3643
+ (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
3644
+ ? self // if in worker
3645
+ : {} // if in node js
3646
+ );
3496
3647
 
3497
- // The grammar object for plaintext
3498
- var plainTextGrammar = {};
3648
+ /**
3649
+ * Prism: Lightweight, robust, elegant syntax highlighting
3650
+ *
3651
+ * @license MIT <https://opensource.org/licenses/MIT>
3652
+ * @author Lea Verou <https://lea.verou.me>
3653
+ * @namespace
3654
+ * @public
3655
+ */
3656
+ var Prism = (function (_self) {
3499
3657
 
3658
+ // Private helper vars
3659
+ var lang = /(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i;
3660
+ var uniqueId = 0;
3500
3661
 
3501
- var _ = {
3502
- /**
3503
- * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
3504
- * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
3505
- * additional languages or plugins yourself.
3506
- *
3507
- * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
3508
- *
3509
- * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
3510
- * empty Prism object into the global scope before loading the Prism script like this:
3511
- *
3512
- * ```js
3513
- * window.Prism = window.Prism || {};
3514
- * Prism.manual = true;
3515
- * // add a new <script> to load Prism's script
3516
- * ```
3517
- *
3518
- * @default false
3519
- * @type {boolean}
3520
- * @memberof Prism
3521
- * @public
3522
- */
3523
- manual: _self.Prism && _self.Prism.manual,
3524
- /**
3525
- * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
3526
- * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
3527
- * own worker, you don't want it to do this.
3528
- *
3529
- * By setting this value to `true`, Prism will not add its own listeners to the worker.
3530
- *
3531
- * You obviously have to change this value before Prism executes. To do this, you can add an
3532
- * empty Prism object into the global scope before loading the Prism script like this:
3533
- *
3534
- * ```js
3535
- * window.Prism = window.Prism || {};
3536
- * Prism.disableWorkerMessageHandler = true;
3537
- * // Load Prism's script
3538
- * ```
3539
- *
3540
- * @default false
3541
- * @type {boolean}
3542
- * @memberof Prism
3543
- * @public
3544
- */
3545
- disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
3662
+ // The grammar object for plaintext
3663
+ var plainTextGrammar = {};
3546
3664
 
3547
- /**
3548
- * A namespace for utility methods.
3549
- *
3550
- * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
3551
- * change or disappear at any time.
3552
- *
3553
- * @namespace
3554
- * @memberof Prism
3555
- */
3556
- util: {
3557
- encode: function encode(tokens) {
3558
- if (tokens instanceof Token) {
3559
- return new Token(tokens.type, encode(tokens.content), tokens.alias);
3560
- } else if (Array.isArray(tokens)) {
3561
- return tokens.map(encode);
3562
- } else {
3563
- return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
3564
- }
3565
- },
3566
3665
 
3666
+ var _ = {
3567
3667
  /**
3568
- * Returns the name of the type of the given value.
3668
+ * By default, Prism will attempt to highlight all code elements (by calling {@link Prism.highlightAll}) on the
3669
+ * current page after the page finished loading. This might be a problem if e.g. you wanted to asynchronously load
3670
+ * additional languages or plugins yourself.
3569
3671
  *
3570
- * @param {any} o
3571
- * @returns {string}
3572
- * @example
3573
- * type(null) === 'Null'
3574
- * type(undefined) === 'Undefined'
3575
- * type(123) === 'Number'
3576
- * type('foo') === 'String'
3577
- * type(true) === 'Boolean'
3578
- * type([1, 2]) === 'Array'
3579
- * type({}) === 'Object'
3580
- * type(String) === 'Function'
3581
- * type(/abc+/) === 'RegExp'
3672
+ * By setting this value to `true`, Prism will not automatically highlight all code elements on the page.
3673
+ *
3674
+ * You obviously have to change this value before the automatic highlighting started. To do this, you can add an
3675
+ * empty Prism object into the global scope before loading the Prism script like this:
3676
+ *
3677
+ * ```js
3678
+ * window.Prism = window.Prism || {};
3679
+ * Prism.manual = true;
3680
+ * // add a new <script> to load Prism's script
3681
+ * ```
3682
+ *
3683
+ * @default false
3684
+ * @type {boolean}
3685
+ * @memberof Prism
3686
+ * @public
3582
3687
  */
3583
- type: function (o) {
3584
- return Object.prototype.toString.call(o).slice(8, -1);
3585
- },
3586
-
3688
+ manual: _self.Prism && _self.Prism.manual,
3587
3689
  /**
3588
- * Returns a unique number for the given object. Later calls will still return the same number.
3690
+ * By default, if Prism is in a web worker, it assumes that it is in a worker it created itself, so it uses
3691
+ * `addEventListener` to communicate with its parent instance. However, if you're using Prism manually in your
3692
+ * own worker, you don't want it to do this.
3693
+ *
3694
+ * By setting this value to `true`, Prism will not add its own listeners to the worker.
3695
+ *
3696
+ * You obviously have to change this value before Prism executes. To do this, you can add an
3697
+ * empty Prism object into the global scope before loading the Prism script like this:
3698
+ *
3699
+ * ```js
3700
+ * window.Prism = window.Prism || {};
3701
+ * Prism.disableWorkerMessageHandler = true;
3702
+ * // Load Prism's script
3703
+ * ```
3589
3704
  *
3590
- * @param {Object} obj
3591
- * @returns {number}
3705
+ * @default false
3706
+ * @type {boolean}
3707
+ * @memberof Prism
3708
+ * @public
3592
3709
  */
3593
- objId: function (obj) {
3594
- if (!obj['__id']) {
3595
- Object.defineProperty(obj, '__id', { value: ++uniqueId });
3596
- }
3597
- return obj['__id'];
3598
- },
3710
+ disableWorkerMessageHandler: _self.Prism && _self.Prism.disableWorkerMessageHandler,
3599
3711
 
3600
3712
  /**
3601
- * Creates a deep clone of the given object.
3713
+ * A namespace for utility methods.
3602
3714
  *
3603
- * The main intended use of this function is to clone language definitions.
3715
+ * All function in this namespace that are not explicitly marked as _public_ are for __internal use only__ and may
3716
+ * change or disappear at any time.
3604
3717
  *
3605
- * @param {T} o
3606
- * @param {Record<number, any>} [visited]
3607
- * @returns {T}
3608
- * @template T
3718
+ * @namespace
3719
+ * @memberof Prism
3609
3720
  */
3610
- clone: function deepClone(o, visited) {
3611
- visited = visited || {};
3612
-
3613
- var clone; var id;
3614
- switch (_.util.type(o)) {
3615
- case 'Object':
3616
- id = _.util.objId(o);
3617
- if (visited[id]) {
3618
- return visited[id];
3619
- }
3620
- clone = /** @type {Record<string, any>} */ ({});
3621
- visited[id] = clone;
3721
+ util: {
3722
+ encode: function encode(tokens) {
3723
+ if (tokens instanceof Token) {
3724
+ return new Token(tokens.type, encode(tokens.content), tokens.alias);
3725
+ } else if (Array.isArray(tokens)) {
3726
+ return tokens.map(encode);
3727
+ } else {
3728
+ return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
3729
+ }
3730
+ },
3731
+
3732
+ /**
3733
+ * Returns the name of the type of the given value.
3734
+ *
3735
+ * @param {any} o
3736
+ * @returns {string}
3737
+ * @example
3738
+ * type(null) === 'Null'
3739
+ * type(undefined) === 'Undefined'
3740
+ * type(123) === 'Number'
3741
+ * type('foo') === 'String'
3742
+ * type(true) === 'Boolean'
3743
+ * type([1, 2]) === 'Array'
3744
+ * type({}) === 'Object'
3745
+ * type(String) === 'Function'
3746
+ * type(/abc+/) === 'RegExp'
3747
+ */
3748
+ type: function (o) {
3749
+ return Object.prototype.toString.call(o).slice(8, -1);
3750
+ },
3751
+
3752
+ /**
3753
+ * Returns a unique number for the given object. Later calls will still return the same number.
3754
+ *
3755
+ * @param {Object} obj
3756
+ * @returns {number}
3757
+ */
3758
+ objId: function (obj) {
3759
+ if (!obj['__id']) {
3760
+ Object.defineProperty(obj, '__id', { value: ++uniqueId });
3761
+ }
3762
+ return obj['__id'];
3763
+ },
3622
3764
 
3623
- for (var key in o) {
3624
- if (o.hasOwnProperty(key)) {
3625
- clone[key] = deepClone(o[key], visited);
3765
+ /**
3766
+ * Creates a deep clone of the given object.
3767
+ *
3768
+ * The main intended use of this function is to clone language definitions.
3769
+ *
3770
+ * @param {T} o
3771
+ * @param {Record<number, any>} [visited]
3772
+ * @returns {T}
3773
+ * @template T
3774
+ */
3775
+ clone: function deepClone(o, visited) {
3776
+ visited = visited || {};
3777
+
3778
+ var clone; var id;
3779
+ switch (_.util.type(o)) {
3780
+ case 'Object':
3781
+ id = _.util.objId(o);
3782
+ if (visited[id]) {
3783
+ return visited[id];
3784
+ }
3785
+ clone = /** @type {Record<string, any>} */ ({});
3786
+ visited[id] = clone;
3787
+
3788
+ for (var key in o) {
3789
+ if (o.hasOwnProperty(key)) {
3790
+ clone[key] = deepClone(o[key], visited);
3791
+ }
3626
3792
  }
3627
- }
3628
3793
 
3629
- return /** @type {any} */ (clone);
3794
+ return /** @type {any} */ (clone);
3630
3795
 
3631
- case 'Array':
3632
- id = _.util.objId(o);
3633
- if (visited[id]) {
3634
- return visited[id];
3796
+ case 'Array':
3797
+ id = _.util.objId(o);
3798
+ if (visited[id]) {
3799
+ return visited[id];
3800
+ }
3801
+ clone = [];
3802
+ visited[id] = clone;
3803
+
3804
+ (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
3805
+ clone[i] = deepClone(v, visited);
3806
+ });
3807
+
3808
+ return /** @type {any} */ (clone);
3809
+
3810
+ default:
3811
+ return o;
3812
+ }
3813
+ },
3814
+
3815
+ /**
3816
+ * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
3817
+ *
3818
+ * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
3819
+ *
3820
+ * @param {Element} element
3821
+ * @returns {string}
3822
+ */
3823
+ getLanguage: function (element) {
3824
+ while (element) {
3825
+ var m = lang.exec(element.className);
3826
+ if (m) {
3827
+ return m[1].toLowerCase();
3635
3828
  }
3636
- clone = [];
3637
- visited[id] = clone;
3829
+ element = element.parentElement;
3830
+ }
3831
+ return 'none';
3832
+ },
3833
+
3834
+ /**
3835
+ * Sets the Prism `language-xxxx` class of the given element.
3836
+ *
3837
+ * @param {Element} element
3838
+ * @param {string} language
3839
+ * @returns {void}
3840
+ */
3841
+ setLanguage: function (element, language) {
3842
+ // remove all `language-xxxx` classes
3843
+ // (this might leave behind a leading space)
3844
+ element.className = element.className.replace(RegExp(lang, 'gi'), '');
3845
+
3846
+ // add the new `language-xxxx` class
3847
+ // (using `classList` will automatically clean up spaces for us)
3848
+ element.classList.add('language-' + language);
3849
+ },
3638
3850
 
3639
- (/** @type {Array} */(/** @type {any} */(o))).forEach(function (v, i) {
3640
- clone[i] = deepClone(v, visited);
3641
- });
3851
+ /**
3852
+ * Returns the script element that is currently executing.
3853
+ *
3854
+ * This does __not__ work for line script element.
3855
+ *
3856
+ * @returns {HTMLScriptElement | null}
3857
+ */
3858
+ currentScript: function () {
3859
+ if (typeof document === 'undefined') {
3860
+ return null;
3861
+ }
3862
+ if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
3863
+ return /** @type {any} */ (document.currentScript);
3864
+ }
3642
3865
 
3643
- return /** @type {any} */ (clone);
3866
+ // IE11 workaround
3867
+ // we'll get the src of the current script by parsing IE11's error stack trace
3868
+ // this will not work for inline scripts
3869
+
3870
+ try {
3871
+ throw new Error();
3872
+ } catch (err) {
3873
+ // Get file src url from stack. Specifically works with the format of stack traces in IE.
3874
+ // A stack will look like this:
3875
+ //
3876
+ // Error
3877
+ // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
3878
+ // at Global code (http://localhost/components/prism-core.js:606:1)
3879
+
3880
+ var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
3881
+ if (src) {
3882
+ var scripts = document.getElementsByTagName('script');
3883
+ for (var i in scripts) {
3884
+ if (scripts[i].src == src) {
3885
+ return scripts[i];
3886
+ }
3887
+ }
3888
+ }
3889
+ return null;
3890
+ }
3891
+ },
3644
3892
 
3645
- default:
3646
- return o;
3893
+ /**
3894
+ * Returns whether a given class is active for `element`.
3895
+ *
3896
+ * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
3897
+ * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
3898
+ * given class is just the given class with a `no-` prefix.
3899
+ *
3900
+ * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
3901
+ * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
3902
+ * ancestors have the given class or the negated version of it, then the default activation will be returned.
3903
+ *
3904
+ * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
3905
+ * version of it, the class is considered active.
3906
+ *
3907
+ * @param {Element} element
3908
+ * @param {string} className
3909
+ * @param {boolean} [defaultActivation=false]
3910
+ * @returns {boolean}
3911
+ */
3912
+ isActive: function (element, className, defaultActivation) {
3913
+ var no = 'no-' + className;
3914
+
3915
+ while (element) {
3916
+ var classList = element.classList;
3917
+ if (classList.contains(className)) {
3918
+ return true;
3919
+ }
3920
+ if (classList.contains(no)) {
3921
+ return false;
3922
+ }
3923
+ element = element.parentElement;
3924
+ }
3925
+ return !!defaultActivation;
3647
3926
  }
3648
3927
  },
3649
3928
 
3650
3929
  /**
3651
- * Returns the Prism language of the given element set by a `language-xxxx` or `lang-xxxx` class.
3652
- *
3653
- * If no language is set for the element or the element is `null` or `undefined`, `none` will be returned.
3930
+ * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
3654
3931
  *
3655
- * @param {Element} element
3656
- * @returns {string}
3932
+ * @namespace
3933
+ * @memberof Prism
3934
+ * @public
3657
3935
  */
3658
- getLanguage: function (element) {
3659
- while (element) {
3660
- var m = lang.exec(element.className);
3661
- if (m) {
3662
- return m[1].toLowerCase();
3936
+ languages: {
3937
+ /**
3938
+ * The grammar for plain, unformatted text.
3939
+ */
3940
+ plain: plainTextGrammar,
3941
+ plaintext: plainTextGrammar,
3942
+ text: plainTextGrammar,
3943
+ txt: plainTextGrammar,
3944
+
3945
+ /**
3946
+ * Creates a deep copy of the language with the given id and appends the given tokens.
3947
+ *
3948
+ * If a token in `redef` also appears in the copied language, then the existing token in the copied language
3949
+ * will be overwritten at its original position.
3950
+ *
3951
+ * ## Best practices
3952
+ *
3953
+ * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
3954
+ * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
3955
+ * understand the language definition because, normally, the order of tokens matters in Prism grammars.
3956
+ *
3957
+ * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
3958
+ * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
3959
+ *
3960
+ * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
3961
+ * @param {Grammar} redef The new tokens to append.
3962
+ * @returns {Grammar} The new language created.
3963
+ * @public
3964
+ * @example
3965
+ * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
3966
+ * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
3967
+ * // at its original position
3968
+ * 'comment': { ... },
3969
+ * // CSS doesn't have a 'color' token, so this token will be appended
3970
+ * 'color': /\b(?:red|green|blue)\b/
3971
+ * });
3972
+ */
3973
+ extend: function (id, redef) {
3974
+ var lang = _.util.clone(_.languages[id]);
3975
+
3976
+ for (var key in redef) {
3977
+ lang[key] = redef[key];
3978
+ }
3979
+
3980
+ return lang;
3981
+ },
3982
+
3983
+ /**
3984
+ * Inserts tokens _before_ another token in a language definition or any other grammar.
3985
+ *
3986
+ * ## Usage
3987
+ *
3988
+ * This helper method makes it easy to modify existing languages. For example, the CSS language definition
3989
+ * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
3990
+ * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
3991
+ * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
3992
+ * this:
3993
+ *
3994
+ * ```js
3995
+ * Prism.languages.markup.style = {
3996
+ * // token
3997
+ * };
3998
+ * ```
3999
+ *
4000
+ * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
4001
+ * before existing tokens. For the CSS example above, you would use it like this:
4002
+ *
4003
+ * ```js
4004
+ * Prism.languages.insertBefore('markup', 'cdata', {
4005
+ * 'style': {
4006
+ * // token
4007
+ * }
4008
+ * });
4009
+ * ```
4010
+ *
4011
+ * ## Special cases
4012
+ *
4013
+ * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
4014
+ * will be ignored.
4015
+ *
4016
+ * This behavior can be used to insert tokens after `before`:
4017
+ *
4018
+ * ```js
4019
+ * Prism.languages.insertBefore('markup', 'comment', {
4020
+ * 'comment': Prism.languages.markup.comment,
4021
+ * // tokens after 'comment'
4022
+ * });
4023
+ * ```
4024
+ *
4025
+ * ## Limitations
4026
+ *
4027
+ * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
4028
+ * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
4029
+ * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
4030
+ * deleting properties which is necessary to insert at arbitrary positions.
4031
+ *
4032
+ * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
4033
+ * Instead, it will create a new object and replace all references to the target object with the new one. This
4034
+ * can be done without temporarily deleting properties, so the iteration order is well-defined.
4035
+ *
4036
+ * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
4037
+ * you hold the target object in a variable, then the value of the variable will not change.
4038
+ *
4039
+ * ```js
4040
+ * var oldMarkup = Prism.languages.markup;
4041
+ * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
4042
+ *
4043
+ * assert(oldMarkup !== Prism.languages.markup);
4044
+ * assert(newMarkup === Prism.languages.markup);
4045
+ * ```
4046
+ *
4047
+ * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
4048
+ * object to be modified.
4049
+ * @param {string} before The key to insert before.
4050
+ * @param {Grammar} insert An object containing the key-value pairs to be inserted.
4051
+ * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
4052
+ * object to be modified.
4053
+ *
4054
+ * Defaults to `Prism.languages`.
4055
+ * @returns {Grammar} The new grammar object.
4056
+ * @public
4057
+ */
4058
+ insertBefore: function (inside, before, insert, root) {
4059
+ root = root || /** @type {any} */ (_.languages);
4060
+ var grammar = root[inside];
4061
+ /** @type {Grammar} */
4062
+ var ret = {};
4063
+
4064
+ for (var token in grammar) {
4065
+ if (grammar.hasOwnProperty(token)) {
4066
+
4067
+ if (token == before) {
4068
+ for (var newToken in insert) {
4069
+ if (insert.hasOwnProperty(newToken)) {
4070
+ ret[newToken] = insert[newToken];
4071
+ }
4072
+ }
4073
+ }
4074
+
4075
+ // Do not insert token which also occur in insert. See #1525
4076
+ if (!insert.hasOwnProperty(token)) {
4077
+ ret[token] = grammar[token];
4078
+ }
4079
+ }
4080
+ }
4081
+
4082
+ var old = root[inside];
4083
+ root[inside] = ret;
4084
+
4085
+ // Update references in other language definitions
4086
+ _.languages.DFS(_.languages, function (key, value) {
4087
+ if (value === old && key != inside) {
4088
+ this[key] = ret;
4089
+ }
4090
+ });
4091
+
4092
+ return ret;
4093
+ },
4094
+
4095
+ // Traverse a language definition with Depth First Search
4096
+ DFS: function DFS(o, callback, type, visited) {
4097
+ visited = visited || {};
4098
+
4099
+ var objId = _.util.objId;
4100
+
4101
+ for (var i in o) {
4102
+ if (o.hasOwnProperty(i)) {
4103
+ callback.call(o, i, o[i], type || i);
4104
+
4105
+ var property = o[i];
4106
+ var propertyType = _.util.type(property);
4107
+
4108
+ if (propertyType === 'Object' && !visited[objId(property)]) {
4109
+ visited[objId(property)] = true;
4110
+ DFS(property, callback, null, visited);
4111
+ } else if (propertyType === 'Array' && !visited[objId(property)]) {
4112
+ visited[objId(property)] = true;
4113
+ DFS(property, callback, i, visited);
4114
+ }
4115
+ }
3663
4116
  }
3664
- element = element.parentElement;
3665
4117
  }
3666
- return 'none';
3667
4118
  },
3668
4119
 
4120
+ plugins: {},
4121
+
3669
4122
  /**
3670
- * Sets the Prism `language-xxxx` class of the given element.
4123
+ * This is the most high-level function in Prism’s API.
4124
+ * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
4125
+ * each one of them.
3671
4126
  *
3672
- * @param {Element} element
3673
- * @param {string} language
3674
- * @returns {void}
4127
+ * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
4128
+ *
4129
+ * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
4130
+ * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
4131
+ * @memberof Prism
4132
+ * @public
3675
4133
  */
3676
- setLanguage: function (element, language) {
3677
- // remove all `language-xxxx` classes
3678
- // (this might leave behind a leading space)
3679
- element.className = element.className.replace(RegExp(lang, 'gi'), '');
3680
-
3681
- // add the new `language-xxxx` class
3682
- // (using `classList` will automatically clean up spaces for us)
3683
- element.classList.add('language-' + language);
4134
+ highlightAll: function (async, callback) {
4135
+ _.highlightAllUnder(document, async, callback);
3684
4136
  },
3685
4137
 
3686
4138
  /**
3687
- * Returns the script element that is currently executing.
4139
+ * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
4140
+ * {@link Prism.highlightElement} on each one of them.
3688
4141
  *
3689
- * This does __not__ work for line script element.
4142
+ * The following hooks will be run:
4143
+ * 1. `before-highlightall`
4144
+ * 2. `before-all-elements-highlight`
4145
+ * 3. All hooks of {@link Prism.highlightElement} for each element.
3690
4146
  *
3691
- * @returns {HTMLScriptElement | null}
4147
+ * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
4148
+ * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
4149
+ * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
4150
+ * @memberof Prism
4151
+ * @public
3692
4152
  */
3693
- currentScript: function () {
3694
- if (typeof document === 'undefined') {
3695
- return null;
3696
- }
3697
- if (document.currentScript && document.currentScript.tagName === 'SCRIPT' && 1 < 2 /* hack to trip TS' flow analysis */) {
3698
- return /** @type {any} */ (document.currentScript);
3699
- }
4153
+ highlightAllUnder: function (container, async, callback) {
4154
+ var env = {
4155
+ callback: callback,
4156
+ container: container,
4157
+ selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
4158
+ };
3700
4159
 
3701
- // IE11 workaround
3702
- // we'll get the src of the current script by parsing IE11's error stack trace
3703
- // this will not work for inline scripts
3704
-
3705
- try {
3706
- throw new Error();
3707
- } catch (err) {
3708
- // Get file src url from stack. Specifically works with the format of stack traces in IE.
3709
- // A stack will look like this:
3710
- //
3711
- // Error
3712
- // at _.util.currentScript (http://localhost/components/prism-core.js:119:5)
3713
- // at Global code (http://localhost/components/prism-core.js:606:1)
3714
-
3715
- var src = (/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(err.stack) || [])[1];
3716
- if (src) {
3717
- var scripts = document.getElementsByTagName('script');
3718
- for (var i in scripts) {
3719
- if (scripts[i].src == src) {
3720
- return scripts[i];
3721
- }
3722
- }
3723
- }
3724
- return null;
4160
+ _.hooks.run('before-highlightall', env);
4161
+
4162
+ env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
4163
+
4164
+ _.hooks.run('before-all-elements-highlight', env);
4165
+
4166
+ for (var i = 0, element; (element = env.elements[i++]);) {
4167
+ _.highlightElement(element, async === true, env.callback);
3725
4168
  }
3726
4169
  },
3727
4170
 
3728
4171
  /**
3729
- * Returns whether a given class is active for `element`.
4172
+ * Highlights the code inside a single element.
3730
4173
  *
3731
- * The class can be activated if `element` or one of its ancestors has the given class and it can be deactivated
3732
- * if `element` or one of its ancestors has the negated version of the given class. The _negated version_ of the
3733
- * given class is just the given class with a `no-` prefix.
4174
+ * The following hooks will be run:
4175
+ * 1. `before-sanity-check`
4176
+ * 2. `before-highlight`
4177
+ * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
4178
+ * 4. `before-insert`
4179
+ * 5. `after-highlight`
4180
+ * 6. `complete`
3734
4181
  *
3735
- * Whether the class is active is determined by the closest ancestor of `element` (where `element` itself is
3736
- * closest ancestor) that has the given class or the negated version of it. If neither `element` nor any of its
3737
- * ancestors have the given class or the negated version of it, then the default activation will be returned.
4182
+ * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
4183
+ * the element's language.
3738
4184
  *
3739
- * In the paradoxical situation where the closest ancestor contains __both__ the given class and the negated
3740
- * version of it, the class is considered active.
4185
+ * @param {Element} element The element containing the code.
4186
+ * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
4187
+ * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
4188
+ * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
4189
+ * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
3741
4190
  *
3742
- * @param {Element} element
3743
- * @param {string} className
3744
- * @param {boolean} [defaultActivation=false]
3745
- * @returns {boolean}
4191
+ * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
4192
+ * asynchronous highlighting to work. You can build your own bundle on the
4193
+ * [Download page](https://prismjs.com/download.html).
4194
+ * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
4195
+ * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
4196
+ * @memberof Prism
4197
+ * @public
3746
4198
  */
3747
- isActive: function (element, className, defaultActivation) {
3748
- var no = 'no-' + className;
4199
+ highlightElement: function (element, async, callback) {
4200
+ // Find language
4201
+ var language = _.util.getLanguage(element);
4202
+ var grammar = _.languages[language];
4203
+
4204
+ // Set language on the element, if not present
4205
+ _.util.setLanguage(element, language);
4206
+
4207
+ // Set language on the parent, for styling
4208
+ var parent = element.parentElement;
4209
+ if (parent && parent.nodeName.toLowerCase() === 'pre') {
4210
+ _.util.setLanguage(parent, language);
4211
+ }
3749
4212
 
3750
- while (element) {
3751
- var classList = element.classList;
3752
- if (classList.contains(className)) {
3753
- return true;
3754
- }
3755
- if (classList.contains(no)) {
3756
- return false;
3757
- }
3758
- element = element.parentElement;
4213
+ var code = element.textContent;
4214
+
4215
+ var env = {
4216
+ element: element,
4217
+ language: language,
4218
+ grammar: grammar,
4219
+ code: code
4220
+ };
4221
+
4222
+ function insertHighlightedCode(highlightedCode) {
4223
+ env.highlightedCode = highlightedCode;
4224
+
4225
+ _.hooks.run('before-insert', env);
4226
+
4227
+ env.element.innerHTML = env.highlightedCode;
4228
+
4229
+ _.hooks.run('after-highlight', env);
4230
+ _.hooks.run('complete', env);
4231
+ callback && callback.call(env.element);
3759
4232
  }
3760
- return !!defaultActivation;
3761
- }
3762
- },
3763
4233
 
3764
- /**
3765
- * This namespace contains all currently loaded languages and the some helper functions to create and modify languages.
3766
- *
3767
- * @namespace
3768
- * @memberof Prism
3769
- * @public
3770
- */
3771
- languages: {
3772
- /**
3773
- * The grammar for plain, unformatted text.
3774
- */
3775
- plain: plainTextGrammar,
3776
- plaintext: plainTextGrammar,
3777
- text: plainTextGrammar,
3778
- txt: plainTextGrammar,
4234
+ _.hooks.run('before-sanity-check', env);
4235
+
4236
+ // plugins may change/add the parent/element
4237
+ parent = env.element.parentElement;
4238
+ if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
4239
+ parent.setAttribute('tabindex', '0');
4240
+ }
4241
+
4242
+ if (!env.code) {
4243
+ _.hooks.run('complete', env);
4244
+ callback && callback.call(env.element);
4245
+ return;
4246
+ }
4247
+
4248
+ _.hooks.run('before-highlight', env);
4249
+
4250
+ if (!env.grammar) {
4251
+ insertHighlightedCode(_.util.encode(env.code));
4252
+ return;
4253
+ }
4254
+
4255
+ if (async && _self.Worker) {
4256
+ var worker = new Worker(_.filename);
4257
+
4258
+ worker.onmessage = function (evt) {
4259
+ insertHighlightedCode(evt.data);
4260
+ };
4261
+
4262
+ worker.postMessage(JSON.stringify({
4263
+ language: env.language,
4264
+ code: env.code,
4265
+ immediateClose: true
4266
+ }));
4267
+ } else {
4268
+ insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
4269
+ }
4270
+ },
3779
4271
 
3780
4272
  /**
3781
- * Creates a deep copy of the language with the given id and appends the given tokens.
3782
- *
3783
- * If a token in `redef` also appears in the copied language, then the existing token in the copied language
3784
- * will be overwritten at its original position.
4273
+ * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
4274
+ * and the language definitions to use, and returns a string with the HTML produced.
3785
4275
  *
3786
- * ## Best practices
4276
+ * The following hooks will be run:
4277
+ * 1. `before-tokenize`
4278
+ * 2. `after-tokenize`
4279
+ * 3. `wrap`: On each {@link Token}.
3787
4280
  *
3788
- * Since the position of overwriting tokens (token in `redef` that overwrite tokens in the copied language)
3789
- * doesn't matter, they can technically be in any order. However, this can be confusing to others that trying to
3790
- * understand the language definition because, normally, the order of tokens matters in Prism grammars.
4281
+ * @param {string} text A string with the code to be highlighted.
4282
+ * @param {Grammar} grammar An object containing the tokens to use.
3791
4283
  *
3792
- * Therefore, it is encouraged to order overwriting tokens according to the positions of the overwritten tokens.
3793
- * Furthermore, all non-overwriting tokens should be placed after the overwriting ones.
3794
- *
3795
- * @param {string} id The id of the language to extend. This has to be a key in `Prism.languages`.
3796
- * @param {Grammar} redef The new tokens to append.
3797
- * @returns {Grammar} The new language created.
4284
+ * Usually a language definition like `Prism.languages.markup`.
4285
+ * @param {string} language The name of the language definition passed to `grammar`.
4286
+ * @returns {string} The highlighted HTML.
4287
+ * @memberof Prism
3798
4288
  * @public
3799
4289
  * @example
3800
- * Prism.languages['css-with-colors'] = Prism.languages.extend('css', {
3801
- * // Prism.languages.css already has a 'comment' token, so this token will overwrite CSS' 'comment' token
3802
- * // at its original position
3803
- * 'comment': { ... },
3804
- * // CSS doesn't have a 'color' token, so this token will be appended
3805
- * 'color': /\b(?:red|green|blue)\b/
3806
- * });
4290
+ * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
3807
4291
  */
3808
- extend: function (id, redef) {
3809
- var lang = _.util.clone(_.languages[id]);
3810
-
3811
- for (var key in redef) {
3812
- lang[key] = redef[key];
4292
+ highlight: function (text, grammar, language) {
4293
+ var env = {
4294
+ code: text,
4295
+ grammar: grammar,
4296
+ language: language
4297
+ };
4298
+ _.hooks.run('before-tokenize', env);
4299
+ if (!env.grammar) {
4300
+ throw new Error('The language "' + env.language + '" has no grammar.');
3813
4301
  }
3814
-
3815
- return lang;
4302
+ env.tokens = _.tokenize(env.code, env.grammar);
4303
+ _.hooks.run('after-tokenize', env);
4304
+ return Token.stringify(_.util.encode(env.tokens), env.language);
3816
4305
  },
3817
4306
 
3818
4307
  /**
3819
- * Inserts tokens _before_ another token in a language definition or any other grammar.
3820
- *
3821
- * ## Usage
4308
+ * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
4309
+ * and the language definitions to use, and returns an array with the tokenized code.
3822
4310
  *
3823
- * This helper method makes it easy to modify existing languages. For example, the CSS language definition
3824
- * not only defines CSS highlighting for CSS documents, but also needs to define highlighting for CSS embedded
3825
- * in HTML through `<style>` elements. To do this, it needs to modify `Prism.languages.markup` and add the
3826
- * appropriate tokens. However, `Prism.languages.markup` is a regular JavaScript object literal, so if you do
3827
- * this:
4311
+ * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
3828
4312
  *
3829
- * ```js
3830
- * Prism.languages.markup.style = {
3831
- * // token
3832
- * };
3833
- * ```
4313
+ * This method could be useful in other contexts as well, as a very crude parser.
3834
4314
  *
3835
- * then the `style` token will be added (and processed) at the end. `insertBefore` allows you to insert tokens
3836
- * before existing tokens. For the CSS example above, you would use it like this:
4315
+ * @param {string} text A string with the code to be highlighted.
4316
+ * @param {Grammar} grammar An object containing the tokens to use.
3837
4317
  *
3838
- * ```js
3839
- * Prism.languages.insertBefore('markup', 'cdata', {
3840
- * 'style': {
3841
- * // token
4318
+ * Usually a language definition like `Prism.languages.markup`.
4319
+ * @returns {TokenStream} An array of strings and tokens, a token stream.
4320
+ * @memberof Prism
4321
+ * @public
4322
+ * @example
4323
+ * let code = `var foo = 0;`;
4324
+ * let tokens = Prism.tokenize(code, Prism.languages.javascript);
4325
+ * tokens.forEach(token => {
4326
+ * if (token instanceof Prism.Token && token.type === 'number') {
4327
+ * console.log(`Found numeric literal: ${token.content}`);
3842
4328
  * }
3843
4329
  * });
3844
- * ```
3845
- *
3846
- * ## Special cases
3847
- *
3848
- * If the grammars of `inside` and `insert` have tokens with the same name, the tokens in `inside`'s grammar
3849
- * will be ignored.
3850
- *
3851
- * This behavior can be used to insert tokens after `before`:
3852
- *
3853
- * ```js
3854
- * Prism.languages.insertBefore('markup', 'comment', {
3855
- * 'comment': Prism.languages.markup.comment,
3856
- * // tokens after 'comment'
3857
- * });
3858
- * ```
3859
- *
3860
- * ## Limitations
3861
- *
3862
- * The main problem `insertBefore` has to solve is iteration order. Since ES2015, the iteration order for object
3863
- * properties is guaranteed to be the insertion order (except for integer keys) but some browsers behave
3864
- * differently when keys are deleted and re-inserted. So `insertBefore` can't be implemented by temporarily
3865
- * deleting properties which is necessary to insert at arbitrary positions.
3866
- *
3867
- * To solve this problem, `insertBefore` doesn't actually insert the given tokens into the target object.
3868
- * Instead, it will create a new object and replace all references to the target object with the new one. This
3869
- * can be done without temporarily deleting properties, so the iteration order is well-defined.
3870
- *
3871
- * However, only references that can be reached from `Prism.languages` or `insert` will be replaced. I.e. if
3872
- * you hold the target object in a variable, then the value of the variable will not change.
3873
- *
3874
- * ```js
3875
- * var oldMarkup = Prism.languages.markup;
3876
- * var newMarkup = Prism.languages.insertBefore('markup', 'comment', { ... });
3877
- *
3878
- * assert(oldMarkup !== Prism.languages.markup);
3879
- * assert(newMarkup === Prism.languages.markup);
3880
- * ```
3881
- *
3882
- * @param {string} inside The property of `root` (e.g. a language id in `Prism.languages`) that contains the
3883
- * object to be modified.
3884
- * @param {string} before The key to insert before.
3885
- * @param {Grammar} insert An object containing the key-value pairs to be inserted.
3886
- * @param {Object<string, any>} [root] The object containing `inside`, i.e. the object that contains the
3887
- * object to be modified.
3888
- *
3889
- * Defaults to `Prism.languages`.
3890
- * @returns {Grammar} The new grammar object.
3891
- * @public
3892
4330
  */
3893
- insertBefore: function (inside, before, insert, root) {
3894
- root = root || /** @type {any} */ (_.languages);
3895
- var grammar = root[inside];
3896
- /** @type {Grammar} */
3897
- var ret = {};
3898
-
3899
- for (var token in grammar) {
3900
- if (grammar.hasOwnProperty(token)) {
3901
-
3902
- if (token == before) {
3903
- for (var newToken in insert) {
3904
- if (insert.hasOwnProperty(newToken)) {
3905
- ret[newToken] = insert[newToken];
3906
- }
3907
- }
3908
- }
3909
-
3910
- // Do not insert token which also occur in insert. See #1525
3911
- if (!insert.hasOwnProperty(token)) {
3912
- ret[token] = grammar[token];
3913
- }
4331
+ tokenize: function (text, grammar) {
4332
+ var rest = grammar.rest;
4333
+ if (rest) {
4334
+ for (var token in rest) {
4335
+ grammar[token] = rest[token];
3914
4336
  }
4337
+
4338
+ delete grammar.rest;
3915
4339
  }
3916
4340
 
3917
- var old = root[inside];
3918
- root[inside] = ret;
4341
+ var tokenList = new LinkedList();
4342
+ addAfter(tokenList, tokenList.head, text);
3919
4343
 
3920
- // Update references in other language definitions
3921
- _.languages.DFS(_.languages, function (key, value) {
3922
- if (value === old && key != inside) {
3923
- this[key] = ret;
3924
- }
3925
- });
4344
+ matchGrammar(text, tokenList, grammar, tokenList.head, 0);
3926
4345
 
3927
- return ret;
4346
+ return toArray(tokenList);
3928
4347
  },
3929
4348
 
3930
- // Traverse a language definition with Depth First Search
3931
- DFS: function DFS(o, callback, type, visited) {
3932
- visited = visited || {};
3933
-
3934
- var objId = _.util.objId;
3935
-
3936
- for (var i in o) {
3937
- if (o.hasOwnProperty(i)) {
3938
- callback.call(o, i, o[i], type || i);
4349
+ /**
4350
+ * @namespace
4351
+ * @memberof Prism
4352
+ * @public
4353
+ */
4354
+ hooks: {
4355
+ all: {},
4356
+
4357
+ /**
4358
+ * Adds the given callback to the list of callbacks for the given hook.
4359
+ *
4360
+ * The callback will be invoked when the hook it is registered for is run.
4361
+ * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
4362
+ *
4363
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
4364
+ *
4365
+ * @param {string} name The name of the hook.
4366
+ * @param {HookCallback} callback The callback function which is given environment variables.
4367
+ * @public
4368
+ */
4369
+ add: function (name, callback) {
4370
+ var hooks = _.hooks.all;
4371
+
4372
+ hooks[name] = hooks[name] || [];
4373
+
4374
+ hooks[name].push(callback);
4375
+ },
3939
4376
 
3940
- var property = o[i];
3941
- var propertyType = _.util.type(property);
4377
+ /**
4378
+ * Runs a hook invoking all registered callbacks with the given environment variables.
4379
+ *
4380
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
4381
+ *
4382
+ * @param {string} name The name of the hook.
4383
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
4384
+ * @public
4385
+ */
4386
+ run: function (name, env) {
4387
+ var callbacks = _.hooks.all[name];
4388
+
4389
+ if (!callbacks || !callbacks.length) {
4390
+ return;
4391
+ }
3942
4392
 
3943
- if (propertyType === 'Object' && !visited[objId(property)]) {
3944
- visited[objId(property)] = true;
3945
- DFS(property, callback, null, visited);
3946
- } else if (propertyType === 'Array' && !visited[objId(property)]) {
3947
- visited[objId(property)] = true;
3948
- DFS(property, callback, i, visited);
3949
- }
4393
+ for (var i = 0, callback; (callback = callbacks[i++]);) {
4394
+ callback(env);
3950
4395
  }
3951
4396
  }
3952
- }
3953
- },
4397
+ },
3954
4398
 
3955
- plugins: {},
4399
+ Token: Token
4400
+ };
4401
+ _self.Prism = _;
3956
4402
 
3957
- /**
3958
- * This is the most high-level function in Prism’s API.
3959
- * It fetches all the elements that have a `.language-xxxx` class and then calls {@link Prism.highlightElement} on
3960
- * each one of them.
3961
- *
3962
- * This is equivalent to `Prism.highlightAllUnder(document, async, callback)`.
3963
- *
3964
- * @param {boolean} [async=false] Same as in {@link Prism.highlightAllUnder}.
3965
- * @param {HighlightCallback} [callback] Same as in {@link Prism.highlightAllUnder}.
3966
- * @memberof Prism
3967
- * @public
3968
- */
3969
- highlightAll: function (async, callback) {
3970
- _.highlightAllUnder(document, async, callback);
3971
- },
3972
-
3973
- /**
3974
- * Fetches all the descendants of `container` that have a `.language-xxxx` class and then calls
3975
- * {@link Prism.highlightElement} on each one of them.
3976
- *
3977
- * The following hooks will be run:
3978
- * 1. `before-highlightall`
3979
- * 2. `before-all-elements-highlight`
3980
- * 3. All hooks of {@link Prism.highlightElement} for each element.
3981
- *
3982
- * @param {ParentNode} container The root element, whose descendants that have a `.language-xxxx` class will be highlighted.
3983
- * @param {boolean} [async=false] Whether each element is to be highlighted asynchronously using Web Workers.
3984
- * @param {HighlightCallback} [callback] An optional callback to be invoked on each element after its highlighting is done.
3985
- * @memberof Prism
3986
- * @public
3987
- */
3988
- highlightAllUnder: function (container, async, callback) {
3989
- var env = {
3990
- callback: callback,
3991
- container: container,
3992
- selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
3993
- };
3994
-
3995
- _.hooks.run('before-highlightall', env);
3996
-
3997
- env.elements = Array.prototype.slice.apply(env.container.querySelectorAll(env.selector));
3998
-
3999
- _.hooks.run('before-all-elements-highlight', env);
4000
-
4001
- for (var i = 0, element; (element = env.elements[i++]);) {
4002
- _.highlightElement(element, async === true, env.callback);
4003
- }
4004
- },
4005
-
4006
- /**
4007
- * Highlights the code inside a single element.
4008
- *
4009
- * The following hooks will be run:
4010
- * 1. `before-sanity-check`
4011
- * 2. `before-highlight`
4012
- * 3. All hooks of {@link Prism.highlight}. These hooks will be run by an asynchronous worker if `async` is `true`.
4013
- * 4. `before-insert`
4014
- * 5. `after-highlight`
4015
- * 6. `complete`
4016
- *
4017
- * Some the above hooks will be skipped if the element doesn't contain any text or there is no grammar loaded for
4018
- * the element's language.
4019
- *
4020
- * @param {Element} element The element containing the code.
4021
- * It must have a class of `language-xxxx` to be processed, where `xxxx` is a valid language identifier.
4022
- * @param {boolean} [async=false] Whether the element is to be highlighted asynchronously using Web Workers
4023
- * to improve performance and avoid blocking the UI when highlighting very large chunks of code. This option is
4024
- * [disabled by default](https://prismjs.com/faq.html#why-is-asynchronous-highlighting-disabled-by-default).
4025
- *
4026
- * Note: All language definitions required to highlight the code must be included in the main `prism.js` file for
4027
- * asynchronous highlighting to work. You can build your own bundle on the
4028
- * [Download page](https://prismjs.com/download.html).
4029
- * @param {HighlightCallback} [callback] An optional callback to be invoked after the highlighting is done.
4030
- * Mostly useful when `async` is `true`, since in that case, the highlighting is done asynchronously.
4031
- * @memberof Prism
4032
- * @public
4033
- */
4034
- highlightElement: function (element, async, callback) {
4035
- // Find language
4036
- var language = _.util.getLanguage(element);
4037
- var grammar = _.languages[language];
4038
-
4039
- // Set language on the element, if not present
4040
- _.util.setLanguage(element, language);
4041
-
4042
- // Set language on the parent, for styling
4043
- var parent = element.parentElement;
4044
- if (parent && parent.nodeName.toLowerCase() === 'pre') {
4045
- _.util.setLanguage(parent, language);
4046
- }
4047
-
4048
- var code = element.textContent;
4049
-
4050
- var env = {
4051
- element: element,
4052
- language: language,
4053
- grammar: grammar,
4054
- code: code
4055
- };
4056
-
4057
- function insertHighlightedCode(highlightedCode) {
4058
- env.highlightedCode = highlightedCode;
4059
-
4060
- _.hooks.run('before-insert', env);
4061
-
4062
- env.element.innerHTML = env.highlightedCode;
4063
-
4064
- _.hooks.run('after-highlight', env);
4065
- _.hooks.run('complete', env);
4066
- callback && callback.call(env.element);
4067
- }
4068
-
4069
- _.hooks.run('before-sanity-check', env);
4070
-
4071
- // plugins may change/add the parent/element
4072
- parent = env.element.parentElement;
4073
- if (parent && parent.nodeName.toLowerCase() === 'pre' && !parent.hasAttribute('tabindex')) {
4074
- parent.setAttribute('tabindex', '0');
4075
- }
4076
-
4077
- if (!env.code) {
4078
- _.hooks.run('complete', env);
4079
- callback && callback.call(env.element);
4080
- return;
4081
- }
4082
-
4083
- _.hooks.run('before-highlight', env);
4084
-
4085
- if (!env.grammar) {
4086
- insertHighlightedCode(_.util.encode(env.code));
4087
- return;
4088
- }
4089
-
4090
- if (async && _self.Worker) {
4091
- var worker = new Worker(_.filename);
4092
-
4093
- worker.onmessage = function (evt) {
4094
- insertHighlightedCode(evt.data);
4095
- };
4096
-
4097
- worker.postMessage(JSON.stringify({
4098
- language: env.language,
4099
- code: env.code,
4100
- immediateClose: true
4101
- }));
4102
- } else {
4103
- insertHighlightedCode(_.highlight(env.code, env.grammar, env.language));
4104
- }
4105
- },
4106
4403
 
4107
- /**
4108
- * Low-level function, only use if you know what you’re doing. It accepts a string of text as input
4109
- * and the language definitions to use, and returns a string with the HTML produced.
4110
- *
4111
- * The following hooks will be run:
4112
- * 1. `before-tokenize`
4113
- * 2. `after-tokenize`
4114
- * 3. `wrap`: On each {@link Token}.
4115
- *
4116
- * @param {string} text A string with the code to be highlighted.
4117
- * @param {Grammar} grammar An object containing the tokens to use.
4118
- *
4119
- * Usually a language definition like `Prism.languages.markup`.
4120
- * @param {string} language The name of the language definition passed to `grammar`.
4121
- * @returns {string} The highlighted HTML.
4122
- * @memberof Prism
4123
- * @public
4124
- * @example
4125
- * Prism.highlight('var foo = true;', Prism.languages.javascript, 'javascript');
4126
- */
4127
- highlight: function (text, grammar, language) {
4128
- var env = {
4129
- code: text,
4130
- grammar: grammar,
4131
- language: language
4132
- };
4133
- _.hooks.run('before-tokenize', env);
4134
- if (!env.grammar) {
4135
- throw new Error('The language "' + env.language + '" has no grammar.');
4136
- }
4137
- env.tokens = _.tokenize(env.code, env.grammar);
4138
- _.hooks.run('after-tokenize', env);
4139
- return Token.stringify(_.util.encode(env.tokens), env.language);
4140
- },
4404
+ // Typescript note:
4405
+ // The following can be used to import the Token type in JSDoc:
4406
+ //
4407
+ // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
4141
4408
 
4142
4409
  /**
4143
- * This is the heart of Prism, and the most low-level function you can use. It accepts a string of text as input
4144
- * and the language definitions to use, and returns an array with the tokenized code.
4145
- *
4146
- * When the language definition includes nested tokens, the function is called recursively on each of these tokens.
4147
- *
4148
- * This method could be useful in other contexts as well, as a very crude parser.
4410
+ * Creates a new token.
4149
4411
  *
4150
- * @param {string} text A string with the code to be highlighted.
4151
- * @param {Grammar} grammar An object containing the tokens to use.
4152
- *
4153
- * Usually a language definition like `Prism.languages.markup`.
4154
- * @returns {TokenStream} An array of strings and tokens, a token stream.
4155
- * @memberof Prism
4156
- * @public
4157
- * @example
4158
- * let code = `var foo = 0;`;
4159
- * let tokens = Prism.tokenize(code, Prism.languages.javascript);
4160
- * tokens.forEach(token => {
4161
- * if (token instanceof Prism.Token && token.type === 'number') {
4162
- * console.log(`Found numeric literal: ${token.content}`);
4163
- * }
4164
- * });
4165
- */
4166
- tokenize: function (text, grammar) {
4167
- var rest = grammar.rest;
4168
- if (rest) {
4169
- for (var token in rest) {
4170
- grammar[token] = rest[token];
4171
- }
4172
-
4173
- delete grammar.rest;
4174
- }
4175
-
4176
- var tokenList = new LinkedList();
4177
- addAfter(tokenList, tokenList.head, text);
4178
-
4179
- matchGrammar(text, tokenList, grammar, tokenList.head, 0);
4180
-
4181
- return toArray(tokenList);
4182
- },
4183
-
4184
- /**
4185
- * @namespace
4186
- * @memberof Prism
4412
+ * @param {string} type See {@link Token#type type}
4413
+ * @param {string | TokenStream} content See {@link Token#content content}
4414
+ * @param {string|string[]} [alias] The alias(es) of the token.
4415
+ * @param {string} [matchedStr=""] A copy of the full string this token was created from.
4416
+ * @class
4417
+ * @global
4187
4418
  * @public
4188
4419
  */
4189
- hooks: {
4190
- all: {},
4191
-
4420
+ function Token(type, content, alias, matchedStr) {
4192
4421
  /**
4193
- * Adds the given callback to the list of callbacks for the given hook.
4422
+ * The type of the token.
4194
4423
  *
4195
- * The callback will be invoked when the hook it is registered for is run.
4196
- * Hooks are usually directly run by a highlight function but you can also run hooks yourself.
4424
+ * This is usually the key of a pattern in a {@link Grammar}.
4197
4425
  *
4198
- * One callback function can be registered to multiple hooks and the same hook multiple times.
4199
- *
4200
- * @param {string} name The name of the hook.
4201
- * @param {HookCallback} callback The callback function which is given environment variables.
4426
+ * @type {string}
4427
+ * @see GrammarToken
4202
4428
  * @public
4203
4429
  */
4204
- add: function (name, callback) {
4205
- var hooks = _.hooks.all;
4206
-
4207
- hooks[name] = hooks[name] || [];
4208
-
4209
- hooks[name].push(callback);
4210
- },
4211
-
4430
+ this.type = type;
4212
4431
  /**
4213
- * Runs a hook invoking all registered callbacks with the given environment variables.
4432
+ * The strings or tokens contained by this token.
4214
4433
  *
4215
- * Callbacks will be invoked synchronously and in the order in which they were registered.
4434
+ * This will be a token stream if the pattern matched also defined an `inside` grammar.
4216
4435
  *
4217
- * @param {string} name The name of the hook.
4218
- * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
4436
+ * @type {string | TokenStream}
4219
4437
  * @public
4220
4438
  */
4221
- run: function (name, env) {
4222
- var callbacks = _.hooks.all[name];
4223
-
4224
- if (!callbacks || !callbacks.length) {
4225
- return;
4226
- }
4227
-
4228
- for (var i = 0, callback; (callback = callbacks[i++]);) {
4229
- callback(env);
4230
- }
4231
- }
4232
- },
4233
-
4234
- Token: Token
4235
- };
4236
- _self.Prism = _;
4237
-
4238
-
4239
- // Typescript note:
4240
- // The following can be used to import the Token type in JSDoc:
4241
- //
4242
- // @typedef {InstanceType<import("./prism-core")["Token"]>} Token
4439
+ this.content = content;
4440
+ /**
4441
+ * The alias(es) of the token.
4442
+ *
4443
+ * @type {string|string[]}
4444
+ * @see GrammarToken
4445
+ * @public
4446
+ */
4447
+ this.alias = alias;
4448
+ // Copy of the full string this token was created from
4449
+ this.length = (matchedStr || '').length | 0;
4450
+ }
4243
4451
 
4244
- /**
4245
- * Creates a new token.
4246
- *
4247
- * @param {string} type See {@link Token#type type}
4248
- * @param {string | TokenStream} content See {@link Token#content content}
4249
- * @param {string|string[]} [alias] The alias(es) of the token.
4250
- * @param {string} [matchedStr=""] A copy of the full string this token was created from.
4251
- * @class
4252
- * @global
4253
- * @public
4254
- */
4255
- function Token(type, content, alias, matchedStr) {
4256
4452
  /**
4257
- * The type of the token.
4453
+ * A token stream is an array of strings and {@link Token Token} objects.
4258
4454
  *
4259
- * This is usually the key of a pattern in a {@link Grammar}.
4455
+ * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
4456
+ * them.
4260
4457
  *
4261
- * @type {string}
4262
- * @see GrammarToken
4263
- * @public
4264
- */
4265
- this.type = type;
4266
- /**
4267
- * The strings or tokens contained by this token.
4458
+ * 1. No adjacent strings.
4459
+ * 2. No empty strings.
4268
4460
  *
4269
- * This will be a token stream if the pattern matched also defined an `inside` grammar.
4461
+ * The only exception here is the token stream that only contains the empty string and nothing else.
4270
4462
  *
4271
- * @type {string | TokenStream}
4463
+ * @typedef {Array<string | Token>} TokenStream
4464
+ * @global
4272
4465
  * @public
4273
4466
  */
4274
- this.content = content;
4467
+
4275
4468
  /**
4276
- * The alias(es) of the token.
4469
+ * Converts the given token or token stream to an HTML representation.
4277
4470
  *
4278
- * @type {string|string[]}
4279
- * @see GrammarToken
4280
- * @public
4471
+ * The following hooks will be run:
4472
+ * 1. `wrap`: On each {@link Token}.
4473
+ *
4474
+ * @param {string | Token | TokenStream} o The token or token stream to be converted.
4475
+ * @param {string} language The name of current language.
4476
+ * @returns {string} The HTML representation of the token or token stream.
4477
+ * @memberof Token
4478
+ * @static
4281
4479
  */
4282
- this.alias = alias;
4283
- // Copy of the full string this token was created from
4284
- this.length = (matchedStr || '').length | 0;
4285
- }
4286
-
4287
- /**
4288
- * A token stream is an array of strings and {@link Token Token} objects.
4289
- *
4290
- * Token streams have to fulfill a few properties that are assumed by most functions (mostly internal ones) that process
4291
- * them.
4292
- *
4293
- * 1. No adjacent strings.
4294
- * 2. No empty strings.
4295
- *
4296
- * The only exception here is the token stream that only contains the empty string and nothing else.
4297
- *
4298
- * @typedef {Array<string | Token>} TokenStream
4299
- * @global
4300
- * @public
4301
- */
4302
-
4303
- /**
4304
- * Converts the given token or token stream to an HTML representation.
4305
- *
4306
- * The following hooks will be run:
4307
- * 1. `wrap`: On each {@link Token}.
4308
- *
4309
- * @param {string | Token | TokenStream} o The token or token stream to be converted.
4310
- * @param {string} language The name of current language.
4311
- * @returns {string} The HTML representation of the token or token stream.
4312
- * @memberof Token
4313
- * @static
4314
- */
4315
- Token.stringify = function stringify(o, language) {
4316
- if (typeof o == 'string') {
4317
- return o;
4318
- }
4319
- if (Array.isArray(o)) {
4320
- var s = '';
4321
- o.forEach(function (e) {
4322
- s += stringify(e, language);
4323
- });
4324
- return s;
4325
- }
4326
-
4327
- var env = {
4328
- type: o.type,
4329
- content: stringify(o.content, language),
4330
- tag: 'span',
4331
- classes: ['token', o.type],
4332
- attributes: {},
4333
- language: language
4334
- };
4335
-
4336
- var aliases = o.alias;
4337
- if (aliases) {
4338
- if (Array.isArray(aliases)) {
4339
- Array.prototype.push.apply(env.classes, aliases);
4340
- } else {
4341
- env.classes.push(aliases);
4480
+ Token.stringify = function stringify(o, language) {
4481
+ if (typeof o == 'string') {
4482
+ return o;
4483
+ }
4484
+ if (Array.isArray(o)) {
4485
+ var s = '';
4486
+ o.forEach(function (e) {
4487
+ s += stringify(e, language);
4488
+ });
4489
+ return s;
4342
4490
  }
4343
- }
4344
-
4345
- _.hooks.run('wrap', env);
4346
4491
 
4347
- var attributes = '';
4348
- for (var name in env.attributes) {
4349
- attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
4350
- }
4492
+ var env = {
4493
+ type: o.type,
4494
+ content: stringify(o.content, language),
4495
+ tag: 'span',
4496
+ classes: ['token', o.type],
4497
+ attributes: {},
4498
+ language: language
4499
+ };
4351
4500
 
4352
- return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
4353
- };
4501
+ var aliases = o.alias;
4502
+ if (aliases) {
4503
+ if (Array.isArray(aliases)) {
4504
+ Array.prototype.push.apply(env.classes, aliases);
4505
+ } else {
4506
+ env.classes.push(aliases);
4507
+ }
4508
+ }
4354
4509
 
4355
- /**
4356
- * @param {RegExp} pattern
4357
- * @param {number} pos
4358
- * @param {string} text
4359
- * @param {boolean} lookbehind
4360
- * @returns {RegExpExecArray | null}
4361
- */
4362
- function matchPattern(pattern, pos, text, lookbehind) {
4363
- pattern.lastIndex = pos;
4364
- var match = pattern.exec(text);
4365
- if (match && lookbehind && match[1]) {
4366
- // change the match to remove the text matched by the Prism lookbehind group
4367
- var lookbehindLength = match[1].length;
4368
- match.index += lookbehindLength;
4369
- match[0] = match[0].slice(lookbehindLength);
4370
- }
4371
- return match;
4372
- }
4510
+ _.hooks.run('wrap', env);
4373
4511
 
4374
- /**
4375
- * @param {string} text
4376
- * @param {LinkedList<string | Token>} tokenList
4377
- * @param {any} grammar
4378
- * @param {LinkedListNode<string | Token>} startNode
4379
- * @param {number} startPos
4380
- * @param {RematchOptions} [rematch]
4381
- * @returns {void}
4382
- * @private
4383
- *
4384
- * @typedef RematchOptions
4385
- * @property {string} cause
4386
- * @property {number} reach
4387
- */
4388
- function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
4389
- for (var token in grammar) {
4390
- if (!grammar.hasOwnProperty(token) || !grammar[token]) {
4391
- continue;
4512
+ var attributes = '';
4513
+ for (var name in env.attributes) {
4514
+ attributes += ' ' + name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
4392
4515
  }
4393
4516
 
4394
- var patterns = grammar[token];
4395
- patterns = Array.isArray(patterns) ? patterns : [patterns];
4396
-
4397
- for (var j = 0; j < patterns.length; ++j) {
4398
- if (rematch && rematch.cause == token + ',' + j) {
4399
- return;
4400
- }
4517
+ return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + attributes + '>' + env.content + '</' + env.tag + '>';
4518
+ };
4401
4519
 
4402
- var patternObj = patterns[j];
4403
- var inside = patternObj.inside;
4404
- var lookbehind = !!patternObj.lookbehind;
4405
- var greedy = !!patternObj.greedy;
4406
- var alias = patternObj.alias;
4520
+ /**
4521
+ * @param {RegExp} pattern
4522
+ * @param {number} pos
4523
+ * @param {string} text
4524
+ * @param {boolean} lookbehind
4525
+ * @returns {RegExpExecArray | null}
4526
+ */
4527
+ function matchPattern(pattern, pos, text, lookbehind) {
4528
+ pattern.lastIndex = pos;
4529
+ var match = pattern.exec(text);
4530
+ if (match && lookbehind && match[1]) {
4531
+ // change the match to remove the text matched by the Prism lookbehind group
4532
+ var lookbehindLength = match[1].length;
4533
+ match.index += lookbehindLength;
4534
+ match[0] = match[0].slice(lookbehindLength);
4535
+ }
4536
+ return match;
4537
+ }
4407
4538
 
4408
- if (greedy && !patternObj.pattern.global) {
4409
- // Without the global flag, lastIndex won't work
4410
- var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
4411
- patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
4539
+ /**
4540
+ * @param {string} text
4541
+ * @param {LinkedList<string | Token>} tokenList
4542
+ * @param {any} grammar
4543
+ * @param {LinkedListNode<string | Token>} startNode
4544
+ * @param {number} startPos
4545
+ * @param {RematchOptions} [rematch]
4546
+ * @returns {void}
4547
+ * @private
4548
+ *
4549
+ * @typedef RematchOptions
4550
+ * @property {string} cause
4551
+ * @property {number} reach
4552
+ */
4553
+ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
4554
+ for (var token in grammar) {
4555
+ if (!grammar.hasOwnProperty(token) || !grammar[token]) {
4556
+ continue;
4412
4557
  }
4413
4558
 
4414
- /** @type {RegExp} */
4415
- var pattern = patternObj.pattern || patternObj;
4559
+ var patterns = grammar[token];
4560
+ patterns = Array.isArray(patterns) ? patterns : [patterns];
4416
4561
 
4417
- for ( // iterate the token list and keep track of the current token/string position
4418
- var currentNode = startNode.next, pos = startPos;
4419
- currentNode !== tokenList.tail;
4420
- pos += currentNode.value.length, currentNode = currentNode.next
4421
- ) {
4422
-
4423
- if (rematch && pos >= rematch.reach) {
4424
- break;
4562
+ for (var j = 0; j < patterns.length; ++j) {
4563
+ if (rematch && rematch.cause == token + ',' + j) {
4564
+ return;
4425
4565
  }
4426
4566
 
4427
- var str = currentNode.value;
4567
+ var patternObj = patterns[j];
4568
+ var inside = patternObj.inside;
4569
+ var lookbehind = !!patternObj.lookbehind;
4570
+ var greedy = !!patternObj.greedy;
4571
+ var alias = patternObj.alias;
4428
4572
 
4429
- if (tokenList.length > text.length) {
4430
- // Something went terribly wrong, ABORT, ABORT!
4431
- return;
4573
+ if (greedy && !patternObj.pattern.global) {
4574
+ // Without the global flag, lastIndex won't work
4575
+ var flags = patternObj.pattern.toString().match(/[imsuy]*$/)[0];
4576
+ patternObj.pattern = RegExp(patternObj.pattern.source, flags + 'g');
4432
4577
  }
4433
4578
 
4434
- if (str instanceof Token) {
4435
- continue;
4436
- }
4579
+ /** @type {RegExp} */
4580
+ var pattern = patternObj.pattern || patternObj;
4437
4581
 
4438
- var removeCount = 1; // this is the to parameter of removeBetween
4439
- var match;
4582
+ for ( // iterate the token list and keep track of the current token/string position
4583
+ var currentNode = startNode.next, pos = startPos;
4584
+ currentNode !== tokenList.tail;
4585
+ pos += currentNode.value.length, currentNode = currentNode.next
4586
+ ) {
4440
4587
 
4441
- if (greedy) {
4442
- match = matchPattern(pattern, pos, text, lookbehind);
4443
- if (!match || match.index >= text.length) {
4588
+ if (rematch && pos >= rematch.reach) {
4444
4589
  break;
4445
4590
  }
4446
4591
 
4447
- var from = match.index;
4448
- var to = match.index + match[0].length;
4449
- var p = pos;
4592
+ var str = currentNode.value;
4450
4593
 
4451
- // find the node that contains the match
4452
- p += currentNode.value.length;
4453
- while (from >= p) {
4454
- currentNode = currentNode.next;
4455
- p += currentNode.value.length;
4594
+ if (tokenList.length > text.length) {
4595
+ // Something went terribly wrong, ABORT, ABORT!
4596
+ return;
4456
4597
  }
4457
- // adjust pos (and p)
4458
- p -= currentNode.value.length;
4459
- pos = p;
4460
4598
 
4461
- // the current node is a Token, then the match starts inside another Token, which is invalid
4462
- if (currentNode.value instanceof Token) {
4599
+ if (str instanceof Token) {
4463
4600
  continue;
4464
4601
  }
4465
4602
 
4466
- // find the last node which is affected by this match
4467
- for (
4468
- var k = currentNode;
4469
- k !== tokenList.tail && (p < to || typeof k.value === 'string');
4470
- k = k.next
4471
- ) {
4472
- removeCount++;
4473
- p += k.value.length;
4474
- }
4475
- removeCount--;
4603
+ var removeCount = 1; // this is the to parameter of removeBetween
4604
+ var match;
4476
4605
 
4477
- // replace with the new match
4478
- str = text.slice(pos, p);
4479
- match.index -= pos;
4480
- } else {
4481
- match = matchPattern(pattern, 0, str, lookbehind);
4482
- if (!match) {
4483
- continue;
4606
+ if (greedy) {
4607
+ match = matchPattern(pattern, pos, text, lookbehind);
4608
+ if (!match || match.index >= text.length) {
4609
+ break;
4610
+ }
4611
+
4612
+ var from = match.index;
4613
+ var to = match.index + match[0].length;
4614
+ var p = pos;
4615
+
4616
+ // find the node that contains the match
4617
+ p += currentNode.value.length;
4618
+ while (from >= p) {
4619
+ currentNode = currentNode.next;
4620
+ p += currentNode.value.length;
4621
+ }
4622
+ // adjust pos (and p)
4623
+ p -= currentNode.value.length;
4624
+ pos = p;
4625
+
4626
+ // the current node is a Token, then the match starts inside another Token, which is invalid
4627
+ if (currentNode.value instanceof Token) {
4628
+ continue;
4629
+ }
4630
+
4631
+ // find the last node which is affected by this match
4632
+ for (
4633
+ var k = currentNode;
4634
+ k !== tokenList.tail && (p < to || typeof k.value === 'string');
4635
+ k = k.next
4636
+ ) {
4637
+ removeCount++;
4638
+ p += k.value.length;
4639
+ }
4640
+ removeCount--;
4641
+
4642
+ // replace with the new match
4643
+ str = text.slice(pos, p);
4644
+ match.index -= pos;
4645
+ } else {
4646
+ match = matchPattern(pattern, 0, str, lookbehind);
4647
+ if (!match) {
4648
+ continue;
4649
+ }
4484
4650
  }
4485
- }
4486
4651
 
4487
- // eslint-disable-next-line no-redeclare
4488
- var from = match.index;
4489
- var matchStr = match[0];
4490
- var before = str.slice(0, from);
4491
- var after = str.slice(from + matchStr.length);
4652
+ // eslint-disable-next-line no-redeclare
4653
+ var from = match.index;
4654
+ var matchStr = match[0];
4655
+ var before = str.slice(0, from);
4656
+ var after = str.slice(from + matchStr.length);
4492
4657
 
4493
- var reach = pos + str.length;
4494
- if (rematch && reach > rematch.reach) {
4495
- rematch.reach = reach;
4496
- }
4658
+ var reach = pos + str.length;
4659
+ if (rematch && reach > rematch.reach) {
4660
+ rematch.reach = reach;
4661
+ }
4497
4662
 
4498
- var removeFrom = currentNode.prev;
4663
+ var removeFrom = currentNode.prev;
4499
4664
 
4500
- if (before) {
4501
- removeFrom = addAfter(tokenList, removeFrom, before);
4502
- pos += before.length;
4503
- }
4665
+ if (before) {
4666
+ removeFrom = addAfter(tokenList, removeFrom, before);
4667
+ pos += before.length;
4668
+ }
4504
4669
 
4505
- removeRange(tokenList, removeFrom, removeCount);
4670
+ removeRange(tokenList, removeFrom, removeCount);
4506
4671
 
4507
- var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
4508
- currentNode = addAfter(tokenList, removeFrom, wrapped);
4672
+ var wrapped = new Token(token, inside ? _.tokenize(matchStr, inside) : matchStr, alias, matchStr);
4673
+ currentNode = addAfter(tokenList, removeFrom, wrapped);
4509
4674
 
4510
- if (after) {
4511
- addAfter(tokenList, currentNode, after);
4512
- }
4675
+ if (after) {
4676
+ addAfter(tokenList, currentNode, after);
4677
+ }
4513
4678
 
4514
- if (removeCount > 1) {
4515
- // at least one Token object was removed, so we have to do some rematching
4516
- // this can only happen if the current pattern is greedy
4679
+ if (removeCount > 1) {
4680
+ // at least one Token object was removed, so we have to do some rematching
4681
+ // this can only happen if the current pattern is greedy
4517
4682
 
4518
- /** @type {RematchOptions} */
4519
- var nestedRematch = {
4520
- cause: token + ',' + j,
4521
- reach: reach
4522
- };
4523
- matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
4683
+ /** @type {RematchOptions} */
4684
+ var nestedRematch = {
4685
+ cause: token + ',' + j,
4686
+ reach: reach
4687
+ };
4688
+ matchGrammar(text, tokenList, grammar, currentNode.prev, pos, nestedRematch);
4524
4689
 
4525
- // the reach might have been extended because of the rematching
4526
- if (rematch && nestedRematch.reach > rematch.reach) {
4527
- rematch.reach = nestedRematch.reach;
4690
+ // the reach might have been extended because of the rematching
4691
+ if (rematch && nestedRematch.reach > rematch.reach) {
4692
+ rematch.reach = nestedRematch.reach;
4693
+ }
4528
4694
  }
4529
4695
  }
4530
4696
  }
4531
4697
  }
4532
4698
  }
4533
- }
4534
4699
 
4535
- /**
4536
- * @typedef LinkedListNode
4537
- * @property {T} value
4538
- * @property {LinkedListNode<T> | null} prev The previous node.
4539
- * @property {LinkedListNode<T> | null} next The next node.
4540
- * @template T
4541
- * @private
4542
- */
4700
+ /**
4701
+ * @typedef LinkedListNode
4702
+ * @property {T} value
4703
+ * @property {LinkedListNode<T> | null} prev The previous node.
4704
+ * @property {LinkedListNode<T> | null} next The next node.
4705
+ * @template T
4706
+ * @private
4707
+ */
4543
4708
 
4544
- /**
4545
- * @template T
4546
- * @private
4547
- */
4548
- function LinkedList() {
4549
- /** @type {LinkedListNode<T>} */
4550
- var head = { value: null, prev: null, next: null };
4551
- /** @type {LinkedListNode<T>} */
4552
- var tail = { value: null, prev: head, next: null };
4553
- head.next = tail;
4554
-
4555
- /** @type {LinkedListNode<T>} */
4556
- this.head = head;
4557
- /** @type {LinkedListNode<T>} */
4558
- this.tail = tail;
4559
- this.length = 0;
4560
- }
4709
+ /**
4710
+ * @template T
4711
+ * @private
4712
+ */
4713
+ function LinkedList() {
4714
+ /** @type {LinkedListNode<T>} */
4715
+ var head = { value: null, prev: null, next: null };
4716
+ /** @type {LinkedListNode<T>} */
4717
+ var tail = { value: null, prev: head, next: null };
4718
+ head.next = tail;
4719
+
4720
+ /** @type {LinkedListNode<T>} */
4721
+ this.head = head;
4722
+ /** @type {LinkedListNode<T>} */
4723
+ this.tail = tail;
4724
+ this.length = 0;
4725
+ }
4561
4726
 
4562
- /**
4563
- * Adds a new node with the given value to the list.
4564
- *
4565
- * @param {LinkedList<T>} list
4566
- * @param {LinkedListNode<T>} node
4567
- * @param {T} value
4568
- * @returns {LinkedListNode<T>} The added node.
4569
- * @template T
4570
- */
4571
- function addAfter(list, node, value) {
4572
- // assumes that node != list.tail && values.length >= 0
4573
- var next = node.next;
4727
+ /**
4728
+ * Adds a new node with the given value to the list.
4729
+ *
4730
+ * @param {LinkedList<T>} list
4731
+ * @param {LinkedListNode<T>} node
4732
+ * @param {T} value
4733
+ * @returns {LinkedListNode<T>} The added node.
4734
+ * @template T
4735
+ */
4736
+ function addAfter(list, node, value) {
4737
+ // assumes that node != list.tail && values.length >= 0
4738
+ var next = node.next;
4574
4739
 
4575
- var newNode = { value: value, prev: node, next: next };
4576
- node.next = newNode;
4577
- next.prev = newNode;
4578
- list.length++;
4740
+ var newNode = { value: value, prev: node, next: next };
4741
+ node.next = newNode;
4742
+ next.prev = newNode;
4743
+ list.length++;
4579
4744
 
4580
- return newNode;
4581
- }
4582
- /**
4583
- * Removes `count` nodes after the given node. The given node will not be removed.
4584
- *
4585
- * @param {LinkedList<T>} list
4586
- * @param {LinkedListNode<T>} node
4587
- * @param {number} count
4588
- * @template T
4589
- */
4590
- function removeRange(list, node, count) {
4591
- var next = node.next;
4592
- for (var i = 0; i < count && next !== list.tail; i++) {
4593
- next = next.next;
4745
+ return newNode;
4594
4746
  }
4595
- node.next = next;
4596
- next.prev = node;
4597
- list.length -= i;
4598
- }
4599
- /**
4600
- * @param {LinkedList<T>} list
4601
- * @returns {T[]}
4602
- * @template T
4603
- */
4604
- function toArray(list) {
4605
- var array = [];
4606
- var node = list.head.next;
4607
- while (node !== list.tail) {
4608
- array.push(node.value);
4609
- node = node.next;
4747
+ /**
4748
+ * Removes `count` nodes after the given node. The given node will not be removed.
4749
+ *
4750
+ * @param {LinkedList<T>} list
4751
+ * @param {LinkedListNode<T>} node
4752
+ * @param {number} count
4753
+ * @template T
4754
+ */
4755
+ function removeRange(list, node, count) {
4756
+ var next = node.next;
4757
+ for (var i = 0; i < count && next !== list.tail; i++) {
4758
+ next = next.next;
4759
+ }
4760
+ node.next = next;
4761
+ next.prev = node;
4762
+ list.length -= i;
4763
+ }
4764
+ /**
4765
+ * @param {LinkedList<T>} list
4766
+ * @returns {T[]}
4767
+ * @template T
4768
+ */
4769
+ function toArray(list) {
4770
+ var array = [];
4771
+ var node = list.head.next;
4772
+ while (node !== list.tail) {
4773
+ array.push(node.value);
4774
+ node = node.next;
4775
+ }
4776
+ return array;
4610
4777
  }
4611
- return array;
4612
- }
4613
4778
 
4614
4779
 
4615
- if (!_self.document) {
4616
- if (!_self.addEventListener) {
4617
- // in Node.js
4618
- return _;
4619
- }
4780
+ if (!_self.document) {
4781
+ if (!_self.addEventListener) {
4782
+ // in Node.js
4783
+ return _;
4784
+ }
4620
4785
 
4621
- if (!_.disableWorkerMessageHandler) {
4622
- // In worker
4623
- _self.addEventListener('message', function (evt) {
4624
- var message = JSON.parse(evt.data);
4625
- var lang = message.language;
4626
- var code = message.code;
4627
- var immediateClose = message.immediateClose;
4628
-
4629
- _self.postMessage(_.highlight(code, _.languages[lang], lang));
4630
- if (immediateClose) {
4631
- _self.close();
4632
- }
4633
- }, false);
4634
- }
4786
+ if (!_.disableWorkerMessageHandler) {
4787
+ // In worker
4788
+ _self.addEventListener('message', function (evt) {
4789
+ var message = JSON.parse(evt.data);
4790
+ var lang = message.language;
4791
+ var code = message.code;
4792
+ var immediateClose = message.immediateClose;
4793
+
4794
+ _self.postMessage(_.highlight(code, _.languages[lang], lang));
4795
+ if (immediateClose) {
4796
+ _self.close();
4797
+ }
4798
+ }, false);
4799
+ }
4635
4800
 
4636
- return _;
4637
- }
4801
+ return _;
4802
+ }
4638
4803
 
4639
- // Get current script and highlight
4640
- var script = _.util.currentScript();
4804
+ // Get current script and highlight
4805
+ var script = _.util.currentScript();
4641
4806
 
4642
- if (script) {
4643
- _.filename = script.src;
4807
+ if (script) {
4808
+ _.filename = script.src;
4644
4809
 
4645
- if (script.hasAttribute('data-manual')) {
4646
- _.manual = true;
4810
+ if (script.hasAttribute('data-manual')) {
4811
+ _.manual = true;
4812
+ }
4647
4813
  }
4648
- }
4649
4814
 
4650
- function highlightAutomaticallyCallback() {
4651
- if (!_.manual) {
4652
- _.highlightAll();
4815
+ function highlightAutomaticallyCallback() {
4816
+ if (!_.manual) {
4817
+ _.highlightAll();
4818
+ }
4653
4819
  }
4654
- }
4655
4820
 
4656
- if (!_.manual) {
4657
- // If the document state is "loading", then we'll use DOMContentLoaded.
4658
- // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
4659
- // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
4660
- // might take longer one animation frame to execute which can create a race condition where only some plugins have
4661
- // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
4662
- // See https://github.com/PrismJS/prism/issues/2102
4663
- var readyState = document.readyState;
4664
- if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
4665
- document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
4666
- } else {
4667
- if (window.requestAnimationFrame) {
4668
- window.requestAnimationFrame(highlightAutomaticallyCallback);
4821
+ if (!_.manual) {
4822
+ // If the document state is "loading", then we'll use DOMContentLoaded.
4823
+ // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
4824
+ // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
4825
+ // might take longer one animation frame to execute which can create a race condition where only some plugins have
4826
+ // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
4827
+ // See https://github.com/PrismJS/prism/issues/2102
4828
+ var readyState = document.readyState;
4829
+ if (readyState === 'loading' || readyState === 'interactive' && script && script.defer) {
4830
+ document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
4669
4831
  } else {
4670
- window.setTimeout(highlightAutomaticallyCallback, 16);
4832
+ if (window.requestAnimationFrame) {
4833
+ window.requestAnimationFrame(highlightAutomaticallyCallback);
4834
+ } else {
4835
+ window.setTimeout(highlightAutomaticallyCallback, 16);
4836
+ }
4671
4837
  }
4672
4838
  }
4673
- }
4674
4839
 
4675
- return _;
4840
+ return _;
4676
4841
 
4677
- }(_self));
4842
+ }(_self));
4678
4843
 
4679
- if (module.exports) {
4680
- module.exports = Prism;
4681
- }
4844
+ if (module.exports) {
4845
+ module.exports = Prism;
4846
+ }
4682
4847
 
4683
- // hack for components to work correctly in node.js
4684
- if (typeof commonjsGlobal !== 'undefined') {
4685
- commonjsGlobal.Prism = Prism;
4686
- }
4687
-
4688
- // some additional documentation/types
4689
-
4690
- /**
4691
- * The expansion of a simple `RegExp` literal to support additional properties.
4692
- *
4693
- * @typedef GrammarToken
4694
- * @property {RegExp} pattern The regular expression of the token.
4695
- * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
4696
- * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
4697
- * @property {boolean} [greedy=false] Whether the token is greedy.
4698
- * @property {string|string[]} [alias] An optional alias or list of aliases.
4699
- * @property {Grammar} [inside] The nested grammar of this token.
4700
- *
4701
- * The `inside` grammar will be used to tokenize the text value of each token of this kind.
4702
- *
4703
- * This can be used to make nested and even recursive language definitions.
4704
- *
4705
- * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
4706
- * each another.
4707
- * @global
4708
- * @public
4709
- */
4710
-
4711
- /**
4712
- * @typedef Grammar
4713
- * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
4714
- * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
4715
- * @global
4716
- * @public
4717
- */
4718
-
4719
- /**
4720
- * A function which will invoked after an element was successfully highlighted.
4721
- *
4722
- * @callback HighlightCallback
4723
- * @param {Element} element The element successfully highlighted.
4724
- * @returns {void}
4725
- * @global
4726
- * @public
4727
- */
4728
-
4729
- /**
4730
- * @callback HookCallback
4731
- * @param {Object<string, any>} env The environment variables of the hook.
4732
- * @returns {void}
4733
- * @global
4734
- * @public
4735
- */
4736
-
4737
-
4738
- /* **********************************************
4739
- Begin prism-markup.js
4740
- ********************************************** */
4741
-
4742
- Prism.languages.markup = {
4743
- 'comment': {
4744
- pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
4745
- greedy: true
4746
- },
4747
- 'prolog': {
4748
- pattern: /<\?[\s\S]+?\?>/,
4749
- greedy: true
4750
- },
4751
- 'doctype': {
4752
- // https://www.w3.org/TR/xml/#NT-doctypedecl
4753
- pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
4754
- greedy: true,
4755
- inside: {
4756
- 'internal-subset': {
4757
- pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
4758
- lookbehind: true,
4759
- greedy: true,
4760
- inside: null // see below
4761
- },
4762
- 'string': {
4763
- pattern: /"[^"]*"|'[^']*'/,
4764
- greedy: true
4765
- },
4766
- 'punctuation': /^<!|>$|[[\]]/,
4767
- 'doctype-tag': /^DOCTYPE/i,
4768
- 'name': /[^\s<>'"]+/
4769
- }
4770
- },
4771
- 'cdata': {
4772
- pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
4773
- greedy: true
4774
- },
4775
- 'tag': {
4776
- pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
4777
- greedy: true,
4778
- inside: {
4779
- 'tag': {
4780
- pattern: /^<\/?[^\s>\/]+/,
4781
- inside: {
4782
- 'punctuation': /^<\/?/,
4783
- 'namespace': /^[^\s>\/:]+:/
4784
- }
4785
- },
4786
- 'special-attr': [],
4787
- 'attr-value': {
4788
- pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
4789
- inside: {
4790
- 'punctuation': [
4791
- {
4792
- pattern: /^=/,
4793
- alias: 'attr-equals'
4794
- },
4795
- {
4796
- pattern: /^(\s*)["']|["']$/,
4797
- lookbehind: true
4798
- }
4799
- ]
4800
- }
4801
- },
4802
- 'punctuation': /\/?>/,
4803
- 'attr-name': {
4804
- pattern: /[^\s>\/]+/,
4805
- inside: {
4806
- 'namespace': /^[^\s>\/:]+:/
4807
- }
4808
- }
4809
-
4810
- }
4811
- },
4812
- 'entity': [
4813
- {
4814
- pattern: /&[\da-z]{1,8};/i,
4815
- alias: 'named-entity'
4816
- },
4817
- /&#x?[\da-f]{1,8};/i
4818
- ]
4819
- };
4820
-
4821
- Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
4822
- Prism.languages.markup['entity'];
4823
- Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
4824
-
4825
- // Plugin to make entity title show the real entity, idea by Roman Komarov
4826
- Prism.hooks.add('wrap', function (env) {
4827
-
4828
- if (env.type === 'entity') {
4829
- env.attributes['title'] = env.content.replace(/&amp;/, '&');
4848
+ // hack for components to work correctly in node.js
4849
+ if (typeof commonjsGlobal !== 'undefined') {
4850
+ commonjsGlobal.Prism = Prism;
4830
4851
  }
4831
- });
4832
4852
 
4833
- Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
4853
+ // some additional documentation/types
4854
+
4834
4855
  /**
4835
- * Adds an inlined language to markup.
4856
+ * The expansion of a simple `RegExp` literal to support additional properties.
4857
+ *
4858
+ * @typedef GrammarToken
4859
+ * @property {RegExp} pattern The regular expression of the token.
4860
+ * @property {boolean} [lookbehind=false] If `true`, then the first capturing group of `pattern` will (effectively)
4861
+ * behave as a lookbehind group meaning that the captured text will not be part of the matched text of the new token.
4862
+ * @property {boolean} [greedy=false] Whether the token is greedy.
4863
+ * @property {string|string[]} [alias] An optional alias or list of aliases.
4864
+ * @property {Grammar} [inside] The nested grammar of this token.
4836
4865
  *
4837
- * An example of an inlined language is CSS with `<style>` tags.
4866
+ * The `inside` grammar will be used to tokenize the text value of each token of this kind.
4838
4867
  *
4839
- * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
4840
- * case insensitive.
4841
- * @param {string} lang The language key.
4842
- * @example
4843
- * addInlined('style', 'css');
4868
+ * This can be used to make nested and even recursive language definitions.
4869
+ *
4870
+ * Note: This can cause infinite recursion. Be careful when you embed different languages or even the same language into
4871
+ * each another.
4872
+ * @global
4873
+ * @public
4844
4874
  */
4845
- value: function addInlined(tagName, lang) {
4846
- var includedCdataInside = {};
4847
- includedCdataInside['language-' + lang] = {
4848
- pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
4849
- lookbehind: true,
4850
- inside: Prism.languages[lang]
4851
- };
4852
- includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
4853
4875
 
4854
- var inside = {
4855
- 'included-cdata': {
4856
- pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
4857
- inside: includedCdataInside
4858
- }
4859
- };
4860
- inside['language-' + lang] = {
4861
- pattern: /[\s\S]+/,
4862
- inside: Prism.languages[lang]
4863
- };
4864
-
4865
- var def = {};
4866
- def[tagName] = {
4867
- pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
4868
- lookbehind: true,
4869
- greedy: true,
4870
- inside: inside
4871
- };
4876
+ /**
4877
+ * @typedef Grammar
4878
+ * @type {Object<string, RegExp | GrammarToken | Array<RegExp | GrammarToken>>}
4879
+ * @property {Grammar} [rest] An optional grammar object that will be appended to this grammar.
4880
+ * @global
4881
+ * @public
4882
+ */
4872
4883
 
4873
- Prism.languages.insertBefore('markup', 'cdata', def);
4874
- }
4875
- });
4876
- Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
4877
4884
  /**
4878
- * Adds an pattern to highlight languages embedded in HTML attributes.
4879
- *
4880
- * An example of an inlined language is CSS with `style` attributes.
4885
+ * A function which will invoked after an element was successfully highlighted.
4881
4886
  *
4882
- * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
4883
- * case insensitive.
4884
- * @param {string} lang The language key.
4885
- * @example
4886
- * addAttribute('style', 'css');
4887
+ * @callback HighlightCallback
4888
+ * @param {Element} element The element successfully highlighted.
4889
+ * @returns {void}
4890
+ * @global
4891
+ * @public
4887
4892
  */
4888
- value: function (attrName, lang) {
4889
- Prism.languages.markup.tag.inside['special-attr'].push({
4890
- pattern: RegExp(
4891
- /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
4892
- 'i'
4893
- ),
4894
- lookbehind: true,
4893
+
4894
+ /**
4895
+ * @callback HookCallback
4896
+ * @param {Object<string, any>} env The environment variables of the hook.
4897
+ * @returns {void}
4898
+ * @global
4899
+ * @public
4900
+ */
4901
+
4902
+
4903
+ /* **********************************************
4904
+ Begin prism-markup.js
4905
+ ********************************************** */
4906
+
4907
+ Prism.languages.markup = {
4908
+ 'comment': {
4909
+ pattern: /<!--(?:(?!<!--)[\s\S])*?-->/,
4910
+ greedy: true
4911
+ },
4912
+ 'prolog': {
4913
+ pattern: /<\?[\s\S]+?\?>/,
4914
+ greedy: true
4915
+ },
4916
+ 'doctype': {
4917
+ // https://www.w3.org/TR/xml/#NT-doctypedecl
4918
+ pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
4919
+ greedy: true,
4920
+ inside: {
4921
+ 'internal-subset': {
4922
+ pattern: /(^[^\[]*\[)[\s\S]+(?=\]>$)/,
4923
+ lookbehind: true,
4924
+ greedy: true,
4925
+ inside: null // see below
4926
+ },
4927
+ 'string': {
4928
+ pattern: /"[^"]*"|'[^']*'/,
4929
+ greedy: true
4930
+ },
4931
+ 'punctuation': /^<!|>$|[[\]]/,
4932
+ 'doctype-tag': /^DOCTYPE/i,
4933
+ 'name': /[^\s<>'"]+/
4934
+ }
4935
+ },
4936
+ 'cdata': {
4937
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
4938
+ greedy: true
4939
+ },
4940
+ 'tag': {
4941
+ pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
4942
+ greedy: true,
4895
4943
  inside: {
4896
- 'attr-name': /^[^\s=]+/,
4944
+ 'tag': {
4945
+ pattern: /^<\/?[^\s>\/]+/,
4946
+ inside: {
4947
+ 'punctuation': /^<\/?/,
4948
+ 'namespace': /^[^\s>\/:]+:/
4949
+ }
4950
+ },
4951
+ 'special-attr': [],
4897
4952
  'attr-value': {
4898
- pattern: /=[\s\S]+/,
4953
+ pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
4899
4954
  inside: {
4900
- 'value': {
4901
- pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
4902
- lookbehind: true,
4903
- alias: [lang, 'language-' + lang],
4904
- inside: Prism.languages[lang]
4905
- },
4906
4955
  'punctuation': [
4907
4956
  {
4908
4957
  pattern: /^=/,
4909
4958
  alias: 'attr-equals'
4910
4959
  },
4911
- /"|'/
4960
+ {
4961
+ pattern: /^(\s*)["']|["']$/,
4962
+ lookbehind: true
4963
+ }
4912
4964
  ]
4913
4965
  }
4966
+ },
4967
+ 'punctuation': /\/?>/,
4968
+ 'attr-name': {
4969
+ pattern: /[^\s>\/]+/,
4970
+ inside: {
4971
+ 'namespace': /^[^\s>\/:]+:/
4972
+ }
4914
4973
  }
4974
+
4915
4975
  }
4916
- });
4917
- }
4918
- });
4976
+ },
4977
+ 'entity': [
4978
+ {
4979
+ pattern: /&[\da-z]{1,8};/i,
4980
+ alias: 'named-entity'
4981
+ },
4982
+ /&#x?[\da-f]{1,8};/i
4983
+ ]
4984
+ };
4919
4985
 
4920
- Prism.languages.html = Prism.languages.markup;
4921
- Prism.languages.mathml = Prism.languages.markup;
4922
- Prism.languages.svg = Prism.languages.markup;
4986
+ Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
4987
+ Prism.languages.markup['entity'];
4988
+ Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
4923
4989
 
4924
- Prism.languages.xml = Prism.languages.extend('markup', {});
4925
- Prism.languages.ssml = Prism.languages.xml;
4926
- Prism.languages.atom = Prism.languages.xml;
4927
- Prism.languages.rss = Prism.languages.xml;
4990
+ // Plugin to make entity title show the real entity, idea by Roman Komarov
4991
+ Prism.hooks.add('wrap', function (env) {
4928
4992
 
4993
+ if (env.type === 'entity') {
4994
+ env.attributes['title'] = env.content.replace(/&amp;/, '&');
4995
+ }
4996
+ });
4929
4997
 
4930
- /* **********************************************
4931
- Begin prism-css.js
4932
- ********************************************** */
4998
+ Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
4999
+ /**
5000
+ * Adds an inlined language to markup.
5001
+ *
5002
+ * An example of an inlined language is CSS with `<style>` tags.
5003
+ *
5004
+ * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
5005
+ * case insensitive.
5006
+ * @param {string} lang The language key.
5007
+ * @example
5008
+ * addInlined('style', 'css');
5009
+ */
5010
+ value: function addInlined(tagName, lang) {
5011
+ var includedCdataInside = {};
5012
+ includedCdataInside['language-' + lang] = {
5013
+ pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
5014
+ lookbehind: true,
5015
+ inside: Prism.languages[lang]
5016
+ };
5017
+ includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
4933
5018
 
4934
- (function (Prism) {
5019
+ var inside = {
5020
+ 'included-cdata': {
5021
+ pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
5022
+ inside: includedCdataInside
5023
+ }
5024
+ };
5025
+ inside['language-' + lang] = {
5026
+ pattern: /[\s\S]+/,
5027
+ inside: Prism.languages[lang]
5028
+ };
4935
5029
 
4936
- var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
5030
+ var def = {};
5031
+ def[tagName] = {
5032
+ pattern: RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
5033
+ lookbehind: true,
5034
+ greedy: true,
5035
+ inside: inside
5036
+ };
4937
5037
 
4938
- Prism.languages.css = {
4939
- 'comment': /\/\*[\s\S]*?\*\//,
4940
- 'atrule': {
4941
- pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
4942
- inside: {
4943
- 'rule': /^@[\w-]+/,
4944
- 'selector-function-argument': {
4945
- pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
4946
- lookbehind: true,
4947
- alias: 'selector'
4948
- },
4949
- 'keyword': {
4950
- pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
4951
- lookbehind: true
5038
+ Prism.languages.insertBefore('markup', 'cdata', def);
5039
+ }
5040
+ });
5041
+ Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {
5042
+ /**
5043
+ * Adds an pattern to highlight languages embedded in HTML attributes.
5044
+ *
5045
+ * An example of an inlined language is CSS with `style` attributes.
5046
+ *
5047
+ * @param {string} attrName The name of the tag that contains the inlined language. This name will be treated as
5048
+ * case insensitive.
5049
+ * @param {string} lang The language key.
5050
+ * @example
5051
+ * addAttribute('style', 'css');
5052
+ */
5053
+ value: function (attrName, lang) {
5054
+ Prism.languages.markup.tag.inside['special-attr'].push({
5055
+ pattern: RegExp(
5056
+ /(^|["'\s])/.source + '(?:' + attrName + ')' + /\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,
5057
+ 'i'
5058
+ ),
5059
+ lookbehind: true,
5060
+ inside: {
5061
+ 'attr-name': /^[^\s=]+/,
5062
+ 'attr-value': {
5063
+ pattern: /=[\s\S]+/,
5064
+ inside: {
5065
+ 'value': {
5066
+ pattern: /(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,
5067
+ lookbehind: true,
5068
+ alias: [lang, 'language-' + lang],
5069
+ inside: Prism.languages[lang]
5070
+ },
5071
+ 'punctuation': [
5072
+ {
5073
+ pattern: /^=/,
5074
+ alias: 'attr-equals'
5075
+ },
5076
+ /"|'/
5077
+ ]
5078
+ }
5079
+ }
4952
5080
  }
4953
- // See rest below
4954
- }
4955
- },
4956
- 'url': {
4957
- // https://drafts.csswg.org/css-values-3/#urls
4958
- pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
4959
- greedy: true,
4960
- inside: {
4961
- 'function': /^url/i,
4962
- 'punctuation': /^\(|\)$/,
4963
- 'string': {
4964
- pattern: RegExp('^' + string.source + '$'),
4965
- alias: 'url'
5081
+ });
5082
+ }
5083
+ });
5084
+
5085
+ Prism.languages.html = Prism.languages.markup;
5086
+ Prism.languages.mathml = Prism.languages.markup;
5087
+ Prism.languages.svg = Prism.languages.markup;
5088
+
5089
+ Prism.languages.xml = Prism.languages.extend('markup', {});
5090
+ Prism.languages.ssml = Prism.languages.xml;
5091
+ Prism.languages.atom = Prism.languages.xml;
5092
+ Prism.languages.rss = Prism.languages.xml;
5093
+
5094
+
5095
+ /* **********************************************
5096
+ Begin prism-css.js
5097
+ ********************************************** */
5098
+
5099
+ (function (Prism) {
5100
+
5101
+ var string = /(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;
5102
+
5103
+ Prism.languages.css = {
5104
+ 'comment': /\/\*[\s\S]*?\*\//,
5105
+ 'atrule': {
5106
+ pattern: RegExp('@[\\w-](?:' + /[^;{\s"']|\s+(?!\s)/.source + '|' + string.source + ')*?' + /(?:;|(?=\s*\{))/.source),
5107
+ inside: {
5108
+ 'rule': /^@[\w-]+/,
5109
+ 'selector-function-argument': {
5110
+ pattern: /(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,
5111
+ lookbehind: true,
5112
+ alias: 'selector'
5113
+ },
5114
+ 'keyword': {
5115
+ pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
5116
+ lookbehind: true
5117
+ }
5118
+ // See rest below
4966
5119
  }
4967
- }
4968
- },
4969
- 'selector': {
4970
- pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
4971
- lookbehind: true
4972
- },
4973
- 'string': {
4974
- pattern: string,
4975
- greedy: true
4976
- },
4977
- 'property': {
4978
- pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
4979
- lookbehind: true
4980
- },
4981
- 'important': /!important\b/i,
4982
- 'function': {
4983
- pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
4984
- lookbehind: true
4985
- },
4986
- 'punctuation': /[(){};:,]/
4987
- };
5120
+ },
5121
+ 'url': {
5122
+ // https://drafts.csswg.org/css-values-3/#urls
5123
+ pattern: RegExp('\\burl\\((?:' + string.source + '|' + /(?:[^\\\r\n()"']|\\[\s\S])*/.source + ')\\)', 'i'),
5124
+ greedy: true,
5125
+ inside: {
5126
+ 'function': /^url/i,
5127
+ 'punctuation': /^\(|\)$/,
5128
+ 'string': {
5129
+ pattern: RegExp('^' + string.source + '$'),
5130
+ alias: 'url'
5131
+ }
5132
+ }
5133
+ },
5134
+ 'selector': {
5135
+ pattern: RegExp('(^|[{}\\s])[^{}\\s](?:[^{};"\'\\s]|\\s+(?![\\s{])|' + string.source + ')*(?=\\s*\\{)'),
5136
+ lookbehind: true
5137
+ },
5138
+ 'string': {
5139
+ pattern: string,
5140
+ greedy: true
5141
+ },
5142
+ 'property': {
5143
+ pattern: /(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,
5144
+ lookbehind: true
5145
+ },
5146
+ 'important': /!important\b/i,
5147
+ 'function': {
5148
+ pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,
5149
+ lookbehind: true
5150
+ },
5151
+ 'punctuation': /[(){};:,]/
5152
+ };
4988
5153
 
4989
- Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
5154
+ Prism.languages.css['atrule'].inside.rest = Prism.languages.css;
4990
5155
 
4991
- var markup = Prism.languages.markup;
4992
- if (markup) {
4993
- markup.tag.addInlined('style', 'css');
4994
- markup.tag.addAttribute('style', 'css');
4995
- }
5156
+ var markup = Prism.languages.markup;
5157
+ if (markup) {
5158
+ markup.tag.addInlined('style', 'css');
5159
+ markup.tag.addAttribute('style', 'css');
5160
+ }
4996
5161
 
4997
- }(Prism));
5162
+ }(Prism));
4998
5163
 
4999
5164
 
5000
- /* **********************************************
5001
- Begin prism-clike.js
5002
- ********************************************** */
5165
+ /* **********************************************
5166
+ Begin prism-clike.js
5167
+ ********************************************** */
5003
5168
 
5004
- Prism.languages.clike = {
5005
- 'comment': [
5006
- {
5007
- pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
5008
- lookbehind: true,
5169
+ Prism.languages.clike = {
5170
+ 'comment': [
5171
+ {
5172
+ pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
5173
+ lookbehind: true,
5174
+ greedy: true
5175
+ },
5176
+ {
5177
+ pattern: /(^|[^\\:])\/\/.*/,
5178
+ lookbehind: true,
5179
+ greedy: true
5180
+ }
5181
+ ],
5182
+ 'string': {
5183
+ pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
5009
5184
  greedy: true
5010
5185
  },
5011
- {
5012
- pattern: /(^|[^\\:])\/\/.*/,
5186
+ 'class-name': {
5187
+ pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
5013
5188
  lookbehind: true,
5014
- greedy: true
5015
- }
5016
- ],
5017
- 'string': {
5018
- pattern: /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
5019
- greedy: true
5020
- },
5021
- 'class-name': {
5022
- pattern: /(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,
5023
- lookbehind: true,
5024
- inside: {
5025
- 'punctuation': /[.\\]/
5026
- }
5027
- },
5028
- 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
5029
- 'boolean': /\b(?:false|true)\b/,
5030
- 'function': /\b\w+(?=\()/,
5031
- 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
5032
- 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
5033
- 'punctuation': /[{}[\];(),.:]/
5034
- };
5189
+ inside: {
5190
+ 'punctuation': /[.\\]/
5191
+ }
5192
+ },
5193
+ 'keyword': /\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,
5194
+ 'boolean': /\b(?:false|true)\b/,
5195
+ 'function': /\b\w+(?=\()/,
5196
+ 'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
5197
+ 'operator': /[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,
5198
+ 'punctuation': /[{}[\];(),.:]/
5199
+ };
5035
5200
 
5036
5201
 
5037
- /* **********************************************
5038
- Begin prism-javascript.js
5039
- ********************************************** */
5202
+ /* **********************************************
5203
+ Begin prism-javascript.js
5204
+ ********************************************** */
5040
5205
 
5041
- Prism.languages.javascript = Prism.languages.extend('clike', {
5042
- 'class-name': [
5043
- Prism.languages.clike['class-name'],
5044
- {
5045
- pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
5046
- lookbehind: true
5047
- }
5048
- ],
5049
- 'keyword': [
5050
- {
5051
- pattern: /((?:^|\})\s*)catch\b/,
5052
- lookbehind: true
5053
- },
5054
- {
5055
- 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/,
5206
+ Prism.languages.javascript = Prism.languages.extend('clike', {
5207
+ 'class-name': [
5208
+ Prism.languages.clike['class-name'],
5209
+ {
5210
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,
5211
+ lookbehind: true
5212
+ }
5213
+ ],
5214
+ 'keyword': [
5215
+ {
5216
+ pattern: /((?:^|\})\s*)catch\b/,
5217
+ lookbehind: true
5218
+ },
5219
+ {
5220
+ 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/,
5221
+ lookbehind: true
5222
+ },
5223
+ ],
5224
+ // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
5225
+ 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
5226
+ 'number': {
5227
+ pattern: RegExp(
5228
+ /(^|[^\w$])/.source +
5229
+ '(?:' +
5230
+ (
5231
+ // constant
5232
+ /NaN|Infinity/.source +
5233
+ '|' +
5234
+ // binary integer
5235
+ /0[bB][01]+(?:_[01]+)*n?/.source +
5236
+ '|' +
5237
+ // octal integer
5238
+ /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
5239
+ '|' +
5240
+ // hexadecimal integer
5241
+ /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
5242
+ '|' +
5243
+ // decimal bigint
5244
+ /\d+(?:_\d+)*n/.source +
5245
+ '|' +
5246
+ // decimal number (integer or float) but no bigint
5247
+ /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
5248
+ ) +
5249
+ ')' +
5250
+ /(?![\w$])/.source
5251
+ ),
5056
5252
  lookbehind: true
5057
5253
  },
5058
- ],
5059
- // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
5060
- 'function': /#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
5061
- 'number': {
5062
- pattern: RegExp(
5063
- /(^|[^\w$])/.source +
5064
- '(?:' +
5065
- (
5066
- // constant
5067
- /NaN|Infinity/.source +
5068
- '|' +
5069
- // binary integer
5070
- /0[bB][01]+(?:_[01]+)*n?/.source +
5071
- '|' +
5072
- // octal integer
5073
- /0[oO][0-7]+(?:_[0-7]+)*n?/.source +
5074
- '|' +
5075
- // hexadecimal integer
5076
- /0[xX][\dA-Fa-f]+(?:_[\dA-Fa-f]+)*n?/.source +
5077
- '|' +
5078
- // decimal bigint
5079
- /\d+(?:_\d+)*n/.source +
5254
+ 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
5255
+ });
5256
+
5257
+ Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
5258
+
5259
+ Prism.languages.insertBefore('javascript', 'keyword', {
5260
+ 'regex': {
5261
+ pattern: RegExp(
5262
+ // lookbehind
5263
+ // eslint-disable-next-line regexp/no-dupe-characters-character-class
5264
+ /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
5265
+ // Regex pattern:
5266
+ // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
5267
+ // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
5268
+ // with the only syntax, so we have to define 2 different regex patterns.
5269
+ /\//.source +
5270
+ '(?:' +
5271
+ /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
5080
5272
  '|' +
5081
- // decimal number (integer or float) but no bigint
5082
- /(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+(?:_\d+)*)?/.source
5083
- ) +
5084
- ')' +
5085
- /(?![\w$])/.source
5086
- ),
5087
- lookbehind: true
5088
- },
5089
- 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/
5090
- });
5091
-
5092
- Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/;
5093
-
5094
- Prism.languages.insertBefore('javascript', 'keyword', {
5095
- 'regex': {
5096
- pattern: RegExp(
5097
- // lookbehind
5098
- // eslint-disable-next-line regexp/no-dupe-characters-character-class
5099
- /((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)/.source +
5100
- // Regex pattern:
5101
- // There are 2 regex patterns here. The RegExp set notation proposal added support for nested character
5102
- // classes if the `v` flag is present. Unfortunately, nested CCs are both context-free and incompatible
5103
- // with the only syntax, so we have to define 2 different regex patterns.
5104
- /\//.source +
5105
- '(?:' +
5106
- /(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}/.source +
5107
- '|' +
5108
- // `v` flag syntax. This supports 3 levels of nested character classes.
5109
- /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
5110
- ')' +
5111
- // lookahead
5112
- /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
5113
- ),
5114
- lookbehind: true,
5115
- greedy: true,
5116
- inside: {
5117
- 'regex-source': {
5118
- pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
5119
- lookbehind: true,
5120
- alias: 'language-regex',
5121
- inside: Prism.languages.regex
5122
- },
5123
- 'regex-delimiter': /^\/|\/$/,
5124
- 'regex-flags': /^[a-z]+$/,
5125
- }
5126
- },
5127
- // This must be declared before keyword because we use "function" inside the look-forward
5128
- 'function-variable': {
5129
- 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*=>))/,
5130
- alias: 'function'
5131
- },
5132
- 'parameter': [
5133
- {
5134
- pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
5135
- lookbehind: true,
5136
- inside: Prism.languages.javascript
5137
- },
5138
- {
5139
- pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
5273
+ // `v` flag syntax. This supports 3 levels of nested character classes.
5274
+ /(?:\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.|\[(?:[^[\]\\\r\n]|\\.)*\])*\])*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}v[dgimyus]{0,7}/.source +
5275
+ ')' +
5276
+ // lookahead
5277
+ /(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/.source
5278
+ ),
5140
5279
  lookbehind: true,
5141
- inside: Prism.languages.javascript
5280
+ greedy: true,
5281
+ inside: {
5282
+ 'regex-source': {
5283
+ pattern: /^(\/)[\s\S]+(?=\/[a-z]*$)/,
5284
+ lookbehind: true,
5285
+ alias: 'language-regex',
5286
+ inside: Prism.languages.regex
5287
+ },
5288
+ 'regex-delimiter': /^\/|\/$/,
5289
+ 'regex-flags': /^[a-z]+$/,
5290
+ }
5142
5291
  },
5143
- {
5144
- pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
5145
- lookbehind: true,
5146
- inside: Prism.languages.javascript
5292
+ // This must be declared before keyword because we use "function" inside the look-forward
5293
+ 'function-variable': {
5294
+ 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*=>))/,
5295
+ alias: 'function'
5147
5296
  },
5148
- {
5149
- 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*\{)/,
5150
- lookbehind: true,
5151
- inside: Prism.languages.javascript
5152
- }
5153
- ],
5154
- 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
5155
- });
5156
-
5157
- Prism.languages.insertBefore('javascript', 'string', {
5158
- 'hashbang': {
5159
- pattern: /^#!.*/,
5160
- greedy: true,
5161
- alias: 'comment'
5162
- },
5163
- 'template-string': {
5164
- pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
5165
- greedy: true,
5166
- inside: {
5167
- 'template-punctuation': {
5168
- pattern: /^`|`$/,
5169
- alias: 'string'
5297
+ 'parameter': [
5298
+ {
5299
+ pattern: /(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,
5300
+ lookbehind: true,
5301
+ inside: Prism.languages.javascript
5170
5302
  },
5171
- 'interpolation': {
5172
- pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
5303
+ {
5304
+ pattern: /(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,
5173
5305
  lookbehind: true,
5174
- inside: {
5175
- 'interpolation-punctuation': {
5176
- pattern: /^\$\{|\}$/,
5177
- alias: 'punctuation'
5178
- },
5179
- rest: Prism.languages.javascript
5180
- }
5306
+ inside: Prism.languages.javascript
5181
5307
  },
5182
- 'string': /[\s\S]+/
5308
+ {
5309
+ pattern: /(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,
5310
+ lookbehind: true,
5311
+ inside: Prism.languages.javascript
5312
+ },
5313
+ {
5314
+ 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*\{)/,
5315
+ lookbehind: true,
5316
+ inside: Prism.languages.javascript
5317
+ }
5318
+ ],
5319
+ 'constant': /\b[A-Z](?:[A-Z_]|\dx?)*\b/
5320
+ });
5321
+
5322
+ Prism.languages.insertBefore('javascript', 'string', {
5323
+ 'hashbang': {
5324
+ pattern: /^#!.*/,
5325
+ greedy: true,
5326
+ alias: 'comment'
5327
+ },
5328
+ 'template-string': {
5329
+ pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
5330
+ greedy: true,
5331
+ inside: {
5332
+ 'template-punctuation': {
5333
+ pattern: /^`|`$/,
5334
+ alias: 'string'
5335
+ },
5336
+ 'interpolation': {
5337
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
5338
+ lookbehind: true,
5339
+ inside: {
5340
+ 'interpolation-punctuation': {
5341
+ pattern: /^\$\{|\}$/,
5342
+ alias: 'punctuation'
5343
+ },
5344
+ rest: Prism.languages.javascript
5345
+ }
5346
+ },
5347
+ 'string': /[\s\S]+/
5348
+ }
5349
+ },
5350
+ 'string-property': {
5351
+ pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
5352
+ lookbehind: true,
5353
+ greedy: true,
5354
+ alias: 'property'
5183
5355
  }
5184
- },
5185
- 'string-property': {
5186
- pattern: /((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,
5187
- lookbehind: true,
5188
- greedy: true,
5189
- alias: 'property'
5190
- }
5191
- });
5356
+ });
5192
5357
 
5193
- Prism.languages.insertBefore('javascript', 'operator', {
5194
- 'literal-property': {
5195
- pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
5196
- lookbehind: true,
5197
- alias: 'property'
5198
- },
5199
- });
5358
+ Prism.languages.insertBefore('javascript', 'operator', {
5359
+ 'literal-property': {
5360
+ pattern: /((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,
5361
+ lookbehind: true,
5362
+ alias: 'property'
5363
+ },
5364
+ });
5200
5365
 
5201
- if (Prism.languages.markup) {
5202
- Prism.languages.markup.tag.addInlined('script', 'javascript');
5366
+ if (Prism.languages.markup) {
5367
+ Prism.languages.markup.tag.addInlined('script', 'javascript');
5203
5368
 
5204
- // add attribute support for all DOM events.
5205
- // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
5206
- Prism.languages.markup.tag.addAttribute(
5207
- /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,
5208
- 'javascript'
5209
- );
5210
- }
5369
+ // add attribute support for all DOM events.
5370
+ // https://developer.mozilla.org/en-US/docs/Web/Events#Standard_events
5371
+ Prism.languages.markup.tag.addAttribute(
5372
+ /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,
5373
+ 'javascript'
5374
+ );
5375
+ }
5211
5376
 
5212
- Prism.languages.js = Prism.languages.javascript;
5377
+ Prism.languages.js = Prism.languages.javascript;
5213
5378
 
5214
5379
 
5215
- /* **********************************************
5216
- Begin prism-file-highlight.js
5217
- ********************************************** */
5380
+ /* **********************************************
5381
+ Begin prism-file-highlight.js
5382
+ ********************************************** */
5218
5383
 
5219
- (function () {
5384
+ (function () {
5220
5385
 
5221
- if (typeof Prism === 'undefined' || typeof document === 'undefined') {
5222
- return;
5223
- }
5386
+ if (typeof Prism === 'undefined' || typeof document === 'undefined') {
5387
+ return;
5388
+ }
5224
5389
 
5225
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
5226
- if (!Element.prototype.matches) {
5227
- Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
5228
- }
5390
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill
5391
+ if (!Element.prototype.matches) {
5392
+ Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
5393
+ }
5229
5394
 
5230
- var LOADING_MESSAGE = 'Loading…';
5231
- var FAILURE_MESSAGE = function (status, message) {
5232
- return '✖ Error ' + status + ' while fetching file: ' + message;
5233
- };
5234
- var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
5235
-
5236
- var EXTENSIONS = {
5237
- 'js': 'javascript',
5238
- 'py': 'python',
5239
- 'rb': 'ruby',
5240
- 'ps1': 'powershell',
5241
- 'psm1': 'powershell',
5242
- 'sh': 'bash',
5243
- 'bat': 'batch',
5244
- 'h': 'c',
5245
- 'tex': 'latex'
5246
- };
5395
+ var LOADING_MESSAGE = 'Loading…';
5396
+ var FAILURE_MESSAGE = function (status, message) {
5397
+ return '✖ Error ' + status + ' while fetching file: ' + message;
5398
+ };
5399
+ var FAILURE_EMPTY_MESSAGE = '✖ Error: File does not exist or is empty';
5400
+
5401
+ var EXTENSIONS = {
5402
+ 'js': 'javascript',
5403
+ 'py': 'python',
5404
+ 'rb': 'ruby',
5405
+ 'ps1': 'powershell',
5406
+ 'psm1': 'powershell',
5407
+ 'sh': 'bash',
5408
+ 'bat': 'batch',
5409
+ 'h': 'c',
5410
+ 'tex': 'latex'
5411
+ };
5247
5412
 
5248
- var STATUS_ATTR = 'data-src-status';
5249
- var STATUS_LOADING = 'loading';
5250
- var STATUS_LOADED = 'loaded';
5251
- var STATUS_FAILED = 'failed';
5413
+ var STATUS_ATTR = 'data-src-status';
5414
+ var STATUS_LOADING = 'loading';
5415
+ var STATUS_LOADED = 'loaded';
5416
+ var STATUS_FAILED = 'failed';
5252
5417
 
5253
- var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
5254
- + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
5418
+ var SELECTOR = 'pre[data-src]:not([' + STATUS_ATTR + '="' + STATUS_LOADED + '"])'
5419
+ + ':not([' + STATUS_ATTR + '="' + STATUS_LOADING + '"])';
5255
5420
 
5256
- /**
5257
- * Loads the given file.
5258
- *
5259
- * @param {string} src The URL or path of the source file to load.
5260
- * @param {(result: string) => void} success
5261
- * @param {(reason: string) => void} error
5262
- */
5263
- function loadFile(src, success, error) {
5264
- var xhr = new XMLHttpRequest();
5265
- xhr.open('GET', src, true);
5266
- xhr.onreadystatechange = function () {
5267
- if (xhr.readyState == 4) {
5268
- if (xhr.status < 400 && xhr.responseText) {
5269
- success(xhr.responseText);
5270
- } else {
5271
- if (xhr.status >= 400) {
5272
- error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
5421
+ /**
5422
+ * Loads the given file.
5423
+ *
5424
+ * @param {string} src The URL or path of the source file to load.
5425
+ * @param {(result: string) => void} success
5426
+ * @param {(reason: string) => void} error
5427
+ */
5428
+ function loadFile(src, success, error) {
5429
+ var xhr = new XMLHttpRequest();
5430
+ xhr.open('GET', src, true);
5431
+ xhr.onreadystatechange = function () {
5432
+ if (xhr.readyState == 4) {
5433
+ if (xhr.status < 400 && xhr.responseText) {
5434
+ success(xhr.responseText);
5273
5435
  } else {
5274
- error(FAILURE_EMPTY_MESSAGE);
5436
+ if (xhr.status >= 400) {
5437
+ error(FAILURE_MESSAGE(xhr.status, xhr.statusText));
5438
+ } else {
5439
+ error(FAILURE_EMPTY_MESSAGE);
5440
+ }
5275
5441
  }
5276
5442
  }
5277
- }
5278
- };
5279
- xhr.send(null);
5280
- }
5443
+ };
5444
+ xhr.send(null);
5445
+ }
5281
5446
 
5282
- /**
5283
- * Parses the given range.
5284
- *
5285
- * This returns a range with inclusive ends.
5286
- *
5287
- * @param {string | null | undefined} range
5288
- * @returns {[number, number | undefined] | undefined}
5289
- */
5290
- function parseRange(range) {
5291
- var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
5292
- if (m) {
5293
- var start = Number(m[1]);
5294
- var comma = m[2];
5295
- var end = m[3];
5296
-
5297
- if (!comma) {
5298
- return [start, start];
5299
- }
5300
- if (!end) {
5301
- return [start, undefined];
5447
+ /**
5448
+ * Parses the given range.
5449
+ *
5450
+ * This returns a range with inclusive ends.
5451
+ *
5452
+ * @param {string | null | undefined} range
5453
+ * @returns {[number, number | undefined] | undefined}
5454
+ */
5455
+ function parseRange(range) {
5456
+ var m = /^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(range || '');
5457
+ if (m) {
5458
+ var start = Number(m[1]);
5459
+ var comma = m[2];
5460
+ var end = m[3];
5461
+
5462
+ if (!comma) {
5463
+ return [start, start];
5464
+ }
5465
+ if (!end) {
5466
+ return [start, undefined];
5467
+ }
5468
+ return [start, Number(end)];
5302
5469
  }
5303
- return [start, Number(end)];
5470
+ return undefined;
5304
5471
  }
5305
- return undefined;
5306
- }
5307
5472
 
5308
- Prism.hooks.add('before-highlightall', function (env) {
5309
- env.selector += ', ' + SELECTOR;
5310
- });
5473
+ Prism.hooks.add('before-highlightall', function (env) {
5474
+ env.selector += ', ' + SELECTOR;
5475
+ });
5311
5476
 
5312
- Prism.hooks.add('before-sanity-check', function (env) {
5313
- var pre = /** @type {HTMLPreElement} */ (env.element);
5314
- if (pre.matches(SELECTOR)) {
5315
- env.code = ''; // fast-path the whole thing and go to complete
5477
+ Prism.hooks.add('before-sanity-check', function (env) {
5478
+ var pre = /** @type {HTMLPreElement} */ (env.element);
5479
+ if (pre.matches(SELECTOR)) {
5480
+ env.code = ''; // fast-path the whole thing and go to complete
5316
5481
 
5317
- pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
5482
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADING); // mark as loading
5318
5483
 
5319
- // add code element with loading message
5320
- var code = pre.appendChild(document.createElement('CODE'));
5321
- code.textContent = LOADING_MESSAGE;
5484
+ // add code element with loading message
5485
+ var code = pre.appendChild(document.createElement('CODE'));
5486
+ code.textContent = LOADING_MESSAGE;
5322
5487
 
5323
- var src = pre.getAttribute('data-src');
5488
+ var src = pre.getAttribute('data-src');
5324
5489
 
5325
- var language = env.language;
5326
- if (language === 'none') {
5327
- // the language might be 'none' because there is no language set;
5328
- // in this case, we want to use the extension as the language
5329
- var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
5330
- language = EXTENSIONS[extension] || extension;
5331
- }
5490
+ var language = env.language;
5491
+ if (language === 'none') {
5492
+ // the language might be 'none' because there is no language set;
5493
+ // in this case, we want to use the extension as the language
5494
+ var extension = (/\.(\w+)$/.exec(src) || [, 'none'])[1];
5495
+ language = EXTENSIONS[extension] || extension;
5496
+ }
5332
5497
 
5333
- // set language classes
5334
- Prism.util.setLanguage(code, language);
5335
- Prism.util.setLanguage(pre, language);
5498
+ // set language classes
5499
+ Prism.util.setLanguage(code, language);
5500
+ Prism.util.setLanguage(pre, language);
5336
5501
 
5337
- // preload the language
5338
- var autoloader = Prism.plugins.autoloader;
5339
- if (autoloader) {
5340
- autoloader.loadLanguages(language);
5341
- }
5502
+ // preload the language
5503
+ var autoloader = Prism.plugins.autoloader;
5504
+ if (autoloader) {
5505
+ autoloader.loadLanguages(language);
5506
+ }
5342
5507
 
5343
- // load file
5344
- loadFile(
5345
- src,
5346
- function (text) {
5347
- // mark as loaded
5348
- pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
5508
+ // load file
5509
+ loadFile(
5510
+ src,
5511
+ function (text) {
5512
+ // mark as loaded
5513
+ pre.setAttribute(STATUS_ATTR, STATUS_LOADED);
5349
5514
 
5350
- // handle data-range
5351
- var range = parseRange(pre.getAttribute('data-range'));
5352
- if (range) {
5353
- var lines = text.split(/\r\n?|\n/g);
5515
+ // handle data-range
5516
+ var range = parseRange(pre.getAttribute('data-range'));
5517
+ if (range) {
5518
+ var lines = text.split(/\r\n?|\n/g);
5354
5519
 
5355
- // the range is one-based and inclusive on both ends
5356
- var start = range[0];
5357
- var end = range[1] == null ? lines.length : range[1];
5520
+ // the range is one-based and inclusive on both ends
5521
+ var start = range[0];
5522
+ var end = range[1] == null ? lines.length : range[1];
5358
5523
 
5359
- if (start < 0) { start += lines.length; }
5360
- start = Math.max(0, Math.min(start - 1, lines.length));
5361
- if (end < 0) { end += lines.length; }
5362
- end = Math.max(0, Math.min(end, lines.length));
5524
+ if (start < 0) { start += lines.length; }
5525
+ start = Math.max(0, Math.min(start - 1, lines.length));
5526
+ if (end < 0) { end += lines.length; }
5527
+ end = Math.max(0, Math.min(end, lines.length));
5363
5528
 
5364
- text = lines.slice(start, end).join('\n');
5529
+ text = lines.slice(start, end).join('\n');
5365
5530
 
5366
- // add data-start for line numbers
5367
- if (!pre.hasAttribute('data-start')) {
5368
- pre.setAttribute('data-start', String(start + 1));
5531
+ // add data-start for line numbers
5532
+ if (!pre.hasAttribute('data-start')) {
5533
+ pre.setAttribute('data-start', String(start + 1));
5534
+ }
5369
5535
  }
5370
- }
5371
5536
 
5372
- // highlight code
5373
- code.textContent = text;
5374
- Prism.highlightElement(code);
5375
- },
5376
- function (error) {
5377
- // mark as failed
5378
- pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
5537
+ // highlight code
5538
+ code.textContent = text;
5539
+ Prism.highlightElement(code);
5540
+ },
5541
+ function (error) {
5542
+ // mark as failed
5543
+ pre.setAttribute(STATUS_ATTR, STATUS_FAILED);
5379
5544
 
5380
- code.textContent = error;
5381
- }
5382
- );
5383
- }
5384
- });
5545
+ code.textContent = error;
5546
+ }
5547
+ );
5548
+ }
5549
+ });
5385
5550
 
5386
- Prism.plugins.fileHighlight = {
5387
- /**
5388
- * Executes the File Highlight plugin for all matching `pre` elements under the given container.
5389
- *
5390
- * Note: Elements which are already loaded or currently loading will not be touched by this method.
5391
- *
5392
- * @param {ParentNode} [container=document]
5393
- */
5394
- highlight: function highlight(container) {
5395
- var elements = (container || document).querySelectorAll(SELECTOR);
5551
+ Prism.plugins.fileHighlight = {
5552
+ /**
5553
+ * Executes the File Highlight plugin for all matching `pre` elements under the given container.
5554
+ *
5555
+ * Note: Elements which are already loaded or currently loading will not be touched by this method.
5556
+ *
5557
+ * @param {ParentNode} [container=document]
5558
+ */
5559
+ highlight: function highlight(container) {
5560
+ var elements = (container || document).querySelectorAll(SELECTOR);
5396
5561
 
5397
- for (var i = 0, element; (element = elements[i++]);) {
5398
- Prism.highlightElement(element);
5562
+ for (var i = 0, element; (element = elements[i++]);) {
5563
+ Prism.highlightElement(element);
5564
+ }
5399
5565
  }
5400
- }
5401
- };
5402
-
5403
- var logged = false;
5404
- /** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
5405
- Prism.fileHighlight = function () {
5406
- if (!logged) {
5407
- console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
5408
- logged = true;
5409
- }
5410
- Prism.plugins.fileHighlight.highlight.apply(this, arguments);
5411
- };
5566
+ };
5412
5567
 
5413
- }());
5414
- } (prism));
5415
-
5416
- Prism.languages.python = {
5417
- 'comment': {
5418
- pattern: /(^|[^\\])#.*/,
5419
- lookbehind: true,
5420
- greedy: true
5421
- },
5422
- 'string-interpolation': {
5423
- pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
5424
- greedy: true,
5425
- inside: {
5426
- 'interpolation': {
5427
- // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
5428
- pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
5429
- lookbehind: true,
5430
- inside: {
5431
- 'format-spec': {
5432
- pattern: /(:)[^:(){}]+(?=\}$)/,
5433
- lookbehind: true
5434
- },
5435
- 'conversion-option': {
5436
- pattern: /![sra](?=[:}]$)/,
5437
- alias: 'punctuation'
5438
- },
5439
- rest: null
5568
+ var logged = false;
5569
+ /** @deprecated Use `Prism.plugins.fileHighlight.highlight` instead. */
5570
+ Prism.fileHighlight = function () {
5571
+ if (!logged) {
5572
+ console.warn('Prism.fileHighlight is deprecated. Use `Prism.plugins.fileHighlight.highlight` instead.');
5573
+ logged = true;
5440
5574
  }
5441
- },
5442
- 'string': /[\s\S]+/
5443
- }
5444
- },
5445
- 'triple-quoted-string': {
5446
- pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
5447
- greedy: true,
5448
- alias: 'string'
5449
- },
5450
- 'string': {
5451
- pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
5452
- greedy: true
5453
- },
5454
- 'function': {
5455
- pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
5456
- lookbehind: true
5457
- },
5458
- 'class-name': {
5459
- pattern: /(\bclass\s+)\w+/i,
5460
- lookbehind: true
5461
- },
5462
- 'decorator': {
5463
- pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
5464
- lookbehind: true,
5465
- alias: ['annotation', 'punctuation'],
5466
- inside: {
5467
- 'punctuation': /\./
5468
- }
5469
- },
5470
- 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
5471
- 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
5472
- 'boolean': /\b(?:False|None|True)\b/,
5473
- 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
5474
- 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
5475
- 'punctuation': /[{}[\];(),.:]/
5476
- };
5575
+ Prism.plugins.fileHighlight.highlight.apply(this, arguments);
5576
+ };
5477
5577
 
5478
- Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
5578
+ }());
5579
+ } (prism));
5580
+ return prism.exports;
5581
+ }
5479
5582
 
5480
- Prism.languages.py = Prism.languages.python;
5583
+ requirePrism();
5481
5584
 
5482
- (function () {
5585
+ var prismPython = {};
5483
5586
 
5484
- if (typeof Prism === 'undefined' || typeof document === 'undefined') {
5485
- return;
5486
- }
5587
+ var hasRequiredPrismPython;
5487
5588
 
5488
- /**
5489
- * Plugin name which is used as a class name for <pre> which is activating the plugin
5490
- *
5491
- * @type {string}
5492
- */
5493
- var PLUGIN_NAME = 'line-numbers';
5589
+ function requirePrismPython () {
5590
+ if (hasRequiredPrismPython) return prismPython;
5591
+ hasRequiredPrismPython = 1;
5592
+ Prism.languages.python = {
5593
+ 'comment': {
5594
+ pattern: /(^|[^\\])#.*/,
5595
+ lookbehind: true,
5596
+ greedy: true
5597
+ },
5598
+ 'string-interpolation': {
5599
+ pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
5600
+ greedy: true,
5601
+ inside: {
5602
+ 'interpolation': {
5603
+ // "{" <expression> <optional "!s", "!r", or "!a"> <optional ":" format specifier> "}"
5604
+ pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
5605
+ lookbehind: true,
5606
+ inside: {
5607
+ 'format-spec': {
5608
+ pattern: /(:)[^:(){}]+(?=\}$)/,
5609
+ lookbehind: true
5610
+ },
5611
+ 'conversion-option': {
5612
+ pattern: /![sra](?=[:}]$)/,
5613
+ alias: 'punctuation'
5614
+ },
5615
+ rest: null
5616
+ }
5617
+ },
5618
+ 'string': /[\s\S]+/
5619
+ }
5620
+ },
5621
+ 'triple-quoted-string': {
5622
+ pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
5623
+ greedy: true,
5624
+ alias: 'string'
5625
+ },
5626
+ 'string': {
5627
+ pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
5628
+ greedy: true
5629
+ },
5630
+ 'function': {
5631
+ pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
5632
+ lookbehind: true
5633
+ },
5634
+ 'class-name': {
5635
+ pattern: /(\bclass\s+)\w+/i,
5636
+ lookbehind: true
5637
+ },
5638
+ 'decorator': {
5639
+ pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
5640
+ lookbehind: true,
5641
+ alias: ['annotation', 'punctuation'],
5642
+ inside: {
5643
+ 'punctuation': /\./
5644
+ }
5645
+ },
5646
+ 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
5647
+ 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
5648
+ 'boolean': /\b(?:False|None|True)\b/,
5649
+ 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
5650
+ 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
5651
+ 'punctuation': /[{}[\];(),.:]/
5652
+ };
5494
5653
 
5495
- /**
5496
- * Regular expression used for determining line breaks
5497
- *
5498
- * @type {RegExp}
5499
- */
5500
- var NEW_LINE_EXP = /\n(?!$)/g;
5654
+ Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
5501
5655
 
5656
+ Prism.languages.py = Prism.languages.python;
5657
+ return prismPython;
5658
+ }
5502
5659
 
5503
- /**
5504
- * Global exports
5505
- */
5506
- var config = Prism.plugins.lineNumbers = {
5507
- /**
5508
- * Get node for provided line number
5509
- *
5510
- * @param {Element} element pre element
5511
- * @param {number} number line number
5512
- * @returns {Element|undefined}
5513
- */
5514
- getLine: function (element, number) {
5515
- if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
5516
- return;
5517
- }
5660
+ requirePrismPython();
5518
5661
 
5519
- var lineNumberRows = element.querySelector('.line-numbers-rows');
5520
- if (!lineNumberRows) {
5521
- return;
5522
- }
5523
- var lineNumberStart = parseInt(element.getAttribute('data-start'), 10) || 1;
5524
- var lineNumberEnd = lineNumberStart + (lineNumberRows.children.length - 1);
5662
+ var prismLineNumbers = {};
5525
5663
 
5526
- if (number < lineNumberStart) {
5527
- number = lineNumberStart;
5528
- }
5529
- if (number > lineNumberEnd) {
5530
- number = lineNumberEnd;
5531
- }
5664
+ var hasRequiredPrismLineNumbers;
5532
5665
 
5533
- var lineIndex = number - lineNumberStart;
5666
+ function requirePrismLineNumbers () {
5667
+ if (hasRequiredPrismLineNumbers) return prismLineNumbers;
5668
+ hasRequiredPrismLineNumbers = 1;
5669
+ (function () {
5534
5670
 
5535
- return lineNumberRows.children[lineIndex];
5536
- },
5671
+ if (typeof Prism === 'undefined' || typeof document === 'undefined') {
5672
+ return;
5673
+ }
5537
5674
 
5538
5675
  /**
5539
- * Resizes the line numbers of the given element.
5676
+ * Plugin name which is used as a class name for <pre> which is activating the plugin
5540
5677
  *
5541
- * This function will not add line numbers. It will only resize existing ones.
5542
- *
5543
- * @param {HTMLElement} element A `<pre>` element with line numbers.
5544
- * @returns {void}
5678
+ * @type {string}
5545
5679
  */
5546
- resize: function (element) {
5547
- resizeElements([element]);
5548
- },
5680
+ var PLUGIN_NAME = 'line-numbers';
5549
5681
 
5550
5682
  /**
5551
- * Whether the plugin can assume that the units font sizes and margins are not depended on the size of
5552
- * the current viewport.
5553
- *
5554
- * Setting this to `true` will allow the plugin to do certain optimizations for better performance.
5683
+ * Regular expression used for determining line breaks
5555
5684
  *
5556
- * Set this to `false` if you use any of the following CSS units: `vh`, `vw`, `vmin`, `vmax`.
5557
- *
5558
- * @type {boolean}
5685
+ * @type {RegExp}
5559
5686
  */
5560
- assumeViewportIndependence: true
5561
- };
5687
+ var NEW_LINE_EXP = /\n(?!$)/g;
5562
5688
 
5563
- /**
5564
- * Resizes the given elements.
5565
- *
5566
- * @param {HTMLElement[]} elements
5567
- */
5568
- function resizeElements(elements) {
5569
- elements = elements.filter(function (e) {
5570
- var codeStyles = getStyles(e);
5571
- var whiteSpace = codeStyles['white-space'];
5572
- return whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line';
5573
- });
5574
5689
 
5575
- if (elements.length == 0) {
5576
- return;
5577
- }
5690
+ /**
5691
+ * Global exports
5692
+ */
5693
+ var config = Prism.plugins.lineNumbers = {
5694
+ /**
5695
+ * Get node for provided line number
5696
+ *
5697
+ * @param {Element} element pre element
5698
+ * @param {number} number line number
5699
+ * @returns {Element|undefined}
5700
+ */
5701
+ getLine: function (element, number) {
5702
+ if (element.tagName !== 'PRE' || !element.classList.contains(PLUGIN_NAME)) {
5703
+ return;
5704
+ }
5578
5705
 
5579
- var infos = elements.map(function (element) {
5580
- var codeElement = element.querySelector('code');
5581
- var lineNumbersWrapper = element.querySelector('.line-numbers-rows');
5582
- if (!codeElement || !lineNumbersWrapper) {
5583
- return undefined;
5584
- }
5706
+ var lineNumberRows = element.querySelector('.line-numbers-rows');
5707
+ if (!lineNumberRows) {
5708
+ return;
5709
+ }
5710
+ var lineNumberStart = parseInt(element.getAttribute('data-start'), 10) || 1;
5711
+ var lineNumberEnd = lineNumberStart + (lineNumberRows.children.length - 1);
5712
+
5713
+ if (number < lineNumberStart) {
5714
+ number = lineNumberStart;
5715
+ }
5716
+ if (number > lineNumberEnd) {
5717
+ number = lineNumberEnd;
5718
+ }
5585
5719
 
5586
- /** @type {HTMLElement} */
5587
- var lineNumberSizer = element.querySelector('.line-numbers-sizer');
5588
- var codeLines = codeElement.textContent.split(NEW_LINE_EXP);
5720
+ var lineIndex = number - lineNumberStart;
5721
+
5722
+ return lineNumberRows.children[lineIndex];
5723
+ },
5724
+
5725
+ /**
5726
+ * Resizes the line numbers of the given element.
5727
+ *
5728
+ * This function will not add line numbers. It will only resize existing ones.
5729
+ *
5730
+ * @param {HTMLElement} element A `<pre>` element with line numbers.
5731
+ * @returns {void}
5732
+ */
5733
+ resize: function (element) {
5734
+ resizeElements([element]);
5735
+ },
5736
+
5737
+ /**
5738
+ * Whether the plugin can assume that the units font sizes and margins are not depended on the size of
5739
+ * the current viewport.
5740
+ *
5741
+ * Setting this to `true` will allow the plugin to do certain optimizations for better performance.
5742
+ *
5743
+ * Set this to `false` if you use any of the following CSS units: `vh`, `vw`, `vmin`, `vmax`.
5744
+ *
5745
+ * @type {boolean}
5746
+ */
5747
+ assumeViewportIndependence: true
5748
+ };
5589
5749
 
5590
- if (!lineNumberSizer) {
5591
- lineNumberSizer = document.createElement('span');
5592
- lineNumberSizer.className = 'line-numbers-sizer';
5750
+ /**
5751
+ * Resizes the given elements.
5752
+ *
5753
+ * @param {HTMLElement[]} elements
5754
+ */
5755
+ function resizeElements(elements) {
5756
+ elements = elements.filter(function (e) {
5757
+ var codeStyles = getStyles(e);
5758
+ var whiteSpace = codeStyles['white-space'];
5759
+ return whiteSpace === 'pre-wrap' || whiteSpace === 'pre-line';
5760
+ });
5593
5761
 
5594
- codeElement.appendChild(lineNumberSizer);
5762
+ if (elements.length == 0) {
5763
+ return;
5595
5764
  }
5596
5765
 
5597
- lineNumberSizer.innerHTML = '0';
5598
- lineNumberSizer.style.display = 'block';
5766
+ var infos = elements.map(function (element) {
5767
+ var codeElement = element.querySelector('code');
5768
+ var lineNumbersWrapper = element.querySelector('.line-numbers-rows');
5769
+ if (!codeElement || !lineNumbersWrapper) {
5770
+ return undefined;
5771
+ }
5599
5772
 
5600
- var oneLinerHeight = lineNumberSizer.getBoundingClientRect().height;
5601
- lineNumberSizer.innerHTML = '';
5773
+ /** @type {HTMLElement} */
5774
+ var lineNumberSizer = element.querySelector('.line-numbers-sizer');
5775
+ var codeLines = codeElement.textContent.split(NEW_LINE_EXP);
5602
5776
 
5603
- return {
5604
- element: element,
5605
- lines: codeLines,
5606
- lineHeights: [],
5607
- oneLinerHeight: oneLinerHeight,
5608
- sizer: lineNumberSizer,
5609
- };
5610
- }).filter(Boolean);
5611
-
5612
- infos.forEach(function (info) {
5613
- var lineNumberSizer = info.sizer;
5614
- var lines = info.lines;
5615
- var lineHeights = info.lineHeights;
5616
- var oneLinerHeight = info.oneLinerHeight;
5617
-
5618
- lineHeights[lines.length - 1] = undefined;
5619
- lines.forEach(function (line, index) {
5620
- if (line && line.length > 1) {
5621
- var e = lineNumberSizer.appendChild(document.createElement('span'));
5622
- e.style.display = 'block';
5623
- e.textContent = line;
5624
- } else {
5625
- lineHeights[index] = oneLinerHeight;
5777
+ if (!lineNumberSizer) {
5778
+ lineNumberSizer = document.createElement('span');
5779
+ lineNumberSizer.className = 'line-numbers-sizer';
5780
+
5781
+ codeElement.appendChild(lineNumberSizer);
5626
5782
  }
5783
+
5784
+ lineNumberSizer.innerHTML = '0';
5785
+ lineNumberSizer.style.display = 'block';
5786
+
5787
+ var oneLinerHeight = lineNumberSizer.getBoundingClientRect().height;
5788
+ lineNumberSizer.innerHTML = '';
5789
+
5790
+ return {
5791
+ element: element,
5792
+ lines: codeLines,
5793
+ lineHeights: [],
5794
+ oneLinerHeight: oneLinerHeight,
5795
+ sizer: lineNumberSizer,
5796
+ };
5797
+ }).filter(Boolean);
5798
+
5799
+ infos.forEach(function (info) {
5800
+ var lineNumberSizer = info.sizer;
5801
+ var lines = info.lines;
5802
+ var lineHeights = info.lineHeights;
5803
+ var oneLinerHeight = info.oneLinerHeight;
5804
+
5805
+ lineHeights[lines.length - 1] = undefined;
5806
+ lines.forEach(function (line, index) {
5807
+ if (line && line.length > 1) {
5808
+ var e = lineNumberSizer.appendChild(document.createElement('span'));
5809
+ e.style.display = 'block';
5810
+ e.textContent = line;
5811
+ } else {
5812
+ lineHeights[index] = oneLinerHeight;
5813
+ }
5814
+ });
5627
5815
  });
5628
- });
5629
5816
 
5630
- infos.forEach(function (info) {
5631
- var lineNumberSizer = info.sizer;
5632
- var lineHeights = info.lineHeights;
5817
+ infos.forEach(function (info) {
5818
+ var lineNumberSizer = info.sizer;
5819
+ var lineHeights = info.lineHeights;
5633
5820
 
5634
- var childIndex = 0;
5635
- for (var i = 0; i < lineHeights.length; i++) {
5636
- if (lineHeights[i] === undefined) {
5637
- lineHeights[i] = lineNumberSizer.children[childIndex++].getBoundingClientRect().height;
5821
+ var childIndex = 0;
5822
+ for (var i = 0; i < lineHeights.length; i++) {
5823
+ if (lineHeights[i] === undefined) {
5824
+ lineHeights[i] = lineNumberSizer.children[childIndex++].getBoundingClientRect().height;
5825
+ }
5638
5826
  }
5639
- }
5640
- });
5827
+ });
5641
5828
 
5642
- infos.forEach(function (info) {
5643
- var lineNumberSizer = info.sizer;
5644
- var wrapper = info.element.querySelector('.line-numbers-rows');
5829
+ infos.forEach(function (info) {
5830
+ var lineNumberSizer = info.sizer;
5831
+ var wrapper = info.element.querySelector('.line-numbers-rows');
5645
5832
 
5646
- lineNumberSizer.style.display = 'none';
5647
- lineNumberSizer.innerHTML = '';
5833
+ lineNumberSizer.style.display = 'none';
5834
+ lineNumberSizer.innerHTML = '';
5648
5835
 
5649
- info.lineHeights.forEach(function (height, lineNumber) {
5650
- wrapper.children[lineNumber].style.height = height + 'px';
5836
+ info.lineHeights.forEach(function (height, lineNumber) {
5837
+ wrapper.children[lineNumber].style.height = height + 'px';
5838
+ });
5651
5839
  });
5652
- });
5653
- }
5654
-
5655
- /**
5656
- * Returns style declarations for the element
5657
- *
5658
- * @param {Element} element
5659
- */
5660
- function getStyles(element) {
5661
- if (!element) {
5662
- return null;
5663
5840
  }
5664
5841
 
5665
- return window.getComputedStyle ? getComputedStyle(element) : (element.currentStyle || null);
5666
- }
5842
+ /**
5843
+ * Returns style declarations for the element
5844
+ *
5845
+ * @param {Element} element
5846
+ */
5847
+ function getStyles(element) {
5848
+ if (!element) {
5849
+ return null;
5850
+ }
5667
5851
 
5668
- var lastWidth = undefined;
5669
- window.addEventListener('resize', function () {
5670
- if (config.assumeViewportIndependence && lastWidth === window.innerWidth) {
5671
- return;
5852
+ return window.getComputedStyle ? getComputedStyle(element) : (element.currentStyle || null);
5672
5853
  }
5673
- lastWidth = window.innerWidth;
5674
5854
 
5675
- resizeElements(Array.prototype.slice.call(document.querySelectorAll('pre.' + PLUGIN_NAME)));
5676
- });
5855
+ var lastWidth = undefined;
5856
+ window.addEventListener('resize', function () {
5857
+ if (config.assumeViewportIndependence && lastWidth === window.innerWidth) {
5858
+ return;
5859
+ }
5860
+ lastWidth = window.innerWidth;
5677
5861
 
5678
- Prism.hooks.add('complete', function (env) {
5679
- if (!env.code) {
5680
- return;
5681
- }
5862
+ resizeElements(Array.prototype.slice.call(document.querySelectorAll('pre.' + PLUGIN_NAME)));
5863
+ });
5682
5864
 
5683
- var code = /** @type {Element} */ (env.element);
5684
- var pre = /** @type {HTMLElement} */ (code.parentNode);
5865
+ Prism.hooks.add('complete', function (env) {
5866
+ if (!env.code) {
5867
+ return;
5868
+ }
5685
5869
 
5686
- // works only for <code> wrapped inside <pre> (not inline)
5687
- if (!pre || !/pre/i.test(pre.nodeName)) {
5688
- return;
5689
- }
5870
+ var code = /** @type {Element} */ (env.element);
5871
+ var pre = /** @type {HTMLElement} */ (code.parentNode);
5690
5872
 
5691
- // Abort if line numbers already exists
5692
- if (code.querySelector('.line-numbers-rows')) {
5693
- return;
5694
- }
5873
+ // works only for <code> wrapped inside <pre> (not inline)
5874
+ if (!pre || !/pre/i.test(pre.nodeName)) {
5875
+ return;
5876
+ }
5695
5877
 
5696
- // only add line numbers if <code> or one of its ancestors has the `line-numbers` class
5697
- if (!Prism.util.isActive(code, PLUGIN_NAME)) {
5698
- return;
5699
- }
5878
+ // Abort if line numbers already exists
5879
+ if (code.querySelector('.line-numbers-rows')) {
5880
+ return;
5881
+ }
5700
5882
 
5701
- // Remove the class 'line-numbers' from the <code>
5702
- code.classList.remove(PLUGIN_NAME);
5703
- // Add the class 'line-numbers' to the <pre>
5704
- pre.classList.add(PLUGIN_NAME);
5883
+ // only add line numbers if <code> or one of its ancestors has the `line-numbers` class
5884
+ if (!Prism.util.isActive(code, PLUGIN_NAME)) {
5885
+ return;
5886
+ }
5705
5887
 
5706
- var match = env.code.match(NEW_LINE_EXP);
5707
- var linesNum = match ? match.length + 1 : 1;
5708
- var lineNumbersWrapper;
5888
+ // Remove the class 'line-numbers' from the <code>
5889
+ code.classList.remove(PLUGIN_NAME);
5890
+ // Add the class 'line-numbers' to the <pre>
5891
+ pre.classList.add(PLUGIN_NAME);
5709
5892
 
5710
- var lines = new Array(linesNum + 1).join('<span></span>');
5893
+ var match = env.code.match(NEW_LINE_EXP);
5894
+ var linesNum = match ? match.length + 1 : 1;
5895
+ var lineNumbersWrapper;
5711
5896
 
5712
- lineNumbersWrapper = document.createElement('span');
5713
- lineNumbersWrapper.setAttribute('aria-hidden', 'true');
5714
- lineNumbersWrapper.className = 'line-numbers-rows';
5715
- lineNumbersWrapper.innerHTML = lines;
5897
+ var lines = new Array(linesNum + 1).join('<span></span>');
5716
5898
 
5717
- if (pre.hasAttribute('data-start')) {
5718
- pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
5719
- }
5899
+ lineNumbersWrapper = document.createElement('span');
5900
+ lineNumbersWrapper.setAttribute('aria-hidden', 'true');
5901
+ lineNumbersWrapper.className = 'line-numbers-rows';
5902
+ lineNumbersWrapper.innerHTML = lines;
5903
+
5904
+ if (pre.hasAttribute('data-start')) {
5905
+ pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
5906
+ }
5907
+
5908
+ env.element.appendChild(lineNumbersWrapper);
5720
5909
 
5721
- env.element.appendChild(lineNumbersWrapper);
5910
+ resizeElements([pre]);
5722
5911
 
5723
- resizeElements([pre]);
5912
+ Prism.hooks.run('line-numbers', env);
5913
+ });
5724
5914
 
5725
- Prism.hooks.run('line-numbers', env);
5726
- });
5915
+ Prism.hooks.add('line-numbers', function (env) {
5916
+ env.plugins = env.plugins || {};
5917
+ env.plugins.lineNumbers = true;
5918
+ });
5727
5919
 
5728
- Prism.hooks.add('line-numbers', function (env) {
5729
- env.plugins = env.plugins || {};
5730
- env.plugins.lineNumbers = true;
5731
- });
5920
+ }());
5921
+ return prismLineNumbers;
5922
+ }
5732
5923
 
5733
- }());
5924
+ requirePrismLineNumbers();
5734
5925
 
5735
5926
  const initialize = () => {
5736
5927
  // @ts-ignore
@@ -5750,7 +5941,11 @@ const initialize = () => {
5750
5941
  }
5751
5942
  };
5752
5943
  // @ts-ignore
5753
- window.setResults = (playerNames, places, parameters, verbose) => {
5944
+ window.setResults = (playerNames, seed, places, statistics, parameters, verbose) => {
5945
+ // @ts-ignore
5946
+ parameters = parameters.toJs();
5947
+ // @ts-ignore
5948
+ statistics = statistics.toJs();
5754
5949
  const results = getLocalStorage("Results");
5755
5950
  if (!results[playerNames.join(", ")]) {
5756
5951
  results[playerNames.join(", ")] = {};
@@ -5758,7 +5953,11 @@ const initialize = () => {
5758
5953
  if (!results[playerNames.join(", ")][JSON.stringify(parameters)]) {
5759
5954
  results[playerNames.join(", ")][JSON.stringify(parameters)] = [];
5760
5955
  }
5761
- results[playerNames.join(", ")][JSON.stringify(parameters)].push(places);
5956
+ results[playerNames.join(", ")][JSON.stringify(parameters)].push({
5957
+ seed,
5958
+ places,
5959
+ statistics,
5960
+ });
5762
5961
  setLocalStorage("Results", results);
5763
5962
  updatePointModifier();
5764
5963
  // @ts-ignore