1
1
import '@uiw/react-markdown-preview/markdown.css'
2
2
import ReactMarkdown from 'react-markdown'
3
- import { SpecialComponents } from 'react-markdown/lib/ast-to-react'
4
- import { NormalComponents } from 'react-markdown/lib/complex-types'
5
3
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
6
4
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'
7
5
import rehypeRaw from 'rehype-raw'
8
- import remarkGfm from 'remark-gfm'
9
6
10
7
import '@uiw/react-markdown-preview/markdown.css'
11
8
import '@uiw/react-md-editor/markdown-editor.css'
9
+ import remarkGfm from 'remark-gfm'
12
10
13
11
interface Params {
14
12
markdown ?: string
15
13
}
16
14
17
- type MarkDownComponents = Partial < Omit < NormalComponents , keyof SpecialComponents > & SpecialComponents >
18
-
19
- const markdownComponents : MarkDownComponents = {
20
- h1 : ( { node, ...props } ) => (
15
+ const markdownComponents = {
16
+ h1 : ( { node, ...props } : any ) => (
21
17
< h1 className = "text-primary dark:text-light font-bold text-2xl py-6" { ...props } >
22
18
{ props . children }
23
19
</ h1 >
24
20
) ,
25
- h2 : ( { node, ...props } ) => (
21
+ h2 : ( { node, ...props } : any ) => (
26
22
< h2 className = "text-primary dark:text-light font-bold text-xl py-6" { ...props } >
27
23
{ props . children }
28
24
</ h2 >
29
25
) ,
30
- h3 : ( { node, ...props } ) => < h3 className = "text-primary dark:text-light font-bold text-lg py-6" { ...props } /> ,
31
- h4 : ( { node, ...props } ) => < h4 className = "text-primary dark:text-light font-bold text-md" { ...props } /> ,
32
- h5 : ( { node, ...props } ) => < h5 className = "text-primary dark:text-light font-bold text-md" { ...props } /> ,
33
- h6 : ( { node, ...props } ) => < h5 className = "text-primary/60 font-bold text-md" { ...props } /> ,
34
- p : ( { node, ...props } ) => (
26
+ h3 : ( { node, ...props } : any ) => < h3 className = "text-primary dark:text-light font-bold text-lg py-6" { ...props } /> ,
27
+ h4 : ( { node, ...props } : any ) => < h4 className = "text-primary dark:text-light font-bold text-md" { ...props } /> ,
28
+ h5 : ( { node, ...props } : any ) => < h5 className = "text-primary dark:text-light font-bold text-md" { ...props } /> ,
29
+ h6 : ( { node, ...props } : any ) => < h5 className = "text-primary/60 font-bold text-md" { ...props } /> ,
30
+ p : ( { node, ...props } : any ) => (
35
31
< p className = "text-dark dark:text-light text-md leading-[1.7rem] whitespace-pre-line py-2" { ...props } />
36
32
) ,
37
- ul : ( { node, ...props } ) => {
33
+ ul : ( { node, ...props } : any ) => {
38
34
const { ordered : _ , ...rest } = props
39
35
return < ul className = "list-disc text-md leading-6 ps-4 md:ps-8" { ...rest } />
40
36
} ,
41
- ol : ( { node, ...props } ) => < ol className = "list-decimal ps-4 text-md leading-8" { ...props } /> ,
42
- li : ( { node, ...props } ) => {
37
+ ol : ( { node, ...props } : any ) => < ol className = "list-decimal ps-4 text-md leading-8" { ...props } /> ,
38
+ li : ( { node, ...props } : any ) => {
43
39
const { ordered : _ , ...rest } = props
44
40
return (
45
41
< li
@@ -53,11 +49,11 @@ const markdownComponents: MarkDownComponents = {
53
49
</ li >
54
50
)
55
51
} ,
56
- hr : ( { node, ...props } ) => < hr className = "my-6 border-primary/60" { ...props } /> ,
57
- a : ( { node, ...props } ) => (
52
+ hr : ( { node, ...props } : any ) => < hr className = "my-6 border-primary/60" { ...props } /> ,
53
+ a : ( { node, ...props } : any ) => (
58
54
< a target = "_blank" className = "text-primary dark:text-secondary underline underline-offset-1" { ...props } />
59
55
) ,
60
- input : ( { node, ...props } ) => {
56
+ input : ( { node, ...props } : any ) => {
61
57
if ( props . type === 'checkbox' ) {
62
58
const { checked : _ , ...rest } = props
63
59
return (
@@ -72,15 +68,15 @@ const markdownComponents: MarkDownComponents = {
72
68
return < input { ...props } />
73
69
}
74
70
} ,
75
- blockquote : ( { node, ...props } ) => (
71
+ blockquote : ( { node, ...props } : any ) => (
76
72
< blockquote
77
73
className = "bg-primary/10 text-primary ps-4 py-1 border-l-[0.2rem] border-primary border-solid [&>p]:leading-8"
78
74
{ ...props }
79
75
>
80
76
{ props . children }
81
77
</ blockquote >
82
78
) ,
83
- code : ( { node, inline, className, children, ...props } ) => {
79
+ code : ( { node, inline, className, children, ...props } : any ) => {
84
80
const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
85
81
const codeBlock = String ( children ) . replace ( / \n $ / , ' ' )
86
82
return ! inline ? (
@@ -103,32 +99,32 @@ const markdownComponents: MarkDownComponents = {
103
99
</ code >
104
100
)
105
101
} ,
106
- table : ( { node, className, children, ...props } ) => (
102
+ table : ( { node, className, children, ...props } : any ) => (
107
103
< div className = "w-full overflow-auto ring-1 ring-inset dark:ring-light/10" >
108
104
< table className = "w-full text-dark dark:text-light ring-inset rounded-md" { ...props } >
109
105
{ children }
110
106
</ table >
111
107
</ div >
112
108
) ,
113
- thead : ( { node, className, children, ...props } ) => (
109
+ thead : ( { node, className, children, ...props } : any ) => (
114
110
< thead className = "w-full border-b-1 border-solid border-light/10" { ...props } >
115
111
{ children }
116
112
</ thead >
117
113
) ,
118
- tr : ( { node, className, children, isHeader, ...props } ) => (
114
+ tr : ( { node, className, children, isHeader, ...props } : any ) => (
119
115
< tr
120
116
className = "w-fit [&>*]:text-md [&>*]:border [&>*]:border-solid [&>*]:border-light [&>*]:border-collapse [&>th]:whitespace-pre-line [&>th]:p-2 [&>td]:whitespace-pre-line [&>td]:p-2"
121
117
{ ...props }
122
118
>
123
119
{ children }
124
120
</ tr >
125
121
) ,
126
- tbody : ( { node, className, children, ...props } ) => (
122
+ tbody : ( { node, className, children, ...props } : any ) => (
127
123
< tbody className = "w-full [&>*]:border [&>*]:border-solid [&>*]:border-light [&>*]:border-collapse" { ...props } >
128
124
{ children }
129
125
</ tbody >
130
126
) ,
131
- img : ( { node, className, children, ...props } ) => (
127
+ img : ( { node, className, children, ...props } : any ) => (
132
128
// eslint-disable-next-line @next/next/no-img-element
133
129
< img { ...props } alt = "" className = "w-full overflow-hidden rounded-md ring-1 ring-primary/60 shadow-md my-4" />
134
130
)
@@ -141,7 +137,7 @@ export const MarkdowRenderer = ({ markdown }: Params) => {
141
137
fontSize : '1rem'
142
138
} }
143
139
>
144
- < ReactMarkdown remarkPlugins = { [ remarkGfm ] } rehypePlugins = { [ rehypeRaw ] } components = { markdownComponents } >
140
+ < ReactMarkdown remarkPlugins = { [ remarkGfm ] } rehypePlugins = { [ rehypeRaw ] } components = { markdownComponents as any } >
145
141
{ markdown ?? '' }
146
142
</ ReactMarkdown >
147
143
</ div >
0 commit comments