Skip to content

Commit

Permalink
fix Review
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 20, 2022
1 parent 3117d3f commit 1b1f097
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
21 changes: 8 additions & 13 deletions apps/meteor/client/components/CustomText.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import React, { FC, memo } from 'react';
import React, { memo, ReactElement } from 'react';

import { highlightWords as getHighlightHtml } from '../../app/highlight-words/client/helper';
import { getKatexHtml } from '../../app/katex/client';
import Katex from './Katex';

type CustomTextType = {
type CustomTextProps = {
text: string;
wordsToHighlight?: {
highlight: string;
regex: RegExp;
urlRegex: RegExp;
}[];
katex?: {
enabled: boolean;
dollarSyntaxEnabled: boolean;
parenthesisSyntaxEnabled: boolean;
};
};

const CustomText: FC<CustomTextType> = ({ text, wordsToHighlight, katex }) => {
let html = text;

if (wordsToHighlight?.length) {
html = getHighlightHtml(html, wordsToHighlight);
}

if (katex?.enabled) {
html = getKatexHtml(html, katex);
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} katex={katex} />;
}

return <span dangerouslySetInnerHTML={{ __html: html }} />;
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/client/components/Katex.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { FC, memo } from 'react';
import React, { memo, ReactElement } from 'react';

import { createKatexMessageRendering } from '../../app/katex/client';

type KatexType = {
type KatexProps = {
text: string;
options: {
dollarSyntax: boolean;
parenthesisSyntax: boolean;
};
};

const Katex: FC<KatexType> = ({ text, options }) => (
<span dangerouslySetInnerHTML={{ __html: createKatexMessageRendering(options)(`${text}`) }} />
const Katex = ({ text, options }: KatexProps): ReactElement => (
<span dangerouslySetInnerHTML={{ __html: createKatexMessageRendering(options)(text) }} />
);

export default memo(Katex);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export type MessageListContextValue = {
urlRegex: RegExp;
}[];
katex?: {
enabled: boolean;
dollarSyntaxEnabled: boolean;
parenthesisSyntaxEnabled: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ export const MessageListProvider: FC<{
showRoles,
showRealName,
showUsername,
katex: {
enabled: katexEnabled,
dollarSyntaxEnabled: katexDollarSyntaxEnabled,
parenthesisSyntaxEnabled: katexParenthesisSyntaxEnabled,
},
...(katexEnabled && {
katex: {
dollarSyntaxEnabled: katexDollarSyntaxEnabled,
parenthesisSyntaxEnabled: katexParenthesisSyntaxEnabled,
},
}),
highlights: highlights
?.map((str) => str.trim())
.map((highlight) => ({
Expand Down

0 comments on commit 1b1f097

Please sign in to comment.