@khanacademy/simple-markdown 0.8.6 → 0.9.0

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.
package/dist/es/index.js CHANGED
@@ -1,5 +1,4 @@
1
- /* eslint-disable prefer-spread, no-regex-spaces, no-unused-vars, guard-for-in, no-console, no-var */
2
-
1
+ /* eslint-disable prefer-spread, no-regex-spaces, @typescript-eslint/no-unused-vars, guard-for-in, no-console, no-var */
3
2
  /**
4
3
  * Simple-Markdown
5
4
  * ===============
@@ -19,36 +18,37 @@
19
18
  * Many of the regexes and original logic has been adapted from
20
19
  * the wonderful [marked.js](https://github.com/chjj/marked)
21
20
  */
22
- // Flow Type Definitions:
21
+
22
+ // Type Definitions:
23
+
23
24
  // We want to clarify our defaultRules types a little bit more so clients can
24
25
  // reuse defaultRules built-ins. So we make some stronger guarantess when
25
26
  // we can:
27
+
26
28
  // End Flow Definitions
29
+
27
30
  var CR_NEWLINE_R = /\r\n?/g;
28
31
  var TAB_R = /\t/g;
29
32
  var FORMFEED_R = /\f/g;
33
+
30
34
  /**
31
35
  * Turn various whitespace into easy-to-process whitespace
32
36
  */
33
-
34
37
  var preprocess = function preprocess(source) {
35
38
  return source.replace(CR_NEWLINE_R, "\n").replace(FORMFEED_R, "").replace(TAB_R, " ");
36
39
  };
37
-
38
40
  var populateInitialState = function populateInitialState(givenState, defaultState) {
39
41
  var state = givenState || {};
40
-
41
42
  if (defaultState != null) {
42
43
  for (var prop in defaultState) {
43
- // $FlowFixMe
44
44
  if (Object.prototype.hasOwnProperty.call(defaultState, prop)) {
45
45
  state[prop] = defaultState[prop];
46
46
  }
47
47
  }
48
48
  }
49
-
50
49
  return state;
51
50
  };
51
+
52
52
  /**
53
53
  * Creates a parser for a given set of rules, with the precedence
54
54
  * specified as a list of rules.
@@ -68,41 +68,36 @@ var populateInitialState = function populateInitialState(givenState, defaultStat
68
68
  * some nesting is. For an example use-case, see passage-ref
69
69
  * parsing in src/widgets/passage/passage-markdown.jsx
70
70
  */
71
-
72
-
73
71
  var parserFor = function parserFor(rules, defaultState) {
74
72
  // Sorts rules in order of increasing order, then
75
73
  // ascending rule name in case of ties.
76
74
  var ruleList = Object.keys(rules).filter(function (type) {
77
75
  var rule = rules[type];
78
-
79
76
  if (rule == null || rule.match == null) {
80
77
  return false;
81
78
  }
82
-
83
79
  var order = rule.order;
84
-
85
80
  if ((typeof order !== "number" || !isFinite(order)) && typeof console !== "undefined") {
86
81
  console.warn("simple-markdown: Invalid order for rule `" + type + "`: " + String(order));
87
82
  }
88
-
89
83
  return true;
90
84
  });
91
85
  ruleList.sort(function (typeA, typeB) {
92
86
  var ruleA = rules[typeA];
93
87
  var ruleB = rules[typeB];
94
88
  var orderA = ruleA.order;
95
- var orderB = ruleB.order; // First sort based on increasing order
89
+ var orderB = ruleB.order;
96
90
 
91
+ // First sort based on increasing order
97
92
  if (orderA !== orderB) {
98
93
  return orderA - orderB;
99
94
  }
100
-
101
95
  var secondaryOrderA = ruleA.quality ? 0 : 1;
102
96
  var secondaryOrderB = ruleB.quality ? 0 : 1;
103
-
104
97
  if (secondaryOrderA !== secondaryOrderB) {
105
- return secondaryOrderA - secondaryOrderB; // Then based on increasing unicode lexicographic ordering
98
+ return secondaryOrderA - secondaryOrderB;
99
+
100
+ // Then based on increasing unicode lexicographic ordering
106
101
  } else if (typeA < typeB) {
107
102
  return -1;
108
103
  } else if (typeA > typeB) {
@@ -114,139 +109,128 @@ var parserFor = function parserFor(rules, defaultState) {
114
109
  }
115
110
  });
116
111
  var latestState;
117
-
118
112
  var nestedParse = function nestedParse(source, state) {
119
113
  var result = [];
120
114
  state = state || latestState;
121
115
  latestState = state;
122
-
123
116
  while (source) {
124
117
  // store the best match, it's rule, and quality:
125
118
  var ruleType = null;
126
119
  var rule = null;
127
120
  var capture = null;
128
- var quality = NaN; // loop control variables:
121
+ var quality = NaN;
129
122
 
123
+ // loop control variables:
130
124
  var i = 0;
131
- var currRuleType = ruleList[0]; // $FlowFixMe
132
-
125
+ var currRuleType = ruleList[0];
133
126
  var currRule = rules[currRuleType];
134
-
135
127
  do {
136
128
  var currOrder = currRule.order;
137
129
  var prevCaptureStr = state.prevCapture == null ? "" : state.prevCapture[0];
138
130
  var currCapture = currRule.match(source, state, prevCaptureStr);
139
-
140
131
  if (currCapture) {
141
- var currQuality = currRule.quality ? currRule.quality(currCapture, state, prevCaptureStr) : 0; // This should always be true the first time because
132
+ var currQuality = currRule.quality ? currRule.quality(currCapture, state, prevCaptureStr) : 0;
133
+ // This should always be true the first time because
142
134
  // the initial quality is NaN (that's why there's the
143
135
  // condition negation).
144
-
145
136
  if (!(currQuality <= quality)) {
137
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
146
138
  ruleType = currRuleType;
139
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'ParserRule' is not assignable to type 'null'.
147
140
  rule = currRule;
141
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'Capture' is not assignable to type 'null'.
148
142
  capture = currCapture;
149
143
  quality = currQuality;
150
144
  }
151
- } // Move on to the next item.
152
- // Note that this makes `currRule` be the next item
153
-
145
+ }
154
146
 
147
+ // Move on to the next item.
148
+ // Note that this makes `currRule` be the next item
155
149
  i++;
156
- currRuleType = ruleList[i]; // $FlowFixMe
157
-
150
+ currRuleType = ruleList[i];
158
151
  currRule = rules[currRuleType];
159
- } while ( // keep looping while we're still within the ruleList
160
- currRule && ( // if we don't have a match yet, continue
161
- !capture || // or if we have a match, but the next rule is
152
+ } while (
153
+ // keep looping while we're still within the ruleList
154
+ currRule && (
155
+ // if we don't have a match yet, continue
156
+ !capture ||
157
+ // or if we have a match, but the next rule is
162
158
  // at the same order, and has a quality measurement
163
159
  // functions, then this rule must have a quality
164
160
  // measurement function (since they are sorted before
165
161
  // those without), and we need to check if there is
166
162
  // a better quality match
167
- currRule.order === currOrder && currRule.quality)); // TODO(aria): Write tests for these
168
-
163
+ currRule.order === currOrder && currRule.quality));
169
164
 
165
+ // TODO(aria): Write tests for these
170
166
  if (rule == null || capture == null) {
171
167
  throw new Error("Could not find a matching rule for the below " + "content. The rule with highest `order` should " + "always match content provided to it. Check " + "the definition of `match` for '" + ruleList[ruleList.length - 1] + "'. It seems to not match the following source:\n" + source);
172
168
  }
173
-
169
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'index' does not exist on type 'never'.
174
170
  if (capture.index) {
175
171
  // If present and non-zero, i.e. a non-^ regexp result:
176
172
  throw new Error("`match` must return a capture starting at index 0 " + "(the current parse index). Did you forget a ^ at the " + "start of the RegExp?");
177
173
  }
178
174
 
179
- var parsed = rule.parse(capture, nestedParse, state); // We maintain the same object here so that rules can
175
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'parse' does not exist on type 'never'.
176
+ var parsed = rule.parse(capture, nestedParse, state);
177
+ // We maintain the same object here so that rules can
180
178
  // store references to the objects they return and
181
179
  // modify them later. (oops sorry! but this adds a lot
182
180
  // of power--see reflinks.)
183
-
184
181
  if (Array.isArray(parsed)) {
185
- // $FlowFixMe
186
182
  Array.prototype.push.apply(result, parsed);
187
183
  } else {
188
184
  if (parsed == null || typeof parsed !== "object") {
189
185
  throw new Error("parse() function returned invalid parse result: '".concat(parsed, "'"));
190
- } // We also let rules override the default type of
186
+ }
187
+
188
+ // We also let rules override the default type of
191
189
  // their parsed node if they would like to, so that
192
190
  // there can be a single output function for all links,
193
191
  // even if there are several rules to parse them.
194
-
195
-
196
192
  if (parsed.type == null) {
197
- // $FlowFixMe
198
193
  parsed.type = ruleType;
199
194
  }
200
-
201
195
  result.push(parsed);
202
196
  }
203
-
204
197
  state.prevCapture = capture;
205
198
  source = source.substring(state.prevCapture[0].length);
206
- } // $FlowFixMe
207
-
208
-
199
+ }
209
200
  return result;
210
201
  };
211
-
212
202
  var outerParse = function outerParse(source, state) {
213
203
  latestState = populateInitialState(state, defaultState);
214
-
215
204
  if (!latestState.inline && !latestState.disableAutoBlockNewlines) {
216
205
  source = source + "\n\n";
217
- } // We store the previous capture so that match functions can
206
+ }
207
+ // We store the previous capture so that match functions can
218
208
  // use some limited amount of lookbehind. Lists use this to
219
209
  // ensure they don't match arbitrary '- ' or '* ' in inline
220
210
  // text (see the list rule for more information). This stores
221
211
  // the full regex capture object, if there is one.
222
-
223
-
224
212
  latestState.prevCapture = null;
225
213
  return nestedParse(preprocess(source), latestState);
226
- }; // $FlowFixMe
227
-
228
-
214
+ };
229
215
  return outerParse;
230
- }; // Creates a match function for an inline scoped element from a regex
231
-
216
+ };
232
217
 
218
+ // Creates a match function for an inline scoped element from a regex
233
219
  var inlineRegex = function inlineRegex(regex) {
234
220
  var match = function match(source, state, prevCapture) {
235
221
  if (state.inline) {
236
- // $FlowFixMe
237
222
  return regex.exec(source);
238
223
  } else {
239
224
  return null;
240
225
  }
241
226
  };
242
-
227
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'regex' does not exist on type '(source: string, state: State, prevCapture: string) => Capture | null | undefined'.
243
228
  match.regex = regex;
244
229
  return match;
245
- }; // Creates a match function for a block scoped element from a regex
246
-
230
+ };
247
231
 
232
+ // Creates a match function for a block scoped element from a regex
248
233
  var blockRegex = function blockRegex(regex) {
249
- // $FlowFixMe
250
234
  var match = function match(source, state) {
251
235
  if (state.inline) {
252
236
  return null;
@@ -254,24 +238,19 @@ var blockRegex = function blockRegex(regex) {
254
238
  return regex.exec(source);
255
239
  }
256
240
  };
257
-
258
241
  match.regex = regex;
259
242
  return match;
260
- }; // Creates a match function from a regex, ignoring block/inline scope
261
-
243
+ };
262
244
 
245
+ // Creates a match function from a regex, ignoring block/inline scope
263
246
  var anyScopeRegex = function anyScopeRegex(regex) {
264
- // $FlowFixMe
265
247
  var match = function match(source, state) {
266
248
  return regex.exec(source);
267
249
  };
268
-
269
250
  match.regex = regex;
270
251
  return match;
271
252
  };
272
-
273
253
  var TYPE_SYMBOL = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
274
-
275
254
  var reactElement = function reactElement(type, key, props) {
276
255
  var element = {
277
256
  $$typeof: TYPE_SYMBOL,
@@ -283,6 +262,7 @@ var reactElement = function reactElement(type, key, props) {
283
262
  };
284
263
  return element;
285
264
  };
265
+
286
266
  /** Returns a closed HTML tag.
287
267
  * @param {string} tagName - Name of HTML tag (eg. "em" or "a")
288
268
  * @param {string} content - Inner content of tag
@@ -291,45 +271,38 @@ var reactElement = function reactElement(type, key, props) {
291
271
  * @param {boolean} [isClosed] - boolean that controls whether tag is closed or not (eg. img tags).
292
272
  * defaults to true
293
273
  */
294
-
295
-
296
274
  var htmlTag = function htmlTag(tagName, content, attributes, isClosed) {
297
275
  attributes = attributes || {};
298
276
  isClosed = typeof isClosed !== "undefined" ? isClosed : true;
299
277
  var attributeString = "";
300
-
301
278
  for (var attr in attributes) {
302
- var attribute = attributes[attr]; // Removes falsey attributes
303
-
304
- if ( // $FlowFixMe
279
+ var attribute = attributes[attr];
280
+ // Removes falsey attributes
281
+ if (
282
+ // $FlowFixMe
305
283
  Object.prototype.hasOwnProperty.call(attributes, attr) && attribute) {
306
284
  attributeString += " " + sanitizeText(attr) + '="' + sanitizeText(attribute) + '"';
307
285
  }
308
286
  }
309
-
310
287
  var unclosedTag = "<" + tagName + attributeString + ">";
311
-
312
288
  if (isClosed) {
313
289
  return unclosedTag + content + "</" + tagName + ">";
314
290
  } else {
315
291
  return unclosedTag;
316
292
  }
317
293
  };
318
-
319
294
  var EMPTY_PROPS = {};
295
+
320
296
  /**
321
297
  * @param {string | null | undefined} url - url to sanitize
322
298
  * @returns {string | null} - url if safe, or null if a safe url could not be made
323
299
  */
324
-
325
300
  var sanitizeUrl = function sanitizeUrl(url) {
326
301
  if (url == null) {
327
302
  return null;
328
303
  }
329
-
330
304
  try {
331
305
  var prot = new URL(url, "https://localhost").protocol;
332
-
333
306
  if (prot.indexOf("javascript:") === 0 || prot.indexOf("vbscript:") === 0 || prot.indexOf("data:") === 0) {
334
307
  return null;
335
308
  }
@@ -338,10 +311,8 @@ var sanitizeUrl = function sanitizeUrl(url) {
338
311
  // see for instance: `new URL("");`
339
312
  return null;
340
313
  }
341
-
342
314
  return url;
343
315
  };
344
-
345
316
  var SANITIZE_TEXT_R = /[<>&"']/g;
346
317
  var SANITIZE_TEXT_CODES = {
347
318
  "<": "&lt;",
@@ -352,25 +323,21 @@ var SANITIZE_TEXT_CODES = {
352
323
  "/": "&#x2F;",
353
324
  "`": "&#96;"
354
325
  };
355
-
356
326
  var sanitizeText = function sanitizeText(text) {
357
327
  return String(text).replace(SANITIZE_TEXT_R, function (chr) {
358
328
  return SANITIZE_TEXT_CODES[chr];
359
329
  });
360
330
  };
361
-
362
331
  var UNESCAPE_URL_R = /\\([^0-9A-Za-z\s])/g;
363
-
364
332
  var unescapeUrl = function unescapeUrl(rawUrlString) {
365
333
  return rawUrlString.replace(UNESCAPE_URL_R, "$1");
366
334
  };
335
+
367
336
  /**
368
337
  * Parse some content with the parser `parse`, with state.inline
369
338
  * set to true. Useful for block elements; not generally necessary
370
339
  * to be used by inline elements (where state.inline is already true.
371
340
  */
372
-
373
-
374
341
  var parseInline = function parseInline(parse, content, state) {
375
342
  var isCurrentlyInline = state.inline || false;
376
343
  state.inline = true;
@@ -378,7 +345,6 @@ var parseInline = function parseInline(parse, content, state) {
378
345
  state.inline = isCurrentlyInline;
379
346
  return result;
380
347
  };
381
-
382
348
  var parseBlock = function parseBlock(parse, content, state) {
383
349
  var isCurrentlyInline = state.inline || false;
384
350
  state.inline = false;
@@ -386,50 +352,50 @@ var parseBlock = function parseBlock(parse, content, state) {
386
352
  state.inline = isCurrentlyInline;
387
353
  return result;
388
354
  };
389
-
390
355
  var parseCaptureInline = function parseCaptureInline(capture, parse, state) {
391
356
  return {
392
357
  content: parseInline(parse, capture[1], state)
393
358
  };
394
359
  };
395
-
396
360
  var ignoreCapture = function ignoreCapture() {
397
361
  return {};
398
- }; // recognize a `*` `-`, `+`, `1.`, `2.`... list bullet
399
-
362
+ };
400
363
 
401
- var LIST_BULLET = "(?:[*+-]|\\d+\\.)"; // recognize the start of a list item:
364
+ // recognize a `*` `-`, `+`, `1.`, `2.`... list bullet
365
+ var LIST_BULLET = "(?:[*+-]|\\d+\\.)";
366
+ // recognize the start of a list item:
402
367
  // leading space plus a bullet plus a space (` * `)
403
-
404
368
  var LIST_ITEM_PREFIX = "( *)(" + LIST_BULLET + ") +";
405
- var LIST_ITEM_PREFIX_R = new RegExp("^" + LIST_ITEM_PREFIX); // recognize an individual list item:
369
+ var LIST_ITEM_PREFIX_R = new RegExp("^" + LIST_ITEM_PREFIX);
370
+ // recognize an individual list item:
406
371
  // * hi
407
372
  // this is part of the same item
408
373
  //
409
374
  // as is this, which is a new paragraph in the same item
410
375
  //
411
376
  // * but this is not part of the same item
412
-
413
377
  var LIST_ITEM_R = new RegExp(LIST_ITEM_PREFIX + "[^\\n]*(?:\\n" + "(?!\\1" + LIST_BULLET + " )[^\\n]*)*(\n|$)", "gm");
414
378
  var BLOCK_END_R = /\n{2,}$/;
415
- var INLINE_CODE_ESCAPE_BACKTICKS_R = /^ (?= *`)|(` *) $/g; // recognize the end of a paragraph block inside a list item:
379
+ var INLINE_CODE_ESCAPE_BACKTICKS_R = /^ (?= *`)|(` *) $/g;
380
+ // recognize the end of a paragraph block inside a list item:
416
381
  // two or more newlines at end end of the item
417
-
418
382
  var LIST_BLOCK_END_R = BLOCK_END_R;
419
- var LIST_ITEM_END_R = / *\n+$/; // check whether a list item has paragraphs: if it does,
383
+ var LIST_ITEM_END_R = / *\n+$/;
384
+ // check whether a list item has paragraphs: if it does,
420
385
  // we leave the newlines at the end
421
-
422
- var LIST_R = new RegExp("^( *)(" + LIST_BULLET + ") " + "[\\s\\S]+?(?:\n{2,}(?! )" + "(?!\\1" + LIST_BULLET + " )\\n*" + // the \\s*$ here is so that we can parse the inside of nested
386
+ var LIST_R = new RegExp("^( *)(" + LIST_BULLET + ") " + "[\\s\\S]+?(?:\n{2,}(?! )" + "(?!\\1" + LIST_BULLET + " )\\n*" +
387
+ // the \\s*$ here is so that we can parse the inside of nested
423
388
  // lists, where our content might end before we receive two `\n`s
424
389
  "|\\s*\n*$)");
425
390
  var LIST_LOOKBEHIND_R = /(?:^|\n)( *)$/;
426
-
427
391
  var TABLES = function () {
428
392
  var TABLE_ROW_SEPARATOR_TRIM = /^ *\| *| *\| *$/g;
429
393
  var TABLE_CELL_END_TRIM = / *$/;
430
394
  var TABLE_RIGHT_ALIGN = /^ *-+: *$/;
431
395
  var TABLE_CENTER_ALIGN = /^ *:-+: *$/;
432
- var TABLE_LEFT_ALIGN = /^ *:-+ *$/; // TODO: This needs a real type
396
+ var TABLE_LEFT_ALIGN = /^ *:-+ *$/;
397
+
398
+ // TODO: This needs a real type
433
399
 
434
400
  var parseTableAlignCapture = function parseTableAlignCapture(alignCapture) {
435
401
  if (TABLE_RIGHT_ALIGN.test(alignCapture)) {
@@ -442,16 +408,13 @@ var TABLES = function () {
442
408
  return null;
443
409
  }
444
410
  };
445
-
446
411
  var parseTableAlign = function parseTableAlign(source, parse, state, trimEndSeparators) {
447
412
  if (trimEndSeparators) {
448
413
  source = source.replace(TABLE_ROW_SEPARATOR_TRIM, "");
449
414
  }
450
-
451
415
  var alignText = source.trim().split("|");
452
416
  return alignText.map(parseTableAlignCapture);
453
417
  };
454
-
455
418
  var parseTableRow = function parseTableRow(source, parse, state, trimEndSeparators) {
456
419
  var prevInTable = state.inTable;
457
420
  state.inTable = true;
@@ -469,12 +432,13 @@ var TABLES = function () {
469
432
  if (node.type === "text" && (tableRow[i + 1] == null || tableRow[i + 1].type === "tableSeparator")) {
470
433
  node.content = node.content.replace(TABLE_CELL_END_TRIM, "");
471
434
  }
472
-
435
+ // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'SingleASTNode' is not assignable to parameter of type 'never'.
473
436
  cells[cells.length - 1].push(node);
474
437
  }
475
438
  });
476
439
  return cells;
477
440
  };
441
+
478
442
  /**
479
443
  * @param {string} source
480
444
  * @param {SimpleMarkdown.Parser} parse
@@ -482,21 +446,17 @@ var TABLES = function () {
482
446
  * @param {boolean} trimEndSeparators
483
447
  * @returns {SimpleMarkdown.ASTNode[][]}
484
448
  */
485
-
486
-
487
449
  var parseTableCells = function parseTableCells(source, parse, state, trimEndSeparators) {
488
450
  var rowsText = source.trim().split("\n");
489
451
  return rowsText.map(function (rowText) {
490
- // $FlowFixMe
491
452
  return parseTableRow(rowText, parse, state, trimEndSeparators);
492
453
  });
493
454
  };
455
+
494
456
  /**
495
457
  * @param {boolean} trimEndSeparators
496
458
  * @returns {SimpleMarkdown.SingleNodeParseFunction}
497
459
  */
498
-
499
-
500
460
  var parseTable = function parseTable(trimEndSeparators) {
501
461
  return function (capture, parse, state) {
502
462
  state.inline = true;
@@ -512,7 +472,6 @@ var TABLES = function () {
512
472
  };
513
473
  };
514
474
  };
515
-
516
475
  return {
517
476
  parseTable: parseTable(true),
518
477
  parseNpTable: parseTable(false),
@@ -520,93 +479,83 @@ var TABLES = function () {
520
479
  NPTABLE_REGEX: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/
521
480
  };
522
481
  }();
523
-
524
482
  var LINK_INSIDE = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*";
525
483
  var LINK_HREF_AND_TITLE = "\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*";
526
484
  var AUTOLINK_MAILTO_CHECK_R = /mailto:/i;
527
-
528
485
  var parseRef = function parseRef(capture, state, refNode) {
529
- var ref = (capture[2] || capture[1]).replace(/\s+/g, " ").toLowerCase(); // We store information about previously seen defs on
486
+ var ref = (capture[2] || capture[1]).replace(/\s+/g, " ").toLowerCase();
487
+
488
+ // We store information about previously seen defs on
530
489
  // state._defs (_ to deconflict with client-defined
531
490
  // state). If the def for this reflink/refimage has
532
491
  // already been seen, we can use its target/source
533
492
  // and title here:
534
-
535
493
  if (state._defs && state._defs[ref]) {
536
- var def = state._defs[ref]; // `refNode` can be a link or an image. Both use
494
+ var def = state._defs[ref];
495
+ // `refNode` can be a link or an image. Both use
537
496
  // target and title properties.
538
-
539
497
  refNode.target = def.target;
540
498
  refNode.title = def.title;
541
- } // In case we haven't seen our def yet (or if someone
499
+ }
500
+
501
+ // In case we haven't seen our def yet (or if someone
542
502
  // overwrites that def later on), we add this node
543
503
  // to the list of ref nodes for that def. Then, when
544
504
  // we find the def, we can modify this link/image AST
545
505
  // node :).
546
506
  // I'm sorry.
547
-
548
-
549
507
  state._refs = state._refs || {};
550
508
  state._refs[ref] = state._refs[ref] || [];
551
-
552
509
  state._refs[ref].push(refNode);
553
-
554
510
  return refNode;
555
511
  };
556
-
557
512
  var currOrder = 0;
558
513
  var defaultRules = {
559
514
  Array: {
560
515
  react: function react(arr, output, state) {
561
516
  var oldKey = state.key;
562
- var result = []; // map output over the ast, except group any text
563
- // nodes together into a single string output.
517
+ var result = [];
564
518
 
519
+ // map output over the ast, except group any text
520
+ // nodes together into a single string output.
565
521
  for (var i = 0, key = 0; i < arr.length; i++, key++) {
566
522
  // `key` is our numerical `state.key`, which we increment for
567
523
  // every output node, but don't change for joined text nodes.
568
524
  // (i, however, must change for joined text nodes)
569
525
  state.key = "" + i;
570
526
  var node = arr[i];
571
-
572
527
  if (node.type === "text") {
573
528
  node = {
574
529
  type: "text",
575
530
  content: node.content
576
531
  };
577
-
578
532
  for (; i + 1 < arr.length && arr[i + 1].type === "text"; i++) {
579
533
  node.content += arr[i + 1].content;
580
534
  }
581
535
  }
582
-
583
536
  result.push(output(node, state));
584
537
  }
585
-
586
538
  state.key = oldKey;
587
539
  return result;
588
540
  },
589
541
  html: function html(arr, output, state) {
590
- var result = ""; // map output over the ast, except group any text
591
- // nodes together into a single string output.
542
+ var result = "";
592
543
 
544
+ // map output over the ast, except group any text
545
+ // nodes together into a single string output.
593
546
  for (var i = 0; i < arr.length; i++) {
594
547
  var node = arr[i];
595
-
596
548
  if (node.type === "text") {
597
549
  node = {
598
550
  type: "text",
599
551
  content: node.content
600
552
  };
601
-
602
553
  for (; i + 1 < arr.length && arr[i + 1].type === "text"; i++) {
603
554
  node.content += arr[i + 1].content;
604
555
  }
605
556
  }
606
-
607
557
  result += output(node, state);
608
558
  }
609
-
610
559
  return result;
611
560
  }
612
561
  },
@@ -617,11 +566,9 @@ var defaultRules = {
617
566
  function parse(_x, _x2, _x3) {
618
567
  return _parse.apply(this, arguments);
619
568
  }
620
-
621
569
  parse.toString = function () {
622
570
  return _parse.toString();
623
571
  };
624
-
625
572
  return parse;
626
573
  }(function (capture, parse, state) {
627
574
  return {
@@ -652,11 +599,9 @@ var defaultRules = {
652
599
  function parse(_x4, _x5, _x6) {
653
600
  return _parse2.apply(this, arguments);
654
601
  }
655
-
656
602
  parse.toString = function () {
657
603
  return _parse2.toString();
658
604
  };
659
-
660
605
  return parse;
661
606
  }(function (capture, parse, state) {
662
607
  return {
@@ -686,11 +631,9 @@ var defaultRules = {
686
631
  function parse(_x7, _x8, _x9) {
687
632
  return _parse3.apply(this, arguments);
688
633
  }
689
-
690
634
  parse.toString = function () {
691
635
  return _parse3.toString();
692
636
  };
693
-
694
637
  return parse;
695
638
  }(function (capture, parse, state) {
696
639
  var content = capture[0].replace(/^ /gm, "").replace(/\n+$/, "");
@@ -723,11 +666,9 @@ var defaultRules = {
723
666
  function parse(_x10, _x11, _x12) {
724
667
  return _parse4.apply(this, arguments);
725
668
  }
726
-
727
669
  parse.toString = function () {
728
670
  return _parse4.toString();
729
671
  };
730
-
731
672
  return parse;
732
673
  }(function (capture, parse, state) {
733
674
  return {
@@ -746,11 +687,9 @@ var defaultRules = {
746
687
  function parse(_x13, _x14, _x15) {
747
688
  return _parse5.apply(this, arguments);
748
689
  }
749
-
750
690
  parse.toString = function () {
751
691
  return _parse5.toString();
752
692
  };
753
-
754
693
  return parse;
755
694
  }(function (capture, parse, state) {
756
695
  var content = capture[0].replace(/^ *> ?/gm, "");
@@ -782,7 +721,6 @@ var defaultRules = {
782
721
  var prevCaptureStr = state.prevCapture == null ? "" : state.prevCapture[0];
783
722
  var isStartOfLineCapture = LIST_LOOKBEHIND_R.exec(prevCaptureStr);
784
723
  var isListBlock = state._list || !state.inline;
785
-
786
724
  if (isStartOfLineCapture && isListBlock) {
787
725
  source = isStartOfLineCapture[1] + source;
788
726
  return LIST_R.exec(source);
@@ -794,31 +732,38 @@ var defaultRules = {
794
732
  function parse(_x16, _x17, _x18) {
795
733
  return _parse6.apply(this, arguments);
796
734
  }
797
-
798
735
  parse.toString = function () {
799
736
  return _parse6.toString();
800
737
  };
801
-
802
738
  return parse;
803
739
  }(function (capture, parse, state) {
804
740
  var bullet = capture[2];
805
741
  var ordered = bullet.length > 1;
806
742
  var start = ordered ? +bullet : undefined;
807
- var items = capture[0].replace(LIST_BLOCK_END_R, "\n").match(LIST_ITEM_R); // We know this will match here, because of how the regexes are
743
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'RegExpMatchArray | null' is not assignable to type 'string[]'.
744
+ var items = capture[0].replace(LIST_BLOCK_END_R, "\n").match(LIST_ITEM_R);
745
+
746
+ // We know this will match here, because of how the regexes are
808
747
  // defined
809
748
 
810
749
  var lastItemWasAParagraph = false;
811
750
  var itemContent = items.map(function (item, i) {
812
751
  // We need to see how far indented this item is:
813
752
  var prefixCapture = LIST_ITEM_PREFIX_R.exec(item);
814
- var space = prefixCapture ? prefixCapture[0].length : 0; // And then we construct a regex to "unindent" the subsequent
753
+ var space = prefixCapture ? prefixCapture[0].length : 0;
754
+ // And then we construct a regex to "unindent" the subsequent
815
755
  // lines of the items by that amount:
756
+ var spaceRegex = new RegExp("^ {1," + space + "}", "gm");
816
757
 
817
- var spaceRegex = new RegExp("^ {1," + space + "}", "gm"); // Before processing the item, we need a couple things
758
+ // Before processing the item, we need a couple things
759
+ var content = item
760
+ // remove indents on trailing lines:
761
+ .replace(spaceRegex, "")
762
+ // remove the bullet:
763
+ .replace(LIST_ITEM_PREFIX_R, "");
764
+
765
+ // I'm not sur4 why this is necessary again?
818
766
 
819
- var content = item // remove indents on trailing lines:
820
- .replace(spaceRegex, "") // remove the bullet:
821
- .replace(LIST_ITEM_PREFIX_R, ""); // I'm not sur4 why this is necessary again?
822
767
  // Handling "loose" lists, like:
823
768
  //
824
769
  // * this is wrapped in a paragraph
@@ -826,27 +771,28 @@ var defaultRules = {
826
771
  // * as is this
827
772
  //
828
773
  // * as is this
829
-
830
774
  var isLastItem = i === items.length - 1;
831
- var containsBlocks = content.indexOf("\n\n") !== -1; // Any element in a list is a block if it contains multiple
775
+ var containsBlocks = content.indexOf("\n\n") !== -1;
776
+
777
+ // Any element in a list is a block if it contains multiple
832
778
  // newlines. The last element in the list can also be a block
833
779
  // if the previous item in the list was a block (this is
834
780
  // because non-last items in the list can end with \n\n, but
835
781
  // the last item can't, so we just "inherit" this property
836
782
  // from our previous element).
837
-
838
783
  var thisItemIsAParagraph = containsBlocks || isLastItem && lastItemWasAParagraph;
839
- lastItemWasAParagraph = thisItemIsAParagraph; // backup our state for restoration afterwards. We're going to
784
+ lastItemWasAParagraph = thisItemIsAParagraph;
785
+
786
+ // backup our state for restoration afterwards. We're going to
840
787
  // want to set state._list to true, and state.inline depending
841
788
  // on our list's looseness.
842
-
843
789
  var oldStateInline = state.inline;
844
790
  var oldStateList = state._list;
845
- state._list = true; // Parse inline if we're in a tight list, or block if we're in
846
- // a loose list.
791
+ state._list = true;
847
792
 
793
+ // Parse inline if we're in a tight list, or block if we're in
794
+ // a loose list.
848
795
  var adjustedContent;
849
-
850
796
  if (thisItemIsAParagraph) {
851
797
  state.inline = false;
852
798
  adjustedContent = content.replace(LIST_ITEM_END_R, "\n\n");
@@ -854,9 +800,9 @@ var defaultRules = {
854
800
  state.inline = true;
855
801
  adjustedContent = content.replace(LIST_ITEM_END_R, "");
856
802
  }
803
+ var result = parse(adjustedContent, state);
857
804
 
858
- var result = parse(adjustedContent, state); // Restore our state before returning
859
-
805
+ // Restore our state before returning
860
806
  state.inline = oldStateInline;
861
807
  state._list = oldStateList;
862
808
  return result;
@@ -899,43 +845,43 @@ var defaultRules = {
899
845
  function parse(_x19, _x20, _x21) {
900
846
  return _parse7.apply(this, arguments);
901
847
  }
902
-
903
848
  parse.toString = function () {
904
849
  return _parse7.toString();
905
850
  };
906
-
907
851
  return parse;
908
852
  }(function (capture, parse, state) {
909
853
  var def = capture[1].replace(/\s+/g, " ").toLowerCase();
910
854
  var target = capture[2];
911
- var title = capture[3]; // Look for previous links/images using this def
855
+ var title = capture[3];
856
+
857
+ // Look for previous links/images using this def
912
858
  // If any links/images using this def have already been declared,
913
859
  // they will have added themselves to the state._refs[def] list
914
860
  // (_ to deconflict with client-defined state). We look through
915
861
  // that list of reflinks for this def, and modify those AST nodes
916
862
  // with our newly found information now.
917
863
  // Sorry :(.
918
-
919
864
  if (state._refs && state._refs[def]) {
920
865
  // `refNode` can be a link or an image
921
866
  state._refs[def].forEach(function (refNode) {
922
867
  refNode.target = target;
923
868
  refNode.title = title;
924
869
  });
925
- } // Add this def to our map of defs for any future links/images
870
+ }
871
+
872
+ // Add this def to our map of defs for any future links/images
926
873
  // In case we haven't found any or all of the refs referring to
927
874
  // this def yet, we add our def to the table of known defs, so
928
875
  // that future reflinks can modify themselves appropriately with
929
876
  // this information.
930
-
931
-
932
877
  state._defs = state._defs || {};
933
878
  state._defs[def] = {
934
879
  target: target,
935
880
  title: title
936
- }; // return the relevant parsed information
937
- // for debugging only.
881
+ };
938
882
 
883
+ // return the relevant parsed information
884
+ // for debugging only.
939
885
  return {
940
886
  def: def,
941
887
  target: target,
@@ -959,7 +905,6 @@ var defaultRules = {
959
905
  textAlign: node.align[colIndex]
960
906
  };
961
907
  };
962
-
963
908
  var headers = node.header.map(function (content, i) {
964
909
  return reactElement("th", "" + i, {
965
910
  style: getStyle(i),
@@ -991,7 +936,6 @@ var defaultRules = {
991
936
  var getStyle = function getStyle(colIndex) {
992
937
  return node.align[colIndex] == null ? "" : "text-align:" + node.align[colIndex] + ";";
993
938
  };
994
-
995
939
  var headers = node.header.map(function (content, i) {
996
940
  return htmlTag("th", output(content, state), {
997
941
  style: getStyle(i),
@@ -1050,11 +994,9 @@ var defaultRules = {
1050
994
  function parse(_x22, _x23, _x24) {
1051
995
  return _parse8.apply(this, arguments);
1052
996
  }
1053
-
1054
997
  parse.toString = function () {
1055
998
  return _parse8.toString();
1056
999
  };
1057
-
1058
1000
  return parse;
1059
1001
  }(function (capture, parse, state) {
1060
1002
  return {
@@ -1072,7 +1014,6 @@ var defaultRules = {
1072
1014
  if (!state.inTable) {
1073
1015
  return null;
1074
1016
  }
1075
-
1076
1017
  return /^ *\| */.exec(source);
1077
1018
  },
1078
1019
  parse: function parse() {
@@ -1095,11 +1036,9 @@ var defaultRules = {
1095
1036
  function parse(_x25, _x26, _x27) {
1096
1037
  return _parse9.apply(this, arguments);
1097
1038
  }
1098
-
1099
1039
  parse.toString = function () {
1100
1040
  return _parse9.toString();
1101
1041
  };
1102
-
1103
1042
  return parse;
1104
1043
  }(function (capture, parse, state) {
1105
1044
  return {
@@ -1121,20 +1060,18 @@ var defaultRules = {
1121
1060
  function parse(_x28, _x29, _x30) {
1122
1061
  return _parse10.apply(this, arguments);
1123
1062
  }
1124
-
1125
1063
  parse.toString = function () {
1126
1064
  return _parse10.toString();
1127
1065
  };
1128
-
1129
1066
  return parse;
1130
1067
  }(function (capture, parse, state) {
1131
1068
  var address = capture[1];
1132
- var target = capture[1]; // Check for a `mailto:` already existing in the link:
1069
+ var target = capture[1];
1133
1070
 
1071
+ // Check for a `mailto:` already existing in the link:
1134
1072
  if (!AUTOLINK_MAILTO_CHECK_R.test(target)) {
1135
1073
  target = "mailto:" + target;
1136
1074
  }
1137
-
1138
1075
  return {
1139
1076
  type: "link",
1140
1077
  content: [{
@@ -1154,11 +1091,9 @@ var defaultRules = {
1154
1091
  function parse(_x31, _x32, _x33) {
1155
1092
  return _parse11.apply(this, arguments);
1156
1093
  }
1157
-
1158
1094
  parse.toString = function () {
1159
1095
  return _parse11.toString();
1160
1096
  };
1161
-
1162
1097
  return parse;
1163
1098
  }(function (capture, parse, state) {
1164
1099
  return {
@@ -1181,11 +1116,9 @@ var defaultRules = {
1181
1116
  function parse(_x34, _x35, _x36) {
1182
1117
  return _parse12.apply(this, arguments);
1183
1118
  }
1184
-
1185
1119
  parse.toString = function () {
1186
1120
  return _parse12.toString();
1187
1121
  };
1188
-
1189
1122
  return parse;
1190
1123
  }(function (capture, parse, state) {
1191
1124
  var link = {
@@ -1217,11 +1150,9 @@ var defaultRules = {
1217
1150
  function parse(_x37, _x38, _x39) {
1218
1151
  return _parse13.apply(this, arguments);
1219
1152
  }
1220
-
1221
1153
  parse.toString = function () {
1222
1154
  return _parse13.toString();
1223
1155
  };
1224
-
1225
1156
  return parse;
1226
1157
  }(function (capture, parse, state) {
1227
1158
  var image = {
@@ -1249,18 +1180,18 @@ var defaultRules = {
1249
1180
  },
1250
1181
  reflink: {
1251
1182
  order: currOrder++,
1252
- match: inlineRegex(new RegExp( // The first [part] of the link
1253
- "^\\[(" + LINK_INSIDE + ")\\]" + // The [ref] target of the link
1183
+ match: inlineRegex(new RegExp(
1184
+ // The first [part] of the link
1185
+ "^\\[(" + LINK_INSIDE + ")\\]" +
1186
+ // The [ref] target of the link
1254
1187
  "\\s*\\[([^\\]]*)\\]")),
1255
1188
  parse: function (_parse14) {
1256
1189
  function parse(_x40, _x41, _x42) {
1257
1190
  return _parse14.apply(this, arguments);
1258
1191
  }
1259
-
1260
1192
  parse.toString = function () {
1261
1193
  return _parse14.toString();
1262
1194
  };
1263
-
1264
1195
  return parse;
1265
1196
  }(function (capture, parse, state) {
1266
1197
  return parseRef(capture, state, {
@@ -1273,18 +1204,18 @@ var defaultRules = {
1273
1204
  },
1274
1205
  refimage: {
1275
1206
  order: currOrder++,
1276
- match: inlineRegex(new RegExp( // The first [part] of the link
1277
- "^!\\[(" + LINK_INSIDE + ")\\]" + // The [ref] target of the link
1207
+ match: inlineRegex(new RegExp(
1208
+ // The first [part] of the link
1209
+ "^!\\[(" + LINK_INSIDE + ")\\]" +
1210
+ // The [ref] target of the link
1278
1211
  "\\s*\\[([^\\]]*)\\]")),
1279
1212
  parse: function (_parse15) {
1280
1213
  function parse(_x43, _x44, _x45) {
1281
1214
  return _parse15.apply(this, arguments);
1282
1215
  }
1283
-
1284
1216
  parse.toString = function () {
1285
1217
  return _parse15.toString();
1286
1218
  };
1287
-
1288
1219
  return parse;
1289
1220
  }(function (capture, parse, state) {
1290
1221
  return parseRef(capture, state, {
@@ -1296,21 +1227,28 @@ var defaultRules = {
1296
1227
  html: null
1297
1228
  },
1298
1229
  em: {
1299
- order: currOrder
1300
- /* same as strong/u */
1301
- ,
1302
- match: inlineRegex(new RegExp( // only match _s surrounding words.
1303
- "^\\b_" + "((?:__|\\\\[\\s\\S]|[^\\\\_])+?)_" + "\\b" + // Or match *s:
1304
- "|" + // Only match *s that are followed by a non-space:
1305
- "^\\*(?=\\S)(" + // Match at least one of:
1306
- "(?:" + // - `**`: so that bolds inside italics don't close the
1230
+ order: currOrder /* same as strong/u */,
1231
+ match: inlineRegex(new RegExp(
1232
+ // only match _s surrounding words.
1233
+ "^\\b_" + "((?:__|\\\\[\\s\\S]|[^\\\\_])+?)_" + "\\b" +
1234
+ // Or match *s:
1235
+ "|" +
1236
+ // Only match *s that are followed by a non-space:
1237
+ "^\\*(?=\\S)(" +
1238
+ // Match at least one of:
1239
+ "(?:" +
1240
+ // - `**`: so that bolds inside italics don't close the
1307
1241
  // italics
1308
- "\\*\\*|" + // - escape sequence: so escaped *s don't close us
1309
- "\\\\[\\s\\S]|" + // - whitespace: followed by a non-* (we don't
1242
+ "\\*\\*|" +
1243
+ // - escape sequence: so escaped *s don't close us
1244
+ "\\\\[\\s\\S]|" +
1245
+ // - whitespace: followed by a non-* (we don't
1310
1246
  // want ' *' to close an italics--it might
1311
1247
  // start a list)
1312
- "\\s+(?:\\\\[\\s\\S]|[^\\s\\*\\\\]|\\*\\*)|" + // - non-whitespace, non-*, non-backslash characters
1313
- "[^\\s\\*\\\\]" + ")+?" + // followed by a non-space, non-* then *
1248
+ "\\s+(?:\\\\[\\s\\S]|[^\\s\\*\\\\]|\\*\\*)|" +
1249
+ // - non-whitespace, non-*, non-backslash characters
1250
+ "[^\\s\\*\\\\]" + ")+?" +
1251
+ // followed by a non-space, non-* then *
1314
1252
  ")\\*(?!\\*)")),
1315
1253
  quality: function quality(capture) {
1316
1254
  // precedence by length, `em` wins ties:
@@ -1320,11 +1258,9 @@ var defaultRules = {
1320
1258
  function parse(_x46, _x47, _x48) {
1321
1259
  return _parse16.apply(this, arguments);
1322
1260
  }
1323
-
1324
1261
  parse.toString = function () {
1325
1262
  return _parse16.toString();
1326
1263
  };
1327
-
1328
1264
  return parse;
1329
1265
  }(function (capture, parse, state) {
1330
1266
  return {
@@ -1341,9 +1277,7 @@ var defaultRules = {
1341
1277
  }
1342
1278
  },
1343
1279
  strong: {
1344
- order: currOrder
1345
- /* same as em */
1346
- ,
1280
+ order: currOrder /* same as em */,
1347
1281
  match: inlineRegex(/^\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)/),
1348
1282
  quality: function quality(capture) {
1349
1283
  // precedence by length, wins ties vs `u`:
@@ -1360,9 +1294,7 @@ var defaultRules = {
1360
1294
  }
1361
1295
  },
1362
1296
  u: {
1363
- order: currOrder++
1364
- /* same as em&strong; increment for next rule */
1365
- ,
1297
+ order: currOrder++ /* same as em&strong; increment for next rule */,
1366
1298
  match: inlineRegex(/^__((?:\\[\s\S]|[^\\])+?)__(?!_)/),
1367
1299
  quality: function quality(capture) {
1368
1300
  // precedence by length, loses all ties
@@ -1398,11 +1330,9 @@ var defaultRules = {
1398
1330
  function parse(_x49, _x50, _x51) {
1399
1331
  return _parse17.apply(this, arguments);
1400
1332
  }
1401
-
1402
1333
  parse.toString = function () {
1403
1334
  return _parse17.toString();
1404
1335
  };
1405
-
1406
1336
  return parse;
1407
1337
  }(function (capture, parse, state) {
1408
1338
  return {
@@ -1440,11 +1370,9 @@ var defaultRules = {
1440
1370
  function parse(_x52, _x53, _x54) {
1441
1371
  return _parse18.apply(this, arguments);
1442
1372
  }
1443
-
1444
1373
  parse.toString = function () {
1445
1374
  return _parse18.toString();
1446
1375
  };
1447
-
1448
1376
  return parse;
1449
1377
  }(function (capture, parse, state) {
1450
1378
  return {
@@ -1459,65 +1387,61 @@ var defaultRules = {
1459
1387
  }
1460
1388
  }
1461
1389
  };
1462
- /** (deprecated) */
1463
1390
 
1464
- var ruleOutput = function ruleOutput( // $FlowFixMe
1391
+ /** (deprecated) */
1392
+ var ruleOutput = function ruleOutput(
1393
+ // $FlowFixMe
1465
1394
  rules, property) {
1466
1395
  if (!property && typeof console !== "undefined") {
1467
1396
  console.warn("simple-markdown ruleOutput should take 'react' or " + "'html' as the second argument.");
1468
1397
  }
1469
-
1470
1398
  var nestedRuleOutput = function nestedRuleOutput(ast, outputFunc, state) {
1399
+ // @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
1400
+ // Type 'unknown' has no call signatures.
1471
1401
  return rules[ast.type][property](ast, outputFunc, state);
1472
1402
  };
1473
-
1474
1403
  return nestedRuleOutput;
1475
1404
  };
1405
+
1476
1406
  /** (deprecated)
1477
1407
  */
1478
-
1479
-
1480
1408
  var reactFor = function reactFor(outputFunc) {
1481
1409
  var nestedOutput = function nestedOutput(ast, state) {
1482
1410
  state = state || {};
1483
-
1484
1411
  if (Array.isArray(ast)) {
1485
1412
  var oldKey = state.key;
1486
- var result = []; // map nestedOutput over the ast, except group any text
1487
- // nodes together into a single string output.
1413
+ var result = [];
1488
1414
 
1415
+ // map nestedOutput over the ast, except group any text
1416
+ // nodes together into a single string output.
1489
1417
  var lastResult = null;
1490
-
1491
1418
  for (var i = 0; i < ast.length; i++) {
1492
1419
  state.key = "" + i;
1493
1420
  var nodeOut = nestedOutput(ast[i], state);
1494
-
1495
1421
  if (typeof nodeOut === "string" && typeof lastResult === "string") {
1422
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
1496
1423
  lastResult = lastResult + nodeOut;
1497
1424
  result[result.length - 1] = lastResult;
1498
1425
  } else {
1499
1426
  result.push(nodeOut);
1427
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'ReactNode' is not assignable to type 'null'.
1500
1428
  lastResult = nodeOut;
1501
1429
  }
1502
1430
  }
1503
-
1504
1431
  state.key = oldKey;
1505
1432
  return result;
1506
1433
  } else {
1507
1434
  return outputFunc(ast, nestedOutput, state);
1508
1435
  }
1509
1436
  };
1510
-
1511
1437
  return nestedOutput;
1512
1438
  };
1439
+
1513
1440
  /** (deprecated)
1514
1441
  */
1515
-
1516
-
1517
1442
  var htmlFor = function htmlFor(outputFunc) {
1518
1443
  var nestedOutput = function nestedOutput(ast, state) {
1519
1444
  state = state || {};
1520
-
1521
1445
  if (Array.isArray(ast)) {
1522
1446
  return ast.map(function (node) {
1523
1447
  return nestedOutput(node, state);
@@ -1526,99 +1450,84 @@ var htmlFor = function htmlFor(outputFunc) {
1526
1450
  return outputFunc(ast, nestedOutput, state);
1527
1451
  }
1528
1452
  };
1529
-
1530
1453
  return nestedOutput;
1531
1454
  };
1532
-
1533
1455
  var outputFor = function outputFor(rules, property) {
1534
1456
  var defaultState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1535
-
1536
1457
  if (!property) {
1537
1458
  throw new Error("simple-markdown: outputFor: `property` must be " + "defined. " + "if you just upgraded, you probably need to replace `outputFor` " + "with `reactFor`");
1538
1459
  }
1460
+ var latestState;
1461
+ var arrayRule = rules.Array || defaultRules.Array;
1539
1462
 
1540
- var latestState; // $FlowFixMe[incompatible-type]
1541
-
1542
- var arrayRule = rules.Array || defaultRules.Array; // Tricks to convince tsc that this var is not null:
1543
-
1463
+ // Tricks to convince tsc that this var is not null:
1464
+ // @ts-expect-error [FEI-5003] - TS2538 - Type 'symbol' cannot be used as an index type.
1544
1465
  var arrayRuleCheck = arrayRule[property];
1545
-
1546
1466
  if (!arrayRuleCheck) {
1547
- throw new Error("simple-markdown: outputFor: to join nodes of type `" + property + "` you must provide an `Array:` joiner rule with that type, " + "Please see the docs for details on specifying an Array rule.");
1467
+ throw new Error("simple-markdown: outputFor: to join nodes of type `" +
1468
+ // @ts-expect-error [FEI-5003] - TS2469 - The '+' operator cannot be applied to type 'symbol'.
1469
+ property + "` you must provide an `Array:` joiner rule with that type, " + "Please see the docs for details on specifying an Array rule.");
1548
1470
  }
1549
-
1550
1471
  var arrayRuleOutput = arrayRuleCheck;
1551
-
1552
1472
  var nestedOutput = function nestedOutput(ast, state) {
1553
1473
  state = state || latestState;
1554
1474
  latestState = state;
1555
-
1556
1475
  if (Array.isArray(ast)) {
1557
1476
  return arrayRuleOutput(ast, nestedOutput, state);
1558
1477
  } else {
1478
+ // @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
1479
+ // Type 'unknown' has no call signatures.
1559
1480
  return rules[ast.type][property](ast, nestedOutput, state);
1560
1481
  }
1561
1482
  };
1562
-
1563
1483
  var outerOutput = function outerOutput(ast, state) {
1564
1484
  latestState = populateInitialState(state, defaultState);
1565
1485
  return nestedOutput(ast, latestState);
1566
1486
  };
1567
-
1568
1487
  return outerOutput;
1569
- }; // $FlowFixMe[incompatible-call]
1570
-
1488
+ };
1571
1489
 
1490
+ // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'DefaultRules' is not assignable to parameter of type 'ParserRules'.
1572
1491
  var defaultRawParse = parserFor(defaultRules);
1573
-
1574
1492
  var defaultBlockParse = function defaultBlockParse(source, state) {
1575
1493
  state = state || {};
1576
1494
  state.inline = false;
1577
1495
  return defaultRawParse(source, state);
1578
1496
  };
1579
-
1580
1497
  var defaultInlineParse = function defaultInlineParse(source, state) {
1581
1498
  state = state || {};
1582
1499
  state.inline = true;
1583
1500
  return defaultRawParse(source, state);
1584
1501
  };
1585
-
1586
1502
  var defaultImplicitParse = function defaultImplicitParse(source, state) {
1587
1503
  var isBlock = BLOCK_END_R.test(source);
1588
1504
  state = state || {};
1589
1505
  state.inline = !isBlock;
1590
1506
  return defaultRawParse(source, state);
1591
- }; // $FlowFixMe[incompatible-call]
1592
-
1593
-
1594
- var defaultReactOutput = outputFor(defaultRules, "react"); // $FlowFixMe[incompatible-call]
1595
-
1507
+ };
1508
+ var defaultReactOutput = outputFor(defaultRules, "react");
1596
1509
  var defaultHtmlOutput = outputFor(defaultRules, "html");
1597
-
1598
1510
  var markdownToReact = function markdownToReact(source, state) {
1599
1511
  return defaultReactOutput(defaultBlockParse(source, state), state);
1600
1512
  };
1601
-
1602
1513
  var markdownToHtml = function markdownToHtml(source, state) {
1603
1514
  return defaultHtmlOutput(defaultBlockParse(source, state), state);
1604
- }; // TODO: This needs definition
1515
+ };
1605
1516
 
1517
+ // TODO: This needs definition
1606
1518
 
1607
1519
  var ReactMarkdown = function ReactMarkdown(props) {
1608
1520
  var divProps = {};
1609
-
1610
1521
  for (var prop in props) {
1611
- if (prop !== "source" && // $FlowFixMe
1522
+ if (prop !== "source" &&
1523
+ // $FlowFixMe
1612
1524
  Object.prototype.hasOwnProperty.call(props, prop)) {
1613
1525
  divProps[prop] = props[prop];
1614
1526
  }
1615
1527
  }
1616
-
1617
1528
  divProps.children = markdownToReact(props.source);
1618
1529
  return reactElement("div", null, divProps);
1619
1530
  };
1620
-
1621
- // $FlowFixMe
1622
1531
  var SimpleMarkdown = {
1623
1532
  defaultRules: defaultRules,
1624
1533
  parserFor: parserFor,
@@ -1631,6 +1540,7 @@ var SimpleMarkdown = {
1631
1540
  // default wrappers:
1632
1541
  markdownToReact: markdownToReact,
1633
1542
  markdownToHtml: markdownToHtml,
1543
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'FC<any>' is not assignable to type '(props: { [key: string]: any; source: string; }) => ReactElement'.
1634
1544
  ReactMarkdown: ReactMarkdown,
1635
1545
  defaultBlockParse: defaultBlockParse,
1636
1546
  defaultInlineParse: defaultInlineParse,
@@ -1652,15 +1562,19 @@ var SimpleMarkdown = {
1652
1562
  if (typeof console !== "undefined") {
1653
1563
  console.warn("defaultParse is deprecated, please use `defaultImplicitParse`");
1654
1564
  }
1655
-
1656
- return defaultImplicitParse.apply(null, arguments);
1565
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1566
+ args[_key] = arguments[_key];
1567
+ }
1568
+ return defaultImplicitParse.apply(null, args);
1657
1569
  },
1658
1570
  defaultOutput: function defaultOutput() {
1659
1571
  if (typeof console !== "undefined") {
1660
1572
  console.warn("defaultOutput is deprecated, please use `defaultReactOutput`");
1661
1573
  }
1662
-
1663
- return defaultReactOutput.apply(null, arguments);
1574
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1575
+ args[_key2] = arguments[_key2];
1576
+ }
1577
+ return defaultReactOutput.apply(null, args);
1664
1578
  }
1665
1579
  };
1666
1580