-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Add katex render to new message react template (#25239)
* feat: add katex render to message react * fix: add boolean to type * fix Review * fix: review Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com> Co-authored-by: dougfabris <devfabris@gmail.com>
- Loading branch information
1 parent
35e2ba8
commit 1d94d60
Showing
7 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { memo, ReactElement } from 'react'; | ||
|
||
import { highlightWords as getHighlightHtml } from '../../app/highlight-words/client/helper'; | ||
import Katex from './Katex'; | ||
|
||
type CustomTextProps = { | ||
text: string; | ||
wordsToHighlight?: { | ||
highlight: string; | ||
regex: RegExp; | ||
urlRegex: RegExp; | ||
}[]; | ||
katex?: { | ||
dollarSyntaxEnabled: boolean; | ||
parenthesisSyntaxEnabled: boolean; | ||
}; | ||
}; | ||
|
||
const CustomText = ({ text, wordsToHighlight, katex }: CustomTextProps): ReactElement => { | ||
// TODO: chapter day frontend: remove dangerouslySetInnerHTML, convert to tokens and do not mix with katex | ||
const html = wordsToHighlight?.length ? getHighlightHtml(text, wordsToHighlight) : text; | ||
if (katex) { | ||
return <Katex text={html} options={{ dollarSyntax: katex.dollarSyntaxEnabled, parenthesisSyntax: katex.parenthesisSyntaxEnabled }} />; | ||
} | ||
|
||
return <span dangerouslySetInnerHTML={{ __html: html }} />; | ||
}; | ||
|
||
export default memo(CustomText); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { memo, ReactElement } from 'react'; | ||
|
||
import { createKatexMessageRendering } from '../../app/katex/client'; | ||
|
||
type KatexProps = { | ||
text: string; | ||
options: { | ||
dollarSyntax: boolean; | ||
parenthesisSyntax: boolean; | ||
}; | ||
}; | ||
|
||
const Katex = ({ text, options }: KatexProps): ReactElement => ( | ||
<span dangerouslySetInnerHTML={{ __html: createKatexMessageRendering(options)(text) }} /> | ||
); | ||
|
||
export default memo(Katex); |
9 changes: 5 additions & 4 deletions
9
apps/meteor/client/components/Message/MessageBodyRender/PlainText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters