@vaadin/bundles 25.0.0-alpha1 → 25.0.0-alpha12

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