@khanacademy/pure-markdown 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/CHANGELOG.md +19 -0
- package/dist/es/index.js +38 -34
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +340 -2
- package/dist/index.js +34 -33
- package/dist/index.js.flow +876 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/{index_test.js → index.test.ts} +3 -2
- package/src/{index.js → index.ts} +15 -15
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
- /package/src/__tests__/__snapshots__/{index_test.js.snap → index.test.ts.snap} +0 -0
package/.eslintrc.js
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @khanacademy/pure-markdown
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 53fd3768: Migrate source code to TypeScript
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [53fd3768]
|
|
12
|
+
- @khanacademy/perseus-error@0.2.0
|
|
13
|
+
- @khanacademy/simple-markdown@0.9.0
|
|
14
|
+
|
|
15
|
+
## 0.1.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [a1b4ab3c]
|
|
20
|
+
- @khanacademy/perseus-error@0.1.5
|
|
21
|
+
|
|
3
22
|
## 0.1.4
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -2,17 +2,14 @@ import SimpleMarkdown from '@khanacademy/simple-markdown';
|
|
|
2
2
|
|
|
3
3
|
function ownKeys(object, enumerableOnly) {
|
|
4
4
|
var keys = Object.keys(object);
|
|
5
|
-
|
|
6
5
|
if (Object.getOwnPropertySymbols) {
|
|
7
6
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
8
7
|
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
9
8
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
10
9
|
})), keys.push.apply(keys, symbols);
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return keys;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
function _objectSpread2(target) {
|
|
17
14
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
15
|
var source = null != arguments[i] ? arguments[i] : {};
|
|
@@ -22,11 +19,10 @@ function _objectSpread2(target) {
|
|
|
22
19
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
23
20
|
});
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
return target;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
function _defineProperty(obj, key, value) {
|
|
25
|
+
key = _toPropertyKey(key);
|
|
30
26
|
if (key in obj) {
|
|
31
27
|
Object.defineProperty(obj, key, {
|
|
32
28
|
value: value,
|
|
@@ -37,9 +33,22 @@ function _defineProperty(obj, key, value) {
|
|
|
37
33
|
} else {
|
|
38
34
|
obj[key] = value;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return obj;
|
|
42
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
|
+
}
|
|
43
52
|
|
|
44
53
|
/**
|
|
45
54
|
* This match function matches math in `$`s, such as:
|
|
@@ -65,35 +74,33 @@ function _defineProperty(obj, key, value) {
|
|
|
65
74
|
*/
|
|
66
75
|
|
|
67
76
|
var rWidgetRule = /^\[\[\u2603 (([a-z-]+) ([0-9]+))\]\]/;
|
|
68
|
-
|
|
69
77
|
var mathMatcher = (source, state, isBlock) => {
|
|
70
78
|
var length = source.length;
|
|
71
|
-
var index = 0;
|
|
79
|
+
var index = 0;
|
|
72
80
|
|
|
81
|
+
// When looking for blocks, skip over leading spaces
|
|
73
82
|
if (isBlock) {
|
|
74
83
|
if (state.inline) {
|
|
75
84
|
return null;
|
|
76
85
|
}
|
|
77
|
-
|
|
78
86
|
while (index < length && source[index] === " ") {
|
|
79
87
|
index++;
|
|
80
88
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
89
|
+
}
|
|
83
90
|
|
|
91
|
+
// Our source must start with a "$"
|
|
84
92
|
if (!(index < length && source[index] === "$")) {
|
|
85
93
|
return null;
|
|
86
94
|
}
|
|
87
|
-
|
|
88
95
|
index++;
|
|
89
96
|
var startIndex = index;
|
|
90
|
-
var braceLevel = 0;
|
|
97
|
+
var braceLevel = 0;
|
|
98
|
+
|
|
99
|
+
// Loop through the source, looking for a closing '$'
|
|
91
100
|
// closing '$'s only count if they are not escaped with
|
|
92
101
|
// a `\`, and we are not in nested `{}` braces.
|
|
93
|
-
|
|
94
102
|
while (index < length) {
|
|
95
103
|
var character = source[index];
|
|
96
|
-
|
|
97
104
|
if (character === "\\") {
|
|
98
105
|
// Consume both the `\` and the escaped char as a single
|
|
99
106
|
// token.
|
|
@@ -106,23 +113,22 @@ var mathMatcher = (source, state, isBlock) => {
|
|
|
106
113
|
index++;
|
|
107
114
|
} else if (braceLevel <= 0 && character === "$") {
|
|
108
115
|
var endIndex = index + 1;
|
|
109
|
-
|
|
110
116
|
if (isBlock) {
|
|
111
117
|
// Look for two trailing newlines after the closing `$`
|
|
112
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'.
|
|
113
120
|
endIndex = match ? endIndex + match[0].length : null;
|
|
114
|
-
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Return an array that looks like the results of a
|
|
115
124
|
// regex's .exec function:
|
|
116
125
|
// capture[0] is the whole string
|
|
117
126
|
// capture[1] is the first "paren" match, which is the
|
|
118
127
|
// content of the math here, as if we wrote the regex
|
|
119
128
|
// /\$([^\$]*)\$/
|
|
120
|
-
|
|
121
|
-
|
|
122
129
|
if (endIndex) {
|
|
123
130
|
return [source.substring(0, endIndex), source.substring(startIndex, index)];
|
|
124
131
|
}
|
|
125
|
-
|
|
126
132
|
return null;
|
|
127
133
|
} else if (character === "{") {
|
|
128
134
|
braceLevel++;
|
|
@@ -136,21 +142,19 @@ var mathMatcher = (source, state, isBlock) => {
|
|
|
136
142
|
// in paragraphs...
|
|
137
143
|
return null;
|
|
138
144
|
}
|
|
139
|
-
|
|
140
145
|
index++;
|
|
141
|
-
}
|
|
142
|
-
|
|
146
|
+
}
|
|
143
147
|
|
|
148
|
+
// we didn't find a closing `$`
|
|
144
149
|
return null;
|
|
145
150
|
};
|
|
146
|
-
|
|
147
151
|
var mathMatch = (source, state) => mathMatcher(source, state, false);
|
|
148
|
-
|
|
149
152
|
var blockMathMatch = (source, state) => mathMatcher(source, state, true);
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
var TITLED_TABLE_REGEX = new RegExp("^\\|\\| +(.*) +\\|\\| *\\n" + "(" +
|
|
154
|
+
// The simple-markdown nptable regex, without
|
|
152
155
|
// the leading `^`
|
|
153
156
|
// $FlowFixMe[incompatible-use]
|
|
157
|
+
// @ts-expect-error [FEI-5003] - TS2532 - Object is possibly 'undefined'.
|
|
154
158
|
SimpleMarkdown.defaultRules.nptable.match.regex.source.substring(1) + ")");
|
|
155
159
|
var crowdinJiptMatcher = SimpleMarkdown.blockRegex(/^(crwdns.*)\n\s*\n/);
|
|
156
160
|
var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules), {}, {
|
|
@@ -172,7 +176,6 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
172
176
|
if (state.isJipt) {
|
|
173
177
|
return crowdinJiptMatcher(source, state, prevCapture);
|
|
174
178
|
}
|
|
175
|
-
|
|
176
179
|
return null;
|
|
177
180
|
},
|
|
178
181
|
parse: (capture, _parse2, state) => ({
|
|
@@ -190,9 +193,10 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
190
193
|
order: SimpleMarkdown.defaultRules.nptable.order - 0.5,
|
|
191
194
|
match: SimpleMarkdown.blockRegex(TITLED_TABLE_REGEX),
|
|
192
195
|
parse: (capture, _parse3, state) => {
|
|
193
|
-
var title = SimpleMarkdown.parseInline(_parse3, capture[1], state);
|
|
194
|
-
// the nptable parser
|
|
196
|
+
var title = SimpleMarkdown.parseInline(_parse3, capture[1], state);
|
|
195
197
|
|
|
198
|
+
// Remove our [0] and [1] captures, and pass the rest to
|
|
199
|
+
// the nptable parser
|
|
196
200
|
var tableCapture = capture.slice(2);
|
|
197
201
|
var table = SimpleMarkdown.defaultRules.nptable.parse(tableCapture, _parse3, state);
|
|
198
202
|
return {
|
|
@@ -238,8 +242,9 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
238
242
|
},
|
|
239
243
|
fence: _objectSpread2(_objectSpread2({}, SimpleMarkdown.defaultRules.fence), {}, {
|
|
240
244
|
parse: (capture, _parse8, state) => {
|
|
241
|
-
var node = SimpleMarkdown.defaultRules.fence.parse(capture, _parse8, state);
|
|
245
|
+
var node = SimpleMarkdown.defaultRules.fence.parse(capture, _parse8, state);
|
|
242
246
|
|
|
247
|
+
// support screenreader-only text with ```alt
|
|
243
248
|
if (node.lang === "alt") {
|
|
244
249
|
return {
|
|
245
250
|
type: "codeBlock",
|
|
@@ -253,7 +258,6 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
253
258
|
content: _parse8(node.content + "\n\n", state)
|
|
254
259
|
};
|
|
255
260
|
}
|
|
256
|
-
|
|
257
261
|
return node;
|
|
258
262
|
}
|
|
259
263
|
}),
|
|
@@ -295,7 +299,6 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
295
299
|
if (state.isJipt) {
|
|
296
300
|
return null;
|
|
297
301
|
}
|
|
298
|
-
|
|
299
302
|
return SimpleMarkdown.defaultRules.list.match(source, state, prevCapture);
|
|
300
303
|
}
|
|
301
304
|
}),
|
|
@@ -308,8 +311,9 @@ var pureMarkdownRules = _objectSpread2(_objectSpread2({}, SimpleMarkdown.default
|
|
|
308
311
|
match: s => null,
|
|
309
312
|
parse: (capture, _parse9, state) => ({})
|
|
310
313
|
}
|
|
311
|
-
});
|
|
314
|
+
});
|
|
312
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'.
|
|
313
317
|
var builtParser = SimpleMarkdown.parserFor(pureMarkdownRules);
|
|
314
318
|
var parse = (source, state) => {
|
|
315
319
|
var paragraphedSource = source + "\n\n";
|
package/dist/es/index.js.map
CHANGED
|
@@ -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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B,CAAA;AAsJ1B+B,EAAAA,IAAI,EACGpC,cAAAA,CAAAA,cAAAA,CAAAA,EAAAA,EAAAA,cAAc,CAACC,YAAf,CAA4BmC,IAD/B,CAAA,EAAA,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":["../../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;IACA,OAAOD,KAAK,GAAGD,MAAM,IAAIH,MAAM,CAACI,KAAK,CAAC,KAAK,GAAG,EAAE;AAC5C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