@@ -15,24 +15,11 @@ import './styles/markdown.less';
15
15
16
16
import { reservedMeta } from './plugins/reservedMeta' ;
17
17
18
- const rehypeRewriteHandle = ( node : ElementContent , index : number | null , parent : Root | Element | null ) => {
19
- if ( node . type === 'element' && parent && parent . type === 'root' && / h ( 1 | 2 | 3 | 4 | 5 | 6 ) / . test ( node . tagName ) ) {
20
- const child = node . children && ( node . children [ 0 ] as Element ) ;
21
- if ( child && child . properties && child . properties . ariaHidden === 'true' ) {
22
- child . properties = { class : 'anchor' , ...child . properties } ;
23
- child . children = [ octiconLink ] ;
24
- }
25
- }
26
- if ( node . type === 'element' && node . tagName === 'pre' ) {
27
- const code = getCodeString ( node . children ) ;
28
- node . children . push ( copyElement ( code ) ) ;
29
- }
30
- } ;
31
-
32
18
export interface MarkdownPreviewProps extends Omit < Options , 'children' > {
33
19
prefixCls ?: string ;
34
20
className ?: string ;
35
21
source ?: string ;
22
+ disableCopy ?: boolean ;
36
23
style ?: React . CSSProperties ;
37
24
pluginsFilter ?: ( type : 'rehype' | 'remark' , plugin : PluggableList ) => PluggableList ;
38
25
warpperElement ?: React . DetailedHTMLProps < React . HTMLAttributes < HTMLDivElement > , HTMLDivElement > ;
@@ -50,6 +37,7 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
50
37
className,
51
38
source,
52
39
style,
40
+ disableCopy = false ,
53
41
onScroll,
54
42
onMouseOver,
55
43
pluginsFilter,
@@ -59,6 +47,21 @@ export default React.forwardRef<MarkdownPreviewRef, MarkdownPreviewProps>((props
59
47
const mdp = React . createRef < HTMLDivElement > ( ) ;
60
48
useImperativeHandle ( ref , ( ) => ( { ...props , mdp } ) , [ mdp , props ] ) ;
61
49
const cls = `${ prefixCls || '' } ${ className || '' } ` ;
50
+
51
+ const rehypeRewriteHandle = ( node : ElementContent , index : number | null , parent : Root | Element | null ) => {
52
+ if ( node . type === 'element' && parent && parent . type === 'root' && / h ( 1 | 2 | 3 | 4 | 5 | 6 ) / . test ( node . tagName ) ) {
53
+ const child = node . children && ( node . children [ 0 ] as Element ) ;
54
+ if ( child && child . properties && child . properties . ariaHidden === 'true' ) {
55
+ child . properties = { class : 'anchor' , ...child . properties } ;
56
+ child . children = [ octiconLink ] ;
57
+ }
58
+ }
59
+ if ( node . type === 'element' && node . tagName === 'pre' && ! disableCopy ) {
60
+ const code = getCodeString ( node . children ) ;
61
+ node . children . push ( copyElement ( code ) ) ;
62
+ }
63
+ } ;
64
+
62
65
const rehypePlugins : PluggableList = [
63
66
reservedMeta ,
64
67
[ rehypePrism , { ignoreMissing : true } ] ,
0 commit comments