diff --git a/app/containers/markdown/components/Katex.tsx b/app/containers/markdown/components/Katex.tsx index c0aac0860a7..18ec99cc056 100644 --- a/app/containers/markdown/components/Katex.tsx +++ b/app/containers/markdown/components/Katex.tsx @@ -13,15 +13,34 @@ interface IKaTeXProps { value: KaTeXProps['value']; } +const BLOCK_ENV_PATTERN = /\\begin\s*\{\s*(array|matrix|pmatrix|bmatrix|Bmatrix|vmatrix|Vmatrix)\s*\}/; + export const KaTeX = ({ value }: IKaTeXProps): React.ReactElement | null => { const { colors } = useTheme(); const fixAndroidWebviewCrashStyle: StyleProp = isAndroid ? { opacity: 0.99, overflow: 'hidden' } : {}; + // KaTeX array does not render correctly in MathView (shows gray box). + // MathView does not throw, so renderError is never triggered. + if (BLOCK_ENV_PATTERN.test(value)) { + return ( + + ); + } + return ( ( - + )} /> ); diff --git a/app/containers/message/Message.stories.tsx b/app/containers/message/Message.stories.tsx index 1f15cea13c4..c4db7254ec3 100644 --- a/app/containers/message/Message.stories.tsx +++ b/app/containers/message/Message.stories.tsx @@ -2238,6 +2238,25 @@ export const Katex = () => ( ); export const KatexLargeFont = () => ; +const katexArray = { + msg: '\\begin{array}{|c|c|c|c|c|c|} \\hline \\text{...} & \\text{...} \\\\ \\hline \\end{array}', + md: [ + { + type: 'KATEX', + value: + ' \\begin{array}{|c|c|c|c|c|c|} \\hline \\text{testing} & \\text{testingII} & \\text{testing III} & \\text{testing IV} & \\text{testV} & \\text{testVI} \\\\ \\hline \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} & \\text{TEST} \\\\ \\hline\\text{TEST} & \\text{✅} & \\text{test} & \\text{test} & \\text{test} & \\text{✅} \\\\ \\hline \\end{array} ' + } + ] +}; + +export const KatexArray = () => ( + <> + + +); + +export const KatexArrayLargeFont = () => ; + const inlineKatex = { msg: '\\(xˆ2 + yˆ2 - zˆ2\\)', md: [ diff --git a/app/containers/message/__snapshots__/Message.test.tsx.snap b/app/containers/message/__snapshots__/Message.test.tsx.snap index 5441ced7633..71d0b3c66d2 100644 --- a/app/containers/message/__snapshots__/Message.test.tsx.snap +++ b/app/containers/message/__snapshots__/Message.test.tsx.snap @@ -49554,15 +49554,7 @@ exports[`Story Snapshots: Katex should match snapshot 1`] = ` } } > - + @@ -49578,7 +49570,7 @@ exports[`Story Snapshots: Katex should match snapshot 1`] = ` `; -exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` +exports[`Story Snapshots: KatexArray should match snapshot 1`] = ` @@ -49674,8 +49666,8 @@ exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` [ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, }, { "marginTop": 4, @@ -49729,7 +49721,7 @@ exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` "top": "50%", } } - height={46.800000000000004} + height={36} nativeViewRef={"[React.ref]"} onError={[Function]} onLoad={[Function]} @@ -49743,19 +49735,19 @@ exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` "headers": { "User-Agent": "RC Mobile; ios unknown; vunknown (unknown)", }, - "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=93.60000000000001", + "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=72", }, ] } style={ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, } } transition={null} - width={46.800000000000004} + width={36} /> @@ -49846,6 +49838,25 @@ exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` > diego.mello + + 10:00 AM + - - 10:00 AM - - + @@ -49915,7 +49899,7 @@ exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` `; -exports[`Story Snapshots: Lists should match snapshot 1`] = ` +exports[`Story Snapshots: KatexArrayLargeFont should match snapshot 1`] = ` @@ -50015,8 +49995,8 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` [ { "borderRadius": 4, - "height": 36, - "width": 36, + "height": 46.800000000000004, + "width": 46.800000000000004, }, { "marginTop": 4, @@ -50070,7 +50050,7 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` "top": "50%", } } - height={36} + height={46.800000000000004} nativeViewRef={"[React.ref]"} onError={[Function]} onLoad={[Function]} @@ -50084,19 +50064,19 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` "headers": { "User-Agent": "RC Mobile; ios unknown; vunknown (unknown)", }, - "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=72", + "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=93.60000000000001", }, ] } style={ { "borderRadius": 4, - "height": 36, - "width": 36, + "height": 46.800000000000004, + "width": 46.800000000000004, } } transition={null} - width={36} + width={46.800000000000004} /> @@ -50187,25 +50167,6 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` > diego.mello - - 10:00 AM - + + 10:00 AM + - - - - • - - - - - Dogs - - - - - - - • - - - - - cats - - - - - - - - - • - - - - - cats - - - - - + @@ -50468,6 +50224,19 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` + + +`; + +exports[`Story Snapshots: KatexLargeFont should match snapshot 1`] = ` + + @@ -50513,8 +50282,7 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` } > @@ -50557,8 +50324,8 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` [ { "borderRadius": 4, - "height": 36, - "width": 36, + "height": 46.800000000000004, + "width": 46.800000000000004, }, { "marginTop": 4, @@ -50612,7 +50379,7 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` "top": "50%", } } - height={36} + height={46.800000000000004} nativeViewRef={"[React.ref]"} onError={[Function]} onLoad={[Function]} @@ -50626,19 +50393,19 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` "headers": { "User-Agent": "RC Mobile; ios unknown; vunknown (unknown)", }, - "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=72", + "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=93.60000000000001", }, ] } style={ { "borderRadius": 4, - "height": 36, - "width": 36, + "height": 46.800000000000004, + "width": 46.800000000000004, } } transition={null} - width={36} + width={46.800000000000004} /> @@ -50729,25 +50496,6 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` > diego.mello - - 10:00 AM - + + 10:00 AM + - - - - 1 - . - - - - - Dogs - - - - - - - 2 - . - - - - - Cats - - - - - + @@ -50962,6 +50553,19 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` + + +`; + +exports[`Story Snapshots: Lists should match snapshot 1`] = ` + + @@ -51007,7 +50611,9 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` } > - 1 - . + • - - - - - - - - - - - - - - - - - - - - - - - - - + • + + - 2 - . + + + cats + + + + + + + • + + - Cats + cats @@ -51574,40 +51104,20 @@ exports[`Story Snapshots: Lists should match snapshot 1`] = ` - - - -`; - -exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` - - @@ -51691,8 +51199,8 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` [ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, }, { "marginTop": 4, @@ -51746,7 +51254,7 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` "top": "50%", } } - height={46.800000000000004} + height={36} nativeViewRef={"[React.ref]"} onError={[Function]} onLoad={[Function]} @@ -51760,19 +51268,19 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` "headers": { "User-Agent": "RC Mobile; ios unknown; vunknown (unknown)", }, - "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=93.60000000000001", + "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=72", }, ] } style={ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, } } transition={null} - width={46.800000000000004} + width={36} /> @@ -51863,6 +51371,25 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` > diego.mello + + 10:00 AM + - - 10:00 AM - - • - - - - - Dogs - - + 1 + . - - - • - - - cats + Dogs - - - • + 2 + . - cats + Cats @@ -52145,13 +51605,13 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` @@ -52233,8 +51691,8 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` [ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, }, { "marginTop": 4, @@ -52288,7 +51746,7 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` "top": "50%", } } - height={46.800000000000004} + height={36} nativeViewRef={"[React.ref]"} onError={[Function]} onLoad={[Function]} @@ -52302,19 +51760,19 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` "headers": { "User-Agent": "RC Mobile; ios unknown; vunknown (unknown)", }, - "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=93.60000000000001", + "uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=72", }, ] } style={ { "borderRadius": 4, - "height": 46.800000000000004, - "width": 46.800000000000004, + "height": 36, + "width": 36, } } transition={null} - width={46.800000000000004} + width={36} /> @@ -52405,6 +51863,25 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` > diego.mello + + 10:00 AM + - - 10:00 AM - - Dogs + Dogs + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`; + +exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` + + @@ -52683,7 +52287,9 @@ exports[`Story Snapshots: ListsLargeFont should match snapshot 1`] = ` } > + • + + - 1 - . + + + Dogs + + + + + + + • + + + + + cats + + + + + + + + + • + + + + + cats + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diego.mello + + + + + + 10:00 AM + + + + + + + + 1 + . + + + + + Dogs + + + + + + + 2 + . + + + + + Cats + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diego.mello + + + + + + 10:00 AM + + + + + + + + 1 + . - - - - - - - - - - - - - - diego.mello - - - 10:00 AM - - - - - - - - - - - - - - - -`; - -exports[`Story Snapshots: MessageWithReadReceipt should match snapshot 1`] = ` - - - - - - - + + + + + + + + + + + + + + diego.mello + + + 10:00 AM + + + + + + + + + + + + + + + +`; + +exports[`Story Snapshots: MessageWithReadReceipt should match snapshot 1`] = ` + + + + + + +