pcm-agents 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/app-globals-BIO4q6tX.js.map +1 -1
  3. package/dist/cjs/components-chat-message_33.cjs.entry.js +54 -2317
  4. package/dist/cjs/components-chat-message_33.cjs.entry.js.map +1 -1
  5. package/dist/cjs/components-oem-virtual-chat-modal.cjs.entry.js +2 -2
  6. package/dist/cjs/{conversation-utils-BmxHPKOt.js → conversation-utils-CKlwCDRf.js} +4 -4
  7. package/dist/cjs/{conversation-utils-BmxHPKOt.js.map → conversation-utils-CKlwCDRf.js.map} +1 -1
  8. package/dist/cjs/{index-BivNZVuE.js → index-DLbq5wiz.js} +3 -3
  9. package/dist/cjs/{index-BivNZVuE.js.map → index-DLbq5wiz.js.map} +1 -1
  10. package/dist/cjs/index.cjs.js +1 -1
  11. package/dist/cjs/loader.cjs.js +1 -1
  12. package/dist/cjs/markdown-C0QWZi9Q.js +2674 -0
  13. package/dist/cjs/{markdown-D3_atg0b.js.map → markdown-C0QWZi9Q.js.map} +1 -1
  14. package/dist/cjs/oem-cast-modal.cjs.entry.js +1 -1
  15. package/dist/cjs/oem-htws-modal.cjs.entry.js +1 -1
  16. package/dist/cjs/oem-jd-modal.cjs.entry.js +2 -2
  17. package/dist/cjs/oem-jlpp-modal.cjs.entry.js +1 -1
  18. package/dist/cjs/oem-jlzz-modal.cjs.entry.js +1 -1
  19. package/dist/cjs/oem-mnct-modal.cjs.entry.js +1 -1
  20. package/dist/cjs/oem-mnms-modal.cjs.entry.js +1 -1
  21. package/dist/cjs/oem-qgqjl-modal.cjs.entry.js +3 -3
  22. package/dist/cjs/pcm-agents.cjs.js +1 -1
  23. package/dist/cjs/pcm-hr-chat-modal.cjs.entry.js +2 -2
  24. package/dist/cjs/pcm-jlsx-modal.cjs.entry.js +3 -3
  25. package/dist/cjs/{sentry-reporter-Ck3EoJAs.js → sentry-reporter-BmrqhSKs.js} +3 -3
  26. package/dist/cjs/{sentry-reporter-Ck3EoJAs.js.map → sentry-reporter-BmrqhSKs.js.map} +1 -1
  27. package/dist/collection/components/components-upload/components-upload.js +1 -1
  28. package/dist/collection/components/components-voice-input-btn/components-voice-input-btn.css +67 -67
  29. package/dist/collection/components/components-voice-input-btn/components-voice-input-btn.js +2 -2
  30. package/dist/collection/components/components-voice-input-btn/components-voice-input-btn.js.map +1 -1
  31. package/dist/collection/components/oem-cast-modal/oem-cast-modal.js +1 -1
  32. package/dist/collection/components/oem-zygh-modal/oem-zygh-modal.js +1 -1
  33. package/dist/collection/components/pcm-htws-modal/pcm-htws-modal.js +26 -1
  34. package/dist/collection/components/pcm-htws-modal/pcm-htws-modal.js.map +1 -1
  35. package/dist/collection/components/pcm-hyzj-modal/pcm-hyzj-modal.js +26 -1
  36. package/dist/collection/components/pcm-hyzj-modal/pcm-hyzj-modal.js.map +1 -1
  37. package/dist/collection/components/pcm-jd-modal/pcm-jd-modal.js +26 -1
  38. package/dist/collection/components/pcm-jd-modal/pcm-jd-modal.js.map +1 -1
  39. package/dist/collection/components/pcm-mnct-modal/pcm-mnct-modal.js +26 -1
  40. package/dist/collection/components/pcm-mnct-modal/pcm-mnct-modal.js.map +1 -1
  41. package/dist/collection/components/pcm-msbg-modal/pcm-msbg-modal.js +26 -1
  42. package/dist/collection/components/pcm-msbg-modal/pcm-msbg-modal.js.map +1 -1
  43. package/dist/collection/components/pcm-qgqjl-modal/pcm-qgqjl-modal.js +26 -1
  44. package/dist/collection/components/pcm-qgqjl-modal/pcm-qgqjl-modal.js.map +1 -1
  45. package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js +27 -2
  46. package/dist/collection/components/pcm-zygh-modal/pcm-zygh-modal.js.map +1 -1
  47. package/dist/collection/components/pcm-zygh-v2-modal/pcm-zygh-v2-modal.js +27 -2
  48. package/dist/collection/components/pcm-zygh-v2-modal/pcm-zygh-v2-modal.js.map +1 -1
  49. package/dist/components/components-chat-message.js +1 -1
  50. package/dist/components/components-digital-human.js +1 -1
  51. package/dist/components/components-export-records-modal.js +1 -1
  52. package/dist/components/components-mobile-input-btn.js +1 -1
  53. package/dist/components/components-mobile-upload-btn.js +1 -1
  54. package/dist/components/components-oem-virtual-chat-modal.js +1 -1
  55. package/dist/components/components-position-selector.js +1 -1
  56. package/dist/components/components-thousand-resume-wrapper.js +1 -1
  57. package/dist/components/components-upload.js +1 -1
  58. package/dist/components/components-voice-input-btn.js +1 -1
  59. package/dist/components/index.js +1 -1
  60. package/dist/components/index.js.map +1 -1
  61. package/dist/components/oem-cast-modal.js +1 -1
  62. package/dist/components/oem-htws-modal.js +5 -5
  63. package/dist/components/oem-jd-modal.js +5 -5
  64. package/dist/components/oem-jlpp-modal.js +7 -7
  65. package/dist/components/oem-jlsx-modal.js +6 -6
  66. package/dist/components/oem-jlzz-modal.js +5 -5
  67. package/dist/components/oem-mnct-modal.js +7 -7
  68. package/dist/components/oem-mnms-modal.js +8 -8
  69. package/dist/components/oem-qgqjl-modal.js +9 -9
  70. package/dist/components/oem-zygh-modal.js +5 -5
  71. package/dist/components/{p-BYD6-WNq.js → p-BFBILVHb.js} +3 -3
  72. package/dist/components/{p-BYD6-WNq.js.map → p-BFBILVHb.js.map} +1 -1
  73. package/dist/components/{p-CyUWH4Mj.js → p-BM8LfA-I.js} +4 -4
  74. package/dist/components/{p-CyUWH4Mj.js.map → p-BM8LfA-I.js.map} +1 -1
  75. package/dist/components/{p-ssn_a1iK.js → p-BMyYj4Nh.js} +3 -3
  76. package/dist/components/{p-ssn_a1iK.js.map → p-BMyYj4Nh.js.map} +1 -1
  77. package/dist/components/{p-BWUzAm4p.js → p-BbgkkZ8z.js} +3 -3
  78. package/dist/components/{p-BWUzAm4p.js.map → p-BbgkkZ8z.js.map} +1 -1
  79. package/dist/components/{p-BG6NTTpT.js → p-BsVthfPT.js} +4 -4
  80. package/dist/components/{p-BG6NTTpT.js.map → p-BsVthfPT.js.map} +1 -1
  81. package/dist/components/{p-A3F6YFmx.js → p-C5cxtSmw.js} +3 -3
  82. package/dist/components/{p-A3F6YFmx.js.map → p-C5cxtSmw.js.map} +1 -1
  83. package/dist/components/{p-Bry80jQE.js → p-CRuYvhDS.js} +3 -3
  84. package/dist/components/{p-Bry80jQE.js.map → p-CRuYvhDS.js.map} +1 -1
  85. package/dist/components/{p-CXalGxO1.js → p-CUgq8UDs.js} +4 -4
  86. package/dist/components/p-CUgq8UDs.js.map +1 -0
  87. package/dist/components/{p-CNf8b_lT.js → p-ChHHPVqa.js} +6 -6
  88. package/dist/components/{p-CNf8b_lT.js.map → p-ChHHPVqa.js.map} +1 -1
  89. package/dist/components/p-CnhOGURu.js +2671 -0
  90. package/dist/components/p-CnhOGURu.js.map +1 -0
  91. package/dist/components/{p-nhuWyXIB.js → p-DMxCytIw.js} +3 -3
  92. package/dist/components/{p-nhuWyXIB.js.map → p-DMxCytIw.js.map} +1 -1
  93. package/dist/components/{p-DLLeEB9s.js → p-DW7If7Qd.js} +4 -5
  94. package/dist/components/p-DW7If7Qd.js.map +1 -0
  95. package/dist/components/{p-0BR5lZiC.js → p-OFgPkEGL.js} +4 -4
  96. package/dist/components/{p-0BR5lZiC.js.map → p-OFgPkEGL.js.map} +1 -1
  97. package/dist/components/{p-CdHCR-Rr.js → p-aK_x2dmu.js} +3 -3
  98. package/dist/components/{p-CdHCR-Rr.js.map → p-aK_x2dmu.js.map} +1 -1
  99. package/dist/components/{p-C-x5thNz.js → p-sXNEbeK0.js} +3 -3
  100. package/dist/components/{p-C-x5thNz.js.map → p-sXNEbeK0.js.map} +1 -1
  101. package/dist/components/pcm-1zhanshi-mnms-modal.js +5 -5
  102. package/dist/components/pcm-app-chat-modal.js +1 -1
  103. package/dist/components/pcm-ats-mnms-modal.js +5 -5
  104. package/dist/components/pcm-card.js +1 -1
  105. package/dist/components/pcm-hr-chat-modal.js +2 -2
  106. package/dist/components/pcm-htws-modal.js +15 -9
  107. package/dist/components/pcm-htws-modal.js.map +1 -1
  108. package/dist/components/pcm-hyzj-modal.js +12 -6
  109. package/dist/components/pcm-hyzj-modal.js.map +1 -1
  110. package/dist/components/pcm-jd-modal.js +13 -7
  111. package/dist/components/pcm-jd-modal.js.map +1 -1
  112. package/dist/components/pcm-jlpp-modal.js +8 -8
  113. package/dist/components/pcm-jlsx-modal.js +6 -6
  114. package/dist/components/pcm-jlzz-modal.js +6 -6
  115. package/dist/components/pcm-mnct-modal.js +14 -8
  116. package/dist/components/pcm-mnct-modal.js.map +1 -1
  117. package/dist/components/pcm-mnms-modal.js +8 -8
  118. package/dist/components/pcm-mnms-zp-modal.js +8 -8
  119. package/dist/components/pcm-msbg-modal.js +12 -6
  120. package/dist/components/pcm-msbg-modal.js.map +1 -1
  121. package/dist/components/pcm-qgqjl-modal.js +16 -10
  122. package/dist/components/pcm-qgqjl-modal.js.map +1 -1
  123. package/dist/components/pcm-virtual-chat-modal.js +1 -1
  124. package/dist/components/pcm-zsk-chat-modal.js +3 -3
  125. package/dist/components/pcm-zygh-modal.js +14 -8
  126. package/dist/components/pcm-zygh-modal.js.map +1 -1
  127. package/dist/components/pcm-zygh-v2-modal.js +14 -8
  128. package/dist/components/pcm-zygh-v2-modal.js.map +1 -1
  129. package/dist/esm/app-globals-Chti62re.js.map +1 -1
  130. package/dist/esm/components-chat-message_33.entry.js +54 -2317
  131. package/dist/esm/components-chat-message_33.entry.js.map +1 -1
  132. package/dist/esm/components-oem-virtual-chat-modal.entry.js +2 -2
  133. package/dist/esm/{conversation-utils-fCK0sgM1.js → conversation-utils-BGcxaSyr.js} +4 -4
  134. package/dist/esm/{conversation-utils-fCK0sgM1.js.map → conversation-utils-BGcxaSyr.js.map} +1 -1
  135. package/dist/esm/{index-D7qB8ZCs.js → index-BaYctFVD.js} +3 -3
  136. package/dist/esm/{index-D7qB8ZCs.js.map → index-BaYctFVD.js.map} +1 -1
  137. package/dist/esm/index.js +1 -1
  138. package/dist/esm/loader.js +1 -1
  139. package/dist/esm/markdown-CnhOGURu.js +2671 -0
  140. package/dist/esm/{markdown-DcmYnk0q.js.map → markdown-CnhOGURu.js.map} +1 -1
  141. package/dist/esm/oem-cast-modal.entry.js +1 -1
  142. package/dist/esm/oem-htws-modal.entry.js +1 -1
  143. package/dist/esm/oem-jd-modal.entry.js +2 -2
  144. package/dist/esm/oem-jlpp-modal.entry.js +1 -1
  145. package/dist/esm/oem-jlzz-modal.entry.js +1 -1
  146. package/dist/esm/oem-mnct-modal.entry.js +1 -1
  147. package/dist/esm/oem-mnms-modal.entry.js +1 -1
  148. package/dist/esm/oem-qgqjl-modal.entry.js +3 -3
  149. package/dist/esm/pcm-agents.js +1 -1
  150. package/dist/esm/pcm-hr-chat-modal.entry.js +2 -2
  151. package/dist/esm/pcm-jlsx-modal.entry.js +3 -3
  152. package/dist/esm/{sentry-reporter-CAPKrssw.js → sentry-reporter-CQ8bX8AM.js} +3 -3
  153. package/dist/esm/{sentry-reporter-CAPKrssw.js.map → sentry-reporter-CQ8bX8AM.js.map} +1 -1
  154. package/dist/pcm-agents/index.esm.js +1 -1
  155. package/dist/pcm-agents/{p-ae9f3219.entry.js → p-07d0bfa5.entry.js} +2 -2
  156. package/dist/pcm-agents/{p-e908843d.entry.js → p-415d021b.entry.js} +2 -2
  157. package/dist/pcm-agents/{p-4a3091a0.entry.js → p-52b8396f.entry.js} +2 -2
  158. package/dist/pcm-agents/{p-713ee0b3.entry.js → p-85b37d21.entry.js} +2 -2
  159. package/dist/pcm-agents/{p-2acf8d44.entry.js → p-86c15766.entry.js} +2 -2
  160. package/dist/pcm-agents/{p-b45645c2.entry.js → p-900ade9f.entry.js} +2 -2
  161. package/dist/pcm-agents/{p-C1T6GEE8.js → p-BUe4kiCQ.js} +2 -2
  162. package/dist/pcm-agents/{p-C1T6GEE8.js.map → p-BUe4kiCQ.js.map} +1 -1
  163. package/dist/pcm-agents/p-CeRTfvY9.js.map +1 -1
  164. package/dist/pcm-agents/p-CnhOGURu.js +2 -0
  165. package/dist/pcm-agents/{p-DcmYnk0q.js.map → p-CnhOGURu.js.map} +1 -1
  166. package/dist/pcm-agents/{p-Cgydfo3f.js → p-DpK1mBu7.js} +2 -2
  167. package/dist/pcm-agents/{p-Cgydfo3f.js.map → p-DpK1mBu7.js.map} +1 -1
  168. package/dist/pcm-agents/{p-MWaXn7-C.js → p-DzZpAxqF.js} +2 -2
  169. package/dist/pcm-agents/{p-MWaXn7-C.js.map → p-DzZpAxqF.js.map} +1 -1
  170. package/dist/pcm-agents/{p-e18cbbc1.entry.js → p-a33ebff7.entry.js} +2 -2
  171. package/dist/pcm-agents/{p-081b9fcf.entry.js → p-be640465.entry.js} +2 -2
  172. package/dist/pcm-agents/{p-19e22dee.entry.js → p-c95e6896.entry.js} +2 -2
  173. package/dist/pcm-agents/{p-50af907f.entry.js → p-cd2844d8.entry.js} +2 -2
  174. package/dist/pcm-agents/{p-08b41c0c.entry.js → p-d25b1c70.entry.js} +2 -2
  175. package/dist/pcm-agents/p-f2445cbd.entry.js +8 -0
  176. package/dist/pcm-agents/p-f2445cbd.entry.js.map +1 -0
  177. package/dist/pcm-agents/pcm-agents.esm.js +1 -1
  178. package/dist/types/components/pcm-htws-modal/pcm-htws-modal.d.ts +5 -0
  179. package/dist/types/components/pcm-hyzj-modal/pcm-hyzj-modal.d.ts +5 -0
  180. package/dist/types/components/pcm-jd-modal/pcm-jd-modal.d.ts +5 -0
  181. package/dist/types/components/pcm-mnct-modal/pcm-mnct-modal.d.ts +5 -0
  182. package/dist/types/components/pcm-msbg-modal/pcm-msbg-modal.d.ts +5 -0
  183. package/dist/types/components/pcm-qgqjl-modal/pcm-qgqjl-modal.d.ts +5 -0
  184. package/dist/types/components/pcm-zygh-modal/pcm-zygh-modal.d.ts +5 -0
  185. package/dist/types/components/pcm-zygh-v2-modal/pcm-zygh-v2-modal.d.ts +5 -0
  186. package/dist/types/components.d.ts +64 -0
  187. package/package.json +1 -1
  188. package/readme.md +307 -307
  189. package/dist/cjs/markdown-D3_atg0b.js +0 -2564
  190. package/dist/components/p-B85MJLTf.js +0 -8
  191. package/dist/components/p-B85MJLTf.js.map +0 -1
  192. package/dist/components/p-CXalGxO1.js.map +0 -1
  193. package/dist/components/p-D483moFs.js +0 -2310
  194. package/dist/components/p-D483moFs.js.map +0 -1
  195. package/dist/components/p-DLLeEB9s.js.map +0 -1
  196. package/dist/components/p-DuXrU5Qi.js +0 -2559
  197. package/dist/components/p-DuXrU5Qi.js.map +0 -1
  198. package/dist/esm/markdown-DcmYnk0q.js +0 -2561
  199. package/dist/pcm-agents/p-4c6e5c43.entry.js +0 -8
  200. package/dist/pcm-agents/p-4c6e5c43.entry.js.map +0 -1
  201. package/dist/pcm-agents/p-DcmYnk0q.js +0 -2
  202. /package/dist/pcm-agents/{p-ae9f3219.entry.js.map → p-07d0bfa5.entry.js.map} +0 -0
  203. /package/dist/pcm-agents/{p-e908843d.entry.js.map → p-415d021b.entry.js.map} +0 -0
  204. /package/dist/pcm-agents/{p-4a3091a0.entry.js.map → p-52b8396f.entry.js.map} +0 -0
  205. /package/dist/pcm-agents/{p-713ee0b3.entry.js.map → p-85b37d21.entry.js.map} +0 -0
  206. /package/dist/pcm-agents/{p-2acf8d44.entry.js.map → p-86c15766.entry.js.map} +0 -0
  207. /package/dist/pcm-agents/{p-b45645c2.entry.js.map → p-900ade9f.entry.js.map} +0 -0
  208. /package/dist/pcm-agents/{p-e18cbbc1.entry.js.map → p-a33ebff7.entry.js.map} +0 -0
  209. /package/dist/pcm-agents/{p-081b9fcf.entry.js.map → p-be640465.entry.js.map} +0 -0
  210. /package/dist/pcm-agents/{p-19e22dee.entry.js.map → p-c95e6896.entry.js.map} +0 -0
  211. /package/dist/pcm-agents/{p-50af907f.entry.js.map → p-cd2844d8.entry.js.map} +0 -0
  212. /package/dist/pcm-agents/{p-08b41c0c.entry.js.map → p-d25b1c70.entry.js.map} +0 -0
  213. /package/dist/types/code/{agents-sdk → sdk}/packages/pcm-agents/.stencil/store/auth.store.d.ts +0 -0
  214. /package/dist/types/code/{agents-sdk → sdk}/packages/pcm-agents/.stencil/store/config.store.d.ts +0 -0
@@ -0,0 +1,2671 @@
1
+ function getDefaultExportFromCjs (x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3
+ }
4
+
5
+ /**
6
+ * marked v9.1.6 - a markdown parser
7
+ * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
8
+ * https://github.com/markedjs/marked
9
+ */
10
+
11
+ /**
12
+ * DO NOT EDIT THIS FILE
13
+ * The code in this file is generated from files in ./src/
14
+ */
15
+
16
+ /**
17
+ * Gets the original marked default options.
18
+ */
19
+ function _getDefaults() {
20
+ return {
21
+ async: false,
22
+ breaks: false,
23
+ extensions: null,
24
+ gfm: true,
25
+ hooks: null,
26
+ pedantic: false,
27
+ renderer: null,
28
+ silent: false,
29
+ tokenizer: null,
30
+ walkTokens: null
31
+ };
32
+ }
33
+ let _defaults = _getDefaults();
34
+ function changeDefaults(newDefaults) {
35
+ _defaults = newDefaults;
36
+ }
37
+
38
+ /**
39
+ * Helpers
40
+ */
41
+ const escapeTest = /[&<>"']/;
42
+ const escapeReplace = new RegExp(escapeTest.source, 'g');
43
+ const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
44
+ const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
45
+ const escapeReplacements = {
46
+ '&': '&amp;',
47
+ '<': '&lt;',
48
+ '>': '&gt;',
49
+ '"': '&quot;',
50
+ "'": '&#39;'
51
+ };
52
+ const getEscapeReplacement = (ch) => escapeReplacements[ch];
53
+ function escape(html, encode) {
54
+ if (encode) {
55
+ if (escapeTest.test(html)) {
56
+ return html.replace(escapeReplace, getEscapeReplacement);
57
+ }
58
+ }
59
+ else {
60
+ if (escapeTestNoEncode.test(html)) {
61
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
62
+ }
63
+ }
64
+ return html;
65
+ }
66
+ const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
67
+ function unescape(html) {
68
+ // explicitly match decimal, hex, and named HTML entities
69
+ return html.replace(unescapeTest, (_, n) => {
70
+ n = n.toLowerCase();
71
+ if (n === 'colon')
72
+ return ':';
73
+ if (n.charAt(0) === '#') {
74
+ return n.charAt(1) === 'x'
75
+ ? String.fromCharCode(parseInt(n.substring(2), 16))
76
+ : String.fromCharCode(+n.substring(1));
77
+ }
78
+ return '';
79
+ });
80
+ }
81
+ const caret = /(^|[^\[])\^/g;
82
+ function edit(regex, opt) {
83
+ regex = typeof regex === 'string' ? regex : regex.source;
84
+ opt = opt || '';
85
+ const obj = {
86
+ replace: (name, val) => {
87
+ val = typeof val === 'object' && 'source' in val ? val.source : val;
88
+ val = val.replace(caret, '$1');
89
+ regex = regex.replace(name, val);
90
+ return obj;
91
+ },
92
+ getRegex: () => {
93
+ return new RegExp(regex, opt);
94
+ }
95
+ };
96
+ return obj;
97
+ }
98
+ function cleanUrl(href) {
99
+ try {
100
+ href = encodeURI(href).replace(/%25/g, '%');
101
+ }
102
+ catch (e) {
103
+ return null;
104
+ }
105
+ return href;
106
+ }
107
+ const noopTest = { exec: () => null };
108
+ function splitCells(tableRow, count) {
109
+ // ensure that every cell-delimiting pipe has a space
110
+ // before it to distinguish it from an escaped pipe
111
+ const row = tableRow.replace(/\|/g, (match, offset, str) => {
112
+ let escaped = false;
113
+ let curr = offset;
114
+ while (--curr >= 0 && str[curr] === '\\')
115
+ escaped = !escaped;
116
+ if (escaped) {
117
+ // odd number of slashes means | is escaped
118
+ // so we leave it alone
119
+ return '|';
120
+ }
121
+ else {
122
+ // add space before unescaped |
123
+ return ' |';
124
+ }
125
+ }), cells = row.split(/ \|/);
126
+ let i = 0;
127
+ // First/last cell in a row cannot be empty if it has no leading/trailing pipe
128
+ if (!cells[0].trim()) {
129
+ cells.shift();
130
+ }
131
+ if (cells.length > 0 && !cells[cells.length - 1].trim()) {
132
+ cells.pop();
133
+ }
134
+ if (count) {
135
+ if (cells.length > count) {
136
+ cells.splice(count);
137
+ }
138
+ else {
139
+ while (cells.length < count)
140
+ cells.push('');
141
+ }
142
+ }
143
+ for (; i < cells.length; i++) {
144
+ // leading or trailing whitespace is ignored per the gfm spec
145
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
146
+ }
147
+ return cells;
148
+ }
149
+ /**
150
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
151
+ * /c*$/ is vulnerable to REDOS.
152
+ *
153
+ * @param str
154
+ * @param c
155
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
156
+ */
157
+ function rtrim(str, c, invert) {
158
+ const l = str.length;
159
+ if (l === 0) {
160
+ return '';
161
+ }
162
+ // Length of suffix matching the invert condition.
163
+ let suffLen = 0;
164
+ // Step left until we fail to match the invert condition.
165
+ while (suffLen < l) {
166
+ const currChar = str.charAt(l - suffLen - 1);
167
+ if (currChar === c && true) {
168
+ suffLen++;
169
+ }
170
+ else {
171
+ break;
172
+ }
173
+ }
174
+ return str.slice(0, l - suffLen);
175
+ }
176
+ function findClosingBracket(str, b) {
177
+ if (str.indexOf(b[1]) === -1) {
178
+ return -1;
179
+ }
180
+ let level = 0;
181
+ for (let i = 0; i < str.length; i++) {
182
+ if (str[i] === '\\') {
183
+ i++;
184
+ }
185
+ else if (str[i] === b[0]) {
186
+ level++;
187
+ }
188
+ else if (str[i] === b[1]) {
189
+ level--;
190
+ if (level < 0) {
191
+ return i;
192
+ }
193
+ }
194
+ }
195
+ return -1;
196
+ }
197
+
198
+ function outputLink(cap, link, raw, lexer) {
199
+ const href = link.href;
200
+ const title = link.title ? escape(link.title) : null;
201
+ const text = cap[1].replace(/\\([\[\]])/g, '$1');
202
+ if (cap[0].charAt(0) !== '!') {
203
+ lexer.state.inLink = true;
204
+ const token = {
205
+ type: 'link',
206
+ raw,
207
+ href,
208
+ title,
209
+ text,
210
+ tokens: lexer.inlineTokens(text)
211
+ };
212
+ lexer.state.inLink = false;
213
+ return token;
214
+ }
215
+ return {
216
+ type: 'image',
217
+ raw,
218
+ href,
219
+ title,
220
+ text: escape(text)
221
+ };
222
+ }
223
+ function indentCodeCompensation(raw, text) {
224
+ const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
225
+ if (matchIndentToCode === null) {
226
+ return text;
227
+ }
228
+ const indentToCode = matchIndentToCode[1];
229
+ return text
230
+ .split('\n')
231
+ .map(node => {
232
+ const matchIndentInNode = node.match(/^\s+/);
233
+ if (matchIndentInNode === null) {
234
+ return node;
235
+ }
236
+ const [indentInNode] = matchIndentInNode;
237
+ if (indentInNode.length >= indentToCode.length) {
238
+ return node.slice(indentToCode.length);
239
+ }
240
+ return node;
241
+ })
242
+ .join('\n');
243
+ }
244
+ /**
245
+ * Tokenizer
246
+ */
247
+ class _Tokenizer {
248
+ options;
249
+ // TODO: Fix this rules type
250
+ rules;
251
+ lexer;
252
+ constructor(options) {
253
+ this.options = options || _defaults;
254
+ }
255
+ space(src) {
256
+ const cap = this.rules.block.newline.exec(src);
257
+ if (cap && cap[0].length > 0) {
258
+ return {
259
+ type: 'space',
260
+ raw: cap[0]
261
+ };
262
+ }
263
+ }
264
+ code(src) {
265
+ const cap = this.rules.block.code.exec(src);
266
+ if (cap) {
267
+ const text = cap[0].replace(/^ {1,4}/gm, '');
268
+ return {
269
+ type: 'code',
270
+ raw: cap[0],
271
+ codeBlockStyle: 'indented',
272
+ text: !this.options.pedantic
273
+ ? rtrim(text, '\n')
274
+ : text
275
+ };
276
+ }
277
+ }
278
+ fences(src) {
279
+ const cap = this.rules.block.fences.exec(src);
280
+ if (cap) {
281
+ const raw = cap[0];
282
+ const text = indentCodeCompensation(raw, cap[3] || '');
283
+ return {
284
+ type: 'code',
285
+ raw,
286
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, '$1') : cap[2],
287
+ text
288
+ };
289
+ }
290
+ }
291
+ heading(src) {
292
+ const cap = this.rules.block.heading.exec(src);
293
+ if (cap) {
294
+ let text = cap[2].trim();
295
+ // remove trailing #s
296
+ if (/#$/.test(text)) {
297
+ const trimmed = rtrim(text, '#');
298
+ if (this.options.pedantic) {
299
+ text = trimmed.trim();
300
+ }
301
+ else if (!trimmed || / $/.test(trimmed)) {
302
+ // CommonMark requires space before trailing #s
303
+ text = trimmed.trim();
304
+ }
305
+ }
306
+ return {
307
+ type: 'heading',
308
+ raw: cap[0],
309
+ depth: cap[1].length,
310
+ text,
311
+ tokens: this.lexer.inline(text)
312
+ };
313
+ }
314
+ }
315
+ hr(src) {
316
+ const cap = this.rules.block.hr.exec(src);
317
+ if (cap) {
318
+ return {
319
+ type: 'hr',
320
+ raw: cap[0]
321
+ };
322
+ }
323
+ }
324
+ blockquote(src) {
325
+ const cap = this.rules.block.blockquote.exec(src);
326
+ if (cap) {
327
+ const text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ''), '\n');
328
+ const top = this.lexer.state.top;
329
+ this.lexer.state.top = true;
330
+ const tokens = this.lexer.blockTokens(text);
331
+ this.lexer.state.top = top;
332
+ return {
333
+ type: 'blockquote',
334
+ raw: cap[0],
335
+ tokens,
336
+ text
337
+ };
338
+ }
339
+ }
340
+ list(src) {
341
+ let cap = this.rules.block.list.exec(src);
342
+ if (cap) {
343
+ let bull = cap[1].trim();
344
+ const isordered = bull.length > 1;
345
+ const list = {
346
+ type: 'list',
347
+ raw: '',
348
+ ordered: isordered,
349
+ start: isordered ? +bull.slice(0, -1) : '',
350
+ loose: false,
351
+ items: []
352
+ };
353
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
354
+ if (this.options.pedantic) {
355
+ bull = isordered ? bull : '[*+-]';
356
+ }
357
+ // Get next list item
358
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
359
+ let raw = '';
360
+ let itemContents = '';
361
+ let endsWithBlankLine = false;
362
+ // Check if current bullet point can start a new List Item
363
+ while (src) {
364
+ let endEarly = false;
365
+ if (!(cap = itemRegex.exec(src))) {
366
+ break;
367
+ }
368
+ if (this.rules.block.hr.test(src)) { // End list if bullet was actually HR (possibly move into itemRegex?)
369
+ break;
370
+ }
371
+ raw = cap[0];
372
+ src = src.substring(raw.length);
373
+ let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
374
+ let nextLine = src.split('\n', 1)[0];
375
+ let indent = 0;
376
+ if (this.options.pedantic) {
377
+ indent = 2;
378
+ itemContents = line.trimStart();
379
+ }
380
+ else {
381
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
382
+ indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
383
+ itemContents = line.slice(indent);
384
+ indent += cap[1].length;
385
+ }
386
+ let blankLine = false;
387
+ if (!line && /^ *$/.test(nextLine)) { // Items begin with at most one blank line
388
+ raw += nextLine + '\n';
389
+ src = src.substring(nextLine.length + 1);
390
+ endEarly = true;
391
+ }
392
+ if (!endEarly) {
393
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
394
+ const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
395
+ const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
396
+ const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
397
+ // Check if following lines should be included in List Item
398
+ while (src) {
399
+ const rawLine = src.split('\n', 1)[0];
400
+ nextLine = rawLine;
401
+ // Re-align to follow commonmark nesting rules
402
+ if (this.options.pedantic) {
403
+ nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
404
+ }
405
+ // End list item if found code fences
406
+ if (fencesBeginRegex.test(nextLine)) {
407
+ break;
408
+ }
409
+ // End list item if found start of new heading
410
+ if (headingBeginRegex.test(nextLine)) {
411
+ break;
412
+ }
413
+ // End list item if found start of new bullet
414
+ if (nextBulletRegex.test(nextLine)) {
415
+ break;
416
+ }
417
+ // Horizontal rule found
418
+ if (hrRegex.test(src)) {
419
+ break;
420
+ }
421
+ if (nextLine.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
422
+ itemContents += '\n' + nextLine.slice(indent);
423
+ }
424
+ else {
425
+ // not enough indentation
426
+ if (blankLine) {
427
+ break;
428
+ }
429
+ // paragraph continuation unless last line was a different block level element
430
+ if (line.search(/[^ ]/) >= 4) { // indented code block
431
+ break;
432
+ }
433
+ if (fencesBeginRegex.test(line)) {
434
+ break;
435
+ }
436
+ if (headingBeginRegex.test(line)) {
437
+ break;
438
+ }
439
+ if (hrRegex.test(line)) {
440
+ break;
441
+ }
442
+ itemContents += '\n' + nextLine;
443
+ }
444
+ if (!blankLine && !nextLine.trim()) { // Check if current line is blank
445
+ blankLine = true;
446
+ }
447
+ raw += rawLine + '\n';
448
+ src = src.substring(rawLine.length + 1);
449
+ line = nextLine.slice(indent);
450
+ }
451
+ }
452
+ if (!list.loose) {
453
+ // If the previous item ended with a blank line, the list is loose
454
+ if (endsWithBlankLine) {
455
+ list.loose = true;
456
+ }
457
+ else if (/\n *\n *$/.test(raw)) {
458
+ endsWithBlankLine = true;
459
+ }
460
+ }
461
+ let istask = null;
462
+ let ischecked;
463
+ // Check for task list items
464
+ if (this.options.gfm) {
465
+ istask = /^\[[ xX]\] /.exec(itemContents);
466
+ if (istask) {
467
+ ischecked = istask[0] !== '[ ] ';
468
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
469
+ }
470
+ }
471
+ list.items.push({
472
+ type: 'list_item',
473
+ raw,
474
+ task: !!istask,
475
+ checked: ischecked,
476
+ loose: false,
477
+ text: itemContents,
478
+ tokens: []
479
+ });
480
+ list.raw += raw;
481
+ }
482
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
483
+ list.items[list.items.length - 1].raw = raw.trimEnd();
484
+ list.items[list.items.length - 1].text = itemContents.trimEnd();
485
+ list.raw = list.raw.trimEnd();
486
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
487
+ for (let i = 0; i < list.items.length; i++) {
488
+ this.lexer.state.top = false;
489
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
490
+ if (!list.loose) {
491
+ // Check if list should be loose
492
+ const spacers = list.items[i].tokens.filter(t => t.type === 'space');
493
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
494
+ list.loose = hasMultipleLineBreaks;
495
+ }
496
+ }
497
+ // Set all items to loose if list is loose
498
+ if (list.loose) {
499
+ for (let i = 0; i < list.items.length; i++) {
500
+ list.items[i].loose = true;
501
+ }
502
+ }
503
+ return list;
504
+ }
505
+ }
506
+ html(src) {
507
+ const cap = this.rules.block.html.exec(src);
508
+ if (cap) {
509
+ const token = {
510
+ type: 'html',
511
+ block: true,
512
+ raw: cap[0],
513
+ pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
514
+ text: cap[0]
515
+ };
516
+ return token;
517
+ }
518
+ }
519
+ def(src) {
520
+ const cap = this.rules.block.def.exec(src);
521
+ if (cap) {
522
+ const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
523
+ const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline._escapes, '$1') : '';
524
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline._escapes, '$1') : cap[3];
525
+ return {
526
+ type: 'def',
527
+ tag,
528
+ raw: cap[0],
529
+ href,
530
+ title
531
+ };
532
+ }
533
+ }
534
+ table(src) {
535
+ const cap = this.rules.block.table.exec(src);
536
+ if (cap) {
537
+ if (!/[:|]/.test(cap[2])) {
538
+ // delimiter row must have a pipe (|) or colon (:) otherwise it is a setext heading
539
+ return;
540
+ }
541
+ const item = {
542
+ type: 'table',
543
+ raw: cap[0],
544
+ header: splitCells(cap[1]).map(c => {
545
+ return { text: c, tokens: [] };
546
+ }),
547
+ align: cap[2].replace(/^\||\| *$/g, '').split('|'),
548
+ rows: cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : []
549
+ };
550
+ if (item.header.length === item.align.length) {
551
+ let l = item.align.length;
552
+ let i, j, k, row;
553
+ for (i = 0; i < l; i++) {
554
+ const align = item.align[i];
555
+ if (align) {
556
+ if (/^ *-+: *$/.test(align)) {
557
+ item.align[i] = 'right';
558
+ }
559
+ else if (/^ *:-+: *$/.test(align)) {
560
+ item.align[i] = 'center';
561
+ }
562
+ else if (/^ *:-+ *$/.test(align)) {
563
+ item.align[i] = 'left';
564
+ }
565
+ else {
566
+ item.align[i] = null;
567
+ }
568
+ }
569
+ }
570
+ l = item.rows.length;
571
+ for (i = 0; i < l; i++) {
572
+ item.rows[i] = splitCells(item.rows[i], item.header.length).map(c => {
573
+ return { text: c, tokens: [] };
574
+ });
575
+ }
576
+ // parse child tokens inside headers and cells
577
+ // header child tokens
578
+ l = item.header.length;
579
+ for (j = 0; j < l; j++) {
580
+ item.header[j].tokens = this.lexer.inline(item.header[j].text);
581
+ }
582
+ // cell child tokens
583
+ l = item.rows.length;
584
+ for (j = 0; j < l; j++) {
585
+ row = item.rows[j];
586
+ for (k = 0; k < row.length; k++) {
587
+ row[k].tokens = this.lexer.inline(row[k].text);
588
+ }
589
+ }
590
+ return item;
591
+ }
592
+ }
593
+ }
594
+ lheading(src) {
595
+ const cap = this.rules.block.lheading.exec(src);
596
+ if (cap) {
597
+ return {
598
+ type: 'heading',
599
+ raw: cap[0],
600
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
601
+ text: cap[1],
602
+ tokens: this.lexer.inline(cap[1])
603
+ };
604
+ }
605
+ }
606
+ paragraph(src) {
607
+ const cap = this.rules.block.paragraph.exec(src);
608
+ if (cap) {
609
+ const text = cap[1].charAt(cap[1].length - 1) === '\n'
610
+ ? cap[1].slice(0, -1)
611
+ : cap[1];
612
+ return {
613
+ type: 'paragraph',
614
+ raw: cap[0],
615
+ text,
616
+ tokens: this.lexer.inline(text)
617
+ };
618
+ }
619
+ }
620
+ text(src) {
621
+ const cap = this.rules.block.text.exec(src);
622
+ if (cap) {
623
+ return {
624
+ type: 'text',
625
+ raw: cap[0],
626
+ text: cap[0],
627
+ tokens: this.lexer.inline(cap[0])
628
+ };
629
+ }
630
+ }
631
+ escape(src) {
632
+ const cap = this.rules.inline.escape.exec(src);
633
+ if (cap) {
634
+ return {
635
+ type: 'escape',
636
+ raw: cap[0],
637
+ text: escape(cap[1])
638
+ };
639
+ }
640
+ }
641
+ tag(src) {
642
+ const cap = this.rules.inline.tag.exec(src);
643
+ if (cap) {
644
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
645
+ this.lexer.state.inLink = true;
646
+ }
647
+ else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
648
+ this.lexer.state.inLink = false;
649
+ }
650
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
651
+ this.lexer.state.inRawBlock = true;
652
+ }
653
+ else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
654
+ this.lexer.state.inRawBlock = false;
655
+ }
656
+ return {
657
+ type: 'html',
658
+ raw: cap[0],
659
+ inLink: this.lexer.state.inLink,
660
+ inRawBlock: this.lexer.state.inRawBlock,
661
+ block: false,
662
+ text: cap[0]
663
+ };
664
+ }
665
+ }
666
+ link(src) {
667
+ const cap = this.rules.inline.link.exec(src);
668
+ if (cap) {
669
+ const trimmedUrl = cap[2].trim();
670
+ if (!this.options.pedantic && /^</.test(trimmedUrl)) {
671
+ // commonmark requires matching angle brackets
672
+ if (!(/>$/.test(trimmedUrl))) {
673
+ return;
674
+ }
675
+ // ending angle bracket cannot be escaped
676
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
677
+ if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
678
+ return;
679
+ }
680
+ }
681
+ else {
682
+ // find closing parenthesis
683
+ const lastParenIndex = findClosingBracket(cap[2], '()');
684
+ if (lastParenIndex > -1) {
685
+ const start = cap[0].indexOf('!') === 0 ? 5 : 4;
686
+ const linkLen = start + cap[1].length + lastParenIndex;
687
+ cap[2] = cap[2].substring(0, lastParenIndex);
688
+ cap[0] = cap[0].substring(0, linkLen).trim();
689
+ cap[3] = '';
690
+ }
691
+ }
692
+ let href = cap[2];
693
+ let title = '';
694
+ if (this.options.pedantic) {
695
+ // split pedantic href and title
696
+ const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
697
+ if (link) {
698
+ href = link[1];
699
+ title = link[3];
700
+ }
701
+ }
702
+ else {
703
+ title = cap[3] ? cap[3].slice(1, -1) : '';
704
+ }
705
+ href = href.trim();
706
+ if (/^</.test(href)) {
707
+ if (this.options.pedantic && !(/>$/.test(trimmedUrl))) {
708
+ // pedantic allows starting angle bracket without ending angle bracket
709
+ href = href.slice(1);
710
+ }
711
+ else {
712
+ href = href.slice(1, -1);
713
+ }
714
+ }
715
+ return outputLink(cap, {
716
+ href: href ? href.replace(this.rules.inline._escapes, '$1') : href,
717
+ title: title ? title.replace(this.rules.inline._escapes, '$1') : title
718
+ }, cap[0], this.lexer);
719
+ }
720
+ }
721
+ reflink(src, links) {
722
+ let cap;
723
+ if ((cap = this.rules.inline.reflink.exec(src))
724
+ || (cap = this.rules.inline.nolink.exec(src))) {
725
+ let link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
726
+ link = links[link.toLowerCase()];
727
+ if (!link) {
728
+ const text = cap[0].charAt(0);
729
+ return {
730
+ type: 'text',
731
+ raw: text,
732
+ text
733
+ };
734
+ }
735
+ return outputLink(cap, link, cap[0], this.lexer);
736
+ }
737
+ }
738
+ emStrong(src, maskedSrc, prevChar = '') {
739
+ let match = this.rules.inline.emStrong.lDelim.exec(src);
740
+ if (!match)
741
+ return;
742
+ // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
743
+ if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
744
+ return;
745
+ const nextChar = match[1] || match[2] || '';
746
+ if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
747
+ // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
748
+ const lLength = [...match[0]].length - 1;
749
+ let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
750
+ const endReg = match[0][0] === '*' ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
751
+ endReg.lastIndex = 0;
752
+ // Clip maskedSrc to same section of string as src (move to lexer?)
753
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
754
+ while ((match = endReg.exec(maskedSrc)) != null) {
755
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
756
+ if (!rDelim)
757
+ continue; // skip single * in __abc*abc__
758
+ rLength = [...rDelim].length;
759
+ if (match[3] || match[4]) { // found another Left Delim
760
+ delimTotal += rLength;
761
+ continue;
762
+ }
763
+ else if (match[5] || match[6]) { // either Left or Right Delim
764
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
765
+ midDelimTotal += rLength;
766
+ continue; // CommonMark Emphasis Rules 9-10
767
+ }
768
+ }
769
+ delimTotal -= rLength;
770
+ if (delimTotal > 0)
771
+ continue; // Haven't found enough closing delimiters
772
+ // Remove extra characters. *a*** -> *a*
773
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
774
+ // char length can be >1 for unicode characters;
775
+ const lastCharLength = [...match[0]][0].length;
776
+ const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
777
+ // Create `em` if smallest delimiter has odd char count. *a***
778
+ if (Math.min(lLength, rLength) % 2) {
779
+ const text = raw.slice(1, -1);
780
+ return {
781
+ type: 'em',
782
+ raw,
783
+ text,
784
+ tokens: this.lexer.inlineTokens(text)
785
+ };
786
+ }
787
+ // Create 'strong' if smallest delimiter has even char count. **a***
788
+ const text = raw.slice(2, -2);
789
+ return {
790
+ type: 'strong',
791
+ raw,
792
+ text,
793
+ tokens: this.lexer.inlineTokens(text)
794
+ };
795
+ }
796
+ }
797
+ }
798
+ codespan(src) {
799
+ const cap = this.rules.inline.code.exec(src);
800
+ if (cap) {
801
+ let text = cap[2].replace(/\n/g, ' ');
802
+ const hasNonSpaceChars = /[^ ]/.test(text);
803
+ const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
804
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
805
+ text = text.substring(1, text.length - 1);
806
+ }
807
+ text = escape(text, true);
808
+ return {
809
+ type: 'codespan',
810
+ raw: cap[0],
811
+ text
812
+ };
813
+ }
814
+ }
815
+ br(src) {
816
+ const cap = this.rules.inline.br.exec(src);
817
+ if (cap) {
818
+ return {
819
+ type: 'br',
820
+ raw: cap[0]
821
+ };
822
+ }
823
+ }
824
+ del(src) {
825
+ const cap = this.rules.inline.del.exec(src);
826
+ if (cap) {
827
+ return {
828
+ type: 'del',
829
+ raw: cap[0],
830
+ text: cap[2],
831
+ tokens: this.lexer.inlineTokens(cap[2])
832
+ };
833
+ }
834
+ }
835
+ autolink(src) {
836
+ const cap = this.rules.inline.autolink.exec(src);
837
+ if (cap) {
838
+ let text, href;
839
+ if (cap[2] === '@') {
840
+ text = escape(cap[1]);
841
+ href = 'mailto:' + text;
842
+ }
843
+ else {
844
+ text = escape(cap[1]);
845
+ href = text;
846
+ }
847
+ return {
848
+ type: 'link',
849
+ raw: cap[0],
850
+ text,
851
+ href,
852
+ tokens: [
853
+ {
854
+ type: 'text',
855
+ raw: text,
856
+ text
857
+ }
858
+ ]
859
+ };
860
+ }
861
+ }
862
+ url(src) {
863
+ let cap;
864
+ if (cap = this.rules.inline.url.exec(src)) {
865
+ let text, href;
866
+ if (cap[2] === '@') {
867
+ text = escape(cap[0]);
868
+ href = 'mailto:' + text;
869
+ }
870
+ else {
871
+ // do extended autolink path validation
872
+ let prevCapZero;
873
+ do {
874
+ prevCapZero = cap[0];
875
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])[0];
876
+ } while (prevCapZero !== cap[0]);
877
+ text = escape(cap[0]);
878
+ if (cap[1] === 'www.') {
879
+ href = 'http://' + cap[0];
880
+ }
881
+ else {
882
+ href = cap[0];
883
+ }
884
+ }
885
+ return {
886
+ type: 'link',
887
+ raw: cap[0],
888
+ text,
889
+ href,
890
+ tokens: [
891
+ {
892
+ type: 'text',
893
+ raw: text,
894
+ text
895
+ }
896
+ ]
897
+ };
898
+ }
899
+ }
900
+ inlineText(src) {
901
+ const cap = this.rules.inline.text.exec(src);
902
+ if (cap) {
903
+ let text;
904
+ if (this.lexer.state.inRawBlock) {
905
+ text = cap[0];
906
+ }
907
+ else {
908
+ text = escape(cap[0]);
909
+ }
910
+ return {
911
+ type: 'text',
912
+ raw: cap[0],
913
+ text
914
+ };
915
+ }
916
+ }
917
+ }
918
+
919
+ /**
920
+ * Block-Level Grammar
921
+ */
922
+ // Not all rules are defined in the object literal
923
+ // @ts-expect-error
924
+ const block = {
925
+ newline: /^(?: *(?:\n|$))+/,
926
+ code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
927
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
928
+ hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
929
+ heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
930
+ blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
931
+ list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
932
+ html: '^ {0,3}(?:' // optional indentation
933
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
934
+ + '|comment[^\\n]*(\\n+|$)' // (2)
935
+ + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
936
+ + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
937
+ + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
938
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
939
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
940
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
941
+ + ')',
942
+ def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
943
+ table: noopTest,
944
+ lheading: /^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
945
+ // regex template, placeholders will be replaced according to different paragraph
946
+ // interruption rules of commonmark and the original markdown spec:
947
+ _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
948
+ text: /^[^\n]+/
949
+ };
950
+ block._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
951
+ block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
952
+ block.def = edit(block.def)
953
+ .replace('label', block._label)
954
+ .replace('title', block._title)
955
+ .getRegex();
956
+ block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
957
+ block.listItemStart = edit(/^( *)(bull) */)
958
+ .replace('bull', block.bullet)
959
+ .getRegex();
960
+ block.list = edit(block.list)
961
+ .replace(/bull/g, block.bullet)
962
+ .replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')
963
+ .replace('def', '\\n+(?=' + block.def.source + ')')
964
+ .getRegex();
965
+ block._tag = 'address|article|aside|base|basefont|blockquote|body|caption'
966
+ + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
967
+ + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
968
+ + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
969
+ + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr'
970
+ + '|track|ul';
971
+ block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
972
+ block.html = edit(block.html, 'i')
973
+ .replace('comment', block._comment)
974
+ .replace('tag', block._tag)
975
+ .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
976
+ .getRegex();
977
+ block.lheading = edit(block.lheading)
978
+ .replace(/bull/g, block.bullet) // lists can interrupt
979
+ .getRegex();
980
+ block.paragraph = edit(block._paragraph)
981
+ .replace('hr', block.hr)
982
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
983
+ .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
984
+ .replace('|table', '')
985
+ .replace('blockquote', ' {0,3}>')
986
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
987
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
988
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
989
+ .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
990
+ .getRegex();
991
+ block.blockquote = edit(block.blockquote)
992
+ .replace('paragraph', block.paragraph)
993
+ .getRegex();
994
+ /**
995
+ * Normal Block Grammar
996
+ */
997
+ block.normal = { ...block };
998
+ /**
999
+ * GFM Block Grammar
1000
+ */
1001
+ block.gfm = {
1002
+ ...block.normal,
1003
+ table: '^ *([^\\n ].*)\\n' // Header
1004
+ + ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
1005
+ + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
1006
+ };
1007
+ block.gfm.table = edit(block.gfm.table)
1008
+ .replace('hr', block.hr)
1009
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1010
+ .replace('blockquote', ' {0,3}>')
1011
+ .replace('code', ' {4}[^\\n]')
1012
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1013
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1014
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1015
+ .replace('tag', block._tag) // tables can be interrupted by type (6) html blocks
1016
+ .getRegex();
1017
+ block.gfm.paragraph = edit(block._paragraph)
1018
+ .replace('hr', block.hr)
1019
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1020
+ .replace('|lheading', '') // setex headings don't interrupt commonmark paragraphs
1021
+ .replace('table', block.gfm.table) // interrupt paragraphs with table
1022
+ .replace('blockquote', ' {0,3}>')
1023
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1024
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1025
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1026
+ .replace('tag', block._tag) // pars can be interrupted by type (6) html blocks
1027
+ .getRegex();
1028
+ /**
1029
+ * Pedantic grammar (original John Gruber's loose markdown specification)
1030
+ */
1031
+ block.pedantic = {
1032
+ ...block.normal,
1033
+ html: edit('^ *(?:comment *(?:\\n|\\s*$)'
1034
+ + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1035
+ + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
1036
+ .replace('comment', block._comment)
1037
+ .replace(/tag/g, '(?!(?:'
1038
+ + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
1039
+ + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
1040
+ + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
1041
+ .getRegex(),
1042
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1043
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
1044
+ fences: noopTest,
1045
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1046
+ paragraph: edit(block.normal._paragraph)
1047
+ .replace('hr', block.hr)
1048
+ .replace('heading', ' *#{1,6} *[^\n]')
1049
+ .replace('lheading', block.lheading)
1050
+ .replace('blockquote', ' {0,3}>')
1051
+ .replace('|fences', '')
1052
+ .replace('|list', '')
1053
+ .replace('|html', '')
1054
+ .getRegex()
1055
+ };
1056
+ /**
1057
+ * Inline-Level Grammar
1058
+ */
1059
+ // Not all rules are defined in the object literal
1060
+ // @ts-expect-error
1061
+ const inline = {
1062
+ escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
1063
+ autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
1064
+ url: noopTest,
1065
+ tag: '^comment'
1066
+ + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1067
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1068
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1069
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1070
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>',
1071
+ link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
1072
+ reflink: /^!?\[(label)\]\[(ref)\]/,
1073
+ nolink: /^!?\[(ref)\](?:\[\])?/,
1074
+ reflinkSearch: 'reflink|nolink(?!\\()',
1075
+ emStrong: {
1076
+ lDelim: /^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,
1077
+ // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1078
+ // | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a
1079
+ rDelimAst: /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/,
1080
+ rDelimUnd: /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/ // ^- Not allowed for _
1081
+ },
1082
+ code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1083
+ br: /^( {2,}|\\)\n(?!\s*$)/,
1084
+ del: noopTest,
1085
+ text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
1086
+ punctuation: /^((?![*_])[\spunctuation])/
1087
+ };
1088
+ // list of unicode punctuation marks, plus any missing characters from CommonMark spec
1089
+ inline._punctuation = '\\p{P}$+<=>`^|~';
1090
+ inline.punctuation = edit(inline.punctuation, 'u').replace(/punctuation/g, inline._punctuation).getRegex();
1091
+ // sequences em should skip over [title](link), `code`, <html>
1092
+ inline.blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
1093
+ inline.anyPunctuation = /\\[punct]/g;
1094
+ inline._escapes = /\\([punct])/g;
1095
+ inline._comment = edit(block._comment).replace('(?:-->|$)', '-->').getRegex();
1096
+ inline.emStrong.lDelim = edit(inline.emStrong.lDelim, 'u')
1097
+ .replace(/punct/g, inline._punctuation)
1098
+ .getRegex();
1099
+ inline.emStrong.rDelimAst = edit(inline.emStrong.rDelimAst, 'gu')
1100
+ .replace(/punct/g, inline._punctuation)
1101
+ .getRegex();
1102
+ inline.emStrong.rDelimUnd = edit(inline.emStrong.rDelimUnd, 'gu')
1103
+ .replace(/punct/g, inline._punctuation)
1104
+ .getRegex();
1105
+ inline.anyPunctuation = edit(inline.anyPunctuation, 'gu')
1106
+ .replace(/punct/g, inline._punctuation)
1107
+ .getRegex();
1108
+ inline._escapes = edit(inline._escapes, 'gu')
1109
+ .replace(/punct/g, inline._punctuation)
1110
+ .getRegex();
1111
+ inline._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
1112
+ inline._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])?)+(?![-_])/;
1113
+ inline.autolink = edit(inline.autolink)
1114
+ .replace('scheme', inline._scheme)
1115
+ .replace('email', inline._email)
1116
+ .getRegex();
1117
+ inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
1118
+ inline.tag = edit(inline.tag)
1119
+ .replace('comment', inline._comment)
1120
+ .replace('attribute', inline._attribute)
1121
+ .getRegex();
1122
+ inline._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1123
+ inline._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
1124
+ inline._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
1125
+ inline.link = edit(inline.link)
1126
+ .replace('label', inline._label)
1127
+ .replace('href', inline._href)
1128
+ .replace('title', inline._title)
1129
+ .getRegex();
1130
+ inline.reflink = edit(inline.reflink)
1131
+ .replace('label', inline._label)
1132
+ .replace('ref', block._label)
1133
+ .getRegex();
1134
+ inline.nolink = edit(inline.nolink)
1135
+ .replace('ref', block._label)
1136
+ .getRegex();
1137
+ inline.reflinkSearch = edit(inline.reflinkSearch, 'g')
1138
+ .replace('reflink', inline.reflink)
1139
+ .replace('nolink', inline.nolink)
1140
+ .getRegex();
1141
+ /**
1142
+ * Normal Inline Grammar
1143
+ */
1144
+ inline.normal = { ...inline };
1145
+ /**
1146
+ * Pedantic Inline Grammar
1147
+ */
1148
+ inline.pedantic = {
1149
+ ...inline.normal,
1150
+ strong: {
1151
+ start: /^__|\*\*/,
1152
+ middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
1153
+ endAst: /\*\*(?!\*)/g,
1154
+ endUnd: /__(?!_)/g
1155
+ },
1156
+ em: {
1157
+ start: /^_|\*/,
1158
+ middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
1159
+ endAst: /\*(?!\*)/g,
1160
+ endUnd: /_(?!_)/g
1161
+ },
1162
+ link: edit(/^!?\[(label)\]\((.*?)\)/)
1163
+ .replace('label', inline._label)
1164
+ .getRegex(),
1165
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1166
+ .replace('label', inline._label)
1167
+ .getRegex()
1168
+ };
1169
+ /**
1170
+ * GFM Inline Grammar
1171
+ */
1172
+ inline.gfm = {
1173
+ ...inline.normal,
1174
+ escape: edit(inline.escape).replace('])', '~|])').getRegex(),
1175
+ _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1176
+ url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
1177
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1178
+ del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
1179
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1180
+ };
1181
+ inline.gfm.url = edit(inline.gfm.url, 'i')
1182
+ .replace('email', inline.gfm._extended_email)
1183
+ .getRegex();
1184
+ /**
1185
+ * GFM + Line Breaks Inline Grammar
1186
+ */
1187
+ inline.breaks = {
1188
+ ...inline.gfm,
1189
+ br: edit(inline.br).replace('{2,}', '*').getRegex(),
1190
+ text: edit(inline.gfm.text)
1191
+ .replace('\\b_', '\\b_| {2,}\\n')
1192
+ .replace(/\{2,\}/g, '*')
1193
+ .getRegex()
1194
+ };
1195
+
1196
+ /**
1197
+ * Block Lexer
1198
+ */
1199
+ class _Lexer {
1200
+ tokens;
1201
+ options;
1202
+ state;
1203
+ tokenizer;
1204
+ inlineQueue;
1205
+ constructor(options) {
1206
+ // TokenList cannot be created in one go
1207
+ // @ts-expect-error
1208
+ this.tokens = [];
1209
+ this.tokens.links = Object.create(null);
1210
+ this.options = options || _defaults;
1211
+ this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
1212
+ this.tokenizer = this.options.tokenizer;
1213
+ this.tokenizer.options = this.options;
1214
+ this.tokenizer.lexer = this;
1215
+ this.inlineQueue = [];
1216
+ this.state = {
1217
+ inLink: false,
1218
+ inRawBlock: false,
1219
+ top: true
1220
+ };
1221
+ const rules = {
1222
+ block: block.normal,
1223
+ inline: inline.normal
1224
+ };
1225
+ if (this.options.pedantic) {
1226
+ rules.block = block.pedantic;
1227
+ rules.inline = inline.pedantic;
1228
+ }
1229
+ else if (this.options.gfm) {
1230
+ rules.block = block.gfm;
1231
+ if (this.options.breaks) {
1232
+ rules.inline = inline.breaks;
1233
+ }
1234
+ else {
1235
+ rules.inline = inline.gfm;
1236
+ }
1237
+ }
1238
+ this.tokenizer.rules = rules;
1239
+ }
1240
+ /**
1241
+ * Expose Rules
1242
+ */
1243
+ static get rules() {
1244
+ return {
1245
+ block,
1246
+ inline
1247
+ };
1248
+ }
1249
+ /**
1250
+ * Static Lex Method
1251
+ */
1252
+ static lex(src, options) {
1253
+ const lexer = new _Lexer(options);
1254
+ return lexer.lex(src);
1255
+ }
1256
+ /**
1257
+ * Static Lex Inline Method
1258
+ */
1259
+ static lexInline(src, options) {
1260
+ const lexer = new _Lexer(options);
1261
+ return lexer.inlineTokens(src);
1262
+ }
1263
+ /**
1264
+ * Preprocessing
1265
+ */
1266
+ lex(src) {
1267
+ src = src
1268
+ .replace(/\r\n|\r/g, '\n');
1269
+ this.blockTokens(src, this.tokens);
1270
+ let next;
1271
+ while (next = this.inlineQueue.shift()) {
1272
+ this.inlineTokens(next.src, next.tokens);
1273
+ }
1274
+ return this.tokens;
1275
+ }
1276
+ blockTokens(src, tokens = []) {
1277
+ if (this.options.pedantic) {
1278
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1279
+ }
1280
+ else {
1281
+ src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
1282
+ return leading + ' '.repeat(tabs.length);
1283
+ });
1284
+ }
1285
+ let token;
1286
+ let lastToken;
1287
+ let cutSrc;
1288
+ let lastParagraphClipped;
1289
+ while (src) {
1290
+ if (this.options.extensions
1291
+ && this.options.extensions.block
1292
+ && this.options.extensions.block.some((extTokenizer) => {
1293
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1294
+ src = src.substring(token.raw.length);
1295
+ tokens.push(token);
1296
+ return true;
1297
+ }
1298
+ return false;
1299
+ })) {
1300
+ continue;
1301
+ }
1302
+ // newline
1303
+ if (token = this.tokenizer.space(src)) {
1304
+ src = src.substring(token.raw.length);
1305
+ if (token.raw.length === 1 && tokens.length > 0) {
1306
+ // if there's a single \n as a spacer, it's terminating the last line,
1307
+ // so move it there so that we don't get unnecessary paragraph tags
1308
+ tokens[tokens.length - 1].raw += '\n';
1309
+ }
1310
+ else {
1311
+ tokens.push(token);
1312
+ }
1313
+ continue;
1314
+ }
1315
+ // code
1316
+ if (token = this.tokenizer.code(src)) {
1317
+ src = src.substring(token.raw.length);
1318
+ lastToken = tokens[tokens.length - 1];
1319
+ // An indented code block cannot interrupt a paragraph.
1320
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1321
+ lastToken.raw += '\n' + token.raw;
1322
+ lastToken.text += '\n' + token.text;
1323
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1324
+ }
1325
+ else {
1326
+ tokens.push(token);
1327
+ }
1328
+ continue;
1329
+ }
1330
+ // fences
1331
+ if (token = this.tokenizer.fences(src)) {
1332
+ src = src.substring(token.raw.length);
1333
+ tokens.push(token);
1334
+ continue;
1335
+ }
1336
+ // heading
1337
+ if (token = this.tokenizer.heading(src)) {
1338
+ src = src.substring(token.raw.length);
1339
+ tokens.push(token);
1340
+ continue;
1341
+ }
1342
+ // hr
1343
+ if (token = this.tokenizer.hr(src)) {
1344
+ src = src.substring(token.raw.length);
1345
+ tokens.push(token);
1346
+ continue;
1347
+ }
1348
+ // blockquote
1349
+ if (token = this.tokenizer.blockquote(src)) {
1350
+ src = src.substring(token.raw.length);
1351
+ tokens.push(token);
1352
+ continue;
1353
+ }
1354
+ // list
1355
+ if (token = this.tokenizer.list(src)) {
1356
+ src = src.substring(token.raw.length);
1357
+ tokens.push(token);
1358
+ continue;
1359
+ }
1360
+ // html
1361
+ if (token = this.tokenizer.html(src)) {
1362
+ src = src.substring(token.raw.length);
1363
+ tokens.push(token);
1364
+ continue;
1365
+ }
1366
+ // def
1367
+ if (token = this.tokenizer.def(src)) {
1368
+ src = src.substring(token.raw.length);
1369
+ lastToken = tokens[tokens.length - 1];
1370
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1371
+ lastToken.raw += '\n' + token.raw;
1372
+ lastToken.text += '\n' + token.raw;
1373
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1374
+ }
1375
+ else if (!this.tokens.links[token.tag]) {
1376
+ this.tokens.links[token.tag] = {
1377
+ href: token.href,
1378
+ title: token.title
1379
+ };
1380
+ }
1381
+ continue;
1382
+ }
1383
+ // table (gfm)
1384
+ if (token = this.tokenizer.table(src)) {
1385
+ src = src.substring(token.raw.length);
1386
+ tokens.push(token);
1387
+ continue;
1388
+ }
1389
+ // lheading
1390
+ if (token = this.tokenizer.lheading(src)) {
1391
+ src = src.substring(token.raw.length);
1392
+ tokens.push(token);
1393
+ continue;
1394
+ }
1395
+ // top-level paragraph
1396
+ // prevent paragraph consuming extensions by clipping 'src' to extension start
1397
+ cutSrc = src;
1398
+ if (this.options.extensions && this.options.extensions.startBlock) {
1399
+ let startIndex = Infinity;
1400
+ const tempSrc = src.slice(1);
1401
+ let tempStart;
1402
+ this.options.extensions.startBlock.forEach((getStartIndex) => {
1403
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1404
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1405
+ startIndex = Math.min(startIndex, tempStart);
1406
+ }
1407
+ });
1408
+ if (startIndex < Infinity && startIndex >= 0) {
1409
+ cutSrc = src.substring(0, startIndex + 1);
1410
+ }
1411
+ }
1412
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1413
+ lastToken = tokens[tokens.length - 1];
1414
+ if (lastParagraphClipped && lastToken.type === 'paragraph') {
1415
+ lastToken.raw += '\n' + token.raw;
1416
+ lastToken.text += '\n' + token.text;
1417
+ this.inlineQueue.pop();
1418
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1419
+ }
1420
+ else {
1421
+ tokens.push(token);
1422
+ }
1423
+ lastParagraphClipped = (cutSrc.length !== src.length);
1424
+ src = src.substring(token.raw.length);
1425
+ continue;
1426
+ }
1427
+ // text
1428
+ if (token = this.tokenizer.text(src)) {
1429
+ src = src.substring(token.raw.length);
1430
+ lastToken = tokens[tokens.length - 1];
1431
+ if (lastToken && lastToken.type === 'text') {
1432
+ lastToken.raw += '\n' + token.raw;
1433
+ lastToken.text += '\n' + token.text;
1434
+ this.inlineQueue.pop();
1435
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1436
+ }
1437
+ else {
1438
+ tokens.push(token);
1439
+ }
1440
+ continue;
1441
+ }
1442
+ if (src) {
1443
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1444
+ if (this.options.silent) {
1445
+ console.error(errMsg);
1446
+ break;
1447
+ }
1448
+ else {
1449
+ throw new Error(errMsg);
1450
+ }
1451
+ }
1452
+ }
1453
+ this.state.top = true;
1454
+ return tokens;
1455
+ }
1456
+ inline(src, tokens = []) {
1457
+ this.inlineQueue.push({ src, tokens });
1458
+ return tokens;
1459
+ }
1460
+ /**
1461
+ * Lexing/Compiling
1462
+ */
1463
+ inlineTokens(src, tokens = []) {
1464
+ let token, lastToken, cutSrc;
1465
+ // String with links masked to avoid interference with em and strong
1466
+ let maskedSrc = src;
1467
+ let match;
1468
+ let keepPrevChar, prevChar;
1469
+ // Mask out reflinks
1470
+ if (this.tokens.links) {
1471
+ const links = Object.keys(this.tokens.links);
1472
+ if (links.length > 0) {
1473
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1474
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1475
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1476
+ }
1477
+ }
1478
+ }
1479
+ }
1480
+ // Mask out other blocks
1481
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1482
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1483
+ }
1484
+ // Mask out escaped characters
1485
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1486
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1487
+ }
1488
+ while (src) {
1489
+ if (!keepPrevChar) {
1490
+ prevChar = '';
1491
+ }
1492
+ keepPrevChar = false;
1493
+ // extensions
1494
+ if (this.options.extensions
1495
+ && this.options.extensions.inline
1496
+ && this.options.extensions.inline.some((extTokenizer) => {
1497
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1498
+ src = src.substring(token.raw.length);
1499
+ tokens.push(token);
1500
+ return true;
1501
+ }
1502
+ return false;
1503
+ })) {
1504
+ continue;
1505
+ }
1506
+ // escape
1507
+ if (token = this.tokenizer.escape(src)) {
1508
+ src = src.substring(token.raw.length);
1509
+ tokens.push(token);
1510
+ continue;
1511
+ }
1512
+ // tag
1513
+ if (token = this.tokenizer.tag(src)) {
1514
+ src = src.substring(token.raw.length);
1515
+ lastToken = tokens[tokens.length - 1];
1516
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1517
+ lastToken.raw += token.raw;
1518
+ lastToken.text += token.text;
1519
+ }
1520
+ else {
1521
+ tokens.push(token);
1522
+ }
1523
+ continue;
1524
+ }
1525
+ // link
1526
+ if (token = this.tokenizer.link(src)) {
1527
+ src = src.substring(token.raw.length);
1528
+ tokens.push(token);
1529
+ continue;
1530
+ }
1531
+ // reflink, nolink
1532
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1533
+ src = src.substring(token.raw.length);
1534
+ lastToken = tokens[tokens.length - 1];
1535
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1536
+ lastToken.raw += token.raw;
1537
+ lastToken.text += token.text;
1538
+ }
1539
+ else {
1540
+ tokens.push(token);
1541
+ }
1542
+ continue;
1543
+ }
1544
+ // em & strong
1545
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1546
+ src = src.substring(token.raw.length);
1547
+ tokens.push(token);
1548
+ continue;
1549
+ }
1550
+ // code
1551
+ if (token = this.tokenizer.codespan(src)) {
1552
+ src = src.substring(token.raw.length);
1553
+ tokens.push(token);
1554
+ continue;
1555
+ }
1556
+ // br
1557
+ if (token = this.tokenizer.br(src)) {
1558
+ src = src.substring(token.raw.length);
1559
+ tokens.push(token);
1560
+ continue;
1561
+ }
1562
+ // del (gfm)
1563
+ if (token = this.tokenizer.del(src)) {
1564
+ src = src.substring(token.raw.length);
1565
+ tokens.push(token);
1566
+ continue;
1567
+ }
1568
+ // autolink
1569
+ if (token = this.tokenizer.autolink(src)) {
1570
+ src = src.substring(token.raw.length);
1571
+ tokens.push(token);
1572
+ continue;
1573
+ }
1574
+ // url (gfm)
1575
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
1576
+ src = src.substring(token.raw.length);
1577
+ tokens.push(token);
1578
+ continue;
1579
+ }
1580
+ // text
1581
+ // prevent inlineText consuming extensions by clipping 'src' to extension start
1582
+ cutSrc = src;
1583
+ if (this.options.extensions && this.options.extensions.startInline) {
1584
+ let startIndex = Infinity;
1585
+ const tempSrc = src.slice(1);
1586
+ let tempStart;
1587
+ this.options.extensions.startInline.forEach((getStartIndex) => {
1588
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1589
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1590
+ startIndex = Math.min(startIndex, tempStart);
1591
+ }
1592
+ });
1593
+ if (startIndex < Infinity && startIndex >= 0) {
1594
+ cutSrc = src.substring(0, startIndex + 1);
1595
+ }
1596
+ }
1597
+ if (token = this.tokenizer.inlineText(cutSrc)) {
1598
+ src = src.substring(token.raw.length);
1599
+ if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1600
+ prevChar = token.raw.slice(-1);
1601
+ }
1602
+ keepPrevChar = true;
1603
+ lastToken = tokens[tokens.length - 1];
1604
+ if (lastToken && lastToken.type === 'text') {
1605
+ lastToken.raw += token.raw;
1606
+ lastToken.text += token.text;
1607
+ }
1608
+ else {
1609
+ tokens.push(token);
1610
+ }
1611
+ continue;
1612
+ }
1613
+ if (src) {
1614
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1615
+ if (this.options.silent) {
1616
+ console.error(errMsg);
1617
+ break;
1618
+ }
1619
+ else {
1620
+ throw new Error(errMsg);
1621
+ }
1622
+ }
1623
+ }
1624
+ return tokens;
1625
+ }
1626
+ }
1627
+
1628
+ /**
1629
+ * Renderer
1630
+ */
1631
+ class _Renderer {
1632
+ options;
1633
+ constructor(options) {
1634
+ this.options = options || _defaults;
1635
+ }
1636
+ code(code, infostring, escaped) {
1637
+ const lang = (infostring || '').match(/^\S*/)?.[0];
1638
+ code = code.replace(/\n$/, '') + '\n';
1639
+ if (!lang) {
1640
+ return '<pre><code>'
1641
+ + (escaped ? code : escape(code, true))
1642
+ + '</code></pre>\n';
1643
+ }
1644
+ return '<pre><code class="language-'
1645
+ + escape(lang)
1646
+ + '">'
1647
+ + (escaped ? code : escape(code, true))
1648
+ + '</code></pre>\n';
1649
+ }
1650
+ blockquote(quote) {
1651
+ return `<blockquote>\n${quote}</blockquote>\n`;
1652
+ }
1653
+ html(html, block) {
1654
+ return html;
1655
+ }
1656
+ heading(text, level, raw) {
1657
+ // ignore IDs
1658
+ return `<h${level}>${text}</h${level}>\n`;
1659
+ }
1660
+ hr() {
1661
+ return '<hr>\n';
1662
+ }
1663
+ list(body, ordered, start) {
1664
+ const type = ordered ? 'ol' : 'ul';
1665
+ const startatt = (ordered && start !== 1) ? (' start="' + start + '"') : '';
1666
+ return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1667
+ }
1668
+ listitem(text, task, checked) {
1669
+ return `<li>${text}</li>\n`;
1670
+ }
1671
+ checkbox(checked) {
1672
+ return '<input '
1673
+ + (checked ? 'checked="" ' : '')
1674
+ + 'disabled="" type="checkbox">';
1675
+ }
1676
+ paragraph(text) {
1677
+ return `<p>${text}</p>\n`;
1678
+ }
1679
+ table(header, body) {
1680
+ if (body)
1681
+ body = `<tbody>${body}</tbody>`;
1682
+ return '<table>\n'
1683
+ + '<thead>\n'
1684
+ + header
1685
+ + '</thead>\n'
1686
+ + body
1687
+ + '</table>\n';
1688
+ }
1689
+ tablerow(content) {
1690
+ return `<tr>\n${content}</tr>\n`;
1691
+ }
1692
+ tablecell(content, flags) {
1693
+ const type = flags.header ? 'th' : 'td';
1694
+ const tag = flags.align
1695
+ ? `<${type} align="${flags.align}">`
1696
+ : `<${type}>`;
1697
+ return tag + content + `</${type}>\n`;
1698
+ }
1699
+ /**
1700
+ * span level renderer
1701
+ */
1702
+ strong(text) {
1703
+ return `<strong>${text}</strong>`;
1704
+ }
1705
+ em(text) {
1706
+ return `<em>${text}</em>`;
1707
+ }
1708
+ codespan(text) {
1709
+ return `<code>${text}</code>`;
1710
+ }
1711
+ br() {
1712
+ return '<br>';
1713
+ }
1714
+ del(text) {
1715
+ return `<del>${text}</del>`;
1716
+ }
1717
+ link(href, title, text) {
1718
+ const cleanHref = cleanUrl(href);
1719
+ if (cleanHref === null) {
1720
+ return text;
1721
+ }
1722
+ href = cleanHref;
1723
+ let out = '<a href="' + href + '"';
1724
+ if (title) {
1725
+ out += ' title="' + title + '"';
1726
+ }
1727
+ out += '>' + text + '</a>';
1728
+ return out;
1729
+ }
1730
+ image(href, title, text) {
1731
+ const cleanHref = cleanUrl(href);
1732
+ if (cleanHref === null) {
1733
+ return text;
1734
+ }
1735
+ href = cleanHref;
1736
+ let out = `<img src="${href}" alt="${text}"`;
1737
+ if (title) {
1738
+ out += ` title="${title}"`;
1739
+ }
1740
+ out += '>';
1741
+ return out;
1742
+ }
1743
+ text(text) {
1744
+ return text;
1745
+ }
1746
+ }
1747
+
1748
+ /**
1749
+ * TextRenderer
1750
+ * returns only the textual part of the token
1751
+ */
1752
+ class _TextRenderer {
1753
+ // no need for block level renderers
1754
+ strong(text) {
1755
+ return text;
1756
+ }
1757
+ em(text) {
1758
+ return text;
1759
+ }
1760
+ codespan(text) {
1761
+ return text;
1762
+ }
1763
+ del(text) {
1764
+ return text;
1765
+ }
1766
+ html(text) {
1767
+ return text;
1768
+ }
1769
+ text(text) {
1770
+ return text;
1771
+ }
1772
+ link(href, title, text) {
1773
+ return '' + text;
1774
+ }
1775
+ image(href, title, text) {
1776
+ return '' + text;
1777
+ }
1778
+ br() {
1779
+ return '';
1780
+ }
1781
+ }
1782
+
1783
+ /**
1784
+ * Parsing & Compiling
1785
+ */
1786
+ class _Parser {
1787
+ options;
1788
+ renderer;
1789
+ textRenderer;
1790
+ constructor(options) {
1791
+ this.options = options || _defaults;
1792
+ this.options.renderer = this.options.renderer || new _Renderer();
1793
+ this.renderer = this.options.renderer;
1794
+ this.renderer.options = this.options;
1795
+ this.textRenderer = new _TextRenderer();
1796
+ }
1797
+ /**
1798
+ * Static Parse Method
1799
+ */
1800
+ static parse(tokens, options) {
1801
+ const parser = new _Parser(options);
1802
+ return parser.parse(tokens);
1803
+ }
1804
+ /**
1805
+ * Static Parse Inline Method
1806
+ */
1807
+ static parseInline(tokens, options) {
1808
+ const parser = new _Parser(options);
1809
+ return parser.parseInline(tokens);
1810
+ }
1811
+ /**
1812
+ * Parse Loop
1813
+ */
1814
+ parse(tokens, top = true) {
1815
+ let out = '';
1816
+ for (let i = 0; i < tokens.length; i++) {
1817
+ const token = tokens[i];
1818
+ // Run any renderer extensions
1819
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
1820
+ const genericToken = token;
1821
+ const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
1822
+ if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
1823
+ out += ret || '';
1824
+ continue;
1825
+ }
1826
+ }
1827
+ switch (token.type) {
1828
+ case 'space': {
1829
+ continue;
1830
+ }
1831
+ case 'hr': {
1832
+ out += this.renderer.hr();
1833
+ continue;
1834
+ }
1835
+ case 'heading': {
1836
+ const headingToken = token;
1837
+ out += this.renderer.heading(this.parseInline(headingToken.tokens), headingToken.depth, unescape(this.parseInline(headingToken.tokens, this.textRenderer)));
1838
+ continue;
1839
+ }
1840
+ case 'code': {
1841
+ const codeToken = token;
1842
+ out += this.renderer.code(codeToken.text, codeToken.lang, !!codeToken.escaped);
1843
+ continue;
1844
+ }
1845
+ case 'table': {
1846
+ const tableToken = token;
1847
+ let header = '';
1848
+ // header
1849
+ let cell = '';
1850
+ for (let j = 0; j < tableToken.header.length; j++) {
1851
+ cell += this.renderer.tablecell(this.parseInline(tableToken.header[j].tokens), { header: true, align: tableToken.align[j] });
1852
+ }
1853
+ header += this.renderer.tablerow(cell);
1854
+ let body = '';
1855
+ for (let j = 0; j < tableToken.rows.length; j++) {
1856
+ const row = tableToken.rows[j];
1857
+ cell = '';
1858
+ for (let k = 0; k < row.length; k++) {
1859
+ cell += this.renderer.tablecell(this.parseInline(row[k].tokens), { header: false, align: tableToken.align[k] });
1860
+ }
1861
+ body += this.renderer.tablerow(cell);
1862
+ }
1863
+ out += this.renderer.table(header, body);
1864
+ continue;
1865
+ }
1866
+ case 'blockquote': {
1867
+ const blockquoteToken = token;
1868
+ const body = this.parse(blockquoteToken.tokens);
1869
+ out += this.renderer.blockquote(body);
1870
+ continue;
1871
+ }
1872
+ case 'list': {
1873
+ const listToken = token;
1874
+ const ordered = listToken.ordered;
1875
+ const start = listToken.start;
1876
+ const loose = listToken.loose;
1877
+ let body = '';
1878
+ for (let j = 0; j < listToken.items.length; j++) {
1879
+ const item = listToken.items[j];
1880
+ const checked = item.checked;
1881
+ const task = item.task;
1882
+ let itemBody = '';
1883
+ if (item.task) {
1884
+ const checkbox = this.renderer.checkbox(!!checked);
1885
+ if (loose) {
1886
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
1887
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
1888
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
1889
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
1890
+ }
1891
+ }
1892
+ else {
1893
+ item.tokens.unshift({
1894
+ type: 'text',
1895
+ text: checkbox + ' '
1896
+ });
1897
+ }
1898
+ }
1899
+ else {
1900
+ itemBody += checkbox + ' ';
1901
+ }
1902
+ }
1903
+ itemBody += this.parse(item.tokens, loose);
1904
+ body += this.renderer.listitem(itemBody, task, !!checked);
1905
+ }
1906
+ out += this.renderer.list(body, ordered, start);
1907
+ continue;
1908
+ }
1909
+ case 'html': {
1910
+ const htmlToken = token;
1911
+ out += this.renderer.html(htmlToken.text, htmlToken.block);
1912
+ continue;
1913
+ }
1914
+ case 'paragraph': {
1915
+ const paragraphToken = token;
1916
+ out += this.renderer.paragraph(this.parseInline(paragraphToken.tokens));
1917
+ continue;
1918
+ }
1919
+ case 'text': {
1920
+ let textToken = token;
1921
+ let body = textToken.tokens ? this.parseInline(textToken.tokens) : textToken.text;
1922
+ while (i + 1 < tokens.length && tokens[i + 1].type === 'text') {
1923
+ textToken = tokens[++i];
1924
+ body += '\n' + (textToken.tokens ? this.parseInline(textToken.tokens) : textToken.text);
1925
+ }
1926
+ out += top ? this.renderer.paragraph(body) : body;
1927
+ continue;
1928
+ }
1929
+ default: {
1930
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
1931
+ if (this.options.silent) {
1932
+ console.error(errMsg);
1933
+ return '';
1934
+ }
1935
+ else {
1936
+ throw new Error(errMsg);
1937
+ }
1938
+ }
1939
+ }
1940
+ }
1941
+ return out;
1942
+ }
1943
+ /**
1944
+ * Parse Inline Tokens
1945
+ */
1946
+ parseInline(tokens, renderer) {
1947
+ renderer = renderer || this.renderer;
1948
+ let out = '';
1949
+ for (let i = 0; i < tokens.length; i++) {
1950
+ const token = tokens[i];
1951
+ // Run any renderer extensions
1952
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[token.type]) {
1953
+ const ret = this.options.extensions.renderers[token.type].call({ parser: this }, token);
1954
+ if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(token.type)) {
1955
+ out += ret || '';
1956
+ continue;
1957
+ }
1958
+ }
1959
+ switch (token.type) {
1960
+ case 'escape': {
1961
+ const escapeToken = token;
1962
+ out += renderer.text(escapeToken.text);
1963
+ break;
1964
+ }
1965
+ case 'html': {
1966
+ const tagToken = token;
1967
+ out += renderer.html(tagToken.text);
1968
+ break;
1969
+ }
1970
+ case 'link': {
1971
+ const linkToken = token;
1972
+ out += renderer.link(linkToken.href, linkToken.title, this.parseInline(linkToken.tokens, renderer));
1973
+ break;
1974
+ }
1975
+ case 'image': {
1976
+ const imageToken = token;
1977
+ out += renderer.image(imageToken.href, imageToken.title, imageToken.text);
1978
+ break;
1979
+ }
1980
+ case 'strong': {
1981
+ const strongToken = token;
1982
+ out += renderer.strong(this.parseInline(strongToken.tokens, renderer));
1983
+ break;
1984
+ }
1985
+ case 'em': {
1986
+ const emToken = token;
1987
+ out += renderer.em(this.parseInline(emToken.tokens, renderer));
1988
+ break;
1989
+ }
1990
+ case 'codespan': {
1991
+ const codespanToken = token;
1992
+ out += renderer.codespan(codespanToken.text);
1993
+ break;
1994
+ }
1995
+ case 'br': {
1996
+ out += renderer.br();
1997
+ break;
1998
+ }
1999
+ case 'del': {
2000
+ const delToken = token;
2001
+ out += renderer.del(this.parseInline(delToken.tokens, renderer));
2002
+ break;
2003
+ }
2004
+ case 'text': {
2005
+ const textToken = token;
2006
+ out += renderer.text(textToken.text);
2007
+ break;
2008
+ }
2009
+ default: {
2010
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2011
+ if (this.options.silent) {
2012
+ console.error(errMsg);
2013
+ return '';
2014
+ }
2015
+ else {
2016
+ throw new Error(errMsg);
2017
+ }
2018
+ }
2019
+ }
2020
+ }
2021
+ return out;
2022
+ }
2023
+ }
2024
+
2025
+ class _Hooks {
2026
+ options;
2027
+ constructor(options) {
2028
+ this.options = options || _defaults;
2029
+ }
2030
+ static passThroughHooks = new Set([
2031
+ 'preprocess',
2032
+ 'postprocess'
2033
+ ]);
2034
+ /**
2035
+ * Process markdown before marked
2036
+ */
2037
+ preprocess(markdown) {
2038
+ return markdown;
2039
+ }
2040
+ /**
2041
+ * Process HTML after marked is finished
2042
+ */
2043
+ postprocess(html) {
2044
+ return html;
2045
+ }
2046
+ }
2047
+
2048
+ class Marked {
2049
+ defaults = _getDefaults();
2050
+ options = this.setOptions;
2051
+ parse = this.#parseMarkdown(_Lexer.lex, _Parser.parse);
2052
+ parseInline = this.#parseMarkdown(_Lexer.lexInline, _Parser.parseInline);
2053
+ Parser = _Parser;
2054
+ Renderer = _Renderer;
2055
+ TextRenderer = _TextRenderer;
2056
+ Lexer = _Lexer;
2057
+ Tokenizer = _Tokenizer;
2058
+ Hooks = _Hooks;
2059
+ constructor(...args) {
2060
+ this.use(...args);
2061
+ }
2062
+ /**
2063
+ * Run callback for every token
2064
+ */
2065
+ walkTokens(tokens, callback) {
2066
+ let values = [];
2067
+ for (const token of tokens) {
2068
+ values = values.concat(callback.call(this, token));
2069
+ switch (token.type) {
2070
+ case 'table': {
2071
+ const tableToken = token;
2072
+ for (const cell of tableToken.header) {
2073
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2074
+ }
2075
+ for (const row of tableToken.rows) {
2076
+ for (const cell of row) {
2077
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2078
+ }
2079
+ }
2080
+ break;
2081
+ }
2082
+ case 'list': {
2083
+ const listToken = token;
2084
+ values = values.concat(this.walkTokens(listToken.items, callback));
2085
+ break;
2086
+ }
2087
+ default: {
2088
+ const genericToken = token;
2089
+ if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
2090
+ this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
2091
+ values = values.concat(this.walkTokens(genericToken[childTokens], callback));
2092
+ });
2093
+ }
2094
+ else if (genericToken.tokens) {
2095
+ values = values.concat(this.walkTokens(genericToken.tokens, callback));
2096
+ }
2097
+ }
2098
+ }
2099
+ }
2100
+ return values;
2101
+ }
2102
+ use(...args) {
2103
+ const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
2104
+ args.forEach((pack) => {
2105
+ // copy options to new object
2106
+ const opts = { ...pack };
2107
+ // set async to true if it was set to true before
2108
+ opts.async = this.defaults.async || opts.async || false;
2109
+ // ==-- Parse "addon" extensions --== //
2110
+ if (pack.extensions) {
2111
+ pack.extensions.forEach((ext) => {
2112
+ if (!ext.name) {
2113
+ throw new Error('extension name required');
2114
+ }
2115
+ if ('renderer' in ext) { // Renderer extensions
2116
+ const prevRenderer = extensions.renderers[ext.name];
2117
+ if (prevRenderer) {
2118
+ // Replace extension with func to run new extension but fall back if false
2119
+ extensions.renderers[ext.name] = function (...args) {
2120
+ let ret = ext.renderer.apply(this, args);
2121
+ if (ret === false) {
2122
+ ret = prevRenderer.apply(this, args);
2123
+ }
2124
+ return ret;
2125
+ };
2126
+ }
2127
+ else {
2128
+ extensions.renderers[ext.name] = ext.renderer;
2129
+ }
2130
+ }
2131
+ if ('tokenizer' in ext) { // Tokenizer Extensions
2132
+ if (!ext.level || (ext.level !== 'block' && ext.level !== 'inline')) {
2133
+ throw new Error("extension level must be 'block' or 'inline'");
2134
+ }
2135
+ const extLevel = extensions[ext.level];
2136
+ if (extLevel) {
2137
+ extLevel.unshift(ext.tokenizer);
2138
+ }
2139
+ else {
2140
+ extensions[ext.level] = [ext.tokenizer];
2141
+ }
2142
+ if (ext.start) { // Function to check for start of token
2143
+ if (ext.level === 'block') {
2144
+ if (extensions.startBlock) {
2145
+ extensions.startBlock.push(ext.start);
2146
+ }
2147
+ else {
2148
+ extensions.startBlock = [ext.start];
2149
+ }
2150
+ }
2151
+ else if (ext.level === 'inline') {
2152
+ if (extensions.startInline) {
2153
+ extensions.startInline.push(ext.start);
2154
+ }
2155
+ else {
2156
+ extensions.startInline = [ext.start];
2157
+ }
2158
+ }
2159
+ }
2160
+ }
2161
+ if ('childTokens' in ext && ext.childTokens) { // Child tokens to be visited by walkTokens
2162
+ extensions.childTokens[ext.name] = ext.childTokens;
2163
+ }
2164
+ });
2165
+ opts.extensions = extensions;
2166
+ }
2167
+ // ==-- Parse "overwrite" extensions --== //
2168
+ if (pack.renderer) {
2169
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2170
+ for (const prop in pack.renderer) {
2171
+ const rendererFunc = pack.renderer[prop];
2172
+ const rendererKey = prop;
2173
+ const prevRenderer = renderer[rendererKey];
2174
+ // Replace renderer with func to run extension, but fall back if false
2175
+ renderer[rendererKey] = (...args) => {
2176
+ let ret = rendererFunc.apply(renderer, args);
2177
+ if (ret === false) {
2178
+ ret = prevRenderer.apply(renderer, args);
2179
+ }
2180
+ return ret || '';
2181
+ };
2182
+ }
2183
+ opts.renderer = renderer;
2184
+ }
2185
+ if (pack.tokenizer) {
2186
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2187
+ for (const prop in pack.tokenizer) {
2188
+ const tokenizerFunc = pack.tokenizer[prop];
2189
+ const tokenizerKey = prop;
2190
+ const prevTokenizer = tokenizer[tokenizerKey];
2191
+ // Replace tokenizer with func to run extension, but fall back if false
2192
+ tokenizer[tokenizerKey] = (...args) => {
2193
+ let ret = tokenizerFunc.apply(tokenizer, args);
2194
+ if (ret === false) {
2195
+ ret = prevTokenizer.apply(tokenizer, args);
2196
+ }
2197
+ return ret;
2198
+ };
2199
+ }
2200
+ opts.tokenizer = tokenizer;
2201
+ }
2202
+ // ==-- Parse Hooks extensions --== //
2203
+ if (pack.hooks) {
2204
+ const hooks = this.defaults.hooks || new _Hooks();
2205
+ for (const prop in pack.hooks) {
2206
+ const hooksFunc = pack.hooks[prop];
2207
+ const hooksKey = prop;
2208
+ const prevHook = hooks[hooksKey];
2209
+ if (_Hooks.passThroughHooks.has(prop)) {
2210
+ hooks[hooksKey] = (arg) => {
2211
+ if (this.defaults.async) {
2212
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
2213
+ return prevHook.call(hooks, ret);
2214
+ });
2215
+ }
2216
+ const ret = hooksFunc.call(hooks, arg);
2217
+ return prevHook.call(hooks, ret);
2218
+ };
2219
+ }
2220
+ else {
2221
+ hooks[hooksKey] = (...args) => {
2222
+ let ret = hooksFunc.apply(hooks, args);
2223
+ if (ret === false) {
2224
+ ret = prevHook.apply(hooks, args);
2225
+ }
2226
+ return ret;
2227
+ };
2228
+ }
2229
+ }
2230
+ opts.hooks = hooks;
2231
+ }
2232
+ // ==-- Parse WalkTokens extensions --== //
2233
+ if (pack.walkTokens) {
2234
+ const walkTokens = this.defaults.walkTokens;
2235
+ const packWalktokens = pack.walkTokens;
2236
+ opts.walkTokens = function (token) {
2237
+ let values = [];
2238
+ values.push(packWalktokens.call(this, token));
2239
+ if (walkTokens) {
2240
+ values = values.concat(walkTokens.call(this, token));
2241
+ }
2242
+ return values;
2243
+ };
2244
+ }
2245
+ this.defaults = { ...this.defaults, ...opts };
2246
+ });
2247
+ return this;
2248
+ }
2249
+ setOptions(opt) {
2250
+ this.defaults = { ...this.defaults, ...opt };
2251
+ return this;
2252
+ }
2253
+ lexer(src, options) {
2254
+ return _Lexer.lex(src, options ?? this.defaults);
2255
+ }
2256
+ parser(tokens, options) {
2257
+ return _Parser.parse(tokens, options ?? this.defaults);
2258
+ }
2259
+ #parseMarkdown(lexer, parser) {
2260
+ return (src, options) => {
2261
+ const origOpt = { ...options };
2262
+ const opt = { ...this.defaults, ...origOpt };
2263
+ // Show warning if an extension set async to true but the parse was called with async: false
2264
+ if (this.defaults.async === true && origOpt.async === false) {
2265
+ if (!opt.silent) {
2266
+ console.warn('marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored.');
2267
+ }
2268
+ opt.async = true;
2269
+ }
2270
+ const throwError = this.#onError(!!opt.silent, !!opt.async);
2271
+ // throw error in case of non string input
2272
+ if (typeof src === 'undefined' || src === null) {
2273
+ return throwError(new Error('marked(): input parameter is undefined or null'));
2274
+ }
2275
+ if (typeof src !== 'string') {
2276
+ return throwError(new Error('marked(): input parameter is of type '
2277
+ + Object.prototype.toString.call(src) + ', string expected'));
2278
+ }
2279
+ if (opt.hooks) {
2280
+ opt.hooks.options = opt;
2281
+ }
2282
+ if (opt.async) {
2283
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2284
+ .then(src => lexer(src, opt))
2285
+ .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2286
+ .then(tokens => parser(tokens, opt))
2287
+ .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
2288
+ .catch(throwError);
2289
+ }
2290
+ try {
2291
+ if (opt.hooks) {
2292
+ src = opt.hooks.preprocess(src);
2293
+ }
2294
+ const tokens = lexer(src, opt);
2295
+ if (opt.walkTokens) {
2296
+ this.walkTokens(tokens, opt.walkTokens);
2297
+ }
2298
+ let html = parser(tokens, opt);
2299
+ if (opt.hooks) {
2300
+ html = opt.hooks.postprocess(html);
2301
+ }
2302
+ return html;
2303
+ }
2304
+ catch (e) {
2305
+ return throwError(e);
2306
+ }
2307
+ };
2308
+ }
2309
+ #onError(silent, async) {
2310
+ return (e) => {
2311
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2312
+ if (silent) {
2313
+ const msg = '<p>An error occurred:</p><pre>'
2314
+ + escape(e.message + '', true)
2315
+ + '</pre>';
2316
+ if (async) {
2317
+ return Promise.resolve(msg);
2318
+ }
2319
+ return msg;
2320
+ }
2321
+ if (async) {
2322
+ return Promise.reject(e);
2323
+ }
2324
+ throw e;
2325
+ };
2326
+ }
2327
+ }
2328
+
2329
+ const markedInstance = new Marked();
2330
+ function marked(src, opt) {
2331
+ return markedInstance.parse(src, opt);
2332
+ }
2333
+ /**
2334
+ * Sets the default options.
2335
+ *
2336
+ * @param options Hash of options
2337
+ */
2338
+ marked.options =
2339
+ marked.setOptions = function (options) {
2340
+ markedInstance.setOptions(options);
2341
+ marked.defaults = markedInstance.defaults;
2342
+ changeDefaults(marked.defaults);
2343
+ return marked;
2344
+ };
2345
+ /**
2346
+ * Gets the original marked default options.
2347
+ */
2348
+ marked.getDefaults = _getDefaults;
2349
+ marked.defaults = _defaults;
2350
+ /**
2351
+ * Use Extension
2352
+ */
2353
+ marked.use = function (...args) {
2354
+ markedInstance.use(...args);
2355
+ marked.defaults = markedInstance.defaults;
2356
+ changeDefaults(marked.defaults);
2357
+ return marked;
2358
+ };
2359
+ /**
2360
+ * Run callback for every token
2361
+ */
2362
+ marked.walkTokens = function (tokens, callback) {
2363
+ return markedInstance.walkTokens(tokens, callback);
2364
+ };
2365
+ /**
2366
+ * Compiles markdown to HTML without enclosing `p` tag.
2367
+ *
2368
+ * @param src String of markdown source to be compiled
2369
+ * @param options Hash of options
2370
+ * @return String of compiled HTML
2371
+ */
2372
+ marked.parseInline = markedInstance.parseInline;
2373
+ /**
2374
+ * Expose
2375
+ */
2376
+ marked.Parser = _Parser;
2377
+ marked.parser = _Parser.parse;
2378
+ marked.Renderer = _Renderer;
2379
+ marked.TextRenderer = _TextRenderer;
2380
+ marked.Lexer = _Lexer;
2381
+ marked.lexer = _Lexer.lex;
2382
+ marked.Tokenizer = _Tokenizer;
2383
+ marked.Hooks = _Hooks;
2384
+ marked.parse = marked;
2385
+
2386
+ var lib;
2387
+ var hasRequiredLib;
2388
+
2389
+ function requireLib () {
2390
+ if (hasRequiredLib) return lib;
2391
+ hasRequiredLib = 1;
2392
+
2393
+ function index({ interruptPatterns = [], skipEmptyRows = true } = {}) {
2394
+ return {
2395
+ extensions: [
2396
+ {
2397
+ name: 'spanTable',
2398
+ level: 'block', // Is this a block-level or inline-level tokenizer?
2399
+ start(src) { return src.match(/\n *([^\n ].*\|.*)\n/m)?.index; }, // Hint to Marked.js to stop and check for a match
2400
+ tokenizer(src, tokens) {
2401
+ // const regex = this.tokenizer.rules.block.table;
2402
+ let regexString = '^ *([^\\n ].*\\|.*\\n(?: *[^\\s].*\\n)*?)' // Header
2403
+ + ' {0,3}(?:\\| *)?(:?-+(?: *(?:100|[1-9][0-9]?%) *-+)?:? *(?:\\| *:?-+(?: *(?:100|[1-9][0-9]?%) *-+)?:? *)*)(?:\\| *)?' // Align
2404
+ + '(?:\\n((?:(?! *\\n| {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})' // Cells
2405
+ + '(?:\\n+|$)| {0,3}#{1,6}(?:\\s|$)| {0,3}>| {4}[^\\n]| {0,3}(?:`{3,}'
2406
+ + '(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n| {0,3}(?:[*+-]|1[.)]) |'
2407
+ + '<\\/?(?:address|article|aside|base|basefont|blockquote|body'
2408
+ + '|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt'
2409
+ + '|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]'
2410
+ + '|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem'
2411
+ + '|meta|nav|noframes|ol|optgroup|option|p|param|section|source'
2412
+ + '|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)'
2413
+ + '(?: +|\\n|\\/?>)|<(?:script|pre|style|textarea|!--)endRegex).*(?:\\n|$))*)\\n*|$)'; // Cells
2414
+
2415
+ regexString = regexString.replace('endRegex', interruptPatterns.map(str => `|(?:${str})`).join(''));
2416
+ const widthRegex = / *(?:100|[1-9][0-9]?%) */g;
2417
+ const regex = new RegExp(regexString);
2418
+ const cap = regex.exec(src);
2419
+
2420
+ if (cap) {
2421
+ const item = {
2422
+ type: 'spanTable',
2423
+ header: cap[1].replace(/\n$/, '').split('\n'),
2424
+ align: cap[2].replace(widthRegex, '').replace(/^ *|\| *$/g, '').split(/ *\| */),
2425
+ rows: cap[3]?.trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : [],
2426
+ width: cap[2].replace(/:/g, '').replace(/-+| /g, '').split('|')
2427
+ };
2428
+
2429
+ // Get first header row to determine how many columns
2430
+ item.header[0] = splitCells(item.header[0]);
2431
+
2432
+ const colCount = item.header[0].reduce((length, header) => {
2433
+ return length + header.colspan;
2434
+ }, 0);
2435
+
2436
+ if (colCount === item.align.length) {
2437
+ item.raw = cap[0];
2438
+
2439
+ let i, j, k, row;
2440
+
2441
+ // Get alignment row (:---:)
2442
+ let l = item.align.length;
2443
+
2444
+ for (i = 0; i < l; i++) {
2445
+ if (/^ *-+: *$/.test(item.align[i])) {
2446
+ item.align[i] = 'right';
2447
+ } else if (/^ *:-+: *$/.test(item.align[i])) {
2448
+ item.align[i] = 'center';
2449
+ } else if (/^ *:-+ *$/.test(item.align[i])) {
2450
+ item.align[i] = 'left';
2451
+ } else {
2452
+ item.align[i] = null;
2453
+ }
2454
+ }
2455
+
2456
+ // Get any remaining header rows
2457
+ l = item.header.length;
2458
+ for (i = 1; i < l; i++) {
2459
+ item.header[i] = splitCells(item.header[i], colCount, item.header[i - 1], skipEmptyRows);
2460
+ }
2461
+
2462
+ // Get main table cells
2463
+ l = item.rows.length;
2464
+ for (i = 0; i < l; i++) {
2465
+ item.rows[i] = splitCells(item.rows[i], colCount, item.rows[i - 1], skipEmptyRows);
2466
+ }
2467
+
2468
+ // header child tokens
2469
+ l = item.header.length;
2470
+ for (j = 0; j < l; j++) {
2471
+ row = item.header[j];
2472
+ for (k = 0; k < row.length; k++) {
2473
+ row[k].tokens = [];
2474
+ this.lexer.inline(row[k].text, row[k].tokens);
2475
+ }
2476
+ }
2477
+
2478
+ // cell child tokens
2479
+ l = item.rows.length;
2480
+ for (j = 0; j < l; j++) {
2481
+ row = item.rows[j];
2482
+ for (k = 0; k < row.length; k++) {
2483
+ row[k].tokens = [];
2484
+ this.lexer.inline(row[k].text, row[k].tokens);
2485
+ }
2486
+ }
2487
+ return item;
2488
+ }
2489
+ }
2490
+ },
2491
+ renderer(token) {
2492
+ let i, j, row, cell, col, text;
2493
+ let output = '<table>';
2494
+ output += '<thead>';
2495
+ for (i = 0; i < token.header.length; i++) {
2496
+ row = token.header[i];
2497
+ let col = 0;
2498
+ output += '<tr>';
2499
+ for (j = 0; j < row.length; j++) {
2500
+ cell = row[j];
2501
+ text = this.parser.parseInline(cell.tokens);
2502
+ output += getTableCell(text, cell, 'th', token.align[col], token.width[col]);
2503
+ col += cell.colspan;
2504
+ }
2505
+ output += '</tr>';
2506
+ }
2507
+ output += '</thead>';
2508
+ if (token.rows.length) {
2509
+ output += '<tbody>';
2510
+ for (i = 0; i < token.rows.length; i++) {
2511
+ row = token.rows[i];
2512
+ col = 0;
2513
+ if (!row[0].emptyRow) {
2514
+ output += '<tr>';
2515
+ for (j = 0; j < row.length; j++) {
2516
+ cell = row[j];
2517
+ text = this.parser.parseInline(cell.tokens);
2518
+ output += getTableCell(text, cell, 'td', token.align[col], token.width[col]);
2519
+ col += cell.colspan;
2520
+ }
2521
+ output += '</tr>';
2522
+ }
2523
+ }
2524
+ output += '</tbody>';
2525
+ }
2526
+ output += '</table>';
2527
+ return output;
2528
+ }
2529
+ }
2530
+ ]
2531
+ };
2532
+ }
2533
+
2534
+ const getTableCell = (text, cell, type, align, width) => {
2535
+ if (!cell.rowspan) {
2536
+ return '';
2537
+ }
2538
+ const tag = `<${type}`
2539
+ + `${cell.colspan > 1 ? ` colspan=${cell.colspan}` : ''}`
2540
+ + `${cell.rowspan > 1 ? ` rowspan=${cell.rowspan}` : ''}`
2541
+ + `${align ? ` align=${align}` : ''}`
2542
+ + `${width ? ` width=${width}` : ''}>`;
2543
+ return `${tag + text}</${type}>\n`;
2544
+ };
2545
+
2546
+ const splitCells = (tableRow, count, prevRow = [], skipEmptyRows) => {
2547
+ const cells = [...tableRow.trim().matchAll(/(?:[^|\\]|\\.?)+(?:\|+|$)/g)].map((x) => x[0]);
2548
+
2549
+ // Remove first/last cell in a row if whitespace only and no leading/trailing pipe
2550
+ if (!cells[0]?.trim()) { cells.shift(); }
2551
+ if (!cells[cells.length - 1]?.trim()) { cells.pop(); }
2552
+
2553
+ let numCols = 0;
2554
+ let i, j, trimmedCell, prevCell, prevCols;
2555
+
2556
+ for (i = 0; i < cells.length; i++) {
2557
+ trimmedCell = cells[i].split(/\|+$/)[0];
2558
+ cells[i] = {
2559
+ rowspan: 1,
2560
+ colspan: Math.max(cells[i].length - trimmedCell.length, 1),
2561
+ text: trimmedCell.trim().replace(/\\\|/g, '|')
2562
+ // display escaped pipes as normal character
2563
+ };
2564
+
2565
+ // Handle Rowspan
2566
+ if (trimmedCell.slice(-1) === '^' && prevRow.length) {
2567
+ // Find matching cell in previous row
2568
+ prevCols = 0;
2569
+ for (j = 0; j < prevRow.length; j++) {
2570
+ prevCell = prevRow[j];
2571
+ if ((prevCols === numCols) && (prevCell.colspan === cells[i].colspan)) {
2572
+ // merge into matching cell in previous row (the "target")
2573
+ cells[i].rowSpanTarget = prevCell.rowSpanTarget ?? prevCell;
2574
+ cells[i].rowSpanTarget.text += ` ${cells[i].text.slice(0, -1)}`;
2575
+ cells[i].rowSpanTarget.rowspan += 1;
2576
+ cells[i].rowspan = 0;
2577
+ break;
2578
+ }
2579
+ prevCols += prevCell.colspan;
2580
+ if (prevCols > numCols) { break; }
2581
+ }
2582
+ }
2583
+
2584
+ numCols += cells[i].colspan;
2585
+ }
2586
+
2587
+ // If all cells have been merged, flag as an empty row
2588
+ if (cells.length > 0 && skipEmptyRows && cells.length === cells.filter((cell) => { return cell.rowspan === 0; }).length) {
2589
+ cells[0].emptyRow = true;
2590
+ for (i = 0; i < cells.length; i++) {
2591
+ cells[i].rowSpanTarget.rowspan -= 1;
2592
+ }
2593
+ }
2594
+
2595
+ // Force main cell rows to match header column count
2596
+ if (numCols > count) {
2597
+ cells.splice(count);
2598
+ } else {
2599
+ while (numCols < count) {
2600
+ cells.push({
2601
+ rowspan: 1,
2602
+ colspan: 1,
2603
+ text: ''
2604
+ });
2605
+ numCols += 1;
2606
+ }
2607
+ }
2608
+ return cells;
2609
+ };
2610
+
2611
+ lib = index;
2612
+ return lib;
2613
+ }
2614
+
2615
+ var libExports = requireLib();
2616
+ var extendedTables = /*@__PURE__*/getDefaultExportFromCjs(libExports);
2617
+
2618
+ /**
2619
+ * marked 全局配置是否已初始化
2620
+ * marked 的 use/setOptions 作用于模块单例,仅需配置一次
2621
+ */
2622
+ let markedConfigured = false;
2623
+ /**
2624
+ * 初始化 marked 全局配置(GFM 表格 + 扩展表格语法 + 换行转 <br>)
2625
+ */
2626
+ function ensureMarkedConfigured() {
2627
+ if (markedConfigured) {
2628
+ return;
2629
+ }
2630
+ marked.use(extendedTables);
2631
+ marked.setOptions({
2632
+ breaks: true,
2633
+ gfm: true
2634
+ });
2635
+ markedConfigured = true;
2636
+ }
2637
+ /**
2638
+ * 为表格包裹滚动容器:
2639
+ * 移动端(<=767px)由 .md-table-wrap 提供横向滚动,表格保持自然宽度不被压缩;
2640
+ * PC 端该容器为普通块级元素,不影响现有展示与打印。
2641
+ */
2642
+ function wrapMarkdownTables(html) {
2643
+ if (!html.includes('<table')) {
2644
+ return html;
2645
+ }
2646
+ return html
2647
+ .replace(/<table(\s|>)/gi, '<div class="md-table-wrap"><table$1')
2648
+ .replace(/<\/table>/gi, '</table></div>');
2649
+ }
2650
+ /**
2651
+ * 渲染 Markdown 为 HTML(项目内统一的渲染入口)
2652
+ *
2653
+ * - 统一应用 GFM / extended-tables / breaks 配置
2654
+ * - 所有 <table> 会被包裹在 <div class="md-table-wrap"> 中,
2655
+ * 配合 global/markdown.css 实现移动端横向滚动、PC 端保持原样
2656
+ *
2657
+ * @param content Markdown 源文本
2658
+ * @returns 渲染后的 HTML 字符串,空内容返回空字符串
2659
+ */
2660
+ function renderMarkdown(content) {
2661
+ if (!content) {
2662
+ return '';
2663
+ }
2664
+ ensureMarkedConfigured();
2665
+ return wrapMarkdownTables(marked(content));
2666
+ }
2667
+
2668
+ export { getDefaultExportFromCjs as g, renderMarkdown as r };
2669
+ //# sourceMappingURL=markdown-CnhOGURu.js.map
2670
+
2671
+ //# sourceMappingURL=markdown-CnhOGURu.js.map