@vaadin/bundles 25.0.0-alpha3 → 25.0.0-alpha5

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