@khanacademy/pure-markdown 0.0.0-PR443-20230328215601

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 ADDED
@@ -0,0 +1,12 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ /* eslint-disable import/no-commonjs */
3
+ const path = require("path");
4
+
5
+ module.exports = {
6
+ rules: {
7
+ "import/no-extraneous-dependencies": [
8
+ "error",
9
+ {packageDir: [__dirname, path.join(__dirname, "../../")]},
10
+ ],
11
+ },
12
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ # @khanacademy/pure-markdown
2
+
3
+ ## 0.0.0-PR443-20230328215601
4
+
5
+ ### Minor Changes
6
+
7
+ - 4ef5607d: Migrate source code to TypeScript
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [4ef5607d]
12
+ - @khanacademy/perseus-error@0.0.0-PR443-20230328215601
13
+ - @khanacademy/simple-markdown@0.0.0-PR443-20230328215601
14
+
15
+ ## 0.1.5
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [a1b4ab3c]
20
+ - @khanacademy/perseus-error@0.1.5
21
+
22
+ ## 0.1.4
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [6a7f36be]
27
+ - @khanacademy/perseus-error@0.1.4
28
+
29
+ ## 0.1.3
30
+
31
+ ### Patch Changes
32
+
33
+ - f567f660: Update the eslint config to look at both the package.json for the package and the one from the root
34
+ - Updated dependencies [f567f660]
35
+ - Updated dependencies [eeaa9010]
36
+ - @khanacademy/perseus-error@0.1.3
37
+ - @khanacademy/simple-markdown@0.8.6
38
+
39
+ ## 0.1.2
40
+
41
+ ### Patch Changes
42
+
43
+ - bf180fe1: Fix our use of import/no-extraneous-dependencies
44
+ - Updated dependencies [bf180fe1]
45
+ - @khanacademy/perseus-error@0.1.2
46
+ - @khanacademy/simple-markdown@0.8.5
47
+
48
+ ## 0.1.1
49
+
50
+ ### Patch Changes
51
+
52
+ - 98d283ff: Fix storybook
53
+ - Updated dependencies [98d283ff]
54
+ - @khanacademy/perseus-error@0.1.1
55
+ - @khanacademy/simple-markdown@0.8.4
56
+
57
+ ## 0.1.0
58
+
59
+ ### Minor Changes
60
+
61
+ - a4f10ace: Move Gorgon, PerseusError, PureMarkdown into their own packages
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [a4f10ace]
66
+ - @khanacademy/perseus-error@0.1.0
@@ -0,0 +1,326 @@
1
+ import SimpleMarkdown from '@khanacademy/simple-markdown';
2
+
3
+ function ownKeys(object, enumerableOnly) {
4
+ var keys = Object.keys(object);
5
+ if (Object.getOwnPropertySymbols) {
6
+ var symbols = Object.getOwnPropertySymbols(object);
7
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
8
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
9
+ })), keys.push.apply(keys, symbols);
10
+ }
11
+ return keys;
12
+ }
13
+ function _objectSpread2(target) {
14
+ for (var i = 1; i < arguments.length; i++) {
15
+ var source = null != arguments[i] ? arguments[i] : {};
16
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
17
+ _defineProperty(target, key, source[key]);
18
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
19
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
20
+ });
21
+ }
22
+ return target;
23
+ }
24
+ function _defineProperty(obj, key, value) {
25
+ key = _toPropertyKey(key);
26
+ if (key in obj) {
27
+ Object.defineProperty(obj, key, {
28
+ value: value,
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true
32
+ });
33
+ } else {
34
+ obj[key] = value;
35
+ }
36
+ return obj;
37
+ }
38
+ function _toPrimitive(input, hint) {
39
+ if (typeof input !== "object" || input === null) return input;
40
+ var prim = input[Symbol.toPrimitive];
41
+ if (prim !== undefined) {
42
+ var res = prim.call(input, hint || "default");
43
+ if (typeof res !== "object") return res;
44
+ throw new TypeError("@@toPrimitive must return a primitive value.");
45
+ }
46
+ return (hint === "string" ? String : Number)(input);
47
+ }
48
+ function _toPropertyKey(arg) {
49
+ var key = _toPrimitive(arg, "string");
50
+ return typeof key === "symbol" ? key : String(key);
51
+ }
52
+
53
+ /**
54
+ * This match function matches math in `$`s, such as:
55
+ *
56
+ * $y = x + 1$
57
+ *
58
+ * It functions roughly like the following regex:
59
+ * /\$([^\$]*)\$/
60
+ *
61
+ * Unfortunately, math may have other `$`s inside it, as
62
+ * long as they are inside `{` braces `}`, mostly for
63
+ * `\text{ $math$ }`.
64
+ *
65
+ * To parse this, we can't use a regex, since we
66
+ * should support arbitrary nesting (even though
67
+ * MathJax actually only supports two levels of nesting
68
+ * here, which we *could* parse with a regex).
69
+ *
70
+ * Non-regex matchers like this are now a first-class
71
+ * concept in simple-markdown. Yay!
72
+ *
73
+ * This can also match block-math, which is math alone in a paragraph.
74
+ */
75
+
76
+ var rWidgetRule = /^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;
77
+ var mathMatcher = (source, state, isBlock) => {
78
+ var length = source.length;
79
+ var index = 0;
80
+
81
+ // When looking for blocks, skip over leading spaces
82
+ if (isBlock) {
83
+ if (state.inline) {
84
+ return null;
85
+ }
86
+ while (index < length && source[index] === " ") {
87
+ index++;
88
+ }
89
+ }
90
+
91
+ // Our source must start with a "$"
92
+ if (!(index < length && source[index] === "$")) {
93
+ return null;
94
+ }
95
+ index++;
96
+ var startIndex = index;
97
+ var braceLevel = 0;
98
+
99
+ // Loop through the source, looking for a closing '$'
100
+ // closing '$'s only count if they are not escaped with
101
+ // a `\`, and we are not in nested `{}` braces.
102
+ while (index < length) {
103
+ var character = source[index];
104
+ if (character === "\\") {
105
+ // Consume both the `\` and the escaped char as a single
106
+ // token.
107
+ // This is so that the second `$` in `$\\$` closes
108
+ // the math expression, since the first `\` is escaping
109
+ // the second `\`, but the second `\` is not escaping
110
+ // the second `$`.
111
+ // This also handles the case of escaping `$`s or
112
+ // braces `\{`
113
+ index++;
114
+ } else if (braceLevel <= 0 && character === "$") {
115
+ var endIndex = index + 1;
116
+ if (isBlock) {
117
+ // Look for two trailing newlines after the closing `$`
118
+ var match = /^(?: *\n){2,}/.exec(source.slice(endIndex));
119
+ // @ts-expect-error [FEI-5003] - TS2322 - Type 'number | null' is not assignable to type 'number'.
120
+ endIndex = match ? endIndex + match[0].length : null;
121
+ }
122
+
123
+ // Return an array that looks like the results of a
124
+ // regex's .exec function:
125
+ // capture[0] is the whole string
126
+ // capture[1] is the first "paren" match, which is the
127
+ // content of the math here, as if we wrote the regex
128
+ // /\$([^\$]*)\$/
129
+ if (endIndex) {
130
+ return [source.substring(0, endIndex), source.substring(startIndex, index)];
131
+ }
132
+ return null;
133
+ } else if (character === "{") {
134
+ braceLevel++;
135
+ } else if (character === "}") {
136
+ braceLevel--;
137
+ } else if (character === "\n" && source[index - 1] === "\n") {
138
+ // This is a weird case we supported in the old
139
+ // math implementation--double newlines break
140
+ // math. I'm preserving it for now because content
141
+ // creators might have questions with single '$'s
142
+ // in paragraphs...
143
+ return null;
144
+ }
145
+ index++;
146
+ }
147
+
148
+ // we didn't find a closing `$`
149
+ return null;
150
+ };
151
+ var mathMatch = (source, state) => mathMatcher(source, state, false);
152
+ var blockMathMatch = (source, state) => mathMatcher(source, state, true);
153
+ var TITLED_TABLE_REGEX = new RegExp("^\\|\\| +(.*) +\\|\\| *\\n" + "(" +
154
+ // The simple-markdown nptable regex, without
155
+ // the leading `^`
156
+ // $FlowFixMe[incompatible-use]
157
+ // @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
158
+ SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) + ")");
159
+ var crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
160
+ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules), {}, {
161
+ // NOTE: basically ignored by JIPT. wraps everything at the outer layer
162
+ columns: {
163
+ order: -2,
164
+ match: SimpleMarkdown.blockRegex(/^([\s\S]*\n\n)={5,}\n\n([\s\S]*)/),
165
+ parse: (capture, _parse, state) => {
166
+ return {
167
+ col1: _parse(capture[1], state),
168
+ col2: _parse(capture[2], state)
169
+ };
170
+ }
171
+ },
172
+ crowdinId: {
173
+ order: -1,
174
+ match: (source, state, prevCapture) => {
175
+ // Only match on the just-in-place translation site
176
+ if (state.isJipt) {
177
+ return crowdinJiptMatcher(source, state, prevCapture);
178
+ }
179
+ return null;
180
+ },
181
+ parse: (capture, _parse2, state) => ({
182
+ id: capture[1]
183
+ })
184
+ },
185
+ // This is pretty much horrible, but we have a regex here to capture an
186
+ // entire table + a title. capture[1] is the title. capture[2] of the
187
+ // regex is a copy of the simple-markdown nptable regex. Then we turn
188
+ // our capture[2] into tableCapture[0], and any further captures in
189
+ // our table regex into tableCapture[1..], and we pass tableCapture to
190
+ // our nptable regex
191
+ titledTable: {
192
+ // process immediately before nptables
193
+ order: SimpleMarkdown.defaultRules.nptable.order - 0.5,
194
+ match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX),
195
+ parse: (capture, _parse3, state) => {
196
+ var title = SimpleMarkdown.parseInline(_parse3, capture[1], state);
197
+
198
+ // Remove our [0] and [1] captures, and pass the rest to
199
+ // the nptable parser
200
+ var tableCapture = capture.slice(2);
201
+ var table = SimpleMarkdown.defaultRules.nptable.parse(tableCapture, _parse3, state);
202
+ return {
203
+ title: title,
204
+ table: table
205
+ };
206
+ }
207
+ },
208
+ widget: {
209
+ order: SimpleMarkdown.defaultRules.link.order - 0.75,
210
+ match: SimpleMarkdown.inlineRegex(rWidgetRule),
211
+ parse: (capture, _parse4, state) => {
212
+ return {
213
+ id: capture[1],
214
+ widgetType: capture[2]
215
+ };
216
+ }
217
+ },
218
+ blockMath: {
219
+ order: SimpleMarkdown.defaultRules.codeBlock.order + 0.5,
220
+ match: blockMathMatch,
221
+ parse: (capture, _parse5, state) => {
222
+ return {
223
+ content: capture[1]
224
+ };
225
+ }
226
+ },
227
+ math: {
228
+ order: SimpleMarkdown.defaultRules.link.order - 0.25,
229
+ match: mathMatch,
230
+ parse: (capture, _parse6, state) => {
231
+ return {
232
+ content: capture[1]
233
+ };
234
+ }
235
+ },
236
+ unescapedDollar: {
237
+ order: SimpleMarkdown.defaultRules.link.order - 0.24,
238
+ match: SimpleMarkdown.inlineRegex(/^(?!\\)\$/),
239
+ parse: (capture, _parse7, state) => {
240
+ return {};
241
+ }
242
+ },
243
+ fence: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.fence), {}, {
244
+ parse: (capture, _parse8, state) => {
245
+ var node = SimpleMarkdown.defaultRules.fence.parse(capture, _parse8, state);
246
+
247
+ // support screenreader-only text with ```alt
248
+ if (node.lang === "alt") {
249
+ return {
250
+ type: "codeBlock",
251
+ lang: "alt",
252
+ // default codeBlock parsing doesn't parse the contents.
253
+ // We need to parse the contents for things like table
254
+ // support :).
255
+ // The \n\n is because the inside of the codeblock might
256
+ // not end in double newlines for block rules, because
257
+ // ordinarily we don't parse this :).
258
+ content: _parse8(node.content + "\n\n", state)
259
+ };
260
+ }
261
+ return node;
262
+ }
263
+ }),
264
+ blockQuote: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.blockQuote), {}, {
265
+ // Replace the less restrictive blockquote regex from SimpleMarkdown
266
+ // with a more restrictive one. The only difference should be that
267
+ //
268
+ // > A blockquote
269
+ //
270
+ // > Another blockquote
271
+ //
272
+ // will now match as two different blockQuotes instead of a single
273
+ // blockquote with some paragraph breaks in it.
274
+ //
275
+ // The main motivation for doing this is to provide better support for
276
+ // translators translating blockquotes with multiple paragraphs in
277
+ // them. When translating articles, we split up paragraphs, translate
278
+ // them separately, and then recombine them. We do this so that
279
+ // translators don't have to translate an entire article at a time,
280
+ // they can instead translate paragraph-by-paragraph.That system
281
+ // doesn't understand blockquotes, so it will split up blockquotes into
282
+ // more than one paragraph. A way to solve this would be to make that
283
+ // system understand blockquotes, but then translators would have to
284
+ // translate an entire, multi-paragraph blockquote at a time. Instead,
285
+ // we choose to modify our blockquote matching to split up
286
+ // multi-paragraph blockquotes into multiple blockquotes.
287
+ //
288
+ // There is also precedence for doing this splitting up in other
289
+ // libraries, for instance CommonMark also splits up blockquotes with
290
+ // empty lines into multiple blockquotes:
291
+ // https://spec.commonmark.org/0.28/#example-205
292
+ match: SimpleMarkdown.blockRegex(/^ *>[^\n]+(\n( *>)?[^\n]+)*\n{2,}/)
293
+ }),
294
+ list: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.list), {}, {
295
+ match: (source, state, prevCapture) => {
296
+ // Since lists can contain double newlines and we have special
297
+ // handling of double newlines while parsing jipt content, just
298
+ // disable the list parser.
299
+ if (state.isJipt) {
300
+ return null;
301
+ }
302
+ return SimpleMarkdown.defaultRules.list.match(source, state, prevCapture);
303
+ }
304
+ }),
305
+ // The lint rule never actually matches anything.
306
+ // We check for lint after parsing, and, if we find any, we
307
+ // transform the tree to add lint nodes. This rule is here
308
+ // just for the react() function
309
+ lint: {
310
+ order: 1000,
311
+ match: s => null,
312
+ parse: (capture, _parse9, state) => ({})
313
+ }
314
+ });
315
+
316
+ // @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'.
317
+ var builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);
318
+ var parse = (source, state) => {
319
+ var paragraphedSource = source + "\n\n";
320
+ return builtParser(paragraphedSource, _objectSpread2(_objectSpread2({}, state), {}, {
321
+ inline: false
322
+ }));
323
+ };
324
+
325
+ export { parse, pureMarkdownRules };
326
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["/**\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","_objectSpread","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMA,WAAW,GAAG,sCAAsC,CAAA;AAE1D,IAAMC,WAAW,GAAGA,CAACC,MAAW,EAAEC,KAAU,EAAEC,OAAgB,KAAK;AAC/D,EAAA,IAAMC,MAAM,GAAGH,MAAM,CAACG,MAAM,CAAA;EAC5B,IAAIC,KAAK,GAAG,CAAC,CAAA;;AAEb;AACA,EAAA,IAAIF,OAAO,EAAE;IACT,IAAID,KAAK,CAACI,MAAM,EAAE;AACd,MAAA,OAAO,IAAI,CAAA;AACf,KAAA;IAC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