-
-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <[email protected]>
- Loading branch information
Showing
6 changed files
with
65 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import katex from 'katex' | ||
import type { FC } from 'react' | ||
import { useMemo } from 'react' | ||
|
||
type KateXProps = { | ||
children: string | ||
mode?: string // If `display` the math will be rendered in display mode. Otherwise the math will be rendered in inline mode. | ||
} | ||
|
||
export const KateX: FC<KateXProps> = (props) => { | ||
const { children, mode } = props | ||
|
||
const displayMode = mode === 'display' | ||
|
||
const throwOnError = false // render unsupported commands as text instead of throwing a `ParseError` | ||
|
||
return ( | ||
<span | ||
dangerouslySetInnerHTML={useMemo( | ||
() => ({ | ||
__html: katex.renderToString(children, { | ||
displayMode, | ||
throwOnError, | ||
}), | ||
}), | ||
[children, displayMode, throwOnError], | ||
)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters