Skip to content

Commit 9b95d4c

Browse files
committed
fix(#2263): remove markdown from slider card
1 parent 97c3aaa commit 9b95d4c

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ changes.
1717
### Fixed
1818

1919
- Fix listing voted-on governance actions [Issue 2379](https://github.com/IntersectMBO/govtool/issues/2379)
20+
- Fix wronly displayed markdown on slider card [Issue 2263](https://github.com/IntersectMBO/govtool/issues/2316)
2021

2122
### Changed
2223

govtool/frontend/src/components/molecules/GovernanceActionCardElement.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
33
import Markdown from "react-markdown";
44

55
import { Typography, Tooltip, CopyButton, TooltipProps } from "@atoms";
6+
import { removeMarkdown } from "@/utils";
67

78
type BaseProps = {
89
label: string;
@@ -115,7 +116,7 @@ export const GovernanceActionCardElement = ({
115116
fontFamily: "Poppins, Arial",
116117
}}
117118
>
118-
{isMarkdown ? (
119+
{!isSliderCard && isMarkdown ? (
119120
<Markdown
120121
components={{
121122
// eslint-disable-next-line
@@ -162,7 +163,7 @@ export const GovernanceActionCardElement = ({
162163
}),
163164
}}
164165
>
165-
{text}
166+
{isMarkdown ? removeMarkdown(text) : text}
166167
</Typography>
167168
)}
168169
{isCopyButton && (

govtool/frontend/src/utils/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from "./callAll";
66
export * from "./canonizeJSON";
77
export * from "./checkIsMaintenanceOn";
88
export * from "./checkIsWalletConnected";
9+
export * from "./cip129identifier";
910
export * from "./dRep";
1011
export * from "./ellipsizeText";
1112
export * from "./filterOutNullParams";
@@ -16,6 +17,7 @@ export * from "./generateJsonld";
1617
export * from "./generateMetadataBody";
1718
export * from "./getDRepID";
1819
export * from "./getGovActionId";
20+
export * from "./getGovActionVotingThresholdKey";
1921
export * from "./getLengthInBytes";
2022
export * from "./getMetadataDataMissingStatusTranslation";
2123
export * from "./getProposalTypeLabel";
@@ -28,8 +30,7 @@ export * from "./mapDtoToProposal";
2830
export * from "./numberValidation";
2931
export * from "./openInNewTab";
3032
export * from "./removeDuplicatedProposals";
33+
export * from "./removeMarkdown";
3134
export * from "./setProtocolParameterUpdate";
3235
export * from "./testIdFromLabel";
3336
export * from "./wait";
34-
export * from "./cip129identifier";
35-
export * from "./getGovActionVotingThresholdKey";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const removeMarkdown = (markdown?: string | number) => {
2+
if (!markdown) return "";
3+
4+
return String(markdown)
5+
.replace(/(\*\*|__)(.*?)\1/g, "$2")
6+
.replace(/(\*|_)(.*?)\1/g, "$2")
7+
.replace(/~~(.*?)~~/g, "$1")
8+
.replace(/!\[.*?\]\(.*?\)/g, "")
9+
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
10+
.replace(/`{1,2}([^`]+)`{1,2}/g, "$1")
11+
.replace(/^\s{0,3}>\s?/g, "")
12+
.replace(/^\s{1,3}([-*+]|\d+\.)\s+/g, "")
13+
.replace(
14+
/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm,
15+
"$1$3$4$6",
16+
)
17+
.replace(/\n{2,}/g, "\n")
18+
.replace(/([\\`*{}[\]()#+\-.!_>])/g, "$1");
19+
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { removeMarkdown } from "../removeMarkdown";
2+
3+
describe("removeMarkdown", () => {
4+
it("should remove bold markdown", () => {
5+
const markdown = "**Hello** World";
6+
const expected = "Hello World";
7+
const result = removeMarkdown(markdown);
8+
expect(result).toEqual(expected);
9+
});
10+
11+
it("should remove italic markdown", () => {
12+
const markdown = "*Hello* World";
13+
const expected = "Hello World";
14+
const result = removeMarkdown(markdown);
15+
expect(result).toEqual(expected);
16+
});
17+
18+
it("should remove strikethrough markdown", () => {
19+
const markdown = "~~Hello~~ World";
20+
const expected = "Hello World";
21+
const result = removeMarkdown(markdown);
22+
expect(result).toEqual(expected);
23+
});
24+
25+
it("should remove image markdown", () => {
26+
const markdown = "![Alt Text](image.jpg)";
27+
const expected = "";
28+
const result = removeMarkdown(markdown);
29+
expect(result).toEqual(expected);
30+
});
31+
32+
it("should remove link markdown", () => {
33+
const markdown = "[Link Text](https://example.com)";
34+
const expected = "Link Text";
35+
const result = removeMarkdown(markdown);
36+
expect(result).toEqual(expected);
37+
});
38+
39+
it("should remove inline code markdown", () => {
40+
const markdown = "`code`";
41+
const expected = "code";
42+
const result = removeMarkdown(markdown);
43+
expect(result).toEqual(expected);
44+
});
45+
46+
it("should remove blockquote markdown", () => {
47+
const markdown = "> Blockquote";
48+
const expected = "Blockquote";
49+
const result = removeMarkdown(markdown);
50+
expect(result).toEqual(expected);
51+
});
52+
53+
it("should remove heading markdown", () => {
54+
const markdown = "# Heading";
55+
const expected = "Heading";
56+
const result = removeMarkdown(markdown);
57+
expect(result).toEqual(expected);
58+
});
59+
60+
it("should remove multiple newlines", () => {
61+
const markdown = "Hello\n\n\nWorld";
62+
const expected = "Hello\nWorld";
63+
const result = removeMarkdown(markdown);
64+
expect(result).toEqual(expected);
65+
});
66+
});

0 commit comments

Comments
 (0)