1
- import { FC , ReactElement , useState } from ' react' ;
2
- import ReactMarkdown from ' react-markdown' ;
3
- import copy from ' copy-to-clipboard' ;
1
+ import { FC , ReactElement , useState } from " react" ;
2
+ import ReactMarkdown from " react-markdown" ;
3
+ import copy from " copy-to-clipboard" ;
4
4
// @ts -ignore
5
- import { Prism as SyntaxHighlighter } from ' react-syntax-highlighter' ;
5
+ import { Prism as SyntaxHighlighter } from " react-syntax-highlighter" ;
6
6
// @ts -ignore
7
- import { okaidia } from ' react-syntax-highlighter/dist/esm/styles/prism' ;
8
- import remarkGfm from ' remark-gfm' ;
9
- import styles from ' ./styles.module.scss' ;
10
- import React from ' react' ;
11
- import RightSvg from ' ../../Icons/Right' ;
7
+ import { okaidia } from " react-syntax-highlighter/dist/esm/styles/prism" ;
8
+ import remarkGfm from " remark-gfm" ;
9
+ import styles from " ./styles.module.scss" ;
10
+ import React from " react" ;
11
+ import RightSvg from " ../@site/static/icons/arrowright.svg" ;
12
12
13
13
interface IProps {
14
- textContent : string
14
+ textContent : string ;
15
15
}
16
- const AskDatabendMarkdown : FC < IProps > = ( { textContent } ) : ReactElement => {
16
+ const AskDatabendMarkdown : FC < IProps > = ( { textContent } ) : ReactElement => {
17
17
const [ isCopy , setIsCopy ] = useState ( false ) ;
18
18
return (
19
19
< ReactMarkdown
20
20
remarkPlugins = { [ remarkGfm ] }
21
21
components = { {
22
+ // @ts -ignore
22
23
code ( { inline, className, children, ...props } ) {
23
- const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' ) ;
24
- const text = String ( children ) . replace ( / \n $ / , '' ) ;
25
- const language = match ? match [ 1 ] : ' sql' ;
24
+ const match = / l a n g u a g e - ( \w + ) / . exec ( className || "" ) ;
25
+ const text = String ( children ) . replace ( / \n $ / , "" ) ;
26
+ const language = match ? match [ 1 ] : " sql" ;
26
27
return ! inline && language ? (
27
- < div
28
- onMouseLeave = { ( ) => setIsCopy ( false ) }
29
- className = { styles . codeWrap } >
28
+ < div
29
+ onMouseLeave = { ( ) => setIsCopy ( false ) }
30
+ className = { styles . codeWrap }
31
+ >
30
32
< SyntaxHighlighter
31
33
showLineNumbers = { true }
32
34
style = { okaidia as any }
33
35
language = { language }
34
- PreTag = ' div'
36
+ PreTag = " div"
35
37
{ ...props }
36
38
>
37
39
{ text }
@@ -43,11 +45,7 @@ const AskDatabendMarkdown: FC<IProps> = ({ textContent }): ReactElement=> {
43
45
setIsCopy ( true ) ;
44
46
} }
45
47
>
46
- {
47
- ( isCopy )
48
- ? < RightSvg />
49
- : < > Copy</ >
50
- }
48
+ { isCopy ? < RightSvg /> : < > Copy</ > }
51
49
</ span >
52
50
</ div >
53
51
) : (
@@ -56,28 +54,29 @@ const AskDatabendMarkdown: FC<IProps> = ({ textContent }): ReactElement=> {
56
54
</ code >
57
55
) ;
58
56
} ,
59
- a : ( props : { href : string , children : string [ ] } | any ) => {
57
+ a : ( props : { href : string ; children : string [ ] } | any ) => {
60
58
const desc = props ?. children [ 0 ] ;
61
59
return (
62
- < a
63
- target = "_blank"
64
- title = { desc }
65
- rel = "noopener noreferrer"
66
- href = { props ?. href } >
60
+ < a
61
+ target = "_blank"
62
+ title = { desc }
63
+ rel = "noopener noreferrer"
64
+ href = { props ?. href }
65
+ >
67
66
{ desc }
68
67
</ a >
69
68
) ;
70
69
} ,
71
- table : ( { ...props } ) => (
72
- < div style = { { overflowX : ' auto' , width : ' 100%' } } >
70
+ table : ( { ...props } ) => (
71
+ < div style = { { overflowX : " auto" , width : " 100%" } } >
73
72
< table { ...props } />
74
73
</ div >
75
- )
74
+ ) ,
76
75
} }
77
76
>
78
77
{ textContent }
79
78
</ ReactMarkdown >
80
79
) ;
81
80
} ;
82
81
83
- export default AskDatabendMarkdown ;
82
+ export default AskDatabendMarkdown ;
0 commit comments