@@ -25,7 +25,7 @@ test('rehype-katex', async function (t) {
2525 . use ( rehypeStringify )
2626 . process (
2727 [
28- '<p>Inline math <code class="math-inline">\\alpha</code >.</p>' ,
28+ '<p>Inline math <span class="math-inline">\\alpha</span >.</p>' ,
2929 '<p>Block math:</p>' ,
3030 '<div class="math-display">\\gamma</div>'
3131 ] . join ( '\n' )
@@ -37,19 +37,35 @@ test('rehype-katex', async function (t) {
3737 . use ( rehypeStringify )
3838 . process (
3939 [
40- '<p>Inline math <code class="math-inline">' +
41- katex . renderToString ( '\\alpha' ) +
42- '</code>.</p>' ,
40+ '<p>Inline math ' + katex . renderToString ( '\\alpha' ) + '.</p>' ,
4341 '<p>Block math:</p>' ,
44- '<div class="math-display">' +
45- katex . renderToString ( '\\gamma' , { displayMode : true } ) +
46- '</div>'
42+ katex . renderToString ( '\\gamma' , { displayMode : true } )
4743 ] . join ( '\n' )
4844 )
4945 )
5046 )
5147 } )
5248
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+
5369 await t . test ( 'should integrate with `remark-math`' , async function ( ) {
5470 assert . deepEqual (
5571 String (
@@ -78,13 +94,9 @@ test('rehype-katex', async function (t) {
7894 . use ( rehypeStringify )
7995 . process (
8096 [
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>' ,
8498 '<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 } )
88100 ] . join ( '\n' )
89101 )
90102 )
@@ -109,9 +121,9 @@ test('rehype-katex', async function (t) {
109121 . use ( rehypeParse , { fragment : true } )
110122 . use ( rehypeStringify )
111123 . process (
112- '<p>Double math <code class="math-inline math-display"> ' +
124+ '<p>Double math ' +
113125 katex . renderToString ( '\\alpha' , { displayMode : true } ) +
114- '</code> .</p>'
126+ '.</p>'
115127 )
116128 )
117129 )
@@ -127,17 +139,13 @@ test('rehype-katex', async function (t) {
127139 . use ( rehypeParse , { fragment : true } )
128140 . use ( rehypeKatex , { macros} )
129141 . use ( rehypeStringify )
130- . process ( '<code class="math-inline">\\RR</code >' )
142+ . process ( '<span class="math-inline">\\RR</span >' )
131143 ) ,
132144 String (
133145 await unified ( )
134146 . use ( rehypeParse , { fragment : true } )
135147 . use ( rehypeStringify )
136- . process (
137- '<code class="math-inline">' +
138- katex . renderToString ( '\\RR' , { macros} ) +
139- '</code>'
140- )
148+ . process ( katex . renderToString ( '\\RR' , { macros} ) )
141149 )
142150 )
143151 } )
@@ -147,7 +155,7 @@ test('rehype-katex', async function (t) {
147155 . use ( rehypeParse , { fragment : true } )
148156 . use ( rehypeKatex , { errorColor : 'orange' } )
149157 . use ( rehypeStringify )
150- . process ( '<code class="math-inline">\\alpa</code >' )
158+ . process ( '<span class="math-inline">\\alpa</span >' )
151159
152160 assert . deepEqual (
153161 String ( file ) ,
@@ -156,12 +164,10 @@ test('rehype-katex', async function (t) {
156164 . use ( rehypeParse , { fragment : true } )
157165 . use ( rehypeStringify )
158166 . 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+ } )
165171 )
166172 )
167173 )
@@ -170,11 +176,11 @@ test('rehype-katex', async function (t) {
170176 const message = file . messages [ 0 ]
171177 assert ( message )
172178 assert ( message . cause )
173- assert ( message . ancestors )
174179 assert . match (
175180 String ( message . cause ) ,
176181 / 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 /
177182 )
183+ assert ( message . ancestors )
178184 assert . equal ( message . ancestors . length , 2 )
179185 assert . deepEqual (
180186 { ...file . messages [ 0 ] , cause : undefined , ancestors : [ ] } ,
@@ -204,14 +210,14 @@ test('rehype-katex', async function (t) {
204210 . use ( rehypeParse , { fragment : true } )
205211 . use ( rehypeKatex , { errorColor : 'orange' , strict : 'ignore' } )
206212 . use ( rehypeStringify )
207- . process ( '<code class="math-inline">ê&</code >' )
213+ . process ( '<span class="math-inline">ê&</span >' )
208214 ) ,
209215 String (
210216 await unified ( )
211217 . use ( rehypeParse , { fragment : true } )
212218 . use ( rehypeStringify )
213219 . 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>'
215221 )
216222 )
217223 )
@@ -225,20 +231,18 @@ test('rehype-katex', async function (t) {
225231 . use ( rehypeKatex , { errorColor : 'orange' , strict : 'ignore' } )
226232 . use ( rehypeStringify )
227233 . 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>'
229235 )
230236 ) ,
231237 String (
232238 await unified ( )
233239 . use ( rehypeParse , { fragment : true } )
234240 . use ( rehypeStringify )
235241 . 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+ )
242246 )
243247 )
244248 )
@@ -252,15 +256,15 @@ test('rehype-katex', async function (t) {
252256 . use ( rehypeKatex )
253257 . use ( rehypeStringify )
254258 . 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 >'
256260 )
257261 ) ,
258262 String (
259263 await unified ( )
260264 . use ( rehypeParse , { fragment : true } )
261265 . use ( rehypeStringify )
262266 . 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>'
264268 )
265269 )
266270 )
0 commit comments