-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useContext } from 'preact/hooks'; | ||
|
||
import { toLaTeX } from './latex'; | ||
import { getMathJax } from './mathjax'; | ||
import { MathsContext } from './maths-provider'; | ||
|
||
export { MathsContext, MathsProvider } from './maths-provider'; | ||
|
||
export type { FontName } from './mathjax'; | ||
|
||
type Props = { | ||
expr: string; | ||
}; | ||
|
||
export function MathJax({ expr }: Props) { | ||
const ctx = useContext(MathsContext); | ||
if (ctx.mathsAsTex) { | ||
return ( | ||
<code | ||
className="latex" | ||
dangerouslySetInnerHTML={{ | ||
__html: toLaTeX(expr), | ||
}} | ||
/> | ||
); | ||
} else { | ||
const children = getMathJax(expr, ctx.fontName); | ||
return <>{children}</>; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Prism from 'prismjs'; | ||
Check failure on line 1 in packages/processor/src/markdown-to-mdx/mdx-handlers/math/latex.ts
|
||
|
||
export function toLaTeX(expr: string) { | ||
const formatted = formatLaTeX(expr); | ||
return Prism.highlight(formatted, Prism.languages.latex, 'latex'); | ||
} | ||
|
||
function formatLaTeX(expr: string) { | ||
return expr | ||
.replace(/\\\\\s?/g, '\\\\\n') | ||
.replace(/\\begin{align(\*?)}/g, '\\begin{align$1}\n') | ||
.replace(/\\end{align(\*?)}/g, '\n\\end{align$1}'); | ||
} |