@lvce-editor/markdown-worker 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -344,22 +344,11 @@ class IpcChildWithModuleWorker extends Ipc {
344
344
  const wrap$f = global => {
345
345
  return new IpcChildWithModuleWorker(global);
346
346
  };
347
- const withResolvers = () => {
348
- let _resolve;
349
- const promise = new Promise(resolve => {
350
- _resolve = resolve;
351
- });
352
- return {
353
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
354
- resolve: _resolve,
355
- promise
356
- };
357
- };
358
347
  const waitForFirstMessage = async port => {
359
348
  const {
360
349
  resolve,
361
350
  promise
362
- } = withResolvers();
351
+ } = Promise.withResolvers();
363
352
  port.addEventListener('message', resolve, {
364
353
  once: true
365
354
  });
@@ -433,7 +422,7 @@ const callbacks = Object.create(null);
433
422
  const set$1 = (id, fn) => {
434
423
  callbacks[id] = fn;
435
424
  };
436
- const get = id => {
425
+ const get$1 = id => {
437
426
  return callbacks[id];
438
427
  };
439
428
  const remove = id => {
@@ -522,6 +511,16 @@ const constructError = (message, type, name) => {
522
511
  }
523
512
  return new ErrorConstructor(message);
524
513
  };
514
+ const joinLines = lines => {
515
+ return lines.join(NewLine);
516
+ };
517
+ const splitLines = lines => {
518
+ return lines.split(NewLine);
519
+ };
520
+ const getCurrentStack = () => {
521
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
522
+ return currentStack;
523
+ };
525
524
  const getNewLineIndex = (string, startIndex = undefined) => {
526
525
  return string.indexOf(NewLine, startIndex);
527
526
  };
@@ -532,19 +531,16 @@ const getParentStack = error => {
532
531
  }
533
532
  return parentStack;
534
533
  };
535
- const joinLines = lines => {
536
- return lines.join(NewLine);
537
- };
538
534
  const MethodNotFound = -32601;
539
535
  const Custom = -32001;
540
- const splitLines = lines => {
541
- return lines.split(NewLine);
542
- };
543
536
  const restoreJsonRpcError = error => {
537
+ const currentStack = getCurrentStack();
544
538
  if (error && error instanceof Error) {
539
+ if (typeof error.stack === 'string') {
540
+ error.stack = error.stack + NewLine + currentStack;
541
+ }
545
542
  return error;
546
543
  }
547
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
548
544
  if (error && error.code && error.code === MethodNotFound) {
549
545
  const restoredError = new JsonRpcError(error.message);
550
546
  const parentStack = getParentStack(error);
@@ -606,7 +602,7 @@ const warn = (...args) => {
606
602
  console.warn(...args);
607
603
  };
608
604
  const resolve = (id, response) => {
609
- const fn = get(id);
605
+ const fn = get$1(id);
610
606
  if (!fn) {
611
607
  console.log(response);
612
608
  warn(`callback ${id} may already be disposed`);
@@ -625,6 +621,17 @@ const getErrorType = prettyError => {
625
621
  }
626
622
  return undefined;
627
623
  };
624
+ const isAlreadyStack = line => {
625
+ return line.trim().startsWith('at ');
626
+ };
627
+ const getStack = prettyError => {
628
+ const stackString = prettyError.stack || '';
629
+ const newLineIndex = stackString.indexOf('\n');
630
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
631
+ return stackString.slice(newLineIndex + 1);
632
+ }
633
+ return stackString;
634
+ };
628
635
  const getErrorProperty = (error, prettyError) => {
629
636
  if (error && error.code === E_COMMAND_NOT_FOUND) {
630
637
  return {
@@ -637,7 +644,7 @@ const getErrorProperty = (error, prettyError) => {
637
644
  code: Custom,
638
645
  message: prettyError.message,
639
646
  data: {
640
- stack: prettyError.stack,
647
+ stack: getStack(prettyError),
641
648
  codeFrame: prettyError.codeFrame,
642
649
  type: getErrorType(prettyError),
643
650
  code: prettyError.code,
@@ -645,18 +652,18 @@ const getErrorProperty = (error, prettyError) => {
645
652
  }
646
653
  };
647
654
  };
648
- const create$1 = (message, error) => {
655
+ const create$1$1 = (id, error) => {
649
656
  return {
650
657
  jsonrpc: Two,
651
- id: message.id,
658
+ id,
652
659
  error
653
660
  };
654
661
  };
655
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
662
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
656
663
  const prettyError = preparePrettyError(error);
657
664
  logError(error, prettyError);
658
665
  const errorProperty = getErrorProperty(error, prettyError);
659
- return create$1(message, errorProperty);
666
+ return create$1$1(id, errorProperty);
660
667
  };
661
668
  const create$5 = (message, result) => {
662
669
  return {
@@ -669,12 +676,27 @@ const getSuccessResponse = (message, result) => {
669
676
  const resultProperty = result ?? null;
670
677
  return create$5(message, resultProperty);
671
678
  };
679
+ const getErrorResponseSimple = (id, error) => {
680
+ return {
681
+ jsonrpc: Two,
682
+ id,
683
+ error: {
684
+ code: Custom,
685
+ // @ts-ignore
686
+ message: error.message,
687
+ data: error
688
+ }
689
+ };
690
+ };
672
691
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
673
692
  try {
674
693
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
675
694
  return getSuccessResponse(message, result);
676
695
  } catch (error) {
677
- return getErrorResponse(message, error, preparePrettyError, logError);
696
+ if (ipc.canUseSimpleErrorResponse) {
697
+ return getErrorResponseSimple(message.id, error);
698
+ }
699
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
678
700
  }
679
701
  };
680
702
  const defaultPreparePrettyError = error => {
@@ -729,7 +751,7 @@ const handleJsonRpcMessage = async (...args) => {
729
751
  try {
730
752
  ipc.send(response);
731
753
  } catch (error) {
732
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
754
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
733
755
  ipc.send(errorResponse);
734
756
  }
735
757
  return;
@@ -834,7 +856,7 @@ const listen$1 = async (module, options) => {
834
856
  const ipc = module.wrap(rawIpc);
835
857
  return ipc;
836
858
  };
837
- const create = async ({
859
+ const create$1 = async ({
838
860
  commandMap
839
861
  }) => {
840
862
  // TODO create a commandMap per rpc instance
@@ -846,7 +868,80 @@ const create = async ({
846
868
  };
847
869
  const WebWorkerRpcClient = {
848
870
  __proto__: null,
849
- create
871
+ create: create$1
872
+ };
873
+
874
+ const Div$1 = 4;
875
+ const H1$1 = 5;
876
+ const Span$1 = 8;
877
+ const Text$1 = 12;
878
+ const Img$1 = 17;
879
+ const H2$1 = 22;
880
+ const H3$1 = 23;
881
+ const H4$1 = 24;
882
+ const H5$1 = 25;
883
+ const Article$1 = 27;
884
+ const Aside$1 = 28;
885
+ const Footer$1 = 29;
886
+ const Header$1 = 30;
887
+ const Nav$1 = 40;
888
+ const Section$1 = 41;
889
+ const Search$1 = 42;
890
+ const Dd$1 = 43;
891
+ const Dl$1 = 44;
892
+ const Figcaption$1 = 45;
893
+ const Figure$1 = 46;
894
+ const Hr$1 = 47;
895
+ const Li$1 = 48;
896
+ const Ol$1 = 49;
897
+ const P$2 = 50;
898
+ const Pre$1 = 51;
899
+ const A$2 = 53;
900
+ const Abbr$1 = 54;
901
+ const Br$1 = 55;
902
+ const Cite$1 = 56;
903
+ const Data$1 = 57;
904
+ const Time$1 = 58;
905
+ const Tfoot$1 = 59;
906
+ const VirtualDomElements = {
907
+ __proto__: null,
908
+ A: A$2,
909
+ Abbr: Abbr$1,
910
+ Article: Article$1,
911
+ Aside: Aside$1,
912
+ Br: Br$1,
913
+ Cite: Cite$1,
914
+ Data: Data$1,
915
+ Dd: Dd$1,
916
+ Div: Div$1,
917
+ Dl: Dl$1,
918
+ Figcaption: Figcaption$1,
919
+ Figure: Figure$1,
920
+ Footer: Footer$1,
921
+ H1: H1$1,
922
+ H2: H2$1,
923
+ H3: H3$1,
924
+ H4: H4$1,
925
+ H5: H5$1,
926
+ Header: Header$1,
927
+ Hr: Hr$1,
928
+ Img: Img$1,
929
+ Li: Li$1,
930
+ Nav: Nav$1,
931
+ Ol: Ol$1,
932
+ P: P$2,
933
+ Pre: Pre$1,
934
+ Search: Search$1,
935
+ Section: Section$1,
936
+ Span: Span$1,
937
+ Tfoot: Tfoot$1,
938
+ Time: Time$1};
939
+ const text = data => {
940
+ return {
941
+ type: Text$1,
942
+ text: data,
943
+ childCount: 0
944
+ };
850
945
  };
851
946
 
852
947
  const allowedMarkdownAttributes = ['src', 'id', 'className', 'title', 'alt', 'href', 'target', 'rel'];
@@ -870,137 +965,104 @@ const getVirtualDomChildCount = markdownDom => {
870
965
  return stack.length;
871
966
  };
872
967
 
873
- const Div$1 = 'div';
874
- const H1$1 = 'h1';
875
- const H2$1 = 'h2';
876
- const H3$1 = 'h3';
877
- const H4$1 = 'h4';
878
- const H5$1 = 'h5';
879
- const Img$1 = 'img';
880
- const Span$1 = 'span';
881
- const Article$1 = 'article';
882
- const Aside$1 = 'aside';
883
- const Footer$1 = 'footer';
884
- const Header$1 = 'header';
885
- const Nav$1 = 'nav';
886
- const Section$1 = 'section';
887
- const Search$1 = 'search';
888
- const Dd$1 = 'dd';
889
- const Dl$1 = 'dl';
890
- const Figcaption$1 = 'figcaption';
891
- const Figure$1 = 'figure';
892
- const Hr$1 = 'hr';
893
- const Li$1 = 'li';
894
- const Ol$1 = 'ol';
968
+ const Div = 'div';
969
+ const H1 = 'h1';
970
+ const H2 = 'h2';
971
+ const H3 = 'h3';
972
+ const H4 = 'h4';
973
+ const H5 = 'h5';
974
+ const Img = 'img';
975
+ const Span = 'span';
976
+ const Article = 'article';
977
+ const Aside = 'aside';
978
+ const Footer = 'footer';
979
+ const Header = 'header';
980
+ const Nav = 'nav';
981
+ const Section = 'section';
982
+ const Search = 'search';
983
+ const Dd = 'dd';
984
+ const Dl = 'dl';
985
+ const Figcaption = 'figcaption';
986
+ const Figure = 'figure';
987
+ const Hr = 'hr';
988
+ const Li = 'li';
989
+ const Ol = 'ol';
895
990
  const P$1 = 'p';
896
- const Pre$1 = 'pre';
991
+ const Pre = 'pre';
897
992
  const A$1 = 'a';
898
- const Abbr$1 = 'abbr';
899
- const Br$1 = 'br';
900
- const Cite$1 = 'cite';
901
- const Data$1 = 'data';
902
- const Time$1 = 'time';
903
- const Tfoot$1 = 'tfoot';
904
-
905
- const A = 53;
906
- const Abbr = 54;
907
- const Article = 27;
908
- const Aside = 28;
909
- const Br = 55;
910
- const Cite = 56;
911
- const Data = 57;
912
- const Dd = 43;
913
- const Div = 4;
914
- const Dl = 44;
915
- const Figcaption = 45;
916
- const Figure = 46;
917
- const Footer = 29;
918
- const H1 = 5;
919
- const H2 = 22;
920
- const H3 = 23;
921
- const H4 = 24;
922
- const H5 = 25;
923
- const Header = 30;
924
- const Hr = 47;
925
- const Img = 17;
926
- const Li = 48;
927
- const Nav = 40;
928
- const Ol = 49;
929
- const P = 50;
930
- const Pre = 51;
931
- const Search = 42;
932
- const Section = 41;
933
- const Span = 8;
934
- const Text$1 = 12;
935
- const Tfoot = 59;
936
- const Time = 58;
993
+ const Abbr = 'abbr';
994
+ const Br = 'br';
995
+ const Cite = 'cite';
996
+ const Data = 'data';
997
+ const Time = 'time';
998
+ const Tfoot = 'tfoot';
937
999
 
938
1000
  const getVirtualDomTag = text => {
939
1001
  switch (text) {
940
- case H1$1:
941
- return H1;
942
- case H2$1:
943
- return H2;
944
- case H3$1:
945
- return H3;
946
- case H4$1:
947
- return H4;
948
- case H5$1:
949
- return H5;
950
- case Div$1:
951
- return Div;
952
- case Article$1:
953
- return Article;
954
- case Aside$1:
955
- return Aside;
956
- case Footer$1:
957
- return Footer;
958
- case Header$1:
959
- return Header;
960
- case Nav$1:
961
- return Nav;
962
- case Section$1:
963
- return Section;
964
- case Search$1:
965
- return Search;
966
- case Dd$1:
967
- return Dd;
968
- case Dl$1:
969
- return Dl;
970
- case Figcaption$1:
971
- return Figcaption;
972
- case Figure$1:
973
- return Figure;
974
- case Hr$1:
975
- return Hr;
976
- case Li$1:
977
- return Li;
978
- case Ol$1:
979
- return Ol;
1002
+ case H1:
1003
+ return VirtualDomElements.H1;
1004
+ case H2:
1005
+ return VirtualDomElements.H2;
1006
+ case H3:
1007
+ return VirtualDomElements.H3;
1008
+ case H4:
1009
+ return VirtualDomElements.H4;
1010
+ case H5:
1011
+ return VirtualDomElements.H5;
1012
+ case Div:
1013
+ return VirtualDomElements.Div;
1014
+ case Article:
1015
+ return VirtualDomElements.Article;
1016
+ case Aside:
1017
+ return VirtualDomElements.Aside;
1018
+ case Footer:
1019
+ return VirtualDomElements.Footer;
1020
+ case Header:
1021
+ return VirtualDomElements.Header;
1022
+ case Nav:
1023
+ return VirtualDomElements.Nav;
1024
+ case Section:
1025
+ return VirtualDomElements.Section;
1026
+ case Search:
1027
+ return VirtualDomElements.Search;
1028
+ case Dd:
1029
+ return VirtualDomElements.Dd;
1030
+ case Dl:
1031
+ return VirtualDomElements.Dl;
1032
+ case Figcaption:
1033
+ return VirtualDomElements.Figcaption;
1034
+ case Figure:
1035
+ return VirtualDomElements.Figure;
1036
+ case Hr:
1037
+ return VirtualDomElements.Hr;
1038
+ case Li:
1039
+ return VirtualDomElements.Li;
1040
+ case Ol:
1041
+ return VirtualDomElements.Ol;
980
1042
  case P$1:
981
- return P;
982
- case Pre$1:
983
- return Pre;
1043
+ return VirtualDomElements.P;
1044
+ case Pre:
1045
+ return VirtualDomElements.Pre;
984
1046
  case A$1:
985
- return A;
986
- case Abbr$1:
987
- return Abbr;
988
- case Br$1:
989
- return Br;
990
- case Cite$1:
991
- return Cite;
992
- case Data$1:
993
- return Data;
994
- case Time$1:
995
- return Time;
996
- case Tfoot$1:
997
- return Tfoot;
998
- case Img$1:
999
- return Img;
1000
- case Span$1:
1001
- return Span;
1047
+ return VirtualDomElements.A;
1048
+ case Abbr:
1049
+ return VirtualDomElements.Abbr;
1050
+ case Br:
1051
+ return VirtualDomElements.Br;
1052
+ case Cite:
1053
+ return VirtualDomElements.Cite;
1054
+ case Data:
1055
+ return VirtualDomElements.Data;
1056
+ case Time:
1057
+ return VirtualDomElements.Time;
1058
+ case Tfoot:
1059
+ return VirtualDomElements.Tfoot;
1060
+ case Img:
1061
+ return VirtualDomElements.Img;
1062
+ case Span:
1063
+ return VirtualDomElements.Span;
1002
1064
  default:
1003
- return Div;
1065
+ return VirtualDomElements.Div;
1004
1066
  }
1005
1067
  };
1006
1068
 
@@ -1029,7 +1091,7 @@ const CommentStart = 21;
1029
1091
 
1030
1092
  const isSelfClosingTag = tag => {
1031
1093
  switch (tag) {
1032
- case Img$1:
1094
+ case Img:
1033
1095
  return true;
1034
1096
  default:
1035
1097
  return false;
@@ -1294,14 +1356,6 @@ const tokenizeHtml = text => {
1294
1356
  return tokens;
1295
1357
  };
1296
1358
 
1297
- const text = data => {
1298
- return {
1299
- type: Text$1,
1300
- text: data,
1301
- childCount: 0
1302
- };
1303
- };
1304
-
1305
1359
  const parseHtml = (html, allowedAttributes) => {
1306
1360
  string(html);
1307
1361
  array(allowedAttributes);
@@ -1357,7 +1411,7 @@ const getMarkdownVirtualDom = html => {
1357
1411
  const childDom = parseHtml(html, allowedMarkdownAttributes);
1358
1412
  const markdownChildCount = getVirtualDomChildCount(childDom);
1359
1413
  return [{
1360
- type: Div,
1414
+ type: VirtualDomElements.Div,
1361
1415
  className: Markdown,
1362
1416
  role: Document,
1363
1417
  onContextMenu: HandleReadmeContextMenu,
@@ -1366,7 +1420,7 @@ const getMarkdownVirtualDom = html => {
1366
1420
  };
1367
1421
 
1368
1422
  /**
1369
- * marked v15.0.9 - a markdown parser
1423
+ * marked v16.0.0 - a markdown parser
1370
1424
  * Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
1371
1425
  * https://github.com/markedjs/marked
1372
1426
  */
@@ -1376,10 +1430,7 @@ const getMarkdownVirtualDom = html => {
1376
1430
  * The code in this file is generated from files in ./src/
1377
1431
  */
1378
1432
 
1379
- /**
1380
- * Gets the original marked default options.
1381
- */
1382
- function _getDefaults() {
1433
+ function M() {
1383
1434
  return {
1384
1435
  async: false,
1385
1436
  breaks: false,
@@ -1393,2482 +1444,1618 @@ function _getDefaults() {
1393
1444
  walkTokens: null
1394
1445
  };
1395
1446
  }
1396
- let _defaults = _getDefaults();
1397
- function changeDefaults(newDefaults) {
1398
- _defaults = newDefaults;
1447
+ var w = M();
1448
+ function H(a) {
1449
+ w = a;
1399
1450
  }
1400
- const noopTest = {
1451
+ var C = {
1401
1452
  exec: () => null
1402
1453
  };
1403
- function edit(regex, opt = '') {
1404
- let source = typeof regex === 'string' ? regex : regex.source;
1405
- const obj = {
1406
- replace: (name, val) => {
1407
- let valSource = typeof val === 'string' ? val : val.source;
1408
- valSource = valSource.replace(other.caret, '$1');
1409
- source = source.replace(name, valSource);
1410
- return obj;
1411
- },
1412
- getRegex: () => {
1413
- return new RegExp(source, opt);
1414
- }
1415
- };
1416
- return obj;
1454
+ function h(a, e = "") {
1455
+ let t = typeof a == "string" ? a : a.source,
1456
+ n = {
1457
+ replace: (s, i) => {
1458
+ let r = typeof i == "string" ? i : i.source;
1459
+ return r = r.replace(m.caret, "$1"), t = t.replace(s, r), n;
1460
+ },
1461
+ getRegex: () => new RegExp(t, e)
1462
+ };
1463
+ return n;
1417
1464
  }
1418
- const other = {
1419
- codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
1420
- outputLinkReplace: /\\([\[\]])/g,
1421
- indentCodeCompensation: /^(\s+)(?:```)/,
1422
- beginningSpace: /^\s+/,
1423
- endingHash: /#$/,
1424
- startingSpaceChar: /^ /,
1425
- endingSpaceChar: / $/,
1426
- nonSpaceChar: /[^ ]/,
1427
- newLineCharGlobal: /\n/g,
1428
- tabCharGlobal: /\t/g,
1429
- multipleSpaceGlobal: /\s+/g,
1430
- blankLine: /^[ \t]*$/,
1431
- doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
1432
- blockquoteStart: /^ {0,3}>/,
1433
- blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
1434
- blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
1435
- listReplaceTabs: /^\t+/,
1436
- listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
1437
- listIsTask: /^\[[ xX]\] /,
1438
- listReplaceTask: /^\[[ xX]\] +/,
1439
- anyLine: /\n.*\n/,
1440
- hrefBrackets: /^<(.*)>$/,
1441
- tableDelimiter: /[:|]/,
1442
- tableAlignChars: /^\||\| *$/g,
1443
- tableRowBlankLine: /\n[ \t]*$/,
1444
- tableAlignRight: /^ *-+: *$/,
1445
- tableAlignCenter: /^ *:-+: *$/,
1446
- tableAlignLeft: /^ *:-+ *$/,
1447
- startATag: /^<a /i,
1448
- endATag: /^<\/a>/i,
1449
- startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
1450
- endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
1451
- startAngleBracket: /^</,
1452
- endAngleBracket: />$/,
1453
- pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
1454
- unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
1455
- escapeTest: /[&<>"']/,
1456
- escapeReplace: /[&<>"']/g,
1457
- escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
1458
- escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
1459
- unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
1460
- caret: /(^|[^\[])\^/g,
1461
- percentDecode: /%25/g,
1462
- findPipe: /\|/g,
1463
- splitPipe: / \|/,
1464
- slashPipe: /\\\|/g,
1465
- carriageReturn: /\r\n|\r/g,
1466
- spaceLine: /^ +$/gm,
1467
- notSpaceStart: /^\S*/,
1468
- endingNewline: /\n$/,
1469
- listItemRegex: bull => new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`),
1470
- nextBulletRegex: indent => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),
1471
- hrRegex: indent => new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
1472
- fencesBeginRegex: indent => new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`),
1473
- headingBeginRegex: indent => new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`),
1474
- htmlBeginRegex: indent => new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, 'i')
1475
- };
1476
- /**
1477
- * Block-Level Grammar
1478
- */
1479
- const newline = /^(?:[ \t]*(?:\n|$))+/;
1480
- const blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
1481
- const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
1482
- const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
1483
- const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
1484
- const bullet = /(?:[*+-]|\d{1,9}[.)])/;
1485
- const lheadingCore = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
1486
- const lheading = edit(lheadingCore).replace(/bull/g, bullet) // lists can interrupt
1487
- .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
1488
- .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
1489
- .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
1490
- .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
1491
- .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
1492
- .replace(/\|table/g, '') // table not in commonmark
1493
- .getRegex();
1494
- const lheadingGfm = edit(lheadingCore).replace(/bull/g, bullet) // lists can interrupt
1495
- .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
1496
- .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
1497
- .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
1498
- .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
1499
- .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
1500
- .replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/) // table can interrupt
1501
- .getRegex();
1502
- const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
1503
- const blockText = /^[^\n]+/;
1504
- const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
1505
- const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace('label', _blockLabel).replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
1506
- const list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, bullet).getRegex();
1507
- const _tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title' + '|tr|track|ul';
1508
- const _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
1509
- const html = edit('^ {0,3}(?:' // optional indentation
1510
- + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1511
- + '|comment[^\\n]*(\\n+|$)' // (2)
1512
- + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1513
- + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1514
- + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1515
- + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (6)
1516
- + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) open tag
1517
- + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) closing tag
1518
- + ')', 'i').replace('comment', _comment).replace('tag', _tag).replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1519
- const paragraph = edit(_paragraph).replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
1520
- .replace('|table', '').replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1521
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1522
- .getRegex();
1523
- const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace('paragraph', paragraph).getRegex();
1524
- /**
1525
- * Normal Block Grammar
1526
- */
1527
- const blockNormal = {
1528
- blockquote,
1529
- code: blockCode,
1530
- def,
1531
- fences,
1532
- heading,
1533
- hr,
1534
- html,
1535
- lheading,
1536
- list,
1537
- newline,
1538
- paragraph,
1539
- table: noopTest,
1540
- text: blockText
1541
- };
1542
- /**
1543
- * GFM Block Grammar
1544
- */
1545
- const gfmTable = edit('^ *([^\\n ].*)\\n' // Header
1546
- + ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
1547
- + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)') // Cells
1548
- .replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('blockquote', ' {0,3}>').replace('code', '(?: {4}| {0,3}\t)[^\\n]').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1549
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // tables can be interrupted by type (6) html blocks
1550
- .getRegex();
1551
- const blockGfm = {
1552
- ...blockNormal,
1553
- lheading: lheadingGfm,
1554
- table: gfmTable,
1555
- paragraph: edit(_paragraph).replace('hr', hr).replace('heading', ' {0,3}#{1,6}(?:\\s|$)').replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
1556
- .replace('table', gfmTable) // interrupt paragraphs with table
1557
- .replace('blockquote', ' {0,3}>').replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n').replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1558
- .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)').replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1559
- .getRegex()
1560
- };
1561
- /**
1562
- * Pedantic grammar (original John Gruber's loose markdown specification)
1563
- */
1564
- const blockPedantic = {
1565
- ...blockNormal,
1566
- html: edit('^ *(?:comment *(?:\\n|\\s*$)' + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1567
- + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))').replace('comment', _comment).replace(/tag/g, '(?!(?:' + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub' + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)' + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b').getRegex(),
1568
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1569
- heading: /^(#{1,6})(.*)(?:\n+|$)/,
1570
- fences: noopTest,
1571
- // fences not supported
1572
- lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1573
- paragraph: edit(_paragraph).replace('hr', hr).replace('heading', ' *#{1,6} *[^\n]').replace('lheading', lheading).replace('|table', '').replace('blockquote', ' {0,3}>').replace('|fences', '').replace('|list', '').replace('|html', '').replace('|tag', '').getRegex()
1574
- };
1575
- /**
1576
- * Inline-Level Grammar
1577
- */
1578
- const escape$1 = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
1579
- const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
1580
- const br = /^( {2,}|\\)\n(?!\s*$)/;
1581
- const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
1582
- // list of unicode punctuation marks, plus any missing characters from CommonMark spec
1583
- const _punctuation = /[\p{P}\p{S}]/u;
1584
- const _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
1585
- const _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
1586
- const punctuation = edit(/^((?![*_])punctSpace)/, 'u').replace(/punctSpace/g, _punctuationOrSpace).getRegex();
1587
- // GFM allows ~ inside strong and em for strikethrough
1588
- const _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
1589
- const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
1590
- const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
1591
- // sequences em should skip over [title](link), `code`, <html>
1592
- const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
1593
- const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
1594
- const emStrongLDelim = edit(emStrongLDelimCore, 'u').replace(/punct/g, _punctuation).getRegex();
1595
- const emStrongLDelimGfm = edit(emStrongLDelimCore, 'u').replace(/punct/g, _punctuationGfmStrongEm).getRegex();
1596
- const emStrongRDelimAstCore = '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
1597
- + '|[^*]+(?=[^*])' // Consume to delim
1598
- + '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
1599
- + '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
1600
- + '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
1601
- + '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
1602
- + '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
1603
- + '|notPunctSpace(\\*+)(?=notPunctSpace)'; // (6) a***a can be either Left or Right Delimiter
1604
- const emStrongRDelimAst = edit(emStrongRDelimAstCore, 'gu').replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
1605
- const emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, 'gu').replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm).replace(/punct/g, _punctuationGfmStrongEm).getRegex();
1606
- // (6) Not allowed for _
1607
- const emStrongRDelimUnd = edit('^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
1608
- + '|[^_]+(?=[^_])' // Consume to delim
1609
- + '|(?!_)punct(_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter
1610
- + '|notPunctSpace(_+)(?!_)(?=punctSpace|$)' // (2) a___#, a___ can only be a Right Delimiter
1611
- + '|(?!_)punctSpace(_+)(?=notPunctSpace)' // (3) #___a, ___a can only be Left Delimiter
1612
- + '|[\\s](_+)(?!_)(?=punct)' // (4) ___# can only be Left Delimiter
1613
- + '|(?!_)punct(_+)(?!_)(?=punct)', 'gu') // (5) #___# can be either Left or Right Delimiter
1614
- .replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
1615
- const anyPunctuation = edit(/\\(punct)/, 'gu').replace(/punct/g, _punctuation).getRegex();
1616
- const autolink = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace('scheme', /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace('email', /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
1617
- const _inlineComment = edit(_comment).replace('(?:-->|$)', '-->').getRegex();
1618
- const tag = edit('^comment' + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1619
- + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1620
- + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1621
- + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1622
- + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>') // CDATA section
1623
- .replace('comment', _inlineComment).replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
1624
- const _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1625
- const link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace('label', _inlineLabel).replace('href', /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace('title', /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
1626
- const reflink = edit(/^!?\[(label)\]\[(ref)\]/).replace('label', _inlineLabel).replace('ref', _blockLabel).getRegex();
1627
- const nolink = edit(/^!?\[(ref)\](?:\[\])?/).replace('ref', _blockLabel).getRegex();
1628
- const reflinkSearch = edit('reflink|nolink(?!\\()', 'g').replace('reflink', reflink).replace('nolink', nolink).getRegex();
1629
- /**
1630
- * Normal Inline Grammar
1631
- */
1632
- const inlineNormal = {
1633
- _backpedal: noopTest,
1634
- // only used for GFM url
1635
- anyPunctuation,
1636
- autolink,
1637
- blockSkip,
1638
- br,
1639
- code: inlineCode,
1640
- del: noopTest,
1641
- emStrongLDelim,
1642
- emStrongRDelimAst,
1643
- emStrongRDelimUnd,
1644
- escape: escape$1,
1645
- link,
1646
- nolink,
1647
- punctuation,
1648
- reflink,
1649
- reflinkSearch,
1650
- tag,
1651
- text: inlineText,
1652
- url: noopTest
1653
- };
1654
- /**
1655
- * Pedantic Inline Grammar
1656
- */
1657
- const inlinePedantic = {
1658
- ...inlineNormal,
1659
- link: edit(/^!?\[(label)\]\((.*?)\)/).replace('label', _inlineLabel).getRegex(),
1660
- reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace('label', _inlineLabel).getRegex()
1661
- };
1662
- /**
1663
- * GFM Inline Grammar
1664
- */
1665
- const inlineGfm = {
1666
- ...inlineNormal,
1667
- emStrongRDelimAst: emStrongRDelimAstGfm,
1668
- emStrongLDelim: emStrongLDelimGfm,
1669
- url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i').replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
1670
- _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1671
- del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
1672
- text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1673
- };
1674
- /**
1675
- * GFM + Line Breaks Inline Grammar
1676
- */
1677
- const inlineBreaks = {
1678
- ...inlineGfm,
1679
- br: edit(br).replace('{2,}', '*').getRegex(),
1680
- text: edit(inlineGfm.text).replace('\\b_', '\\b_| {2,}\\n').replace(/\{2,\}/g, '*').getRegex()
1681
- };
1682
- /**
1683
- * exports
1684
- */
1685
- const block = {
1686
- normal: blockNormal,
1687
- gfm: blockGfm,
1688
- pedantic: blockPedantic
1689
- };
1690
- const inline = {
1691
- normal: inlineNormal,
1692
- gfm: inlineGfm,
1693
- breaks: inlineBreaks,
1694
- pedantic: inlinePedantic
1695
- };
1696
-
1697
- /**
1698
- * Helpers
1699
- */
1700
- const escapeReplacements = {
1701
- '&': '&amp;',
1702
- '<': '&lt;',
1703
- '>': '&gt;',
1704
- '"': '&quot;',
1705
- "'": '&#39;'
1706
- };
1707
- const getEscapeReplacement = ch => escapeReplacements[ch];
1708
- function escape(html, encode) {
1709
- if (encode) {
1710
- if (other.escapeTest.test(html)) {
1711
- return html.replace(other.escapeReplace, getEscapeReplacement);
1712
- }
1713
- } else {
1714
- if (other.escapeTestNoEncode.test(html)) {
1715
- return html.replace(other.escapeReplaceNoEncode, getEscapeReplacement);
1716
- }
1717
- }
1718
- return html;
1465
+ var m = {
1466
+ codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
1467
+ outputLinkReplace: /\\([\[\]])/g,
1468
+ indentCodeCompensation: /^(\s+)(?:```)/,
1469
+ beginningSpace: /^\s+/,
1470
+ endingHash: /#$/,
1471
+ startingSpaceChar: /^ /,
1472
+ endingSpaceChar: / $/,
1473
+ nonSpaceChar: /[^ ]/,
1474
+ newLineCharGlobal: /\n/g,
1475
+ tabCharGlobal: /\t/g,
1476
+ multipleSpaceGlobal: /\s+/g,
1477
+ blankLine: /^[ \t]*$/,
1478
+ doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
1479
+ blockquoteStart: /^ {0,3}>/,
1480
+ blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g,
1481
+ blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm,
1482
+ listReplaceTabs: /^\t+/,
1483
+ listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g,
1484
+ listIsTask: /^\[[ xX]\] /,
1485
+ listReplaceTask: /^\[[ xX]\] +/,
1486
+ anyLine: /\n.*\n/,
1487
+ hrefBrackets: /^<(.*)>$/,
1488
+ tableDelimiter: /[:|]/,
1489
+ tableAlignChars: /^\||\| *$/g,
1490
+ tableRowBlankLine: /\n[ \t]*$/,
1491
+ tableAlignRight: /^ *-+: *$/,
1492
+ tableAlignCenter: /^ *:-+: *$/,
1493
+ tableAlignLeft: /^ *:-+ *$/,
1494
+ startATag: /^<a /i,
1495
+ endATag: /^<\/a>/i,
1496
+ startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i,
1497
+ endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i,
1498
+ startAngleBracket: /^</,
1499
+ endAngleBracket: />$/,
1500
+ pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/,
1501
+ unicodeAlphaNumeric: /[\p{L}\p{N}]/u,
1502
+ escapeTest: /[&<>"']/,
1503
+ escapeReplace: /[&<>"']/g,
1504
+ escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
1505
+ escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,
1506
+ unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,
1507
+ caret: /(^|[^\[])\^/g,
1508
+ percentDecode: /%25/g,
1509
+ findPipe: /\|/g,
1510
+ splitPipe: / \|/,
1511
+ slashPipe: /\\\|/g,
1512
+ carriageReturn: /\r\n|\r/g,
1513
+ spaceLine: /^ +$/gm,
1514
+ notSpaceStart: /^\S*/,
1515
+ endingNewline: /\n$/,
1516
+ listItemRegex: a => new RegExp(`^( {0,3}${a})((?:[ ][^\\n]*)?(?:\\n|$))`),
1517
+ nextBulletRegex: a => new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),
1518
+ hrRegex: a => new RegExp(`^ {0,${Math.min(3, a - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),
1519
+ fencesBeginRegex: a => new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:\`\`\`|~~~)`),
1520
+ headingBeginRegex: a => new RegExp(`^ {0,${Math.min(3, a - 1)}}#`),
1521
+ htmlBeginRegex: a => new RegExp(`^ {0,${Math.min(3, a - 1)}}<(?:[a-z].*>|!--)`, "i")
1522
+ },
1523
+ xe = /^(?:[ \t]*(?:\n|$))+/,
1524
+ be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,
1525
+ Te = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1526
+ I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
1527
+ we = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1528
+ j = /(?:[*+-]|\d{1,9}[.)])/,
1529
+ re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1530
+ ie = h(re).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex(),
1531
+ ye = h(re).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),
1532
+ F = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
1533
+ Re = /^[^\n]+/,
1534
+ Q = /(?!\s*\])(?:\\.|[^\[\]\\])+/,
1535
+ Se = h(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", Q).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),
1536
+ $e = h(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, j).getRegex(),
1537
+ v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",
1538
+ U = /<!--(?:-?>|[\s\S]*?(?:-->|$))/,
1539
+ _e = h("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", U).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),
1540
+ oe = h(F).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(),
1541
+ Le = h(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", oe).getRegex(),
1542
+ K = {
1543
+ blockquote: Le,
1544
+ code: be,
1545
+ def: Se,
1546
+ fences: Te,
1547
+ heading: we,
1548
+ hr: I,
1549
+ html: _e,
1550
+ lheading: ie,
1551
+ list: $e,
1552
+ newline: xe,
1553
+ paragraph: oe,
1554
+ table: C,
1555
+ text: Re
1556
+ },
1557
+ se = h("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex(),
1558
+ ze = {
1559
+ ...K,
1560
+ lheading: ye,
1561
+ table: se,
1562
+ paragraph: h(F).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex()
1563
+ },
1564
+ Me = {
1565
+ ...K,
1566
+ html: h(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", U).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
1567
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1568
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
1569
+ fences: C,
1570
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1571
+ paragraph: h(F).replace("hr", I).replace("heading", ` *#{1,6} *[^
1572
+ ]`).replace("lheading", ie).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex()
1573
+ },
1574
+ Pe = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1575
+ Ae = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1576
+ le = /^( {2,}|\\)\n(?!\s*$)/,
1577
+ Ee = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
1578
+ D = /[\p{P}\p{S}]/u,
1579
+ X = /[\s\p{P}\p{S}]/u,
1580
+ ae = /[^\s\p{P}\p{S}]/u,
1581
+ Ce = h(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, X).getRegex(),
1582
+ ce = /(?!~)[\p{P}\p{S}]/u,
1583
+ Ie = /(?!~)[\s\p{P}\p{S}]/u,
1584
+ Oe = /(?:[^\s\p{P}\p{S}]|~)/u,
1585
+ Be = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,
1586
+ pe = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,
1587
+ qe = h(pe, "u").replace(/punct/g, D).getRegex(),
1588
+ ve = h(pe, "u").replace(/punct/g, ce).getRegex(),
1589
+ ue = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",
1590
+ De = h(ue, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, X).replace(/punct/g, D).getRegex(),
1591
+ Ze = h(ue, "gu").replace(/notPunctSpace/g, Oe).replace(/punctSpace/g, Ie).replace(/punct/g, ce).getRegex(),
1592
+ Ge = h("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, X).replace(/punct/g, D).getRegex(),
1593
+ He = h(/\\(punct)/, "gu").replace(/punct/g, D).getRegex(),
1594
+ Ne = h(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),
1595
+ je = h(U).replace("(?:-->|$)", "-->").getRegex(),
1596
+ Fe = h("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", je).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),
1597
+ q = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,
1598
+ Qe = h(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),
1599
+ he = h(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", Q).getRegex(),
1600
+ ke = h(/^!?\[(ref)\](?:\[\])?/).replace("ref", Q).getRegex(),
1601
+ Ue = h("reflink|nolink(?!\\()", "g").replace("reflink", he).replace("nolink", ke).getRegex(),
1602
+ W = {
1603
+ _backpedal: C,
1604
+ anyPunctuation: He,
1605
+ autolink: Ne,
1606
+ blockSkip: Be,
1607
+ br: le,
1608
+ code: Ae,
1609
+ del: C,
1610
+ emStrongLDelim: qe,
1611
+ emStrongRDelimAst: De,
1612
+ emStrongRDelimUnd: Ge,
1613
+ escape: Pe,
1614
+ link: Qe,
1615
+ nolink: ke,
1616
+ punctuation: Ce,
1617
+ reflink: he,
1618
+ reflinkSearch: Ue,
1619
+ tag: Fe,
1620
+ text: Ee,
1621
+ url: C
1622
+ },
1623
+ Ke = {
1624
+ ...W,
1625
+ link: h(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(),
1626
+ reflink: h(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex()
1627
+ },
1628
+ N = {
1629
+ ...W,
1630
+ emStrongRDelimAst: Ze,
1631
+ emStrongLDelim: ve,
1632
+ url: h(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i").replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
1633
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1634
+ del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
1635
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1636
+ },
1637
+ Xe = {
1638
+ ...N,
1639
+ br: h(le).replace("{2,}", "*").getRegex(),
1640
+ text: h(N.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
1641
+ },
1642
+ O = {
1643
+ normal: K,
1644
+ gfm: ze,
1645
+ pedantic: Me
1646
+ },
1647
+ P = {
1648
+ normal: W,
1649
+ gfm: N,
1650
+ breaks: Xe,
1651
+ pedantic: Ke
1652
+ };
1653
+ var We = {
1654
+ "&": "&amp;",
1655
+ "<": "&lt;",
1656
+ ">": "&gt;",
1657
+ '"': "&quot;",
1658
+ "'": "&#39;"
1659
+ },
1660
+ ge = a => We[a];
1661
+ function R(a, e) {
1662
+ if (e) {
1663
+ if (m.escapeTest.test(a)) return a.replace(m.escapeReplace, ge);
1664
+ } else if (m.escapeTestNoEncode.test(a)) return a.replace(m.escapeReplaceNoEncode, ge);
1665
+ return a;
1719
1666
  }
1720
- function cleanUrl(href) {
1667
+ function J(a) {
1721
1668
  try {
1722
- href = encodeURI(href).replace(other.percentDecode, '%');
1669
+ a = encodeURI(a).replace(m.percentDecode, "%");
1723
1670
  } catch {
1724
1671
  return null;
1725
1672
  }
1726
- return href;
1673
+ return a;
1727
1674
  }
1728
- function splitCells(tableRow, count) {
1729
- // ensure that every cell-delimiting pipe has a space
1730
- // before it to distinguish it from an escaped pipe
1731
- const row = tableRow.replace(other.findPipe, (match, offset, str) => {
1732
- let escaped = false;
1733
- let curr = offset;
1734
- while (--curr >= 0 && str[curr] === '\\') escaped = !escaped;
1735
- if (escaped) {
1736
- // odd number of slashes means | is escaped
1737
- // so we leave it alone
1738
- return '|';
1739
- } else {
1740
- // add space before unescaped |
1741
- return ' |';
1742
- }
1675
+ function V(a, e) {
1676
+ let t = a.replace(m.findPipe, (i, r, o) => {
1677
+ let l = false,
1678
+ c = r;
1679
+ for (; --c >= 0 && o[c] === "\\";) l = !l;
1680
+ return l ? "|" : " |";
1743
1681
  }),
1744
- cells = row.split(other.splitPipe);
1745
- let i = 0;
1746
- // First/last cell in a row cannot be empty if it has no leading/trailing pipe
1747
- if (!cells[0].trim()) {
1748
- cells.shift();
1749
- }
1750
- if (cells.length > 0 && !cells.at(-1)?.trim()) {
1751
- cells.pop();
1752
- }
1753
- if (count) {
1754
- if (cells.length > count) {
1755
- cells.splice(count);
1756
- } else {
1757
- while (cells.length < count) cells.push('');
1758
- }
1759
- }
1760
- for (; i < cells.length; i++) {
1761
- // leading or trailing whitespace is ignored per the gfm spec
1762
- cells[i] = cells[i].trim().replace(other.slashPipe, '|');
1763
- }
1764
- return cells;
1682
+ n = t.split(m.splitPipe),
1683
+ s = 0;
1684
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);else for (; n.length < e;) n.push("");
1685
+ for (; s < n.length; s++) n[s] = n[s].trim().replace(m.slashPipe, "|");
1686
+ return n;
1765
1687
  }
1766
- /**
1767
- * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
1768
- * /c*$/ is vulnerable to REDOS.
1769
- *
1770
- * @param str
1771
- * @param c
1772
- * @param invert Remove suffix of non-c chars instead. Default falsey.
1773
- */
1774
- function rtrim(str, c, invert) {
1775
- const l = str.length;
1776
- if (l === 0) {
1777
- return '';
1778
- }
1779
- // Length of suffix matching the invert condition.
1780
- let suffLen = 0;
1781
- // Step left until we fail to match the invert condition.
1782
- while (suffLen < l) {
1783
- const currChar = str.charAt(l - suffLen - 1);
1784
- if (currChar === c && true) {
1785
- suffLen++;
1786
- } else {
1787
- break;
1788
- }
1789
- }
1790
- return str.slice(0, l - suffLen);
1688
+ function A(a, e, t) {
1689
+ let n = a.length;
1690
+ if (n === 0) return "";
1691
+ let s = 0;
1692
+ for (; s < n;) {
1693
+ let i = a.charAt(n - s - 1);
1694
+ if (i === e && true) s++;else break;
1695
+ }
1696
+ return a.slice(0, n - s);
1791
1697
  }
1792
- function findClosingBracket(str, b) {
1793
- if (str.indexOf(b[1]) === -1) {
1794
- return -1;
1795
- }
1796
- let level = 0;
1797
- for (let i = 0; i < str.length; i++) {
1798
- if (str[i] === '\\') {
1799
- i++;
1800
- } else if (str[i] === b[0]) {
1801
- level++;
1802
- } else if (str[i] === b[1]) {
1803
- level--;
1804
- if (level < 0) {
1805
- return i;
1806
- }
1807
- }
1808
- }
1809
- if (level > 0) {
1810
- return -2;
1811
- }
1812
- return -1;
1698
+ function fe(a, e) {
1699
+ if (a.indexOf(e[1]) === -1) return -1;
1700
+ let t = 0;
1701
+ for (let n = 0; n < a.length; n++) if (a[n] === "\\") n++;else if (a[n] === e[0]) t++;else if (a[n] === e[1] && (t--, t < 0)) return n;
1702
+ return t > 0 ? -2 : -1;
1813
1703
  }
1814
- function outputLink(cap, link, raw, lexer, rules) {
1815
- const href = link.href;
1816
- const title = link.title || null;
1817
- const text = cap[1].replace(rules.other.outputLinkReplace, '$1');
1818
- if (cap[0].charAt(0) !== '!') {
1819
- lexer.state.inLink = true;
1820
- const token = {
1821
- type: 'link',
1822
- raw,
1823
- href,
1824
- title,
1825
- text,
1826
- tokens: lexer.inlineTokens(text)
1827
- };
1828
- lexer.state.inLink = false;
1829
- return token;
1830
- }
1831
- return {
1832
- type: 'image',
1833
- raw,
1834
- href,
1835
- title,
1836
- text
1704
+ function de(a, e, t, n, s) {
1705
+ let i = e.href,
1706
+ r = e.title || null,
1707
+ o = a[1].replace(s.other.outputLinkReplace, "$1");
1708
+ n.state.inLink = true;
1709
+ let l = {
1710
+ type: a[0].charAt(0) === "!" ? "image" : "link",
1711
+ raw: t,
1712
+ href: i,
1713
+ title: r,
1714
+ text: o,
1715
+ tokens: n.inlineTokens(o)
1837
1716
  };
1717
+ return n.state.inLink = false, l;
1838
1718
  }
1839
- function indentCodeCompensation(raw, text, rules) {
1840
- const matchIndentToCode = raw.match(rules.other.indentCodeCompensation);
1841
- if (matchIndentToCode === null) {
1842
- return text;
1843
- }
1844
- const indentToCode = matchIndentToCode[1];
1845
- return text.split('\n').map(node => {
1846
- const matchIndentInNode = node.match(rules.other.beginningSpace);
1847
- if (matchIndentInNode === null) {
1848
- return node;
1849
- }
1850
- const [indentInNode] = matchIndentInNode;
1851
- if (indentInNode.length >= indentToCode.length) {
1852
- return node.slice(indentToCode.length);
1853
- }
1854
- return node;
1855
- }).join('\n');
1719
+ function Je(a, e, t) {
1720
+ let n = a.match(t.other.indentCodeCompensation);
1721
+ if (n === null) return e;
1722
+ let s = n[1];
1723
+ return e.split(`
1724
+ `).map(i => {
1725
+ let r = i.match(t.other.beginningSpace);
1726
+ if (r === null) return i;
1727
+ let [o] = r;
1728
+ return o.length >= s.length ? i.slice(s.length) : i;
1729
+ }).join(`
1730
+ `);
1856
1731
  }
1857
- /**
1858
- * Tokenizer
1859
- */
1860
- class _Tokenizer {
1732
+ var S = class {
1861
1733
  options;
1862
- rules; // set by the lexer
1863
- lexer; // set by the lexer
1864
- constructor(options) {
1865
- this.options = options || _defaults;
1866
- }
1867
- space(src) {
1868
- const cap = this.rules.block.newline.exec(src);
1869
- if (cap && cap[0].length > 0) {
1870
- return {
1871
- type: 'space',
1872
- raw: cap[0]
1873
- };
1874
- }
1734
+ rules;
1735
+ lexer;
1736
+ constructor(e) {
1737
+ this.options = e || w;
1738
+ }
1739
+ space(e) {
1740
+ let t = this.rules.block.newline.exec(e);
1741
+ if (t && t[0].length > 0) return {
1742
+ type: "space",
1743
+ raw: t[0]
1744
+ };
1875
1745
  }
1876
- code(src) {
1877
- const cap = this.rules.block.code.exec(src);
1878
- if (cap) {
1879
- const text = cap[0].replace(this.rules.other.codeRemoveIndent, '');
1746
+ code(e) {
1747
+ let t = this.rules.block.code.exec(e);
1748
+ if (t) {
1749
+ let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
1880
1750
  return {
1881
- type: 'code',
1882
- raw: cap[0],
1883
- codeBlockStyle: 'indented',
1884
- text: !this.options.pedantic ? rtrim(text, '\n') : text
1751
+ type: "code",
1752
+ raw: t[0],
1753
+ codeBlockStyle: "indented",
1754
+ text: this.options.pedantic ? n : A(n, `
1755
+ `)
1885
1756
  };
1886
1757
  }
1887
1758
  }
1888
- fences(src) {
1889
- const cap = this.rules.block.fences.exec(src);
1890
- if (cap) {
1891
- const raw = cap[0];
1892
- const text = indentCodeCompensation(raw, cap[3] || '', this.rules);
1759
+ fences(e) {
1760
+ let t = this.rules.block.fences.exec(e);
1761
+ if (t) {
1762
+ let n = t[0],
1763
+ s = Je(n, t[3] || "", this.rules);
1893
1764
  return {
1894
- type: 'code',
1895
- raw,
1896
- lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
1897
- text
1765
+ type: "code",
1766
+ raw: n,
1767
+ lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2],
1768
+ text: s
1898
1769
  };
1899
1770
  }
1900
1771
  }
1901
- heading(src) {
1902
- const cap = this.rules.block.heading.exec(src);
1903
- if (cap) {
1904
- let text = cap[2].trim();
1905
- // remove trailing #s
1906
- if (this.rules.other.endingHash.test(text)) {
1907
- const trimmed = rtrim(text, '#');
1908
- if (this.options.pedantic) {
1909
- text = trimmed.trim();
1910
- } else if (!trimmed || this.rules.other.endingSpaceChar.test(trimmed)) {
1911
- // CommonMark requires space before trailing #s
1912
- text = trimmed.trim();
1913
- }
1772
+ heading(e) {
1773
+ let t = this.rules.block.heading.exec(e);
1774
+ if (t) {
1775
+ let n = t[2].trim();
1776
+ if (this.rules.other.endingHash.test(n)) {
1777
+ let s = A(n, "#");
1778
+ (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
1914
1779
  }
1915
1780
  return {
1916
- type: 'heading',
1917
- raw: cap[0],
1918
- depth: cap[1].length,
1919
- text,
1920
- tokens: this.lexer.inline(text)
1781
+ type: "heading",
1782
+ raw: t[0],
1783
+ depth: t[1].length,
1784
+ text: n,
1785
+ tokens: this.lexer.inline(n)
1921
1786
  };
1922
1787
  }
1923
1788
  }
1924
- hr(src) {
1925
- const cap = this.rules.block.hr.exec(src);
1926
- if (cap) {
1927
- return {
1928
- type: 'hr',
1929
- raw: rtrim(cap[0], '\n')
1930
- };
1931
- }
1789
+ hr(e) {
1790
+ let t = this.rules.block.hr.exec(e);
1791
+ if (t) return {
1792
+ type: "hr",
1793
+ raw: A(t[0], `
1794
+ `)
1795
+ };
1932
1796
  }
1933
- blockquote(src) {
1934
- const cap = this.rules.block.blockquote.exec(src);
1935
- if (cap) {
1936
- let lines = rtrim(cap[0], '\n').split('\n');
1937
- let raw = '';
1938
- let text = '';
1939
- const tokens = [];
1940
- while (lines.length > 0) {
1941
- let inBlockquote = false;
1942
- const currentLines = [];
1943
- let i;
1944
- for (i = 0; i < lines.length; i++) {
1945
- // get lines up to a continuation
1946
- if (this.rules.other.blockquoteStart.test(lines[i])) {
1947
- currentLines.push(lines[i]);
1948
- inBlockquote = true;
1949
- } else if (!inBlockquote) {
1950
- currentLines.push(lines[i]);
1951
- } else {
1952
- break;
1953
- }
1954
- }
1955
- lines = lines.slice(i);
1956
- const currentRaw = currentLines.join('\n');
1957
- const currentText = currentRaw
1958
- // precede setext continuation with 4 spaces so it isn't a setext
1959
- .replace(this.rules.other.blockquoteSetextReplace, '\n $1').replace(this.rules.other.blockquoteSetextReplace2, '');
1960
- raw = raw ? `${raw}\n${currentRaw}` : currentRaw;
1961
- text = text ? `${text}\n${currentText}` : currentText;
1962
- // parse blockquote lines as top level tokens
1963
- // merge paragraphs if this is a continuation
1964
- const top = this.lexer.state.top;
1965
- this.lexer.state.top = true;
1966
- this.lexer.blockTokens(currentText, tokens, true);
1967
- this.lexer.state.top = top;
1968
- // if there is no continuation then we are done
1969
- if (lines.length === 0) {
1970
- break;
1971
- }
1972
- const lastToken = tokens.at(-1);
1973
- if (lastToken?.type === 'code') {
1974
- // blockquote continuation cannot be preceded by a code block
1797
+ blockquote(e) {
1798
+ let t = this.rules.block.blockquote.exec(e);
1799
+ if (t) {
1800
+ let n = A(t[0], `
1801
+ `).split(`
1802
+ `),
1803
+ s = "",
1804
+ i = "",
1805
+ r = [];
1806
+ for (; n.length > 0;) {
1807
+ let o = false,
1808
+ l = [],
1809
+ c;
1810
+ for (c = 0; c < n.length; c++) if (this.rules.other.blockquoteStart.test(n[c])) l.push(n[c]), o = true;else if (!o) l.push(n[c]);else break;
1811
+ n = n.slice(c);
1812
+ let p = l.join(`
1813
+ `),
1814
+ u = p.replace(this.rules.other.blockquoteSetextReplace, `
1815
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
1816
+ s = s ? `${s}
1817
+ ${p}` : p, i = i ? `${i}
1818
+ ${u}` : u;
1819
+ let d = this.lexer.state.top;
1820
+ if (this.lexer.state.top = true, this.lexer.blockTokens(u, r, true), this.lexer.state.top = d, n.length === 0) break;
1821
+ let g = r.at(-1);
1822
+ if (g?.type === "code") break;
1823
+ if (g?.type === "blockquote") {
1824
+ let x = g,
1825
+ f = x.raw + `
1826
+ ` + n.join(`
1827
+ `),
1828
+ y = this.blockquote(f);
1829
+ r[r.length - 1] = y, s = s.substring(0, s.length - x.raw.length) + y.raw, i = i.substring(0, i.length - x.text.length) + y.text;
1975
1830
  break;
1976
- } else if (lastToken?.type === 'blockquote') {
1977
- // include continuation in nested blockquote
1978
- const oldToken = lastToken;
1979
- const newText = oldToken.raw + '\n' + lines.join('\n');
1980
- const newToken = this.blockquote(newText);
1981
- tokens[tokens.length - 1] = newToken;
1982
- raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
1983
- text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
1984
- break;
1985
- } else if (lastToken?.type === 'list') {
1986
- // include continuation in nested list
1987
- const oldToken = lastToken;
1988
- const newText = oldToken.raw + '\n' + lines.join('\n');
1989
- const newToken = this.list(newText);
1990
- tokens[tokens.length - 1] = newToken;
1991
- raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
1992
- text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
1993
- lines = newText.substring(tokens.at(-1).raw.length).split('\n');
1831
+ } else if (g?.type === "list") {
1832
+ let x = g,
1833
+ f = x.raw + `
1834
+ ` + n.join(`
1835
+ `),
1836
+ y = this.list(f);
1837
+ r[r.length - 1] = y, s = s.substring(0, s.length - g.raw.length) + y.raw, i = i.substring(0, i.length - x.raw.length) + y.raw, n = f.substring(r.at(-1).raw.length).split(`
1838
+ `);
1994
1839
  continue;
1995
1840
  }
1996
1841
  }
1997
1842
  return {
1998
- type: 'blockquote',
1999
- raw,
2000
- tokens,
2001
- text
1843
+ type: "blockquote",
1844
+ raw: s,
1845
+ tokens: r,
1846
+ text: i
2002
1847
  };
2003
1848
  }
2004
1849
  }
2005
- list(src) {
2006
- let cap = this.rules.block.list.exec(src);
2007
- if (cap) {
2008
- let bull = cap[1].trim();
2009
- const isordered = bull.length > 1;
2010
- const list = {
2011
- type: 'list',
2012
- raw: '',
2013
- ordered: isordered,
2014
- start: isordered ? +bull.slice(0, -1) : '',
2015
- loose: false,
2016
- items: []
2017
- };
2018
- bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
2019
- if (this.options.pedantic) {
2020
- bull = isordered ? bull : '[*+-]';
2021
- }
2022
- // Get next list item
2023
- const itemRegex = this.rules.other.listItemRegex(bull);
2024
- let endsWithBlankLine = false;
2025
- // Check if current bullet point can start a new List Item
2026
- while (src) {
2027
- let endEarly = false;
2028
- let raw = '';
2029
- let itemContents = '';
2030
- if (!(cap = itemRegex.exec(src))) {
2031
- break;
2032
- }
2033
- if (this.rules.block.hr.test(src)) {
2034
- // End list if bullet was actually HR (possibly move into itemRegex?)
2035
- break;
2036
- }
2037
- raw = cap[0];
2038
- src = src.substring(raw.length);
2039
- let line = cap[2].split('\n', 1)[0].replace(this.rules.other.listReplaceTabs, t => ' '.repeat(3 * t.length));
2040
- let nextLine = src.split('\n', 1)[0];
2041
- let blankLine = !line.trim();
2042
- let indent = 0;
2043
- if (this.options.pedantic) {
2044
- indent = 2;
2045
- itemContents = line.trimStart();
2046
- } else if (blankLine) {
2047
- indent = cap[1].length + 1;
2048
- } else {
2049
- indent = cap[2].search(this.rules.other.nonSpaceChar); // Find first non-space char
2050
- indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
2051
- itemContents = line.slice(indent);
2052
- indent += cap[1].length;
2053
- }
2054
- if (blankLine && this.rules.other.blankLine.test(nextLine)) {
2055
- // Items begin with at most one blank line
2056
- raw += nextLine + '\n';
2057
- src = src.substring(nextLine.length + 1);
2058
- endEarly = true;
2059
- }
2060
- if (!endEarly) {
2061
- const nextBulletRegex = this.rules.other.nextBulletRegex(indent);
2062
- const hrRegex = this.rules.other.hrRegex(indent);
2063
- const fencesBeginRegex = this.rules.other.fencesBeginRegex(indent);
2064
- const headingBeginRegex = this.rules.other.headingBeginRegex(indent);
2065
- const htmlBeginRegex = this.rules.other.htmlBeginRegex(indent);
2066
- // Check if following lines should be included in List Item
2067
- while (src) {
2068
- const rawLine = src.split('\n', 1)[0];
2069
- let nextLineWithoutTabs;
2070
- nextLine = rawLine;
2071
- // Re-align to follow commonmark nesting rules
2072
- if (this.options.pedantic) {
2073
- nextLine = nextLine.replace(this.rules.other.listReplaceNesting, ' ');
2074
- nextLineWithoutTabs = nextLine;
2075
- } else {
2076
- nextLineWithoutTabs = nextLine.replace(this.rules.other.tabCharGlobal, ' ');
2077
- }
2078
- // End list item if found code fences
2079
- if (fencesBeginRegex.test(nextLine)) {
2080
- break;
2081
- }
2082
- // End list item if found start of new heading
2083
- if (headingBeginRegex.test(nextLine)) {
2084
- break;
2085
- }
2086
- // End list item if found start of html block
2087
- if (htmlBeginRegex.test(nextLine)) {
2088
- break;
2089
- }
2090
- // End list item if found start of new bullet
2091
- if (nextBulletRegex.test(nextLine)) {
2092
- break;
2093
- }
2094
- // Horizontal rule found
2095
- if (hrRegex.test(nextLine)) {
2096
- break;
2097
- }
2098
- if (nextLineWithoutTabs.search(this.rules.other.nonSpaceChar) >= indent || !nextLine.trim()) {
2099
- // Dedent if possible
2100
- itemContents += '\n' + nextLineWithoutTabs.slice(indent);
2101
- } else {
2102
- // not enough indentation
2103
- if (blankLine) {
2104
- break;
2105
- }
2106
- // paragraph continuation unless last line was a different block level element
2107
- if (line.replace(this.rules.other.tabCharGlobal, ' ').search(this.rules.other.nonSpaceChar) >= 4) {
2108
- // indented code block
2109
- break;
2110
- }
2111
- if (fencesBeginRegex.test(line)) {
2112
- break;
2113
- }
2114
- if (headingBeginRegex.test(line)) {
2115
- break;
2116
- }
2117
- if (hrRegex.test(line)) {
2118
- break;
2119
- }
2120
- itemContents += '\n' + nextLine;
2121
- }
2122
- if (!blankLine && !nextLine.trim()) {
2123
- // Check if current line is blank
2124
- blankLine = true;
1850
+ list(e) {
1851
+ let t = this.rules.block.list.exec(e);
1852
+ if (t) {
1853
+ let n = t[1].trim(),
1854
+ s = n.length > 1,
1855
+ i = {
1856
+ type: "list",
1857
+ raw: "",
1858
+ ordered: s,
1859
+ start: s ? +n.slice(0, -1) : "",
1860
+ loose: false,
1861
+ items: []
1862
+ };
1863
+ n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
1864
+ let r = this.rules.other.listItemRegex(n),
1865
+ o = false;
1866
+ for (; e;) {
1867
+ let c = false,
1868
+ p = "",
1869
+ u = "";
1870
+ if (!(t = r.exec(e)) || this.rules.block.hr.test(e)) break;
1871
+ p = t[0], e = e.substring(p.length);
1872
+ let d = t[2].split(`
1873
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, Z => " ".repeat(3 * Z.length)),
1874
+ g = e.split(`
1875
+ `, 1)[0],
1876
+ x = !d.trim(),
1877
+ f = 0;
1878
+ if (this.options.pedantic ? (f = 2, u = d.trimStart()) : x ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, u = d.slice(f), f += t[1].length), x && this.rules.other.blankLine.test(g) && (p += g + `
1879
+ `, e = e.substring(g.length + 1), c = true), !c) {
1880
+ let Z = this.rules.other.nextBulletRegex(f),
1881
+ ee = this.rules.other.hrRegex(f),
1882
+ te = this.rules.other.fencesBeginRegex(f),
1883
+ ne = this.rules.other.headingBeginRegex(f),
1884
+ me = this.rules.other.htmlBeginRegex(f);
1885
+ for (; e;) {
1886
+ let G = e.split(`
1887
+ `, 1)[0],
1888
+ E;
1889
+ if (g = G, this.options.pedantic ? (g = g.replace(this.rules.other.listReplaceNesting, " "), E = g) : E = g.replace(this.rules.other.tabCharGlobal, " "), te.test(g) || ne.test(g) || me.test(g) || Z.test(g) || ee.test(g)) break;
1890
+ if (E.search(this.rules.other.nonSpaceChar) >= f || !g.trim()) u += `
1891
+ ` + E.slice(f);else {
1892
+ if (x || d.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || te.test(d) || ne.test(d) || ee.test(d)) break;
1893
+ u += `
1894
+ ` + g;
2125
1895
  }
2126
- raw += rawLine + '\n';
2127
- src = src.substring(rawLine.length + 1);
2128
- line = nextLineWithoutTabs.slice(indent);
1896
+ !x && !g.trim() && (x = true), p += G + `
1897
+ `, e = e.substring(G.length + 1), d = E.slice(f);
2129
1898
  }
2130
1899
  }
2131
- if (!list.loose) {
2132
- // If the previous item ended with a blank line, the list is loose
2133
- if (endsWithBlankLine) {
2134
- list.loose = true;
2135
- } else if (this.rules.other.doubleBlankLine.test(raw)) {
2136
- endsWithBlankLine = true;
2137
- }
2138
- }
2139
- let istask = null;
2140
- let ischecked;
2141
- // Check for task list items
2142
- if (this.options.gfm) {
2143
- istask = this.rules.other.listIsTask.exec(itemContents);
2144
- if (istask) {
2145
- ischecked = istask[0] !== '[ ] ';
2146
- itemContents = itemContents.replace(this.rules.other.listReplaceTask, '');
2147
- }
2148
- }
2149
- list.items.push({
2150
- type: 'list_item',
2151
- raw,
2152
- task: !!istask,
2153
- checked: ischecked,
1900
+ i.loose || (o ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (o = true));
1901
+ let y = null,
1902
+ Y;
1903
+ this.options.gfm && (y = this.rules.other.listIsTask.exec(u), y && (Y = y[0] !== "[ ] ", u = u.replace(this.rules.other.listReplaceTask, ""))), i.items.push({
1904
+ type: "list_item",
1905
+ raw: p,
1906
+ task: !!y,
1907
+ checked: Y,
2154
1908
  loose: false,
2155
- text: itemContents,
1909
+ text: u,
2156
1910
  tokens: []
2157
- });
2158
- list.raw += raw;
2159
- }
2160
- // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
2161
- const lastItem = list.items.at(-1);
2162
- if (lastItem) {
2163
- lastItem.raw = lastItem.raw.trimEnd();
2164
- lastItem.text = lastItem.text.trimEnd();
2165
- } else {
2166
- // not a list since there were no items
2167
- return;
2168
- }
2169
- list.raw = list.raw.trimEnd();
2170
- // Item child tokens handled here at end because we needed to have the final item to trim it first
2171
- for (let i = 0; i < list.items.length; i++) {
2172
- this.lexer.state.top = false;
2173
- list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
2174
- if (!list.loose) {
2175
- // Check if list should be loose
2176
- const spacers = list.items[i].tokens.filter(t => t.type === 'space');
2177
- const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => this.rules.other.anyLine.test(t.raw));
2178
- list.loose = hasMultipleLineBreaks;
2179
- }
2180
- }
2181
- // Set all items to loose if list is loose
2182
- if (list.loose) {
2183
- for (let i = 0; i < list.items.length; i++) {
2184
- list.items[i].loose = true;
2185
- }
2186
- }
2187
- return list;
2188
- }
2189
- }
2190
- html(src) {
2191
- const cap = this.rules.block.html.exec(src);
2192
- if (cap) {
2193
- const token = {
2194
- type: 'html',
2195
- block: true,
2196
- raw: cap[0],
2197
- pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
2198
- text: cap[0]
2199
- };
2200
- return token;
2201
- }
1911
+ }), i.raw += p;
1912
+ }
1913
+ let l = i.items.at(-1);
1914
+ if (l) l.raw = l.raw.trimEnd(), l.text = l.text.trimEnd();else return;
1915
+ i.raw = i.raw.trimEnd();
1916
+ for (let c = 0; c < i.items.length; c++) if (this.lexer.state.top = false, i.items[c].tokens = this.lexer.blockTokens(i.items[c].text, []), !i.loose) {
1917
+ let p = i.items[c].tokens.filter(d => d.type === "space"),
1918
+ u = p.length > 0 && p.some(d => this.rules.other.anyLine.test(d.raw));
1919
+ i.loose = u;
1920
+ }
1921
+ if (i.loose) for (let c = 0; c < i.items.length; c++) i.items[c].loose = true;
1922
+ return i;
1923
+ }
1924
+ }
1925
+ html(e) {
1926
+ let t = this.rules.block.html.exec(e);
1927
+ if (t) return {
1928
+ type: "html",
1929
+ block: true,
1930
+ raw: t[0],
1931
+ pre: t[1] === "pre" || t[1] === "script" || t[1] === "style",
1932
+ text: t[0]
1933
+ };
2202
1934
  }
2203
- def(src) {
2204
- const cap = this.rules.block.def.exec(src);
2205
- if (cap) {
2206
- const tag = cap[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, ' ');
2207
- const href = cap[2] ? cap[2].replace(this.rules.other.hrefBrackets, '$1').replace(this.rules.inline.anyPunctuation, '$1') : '';
2208
- const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, '$1') : cap[3];
1935
+ def(e) {
1936
+ let t = this.rules.block.def.exec(e);
1937
+ if (t) {
1938
+ let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "),
1939
+ s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "",
1940
+ i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
2209
1941
  return {
2210
- type: 'def',
2211
- tag,
2212
- raw: cap[0],
2213
- href,
2214
- title
1942
+ type: "def",
1943
+ tag: n,
1944
+ raw: t[0],
1945
+ href: s,
1946
+ title: i
2215
1947
  };
2216
1948
  }
2217
1949
  }
2218
- table(src) {
2219
- const cap = this.rules.block.table.exec(src);
2220
- if (!cap) {
2221
- return;
2222
- }
2223
- if (!this.rules.other.tableDelimiter.test(cap[2])) {
2224
- // delimiter row must have a pipe (|) or colon (:) otherwise it is a setext heading
2225
- return;
2226
- }
2227
- const headers = splitCells(cap[1]);
2228
- const aligns = cap[2].replace(this.rules.other.tableAlignChars, '').split('|');
2229
- const rows = cap[3]?.trim() ? cap[3].replace(this.rules.other.tableRowBlankLine, '').split('\n') : [];
2230
- const item = {
2231
- type: 'table',
2232
- raw: cap[0],
2233
- header: [],
2234
- align: [],
2235
- rows: []
2236
- };
2237
- if (headers.length !== aligns.length) {
2238
- // header and align columns must be equal, rows can be different.
2239
- return;
2240
- }
2241
- for (const align of aligns) {
2242
- if (this.rules.other.tableAlignRight.test(align)) {
2243
- item.align.push('right');
2244
- } else if (this.rules.other.tableAlignCenter.test(align)) {
2245
- item.align.push('center');
2246
- } else if (this.rules.other.tableAlignLeft.test(align)) {
2247
- item.align.push('left');
2248
- } else {
2249
- item.align.push(null);
2250
- }
2251
- }
2252
- for (let i = 0; i < headers.length; i++) {
2253
- item.header.push({
2254
- text: headers[i],
2255
- tokens: this.lexer.inline(headers[i]),
1950
+ table(e) {
1951
+ let t = this.rules.block.table.exec(e);
1952
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
1953
+ let n = V(t[1]),
1954
+ s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"),
1955
+ i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
1956
+ `) : [],
1957
+ r = {
1958
+ type: "table",
1959
+ raw: t[0],
1960
+ header: [],
1961
+ align: [],
1962
+ rows: []
1963
+ };
1964
+ if (n.length === s.length) {
1965
+ for (let o of s) this.rules.other.tableAlignRight.test(o) ? r.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? r.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? r.align.push("left") : r.align.push(null);
1966
+ for (let o = 0; o < n.length; o++) r.header.push({
1967
+ text: n[o],
1968
+ tokens: this.lexer.inline(n[o]),
2256
1969
  header: true,
2257
- align: item.align[i]
1970
+ align: r.align[o]
2258
1971
  });
2259
- }
2260
- for (const row of rows) {
2261
- item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
2262
- return {
2263
- text: cell,
2264
- tokens: this.lexer.inline(cell),
2265
- header: false,
2266
- align: item.align[i]
2267
- };
2268
- }));
2269
- }
2270
- return item;
2271
- }
2272
- lheading(src) {
2273
- const cap = this.rules.block.lheading.exec(src);
2274
- if (cap) {
2275
- return {
2276
- type: 'heading',
2277
- raw: cap[0],
2278
- depth: cap[2].charAt(0) === '=' ? 1 : 2,
2279
- text: cap[1],
2280
- tokens: this.lexer.inline(cap[1])
2281
- };
2282
- }
1972
+ for (let o of i) r.rows.push(V(o, r.header.length).map((l, c) => ({
1973
+ text: l,
1974
+ tokens: this.lexer.inline(l),
1975
+ header: false,
1976
+ align: r.align[c]
1977
+ })));
1978
+ return r;
1979
+ }
1980
+ }
1981
+ lheading(e) {
1982
+ let t = this.rules.block.lheading.exec(e);
1983
+ if (t) return {
1984
+ type: "heading",
1985
+ raw: t[0],
1986
+ depth: t[2].charAt(0) === "=" ? 1 : 2,
1987
+ text: t[1],
1988
+ tokens: this.lexer.inline(t[1])
1989
+ };
2283
1990
  }
2284
- paragraph(src) {
2285
- const cap = this.rules.block.paragraph.exec(src);
2286
- if (cap) {
2287
- const text = cap[1].charAt(cap[1].length - 1) === '\n' ? cap[1].slice(0, -1) : cap[1];
1991
+ paragraph(e) {
1992
+ let t = this.rules.block.paragraph.exec(e);
1993
+ if (t) {
1994
+ let n = t[1].charAt(t[1].length - 1) === `
1995
+ ` ? t[1].slice(0, -1) : t[1];
2288
1996
  return {
2289
- type: 'paragraph',
2290
- raw: cap[0],
2291
- text,
2292
- tokens: this.lexer.inline(text)
1997
+ type: "paragraph",
1998
+ raw: t[0],
1999
+ text: n,
2000
+ tokens: this.lexer.inline(n)
2293
2001
  };
2294
2002
  }
2295
2003
  }
2296
- text(src) {
2297
- const cap = this.rules.block.text.exec(src);
2298
- if (cap) {
2299
- return {
2300
- type: 'text',
2301
- raw: cap[0],
2302
- text: cap[0],
2303
- tokens: this.lexer.inline(cap[0])
2304
- };
2305
- }
2004
+ text(e) {
2005
+ let t = this.rules.block.text.exec(e);
2006
+ if (t) return {
2007
+ type: "text",
2008
+ raw: t[0],
2009
+ text: t[0],
2010
+ tokens: this.lexer.inline(t[0])
2011
+ };
2306
2012
  }
2307
- escape(src) {
2308
- const cap = this.rules.inline.escape.exec(src);
2309
- if (cap) {
2310
- return {
2311
- type: 'escape',
2312
- raw: cap[0],
2313
- text: cap[1]
2314
- };
2315
- }
2013
+ escape(e) {
2014
+ let t = this.rules.inline.escape.exec(e);
2015
+ if (t) return {
2016
+ type: "escape",
2017
+ raw: t[0],
2018
+ text: t[1]
2019
+ };
2316
2020
  }
2317
- tag(src) {
2318
- const cap = this.rules.inline.tag.exec(src);
2319
- if (cap) {
2320
- if (!this.lexer.state.inLink && this.rules.other.startATag.test(cap[0])) {
2321
- this.lexer.state.inLink = true;
2322
- } else if (this.lexer.state.inLink && this.rules.other.endATag.test(cap[0])) {
2323
- this.lexer.state.inLink = false;
2324
- }
2325
- if (!this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(cap[0])) {
2326
- this.lexer.state.inRawBlock = true;
2327
- } else if (this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(cap[0])) {
2328
- this.lexer.state.inRawBlock = false;
2329
- }
2330
- return {
2331
- type: 'html',
2332
- raw: cap[0],
2333
- inLink: this.lexer.state.inLink,
2334
- inRawBlock: this.lexer.state.inRawBlock,
2335
- block: false,
2336
- text: cap[0]
2337
- };
2338
- }
2021
+ tag(e) {
2022
+ let t = this.rules.inline.tag.exec(e);
2023
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), {
2024
+ type: "html",
2025
+ raw: t[0],
2026
+ inLink: this.lexer.state.inLink,
2027
+ inRawBlock: this.lexer.state.inRawBlock,
2028
+ block: false,
2029
+ text: t[0]
2030
+ };
2339
2031
  }
2340
- link(src) {
2341
- const cap = this.rules.inline.link.exec(src);
2342
- if (cap) {
2343
- const trimmedUrl = cap[2].trim();
2344
- if (!this.options.pedantic && this.rules.other.startAngleBracket.test(trimmedUrl)) {
2345
- // commonmark requires matching angle brackets
2346
- if (!this.rules.other.endAngleBracket.test(trimmedUrl)) {
2347
- return;
2348
- }
2349
- // ending angle bracket cannot be escaped
2350
- const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
2351
- if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
2352
- return;
2353
- }
2032
+ link(e) {
2033
+ let t = this.rules.inline.link.exec(e);
2034
+ if (t) {
2035
+ let n = t[2].trim();
2036
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
2037
+ if (!this.rules.other.endAngleBracket.test(n)) return;
2038
+ let r = A(n.slice(0, -1), "\\");
2039
+ if ((n.length - r.length) % 2 === 0) return;
2354
2040
  } else {
2355
- // find closing parenthesis
2356
- const lastParenIndex = findClosingBracket(cap[2], '()');
2357
- if (lastParenIndex === -2) {
2358
- // more open parens than closed
2359
- return;
2360
- }
2361
- if (lastParenIndex > -1) {
2362
- const start = cap[0].indexOf('!') === 0 ? 5 : 4;
2363
- const linkLen = start + cap[1].length + lastParenIndex;
2364
- cap[2] = cap[2].substring(0, lastParenIndex);
2365
- cap[0] = cap[0].substring(0, linkLen).trim();
2366
- cap[3] = '';
2041
+ let r = fe(t[2], "()");
2042
+ if (r === -2) return;
2043
+ if (r > -1) {
2044
+ let l = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + r;
2045
+ t[2] = t[2].substring(0, r), t[0] = t[0].substring(0, l).trim(), t[3] = "";
2367
2046
  }
2368
2047
  }
2369
- let href = cap[2];
2370
- let title = '';
2048
+ let s = t[2],
2049
+ i = "";
2371
2050
  if (this.options.pedantic) {
2372
- // split pedantic href and title
2373
- const link = this.rules.other.pedanticHrefTitle.exec(href);
2374
- if (link) {
2375
- href = link[1];
2376
- title = link[3];
2377
- }
2378
- } else {
2379
- title = cap[3] ? cap[3].slice(1, -1) : '';
2380
- }
2381
- href = href.trim();
2382
- if (this.rules.other.startAngleBracket.test(href)) {
2383
- if (this.options.pedantic && !this.rules.other.endAngleBracket.test(trimmedUrl)) {
2384
- // pedantic allows starting angle bracket without ending angle bracket
2385
- href = href.slice(1);
2386
- } else {
2387
- href = href.slice(1, -1);
2388
- }
2389
- }
2390
- return outputLink(cap, {
2391
- href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
2392
- title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title
2393
- }, cap[0], this.lexer, this.rules);
2394
- }
2395
- }
2396
- reflink(src, links) {
2397
- let cap;
2398
- if ((cap = this.rules.inline.reflink.exec(src)) || (cap = this.rules.inline.nolink.exec(src))) {
2399
- const linkString = (cap[2] || cap[1]).replace(this.rules.other.multipleSpaceGlobal, ' ');
2400
- const link = links[linkString.toLowerCase()];
2401
- if (!link) {
2402
- const text = cap[0].charAt(0);
2051
+ let r = this.rules.other.pedanticHrefTitle.exec(s);
2052
+ r && (s = r[1], i = r[3]);
2053
+ } else i = t[3] ? t[3].slice(1, -1) : "";
2054
+ return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), de(t, {
2055
+ href: s && s.replace(this.rules.inline.anyPunctuation, "$1"),
2056
+ title: i && i.replace(this.rules.inline.anyPunctuation, "$1")
2057
+ }, t[0], this.lexer, this.rules);
2058
+ }
2059
+ }
2060
+ reflink(e, t) {
2061
+ let n;
2062
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
2063
+ let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "),
2064
+ i = t[s.toLowerCase()];
2065
+ if (!i) {
2066
+ let r = n[0].charAt(0);
2403
2067
  return {
2404
- type: 'text',
2405
- raw: text,
2406
- text
2068
+ type: "text",
2069
+ raw: r,
2070
+ text: r
2407
2071
  };
2408
2072
  }
2409
- return outputLink(cap, link, cap[0], this.lexer, this.rules);
2410
- }
2411
- }
2412
- emStrong(src, maskedSrc, prevChar = '') {
2413
- let match = this.rules.inline.emStrongLDelim.exec(src);
2414
- if (!match) return;
2415
- // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
2416
- if (match[3] && prevChar.match(this.rules.other.unicodeAlphaNumeric)) return;
2417
- const nextChar = match[1] || match[2] || '';
2418
- if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
2419
- // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
2420
- const lLength = [...match[0]].length - 1;
2421
- let rDelim,
2422
- rLength,
2423
- delimTotal = lLength,
2424
- midDelimTotal = 0;
2425
- const endReg = match[0][0] === '*' ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
2426
- endReg.lastIndex = 0;
2427
- // Clip maskedSrc to same section of string as src (move to lexer?)
2428
- maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
2429
- while ((match = endReg.exec(maskedSrc)) != null) {
2430
- rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
2431
- if (!rDelim) continue; // skip single * in __abc*abc__
2432
- rLength = [...rDelim].length;
2433
- if (match[3] || match[4]) {
2434
- // found another Left Delim
2435
- delimTotal += rLength;
2073
+ return de(n, i, n[0], this.lexer, this.rules);
2074
+ }
2075
+ }
2076
+ emStrong(e, t, n = "") {
2077
+ let s = this.rules.inline.emStrongLDelim.exec(e);
2078
+ if (!s || s[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
2079
+ if (!(s[1] || s[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
2080
+ let r = [...s[0]].length - 1,
2081
+ o,
2082
+ l,
2083
+ c = r,
2084
+ p = 0,
2085
+ u = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
2086
+ for (u.lastIndex = 0, t = t.slice(-1 * e.length + r); (s = u.exec(t)) != null;) {
2087
+ if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
2088
+ if (l = [...o].length, s[3] || s[4]) {
2089
+ c += l;
2090
+ continue;
2091
+ } else if ((s[5] || s[6]) && r % 3 && !((r + l) % 3)) {
2092
+ p += l;
2436
2093
  continue;
2437
- } else if (match[5] || match[6]) {
2438
- // either Left or Right Delim
2439
- if (lLength % 3 && !((lLength + rLength) % 3)) {
2440
- midDelimTotal += rLength;
2441
- continue; // CommonMark Emphasis Rules 9-10
2442
- }
2443
2094
  }
2444
- delimTotal -= rLength;
2445
- if (delimTotal > 0) continue; // Haven't found enough closing delimiters
2446
- // Remove extra characters. *a*** -> *a*
2447
- rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
2448
- // char length can be >1 for unicode characters;
2449
- const lastCharLength = [...match[0]][0].length;
2450
- const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
2451
- // Create `em` if smallest delimiter has odd char count. *a***
2452
- if (Math.min(lLength, rLength) % 2) {
2453
- const text = raw.slice(1, -1);
2095
+ if (c -= l, c > 0) continue;
2096
+ l = Math.min(l, l + c + p);
2097
+ let d = [...s[0]][0].length,
2098
+ g = e.slice(0, r + s.index + d + l);
2099
+ if (Math.min(r, l) % 2) {
2100
+ let f = g.slice(1, -1);
2454
2101
  return {
2455
- type: 'em',
2456
- raw,
2457
- text,
2458
- tokens: this.lexer.inlineTokens(text)
2102
+ type: "em",
2103
+ raw: g,
2104
+ text: f,
2105
+ tokens: this.lexer.inlineTokens(f)
2459
2106
  };
2460
2107
  }
2461
- // Create 'strong' if smallest delimiter has even char count. **a***
2462
- const text = raw.slice(2, -2);
2108
+ let x = g.slice(2, -2);
2463
2109
  return {
2464
- type: 'strong',
2465
- raw,
2466
- text,
2467
- tokens: this.lexer.inlineTokens(text)
2110
+ type: "strong",
2111
+ raw: g,
2112
+ text: x,
2113
+ tokens: this.lexer.inlineTokens(x)
2468
2114
  };
2469
2115
  }
2470
2116
  }
2471
2117
  }
2472
- codespan(src) {
2473
- const cap = this.rules.inline.code.exec(src);
2474
- if (cap) {
2475
- let text = cap[2].replace(this.rules.other.newLineCharGlobal, ' ');
2476
- const hasNonSpaceChars = this.rules.other.nonSpaceChar.test(text);
2477
- const hasSpaceCharsOnBothEnds = this.rules.other.startingSpaceChar.test(text) && this.rules.other.endingSpaceChar.test(text);
2478
- if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
2479
- text = text.substring(1, text.length - 1);
2480
- }
2481
- return {
2482
- type: 'codespan',
2483
- raw: cap[0],
2484
- text
2118
+ codespan(e) {
2119
+ let t = this.rules.inline.code.exec(e);
2120
+ if (t) {
2121
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " "),
2122
+ s = this.rules.other.nonSpaceChar.test(n),
2123
+ i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
2124
+ return s && i && (n = n.substring(1, n.length - 1)), {
2125
+ type: "codespan",
2126
+ raw: t[0],
2127
+ text: n
2485
2128
  };
2486
2129
  }
2487
2130
  }
2488
- br(src) {
2489
- const cap = this.rules.inline.br.exec(src);
2490
- if (cap) {
2491
- return {
2492
- type: 'br',
2493
- raw: cap[0]
2494
- };
2495
- }
2131
+ br(e) {
2132
+ let t = this.rules.inline.br.exec(e);
2133
+ if (t) return {
2134
+ type: "br",
2135
+ raw: t[0]
2136
+ };
2496
2137
  }
2497
- del(src) {
2498
- const cap = this.rules.inline.del.exec(src);
2499
- if (cap) {
2500
- return {
2501
- type: 'del',
2502
- raw: cap[0],
2503
- text: cap[2],
2504
- tokens: this.lexer.inlineTokens(cap[2])
2505
- };
2506
- }
2138
+ del(e) {
2139
+ let t = this.rules.inline.del.exec(e);
2140
+ if (t) return {
2141
+ type: "del",
2142
+ raw: t[0],
2143
+ text: t[2],
2144
+ tokens: this.lexer.inlineTokens(t[2])
2145
+ };
2507
2146
  }
2508
- autolink(src) {
2509
- const cap = this.rules.inline.autolink.exec(src);
2510
- if (cap) {
2511
- let text, href;
2512
- if (cap[2] === '@') {
2513
- text = cap[1];
2514
- href = 'mailto:' + text;
2515
- } else {
2516
- text = cap[1];
2517
- href = text;
2518
- }
2519
- return {
2520
- type: 'link',
2521
- raw: cap[0],
2522
- text,
2523
- href,
2147
+ autolink(e) {
2148
+ let t = this.rules.inline.autolink.exec(e);
2149
+ if (t) {
2150
+ let n, s;
2151
+ return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), {
2152
+ type: "link",
2153
+ raw: t[0],
2154
+ text: n,
2155
+ href: s,
2524
2156
  tokens: [{
2525
- type: 'text',
2526
- raw: text,
2527
- text
2157
+ type: "text",
2158
+ raw: n,
2159
+ text: n
2528
2160
  }]
2529
2161
  };
2530
2162
  }
2531
2163
  }
2532
- url(src) {
2533
- let cap;
2534
- if (cap = this.rules.inline.url.exec(src)) {
2535
- let text, href;
2536
- if (cap[2] === '@') {
2537
- text = cap[0];
2538
- href = 'mailto:' + text;
2539
- } else {
2540
- // do extended autolink path validation
2541
- let prevCapZero;
2542
- do {
2543
- prevCapZero = cap[0];
2544
- cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? '';
2545
- } while (prevCapZero !== cap[0]);
2546
- text = cap[0];
2547
- if (cap[1] === 'www.') {
2548
- href = 'http://' + cap[0];
2549
- } else {
2550
- href = cap[0];
2551
- }
2164
+ url(e) {
2165
+ let t;
2166
+ if (t = this.rules.inline.url.exec(e)) {
2167
+ let n, s;
2168
+ if (t[2] === "@") n = t[0], s = "mailto:" + n;else {
2169
+ let i;
2170
+ do i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? ""; while (i !== t[0]);
2171
+ n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
2552
2172
  }
2553
2173
  return {
2554
- type: 'link',
2555
- raw: cap[0],
2556
- text,
2557
- href,
2174
+ type: "link",
2175
+ raw: t[0],
2176
+ text: n,
2177
+ href: s,
2558
2178
  tokens: [{
2559
- type: 'text',
2560
- raw: text,
2561
- text
2179
+ type: "text",
2180
+ raw: n,
2181
+ text: n
2562
2182
  }]
2563
2183
  };
2564
2184
  }
2565
2185
  }
2566
- inlineText(src) {
2567
- const cap = this.rules.inline.text.exec(src);
2568
- if (cap) {
2569
- const escaped = this.lexer.state.inRawBlock;
2186
+ inlineText(e) {
2187
+ let t = this.rules.inline.text.exec(e);
2188
+ if (t) {
2189
+ let n = this.lexer.state.inRawBlock;
2570
2190
  return {
2571
- type: 'text',
2572
- raw: cap[0],
2573
- text: cap[0],
2574
- escaped
2191
+ type: "text",
2192
+ raw: t[0],
2193
+ text: t[0],
2194
+ escaped: n
2575
2195
  };
2576
2196
  }
2577
2197
  }
2578
- }
2579
-
2580
- /**
2581
- * Block Lexer
2582
- */
2583
- class _Lexer {
2198
+ };
2199
+ var b = class a {
2584
2200
  tokens;
2585
2201
  options;
2586
2202
  state;
2587
2203
  tokenizer;
2588
2204
  inlineQueue;
2589
- constructor(options) {
2590
- // TokenList cannot be created in one go
2591
- this.tokens = [];
2592
- this.tokens.links = Object.create(null);
2593
- this.options = options || _defaults;
2594
- this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
2595
- this.tokenizer = this.options.tokenizer;
2596
- this.tokenizer.options = this.options;
2597
- this.tokenizer.lexer = this;
2598
- this.inlineQueue = [];
2599
- this.state = {
2205
+ constructor(e) {
2206
+ this.tokens = [], this.tokens.links = Object.create(null), this.options = e || w, this.options.tokenizer = this.options.tokenizer || new S(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
2600
2207
  inLink: false,
2601
2208
  inRawBlock: false,
2602
2209
  top: true
2603
2210
  };
2604
- const rules = {
2605
- other,
2606
- block: block.normal,
2607
- inline: inline.normal
2211
+ let t = {
2212
+ other: m,
2213
+ block: O.normal,
2214
+ inline: P.normal
2608
2215
  };
2609
- if (this.options.pedantic) {
2610
- rules.block = block.pedantic;
2611
- rules.inline = inline.pedantic;
2612
- } else if (this.options.gfm) {
2613
- rules.block = block.gfm;
2614
- if (this.options.breaks) {
2615
- rules.inline = inline.breaks;
2616
- } else {
2617
- rules.inline = inline.gfm;
2618
- }
2619
- }
2620
- this.tokenizer.rules = rules;
2216
+ this.options.pedantic ? (t.block = O.pedantic, t.inline = P.pedantic) : this.options.gfm && (t.block = O.gfm, this.options.breaks ? t.inline = P.breaks : t.inline = P.gfm), this.tokenizer.rules = t;
2621
2217
  }
2622
- /**
2623
- * Expose Rules
2624
- */
2625
2218
  static get rules() {
2626
2219
  return {
2627
- block,
2628
- inline
2220
+ block: O,
2221
+ inline: P
2629
2222
  };
2630
2223
  }
2631
- /**
2632
- * Static Lex Method
2633
- */
2634
- static lex(src, options) {
2635
- const lexer = new _Lexer(options);
2636
- return lexer.lex(src);
2637
- }
2638
- /**
2639
- * Static Lex Inline Method
2640
- */
2641
- static lexInline(src, options) {
2642
- const lexer = new _Lexer(options);
2643
- return lexer.inlineTokens(src);
2644
- }
2645
- /**
2646
- * Preprocessing
2647
- */
2648
- lex(src) {
2649
- src = src.replace(other.carriageReturn, '\n');
2650
- this.blockTokens(src, this.tokens);
2651
- for (let i = 0; i < this.inlineQueue.length; i++) {
2652
- const next = this.inlineQueue[i];
2653
- this.inlineTokens(next.src, next.tokens);
2654
- }
2655
- this.inlineQueue = [];
2656
- return this.tokens;
2657
- }
2658
- blockTokens(src, tokens = [], lastParagraphClipped = false) {
2659
- if (this.options.pedantic) {
2660
- src = src.replace(other.tabCharGlobal, ' ').replace(other.spaceLine, '');
2661
- }
2662
- while (src) {
2663
- let token;
2664
- if (this.options.extensions?.block?.some(extTokenizer => {
2665
- if (token = extTokenizer.call({
2666
- lexer: this
2667
- }, src, tokens)) {
2668
- src = src.substring(token.raw.length);
2669
- tokens.push(token);
2670
- return true;
2671
- }
2672
- return false;
2673
- })) {
2674
- continue;
2675
- }
2676
- // newline
2677
- if (token = this.tokenizer.space(src)) {
2678
- src = src.substring(token.raw.length);
2679
- const lastToken = tokens.at(-1);
2680
- if (token.raw.length === 1 && lastToken !== undefined) {
2681
- // if there's a single \n as a spacer, it's terminating the last line,
2682
- // so move it there so that we don't get unnecessary paragraph tags
2683
- lastToken.raw += '\n';
2684
- } else {
2685
- tokens.push(token);
2686
- }
2224
+ static lex(e, t) {
2225
+ return new a(t).lex(e);
2226
+ }
2227
+ static lexInline(e, t) {
2228
+ return new a(t).inlineTokens(e);
2229
+ }
2230
+ lex(e) {
2231
+ e = e.replace(m.carriageReturn, `
2232
+ `), this.blockTokens(e, this.tokens);
2233
+ for (let t = 0; t < this.inlineQueue.length; t++) {
2234
+ let n = this.inlineQueue[t];
2235
+ this.inlineTokens(n.src, n.tokens);
2236
+ }
2237
+ return this.inlineQueue = [], this.tokens;
2238
+ }
2239
+ blockTokens(e, t = [], n = false) {
2240
+ for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e;) {
2241
+ let s;
2242
+ if (this.options.extensions?.block?.some(r => (s = r.call({
2243
+ lexer: this
2244
+ }, e, t)) ? (e = e.substring(s.raw.length), t.push(s), true) : false)) continue;
2245
+ if (s = this.tokenizer.space(e)) {
2246
+ e = e.substring(s.raw.length);
2247
+ let r = t.at(-1);
2248
+ s.raw.length === 1 && r !== void 0 ? r.raw += `
2249
+ ` : t.push(s);
2687
2250
  continue;
2688
2251
  }
2689
- // code
2690
- if (token = this.tokenizer.code(src)) {
2691
- src = src.substring(token.raw.length);
2692
- const lastToken = tokens.at(-1);
2693
- // An indented code block cannot interrupt a paragraph.
2694
- if (lastToken?.type === 'paragraph' || lastToken?.type === 'text') {
2695
- lastToken.raw += '\n' + token.raw;
2696
- lastToken.text += '\n' + token.text;
2697
- this.inlineQueue.at(-1).src = lastToken.text;
2698
- } else {
2699
- tokens.push(token);
2700
- }
2252
+ if (s = this.tokenizer.code(e)) {
2253
+ e = e.substring(s.raw.length);
2254
+ let r = t.at(-1);
2255
+ r?.type === "paragraph" || r?.type === "text" ? (r.raw += `
2256
+ ` + s.raw, r.text += `
2257
+ ` + s.text, this.inlineQueue.at(-1).src = r.text) : t.push(s);
2701
2258
  continue;
2702
2259
  }
2703
- // fences
2704
- if (token = this.tokenizer.fences(src)) {
2705
- src = src.substring(token.raw.length);
2706
- tokens.push(token);
2260
+ if (s = this.tokenizer.fences(e)) {
2261
+ e = e.substring(s.raw.length), t.push(s);
2707
2262
  continue;
2708
2263
  }
2709
- // heading
2710
- if (token = this.tokenizer.heading(src)) {
2711
- src = src.substring(token.raw.length);
2712
- tokens.push(token);
2264
+ if (s = this.tokenizer.heading(e)) {
2265
+ e = e.substring(s.raw.length), t.push(s);
2713
2266
  continue;
2714
2267
  }
2715
- // hr
2716
- if (token = this.tokenizer.hr(src)) {
2717
- src = src.substring(token.raw.length);
2718
- tokens.push(token);
2268
+ if (s = this.tokenizer.hr(e)) {
2269
+ e = e.substring(s.raw.length), t.push(s);
2719
2270
  continue;
2720
2271
  }
2721
- // blockquote
2722
- if (token = this.tokenizer.blockquote(src)) {
2723
- src = src.substring(token.raw.length);
2724
- tokens.push(token);
2272
+ if (s = this.tokenizer.blockquote(e)) {
2273
+ e = e.substring(s.raw.length), t.push(s);
2725
2274
  continue;
2726
2275
  }
2727
- // list
2728
- if (token = this.tokenizer.list(src)) {
2729
- src = src.substring(token.raw.length);
2730
- tokens.push(token);
2276
+ if (s = this.tokenizer.list(e)) {
2277
+ e = e.substring(s.raw.length), t.push(s);
2731
2278
  continue;
2732
2279
  }
2733
- // html
2734
- if (token = this.tokenizer.html(src)) {
2735
- src = src.substring(token.raw.length);
2736
- tokens.push(token);
2280
+ if (s = this.tokenizer.html(e)) {
2281
+ e = e.substring(s.raw.length), t.push(s);
2737
2282
  continue;
2738
2283
  }
2739
- // def
2740
- if (token = this.tokenizer.def(src)) {
2741
- src = src.substring(token.raw.length);
2742
- const lastToken = tokens.at(-1);
2743
- if (lastToken?.type === 'paragraph' || lastToken?.type === 'text') {
2744
- lastToken.raw += '\n' + token.raw;
2745
- lastToken.text += '\n' + token.raw;
2746
- this.inlineQueue.at(-1).src = lastToken.text;
2747
- } else if (!this.tokens.links[token.tag]) {
2748
- this.tokens.links[token.tag] = {
2749
- href: token.href,
2750
- title: token.title
2751
- };
2752
- }
2284
+ if (s = this.tokenizer.def(e)) {
2285
+ e = e.substring(s.raw.length);
2286
+ let r = t.at(-1);
2287
+ r?.type === "paragraph" || r?.type === "text" ? (r.raw += `
2288
+ ` + s.raw, r.text += `
2289
+ ` + s.raw, this.inlineQueue.at(-1).src = r.text) : this.tokens.links[s.tag] || (this.tokens.links[s.tag] = {
2290
+ href: s.href,
2291
+ title: s.title
2292
+ });
2753
2293
  continue;
2754
2294
  }
2755
- // table (gfm)
2756
- if (token = this.tokenizer.table(src)) {
2757
- src = src.substring(token.raw.length);
2758
- tokens.push(token);
2295
+ if (s = this.tokenizer.table(e)) {
2296
+ e = e.substring(s.raw.length), t.push(s);
2759
2297
  continue;
2760
2298
  }
2761
- // lheading
2762
- if (token = this.tokenizer.lheading(src)) {
2763
- src = src.substring(token.raw.length);
2764
- tokens.push(token);
2299
+ if (s = this.tokenizer.lheading(e)) {
2300
+ e = e.substring(s.raw.length), t.push(s);
2765
2301
  continue;
2766
2302
  }
2767
- // top-level paragraph
2768
- // prevent paragraph consuming extensions by clipping 'src' to extension start
2769
- let cutSrc = src;
2303
+ let i = e;
2770
2304
  if (this.options.extensions?.startBlock) {
2771
- let startIndex = Infinity;
2772
- const tempSrc = src.slice(1);
2773
- let tempStart;
2774
- this.options.extensions.startBlock.forEach(getStartIndex => {
2775
- tempStart = getStartIndex.call({
2305
+ let r = 1 / 0,
2306
+ o = e.slice(1),
2307
+ l;
2308
+ this.options.extensions.startBlock.forEach(c => {
2309
+ l = c.call({
2776
2310
  lexer: this
2777
- }, tempSrc);
2778
- if (typeof tempStart === 'number' && tempStart >= 0) {
2779
- startIndex = Math.min(startIndex, tempStart);
2780
- }
2781
- });
2782
- if (startIndex < Infinity && startIndex >= 0) {
2783
- cutSrc = src.substring(0, startIndex + 1);
2784
- }
2785
- }
2786
- if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
2787
- const lastToken = tokens.at(-1);
2788
- if (lastParagraphClipped && lastToken?.type === 'paragraph') {
2789
- lastToken.raw += '\n' + token.raw;
2790
- lastToken.text += '\n' + token.text;
2791
- this.inlineQueue.pop();
2792
- this.inlineQueue.at(-1).src = lastToken.text;
2793
- } else {
2794
- tokens.push(token);
2795
- }
2796
- lastParagraphClipped = cutSrc.length !== src.length;
2797
- src = src.substring(token.raw.length);
2311
+ }, o), typeof l == "number" && l >= 0 && (r = Math.min(r, l));
2312
+ }), r < 1 / 0 && r >= 0 && (i = e.substring(0, r + 1));
2313
+ }
2314
+ if (this.state.top && (s = this.tokenizer.paragraph(i))) {
2315
+ let r = t.at(-1);
2316
+ n && r?.type === "paragraph" ? (r.raw += `
2317
+ ` + s.raw, r.text += `
2318
+ ` + s.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = r.text) : t.push(s), n = i.length !== e.length, e = e.substring(s.raw.length);
2798
2319
  continue;
2799
2320
  }
2800
- // text
2801
- if (token = this.tokenizer.text(src)) {
2802
- src = src.substring(token.raw.length);
2803
- const lastToken = tokens.at(-1);
2804
- if (lastToken?.type === 'text') {
2805
- lastToken.raw += '\n' + token.raw;
2806
- lastToken.text += '\n' + token.text;
2807
- this.inlineQueue.pop();
2808
- this.inlineQueue.at(-1).src = lastToken.text;
2809
- } else {
2810
- tokens.push(token);
2811
- }
2321
+ if (s = this.tokenizer.text(e)) {
2322
+ e = e.substring(s.raw.length);
2323
+ let r = t.at(-1);
2324
+ r?.type === "text" ? (r.raw += `
2325
+ ` + s.raw, r.text += `
2326
+ ` + s.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = r.text) : t.push(s);
2812
2327
  continue;
2813
2328
  }
2814
- if (src) {
2815
- const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
2329
+ if (e) {
2330
+ let r = "Infinite loop on byte: " + e.charCodeAt(0);
2816
2331
  if (this.options.silent) {
2817
- console.error(errMsg);
2332
+ console.error(r);
2818
2333
  break;
2819
- } else {
2820
- throw new Error(errMsg);
2821
- }
2334
+ } else throw new Error(r);
2822
2335
  }
2823
2336
  }
2824
- this.state.top = true;
2825
- return tokens;
2337
+ return this.state.top = true, t;
2826
2338
  }
2827
- inline(src, tokens = []) {
2828
- this.inlineQueue.push({
2829
- src,
2830
- tokens
2831
- });
2832
- return tokens;
2833
- }
2834
- /**
2835
- * Lexing/Compiling
2836
- */
2837
- inlineTokens(src, tokens = []) {
2838
- // String with links masked to avoid interference with em and strong
2839
- let maskedSrc = src;
2840
- let match = null;
2841
- // Mask out reflinks
2339
+ inline(e, t = []) {
2340
+ return this.inlineQueue.push({
2341
+ src: e,
2342
+ tokens: t
2343
+ }), t;
2344
+ }
2345
+ inlineTokens(e, t = []) {
2346
+ let n = e,
2347
+ s = null;
2842
2348
  if (this.tokens.links) {
2843
- const links = Object.keys(this.tokens.links);
2844
- if (links.length > 0) {
2845
- while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
2846
- if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
2847
- maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
2848
- }
2849
- }
2850
- }
2851
- }
2852
- // Mask out escaped characters
2853
- while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
2854
- maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
2855
- }
2856
- // Mask out other blocks
2857
- while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
2858
- maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
2859
- }
2860
- let keepPrevChar = false;
2861
- let prevChar = '';
2862
- while (src) {
2863
- if (!keepPrevChar) {
2864
- prevChar = '';
2865
- }
2866
- keepPrevChar = false;
2867
- let token;
2868
- // extensions
2869
- if (this.options.extensions?.inline?.some(extTokenizer => {
2870
- if (token = extTokenizer.call({
2871
- lexer: this
2872
- }, src, tokens)) {
2873
- src = src.substring(token.raw.length);
2874
- tokens.push(token);
2875
- return true;
2876
- }
2877
- return false;
2878
- })) {
2349
+ let o = Object.keys(this.tokens.links);
2350
+ if (o.length > 0) for (; (s = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null;) o.includes(s[0].slice(s[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
2351
+ }
2352
+ for (; (s = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null;) n = n.slice(0, s.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
2353
+ for (; (s = this.tokenizer.rules.inline.blockSkip.exec(n)) != null;) n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
2354
+ let i = false,
2355
+ r = "";
2356
+ for (; e;) {
2357
+ i || (r = ""), i = false;
2358
+ let o;
2359
+ if (this.options.extensions?.inline?.some(c => (o = c.call({
2360
+ lexer: this
2361
+ }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false)) continue;
2362
+ if (o = this.tokenizer.escape(e)) {
2363
+ e = e.substring(o.raw.length), t.push(o);
2879
2364
  continue;
2880
2365
  }
2881
- // escape
2882
- if (token = this.tokenizer.escape(src)) {
2883
- src = src.substring(token.raw.length);
2884
- tokens.push(token);
2366
+ if (o = this.tokenizer.tag(e)) {
2367
+ e = e.substring(o.raw.length), t.push(o);
2885
2368
  continue;
2886
2369
  }
2887
- // tag
2888
- if (token = this.tokenizer.tag(src)) {
2889
- src = src.substring(token.raw.length);
2890
- tokens.push(token);
2370
+ if (o = this.tokenizer.link(e)) {
2371
+ e = e.substring(o.raw.length), t.push(o);
2891
2372
  continue;
2892
2373
  }
2893
- // link
2894
- if (token = this.tokenizer.link(src)) {
2895
- src = src.substring(token.raw.length);
2896
- tokens.push(token);
2374
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
2375
+ e = e.substring(o.raw.length);
2376
+ let c = t.at(-1);
2377
+ o.type === "text" && c?.type === "text" ? (c.raw += o.raw, c.text += o.text) : t.push(o);
2897
2378
  continue;
2898
2379
  }
2899
- // reflink, nolink
2900
- if (token = this.tokenizer.reflink(src, this.tokens.links)) {
2901
- src = src.substring(token.raw.length);
2902
- const lastToken = tokens.at(-1);
2903
- if (token.type === 'text' && lastToken?.type === 'text') {
2904
- lastToken.raw += token.raw;
2905
- lastToken.text += token.text;
2906
- } else {
2907
- tokens.push(token);
2908
- }
2909
- continue;
2910
- }
2911
- // em & strong
2912
- if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
2913
- src = src.substring(token.raw.length);
2914
- tokens.push(token);
2380
+ if (o = this.tokenizer.emStrong(e, n, r)) {
2381
+ e = e.substring(o.raw.length), t.push(o);
2915
2382
  continue;
2916
2383
  }
2917
- // code
2918
- if (token = this.tokenizer.codespan(src)) {
2919
- src = src.substring(token.raw.length);
2920
- tokens.push(token);
2384
+ if (o = this.tokenizer.codespan(e)) {
2385
+ e = e.substring(o.raw.length), t.push(o);
2921
2386
  continue;
2922
2387
  }
2923
- // br
2924
- if (token = this.tokenizer.br(src)) {
2925
- src = src.substring(token.raw.length);
2926
- tokens.push(token);
2388
+ if (o = this.tokenizer.br(e)) {
2389
+ e = e.substring(o.raw.length), t.push(o);
2927
2390
  continue;
2928
2391
  }
2929
- // del (gfm)
2930
- if (token = this.tokenizer.del(src)) {
2931
- src = src.substring(token.raw.length);
2932
- tokens.push(token);
2392
+ if (o = this.tokenizer.del(e)) {
2393
+ e = e.substring(o.raw.length), t.push(o);
2933
2394
  continue;
2934
2395
  }
2935
- // autolink
2936
- if (token = this.tokenizer.autolink(src)) {
2937
- src = src.substring(token.raw.length);
2938
- tokens.push(token);
2396
+ if (o = this.tokenizer.autolink(e)) {
2397
+ e = e.substring(o.raw.length), t.push(o);
2939
2398
  continue;
2940
2399
  }
2941
- // url (gfm)
2942
- if (!this.state.inLink && (token = this.tokenizer.url(src))) {
2943
- src = src.substring(token.raw.length);
2944
- tokens.push(token);
2400
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
2401
+ e = e.substring(o.raw.length), t.push(o);
2945
2402
  continue;
2946
2403
  }
2947
- // text
2948
- // prevent inlineText consuming extensions by clipping 'src' to extension start
2949
- let cutSrc = src;
2404
+ let l = e;
2950
2405
  if (this.options.extensions?.startInline) {
2951
- let startIndex = Infinity;
2952
- const tempSrc = src.slice(1);
2953
- let tempStart;
2954
- this.options.extensions.startInline.forEach(getStartIndex => {
2955
- tempStart = getStartIndex.call({
2406
+ let c = 1 / 0,
2407
+ p = e.slice(1),
2408
+ u;
2409
+ this.options.extensions.startInline.forEach(d => {
2410
+ u = d.call({
2956
2411
  lexer: this
2957
- }, tempSrc);
2958
- if (typeof tempStart === 'number' && tempStart >= 0) {
2959
- startIndex = Math.min(startIndex, tempStart);
2960
- }
2961
- });
2962
- if (startIndex < Infinity && startIndex >= 0) {
2963
- cutSrc = src.substring(0, startIndex + 1);
2964
- }
2412
+ }, p), typeof u == "number" && u >= 0 && (c = Math.min(c, u));
2413
+ }), c < 1 / 0 && c >= 0 && (l = e.substring(0, c + 1));
2965
2414
  }
2966
- if (token = this.tokenizer.inlineText(cutSrc)) {
2967
- src = src.substring(token.raw.length);
2968
- if (token.raw.slice(-1) !== '_') {
2969
- // Track prevChar before string of ____ started
2970
- prevChar = token.raw.slice(-1);
2971
- }
2972
- keepPrevChar = true;
2973
- const lastToken = tokens.at(-1);
2974
- if (lastToken?.type === 'text') {
2975
- lastToken.raw += token.raw;
2976
- lastToken.text += token.text;
2977
- } else {
2978
- tokens.push(token);
2979
- }
2415
+ if (o = this.tokenizer.inlineText(l)) {
2416
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (r = o.raw.slice(-1)), i = true;
2417
+ let c = t.at(-1);
2418
+ c?.type === "text" ? (c.raw += o.raw, c.text += o.text) : t.push(o);
2980
2419
  continue;
2981
2420
  }
2982
- if (src) {
2983
- const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
2421
+ if (e) {
2422
+ let c = "Infinite loop on byte: " + e.charCodeAt(0);
2984
2423
  if (this.options.silent) {
2985
- console.error(errMsg);
2424
+ console.error(c);
2986
2425
  break;
2987
- } else {
2988
- throw new Error(errMsg);
2989
- }
2426
+ } else throw new Error(c);
2990
2427
  }
2991
2428
  }
2992
- return tokens;
2429
+ return t;
2993
2430
  }
2994
- }
2995
-
2996
- /**
2997
- * Renderer
2998
- */
2999
- class _Renderer {
2431
+ };
2432
+ var $ = class {
3000
2433
  options;
3001
- parser; // set by the parser
3002
- constructor(options) {
3003
- this.options = options || _defaults;
2434
+ parser;
2435
+ constructor(e) {
2436
+ this.options = e || w;
3004
2437
  }
3005
- space(token) {
3006
- return '';
2438
+ space(e) {
2439
+ return "";
3007
2440
  }
3008
2441
  code({
3009
- text,
3010
- lang,
3011
- escaped
2442
+ text: e,
2443
+ lang: t,
2444
+ escaped: n
3012
2445
  }) {
3013
- const langString = (lang || '').match(other.notSpaceStart)?.[0];
3014
- const code = text.replace(other.endingNewline, '') + '\n';
3015
- if (!langString) {
3016
- return '<pre><code>' + (escaped ? code : escape(code, true)) + '</code></pre>\n';
3017
- }
3018
- return '<pre><code class="language-' + escape(langString) + '">' + (escaped ? code : escape(code, true)) + '</code></pre>\n';
2446
+ let s = (t || "").match(m.notSpaceStart)?.[0],
2447
+ i = e.replace(m.endingNewline, "") + `
2448
+ `;
2449
+ return s ? '<pre><code class="language-' + R(s) + '">' + (n ? i : R(i, true)) + `</code></pre>
2450
+ ` : "<pre><code>" + (n ? i : R(i, true)) + `</code></pre>
2451
+ `;
3019
2452
  }
3020
2453
  blockquote({
3021
- tokens
2454
+ tokens: e
3022
2455
  }) {
3023
- const body = this.parser.parse(tokens);
3024
- return `<blockquote>\n${body}</blockquote>\n`;
2456
+ return `<blockquote>
2457
+ ${this.parser.parse(e)}</blockquote>
2458
+ `;
3025
2459
  }
3026
2460
  html({
3027
- text
2461
+ text: e
3028
2462
  }) {
3029
- return text;
2463
+ return e;
3030
2464
  }
3031
2465
  heading({
3032
- tokens,
3033
- depth
2466
+ tokens: e,
2467
+ depth: t
3034
2468
  }) {
3035
- return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>\n`;
3036
- }
3037
- hr(token) {
3038
- return '<hr>\n';
3039
- }
3040
- list(token) {
3041
- const ordered = token.ordered;
3042
- const start = token.start;
3043
- let body = '';
3044
- for (let j = 0; j < token.items.length; j++) {
3045
- const item = token.items[j];
3046
- body += this.listitem(item);
3047
- }
3048
- const type = ordered ? 'ol' : 'ul';
3049
- const startAttr = ordered && start !== 1 ? ' start="' + start + '"' : '';
3050
- return '<' + type + startAttr + '>\n' + body + '</' + type + '>\n';
3051
- }
3052
- listitem(item) {
3053
- let itemBody = '';
3054
- if (item.task) {
3055
- const checkbox = this.checkbox({
3056
- checked: !!item.checked
2469
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
2470
+ `;
2471
+ }
2472
+ hr(e) {
2473
+ return `<hr>
2474
+ `;
2475
+ }
2476
+ list(e) {
2477
+ let t = e.ordered,
2478
+ n = e.start,
2479
+ s = "";
2480
+ for (let o = 0; o < e.items.length; o++) {
2481
+ let l = e.items[o];
2482
+ s += this.listitem(l);
2483
+ }
2484
+ let i = t ? "ol" : "ul",
2485
+ r = t && n !== 1 ? ' start="' + n + '"' : "";
2486
+ return "<" + i + r + `>
2487
+ ` + s + "</" + i + `>
2488
+ `;
2489
+ }
2490
+ listitem(e) {
2491
+ let t = "";
2492
+ if (e.task) {
2493
+ let n = this.checkbox({
2494
+ checked: !!e.checked
3057
2495
  });
3058
- if (item.loose) {
3059
- if (item.tokens[0]?.type === 'paragraph') {
3060
- item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
3061
- if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
3062
- item.tokens[0].tokens[0].text = checkbox + ' ' + escape(item.tokens[0].tokens[0].text);
3063
- item.tokens[0].tokens[0].escaped = true;
3064
- }
3065
- } else {
3066
- item.tokens.unshift({
3067
- type: 'text',
3068
- raw: checkbox + ' ',
3069
- text: checkbox + ' ',
3070
- escaped: true
3071
- });
3072
- }
3073
- } else {
3074
- itemBody += checkbox + ' ';
3075
- }
2496
+ e.loose ? e.tokens[0]?.type === "paragraph" ? (e.tokens[0].text = n + " " + e.tokens[0].text, e.tokens[0].tokens && e.tokens[0].tokens.length > 0 && e.tokens[0].tokens[0].type === "text" && (e.tokens[0].tokens[0].text = n + " " + R(e.tokens[0].tokens[0].text), e.tokens[0].tokens[0].escaped = true)) : e.tokens.unshift({
2497
+ type: "text",
2498
+ raw: n + " ",
2499
+ text: n + " ",
2500
+ escaped: true
2501
+ }) : t += n + " ";
3076
2502
  }
3077
- itemBody += this.parser.parse(item.tokens, !!item.loose);
3078
- return `<li>${itemBody}</li>\n`;
2503
+ return t += this.parser.parse(e.tokens, !!e.loose), `<li>${t}</li>
2504
+ `;
3079
2505
  }
3080
2506
  checkbox({
3081
- checked
2507
+ checked: e
3082
2508
  }) {
3083
- return '<input ' + (checked ? 'checked="" ' : '') + 'disabled="" type="checkbox">';
2509
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox">';
3084
2510
  }
3085
2511
  paragraph({
3086
- tokens
2512
+ tokens: e
3087
2513
  }) {
3088
- return `<p>${this.parser.parseInline(tokens)}</p>\n`;
3089
- }
3090
- table(token) {
3091
- let header = '';
3092
- // header
3093
- let cell = '';
3094
- for (let j = 0; j < token.header.length; j++) {
3095
- cell += this.tablecell(token.header[j]);
3096
- }
3097
- header += this.tablerow({
3098
- text: cell
2514
+ return `<p>${this.parser.parseInline(e)}</p>
2515
+ `;
2516
+ }
2517
+ table(e) {
2518
+ let t = "",
2519
+ n = "";
2520
+ for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
2521
+ t += this.tablerow({
2522
+ text: n
3099
2523
  });
3100
- let body = '';
3101
- for (let j = 0; j < token.rows.length; j++) {
3102
- const row = token.rows[j];
3103
- cell = '';
3104
- for (let k = 0; k < row.length; k++) {
3105
- cell += this.tablecell(row[k]);
3106
- }
3107
- body += this.tablerow({
3108
- text: cell
2524
+ let s = "";
2525
+ for (let i = 0; i < e.rows.length; i++) {
2526
+ let r = e.rows[i];
2527
+ n = "";
2528
+ for (let o = 0; o < r.length; o++) n += this.tablecell(r[o]);
2529
+ s += this.tablerow({
2530
+ text: n
3109
2531
  });
3110
2532
  }
3111
- if (body) body = `<tbody>${body}</tbody>`;
3112
- return '<table>\n' + '<thead>\n' + header + '</thead>\n' + body + '</table>\n';
2533
+ return s && (s = `<tbody>${s}</tbody>`), `<table>
2534
+ <thead>
2535
+ ` + t + `</thead>
2536
+ ` + s + `</table>
2537
+ `;
3113
2538
  }
3114
2539
  tablerow({
3115
- text
2540
+ text: e
3116
2541
  }) {
3117
- return `<tr>\n${text}</tr>\n`;
2542
+ return `<tr>
2543
+ ${e}</tr>
2544
+ `;
3118
2545
  }
3119
- tablecell(token) {
3120
- const content = this.parser.parseInline(token.tokens);
3121
- const type = token.header ? 'th' : 'td';
3122
- const tag = token.align ? `<${type} align="${token.align}">` : `<${type}>`;
3123
- return tag + content + `</${type}>\n`;
2546
+ tablecell(e) {
2547
+ let t = this.parser.parseInline(e.tokens),
2548
+ n = e.header ? "th" : "td";
2549
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
2550
+ `;
3124
2551
  }
3125
- /**
3126
- * span level renderer
3127
- */
3128
2552
  strong({
3129
- tokens
2553
+ tokens: e
3130
2554
  }) {
3131
- return `<strong>${this.parser.parseInline(tokens)}</strong>`;
2555
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
3132
2556
  }
3133
2557
  em({
3134
- tokens
2558
+ tokens: e
3135
2559
  }) {
3136
- return `<em>${this.parser.parseInline(tokens)}</em>`;
2560
+ return `<em>${this.parser.parseInline(e)}</em>`;
3137
2561
  }
3138
2562
  codespan({
3139
- text
2563
+ text: e
3140
2564
  }) {
3141
- return `<code>${escape(text, true)}</code>`;
2565
+ return `<code>${R(e, true)}</code>`;
3142
2566
  }
3143
- br(token) {
3144
- return '<br>';
2567
+ br(e) {
2568
+ return "<br>";
3145
2569
  }
3146
2570
  del({
3147
- tokens
2571
+ tokens: e
3148
2572
  }) {
3149
- return `<del>${this.parser.parseInline(tokens)}</del>`;
2573
+ return `<del>${this.parser.parseInline(e)}</del>`;
3150
2574
  }
3151
2575
  link({
3152
- href,
3153
- title,
3154
- tokens
2576
+ href: e,
2577
+ title: t,
2578
+ tokens: n
3155
2579
  }) {
3156
- const text = this.parser.parseInline(tokens);
3157
- const cleanHref = cleanUrl(href);
3158
- if (cleanHref === null) {
3159
- return text;
3160
- }
3161
- href = cleanHref;
3162
- let out = '<a href="' + href + '"';
3163
- if (title) {
3164
- out += ' title="' + escape(title) + '"';
3165
- }
3166
- out += '>' + text + '</a>';
3167
- return out;
2580
+ let s = this.parser.parseInline(n),
2581
+ i = J(e);
2582
+ if (i === null) return s;
2583
+ e = i;
2584
+ let r = '<a href="' + e + '"';
2585
+ return t && (r += ' title="' + R(t) + '"'), r += ">" + s + "</a>", r;
3168
2586
  }
3169
2587
  image({
3170
- href,
3171
- title,
3172
- text
2588
+ href: e,
2589
+ title: t,
2590
+ text: n,
2591
+ tokens: s
3173
2592
  }) {
3174
- const cleanHref = cleanUrl(href);
3175
- if (cleanHref === null) {
3176
- return escape(text);
3177
- }
3178
- href = cleanHref;
3179
- let out = `<img src="${href}" alt="${text}"`;
3180
- if (title) {
3181
- out += ` title="${escape(title)}"`;
3182
- }
3183
- out += '>';
3184
- return out;
2593
+ s && (n = this.parser.parseInline(s, this.parser.textRenderer));
2594
+ let i = J(e);
2595
+ if (i === null) return R(n);
2596
+ e = i;
2597
+ let r = `<img src="${e}" alt="${n}"`;
2598
+ return t && (r += ` title="${R(t)}"`), r += ">", r;
3185
2599
  }
3186
- text(token) {
3187
- return 'tokens' in token && token.tokens ? this.parser.parseInline(token.tokens) : 'escaped' in token && token.escaped ? token.text : escape(token.text);
2600
+ text(e) {
2601
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : R(e.text);
3188
2602
  }
3189
- }
3190
-
3191
- /**
3192
- * TextRenderer
3193
- * returns only the textual part of the token
3194
- */
3195
- class _TextRenderer {
3196
- // no need for block level renderers
2603
+ };
2604
+ var _ = class {
3197
2605
  strong({
3198
- text
2606
+ text: e
3199
2607
  }) {
3200
- return text;
2608
+ return e;
3201
2609
  }
3202
2610
  em({
3203
- text
2611
+ text: e
3204
2612
  }) {
3205
- return text;
2613
+ return e;
3206
2614
  }
3207
2615
  codespan({
3208
- text
2616
+ text: e
3209
2617
  }) {
3210
- return text;
2618
+ return e;
3211
2619
  }
3212
2620
  del({
3213
- text
2621
+ text: e
3214
2622
  }) {
3215
- return text;
2623
+ return e;
3216
2624
  }
3217
2625
  html({
3218
- text
2626
+ text: e
3219
2627
  }) {
3220
- return text;
2628
+ return e;
3221
2629
  }
3222
2630
  text({
3223
- text
2631
+ text: e
3224
2632
  }) {
3225
- return text;
2633
+ return e;
3226
2634
  }
3227
2635
  link({
3228
- text
2636
+ text: e
3229
2637
  }) {
3230
- return '' + text;
2638
+ return "" + e;
3231
2639
  }
3232
2640
  image({
3233
- text
2641
+ text: e
3234
2642
  }) {
3235
- return '' + text;
2643
+ return "" + e;
3236
2644
  }
3237
2645
  br() {
3238
- return '';
2646
+ return "";
3239
2647
  }
3240
- }
3241
-
3242
- /**
3243
- * Parsing & Compiling
3244
- */
3245
- class _Parser {
2648
+ };
2649
+ var T = class a {
3246
2650
  options;
3247
2651
  renderer;
3248
2652
  textRenderer;
3249
- constructor(options) {
3250
- this.options = options || _defaults;
3251
- this.options.renderer = this.options.renderer || new _Renderer();
3252
- this.renderer = this.options.renderer;
3253
- this.renderer.options = this.options;
3254
- this.renderer.parser = this;
3255
- this.textRenderer = new _TextRenderer();
3256
- }
3257
- /**
3258
- * Static Parse Method
3259
- */
3260
- static parse(tokens, options) {
3261
- const parser = new _Parser(options);
3262
- return parser.parse(tokens);
3263
- }
3264
- /**
3265
- * Static Parse Inline Method
3266
- */
3267
- static parseInline(tokens, options) {
3268
- const parser = new _Parser(options);
3269
- return parser.parseInline(tokens);
3270
- }
3271
- /**
3272
- * Parse Loop
3273
- */
3274
- parse(tokens, top = true) {
3275
- let out = '';
3276
- for (let i = 0; i < tokens.length; i++) {
3277
- const anyToken = tokens[i];
3278
- // Run any renderer extensions
3279
- if (this.options.extensions?.renderers?.[anyToken.type]) {
3280
- const genericToken = anyToken;
3281
- const ret = this.options.extensions.renderers[genericToken.type].call({
3282
- parser: this
3283
- }, genericToken);
3284
- if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
3285
- out += ret || '';
2653
+ constructor(e) {
2654
+ this.options = e || w, this.options.renderer = this.options.renderer || new $(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new _();
2655
+ }
2656
+ static parse(e, t) {
2657
+ return new a(t).parse(e);
2658
+ }
2659
+ static parseInline(e, t) {
2660
+ return new a(t).parseInline(e);
2661
+ }
2662
+ parse(e, t = true) {
2663
+ let n = "";
2664
+ for (let s = 0; s < e.length; s++) {
2665
+ let i = e[s];
2666
+ if (this.options.extensions?.renderers?.[i.type]) {
2667
+ let o = i,
2668
+ l = this.options.extensions.renderers[o.type].call({
2669
+ parser: this
2670
+ }, o);
2671
+ if (l !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(o.type)) {
2672
+ n += l || "";
3286
2673
  continue;
3287
2674
  }
3288
2675
  }
3289
- const token = anyToken;
3290
- switch (token.type) {
3291
- case 'space':
2676
+ let r = i;
2677
+ switch (r.type) {
2678
+ case "space":
3292
2679
  {
3293
- out += this.renderer.space(token);
2680
+ n += this.renderer.space(r);
3294
2681
  continue;
3295
2682
  }
3296
- case 'hr':
2683
+ case "hr":
3297
2684
  {
3298
- out += this.renderer.hr(token);
2685
+ n += this.renderer.hr(r);
3299
2686
  continue;
3300
2687
  }
3301
- case 'heading':
2688
+ case "heading":
3302
2689
  {
3303
- out += this.renderer.heading(token);
2690
+ n += this.renderer.heading(r);
3304
2691
  continue;
3305
2692
  }
3306
- case 'code':
2693
+ case "code":
3307
2694
  {
3308
- out += this.renderer.code(token);
2695
+ n += this.renderer.code(r);
3309
2696
  continue;
3310
2697
  }
3311
- case 'table':
2698
+ case "table":
3312
2699
  {
3313
- out += this.renderer.table(token);
2700
+ n += this.renderer.table(r);
3314
2701
  continue;
3315
2702
  }
3316
- case 'blockquote':
2703
+ case "blockquote":
3317
2704
  {
3318
- out += this.renderer.blockquote(token);
2705
+ n += this.renderer.blockquote(r);
3319
2706
  continue;
3320
2707
  }
3321
- case 'list':
2708
+ case "list":
3322
2709
  {
3323
- out += this.renderer.list(token);
2710
+ n += this.renderer.list(r);
3324
2711
  continue;
3325
2712
  }
3326
- case 'html':
2713
+ case "html":
3327
2714
  {
3328
- out += this.renderer.html(token);
2715
+ n += this.renderer.html(r);
3329
2716
  continue;
3330
2717
  }
3331
- case 'paragraph':
2718
+ case "paragraph":
3332
2719
  {
3333
- out += this.renderer.paragraph(token);
2720
+ n += this.renderer.paragraph(r);
3334
2721
  continue;
3335
2722
  }
3336
- case 'text':
2723
+ case "text":
3337
2724
  {
3338
- let textToken = token;
3339
- let body = this.renderer.text(textToken);
3340
- while (i + 1 < tokens.length && tokens[i + 1].type === 'text') {
3341
- textToken = tokens[++i];
3342
- body += '\n' + this.renderer.text(textToken);
3343
- }
3344
- if (top) {
3345
- out += this.renderer.paragraph({
3346
- type: 'paragraph',
3347
- raw: body,
3348
- text: body,
3349
- tokens: [{
3350
- type: 'text',
3351
- raw: body,
3352
- text: body,
3353
- escaped: true
3354
- }]
3355
- });
3356
- } else {
3357
- out += body;
3358
- }
2725
+ let o = r,
2726
+ l = this.renderer.text(o);
2727
+ for (; s + 1 < e.length && e[s + 1].type === "text";) o = e[++s], l += `
2728
+ ` + this.renderer.text(o);
2729
+ t ? n += this.renderer.paragraph({
2730
+ type: "paragraph",
2731
+ raw: l,
2732
+ text: l,
2733
+ tokens: [{
2734
+ type: "text",
2735
+ raw: l,
2736
+ text: l,
2737
+ escaped: true
2738
+ }]
2739
+ }) : n += l;
3359
2740
  continue;
3360
2741
  }
3361
2742
  default:
3362
2743
  {
3363
- const errMsg = 'Token with "' + token.type + '" type was not found.';
3364
- if (this.options.silent) {
3365
- console.error(errMsg);
3366
- return '';
3367
- } else {
3368
- throw new Error(errMsg);
3369
- }
2744
+ let o = 'Token with "' + r.type + '" type was not found.';
2745
+ if (this.options.silent) return console.error(o), "";
2746
+ throw new Error(o);
3370
2747
  }
3371
2748
  }
3372
2749
  }
3373
- return out;
3374
- }
3375
- /**
3376
- * Parse Inline Tokens
3377
- */
3378
- parseInline(tokens, renderer = this.renderer) {
3379
- let out = '';
3380
- for (let i = 0; i < tokens.length; i++) {
3381
- const anyToken = tokens[i];
3382
- // Run any renderer extensions
3383
- if (this.options.extensions?.renderers?.[anyToken.type]) {
3384
- const ret = this.options.extensions.renderers[anyToken.type].call({
2750
+ return n;
2751
+ }
2752
+ parseInline(e, t = this.renderer) {
2753
+ let n = "";
2754
+ for (let s = 0; s < e.length; s++) {
2755
+ let i = e[s];
2756
+ if (this.options.extensions?.renderers?.[i.type]) {
2757
+ let o = this.options.extensions.renderers[i.type].call({
3385
2758
  parser: this
3386
- }, anyToken);
3387
- if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(anyToken.type)) {
3388
- out += ret || '';
2759
+ }, i);
2760
+ if (o !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
2761
+ n += o || "";
3389
2762
  continue;
3390
2763
  }
3391
2764
  }
3392
- const token = anyToken;
3393
- switch (token.type) {
3394
- case 'escape':
2765
+ let r = i;
2766
+ switch (r.type) {
2767
+ case "escape":
3395
2768
  {
3396
- out += renderer.text(token);
2769
+ n += t.text(r);
3397
2770
  break;
3398
2771
  }
3399
- case 'html':
2772
+ case "html":
3400
2773
  {
3401
- out += renderer.html(token);
2774
+ n += t.html(r);
3402
2775
  break;
3403
2776
  }
3404
- case 'link':
2777
+ case "link":
3405
2778
  {
3406
- out += renderer.link(token);
2779
+ n += t.link(r);
3407
2780
  break;
3408
2781
  }
3409
- case 'image':
2782
+ case "image":
3410
2783
  {
3411
- out += renderer.image(token);
2784
+ n += t.image(r);
3412
2785
  break;
3413
2786
  }
3414
- case 'strong':
2787
+ case "strong":
3415
2788
  {
3416
- out += renderer.strong(token);
2789
+ n += t.strong(r);
3417
2790
  break;
3418
2791
  }
3419
- case 'em':
2792
+ case "em":
3420
2793
  {
3421
- out += renderer.em(token);
2794
+ n += t.em(r);
3422
2795
  break;
3423
2796
  }
3424
- case 'codespan':
2797
+ case "codespan":
3425
2798
  {
3426
- out += renderer.codespan(token);
2799
+ n += t.codespan(r);
3427
2800
  break;
3428
2801
  }
3429
- case 'br':
2802
+ case "br":
3430
2803
  {
3431
- out += renderer.br(token);
2804
+ n += t.br(r);
3432
2805
  break;
3433
2806
  }
3434
- case 'del':
2807
+ case "del":
3435
2808
  {
3436
- out += renderer.del(token);
2809
+ n += t.del(r);
3437
2810
  break;
3438
2811
  }
3439
- case 'text':
2812
+ case "text":
3440
2813
  {
3441
- out += renderer.text(token);
2814
+ n += t.text(r);
3442
2815
  break;
3443
2816
  }
3444
2817
  default:
3445
2818
  {
3446
- const errMsg = 'Token with "' + token.type + '" type was not found.';
3447
- if (this.options.silent) {
3448
- console.error(errMsg);
3449
- return '';
3450
- } else {
3451
- throw new Error(errMsg);
3452
- }
2819
+ let o = 'Token with "' + r.type + '" type was not found.';
2820
+ if (this.options.silent) return console.error(o), "";
2821
+ throw new Error(o);
3453
2822
  }
3454
2823
  }
3455
2824
  }
3456
- return out;
2825
+ return n;
3457
2826
  }
3458
- }
3459
- class _Hooks {
2827
+ };
2828
+ var L = class {
3460
2829
  options;
3461
2830
  block;
3462
- constructor(options) {
3463
- this.options = options || _defaults;
3464
- }
3465
- static passThroughHooks = new Set(['preprocess', 'postprocess', 'processAllTokens']);
3466
- /**
3467
- * Process markdown before marked
3468
- */
3469
- preprocess(markdown) {
3470
- return markdown;
3471
- }
3472
- /**
3473
- * Process HTML after marked is finished
3474
- */
3475
- postprocess(html) {
3476
- return html;
3477
- }
3478
- /**
3479
- * Process all tokens before walk tokens
3480
- */
3481
- processAllTokens(tokens) {
3482
- return tokens;
3483
- }
3484
- /**
3485
- * Provide function to tokenize markdown
3486
- */
2831
+ constructor(e) {
2832
+ this.options = e || w;
2833
+ }
2834
+ static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens"]);
2835
+ preprocess(e) {
2836
+ return e;
2837
+ }
2838
+ postprocess(e) {
2839
+ return e;
2840
+ }
2841
+ processAllTokens(e) {
2842
+ return e;
2843
+ }
3487
2844
  provideLexer() {
3488
- return this.block ? _Lexer.lex : _Lexer.lexInline;
2845
+ return this.block ? b.lex : b.lexInline;
3489
2846
  }
3490
- /**
3491
- * Provide function to parse tokens
3492
- */
3493
2847
  provideParser() {
3494
- return this.block ? _Parser.parse : _Parser.parseInline;
2848
+ return this.block ? T.parse : T.parseInline;
3495
2849
  }
3496
- }
3497
- class Marked {
3498
- defaults = _getDefaults();
2850
+ };
2851
+ var B = class {
2852
+ defaults = M();
3499
2853
  options = this.setOptions;
3500
2854
  parse = this.parseMarkdown(true);
3501
2855
  parseInline = this.parseMarkdown(false);
3502
- Parser = _Parser;
3503
- Renderer = _Renderer;
3504
- TextRenderer = _TextRenderer;
3505
- Lexer = _Lexer;
3506
- Tokenizer = _Tokenizer;
3507
- Hooks = _Hooks;
3508
- constructor(...args) {
3509
- this.use(...args);
3510
- }
3511
- /**
3512
- * Run callback for every token
3513
- */
3514
- walkTokens(tokens, callback) {
3515
- let values = [];
3516
- for (const token of tokens) {
3517
- values = values.concat(callback.call(this, token));
3518
- switch (token.type) {
3519
- case 'table':
3520
- {
3521
- const tableToken = token;
3522
- for (const cell of tableToken.header) {
3523
- values = values.concat(this.walkTokens(cell.tokens, callback));
3524
- }
3525
- for (const row of tableToken.rows) {
3526
- for (const cell of row) {
3527
- values = values.concat(this.walkTokens(cell.tokens, callback));
3528
- }
3529
- }
3530
- break;
3531
- }
3532
- case 'list':
3533
- {
3534
- const listToken = token;
3535
- values = values.concat(this.walkTokens(listToken.items, callback));
3536
- break;
3537
- }
3538
- default:
3539
- {
3540
- const genericToken = token;
3541
- if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
3542
- this.defaults.extensions.childTokens[genericToken.type].forEach(childTokens => {
3543
- const tokens = genericToken[childTokens].flat(Infinity);
3544
- values = values.concat(this.walkTokens(tokens, callback));
3545
- });
3546
- } else if (genericToken.tokens) {
3547
- values = values.concat(this.walkTokens(genericToken.tokens, callback));
3548
- }
3549
- }
3550
- }
2856
+ Parser = T;
2857
+ Renderer = $;
2858
+ TextRenderer = _;
2859
+ Lexer = b;
2860
+ Tokenizer = S;
2861
+ Hooks = L;
2862
+ constructor(...e) {
2863
+ this.use(...e);
2864
+ }
2865
+ walkTokens(e, t) {
2866
+ let n = [];
2867
+ for (let s of e) switch (n = n.concat(t.call(this, s)), s.type) {
2868
+ case "table":
2869
+ {
2870
+ let i = s;
2871
+ for (let r of i.header) n = n.concat(this.walkTokens(r.tokens, t));
2872
+ for (let r of i.rows) for (let o of r) n = n.concat(this.walkTokens(o.tokens, t));
2873
+ break;
2874
+ }
2875
+ case "list":
2876
+ {
2877
+ let i = s;
2878
+ n = n.concat(this.walkTokens(i.items, t));
2879
+ break;
2880
+ }
2881
+ default:
2882
+ {
2883
+ let i = s;
2884
+ this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach(r => {
2885
+ let o = i[r].flat(1 / 0);
2886
+ n = n.concat(this.walkTokens(o, t));
2887
+ }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
2888
+ }
3551
2889
  }
3552
- return values;
2890
+ return n;
3553
2891
  }
3554
- use(...args) {
3555
- const extensions = this.defaults.extensions || {
2892
+ use(...e) {
2893
+ let t = this.defaults.extensions || {
3556
2894
  renderers: {},
3557
2895
  childTokens: {}
3558
2896
  };
3559
- args.forEach(pack => {
3560
- // copy options to new object
3561
- const opts = {
3562
- ...pack
2897
+ return e.forEach(n => {
2898
+ let s = {
2899
+ ...n
3563
2900
  };
3564
- // set async to true if it was set to true before
3565
- opts.async = this.defaults.async || opts.async || false;
3566
- // ==-- Parse "addon" extensions --== //
3567
- if (pack.extensions) {
3568
- pack.extensions.forEach(ext => {
3569
- if (!ext.name) {
3570
- throw new Error('extension name required');
3571
- }
3572
- if ('renderer' in ext) {
3573
- // Renderer extensions
3574
- const prevRenderer = extensions.renderers[ext.name];
3575
- if (prevRenderer) {
3576
- // Replace extension with func to run new extension but fall back if false
3577
- extensions.renderers[ext.name] = function (...args) {
3578
- let ret = ext.renderer.apply(this, args);
3579
- if (ret === false) {
3580
- ret = prevRenderer.apply(this, args);
3581
- }
3582
- return ret;
3583
- };
3584
- } else {
3585
- extensions.renderers[ext.name] = ext.renderer;
3586
- }
3587
- }
3588
- if ('tokenizer' in ext) {
3589
- // Tokenizer Extensions
3590
- if (!ext.level || ext.level !== 'block' && ext.level !== 'inline') {
3591
- throw new Error("extension level must be 'block' or 'inline'");
3592
- }
3593
- const extLevel = extensions[ext.level];
3594
- if (extLevel) {
3595
- extLevel.unshift(ext.tokenizer);
3596
- } else {
3597
- extensions[ext.level] = [ext.tokenizer];
3598
- }
3599
- if (ext.start) {
3600
- // Function to check for start of token
3601
- if (ext.level === 'block') {
3602
- if (extensions.startBlock) {
3603
- extensions.startBlock.push(ext.start);
3604
- } else {
3605
- extensions.startBlock = [ext.start];
3606
- }
3607
- } else if (ext.level === 'inline') {
3608
- if (extensions.startInline) {
3609
- extensions.startInline.push(ext.start);
3610
- } else {
3611
- extensions.startInline = [ext.start];
3612
- }
3613
- }
3614
- }
3615
- }
3616
- if ('childTokens' in ext && ext.childTokens) {
3617
- // Child tokens to be visited by walkTokens
3618
- extensions.childTokens[ext.name] = ext.childTokens;
3619
- }
3620
- });
3621
- opts.extensions = extensions;
3622
- }
3623
- // ==-- Parse "overwrite" extensions --== //
3624
- if (pack.renderer) {
3625
- const renderer = this.defaults.renderer || new _Renderer(this.defaults);
3626
- for (const prop in pack.renderer) {
3627
- if (!(prop in renderer)) {
3628
- throw new Error(`renderer '${prop}' does not exist`);
3629
- }
3630
- if (['options', 'parser'].includes(prop)) {
3631
- // ignore options property
3632
- continue;
3633
- }
3634
- const rendererProp = prop;
3635
- const rendererFunc = pack.renderer[rendererProp];
3636
- const prevRenderer = renderer[rendererProp];
3637
- // Replace renderer with func to run extension, but fall back if false
3638
- renderer[rendererProp] = (...args) => {
3639
- let ret = rendererFunc.apply(renderer, args);
3640
- if (ret === false) {
3641
- ret = prevRenderer.apply(renderer, args);
3642
- }
3643
- return ret || '';
2901
+ if (s.async = this.defaults.async || s.async || false, n.extensions && (n.extensions.forEach(i => {
2902
+ if (!i.name) throw new Error("extension name required");
2903
+ if ("renderer" in i) {
2904
+ let r = t.renderers[i.name];
2905
+ r ? t.renderers[i.name] = function (...o) {
2906
+ let l = i.renderer.apply(this, o);
2907
+ return l === false && (l = r.apply(this, o)), l;
2908
+ } : t.renderers[i.name] = i.renderer;
2909
+ }
2910
+ if ("tokenizer" in i) {
2911
+ if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
2912
+ let r = t[i.level];
2913
+ r ? r.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
2914
+ }
2915
+ "childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
2916
+ }), s.extensions = t), n.renderer) {
2917
+ let i = this.defaults.renderer || new $(this.defaults);
2918
+ for (let r in n.renderer) {
2919
+ if (!(r in i)) throw new Error(`renderer '${r}' does not exist`);
2920
+ if (["options", "parser"].includes(r)) continue;
2921
+ let o = r,
2922
+ l = n.renderer[o],
2923
+ c = i[o];
2924
+ i[o] = (...p) => {
2925
+ let u = l.apply(i, p);
2926
+ return u === false && (u = c.apply(i, p)), u || "";
3644
2927
  };
3645
2928
  }
3646
- opts.renderer = renderer;
3647
- }
3648
- if (pack.tokenizer) {
3649
- const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
3650
- for (const prop in pack.tokenizer) {
3651
- if (!(prop in tokenizer)) {
3652
- throw new Error(`tokenizer '${prop}' does not exist`);
3653
- }
3654
- if (['options', 'rules', 'lexer'].includes(prop)) {
3655
- // ignore options, rules, and lexer properties
3656
- continue;
3657
- }
3658
- const tokenizerProp = prop;
3659
- const tokenizerFunc = pack.tokenizer[tokenizerProp];
3660
- const prevTokenizer = tokenizer[tokenizerProp];
3661
- // Replace tokenizer with func to run extension, but fall back if false
3662
- // @ts-expect-error cannot type tokenizer function dynamically
3663
- tokenizer[tokenizerProp] = (...args) => {
3664
- let ret = tokenizerFunc.apply(tokenizer, args);
3665
- if (ret === false) {
3666
- ret = prevTokenizer.apply(tokenizer, args);
3667
- }
3668
- return ret;
2929
+ s.renderer = i;
2930
+ }
2931
+ if (n.tokenizer) {
2932
+ let i = this.defaults.tokenizer || new S(this.defaults);
2933
+ for (let r in n.tokenizer) {
2934
+ if (!(r in i)) throw new Error(`tokenizer '${r}' does not exist`);
2935
+ if (["options", "rules", "lexer"].includes(r)) continue;
2936
+ let o = r,
2937
+ l = n.tokenizer[o],
2938
+ c = i[o];
2939
+ i[o] = (...p) => {
2940
+ let u = l.apply(i, p);
2941
+ return u === false && (u = c.apply(i, p)), u;
3669
2942
  };
3670
2943
  }
3671
- opts.tokenizer = tokenizer;
3672
- }
3673
- // ==-- Parse Hooks extensions --== //
3674
- if (pack.hooks) {
3675
- const hooks = this.defaults.hooks || new _Hooks();
3676
- for (const prop in pack.hooks) {
3677
- if (!(prop in hooks)) {
3678
- throw new Error(`hook '${prop}' does not exist`);
3679
- }
3680
- if (['options', 'block'].includes(prop)) {
3681
- // ignore options and block properties
3682
- continue;
3683
- }
3684
- const hooksProp = prop;
3685
- const hooksFunc = pack.hooks[hooksProp];
3686
- const prevHook = hooks[hooksProp];
3687
- if (_Hooks.passThroughHooks.has(prop)) {
3688
- // @ts-expect-error cannot type hook function dynamically
3689
- hooks[hooksProp] = arg => {
3690
- if (this.defaults.async) {
3691
- return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
3692
- return prevHook.call(hooks, ret);
3693
- });
3694
- }
3695
- const ret = hooksFunc.call(hooks, arg);
3696
- return prevHook.call(hooks, ret);
3697
- };
3698
- } else {
3699
- // @ts-expect-error cannot type hook function dynamically
3700
- hooks[hooksProp] = (...args) => {
3701
- let ret = hooksFunc.apply(hooks, args);
3702
- if (ret === false) {
3703
- ret = prevHook.apply(hooks, args);
3704
- }
3705
- return ret;
3706
- };
3707
- }
2944
+ s.tokenizer = i;
2945
+ }
2946
+ if (n.hooks) {
2947
+ let i = this.defaults.hooks || new L();
2948
+ for (let r in n.hooks) {
2949
+ if (!(r in i)) throw new Error(`hook '${r}' does not exist`);
2950
+ if (["options", "block"].includes(r)) continue;
2951
+ let o = r,
2952
+ l = n.hooks[o],
2953
+ c = i[o];
2954
+ L.passThroughHooks.has(r) ? i[o] = p => {
2955
+ if (this.defaults.async) return Promise.resolve(l.call(i, p)).then(d => c.call(i, d));
2956
+ let u = l.call(i, p);
2957
+ return c.call(i, u);
2958
+ } : i[o] = (...p) => {
2959
+ let u = l.apply(i, p);
2960
+ return u === false && (u = c.apply(i, p)), u;
2961
+ };
3708
2962
  }
3709
- opts.hooks = hooks;
2963
+ s.hooks = i;
3710
2964
  }
3711
- // ==-- Parse WalkTokens extensions --== //
3712
- if (pack.walkTokens) {
3713
- const walkTokens = this.defaults.walkTokens;
3714
- const packWalktokens = pack.walkTokens;
3715
- opts.walkTokens = function (token) {
3716
- let values = [];
3717
- values.push(packWalktokens.call(this, token));
3718
- if (walkTokens) {
3719
- values = values.concat(walkTokens.call(this, token));
3720
- }
3721
- return values;
2965
+ if (n.walkTokens) {
2966
+ let i = this.defaults.walkTokens,
2967
+ r = n.walkTokens;
2968
+ s.walkTokens = function (o) {
2969
+ let l = [];
2970
+ return l.push(r.call(this, o)), i && (l = l.concat(i.call(this, o))), l;
3722
2971
  };
3723
2972
  }
3724
2973
  this.defaults = {
3725
2974
  ...this.defaults,
3726
- ...opts
2975
+ ...s
3727
2976
  };
3728
- });
3729
- return this;
2977
+ }), this;
3730
2978
  }
3731
- setOptions(opt) {
3732
- this.defaults = {
2979
+ setOptions(e) {
2980
+ return this.defaults = {
3733
2981
  ...this.defaults,
3734
- ...opt
3735
- };
3736
- return this;
3737
- }
3738
- lexer(src, options) {
3739
- return _Lexer.lex(src, options ?? this.defaults);
3740
- }
3741
- parser(tokens, options) {
3742
- return _Parser.parse(tokens, options ?? this.defaults);
3743
- }
3744
- parseMarkdown(blockType) {
3745
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3746
- const parse = (src, options) => {
3747
- const origOpt = {
3748
- ...options
3749
- };
3750
- const opt = {
3751
- ...this.defaults,
3752
- ...origOpt
3753
- };
3754
- const throwError = this.onError(!!opt.silent, !!opt.async);
3755
- // throw error if an extension set async to true but parse was called with async: false
3756
- if (this.defaults.async === true && origOpt.async === false) {
3757
- return throwError(new Error('marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.'));
3758
- }
3759
- // throw error in case of non string input
3760
- if (typeof src === 'undefined' || src === null) {
3761
- return throwError(new Error('marked(): input parameter is undefined or null'));
3762
- }
3763
- if (typeof src !== 'string') {
3764
- return throwError(new Error('marked(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected'));
3765
- }
3766
- if (opt.hooks) {
3767
- opt.hooks.options = opt;
3768
- opt.hooks.block = blockType;
3769
- }
3770
- const lexer = opt.hooks ? opt.hooks.provideLexer() : blockType ? _Lexer.lex : _Lexer.lexInline;
3771
- const parser = opt.hooks ? opt.hooks.provideParser() : blockType ? _Parser.parse : _Parser.parseInline;
3772
- if (opt.async) {
3773
- return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then(src => lexer(src, opt)).then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens).then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then(tokens => parser(tokens, opt)).then(html => opt.hooks ? opt.hooks.postprocess(html) : html).catch(throwError);
3774
- }
2982
+ ...e
2983
+ }, this;
2984
+ }
2985
+ lexer(e, t) {
2986
+ return b.lex(e, t ?? this.defaults);
2987
+ }
2988
+ parser(e, t) {
2989
+ return T.parse(e, t ?? this.defaults);
2990
+ }
2991
+ parseMarkdown(e) {
2992
+ return (n, s) => {
2993
+ let i = {
2994
+ ...s
2995
+ },
2996
+ r = {
2997
+ ...this.defaults,
2998
+ ...i
2999
+ },
3000
+ o = this.onError(!!r.silent, !!r.async);
3001
+ if (this.defaults.async === true && i.async === false) return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
3002
+ if (typeof n > "u" || n === null) return o(new Error("marked(): input parameter is undefined or null"));
3003
+ if (typeof n != "string") return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
3004
+ r.hooks && (r.hooks.options = r, r.hooks.block = e);
3005
+ let l = r.hooks ? r.hooks.provideLexer() : e ? b.lex : b.lexInline,
3006
+ c = r.hooks ? r.hooks.provideParser() : e ? T.parse : T.parseInline;
3007
+ if (r.async) return Promise.resolve(r.hooks ? r.hooks.preprocess(n) : n).then(p => l(p, r)).then(p => r.hooks ? r.hooks.processAllTokens(p) : p).then(p => r.walkTokens ? Promise.all(this.walkTokens(p, r.walkTokens)).then(() => p) : p).then(p => c(p, r)).then(p => r.hooks ? r.hooks.postprocess(p) : p).catch(o);
3775
3008
  try {
3776
- if (opt.hooks) {
3777
- src = opt.hooks.preprocess(src);
3778
- }
3779
- let tokens = lexer(src, opt);
3780
- if (opt.hooks) {
3781
- tokens = opt.hooks.processAllTokens(tokens);
3782
- }
3783
- if (opt.walkTokens) {
3784
- this.walkTokens(tokens, opt.walkTokens);
3785
- }
3786
- let html = parser(tokens, opt);
3787
- if (opt.hooks) {
3788
- html = opt.hooks.postprocess(html);
3789
- }
3790
- return html;
3791
- } catch (e) {
3792
- return throwError(e);
3009
+ r.hooks && (n = r.hooks.preprocess(n));
3010
+ let p = l(n, r);
3011
+ r.hooks && (p = r.hooks.processAllTokens(p)), r.walkTokens && this.walkTokens(p, r.walkTokens);
3012
+ let u = c(p, r);
3013
+ return r.hooks && (u = r.hooks.postprocess(u)), u;
3014
+ } catch (p) {
3015
+ return o(p);
3793
3016
  }
3794
3017
  };
3795
- return parse;
3796
- }
3797
- onError(silent, async) {
3798
- return e => {
3799
- e.message += '\nPlease report this to https://github.com/markedjs/marked.';
3800
- if (silent) {
3801
- const msg = '<p>An error occurred:</p><pre>' + escape(e.message + '', true) + '</pre>';
3802
- if (async) {
3803
- return Promise.resolve(msg);
3804
- }
3805
- return msg;
3806
- }
3807
- if (async) {
3808
- return Promise.reject(e);
3018
+ }
3019
+ onError(e, t) {
3020
+ return n => {
3021
+ if (n.message += `
3022
+ Please report this to https://github.com/markedjs/marked.`, e) {
3023
+ let s = "<p>An error occurred:</p><pre>" + R(n.message + "", true) + "</pre>";
3024
+ return t ? Promise.resolve(s) : s;
3809
3025
  }
3810
- throw e;
3026
+ if (t) return Promise.reject(n);
3027
+ throw n;
3811
3028
  };
3812
3029
  }
3813
- }
3814
- const markedInstance = new Marked();
3815
- function marked(src, opt) {
3816
- return markedInstance.parse(src, opt);
3817
- }
3818
- /**
3819
- * Sets the default options.
3820
- *
3821
- * @param options Hash of options
3822
- */
3823
- marked.options = marked.setOptions = function (options) {
3824
- markedInstance.setOptions(options);
3825
- marked.defaults = markedInstance.defaults;
3826
- changeDefaults(marked.defaults);
3827
- return marked;
3828
- };
3829
- /**
3830
- * Gets the original marked default options.
3831
- */
3832
- marked.getDefaults = _getDefaults;
3833
- marked.defaults = _defaults;
3834
- /**
3835
- * Use Extension
3836
- */
3837
- marked.use = function (...args) {
3838
- markedInstance.use(...args);
3839
- marked.defaults = markedInstance.defaults;
3840
- changeDefaults(marked.defaults);
3841
- return marked;
3842
- };
3843
- /**
3844
- * Run callback for every token
3845
- */
3846
- marked.walkTokens = function (tokens, callback) {
3847
- return markedInstance.walkTokens(tokens, callback);
3848
3030
  };
3849
- /**
3850
- * Compiles markdown to HTML without enclosing `p` tag.
3851
- *
3852
- * @param src String of markdown source to be compiled
3853
- * @param options Hash of options
3854
- * @return String of compiled HTML
3855
- */
3856
- marked.parseInline = markedInstance.parseInline;
3857
- /**
3858
- * Expose
3859
- */
3860
- marked.Parser = _Parser;
3861
- marked.parser = _Parser.parse;
3862
- marked.Renderer = _Renderer;
3863
- marked.TextRenderer = _TextRenderer;
3864
- marked.Lexer = _Lexer;
3865
- marked.lexer = _Lexer.lex;
3866
- marked.Tokenizer = _Tokenizer;
3867
- marked.Hooks = _Hooks;
3868
- marked.parse = marked;
3031
+ var z = new B();
3032
+ function k(a, e) {
3033
+ return z.parse(a, e);
3034
+ }
3035
+ k.options = k.setOptions = function (a) {
3036
+ return z.setOptions(a), k.defaults = z.defaults, H(k.defaults), k;
3037
+ };
3038
+ k.getDefaults = M;
3039
+ k.defaults = w;
3040
+ k.use = function (...a) {
3041
+ return z.use(...a), k.defaults = z.defaults, H(k.defaults), k;
3042
+ };
3043
+ k.walkTokens = function (a, e) {
3044
+ return z.walkTokens(a, e);
3045
+ };
3046
+ k.parseInline = z.parseInline;
3047
+ k.Parser = T;
3048
+ k.parser = T.parse;
3049
+ k.Renderer = $;
3050
+ k.TextRenderer = _;
3051
+ k.Lexer = b;
3052
+ k.lexer = b.lex;
3053
+ k.Tokenizer = S;
3054
+ k.Hooks = L;
3055
+ k.parse = k;
3869
3056
 
3870
3057
  const renderMarkdown = async (markdown, options = {}) => {
3871
- const html = await marked(markdown, {});
3058
+ const html = await k(markdown, {});
3872
3059
  return html;
3873
3060
  };
3874
3061
 
@@ -3885,18 +3072,56 @@ const commandMap = {
3885
3072
  'Markdown.getMarkDownVirtualDom': getMarkdownVirtualDom
3886
3073
  };
3887
3074
 
3888
- const RendererWorker = 1;
3889
-
3890
3075
  const rpcs = Object.create(null);
3891
- const set = (id, rpc) => {
3076
+ const set$g = (id, rpc) => {
3892
3077
  rpcs[id] = rpc;
3893
3078
  };
3079
+ const get = id => {
3080
+ return rpcs[id];
3081
+ };
3082
+
3083
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
3084
+
3085
+ const create = rpcId => {
3086
+ return {
3087
+ // @ts-ignore
3088
+ invoke(method, ...params) {
3089
+ const rpc = get(rpcId);
3090
+ // @ts-ignore
3091
+ return rpc.invoke(method, ...params);
3092
+ },
3093
+ // @ts-ignore
3094
+ invokeAndTransfer(method, ...params) {
3095
+ const rpc = get(rpcId);
3096
+ // @ts-ignore
3097
+ return rpc.invokeAndTransfer(method, ...params);
3098
+ },
3099
+ set(rpc) {
3100
+ set$g(rpcId, rpc);
3101
+ },
3102
+ async dispose() {
3103
+ const rpc = get(rpcId);
3104
+ await rpc.dispose();
3105
+ }
3106
+ };
3107
+ };
3108
+ const RendererWorker$1 = 1;
3109
+ const {
3110
+ set: set$3} = create(RendererWorker$1);
3111
+ const RendererWorker = {
3112
+ __proto__: null,
3113
+ set: set$3
3114
+ };
3115
+
3116
+ const {
3117
+ set
3118
+ } = RendererWorker;
3894
3119
 
3895
3120
  const listen = async () => {
3896
3121
  const rpc = await WebWorkerRpcClient.create({
3897
3122
  commandMap: commandMap
3898
3123
  });
3899
- set(RendererWorker, rpc);
3124
+ set(rpc);
3900
3125
  };
3901
3126
 
3902
3127
  const main = async () => {