@khanacademy/pure-markdown 0.1.5 → 0.2.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.
package/.eslintrc.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
1
2
  /* eslint-disable import/no-commonjs */
2
3
  const path = require("path");
3
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @khanacademy/pure-markdown
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 1f062e98: Bump all package versions since the build settings have been updated
8
+ - Updated dependencies [1f062e98]
9
+ - @khanacademy/perseus-error@0.2.1
10
+ - @khanacademy/simple-markdown@0.9.1
11
+
12
+ ## 0.2.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 53fd3768: Migrate source code to TypeScript
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [53fd3768]
21
+ - @khanacademy/perseus-error@0.2.0
22
+ - @khanacademy/simple-markdown@0.9.0
23
+
3
24
  ## 0.1.5
4
25
 
5
26
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -1,44 +1,21 @@
1
1
  import SimpleMarkdown from '@khanacademy/simple-markdown';
2
2
 
3
- function ownKeys(object, enumerableOnly) {
4
- var keys = Object.keys(object);
5
-
6
- if (Object.getOwnPropertySymbols) {
7
- var symbols = Object.getOwnPropertySymbols(object);
8
- enumerableOnly && (symbols = symbols.filter(function (sym) {
9
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
10
- })), keys.push.apply(keys, symbols);
11
- }
12
-
13
- return keys;
14
- }
15
-
16
- function _objectSpread2(target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = null != arguments[i] ? arguments[i] : {};
19
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
20
- _defineProperty(target, key, source[key]);
21
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
22
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
23
- });
24
- }
25
-
26
- return target;
27
- }
3
+ function _extends() {
4
+ _extends = Object.assign || function (target) {
5
+ for (var i = 1; i < arguments.length; i++) {
6
+ var source = arguments[i];
7
+
8
+ for (var key in source) {
9
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
10
+ target[key] = source[key];
11
+ }
12
+ }
13
+ }
28
14
 
29
- function _defineProperty(obj, key, value) {
30
- if (key in obj) {
31
- Object.defineProperty(obj, key, {
32
- value: value,
33
- enumerable: true,
34
- configurable: true,
35
- writable: true
36
- });
37
- } else {
38
- obj[key] = value;
39
- }
15
+ return target;
16
+ };
40
17
 
41
- return obj;
18
+ return _extends.apply(this, arguments);
42
19
  }
43
20
 
44
21
  /**
@@ -64,36 +41,34 @@ function _defineProperty(obj, key, value) {
64
41
  * This can also match block-math, which is math alone in a paragraph.
65
42
  */
66
43
 
67
- var rWidgetRule = /^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;
68
-
69
- var mathMatcher = (source, state, isBlock) => {
70
- var length = source.length;
71
- var index = 0; // When looking for blocks, skip over leading spaces
44
+ const rWidgetRule = /^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;
45
+ const mathMatcher = (source, state, isBlock) => {
46
+ const length = source.length;
47
+ let index = 0;
72
48
 
49
+ // When looking for blocks, skip over leading spaces
73
50
  if (isBlock) {
74
51
  if (state.inline) {
75
52
  return null;
76
53
  }
77
-
78
54
  while (index < length && source[index] === " ") {
79
55
  index++;
80
56
  }
81
- } // Our source must start with a "$"
82
-
57
+ }
83
58
 
59
+ // Our source must start with a "$"
84
60
  if (!(index < length && source[index] === "$")) {
85
61
  return null;
86
62
  }
87
-
88
63
  index++;
89
- var startIndex = index;
90
- var braceLevel = 0; // Loop through the source, looking for a closing '$'
64
+ const startIndex = index;
65
+ let braceLevel = 0;
66
+
67
+ // Loop through the source, looking for a closing '$'
91
68
  // closing '$'s only count if they are not escaped with
92
69
  // a `\`, and we are not in nested `{}` braces.
93
-
94
70
  while (index < length) {
95
- var character = source[index];
96
-
71
+ const character = source[index];
97
72
  if (character === "\\") {
98
73
  // Consume both the `\` and the escaped char as a single
99
74
  // token.
@@ -105,24 +80,23 @@ var mathMatcher = (source, state, isBlock) => {
105
80
  // braces `\{`
106
81
  index++;
107
82
  } else if (braceLevel <= 0 && character === "$") {
108
- var endIndex = index + 1;
109
-
83
+ let endIndex = index + 1;
110
84
  if (isBlock) {
111
85
  // Look for two trailing newlines after the closing `$`
112
- var match = /^(?: *\n){2,}/.exec(source.slice(endIndex));
86
+ const match = /^(?: *\n){2,}/.exec(source.slice(endIndex));
87
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number | null' is not assignable to type 'number'.
113
88
  endIndex = match ? endIndex + match[0].length : null;
114
- } // Return an array that looks like the results of a
89
+ }
90
+
91
+ // Return an array that looks like the results of a
115
92
  // regex's .exec function:
116
93
  // capture[0] is the whole string
117
94
  // capture[1] is the first "paren" match, which is the
118
95
  // content of the math here, as if we wrote the regex
119
96
  // /\$([^\$]*)\$/
120
-
121
-
122
97
  if (endIndex) {
123
98
  return [source.substring(0, endIndex), source.substring(startIndex, index)];
124
99
  }
125
-
126
100
  return null;
127
101
  } else if (character === "{") {
128
102
  braceLevel++;
@@ -136,32 +110,30 @@ var mathMatcher = (source, state, isBlock) => {
136
110
  // in paragraphs...
137
111
  return null;
138
112
  }
139
-
140
113
  index++;
141
- } // we didn't find a closing `$`
142
-
114
+ }
143
115
 
116
+ // we didn't find a closing `$`
144
117
  return null;
145
118
  };
146
-
147
- var mathMatch = (source, state) => mathMatcher(source, state, false);
148
-
149
- var blockMathMatch = (source, state) => mathMatcher(source, state, true);
150
-
151
- var TITLED_TABLE_REGEX = new RegExp("^\\|\\| +(.*) +\\|\\| *\\n" + "(" + // The simple-markdown nptable regex, without
119
+ const mathMatch = (source, state) => mathMatcher(source, state, false);
120
+ const blockMathMatch = (source, state) => mathMatcher(source, state, true);
121
+ const TITLED_TABLE_REGEX = new RegExp("^\\|\\| +(.*) +\\|\\| *\\n" + "(" +
122
+ // The simple-markdown nptable regex, without
152
123
  // the leading `^`
153
124
  // $FlowFixMe[incompatible-use]
125
+ // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
154
126
  SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) + ")");
155
- var crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
156
- var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules), {}, {
127
+ const crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
128
+ const pureMarkdownRules = _extends({}, SimpleMarkdown.defaultRules, {
157
129
  // NOTE: basically ignored by JIPT. wraps everything at the outer layer
158
130
  columns: {
159
131
  order: -2,
160
132
  match: SimpleMarkdown.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),
161
- parse: (capture, _parse, state) => {
133
+ parse: (capture, parse, state) => {
162
134
  return {
163
- col1: _parse(capture[1], state),
164
- col2: _parse(capture[2], state)
135
+ col1: parse(capture[1], state),
136
+ col2: parse(capture[2], state)
165
137
  };
166
138
  }
167
139
  },
@@ -172,10 +144,9 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
172
144
  if (state.isJipt) {
173
145
  return crowdinJiptMatcher(source, state, prevCapture);
174
146
  }
175
-
176
147
  return null;
177
148
  },
178
- parse: (capture, _parse2, state) => ({
149
+ parse: (capture, parse, state) => ({
179
150
  id: capture[1]
180
151
  })
181
152
  },
@@ -189,12 +160,13 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
189
160
  // process immediately before nptables
190
161
  order: SimpleMarkdown.defaultRules.nptable.order - 0.5,
191
162
  match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX),
192
- parse: (capture, _parse3, state) => {
193
- var title = SimpleMarkdown.parseInline(_parse3, capture[1], state); // Remove our [0] and [1] captures, and pass the rest to
194
- // the nptable parser
163
+ parse: (capture, parse, state) => {
164
+ const title = SimpleMarkdown.parseInline(parse, capture[1], state);
195
165
 
196
- var tableCapture = capture.slice(2);
197
- var table = SimpleMarkdown.defaultRules.nptable.parse(tableCapture, _parse3, state);
166
+ // Remove our [0] and [1] captures, and pass the rest to
167
+ // the nptable parser
168
+ const tableCapture = capture.slice(2);
169
+ const table = SimpleMarkdown.defaultRules.nptable.parse(tableCapture, parse, state);
198
170
  return {
199
171
  title: title,
200
172
  table: table
@@ -204,7 +176,7 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
204
176
  widget: {
205
177
  order: SimpleMarkdown.defaultRules.link.order - 0.75,
206
178
  match: SimpleMarkdown.inlineRegex(rWidgetRule),
207
- parse: (capture, _parse4, state) => {
179
+ parse: (capture, parse, state) => {
208
180
  return {
209
181
  id: capture[1],
210
182
  widgetType: capture[2]
@@ -214,7 +186,7 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
214
186
  blockMath: {
215
187
  order: SimpleMarkdown.defaultRules.codeBlock.order + 0.5,
216
188
  match: blockMathMatch,
217
- parse: (capture, _parse5, state) => {
189
+ parse: (capture, parse, state) => {
218
190
  return {
219
191
  content: capture[1]
220
192
  };
@@ -223,7 +195,7 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
223
195
  math: {
224
196
  order: SimpleMarkdown.defaultRules.link.order - 0.25,
225
197
  match: mathMatch,
226
- parse: (capture, _parse6, state) => {
198
+ parse: (capture, parse, state) => {
227
199
  return {
228
200
  content: capture[1]
229
201
  };
@@ -232,14 +204,15 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
232
204
  unescapedDollar: {
233
205
  order: SimpleMarkdown.defaultRules.link.order - 0.24,
234
206
  match: SimpleMarkdown.inlineRegex(/^(?!\\)\$/),
235
- parse: (capture, _parse7, state) => {
207
+ parse: (capture, parse, state) => {
236
208
  return {};
237
209
  }
238
210
  },
239
- fence: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.fence), {}, {
240
- parse: (capture, _parse8, state) => {
241
- var node = SimpleMarkdown.defaultRules.fence.parse(capture, _parse8, state); // support screenreader-only text with ```alt
211
+ fence: _extends({}, SimpleMarkdown.defaultRules.fence, {
212
+ parse: (capture, parse, state) => {
213
+ const node = SimpleMarkdown.defaultRules.fence.parse(capture, parse, state);
242
214
 
215
+ // support screenreader-only text with ```alt
243
216
  if (node.lang === "alt") {
244
217
  return {
245
218
  type: "codeBlock",
@@ -250,14 +223,13 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
250
223
  // The \n\n is because the inside of the codeblock might
251
224
  // not end in double newlines for block rules, because
252
225
  // ordinarily we don't parse this :).
253
- content: _parse8(node.content + "\n\n", state)
226
+ content: parse(node.content + "\n\n", state)
254
227
  };
255
228
  }
256
-
257
229
  return node;
258
230
  }
259
231
  }),
260
- blockQuote: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.blockQuote), {}, {
232
+ blockQuote: _extends({}, SimpleMarkdown.defaultRules.blockQuote, {
261
233
  // Replace the less restrictive blockquote regex from SimpleMarkdown
262
234
  // with a more restrictive one. The only difference should be that
263
235
  //
@@ -287,7 +259,7 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
287
259
  // https://spec.commonmark.org/0.28/#example-205
288
260
  match: SimpleMarkdown.blockRegex(/^ *>[^\n]+(\n( *>)?[^\n]+)*\n{2,}/)
289
261
  }),
290
- list: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.list), {}, {
262
+ list: _extends({}, SimpleMarkdown.defaultRules.list, {
291
263
  match: (source, state, prevCapture) => {
292
264
  // Since lists can contain double newlines and we have special
293
265
  // handling of double newlines while parsing jipt content, just
@@ -295,7 +267,6 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
295
267
  if (state.isJipt) {
296
268
  return null;
297
269
  }
298
-
299
270
  return SimpleMarkdown.defaultRules.list.match(source, state, prevCapture);
300
271
  }
301
272
  }),
@@ -306,14 +277,15 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
306
277
  lint: {
307
278
  order: 1000,
308
279
  match: s => null,
309
- parse: (capture, _parse9, state) => ({})
280
+ parse: (capture, parse, state) => ({})
310
281
  }
311
- }); // $FlowFixMe[incompatible-call]
282
+ });
312
283
 
313
- var builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);
314
- var parse = (source, state) => {
315
- var paragraphedSource = source + "\n\n";
316
- return builtParser(paragraphedSource, _objectSpread2(_objectSpread2({}, state), {}, {
284
+ // @ts-expect-error [FEI-5003] - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.
285
+ const builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);
286
+ const parse = (source, state) => {
287
+ const paragraphedSource = source + "\n\n";
288
+ return builtParser(paragraphedSource, _extends({}, state, {
317
289
  inline: false
318
290
  }));
319
291
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.js"],"sourcesContent":["// @flow\n\n/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\n\nconst rWidgetRule: RegExp = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\nconst mathMatcher = (source, state, isBlock) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // $FlowFixMe[incompatible-use]\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: (SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ): any),\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: (SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX): any),\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: (SimpleMarkdown.inlineRegex(rWidgetRule): any),\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5: any),\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: (SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/): any),\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: (SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ): any),\n },\n list: {\n ...SimpleMarkdown.defaultRules.list,\n match: (source: any, state: any, prevCapture: any): any => {\n // Since lists can contain double newlines and we have special\n // handling of double newlines while parsing jipt content, just\n // disable the list parser.\n if (state.isJipt) {\n return null;\n }\n return SimpleMarkdown.defaultRules.list.match(\n source,\n state,\n prevCapture,\n );\n },\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n};\n\n// $FlowFixMe[incompatible-call]\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\nexport const parse = (source: string, state: $FlowFixMe): $FlowFixMe => {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n};\n"],"names":["rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","columns","order","parse","capture","col1","col2","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","table","widget","link","inlineRegex","widgetType","blockMath","codeBlock","content","math","unescapedDollar","fence","node","lang","type","blockQuote","list","lint","s","builtParser","parserFor","paragraphedSource","_objectSpread"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMA,WAAmB,GAAG,sCAA5B,CAAA;;AAEA,IAAMC,WAAW,GAAG,CAACC,MAAD,EAASC,KAAT,EAAgBC,OAAhB,KAA4B;AAC5C,EAAA,IAAMC,MAAM,GAAGH,MAAM,CAACG,MAAtB,CAAA;AACA,EAAA,IAAIC,KAAK,GAAG,CAAZ,CAF4C;;AAK5C,EAAA,IAAIF,OAAJ,EAAa;AACT,IAAID,IAAAA,KAAK,CAACI,MAAV,EAAkB;AACd,MAAA,OAAO,IAAP,CAAA;AACH,KAAA;;AACD,IAAOD,OAAAA,KAAK,GAAGD,MAAR,IAAkBH,MAAM,CAACI,KAAD,CAAN,KAAkB,GAA3C,EAAgD;AAC5CA,MAAAA,KAAK,EAAA,CAAA;AACR,KAAA;AACJ,GAZ2C;;;AAe5C,EAAA,IAAI,EAAEA,KAAK,GAAGD,MAAR,IAAkBH,MAAM,CAACI,KAAD,CAAN,KAAkB,GAAtC,CAAJ,EAAgD;AAC5C,IAAA,OAAO,IAAP,CAAA;AACH,GAAA;;AAEDA,EAAAA,KAAK,EAAA,CAAA;AACL,EAAME,IAAAA,UAAU,GAAGF,KAAnB,CAAA;AACA,EAAA,IAAIG,UAAU,GAAG,CAAjB,CArB4C;AAwB5C;AACA;;AACA,EAAOH,OAAAA,KAAK,GAAGD,MAAf,EAAuB;AACnB,IAAA,IAAMK,SAAS,GAAGR,MAAM,CAACI,KAAD,CAAxB,CAAA;;AAEA,IAAII,IAAAA,SAAS,KAAK,IAAlB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,EAAA,EAAA;AAEA5C,IAAAA,KAAK,EAAE,CAACV,MAAD,EAAcC,KAAd,EAA0B+B,WAA1B,KAAoD;AACvD;AACA;AACA;AACA,MAAI/B,IAAAA,KAAK,CAACgC,MAAV,EAAkB;AACd,QAAA,OAAO,IAAP,CAAA;AACH,OAAA;;AACD,MAAA,OAAOf,cAAc,CAACC,YAAf,CAA4BmC,IAA5B,CAAiC5C,KAAjC,CACHV,MADG,EAEHC,KAFG,EAGH+B,WAHG,CAAP,CAAA;AAKH,KAAA;AAdD,GAtJsB,CAAA;AAsK1B;AACA;AACA;AACA;AACAuB,EAAAA,IAAI,EAAE;AACF7B,IAAAA,KAAK,EAAE,IADL;AAEFhB,IAAAA,KAAK,EAAG8C,CAAD,IAAiB,IAFtB;AAGF7B,IAAAA,KAAK,EAAE,CAACC,OAAD,EAAeD,OAAf,EAA2B1B,KAA3B,MAAgD,EAAhD,CAAA;AAHL,GAAA;AA1KoB,CAAA;;AAkL9B,IAAMwD,WAAW,GAAGvC,cAAc,CAACwC,SAAf,CAAyBlC,iBAAzB,CAApB,CAAA;IAEaG,KAAK,GAAG,CAAC3B,MAAD,EAAiBC,KAAjB,KAAmD;AACpE,EAAA,IAAM0D,iBAAiB,GAAG3D,MAAM,GAAG,MAAnC,CAAA;AAEA,EAAA,OAAOyD,WAAW,CAACE,iBAAD,EAAAC,cAAA,CAAAA,cAAA,CAAA,EAAA,EACX3D,KADW,CAAA,EAAA,EAAA,EAAA;AAEdI,IAAAA,MAAM,EAAE,KAAA;AAFM,GAAlB,CAAA,CAAA,CAAA;AAIH;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../node_modules/@babel/runtime/helpers/esm/extends.js","../../src/index.ts"],"sourcesContent":["export default function _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}","/**\n * Contains markdown related functions in pure javascript,\n * extracted from perseus-markdown.jsx\n * Note that this file may be used in stand alone nodejs, thus\n * do not import anything from Perseus\n */\nimport SimpleMarkdown from \"@khanacademy/simple-markdown\";\n\n/**\n * This match function matches math in `$`s, such as:\n *\n * $y = x + 1$\n *\n * It functions roughly like the following regex:\n * /\\$([^\\$]*)\\$/\n *\n * Unfortunately, math may have other `$`s inside it, as\n * long as they are inside `{` braces `}`, mostly for\n * `\\text{ $math$ }`.\n *\n * To parse this, we can't use a regex, since we\n * should support arbitrary nesting (even though\n * MathJax actually only supports two levels of nesting\n * here, which we *could* parse with a regex).\n *\n * Non-regex matchers like this are now a first-class\n * concept in simple-markdown. Yay!\n *\n * This can also match block-math, which is math alone in a paragraph.\n */\n\nconst rWidgetRule = /^\\[\\[\\u2603 (([a-z-]+) ([0-9]+))\\]\\]/;\n\nconst mathMatcher = (source: any, state: any, isBlock: boolean) => {\n const length = source.length;\n let index = 0;\n\n // When looking for blocks, skip over leading spaces\n if (isBlock) {\n if (state.inline) {\n return null;\n }\n while (index < length && source[index] === \" \") {\n index++;\n }\n }\n\n // Our source must start with a \"$\"\n if (!(index < length && source[index] === \"$\")) {\n return null;\n }\n\n index++;\n const startIndex = index;\n let braceLevel = 0;\n\n // Loop through the source, looking for a closing '$'\n // closing '$'s only count if they are not escaped with\n // a `\\`, and we are not in nested `{}` braces.\n while (index < length) {\n const character = source[index];\n\n if (character === \"\\\\\") {\n // Consume both the `\\` and the escaped char as a single\n // token.\n // This is so that the second `$` in `$\\\\$` closes\n // the math expression, since the first `\\` is escaping\n // the second `\\`, but the second `\\` is not escaping\n // the second `$`.\n // This also handles the case of escaping `$`s or\n // braces `\\{`\n index++;\n } else if (braceLevel <= 0 && character === \"$\") {\n let endIndex = index + 1;\n if (isBlock) {\n // Look for two trailing newlines after the closing `$`\n const match = /^(?: *\\n){2,}/.exec(source.slice(endIndex));\n // @ts-expect-error [FEI-5003] - TS2322 - Type 'number | null' is not assignable to type 'number'.\n endIndex = match ? endIndex + match[0].length : null;\n }\n\n // Return an array that looks like the results of a\n // regex's .exec function:\n // capture[0] is the whole string\n // capture[1] is the first \"paren\" match, which is the\n // content of the math here, as if we wrote the regex\n // /\\$([^\\$]*)\\$/\n if (endIndex) {\n return [\n source.substring(0, endIndex),\n source.substring(startIndex, index),\n ];\n }\n return null;\n } else if (character === \"{\") {\n braceLevel++;\n } else if (character === \"}\") {\n braceLevel--;\n } else if (character === \"\\n\" && source[index - 1] === \"\\n\") {\n // This is a weird case we supported in the old\n // math implementation--double newlines break\n // math. I'm preserving it for now because content\n // creators might have questions with single '$'s\n // in paragraphs...\n return null;\n }\n\n index++;\n }\n\n // we didn't find a closing `$`\n return null;\n};\nconst mathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, false);\nconst blockMathMatch = (source: any, state: any): any =>\n mathMatcher(source, state, true);\n\nconst TITLED_TABLE_REGEX = new RegExp(\n \"^\\\\|\\\\| +(.*) +\\\\|\\\\| *\\\\n\" +\n \"(\" +\n // The simple-markdown nptable regex, without\n // the leading `^`\n // $FlowFixMe[incompatible-use]\n // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.\n SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) +\n \")\",\n);\n\nconst crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\\n\\s*\\n/);\n\nexport const pureMarkdownRules = {\n ...SimpleMarkdown.defaultRules,\n\n // NOTE: basically ignored by JIPT. wraps everything at the outer layer\n columns: {\n order: -2,\n match: SimpleMarkdown.blockRegex(\n /^([\\s\\S]*\\n\\n)={5,}\\n\\n([\\s\\S]*)/,\n ) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n col1: parse(capture[1], state),\n col2: parse(capture[2], state),\n };\n },\n },\n crowdinId: {\n order: -1,\n match: (source: any, state: any, prevCapture: any): any => {\n // Only match on the just-in-place translation site\n if (state.isJipt) {\n return crowdinJiptMatcher(source, state, prevCapture);\n }\n return null;\n },\n parse: (capture: any, parse: any, state: any): any => ({\n id: capture[1],\n }),\n },\n // This is pretty much horrible, but we have a regex here to capture an\n // entire table + a title. capture[1] is the title. capture[2] of the\n // regex is a copy of the simple-markdown nptable regex. Then we turn\n // our capture[2] into tableCapture[0], and any further captures in\n // our table regex into tableCapture[1..], and we pass tableCapture to\n // our nptable regex\n titledTable: {\n // process immediately before nptables\n order: SimpleMarkdown.defaultRules.nptable.order - 0.5,\n match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX) as any,\n parse: (capture: any, parse: any, state: any): any => {\n const title = SimpleMarkdown.parseInline(parse, capture[1], state);\n\n // Remove our [0] and [1] captures, and pass the rest to\n // the nptable parser\n const tableCapture = capture.slice(2);\n const table = SimpleMarkdown.defaultRules.nptable.parse(\n tableCapture,\n parse,\n state,\n );\n return {\n title: title,\n table: table,\n };\n },\n },\n widget: {\n order: SimpleMarkdown.defaultRules.link.order - 0.75,\n match: SimpleMarkdown.inlineRegex(rWidgetRule) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n id: capture[1],\n widgetType: capture[2],\n };\n },\n },\n blockMath: {\n order: (SimpleMarkdown.defaultRules.codeBlock.order + 0.5) as any,\n match: blockMathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n math: {\n order: SimpleMarkdown.defaultRules.link.order - 0.25,\n match: mathMatch,\n parse: (capture: any, parse: any, state: any): any => {\n return {\n content: capture[1],\n };\n },\n },\n unescapedDollar: {\n order: SimpleMarkdown.defaultRules.link.order - 0.24,\n match: SimpleMarkdown.inlineRegex(/^(?!\\\\)\\$/) as any,\n parse: (capture: any, parse: any, state: any): any => {\n return {};\n },\n },\n fence: {\n ...SimpleMarkdown.defaultRules.fence,\n parse: (capture: any, parse: any, state: any): any => {\n const node = SimpleMarkdown.defaultRules.fence.parse(\n capture,\n parse,\n state,\n );\n\n // support screenreader-only text with ```alt\n if (node.lang === \"alt\") {\n return {\n type: \"codeBlock\",\n lang: \"alt\",\n // default codeBlock parsing doesn't parse the contents.\n // We need to parse the contents for things like table\n // support :).\n // The \\n\\n is because the inside of the codeblock might\n // not end in double newlines for block rules, because\n // ordinarily we don't parse this :).\n content: parse(node.content + \"\\n\\n\", state),\n };\n }\n return node;\n },\n },\n blockQuote: {\n ...SimpleMarkdown.defaultRules.blockQuote,\n // Replace the less restrictive blockquote regex from SimpleMarkdown\n // with a more restrictive one. The only difference should be that\n //\n // > A blockquote\n //\n // > Another blockquote\n //\n // will now match as two different blockQuotes instead of a single\n // blockquote with some paragraph breaks in it.\n //\n // The main motivation for doing this is to provide better support for\n // translators translating blockquotes with multiple paragraphs in\n // them. When translating articles, we split up paragraphs, translate\n // them separately, and then recombine them. We do this so that\n // translators don't have to translate an entire article at a time,\n // they can instead translate paragraph-by-paragraph.That system\n // doesn't understand blockquotes, so it will split up blockquotes into\n // more than one paragraph. A way to solve this would be to make that\n // system understand blockquotes, but then translators would have to\n // translate an entire, multi-paragraph blockquote at a time. Instead,\n // we choose to modify our blockquote matching to split up\n // multi-paragraph blockquotes into multiple blockquotes.\n //\n // There is also precedence for doing this splitting up in other\n // libraries, for instance CommonMark also splits up blockquotes with\n // empty lines into multiple blockquotes:\n // https://spec.commonmark.org/0.28/#example-205\n match: SimpleMarkdown.blockRegex(\n /^ *>[^\\n]+(\\n( *>)?[^\\n]+)*\\n{2,}/,\n ) as any,\n },\n list: {\n ...SimpleMarkdown.defaultRules.list,\n match: (source: any, state: any, prevCapture: any): any => {\n // Since lists can contain double newlines and we have special\n // handling of double newlines while parsing jipt content, just\n // disable the list parser.\n if (state.isJipt) {\n return null;\n }\n return SimpleMarkdown.defaultRules.list.match(\n source,\n state,\n prevCapture,\n );\n },\n },\n // The lint rule never actually matches anything.\n // We check for lint after parsing, and, if we find any, we\n // transform the tree to add lint nodes. This rule is here\n // just for the react() function\n lint: {\n order: 1000,\n match: (s: any): any => null,\n parse: (capture: any, parse: any, state: any): any => ({}),\n },\n} as const;\n\n// @ts-expect-error [FEI-5003] - TS2345 - Argument of type '{ readonly columns: { readonly order: -2; readonly match: any; readonly parse: (capture: any, parse: any, state: any) => any; }; readonly crowdinId: { readonly order: -1; readonly match: (source: any, state: any, prevCapture: any) => any; readonly parse: (capture: any, parse: any, state: any) => any; }; ... 34 more ...' is not assignable to parameter of type 'ParserRules'.\nconst builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);\n\nexport const parse = (source: string, state?: any): any => {\n const paragraphedSource = source + \"\\n\\n\";\n\n return builtParser(paragraphedSource, {\n ...state,\n inline: false,\n });\n};\n"],"names":["rWidgetRule","mathMatcher","source","state","isBlock","length","index","inline","startIndex","braceLevel","character","endIndex","match","exec","slice","substring","mathMatch","blockMathMatch","TITLED_TABLE_REGEX","RegExp","SimpleMarkdown","defaultRules","nptable","regex","crowdinJiptMatcher","blockRegex","pureMarkdownRules","_extends","columns","order","parse","capture","col1","col2","crowdinId","prevCapture","isJipt","id","titledTable","title","parseInline","tableCapture","table","widget","link","inlineRegex","widgetType","blockMath","codeBlock","content","math","unescapedDollar","fence","node","lang","type","blockQuote","list","lint","s","builtParser","parserFor","paragraphedSource"],"mappings":";;AAAe,SAAS,QAAQ,GAAG;AACnC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,IAAI,UAAU,MAAM,EAAE;AAChD,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/C,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAChC;AACA,MAAM,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;AAC9B,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;AAC/D,UAAU,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACpC,SAAS;AACT,OAA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