1
1
import React , { useState } from 'react'
2
- import {
3
- blockRegex ,
4
- parseCaptureInline ,
5
- Priority ,
6
- simpleInlineRegex ,
7
- } from 'markdown-to-jsx'
2
+ import { blockRegex , Priority , simpleInlineRegex } from 'markdown-to-jsx'
8
3
import type { MarkdownToJSX } from 'markdown-to-jsx'
9
4
import type { FC } from 'react'
10
5
@@ -17,17 +12,16 @@ export const KateXRule: MarkdownToJSX.Rule = {
17
12
match : simpleInlineRegex (
18
13
/ ^ \$ \s { 0 , } ( (?: \[ .* ?\] | < .* ?> (?: .* ?< .* ?> ) ? | ` .* ?` | .) * ?) \s { 0 , } \$ / ,
19
14
) ,
20
- order : Priority . LOW ,
21
- parse : parseCaptureInline ,
22
- react ( node , _ , state ?) {
23
- try {
24
- const str = node . content . map ( ( item : any ) => item . content ) . join ( '' )
25
-
26
- return < LateX key = { state ?. key } > { str } </ LateX >
27
- } catch {
28
- return null as any
15
+ order : Priority . MED ,
16
+ parse ( capture ) {
17
+ return {
18
+ type : 'kateX' ,
19
+ katex : capture [ 1 ] ,
29
20
}
30
21
} ,
22
+ react ( node , output , state ) {
23
+ return < LateX key = { state ?. key } > { node . katex } </ LateX >
24
+ } ,
31
25
}
32
26
33
27
type LateXProps = {
@@ -52,7 +46,10 @@ const LateX: FC<LateXProps> = (props) => {
52
46
'https://cdn.jsdelivr.net/npm/[email protected] /dist/katex.min.js' ,
53
47
) . then ( ( ) => {
54
48
// @ts -ignore
55
- const html = window . katex . renderToString ( children , { displayMode, throwOnError } )
49
+ const html = window . katex . renderToString ( children , {
50
+ displayMode,
51
+ throwOnError,
52
+ } )
56
53
setHtml ( html )
57
54
} )
58
55
} , [ ] )
0 commit comments