Skip to content

Commit ed4e71b

Browse files
committed
emotion: Markdown
1 parent ad20b77 commit ed4e71b

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

site/src/components/Markdown/Markdown.tsx

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Link from "@mui/material/Link";
2-
import { makeStyles } from "@mui/styles";
32
import Table from "@mui/material/Table";
43
import TableBody from "@mui/material/TableBody";
54
import TableCell from "@mui/material/TableCell";
@@ -12,17 +11,24 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
1211
import gfm from "remark-gfm";
1312
import { colors } from "theme/colors";
1413
import { darcula } from "react-syntax-highlighter/dist/cjs/styles/prism";
15-
import { combineClasses } from "utils/combineClasses";
14+
import { type Interpolation, type Theme } from "@emotion/react";
1615

17-
export const Markdown: FC<{ children: string; className?: string }> = ({
18-
children,
19-
className,
20-
}) => {
21-
const styles = useStyles();
16+
interface MarkdownProps {
17+
/**
18+
* The Markdown text to parse and render
19+
*/
20+
children: string;
21+
22+
className?: string;
23+
}
24+
25+
export const Markdown: FC<MarkdownProps> = (props) => {
26+
const { children, className } = props;
2227

2328
return (
2429
<ReactMarkdown
25-
className={combineClasses([styles.markdown, className])}
30+
css={markdownStyles}
31+
className={className}
2632
remarkPlugins={[gfm]}
2733
components={{
2834
a: ({ href, target, children }) => (
@@ -58,7 +64,16 @@ export const Markdown: FC<{ children: string; className?: string }> = ({
5864
{String(children)}
5965
</SyntaxHighlighter>
6066
) : (
61-
<code className={styles.codeWithoutLanguage} {...props}>
67+
<code
68+
css={(theme) => ({
69+
padding: theme.spacing(0.125, 0.5),
70+
background: theme.palette.divider,
71+
borderRadius: 4,
72+
color: theme.palette.text.primary,
73+
fontSize: 14,
74+
})}
75+
{...props}
76+
>
6277
{children}
6378
</code>
6479
);
@@ -100,67 +115,57 @@ export const Markdown: FC<{ children: string; className?: string }> = ({
100115

101116
export const MemoizedMarkdown = memo(Markdown);
102117

103-
const useStyles = makeStyles((theme) => ({
104-
markdown: {
105-
fontSize: 16,
106-
lineHeight: "24px",
107-
108-
"& h1, & h2, & h3, & h4, & h5, & h6": {
109-
marginTop: theme.spacing(4),
110-
marginBottom: theme.spacing(2),
111-
lineHeight: "1.25",
112-
},
118+
const markdownStyles: Interpolation<Theme> = (theme: Theme) => ({
119+
fontSize: 16,
120+
lineHeight: "24px",
113121

114-
"& p": {
115-
marginTop: 0,
116-
marginBottom: theme.spacing(2),
117-
},
122+
"& h1, & h2, & h3, & h4, & h5, & h6": {
123+
marginTop: theme.spacing(4),
124+
marginBottom: theme.spacing(2),
125+
lineHeight: "1.25",
126+
},
118127

119-
"& p:only-child": {
120-
marginTop: 0,
121-
marginBottom: 0,
122-
},
128+
"& p": {
129+
marginTop: 0,
130+
marginBottom: theme.spacing(2),
131+
},
123132

124-
"& ul, & ol": {
125-
display: "flex",
126-
flexDirection: "column",
127-
gap: theme.spacing(1),
128-
marginBottom: theme.spacing(2),
129-
},
133+
"& p:only-child": {
134+
marginTop: 0,
135+
marginBottom: 0,
136+
},
130137

131-
"& li > ul, & li > ol": {
132-
marginTop: theme.spacing(2),
133-
},
138+
"& ul, & ol": {
139+
display: "flex",
140+
flexDirection: "column",
141+
gap: theme.spacing(1),
142+
marginBottom: theme.spacing(2),
143+
},
134144

135-
"& li > p": {
136-
marginBottom: 0,
137-
},
145+
"& li > ul, & li > ol": {
146+
marginTop: theme.spacing(2),
147+
},
138148

139-
"& .prismjs": {
140-
background: theme.palette.background.paperLight,
141-
borderRadius: theme.shape.borderRadius,
142-
padding: theme.spacing(2, 3),
143-
overflowX: "auto",
149+
"& li > p": {
150+
marginBottom: 0,
151+
},
144152

145-
"& code": {
146-
color: theme.palette.text.secondary,
147-
},
153+
"& .prismjs": {
154+
background: theme.palette.background.paperLight,
155+
borderRadius: theme.shape.borderRadius,
156+
padding: theme.spacing(2, 3),
157+
overflowX: "auto",
148158

149-
"& .key, & .property, & .inserted, .keyword": {
150-
color: colors.turquoise[7],
151-
},
159+
"& code": {
160+
color: theme.palette.text.secondary,
161+
},
152162

153-
"& .deleted": {
154-
color: theme.palette.error.light,
155-
},
163+
"& .key, & .property, & .inserted, .keyword": {
164+
color: colors.turquoise[7],
156165
},
157-
},
158166

159-
codeWithoutLanguage: {
160-
padding: theme.spacing(0.125, 0.5),
161-
background: theme.palette.divider,
162-
borderRadius: 4,
163-
color: theme.palette.text.primary,
164-
fontSize: 14,
167+
"& .deleted": {
168+
color: theme.palette.error.light,
169+
},
165170
},
166-
}));
171+
});

0 commit comments

Comments
 (0)