Skip to content

Commit

Permalink
Merge pull request #112 from ammar-ahmed22/development
Browse files Browse the repository at this point in the history
Inline Latex
  • Loading branch information
ammar-ahmed22 authored May 31, 2023
2 parents a80ca46 + ba66965 commit 3d94f72
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@ammarahmedca/types": "^0.0.12",
"@ammarahmedca/types": "^0.0.13",
"@apollo/client": "^3.5.8",
"@chakra-ui/icons": "^1.1.1",
"@chakra-ui/react": "^2.3.6",
Expand Down
15 changes: 14 additions & 1 deletion src/components/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LinkProps,
useColorModeValue,
} from "@chakra-ui/react";
import MathJax from "react-mathjax";

type RichTextProps = TextProps & {
data: IRichText[];
Expand Down Expand Up @@ -49,8 +50,9 @@ const RichText: React.FC<RichTextProps> = ({ data, ...rest }) => {

return (
<Text {...rest}>
<MathJax.Provider>
{data.map((richText, idx) => {
const { annotations, plainText, href } = richText;
const { annotations, plainText, href, inlineLatex } = richText;
const { code } = annotations;
const key: string = `rich-text-${idx}`;
if (href) {
Expand All @@ -64,6 +66,16 @@ const RichText: React.FC<RichTextProps> = ({ data, ...rest }) => {
{plainText}
</Link>
);
} else if (inlineLatex) {
return (
<Text
key={key}
as="span"
{...createProps<TextProps>(annotations)}
>
<MathJax.Node inline formula={plainText} />
</Text>
)
} else {
return (
<Text
Expand All @@ -76,6 +88,7 @@ const RichText: React.FC<RichTextProps> = ({ data, ...rest }) => {
);
}
})}
</MathJax.Provider>
</Text>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/graphql/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const RICH_TEXT_FRAGMENTS = gql`
annotations {
...all
}
inlineLatex
}
fragment all on Annotations {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@adobe/css-tools/-/css-tools-4.0.1.tgz#b38b444ad3aa5fedbb15f2f746dcd934226a12dd"
integrity sha512-+u76oB43nOHrF4DDWRLWDCtci7f3QJoEBigemIdIeTi1ODqjx6Tad9NCVnPRwewWlKkVab5PlK8DCtPTyX7S8g==

"@ammarahmedca/types@^0.0.12":
version "0.0.12"
resolved "https://registry.yarnpkg.com/@ammarahmedca/types/-/types-0.0.12.tgz#08817ba4b7e38dde59ed1df11a4a8d29de0d9d1d"
integrity sha512-rOD+TS0iezM3UkHajSMpXxRM27vBbsBJkRJa2dc0ZmCy3znURWY3kK7dpP7ZSCKClr61kSPLDDD2UentAqWHKQ==
"@ammarahmedca/types@^0.0.13":
version "0.0.13"
resolved "https://registry.yarnpkg.com/@ammarahmedca/types/-/types-0.0.13.tgz#2bd407a420a7e880729ed093b554a834c505cfd1"
integrity sha512-LvtKRfw/K7c86uYuv5Q9/KDlMYsd1ec8IRbZPTwnM3Io4Q+JvAIcfGx/e7O8MG13vkzYUB+ij1dhHVlELRNlwA==
dependencies:
"@notionhq/client" "^2.2.3"
asynckit "^0.4.0"
Expand Down

0 comments on commit 3d94f72

Please sign in to comment.