@khanacademy/simple-markdown 0.8.6 → 0.9.1

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.
@@ -1,6 +1,4 @@
1
- /* eslint-disable prefer-spread, no-regex-spaces, no-unused-vars, guard-for-in, no-console, no-var */
2
- // @flow
3
-
1
+ /* eslint-disable prefer-spread, no-regex-spaces, @typescript-eslint/no-unused-vars, guard-for-in, no-console, no-var */
4
2
  /**
5
3
  * Simple-Markdown
6
4
  * ===============
@@ -20,42 +18,52 @@
20
18
  * Many of the regexes and original logic has been adapted from
21
19
  * the wonderful [marked.js](https://github.com/chjj/marked)
22
20
  */
21
+ import * as React from "react";
23
22
 
24
- // Flow Type Definitions:
23
+ // Type Definitions:
25
24
 
26
25
  type Capture =
27
- | (Array<string> & {index: number})
28
- | (Array<string> & {index?: number});
26
+ | (Array<string> & {
27
+ index: number;
28
+ })
29
+ | (Array<string> & {
30
+ index?: number;
31
+ });
29
32
 
30
- type Attr = string | number | boolean | null | void;
33
+ type Attr = string | number | boolean | null | undefined;
31
34
 
32
35
  type SingleASTNode = {
33
- type: string,
34
- [string]: any,
36
+ type: string;
37
+ [key: string]: any;
35
38
  };
36
39
 
37
40
  type UnTypedASTNode = {
38
- [string]: any,
41
+ [key: string]: any;
39
42
  };
40
43
 
41
44
  type ASTNode = SingleASTNode | Array<SingleASTNode>;
42
45
 
43
46
  type State = {
44
- key?: string | number | void,
45
- inline?: ?boolean,
46
- [string]: any,
47
+ key?: string | number | undefined;
48
+ inline?: boolean | null | undefined;
49
+ [key: string]: any;
47
50
  };
48
51
 
49
- type ReactElement = React$Element<any>;
50
- type ReactElements = React$Node;
52
+ type ReactElement = React.ReactElement<any>;
53
+ type ReactElements = React.ReactNode;
51
54
 
52
- type MatchFunction = {regex?: RegExp} & ((
55
+ type MatchFunction = {
56
+ regex?: RegExp;
57
+ } & ((
53
58
  source: string,
54
59
  state: State,
55
60
  prevCapture: string,
56
- ) => ?Capture);
61
+ ) => Capture | null | undefined);
57
62
 
58
- type Parser = (source: string, state?: ?State) => Array<SingleASTNode>;
63
+ type Parser = (
64
+ source: string,
65
+ state?: State | null | undefined,
66
+ ) => Array<SingleASTNode>;
59
67
 
60
68
  type ParseFunction = (
61
69
  capture: Capture,
@@ -69,7 +77,10 @@ type SingleNodeParseFunction = (
69
77
  state: State,
70
78
  ) => UnTypedASTNode;
71
79
 
72
- type Output<Result> = (node: ASTNode, state?: ?State) => Result;
80
+ type Output<Result> = (
81
+ node: ASTNode,
82
+ state?: State | null | undefined,
83
+ ) => Result;
73
84
 
74
85
  type NodeOutput<Result> = (
75
86
  node: SingleASTNode,
@@ -89,17 +100,25 @@ type HtmlOutput = Output<string>;
89
100
  type HtmlNodeOutput = NodeOutput<string>;
90
101
 
91
102
  type ParserRule = {
92
- +order: number,
93
- +match: MatchFunction,
94
- +quality?: (capture: Capture, state: State, prevCapture: string) => number,
95
- +parse: ParseFunction,
103
+ readonly order: number;
104
+ readonly match: MatchFunction;
105
+ readonly quality?: (
106
+ capture: Capture,
107
+ state: State,
108
+ prevCapture: string,
109
+ ) => number;
110
+ readonly parse: ParseFunction;
96
111
  };
97
112
 
98
113
  type SingleNodeParserRule = {
99
- +order: number,
100
- +match: MatchFunction,
101
- +quality?: (capture: Capture, state: State, prevCapture: string) => number,
102
- +parse: SingleNodeParseFunction,
114
+ readonly order: number;
115
+ readonly match: MatchFunction;
116
+ readonly quality?: (
117
+ capture: Capture,
118
+ state: State,
119
+ prevCapture: string,
120
+ ) => number;
121
+ readonly parse: SingleNodeParseFunction;
103
122
  };
104
123
 
105
124
  type ReactOutputRule = {
@@ -107,59 +126,66 @@ type ReactOutputRule = {
107
126
  // legal as long as no parsers return an AST node matching that rule.
108
127
  // We don't use ? because this makes it be explicitly defined as either
109
128
  // a valid function or null, so it can't be forgotten.
110
- +react: ReactNodeOutput | null,
129
+ readonly react: ReactNodeOutput | null;
111
130
  };
112
131
 
113
132
  type HtmlOutputRule = {
114
- +html: HtmlNodeOutput | null,
133
+ readonly html: HtmlNodeOutput | null;
115
134
  };
116
135
 
117
136
  type ArrayRule = {
118
- +react?: ArrayNodeOutput<ReactElements>,
119
- +html?: ArrayNodeOutput<string>,
120
- +[string]: ArrayNodeOutput<any>,
137
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'react' of type 'ArrayNodeOutput<ReactNode> | undefined' is not assignable to 'string' index type 'ArrayNodeOutput<any>'.
138
+ readonly react?: ArrayNodeOutput<ReactElements>;
139
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'html' of type 'ArrayNodeOutput<string> | undefined' is not assignable to 'string' index type 'ArrayNodeOutput<any>'.
140
+ readonly html?: ArrayNodeOutput<string>;
141
+ readonly [key: string]: ArrayNodeOutput<any>;
121
142
  };
122
143
 
123
144
  type ParserRules = {
124
- +Array?: ArrayRule,
125
- +[type: string]: ParserRule,
145
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'Array' of type 'ArrayRule | undefined' is not assignable to 'string' index type 'ParserRule'.
146
+ readonly Array?: ArrayRule;
147
+ readonly [type: string]: ParserRule;
126
148
  };
127
149
 
128
150
  type OutputRules<Rule> = {
129
- +Array?: ArrayRule,
130
- +[type: string]: Rule,
151
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'Array' of type 'ArrayRule | undefined' is not assignable to 'string' index type 'Rule'.
152
+ readonly Array?: ArrayRule;
153
+ readonly [type: string]: Rule;
131
154
  };
132
155
  type Rules<OutputRule> = {
133
- +Array?: ArrayRule,
134
- +[type: string]: ParserRule & OutputRule,
156
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'Array' of type 'ArrayRule | undefined' is not assignable to 'string' index type 'ParserRule & OutputRule'.
157
+ readonly Array?: ArrayRule;
158
+ readonly [type: string]: ParserRule & OutputRule;
135
159
  };
136
160
  type ReactRules = {
137
- +Array?: {
138
- +react: ArrayNodeOutput<ReactElements>,
139
- },
140
- +[type: string]: ParserRule & ReactOutputRule,
161
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'Array' of type '{ readonly react: ArrayNodeOutput<ReactNode>; } | undefined' is not assignable to 'string' index type 'ParserRule & ReactOutputRule'.
162
+ readonly Array?: {
163
+ readonly react: ArrayNodeOutput<ReactElements>;
164
+ };
165
+ readonly [type: string]: ParserRule & ReactOutputRule;
141
166
  };
142
167
  type HtmlRules = {
143
- +Array?: {
144
- +html: ArrayNodeOutput<string>,
145
- },
146
- +[type: string]: ParserRule & HtmlOutputRule,
168
+ // @ts-expect-error [FEI-5003] - TS2411 - Property 'Array' of type '{ readonly html: ArrayNodeOutput<string>; } | undefined' is not assignable to 'string' index type 'ParserRule & HtmlOutputRule'.
169
+ readonly Array?: {
170
+ readonly html: ArrayNodeOutput<string>;
171
+ };
172
+ readonly [type: string]: ParserRule & HtmlOutputRule;
147
173
  };
148
174
 
149
175
  // We want to clarify our defaultRules types a little bit more so clients can
150
176
  // reuse defaultRules built-ins. So we make some stronger guarantess when
151
177
  // we can:
152
178
  type NonNullReactOutputRule = {
153
- +react: ReactNodeOutput,
179
+ readonly react: ReactNodeOutput;
154
180
  };
155
181
  type ElementReactOutputRule = {
156
- +react: NodeOutput<ReactElement>,
182
+ readonly react: NodeOutput<ReactElement>;
157
183
  };
158
184
  type TextReactOutputRule = {
159
- +react: NodeOutput<string>,
185
+ readonly react: NodeOutput<string>;
160
186
  };
161
187
  type NonNullHtmlOutputRule = {
162
- +html: HtmlNodeOutput,
188
+ readonly html: HtmlNodeOutput;
163
189
  };
164
190
 
165
191
  type DefaultInRule = SingleNodeParserRule & ReactOutputRule & HtmlOutputRule;
@@ -174,46 +200,46 @@ type DefaultInOutRule = SingleNodeParserRule &
174
200
  NonNullHtmlOutputRule;
175
201
 
176
202
  type DefaultRules = {
177
- +Array: {
178
- +react: ArrayNodeOutput<ReactElements>,
179
- +html: ArrayNodeOutput<string>,
180
- },
181
- +heading: DefaultInOutRule,
182
- +nptable: DefaultInRule,
183
- +lheading: DefaultInRule,
184
- +hr: DefaultInOutRule,
185
- +codeBlock: DefaultInOutRule,
186
- +fence: DefaultInRule,
187
- +blockQuote: DefaultInOutRule,
188
- +list: DefaultInOutRule,
189
- +def: LenientInOutRule,
190
- +table: DefaultInOutRule,
191
- +tableSeparator: DefaultInRule,
192
- +newline: TextInOutRule,
193
- +paragraph: DefaultInOutRule,
194
- +escape: DefaultInRule,
195
- +autolink: DefaultInRule,
196
- +mailto: DefaultInRule,
197
- +url: DefaultInRule,
198
- +link: DefaultInOutRule,
199
- +image: DefaultInOutRule,
200
- +reflink: DefaultInRule,
201
- +refimage: DefaultInRule,
202
- +em: DefaultInOutRule,
203
- +strong: DefaultInOutRule,
204
- +u: DefaultInOutRule,
205
- +del: DefaultInOutRule,
206
- +inlineCode: DefaultInOutRule,
207
- +br: DefaultInOutRule,
208
- +text: TextInOutRule,
203
+ readonly Array: {
204
+ readonly react: ArrayNodeOutput<ReactElements>;
205
+ readonly html: ArrayNodeOutput<string>;
206
+ };
207
+ readonly heading: DefaultInOutRule;
208
+ readonly nptable: DefaultInRule;
209
+ readonly lheading: DefaultInRule;
210
+ readonly hr: DefaultInOutRule;
211
+ readonly codeBlock: DefaultInOutRule;
212
+ readonly fence: DefaultInRule;
213
+ readonly blockQuote: DefaultInOutRule;
214
+ readonly list: DefaultInOutRule;
215
+ readonly def: LenientInOutRule;
216
+ readonly table: DefaultInOutRule;
217
+ readonly tableSeparator: DefaultInRule;
218
+ readonly newline: TextInOutRule;
219
+ readonly paragraph: DefaultInOutRule;
220
+ readonly escape: DefaultInRule;
221
+ readonly autolink: DefaultInRule;
222
+ readonly mailto: DefaultInRule;
223
+ readonly url: DefaultInRule;
224
+ readonly link: DefaultInOutRule;
225
+ readonly image: DefaultInOutRule;
226
+ readonly reflink: DefaultInRule;
227
+ readonly refimage: DefaultInRule;
228
+ readonly em: DefaultInOutRule;
229
+ readonly strong: DefaultInOutRule;
230
+ readonly u: DefaultInOutRule;
231
+ readonly del: DefaultInOutRule;
232
+ readonly inlineCode: DefaultInOutRule;
233
+ readonly br: DefaultInOutRule;
234
+ readonly text: TextInOutRule;
209
235
  };
210
236
 
211
237
  type RefNode = {
212
- type: string,
213
- content?: ASTNode,
214
- target?: string,
215
- title?: string,
216
- alt?: string,
238
+ type: string;
239
+ content?: ASTNode;
240
+ target?: string;
241
+ title?: string;
242
+ alt?: string;
217
243
  };
218
244
 
219
245
  // End Flow Definitions
@@ -233,13 +259,12 @@ var preprocess = function (source: string): string {
233
259
  };
234
260
 
235
261
  var populateInitialState = function (
236
- givenState: ?State,
237
- defaultState: ?State,
262
+ givenState?: State | null,
263
+ defaultState?: State | null,
238
264
  ): State {
239
265
  var state: State = givenState || {};
240
266
  if (defaultState != null) {
241
267
  for (var prop in defaultState) {
242
- // $FlowFixMe
243
268
  if (Object.prototype.hasOwnProperty.call(defaultState, prop)) {
244
269
  state[prop] = defaultState[prop];
245
270
  }
@@ -267,7 +292,10 @@ var populateInitialState = function (
267
292
  * some nesting is. For an example use-case, see passage-ref
268
293
  * parsing in src/widgets/passage/passage-markdown.jsx
269
294
  */
270
- var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
295
+ var parserFor = function (
296
+ rules: ParserRules,
297
+ defaultState?: State | null,
298
+ ): Parser {
271
299
  // Sorts rules in order of increasing order, then
272
300
  // ascending rule name in case of ties.
273
301
  var ruleList = Object.keys(rules).filter(function (type) {
@@ -291,8 +319,8 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
291
319
  });
292
320
 
293
321
  ruleList.sort(function (typeA, typeB) {
294
- var ruleA: ParserRule = (rules[typeA]: any);
295
- var ruleB: ParserRule = (rules[typeB]: any);
322
+ var ruleA: ParserRule = rules[typeA] as any;
323
+ var ruleB: ParserRule = rules[typeB] as any;
296
324
  var orderA = ruleA.order;
297
325
  var orderB = ruleB.order;
298
326
 
@@ -322,7 +350,7 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
322
350
  var latestState: State;
323
351
  var nestedParse: Parser = function (
324
352
  source: string,
325
- state: ?State,
353
+ state?: State | null,
326
354
  ): Array<SingleASTNode> {
327
355
  var result: Array<SingleASTNode> = [];
328
356
  state = state || latestState;
@@ -338,7 +366,6 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
338
366
  var i = 0;
339
367
  var currRuleType = ruleList[0];
340
368
 
341
- // $FlowFixMe
342
369
  var currRule: ParserRule = rules[currRuleType];
343
370
 
344
371
  do {
@@ -355,8 +382,11 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
355
382
  // the initial quality is NaN (that's why there's the
356
383
  // condition negation).
357
384
  if (!(currQuality <= quality)) {
385
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
358
386
  ruleType = currRuleType;
387
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'ParserRule' is not assignable to type 'null'.
359
388
  rule = currRule;
389
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'Capture' is not assignable to type 'null'.
360
390
  capture = currCapture;
361
391
  quality = currQuality;
362
392
  }
@@ -366,7 +396,6 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
366
396
  // Note that this makes `currRule` be the next item
367
397
  i++;
368
398
  currRuleType = ruleList[i];
369
- // $FlowFixMe
370
399
  currRule = rules[currRuleType];
371
400
  } while (
372
401
  // keep looping while we're still within the ruleList
@@ -394,6 +423,7 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
394
423
  source,
395
424
  );
396
425
  }
426
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'index' does not exist on type 'never'.
397
427
  if (capture.index) {
398
428
  // If present and non-zero, i.e. a non-^ regexp result:
399
429
  throw new Error(
@@ -403,13 +433,13 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
403
433
  );
404
434
  }
405
435
 
436
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'parse' does not exist on type 'never'.
406
437
  var parsed = rule.parse(capture, nestedParse, state);
407
438
  // We maintain the same object here so that rules can
408
439
  // store references to the objects they return and
409
440
  // modify them later. (oops sorry! but this adds a lot
410
441
  // of power--see reflinks.)
411
442
  if (Array.isArray(parsed)) {
412
- // $FlowFixMe
413
443
  Array.prototype.push.apply(result, parsed);
414
444
  } else {
415
445
  if (parsed == null || typeof parsed !== "object") {
@@ -423,7 +453,6 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
423
453
  // there can be a single output function for all links,
424
454
  // even if there are several rules to parse them.
425
455
  if (parsed.type == null) {
426
- // $FlowFixMe
427
456
  parsed.type = ruleType;
428
457
  }
429
458
  result.push(parsed);
@@ -433,13 +462,12 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
433
462
  source = source.substring(state.prevCapture[0].length);
434
463
  }
435
464
 
436
- // $FlowFixMe
437
465
  return result;
438
466
  };
439
467
 
440
468
  var outerParse: Parser = function (
441
469
  source: string,
442
- state: ?State,
470
+ state?: State | null,
443
471
  ): Array<SingleASTNode> {
444
472
  latestState = populateInitialState(state, defaultState);
445
473
  if (!latestState.inline && !latestState.disableAutoBlockNewlines) {
@@ -454,7 +482,6 @@ var parserFor = function (rules: ParserRules, defaultState: ?State): Parser {
454
482
  return nestedParse(preprocess(source), latestState);
455
483
  };
456
484
 
457
- // $FlowFixMe
458
485
  return outerParse;
459
486
  };
460
487
 
@@ -464,14 +491,14 @@ var inlineRegex = function (regex: RegExp): MatchFunction {
464
491
  source: string,
465
492
  state: State,
466
493
  prevCapture: string,
467
- ): ?Capture {
494
+ ): Capture | null | undefined {
468
495
  if (state.inline) {
469
- // $FlowFixMe
470
496
  return regex.exec(source);
471
497
  } else {
472
498
  return null;
473
499
  }
474
500
  };
501
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'regex' does not exist on type '(source: string, state: State, prevCapture: string) => Capture | null | undefined'.
475
502
  match.regex = regex;
476
503
 
477
504
  return match;
@@ -479,7 +506,6 @@ var inlineRegex = function (regex: RegExp): MatchFunction {
479
506
 
480
507
  // Creates a match function for a block scoped element from a regex
481
508
  var blockRegex = function (regex: RegExp): MatchFunction {
482
- // $FlowFixMe
483
509
  var match: MatchFunction = function (source, state) {
484
510
  if (state.inline) {
485
511
  return null;
@@ -493,7 +519,6 @@ var blockRegex = function (regex: RegExp): MatchFunction {
493
519
 
494
520
  // Creates a match function from a regex, ignoring block/inline scope
495
521
  var anyScopeRegex = function (regex: RegExp): MatchFunction {
496
- // $FlowFixMe
497
522
  var match: MatchFunction = function (source, state) {
498
523
  return regex.exec(source);
499
524
  };
@@ -509,17 +534,19 @@ var TYPE_SYMBOL =
509
534
 
510
535
  var reactElement = function (
511
536
  type: string,
512
- key: string | number | null | void,
513
- props: {[string]: any},
537
+ key: string | number | null | undefined,
538
+ props: {
539
+ [key: string]: any;
540
+ },
514
541
  ): ReactElement {
515
- var element: ReactElement = ({
542
+ var element: ReactElement = {
516
543
  $$typeof: TYPE_SYMBOL,
517
544
  type: type,
518
545
  key: key == null ? undefined : key,
519
546
  ref: null,
520
547
  props: props,
521
548
  _owner: null,
522
- }: any);
549
+ } as any;
523
550
  return element;
524
551
  };
525
552
 
@@ -534,8 +561,8 @@ var reactElement = function (
534
561
  var htmlTag = function (
535
562
  tagName: string,
536
563
  content: string,
537
- attributes: ?{[any]: ?Attr},
538
- isClosed: ?boolean,
564
+ attributes?: Partial<Record<any, Attr | null | undefined>> | null,
565
+ isClosed?: boolean | null,
539
566
  ) {
540
567
  attributes = attributes || {};
541
568
  isClosed = typeof isClosed !== "undefined" ? isClosed : true;
@@ -563,13 +590,13 @@ var htmlTag = function (
563
590
  }
564
591
  };
565
592
 
566
- var EMPTY_PROPS = {};
593
+ var EMPTY_PROPS: Record<string, any> = {};
567
594
 
568
595
  /**
569
596
  * @param {string | null | undefined} url - url to sanitize
570
597
  * @returns {string | null} - url if safe, or null if a safe url could not be made
571
598
  */
572
- var sanitizeUrl = function (url: ?string) {
599
+ var sanitizeUrl = function (url?: string | null) {
573
600
  if (url == null) {
574
601
  return null;
575
602
  }
@@ -582,7 +609,7 @@ var sanitizeUrl = function (url: ?string) {
582
609
  ) {
583
610
  return null;
584
611
  }
585
- } catch (e) {
612
+ } catch (e: any) {
586
613
  // invalid URLs should throw a TypeError
587
614
  // see for instance: `new URL("");`
588
615
  return null;
@@ -773,6 +800,7 @@ var TABLES = (function () {
773
800
  "",
774
801
  );
775
802
  }
803
+ // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'SingleASTNode' is not assignable to parameter of type 'never'.
776
804
  cells[cells.length - 1].push(node);
777
805
  }
778
806
  });
@@ -796,7 +824,6 @@ var TABLES = (function () {
796
824
  var rowsText = source.trim().split("\n");
797
825
 
798
826
  return rowsText.map(function (rowText) {
799
- // $FlowFixMe
800
827
  return parseTableRow(rowText, parse, state, trimEndSeparators);
801
828
  });
802
829
  };
@@ -805,8 +832,8 @@ var TABLES = (function () {
805
832
  * @param {boolean} trimEndSeparators
806
833
  * @returns {SimpleMarkdown.SingleNodeParseFunction}
807
834
  */
808
- var parseTable = function (trimEndSeparators) {
809
- return function (capture, parse, state) {
835
+ var parseTable = function (trimEndSeparators: boolean) {
836
+ return function (capture: Capture, parse: Parser, state: State) {
810
837
  state.inline = true;
811
838
  var header = parseTableRow(
812
839
  capture[1],
@@ -1085,6 +1112,7 @@ var defaultRules: DefaultRules = {
1085
1112
  var bullet = capture[2];
1086
1113
  var ordered = bullet.length > 1;
1087
1114
  var start = ordered ? +bullet : undefined;
1115
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'RegExpMatchArray | null' is not assignable to type 'string[]'.
1088
1116
  var items: Array<string> = capture[0]
1089
1117
  .replace(LIST_BLOCK_END_R, "\n")
1090
1118
  .match(LIST_ITEM_R);
@@ -1248,7 +1276,7 @@ var defaultRules: DefaultRules = {
1248
1276
  parse: TABLES.parseTable,
1249
1277
  react: function (node, output, state) {
1250
1278
  var getStyle = function (colIndex: number): {
1251
- [attr: string]: Attr,
1279
+ [attr: string]: Attr;
1252
1280
  } {
1253
1281
  return node.align[colIndex] == null
1254
1282
  ? {}
@@ -1719,10 +1747,10 @@ var defaultRules: DefaultRules = {
1719
1747
  };
1720
1748
 
1721
1749
  /** (deprecated) */
1722
- var ruleOutput = function (
1750
+ var ruleOutput = function <Rule>(
1723
1751
  // $FlowFixMe
1724
1752
  rules: OutputRules<Rule>,
1725
- property: $Keys<Rule>,
1753
+ property: keyof Rule,
1726
1754
  ) {
1727
1755
  if (!property && typeof console !== "undefined") {
1728
1756
  console.warn(
@@ -1736,6 +1764,8 @@ var ruleOutput = function (
1736
1764
  outputFunc: Output<any>,
1737
1765
  state: State,
1738
1766
  ) {
1767
+ // @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
1768
+ // Type 'unknown' has no call signatures.
1739
1769
  return rules[ast.type][property](ast, outputFunc, state);
1740
1770
  };
1741
1771
  return nestedRuleOutput;
@@ -1760,10 +1790,12 @@ var reactFor = function (outputFunc: ReactNodeOutput): ReactOutput {
1760
1790
  typeof nodeOut === "string" &&
1761
1791
  typeof lastResult === "string"
1762
1792
  ) {
1793
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'string' is not assignable to type 'null'.
1763
1794
  lastResult = lastResult + nodeOut;
1764
1795
  result[result.length - 1] = lastResult;
1765
1796
  } else {
1766
1797
  result.push(nodeOut);
1798
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'ReactNode' is not assignable to type 'null'.
1767
1799
  lastResult = nodeOut;
1768
1800
  }
1769
1801
  }
@@ -1795,10 +1827,10 @@ var htmlFor = function (outputFunc: HtmlNodeOutput): HtmlOutput {
1795
1827
  return nestedOutput;
1796
1828
  };
1797
1829
 
1798
- var outputFor = function (
1830
+ var outputFor = function <Rule>(
1799
1831
  rules: OutputRules<Rule>,
1800
- property: $Keys<Rule>,
1801
- defaultState: ?State = {},
1832
+ property: keyof Rule,
1833
+ defaultState: State | null = {},
1802
1834
  ) {
1803
1835
  if (!property) {
1804
1836
  throw new Error(
@@ -1810,14 +1842,15 @@ var outputFor = function (
1810
1842
  }
1811
1843
 
1812
1844
  var latestState: State;
1813
- // $FlowFixMe[incompatible-type]
1814
1845
  var arrayRule: ArrayRule = rules.Array || defaultRules.Array;
1815
1846
 
1816
1847
  // Tricks to convince tsc that this var is not null:
1848
+ // @ts-expect-error [FEI-5003] - TS2538 - Type 'symbol' cannot be used as an index type.
1817
1849
  var arrayRuleCheck = arrayRule[property];
1818
1850
  if (!arrayRuleCheck) {
1819
1851
  throw new Error(
1820
1852
  "simple-markdown: outputFor: to join nodes of type `" +
1853
+ // @ts-expect-error [FEI-5003] - TS2469 - The '+' operator cannot be applied to type 'symbol'.
1821
1854
  property +
1822
1855
  "` you must provide an `Array:` joiner rule with that type, " +
1823
1856
  "Please see the docs for details on specifying an Array rule.",
@@ -1831,6 +1864,8 @@ var outputFor = function (
1831
1864
  if (Array.isArray(ast)) {
1832
1865
  return arrayRuleOutput(ast, nestedOutput, state);
1833
1866
  } else {
1867
+ // @ts-expect-error [FEI-5003] - TS2349 - This expression is not callable.
1868
+ // Type 'unknown' has no call signatures.
1834
1869
  return rules[ast.type][property](ast, nestedOutput, state);
1835
1870
  }
1836
1871
  };
@@ -1842,12 +1877,12 @@ var outputFor = function (
1842
1877
  return outerOutput;
1843
1878
  };
1844
1879
 
1845
- // $FlowFixMe[incompatible-call]
1880
+ // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'DefaultRules' is not assignable to parameter of type 'ParserRules'.
1846
1881
  var defaultRawParse = parserFor(defaultRules);
1847
1882
 
1848
1883
  var defaultBlockParse = function (
1849
1884
  source: string,
1850
- state: ?State,
1885
+ state?: State | null,
1851
1886
  ): Array<SingleASTNode> {
1852
1887
  state = state || {};
1853
1888
  state.inline = false;
@@ -1856,7 +1891,7 @@ var defaultBlockParse = function (
1856
1891
 
1857
1892
  var defaultInlineParse = function (
1858
1893
  source: string,
1859
- state: ?State,
1894
+ state?: State | null,
1860
1895
  ): Array<SingleASTNode> {
1861
1896
  state = state || {};
1862
1897
  state.inline = true;
@@ -1865,7 +1900,7 @@ var defaultInlineParse = function (
1865
1900
 
1866
1901
  var defaultImplicitParse = function (
1867
1902
  source: string,
1868
- state: ?State,
1903
+ state?: State | null,
1869
1904
  ): Array<SingleASTNode> {
1870
1905
  var isBlock = BLOCK_END_R.test(source);
1871
1906
  state = state || {};
@@ -1873,23 +1908,26 @@ var defaultImplicitParse = function (
1873
1908
  return defaultRawParse(source, state);
1874
1909
  };
1875
1910
 
1876
- // $FlowFixMe[incompatible-call]
1877
1911
  var defaultReactOutput: ReactOutput = outputFor(defaultRules, "react");
1878
- // $FlowFixMe[incompatible-call]
1879
1912
  var defaultHtmlOutput: HtmlOutput = outputFor(defaultRules, "html");
1880
1913
 
1881
- var markdownToReact = function (source: string, state: ?State): ReactElements {
1914
+ var markdownToReact = function (
1915
+ source: string,
1916
+ state?: State | null,
1917
+ ): ReactElements {
1882
1918
  return defaultReactOutput(defaultBlockParse(source, state), state);
1883
1919
  };
1884
1920
 
1885
- var markdownToHtml = function (source: string, state: ?State): string {
1921
+ var markdownToHtml = function (source: string, state?: State | null): string {
1886
1922
  return defaultHtmlOutput(defaultBlockParse(source, state), state);
1887
1923
  };
1888
1924
 
1889
1925
  // TODO: This needs definition
1890
1926
  type ReactMarkdownProps = any;
1891
- var ReactMarkdown = function (props: ReactMarkdownProps): ReactElement {
1892
- var divProps = {};
1927
+ var ReactMarkdown: React.FC<ReactMarkdownProps> = function (
1928
+ props,
1929
+ ): React.ReactElement {
1930
+ var divProps: Record<string, any> = {};
1893
1931
 
1894
1932
  for (var prop in props) {
1895
1933
  if (
@@ -1906,63 +1944,87 @@ var ReactMarkdown = function (props: ReactMarkdownProps): ReactElement {
1906
1944
  };
1907
1945
 
1908
1946
  type Exports = {
1909
- +defaultRules: DefaultRules,
1910
- +parserFor: (rules: ParserRules, defaultState?: ?State) => Parser,
1911
- +outputFor: <Rule: Object>(
1947
+ readonly defaultRules: DefaultRules;
1948
+ readonly parserFor: (
1949
+ rules: ParserRules,
1950
+ defaultState?: State | null | undefined,
1951
+ ) => Parser;
1952
+ readonly outputFor: <Rule>(
1912
1953
  rules: OutputRules<Rule>,
1913
- param: $Keys<Rule>,
1914
- defaultState?: ?State,
1915
- ) => Output<any>,
1916
-
1917
- +ruleOutput: <Rule: Object>(
1954
+ param: keyof Rule,
1955
+ defaultState?: State | null | undefined,
1956
+ ) => Output<any>;
1957
+ readonly ruleOutput: <Rule>(
1918
1958
  rules: OutputRules<Rule>,
1919
- param: $Keys<Rule>,
1920
- ) => NodeOutput<any>,
1921
- +reactFor: (ReactNodeOutput) => ReactOutput,
1922
- +htmlFor: (HtmlNodeOutput) => HtmlOutput,
1923
-
1924
- +inlineRegex: (regex: RegExp) => MatchFunction,
1925
- +blockRegex: (regex: RegExp) => MatchFunction,
1926
- +anyScopeRegex: (regex: RegExp) => MatchFunction,
1927
- +parseInline: (parse: Parser, content: string, state: State) => ASTNode,
1928
- +parseBlock: (parse: Parser, content: string, state: State) => ASTNode,
1929
-
1930
- +markdownToReact: (source: string, state?: ?State) => ReactElements,
1931
- +markdownToHtml: (source: string, state?: ?State) => string,
1932
- +ReactMarkdown: (props: {source: string, [string]: any}) => ReactElement,
1933
-
1934
- +defaultRawParse: (source: string, state?: ?State) => Array<SingleASTNode>,
1935
- +defaultBlockParse: (
1959
+ param: keyof Rule,
1960
+ ) => NodeOutput<any>;
1961
+ readonly reactFor: (arg1: ReactNodeOutput) => ReactOutput;
1962
+ readonly htmlFor: (arg1: HtmlNodeOutput) => HtmlOutput;
1963
+ readonly inlineRegex: (regex: RegExp) => MatchFunction;
1964
+ readonly blockRegex: (regex: RegExp) => MatchFunction;
1965
+ readonly anyScopeRegex: (regex: RegExp) => MatchFunction;
1966
+ readonly parseInline: (
1967
+ parse: Parser,
1968
+ content: string,
1969
+ state: State,
1970
+ ) => ASTNode;
1971
+ readonly parseBlock: (
1972
+ parse: Parser,
1973
+ content: string,
1974
+ state: State,
1975
+ ) => ASTNode;
1976
+ readonly markdownToReact: (
1936
1977
  source: string,
1937
- state?: ?State,
1938
- ) => Array<SingleASTNode>,
1939
- +defaultInlineParse: (
1978
+ state?: State | null | undefined,
1979
+ ) => ReactElements;
1980
+ readonly markdownToHtml: (
1940
1981
  source: string,
1941
- state?: ?State,
1942
- ) => Array<SingleASTNode>,
1943
- +defaultImplicitParse: (
1982
+ state?: State | null | undefined,
1983
+ ) => string;
1984
+ readonly ReactMarkdown: (props: {
1985
+ source: string;
1986
+ [key: string]: any;
1987
+ }) => ReactElement;
1988
+ readonly defaultRawParse: (
1944
1989
  source: string,
1945
- state?: ?State,
1946
- ) => Array<SingleASTNode>,
1947
-
1948
- +defaultReactOutput: ReactOutput,
1949
- +defaultHtmlOutput: HtmlOutput,
1950
-
1951
- +preprocess: (source: string) => string,
1952
- +sanitizeText: (text: Attr) => string,
1953
- +sanitizeUrl: (url: ?string) => ?string,
1954
- +unescapeUrl: (url: string) => string,
1955
- +htmlTag: (
1990
+ state?: State | null | undefined,
1991
+ ) => Array<SingleASTNode>;
1992
+ readonly defaultBlockParse: (
1993
+ source: string,
1994
+ state?: State | null | undefined,
1995
+ ) => Array<SingleASTNode>;
1996
+ readonly defaultInlineParse: (
1997
+ source: string,
1998
+ state?: State | null | undefined,
1999
+ ) => Array<SingleASTNode>;
2000
+ readonly defaultImplicitParse: (
2001
+ source: string,
2002
+ state?: State | null | undefined,
2003
+ ) => Array<SingleASTNode>;
2004
+ readonly defaultReactOutput: ReactOutput;
2005
+ readonly defaultHtmlOutput: HtmlOutput;
2006
+ readonly preprocess: (source: string) => string;
2007
+ readonly sanitizeText: (text: Attr) => string;
2008
+ readonly sanitizeUrl: (
2009
+ url?: string | null | undefined,
2010
+ ) => string | null | undefined;
2011
+ readonly unescapeUrl: (url: string) => string;
2012
+ readonly htmlTag: (
1956
2013
  tagName: string,
1957
2014
  content: string,
1958
- attributes: ?{[any]: ?Attr},
1959
- isClosed: ?boolean,
1960
- ) => string,
1961
- +reactElement: (
2015
+ attributes?:
2016
+ | Partial<Record<any, Attr | null | undefined>>
2017
+ | null
2018
+ | undefined,
2019
+ isClosed?: boolean | null | undefined,
2020
+ ) => string;
2021
+ readonly reactElement: (
1962
2022
  type: string,
1963
2023
  key: string | null,
1964
- props: {[string]: any},
1965
- ) => ReactElement,
2024
+ props: {
2025
+ [key: string]: any;
2026
+ },
2027
+ ) => ReactElement;
1966
2028
  };
1967
2029
 
1968
2030
  export type {
@@ -1997,7 +2059,6 @@ export type {
1997
2059
  SingleASTNode,
1998
2060
  };
1999
2061
 
2000
- // $FlowFixMe
2001
2062
  var SimpleMarkdown: Exports = {
2002
2063
  defaultRules: defaultRules,
2003
2064
  parserFor: parserFor,
@@ -2012,6 +2073,7 @@ var SimpleMarkdown: Exports = {
2012
2073
  // default wrappers:
2013
2074
  markdownToReact: markdownToReact,
2014
2075
  markdownToHtml: markdownToHtml,
2076
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'FC<any>' is not assignable to type '(props: { [key: string]: any; source: string; }) => ReactElement'.
2015
2077
  ReactMarkdown: ReactMarkdown,
2016
2078
 
2017
2079
  defaultBlockParse: defaultBlockParse,
@@ -2034,21 +2096,21 @@ var SimpleMarkdown: Exports = {
2034
2096
  reactFor: reactFor,
2035
2097
  htmlFor: htmlFor,
2036
2098
 
2037
- defaultParse: function () {
2099
+ defaultParse: function (...args) {
2038
2100
  if (typeof console !== "undefined") {
2039
2101
  console.warn(
2040
2102
  "defaultParse is deprecated, please use `defaultImplicitParse`",
2041
2103
  );
2042
2104
  }
2043
- return defaultImplicitParse.apply(null, (arguments: any));
2105
+ return defaultImplicitParse.apply(null, args);
2044
2106
  },
2045
- defaultOutput: function () {
2107
+ defaultOutput: function (...args) {
2046
2108
  if (typeof console !== "undefined") {
2047
2109
  console.warn(
2048
2110
  "defaultOutput is deprecated, please use `defaultReactOutput`",
2049
2111
  );
2050
2112
  }
2051
- return defaultReactOutput.apply(null, (arguments: any));
2113
+ return defaultReactOutput.apply(null, args);
2052
2114
  },
2053
2115
  };
2054
2116