@khanacademy/perseus 0.2.6 → 0.2.7
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/CHANGELOG.md +8 -0
- package/dist/es/index.js +11 -6
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/jipt-paragraphs_test.js +34 -0
- package/src/jipt-paragraphs.js +16 -8
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Core Perseus API (includes renderers and widgets)",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.7",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@khanacademy/kmath": "^0.0.5",
|
|
25
25
|
"@khanacademy/math-input": "^0.5.2",
|
|
26
26
|
"@khanacademy/kas": "^0.2.4",
|
|
27
|
-
"@khanacademy/simple-markdown": "^0.8.
|
|
27
|
+
"@khanacademy/simple-markdown": "^0.8.3",
|
|
28
28
|
"mathquill": "git+https://git@github.com/Khan/mathquill.git#a9ae54e057c5c1acc8244a5627acbff29901d992"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import JiptParagraphs from "../jipt-paragraphs.js";
|
|
4
|
+
|
|
5
|
+
const {parseToArray} = JiptParagraphs;
|
|
6
|
+
|
|
7
|
+
describe("jipt-paragraphs", () => {
|
|
8
|
+
it("should split paragraphs using custom JIPT SimpleMarkdown rules", () => {
|
|
9
|
+
expect(parseToArray(" \n\nhello\n\n")).toMatchInlineSnapshot(`
|
|
10
|
+
Array [
|
|
11
|
+
" ",
|
|
12
|
+
"hello",
|
|
13
|
+
]
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should recognize code fences using custom JIPT SimpleMarkdown rules", () => {
|
|
18
|
+
expect(
|
|
19
|
+
parseToArray(
|
|
20
|
+
"Let's write the canonical Hello World in Javascript\n\n" +
|
|
21
|
+
'```js\nconst x = "hello world";\nconsole.log(x);```\n\n' +
|
|
22
|
+
"**Congratulations, you are on your way to becoming a " +
|
|
23
|
+
"computer programmer!",
|
|
24
|
+
),
|
|
25
|
+
).toMatchInlineSnapshot(`
|
|
26
|
+
Array [
|
|
27
|
+
"Let's write the canonical Hello World in Javascript",
|
|
28
|
+
"const x = \\"hello world\\";
|
|
29
|
+
console.log(x);",
|
|
30
|
+
"**Congratulations, you are on your way to becoming a computer programmer!",
|
|
31
|
+
]
|
|
32
|
+
`);
|
|
33
|
+
});
|
|
34
|
+
});
|
package/src/jipt-paragraphs.js
CHANGED
|
@@ -11,28 +11,36 @@ const arrayRules: ParserRules = {
|
|
|
11
11
|
fence: {
|
|
12
12
|
match: SimpleMarkdown.defaultRules.fence.match,
|
|
13
13
|
order: 1,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
parse: (capture, state, parse) => ({
|
|
15
|
+
type: "codeBlock",
|
|
16
|
+
lang: capture[2] || undefined,
|
|
17
|
+
content: capture[3],
|
|
18
|
+
}),
|
|
16
19
|
},
|
|
17
20
|
paragraph: {
|
|
18
21
|
match: SimpleMarkdown.defaultRules.paragraph.match,
|
|
19
22
|
order: 2,
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
parse: (capture, state, parse) => ({
|
|
24
|
+
content: capture[1],
|
|
25
|
+
}),
|
|
22
26
|
},
|
|
23
27
|
};
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const builtArrayParser: $Call<
|
|
30
|
+
typeof SimpleMarkdown.parserFor,
|
|
31
|
+
typeof arrayRules,
|
|
32
|
+
> = SimpleMarkdown.parserFor(arrayRules);
|
|
27
33
|
|
|
28
34
|
// This should just return an array of strings! magick!
|
|
29
|
-
const parseToArray = (source: string):
|
|
35
|
+
const parseToArray = (source: string): Array<string> => {
|
|
30
36
|
// Remove any leading newlines to avoid splitting weirdness
|
|
31
37
|
// (simple-markdown has the `newline` rule for this, and i have
|
|
32
38
|
// no idea how this will handle leading newlines without that rule),
|
|
33
39
|
// and add \n\n to let it parse at a block/paragraph level
|
|
34
40
|
const paragraphedSource = source.replace(/^\n\s*\n/, "") + "\n\n";
|
|
35
|
-
return builtArrayParser(paragraphedSource, {inline: false})
|
|
41
|
+
return builtArrayParser(paragraphedSource, {inline: false}).map((c) => {
|
|
42
|
+
return c["content"];
|
|
43
|
+
});
|
|
36
44
|
};
|
|
37
45
|
|
|
38
46
|
const joinFromArray = (paragraphs: $ReadOnlyArray<string>): string =>
|