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