Skip to content

Commit

Permalink
feat: impl simple MathJaxNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Dup4 committed Jun 4, 2022
1 parent a458a32 commit 8c7a4ef
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/mathjax-render-react/package.json
Expand Up @@ -38,5 +38,18 @@
"test": "vitest",
"lint:build": "tsc --noEmit",
"prepublishOnly": "npm run build"
},
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
},
"dependencies": {
"mathjax-render": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.0.11",
"@types/react-dom": "^18.0.5",
"react": "^18.1.0",
"react-dom": "^18.1.0"
}
}
29 changes: 29 additions & 0 deletions packages/mathjax-render-react/src/MathJaxNode.tsx
@@ -0,0 +1,29 @@
import React from "react";
import { Options, Tex2SVG } from "mathjax-render";

export interface MathJaxNodeProps extends Options {
tex: string;
display: boolean;
}

export const MathJaxNode: React.FC<MathJaxNodeProps> = (props) => {
const { tex, display, ...options } = props;

if (display) {
return (
<div
dangerouslySetInnerHTML={{
__html: Tex2SVG(tex, display, options).outerHTML,
}}
></div>
);
}

return (
<span
dangerouslySetInnerHTML={{
__html: Tex2SVG(tex, display, options).outerHTML,
}}
></span>
);
};
Empty file.
1 change: 1 addition & 0 deletions packages/mathjax-render-react/src/index.tsx
@@ -0,0 +1 @@
export * from "./MathJaxNode";
3 changes: 2 additions & 1 deletion packages/mathjax-render-react/tsconfig.json
Expand Up @@ -5,13 +5,14 @@
],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@/*": [
"src/*"
],
"mathjax-render": [
"../mathjax-render/src/index.ts"
"../mathjax-render/src/browser/index.ts"
]
}
}
Expand Down
71 changes: 71 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c7a4ef

Please sign in to comment.