@@ -25,7 +25,7 @@ test('rehype-katex', async function (t) {
25
25
. use ( rehypeStringify )
26
26
. process (
27
27
[
28
- '<p>Inline math <code class="math-inline">\\alpha</code >.</p>' ,
28
+ '<p>Inline math <span class="math-inline">\\alpha</span >.</p>' ,
29
29
'<p>Block math:</p>' ,
30
30
'<div class="math-display">\\gamma</div>'
31
31
] . join ( '\n' )
@@ -37,19 +37,35 @@ test('rehype-katex', async function (t) {
37
37
. use ( rehypeStringify )
38
38
. process (
39
39
[
40
- '<p>Inline math <code class="math-inline">' +
41
- katex . renderToString ( '\\alpha' ) +
42
- '</code>.</p>' ,
40
+ '<p>Inline math ' + katex . renderToString ( '\\alpha' ) + '.</p>' ,
43
41
'<p>Block math:</p>' ,
44
- '<div class="math-display">' +
45
- katex . renderToString ( '\\gamma' , { displayMode : true } ) +
46
- '</div>'
42
+ katex . renderToString ( '\\gamma' , { displayMode : true } )
47
43
] . join ( '\n' )
48
44
)
49
45
)
50
46
)
51
47
} )
52
48
49
+ await t . test ( 'should support markdown fenced code' , async function ( ) {
50
+ assert . deepEqual (
51
+ String (
52
+ await unified ( )
53
+ . use ( remarkParse )
54
+ // @ts -expect-error: to do: remove when `remark-rehype` is released.
55
+ . use ( remarkRehype )
56
+ . use ( rehypeKatex )
57
+ . use ( rehypeStringify )
58
+ . process ( '```math\n\\gamma\n```' )
59
+ ) ,
60
+ String (
61
+ await unified ( )
62
+ . use ( rehypeParse , { fragment : true } )
63
+ . use ( rehypeStringify )
64
+ . process ( katex . renderToString ( '\\gamma\n' , { displayMode : true } ) )
65
+ )
66
+ )
67
+ } )
68
+
53
69
await t . test ( 'should integrate with `remark-math`' , async function ( ) {
54
70
assert . deepEqual (
55
71
String (
@@ -78,13 +94,9 @@ test('rehype-katex', async function (t) {
78
94
. use ( rehypeStringify )
79
95
. process (
80
96
[
81
- '<p>Inline math <code class="language-math math-inline">' +
82
- katex . renderToString ( '\\alpha' ) +
83
- '</code>.</p>' ,
97
+ '<p>Inline math ' + katex . renderToString ( '\\alpha' ) + '.</p>' ,
84
98
'<p>Block math:</p>' ,
85
- '<pre><code class="language-math math-display">' +
86
- katex . renderToString ( '\\gamma' , { displayMode : true } ) +
87
- '</code></pre>'
99
+ katex . renderToString ( '\\gamma' , { displayMode : true } )
88
100
] . join ( '\n' )
89
101
)
90
102
)
@@ -109,9 +121,9 @@ test('rehype-katex', async function (t) {
109
121
. use ( rehypeParse , { fragment : true } )
110
122
. use ( rehypeStringify )
111
123
. process (
112
- '<p>Double math <code class="math-inline math-display"> ' +
124
+ '<p>Double math ' +
113
125
katex . renderToString ( '\\alpha' , { displayMode : true } ) +
114
- '</code> .</p>'
126
+ '.</p>'
115
127
)
116
128
)
117
129
)
@@ -127,17 +139,13 @@ test('rehype-katex', async function (t) {
127
139
. use ( rehypeParse , { fragment : true } )
128
140
. use ( rehypeKatex , { macros} )
129
141
. use ( rehypeStringify )
130
- . process ( '<code class="math-inline">\\RR</code >' )
142
+ . process ( '<span class="math-inline">\\RR</span >' )
131
143
) ,
132
144
String (
133
145
await unified ( )
134
146
. use ( rehypeParse , { fragment : true } )
135
147
. use ( rehypeStringify )
136
- . process (
137
- '<code class="math-inline">' +
138
- katex . renderToString ( '\\RR' , { macros} ) +
139
- '</code>'
140
- )
148
+ . process ( katex . renderToString ( '\\RR' , { macros} ) )
141
149
)
142
150
)
143
151
} )
@@ -147,7 +155,7 @@ test('rehype-katex', async function (t) {
147
155
. use ( rehypeParse , { fragment : true } )
148
156
. use ( rehypeKatex , { errorColor : 'orange' } )
149
157
. use ( rehypeStringify )
150
- . process ( '<code class="math-inline">\\alpa</code >' )
158
+ . process ( '<span class="math-inline">\\alpa</span >' )
151
159
152
160
assert . deepEqual (
153
161
String ( file ) ,
@@ -156,12 +164,10 @@ test('rehype-katex', async function (t) {
156
164
. use ( rehypeParse , { fragment : true } )
157
165
. use ( rehypeStringify )
158
166
. process (
159
- '<code class="math-inline">' +
160
- katex . renderToString ( '\\alpa' , {
161
- errorColor : 'orange' ,
162
- throwOnError : false
163
- } ) +
164
- '</code>'
167
+ katex . renderToString ( '\\alpa' , {
168
+ errorColor : 'orange' ,
169
+ throwOnError : false
170
+ } )
165
171
)
166
172
)
167
173
)
@@ -170,11 +176,11 @@ test('rehype-katex', async function (t) {
170
176
const message = file . messages [ 0 ]
171
177
assert ( message )
172
178
assert ( message . cause )
173
- assert ( message . ancestors )
174
179
assert . match (
175
180
String ( message . cause ) ,
176
181
/ K a T e X p a r s e e r r o r : U n d e f i n e d c o n t r o l s e q u e n c e /
177
182
)
183
+ assert ( message . ancestors )
178
184
assert . equal ( message . ancestors . length , 2 )
179
185
assert . deepEqual (
180
186
{ ...file . messages [ 0 ] , cause : undefined , ancestors : [ ] } ,
@@ -204,14 +210,14 @@ test('rehype-katex', async function (t) {
204
210
. use ( rehypeParse , { fragment : true } )
205
211
. use ( rehypeKatex , { errorColor : 'orange' , strict : 'ignore' } )
206
212
. use ( rehypeStringify )
207
- . process ( '<code class="math-inline">ê&</code >' )
213
+ . process ( '<span class="math-inline">ê&</span >' )
208
214
) ,
209
215
String (
210
216
await unified ( )
211
217
. use ( rehypeParse , { fragment : true } )
212
218
. use ( rehypeStringify )
213
219
. process (
214
- '<code class="math-inline">< span class="katex-error" title="ParseError: KaTeX parse error: Expected \'EOF\', got \'&\' at position 2: ê&̲" style="color:orange">ê&</span></code >'
220
+ '<span class="katex-error" title="ParseError: KaTeX parse error: Expected \'EOF\', got \'&\' at position 2: ê&̲" style="color:orange">ê&</span>'
215
221
)
216
222
)
217
223
)
@@ -225,20 +231,18 @@ test('rehype-katex', async function (t) {
225
231
. use ( rehypeKatex , { errorColor : 'orange' , strict : 'ignore' } )
226
232
. use ( rehypeStringify )
227
233
. process (
228
- '<div class="math math -display">\\begin{split}\n f(-2) &= \\sqrt{-2+4} \\\\\n &= x % Test Comment\n\\end{split}</div>'
234
+ '<div class="math-display">\\begin{split}\n f(-2) &= \\sqrt{-2+4} \\\\\n &= x % Test Comment\n\\end{split}</div>'
229
235
)
230
236
) ,
231
237
String (
232
238
await unified ( )
233
239
. use ( rehypeParse , { fragment : true } )
234
240
. use ( rehypeStringify )
235
241
. process (
236
- '<div class="math math-display">' +
237
- katex . renderToString (
238
- '\\begin{split}\n f(-2) &= \\sqrt{-2+4} \\\\\n &= x % Test Comment\n\\end{split}' ,
239
- { displayMode : true }
240
- ) +
241
- '</div>'
242
+ katex . renderToString (
243
+ '\\begin{split}\n f(-2) &= \\sqrt{-2+4} \\\\\n &= x % Test Comment\n\\end{split}' ,
244
+ { displayMode : true }
245
+ )
242
246
)
243
247
)
244
248
)
@@ -252,15 +256,15 @@ test('rehype-katex', async function (t) {
252
256
. use ( rehypeKatex )
253
257
. use ( rehypeStringify )
254
258
. process (
255
- '<code class="math-display">\\begin{split}\n\\end{{split}}\n</code >'
259
+ '<span class="math-display">\\begin{split}\n\\end{{split}}\n</span >'
256
260
)
257
261
) ,
258
262
String (
259
263
await unified ( )
260
264
. use ( rehypeParse , { fragment : true } )
261
265
. use ( rehypeStringify )
262
266
. process (
263
- '<code class="math-display">< span class="katex-error" style="color:#cc0000" title="Error: Expected node of type textord, but got node of type ordgroup">\\begin{split}\n\\end{{split}}\n</span></code >'
267
+ '<span class="katex-error" style="color:#cc0000" title="Error: Expected node of type textord, but got node of type ordgroup">\\begin{split}\n\\end{{split}}\n</span>'
264
268
)
265
269
)
266
270
)
0 commit comments