Skip to content

Commit

Permalink
support \(...\) and \[...\] style math formula
Browse files Browse the repository at this point in the history
  • Loading branch information
MrrDrr committed Mar 2, 2024
1 parent 99fb9dc commit 524c9be
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/components/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,27 @@ function escapeDollarNumber(text: string) {
return escapedText;
}

function escapeBrackets(text: string) {
const pattern =
/(```[\s\S]*?```|`.*?`)|\\\[([\s\S]*?[^\\])\\\]|\\\((.*?)\\\)/g;
return text.replace(
pattern,
(match, codeBlock, squareBracket, roundBracket) => {
if (codeBlock) {
return codeBlock;
} else if (squareBracket) {
return `$$${squareBracket}$$`;
} else if (roundBracket) {
return `$${roundBracket}$`;
}
return match;
},
);
}

function _MarkDownContent(props: { content: string }) {
const escapedContent = useMemo(
() => escapeDollarNumber(props.content),
() => escapeBrackets(escapeDollarNumber(props.content)),
[props.content],
);

Expand Down

0 comments on commit 524c9be

Please sign in to comment.