-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathmarkdown.tsx
81 lines (72 loc) · 1.67 KB
/
markdown.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { css } from "styled-components";
import { lazy } from "react";
// import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
import remarkGfm from "remark-gfm";
import type { Options as ReactMarkdownOptions } from "react-markdown/lib";
const ReactMarkdown = lazy(() => import('react-markdown'));
export const markdownCompCss = css`
.markdown-body {
background-color: unset;
font-size: 13px;
margin: 3px 0;
h1,
h2 {
border: none;
padding-bottom: 0;
}
p {
line-height: 1.9;
}
h3 {
padding: 2px 0;
}
h4 {
padding: 4px 0;
}
}
`;
interface TacoMarkDownProps extends ReactMarkdownOptions {
children: string;
}
const components = {
a: (props: any) => {
const { node, children, ...otherProps } = props;
return (
<a {...otherProps} target="_blank">
{children}
</a>
);
},
};
export const TacoMarkDown = (props: TacoMarkDownProps) => {
const { children, ...otherProps } = props;
return (
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={components}
rehypePlugins={[
[rehypeRaw],
[
rehypeSanitize,
{
...defaultSchema,
attributes: {
...defaultSchema.attributes,
"*": [
...((defaultSchema.attributes && defaultSchema.attributes["*"]) || []),
"style",
"className",
],
},
},
],
]}
className="markdown-body"
{...otherProps}
>
{children}
</ReactMarkdown>
);
};