Skip to content

Commit 859834b

Browse files
committed
feat: switch to reactmarkdown, remark gfm, rehype raw and rehype sanitize
1 parent 48abffb commit 859834b

File tree

14 files changed

+826
-242
lines changed

14 files changed

+826
-242
lines changed

web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"@solana/wallet-adapter-react": "^0.15.36",
101101
"@solana/web3.js": "^1.98.0",
102102
"@tanstack/react-query": "^5.69.0",
103-
"@types/dompurify": "^3.2.0",
104103
"@types/react-modal": "^3.16.3",
105104
"@wagmi/connectors": "^5.7.11",
106105
"@wagmi/core": "^2.16.7",
@@ -109,7 +108,6 @@
109108
"chartjs-adapter-moment": "^1.0.1",
110109
"chartjs-plugin-datalabels": "^2.2.0",
111110
"core-js": "^3.39.0",
112-
"dompurify": "^3.2.6",
113111
"ethers": "^5.8.0",
114112
"graphql": "^16.9.0",
115113
"graphql-request": "^7.1.2",
@@ -130,6 +128,9 @@
130128
"react-scripts": "^5.0.1",
131129
"react-toastify": "^9.1.3",
132130
"react-use": "^17.5.1",
131+
"rehype-raw": "^7.0.0",
132+
"rehype-sanitize": "^6.0.0",
133+
"remark-gfm": "^3.0.1",
133134
"styled-components": "^5.3.3",
134135
"subgraph-status": "^1.2.4",
135136
"viem": "^2.24.1",

web/src/components/DisputePreview/DisputeContext.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import React, { useMemo } from "react";
22
import styled from "styled-components";
33

4-
import { DisputeDetails } from "@kleros/kleros-sdk/src/dataMappings/utils/disputeDetailsTypes";
54
import { useAccount } from "wagmi";
65

6+
import { DisputeDetails } from "@kleros/kleros-sdk/src/dataMappings/utils/disputeDetailsTypes";
7+
78
import { INVALID_DISPUTE_DATA_ERROR, RPC_ERROR } from "consts/index";
89
import { Answer as IAnswer } from "context/NewDisputeContext";
910
import { isUndefined } from "utils/index";
1011

11-
import { responsiveSize } from "styles/responsiveSize";
12-
1312
import { DisputeDetailsQuery, VotingHistoryQuery } from "src/graphql/graphql";
1413

15-
import ReactMarkdown from "components/ReactMarkdown";
14+
import { responsiveSize } from "styles/responsiveSize";
15+
16+
import MarkdownRenderer from "components/MarkdownRenderer";
1617
import { StyledSkeleton } from "components/StyledSkeleton";
1718

19+
import CardLabel from "../DisputeView/CardLabels";
1820
import { Divider } from "../Divider";
1921
import { ExternalLink } from "../ExternalLink";
22+
import RulingAndRewardsIndicators from "../Verdict/RulingAndRewardsIndicators";
2023

2124
import AliasDisplay from "./Alias";
22-
import RulingAndRewardsIndicators from "../Verdict/RulingAndRewardsIndicators";
23-
import CardLabel from "../DisputeView/CardLabels";
2425

2526
const StyledH1 = styled.h1`
2627
margin: 0;
@@ -134,12 +135,12 @@ export const DisputeContext: React.FC<IDisputeContext> = ({
134135
<div>
135136
{disputeDetails?.question?.trim() ? (
136137
<ReactMarkdownWrapper dir="auto">
137-
<ReactMarkdown>{disputeDetails.question}</ReactMarkdown>
138+
<MarkdownRenderer content={disputeDetails.question} />
138139
</ReactMarkdownWrapper>
139140
) : null}
140141
{disputeDetails?.description?.trim() ? (
141142
<ReactMarkdownWrapper dir="auto">
142-
<ReactMarkdown>{disputeDetails.description}</ReactMarkdown>
143+
<MarkdownRenderer content={disputeDetails.description} />
143144
</ReactMarkdownWrapper>
144145
) : null}
145146
</div>

web/src/components/MarkdownEditor.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ import {
1313
linkPlugin,
1414
linkDialogPlugin,
1515
tablePlugin,
16+
codeBlockPlugin,
17+
codeMirrorPlugin,
1618
toolbarPlugin,
1719
UndoRedo,
1820
BoldItalicUnderlineToggles,
19-
CodeToggle,
2021
ListsToggle,
2122
CreateLink,
2223
InsertTable,
24+
InsertCodeBlock,
2325
BlockTypeSelect,
2426
Separator,
2527
} from "@mdxeditor/editor";
2628

2729
import InfoIcon from "svgs/icons/info-circle.svg";
2830

29-
import { sanitizeMarkdown } from "utils/markdownSanitization";
3031
import { isValidUrl } from "utils/urlValidation";
3132

3233
import { MDXEditorContainer, MDXEditorGlobalStyles } from "styles/mdxEditorTheme";
@@ -82,9 +83,13 @@ const MarkdownEditor: React.FC<IMarkdownEditor> = ({
8283
const editorRef = useRef<MDXEditorMethods>(null);
8384

8485
const handleChange = (markdown: string) => {
85-
const cleanedMarkdown = markdown === "\u200B" ? "" : markdown.replace(/^\u200B/, "");
86-
const sanitizedMarkdown = sanitizeMarkdown(cleanedMarkdown);
87-
onChange(sanitizedMarkdown);
86+
let cleanedMarkdown = markdown === "\u200B" ? "" : markdown.replace(/^\u200B/, "");
87+
// Remove ALL escape characters - no exceptions
88+
cleanedMarkdown = cleanedMarkdown.replace(/\\([`[]*_#|>-+=~^{}()!&<$%\\])/g, "$1");
89+
// Also handle multiple consecutive backslashes that might accumulate
90+
cleanedMarkdown = cleanedMarkdown.replace(/\\+/g, "");
91+
92+
onChange(cleanedMarkdown);
8893
};
8994

9095
const handleContainerClick = () => {
@@ -116,13 +121,19 @@ const MarkdownEditor: React.FC<IMarkdownEditor> = ({
116121
}),
117122
linkDialogPlugin(),
118123
tablePlugin(),
124+
codeBlockPlugin({ defaultCodeBlockLanguage: "text" }),
125+
codeMirrorPlugin({
126+
codeBlockLanguages: {
127+
text: "Code",
128+
},
129+
}),
119130
toolbarPlugin({
120131
toolbarContents: () => (
121132
<>
122133
<UndoRedo />
123134
<Separator />
124135
<BoldItalicUnderlineToggles />
125-
<CodeToggle />
136+
<InsertCodeBlock />
126137
<Separator />
127138
<BlockTypeSelect />
128139
<Separator />

0 commit comments

Comments
 (0)