Skip to content

Commit dca3c4a

Browse files
TejasvCypherockTejasvOnly
andauthored
refactor: use markdown renderer to show terms (#428)
* refactor: use markdown render to show terms * style: improve ui and markdown syntax --------- Co-authored-by: Tejasv Sharma <tejasvonly@gmail.com>
1 parent c832848 commit dca3c4a

8 files changed

Lines changed: 412 additions & 1837 deletions

File tree

cysync/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
"eslint": "^8.8.0",
6666
"eslint-plugin-import": "^2.20.0",
6767
"fork-ts-checker-webpack-plugin": "^7.1.1",
68+
"html-loader": "^4.2.0",
6869
"lint-staged": "^12.3.4",
70+
"markdown-loader": "^8.0.0",
6971
"mock-aws-s3": "^4.0.2",
7072
"node-loader": "^2.0.0",
7173
"patch-package": "^6.5.1",
@@ -111,6 +113,7 @@
111113
"file-type": "^17.1.6",
112114
"github-url-to-object": "^4.0.6",
113115
"lodash": "^4.17.21",
116+
"markdown-to-jsx": "^7.2.1",
114117
"multicoin-address-validator": "^0.5.8",
115118
"nock": "^13.2.4",
116119
"node-cache": "^5.1.2",
@@ -148,4 +151,4 @@
148151
"prettier --write"
149152
]
150153
}
151-
}
154+
}

cysync/src/constants/markdown/terms.md

Lines changed: 206 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Box from '@mui/material/Box';
2+
import Link from '@mui/material/Link';
3+
import Typography from '@mui/material/Typography';
4+
import { shell } from 'electron';
5+
import ReactMarkdown from 'markdown-to-jsx';
6+
import * as React from 'react';
7+
8+
function MarkdownListItem(props: any) {
9+
return <Box component="li" sx={{ typography: 'body1' }} {...props} />;
10+
}
11+
12+
const openExternalLink = (event: React.SyntheticEvent, link: string) => {
13+
event.preventDefault();
14+
shell.openExternal(link);
15+
};
16+
17+
const ExternalLink: React.FC = ({ children }) => (
18+
<Link
19+
href="#"
20+
onClick={e => openExternalLink(e, children.toString())}
21+
color="secondary"
22+
underline="hover"
23+
>
24+
{children}
25+
</Link>
26+
);
27+
28+
const options = {
29+
overrides: {
30+
h1: {
31+
component: Typography,
32+
props: {
33+
color: 'textPrimary',
34+
variant: 'h3',
35+
gutterBottom: true,
36+
style: { fontWeight: 700, marginTop: '1.5rem' }
37+
}
38+
},
39+
h2: {
40+
component: Typography,
41+
props: {
42+
color: 'textPrimary',
43+
variant: 'h5',
44+
gutterBottom: true,
45+
style: { fontWeight: 600, marginTop: '1rem' }
46+
}
47+
},
48+
p: {
49+
component: Typography,
50+
props: {
51+
color: 'textPrimary',
52+
paragraph: true
53+
}
54+
},
55+
a: {
56+
component: ExternalLink
57+
},
58+
li: {
59+
component: MarkdownListItem
60+
}
61+
}
62+
};
63+
64+
export default function Markdown(props: any) {
65+
return <ReactMarkdown options={options} {...props} />;
66+
}

cysync/src/globals.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
declare module '*.md' {
2+
const content: string;
3+
export default content;
4+
}
15
declare module '*.png' {
26
const value: any;
37
export default value;

0 commit comments

Comments
 (0)