1
- import { FC , PropsWithChildren , useEffect , useRef } from 'react' ;
1
+ import { FC , PropsWithChildren , useRef } from 'react' ;
2
2
import CodeLayout from 'react-code-preview-layout' ;
3
3
import { getMetaId , isMeta , getURLParameters , CodeBlockData } from 'markdown-react-code-preview-loader' ;
4
4
import MarkdownPreview , { MarkdownPreviewProps } from '@uiw/react-markdown-preview' ;
5
5
import rehypeIgnore from 'rehype-ignore' ;
6
6
import { CodeProps } from 'react-markdown/lib/ast-to-react' ;
7
+ import styled from 'styled-components' ;
7
8
8
9
const Preview = CodeLayout . Preview ;
9
10
const Code = CodeLayout . Code ;
@@ -13,6 +14,12 @@ interface CodePreviewProps extends CodeProps {
13
14
mdData ?: CodeBlockData ;
14
15
}
15
16
17
+ const CodeLayoutView = styled ( CodeLayout ) `
18
+ & + div.copied {
19
+ display: none !important;
20
+ }
21
+ ` ;
22
+
16
23
const CodePreview : FC < PropsWithChildren < CodePreviewProps > > = ( { inline, node, ...props } ) => {
17
24
const $dom = useRef < HTMLDivElement > ( null ) ;
18
25
const { mdData, ...rest } = props ;
@@ -35,15 +42,15 @@ const CodePreview: FC<PropsWithChildren<CodePreviewProps>> = ({ inline, node, ..
35
42
const code = mdData ?. data [ metaId ] . value || '' ;
36
43
const param = getURLParameters ( meta ) ;
37
44
return (
38
- < CodeLayout ref = { $dom } >
45
+ < CodeLayoutView ref = { $dom } >
39
46
< Preview >
40
47
< Child />
41
48
</ Preview >
42
- < Toolbar > { param . title || 'Example' } </ Toolbar >
49
+ < Toolbar text = { code } > { param . title || 'Example' } </ Toolbar >
43
50
< Code >
44
51
< pre { ...rest } />
45
52
</ Code >
46
- </ CodeLayout >
53
+ </ CodeLayoutView >
47
54
) ;
48
55
}
49
56
return < code { ...rest } /> ;
@@ -59,7 +66,7 @@ export default function Markdown(props: MarkdownProps) {
59
66
< MarkdownPreview
60
67
{ ...rest }
61
68
style = { { paddingTop : 30 } }
62
- disableCopy = { true }
69
+ // disableCopy={true}
63
70
rehypePlugins = { [ rehypeIgnore ] }
64
71
source = { props . source || '' }
65
72
components = { {
0 commit comments