Skip to content

Commit d5d9815

Browse files
macochafk
authored andcommitted
[gatsby-remark-katex] Upgrade remark-math to latest (#4005)
* update remark-math to latest version to fix an issue where equations surrounded by `$$` with new lines are not displayed in KaTeX' `displayMode` * update broken spec * add spec for display math node * [using-remark] fix "Math Equations in Display Mode" example
1 parent 224af0f commit d5d9815

File tree

4 files changed

+84
-18
lines changed

4 files changed

+84
-18
lines changed

examples/using-remark/src/pages/2017-08-07---katex/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ a^2 + b^2 = c^2
3737
$$
3838
```
3939

40-
**Example output:** $$ a^2 + b^2 = c^2 $$
40+
**Example output:**
41+
$$
42+
a^2 + b^2 = c^2
43+
$$
4144

4245
**Add Katex CSS to your template** Katex's CSS file is required to render the
4346
formulas correctly. Include the CSS file in your template ([example][4])

packages/gatsby-remark-katex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"babel-runtime": "^6.26.0",
1111
"katex": "^0.8.3",
12-
"remark-math": "^0.2.4",
12+
"remark-math": "^1.0.3",
1313
"unist-util-visit": "^1.1.1"
1414
},
1515
"devDependencies": {

packages/gatsby-remark-katex/src/__tests__/__snapshots__/index.js.snap

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`remark katex plugin renders inlineMath node properly 1`] = `
3+
exports[`remark katex plugin renders double $ inlineMath node properly 1`] = `
44
Object {
55
"children": Array [
66
Object {
@@ -20,9 +20,9 @@ Object {
2020
},
2121
"position": Position {
2222
"end": Object {
23-
"column": 18,
23+
"column": 20,
2424
"line": 1,
25-
"offset": 17,
25+
"offset": 19,
2626
},
2727
"indent": Array [],
2828
"start": Object {
@@ -37,9 +37,9 @@ Object {
3737
],
3838
"position": Position {
3939
"end": Object {
40-
"column": 18,
40+
"column": 20,
4141
"line": 1,
42-
"offset": 17,
42+
"offset": 19,
4343
},
4444
"indent": Array [],
4545
"start": Object {
@@ -53,9 +53,9 @@ Object {
5353
],
5454
"position": Object {
5555
"end": Object {
56-
"column": 18,
56+
"column": 20,
5757
"line": 1,
58-
"offset": 17,
58+
"offset": 19,
5959
},
6060
"start": Object {
6161
"column": 1,
@@ -67,7 +67,7 @@ Object {
6767
}
6868
`;
6969

70-
exports[`remark katex plugin renders math node properly 1`] = `
70+
exports[`remark katex plugin renders inlineMath node properly 1`] = `
7171
Object {
7272
"children": Array [
7373
Object {
@@ -82,14 +82,14 @@ Object {
8282
],
8383
"hName": "span",
8484
"hProperties": Object {
85-
"className": "inlineMath inlineMathDouble",
85+
"className": "inlineMath",
8686
},
8787
},
8888
"position": Position {
8989
"end": Object {
90-
"column": 20,
90+
"column": 18,
9191
"line": 1,
92-
"offset": 19,
92+
"offset": 17,
9393
},
9494
"indent": Array [],
9595
"start": Object {
@@ -104,9 +104,9 @@ Object {
104104
],
105105
"position": Position {
106106
"end": Object {
107-
"column": 20,
107+
"column": 18,
108108
"line": 1,
109-
"offset": 19,
109+
"offset": 17,
110110
},
111111
"indent": Array [],
112112
"start": Object {
@@ -120,9 +120,61 @@ Object {
120120
],
121121
"position": Object {
122122
"end": Object {
123-
"column": 20,
123+
"column": 18,
124124
"line": 1,
125-
"offset": 19,
125+
"offset": 17,
126+
},
127+
"start": Object {
128+
"column": 1,
129+
"line": 1,
130+
"offset": 0,
131+
},
132+
},
133+
"type": "root",
134+
}
135+
`;
136+
137+
exports[`remark katex plugin renders math node properly 1`] = `
138+
Object {
139+
"children": Array [
140+
Object {
141+
"data": Object {
142+
"hChildren": Array [
143+
Object {
144+
"type": "text",
145+
"value": "a^2 + b^2 = c^2",
146+
},
147+
],
148+
"hName": "div",
149+
"hProperties": Object {
150+
"className": "math",
151+
},
152+
},
153+
"position": Position {
154+
"end": Object {
155+
"column": 3,
156+
"line": 3,
157+
"offset": 21,
158+
},
159+
"indent": Array [
160+
1,
161+
1,
162+
],
163+
"start": Object {
164+
"column": 1,
165+
"line": 1,
166+
"offset": 0,
167+
},
168+
},
169+
"type": "html",
170+
"value": "<span class=\\"katex-display\\"><span class=\\"katex\\"><span class=\\"katex-mathml\\"><math><semantics><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup></mrow><annotation encoding=\\"application/x-tex\\">a^2 + b^2 = c^2</annotation></semantics></math></span><span class=\\"katex-html\\" aria-hidden=\\"true\\"><span class=\\"strut\\" style=\\"height:0.8641079999999999em;\\"></span><span class=\\"strut bottom\\" style=\\"height:0.9474379999999999em;vertical-align:-0.08333em;\\"></span><span class=\\"base\\"><span class=\\"mord\\"><span class=\\"mord mathit\\">a</span><span class=\\"msupsub\\"><span class=\\"vlist-t\\"><span class=\\"vlist-r\\"><span class=\\"vlist\\" style=\\"height:0.8641079999999999em;\\"><span style=\\"top:-3.113em;margin-right:0.05em;\\"><span class=\\"pstrut\\" style=\\"height:2.7em;\\"></span><span class=\\"sizing reset-size6 size3 mtight\\"><span class=\\"mord mathrm mtight\\">2</span></span></span></span></span></span></span></span><span class=\\"mbin\\">+</span><span class=\\"mord\\"><span class=\\"mord mathit\\">b</span><span class=\\"msupsub\\"><span class=\\"vlist-t\\"><span class=\\"vlist-r\\"><span class=\\"vlist\\" style=\\"height:0.8641079999999999em;\\"><span style=\\"top:-3.113em;margin-right:0.05em;\\"><span class=\\"pstrut\\" style=\\"height:2.7em;\\"></span><span class=\\"sizing reset-size6 size3 mtight\\"><span class=\\"mord mathrm mtight\\">2</span></span></span></span></span></span></span></span><span class=\\"mrel\\">=</span><span class=\\"mord\\"><span class=\\"mord mathit\\">c</span><span class=\\"msupsub\\"><span class=\\"vlist-t\\"><span class=\\"vlist-r\\"><span class=\\"vlist\\" style=\\"height:0.8641079999999999em;\\"><span style=\\"top:-3.113em;margin-right:0.05em;\\"><span class=\\"pstrut\\" style=\\"height:2.7em;\\"></span><span class=\\"sizing reset-size6 size3 mtight\\"><span class=\\"mord mathrm mtight\\">2</span></span></span></span></span></span></span></span></span></span></span></span>",
171+
},
172+
],
173+
"position": Object {
174+
"end": Object {
175+
"column": 3,
176+
"line": 3,
177+
"offset": 21,
126178
},
127179
"start": Object {
128180
"column": 1,

packages/gatsby-remark-katex/src/__tests__/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe(`remark katex plugin`, () => {
1313
expect(markdownAST).toMatchSnapshot()
1414
})
1515

16-
it(`renders math node properly`, () => {
16+
it(`renders double $ inlineMath node properly`, () => {
1717
const equation = `$$a^2 + b^2 = c^2$$`
1818
let remark = new Remark()
1919
for (let parserPlugins of plugin.setParserPlugins()) {
@@ -23,4 +23,15 @@ describe(`remark katex plugin`, () => {
2323
plugin({ markdownAST })
2424
expect(markdownAST).toMatchSnapshot()
2525
})
26+
27+
it(`renders math node properly`, () => {
28+
const equation = `$$\na^2 + b^2 = c^2\n$$`
29+
let remark = new Remark()
30+
for (let parserPlugins of plugin.setParserPlugins()) {
31+
remark = remark.use(parserPlugins)
32+
}
33+
const markdownAST = remark.parse(equation)
34+
plugin({ markdownAST })
35+
expect(markdownAST).toMatchSnapshot()
36+
})
2637
})

0 commit comments

Comments
 (0)