chrome-devtools-frontend 1.0.1636056 → 1.0.1640418

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