Skip to content

Commit

Permalink
convert Latex to function component to work without 'use client'
Browse files Browse the repository at this point in the history
  • Loading branch information
harunurhan committed Mar 9, 2024
1 parent 0ac4d8c commit 782adb0
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Latex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ export interface LatexProps {
macros?: Macros
}

export default class Latex extends React.Component<LatexProps> {
static defaultProps: Partial<LatexProps> = {
delimiters: [
{ left: '$$', right: '$$', display: true },
{ left: '\\(', right: '\\)', display: false },
{ left: '$', right: '$', display: false },
{ left: '\\[', right: '\\]', display: true },
],
strict: false
};
const defaultDelimiters = [
{ left: '$$', right: '$$', display: true },
{ left: '\\(', right: '\\)', display: false },
{ left: '$', right: '$', display: false },
{ left: '\\[', right: '\\]', display: true },
]

render() {
const { children, delimiters, strict, macros } = this.props
const renderedLatex = renderLatex(Array.isArray(children) ? children.join('') : children, delimiters!, strict!, macros);
return (
<span className="__Latex__" dangerouslySetInnerHTML={{ __html: renderedLatex }} />
)
}
}
export default function Latex({children, delimiters = defaultDelimiters, strict = false, macros }: LatexProps): React.ReactNode {
const renderedLatex = renderLatex(Array.isArray(children) ? children.join('') : children, delimiters!, strict!, macros);
return (
<span className="__Latex__" dangerouslySetInnerHTML={{ __html: renderedLatex }} />
)
}

0 comments on commit 782adb0

Please sign in to comment.