File tree 2 files changed +28
-26
lines changed
2 files changed +28
-26
lines changed Original file line number Diff line number Diff line change 1
- 'use client'
2
- import { useEffect } from " react" ;
1
+ 'use client' ;
2
+ import { useEffect } from ' react' ;
3
3
4
4
export default function MarkdownCopyListener ( ) {
5
5
useEffect ( ( ) => {
6
- const copyBtns = document . querySelectorAll ( 'button.copy-code-btn' )
6
+ const copyBtns = document . querySelectorAll ( 'button.copy-code-btn' ) ;
7
7
copyBtns . forEach ( ( btn ) => {
8
8
( btn as HTMLButtonElement ) . addEventListener ( 'click' , ( ) => {
9
- const codeBlockContent = btn . parentElement ?. nextElementSibling ?. textContent
9
+ const codeBlockContent = btn . parentElement ?. nextElementSibling ?. textContent ;
10
10
if ( codeBlockContent ) {
11
11
navigator . clipboard . writeText ( codeBlockContent ) . then ( ( ) => {
12
- btn . textContent = 'Copied'
12
+ btn . textContent = 'Copied' ;
13
13
setTimeout ( ( ) => {
14
- btn . textContent = 'Copy'
15
- } , 2000 )
16
- } )
14
+ btn . textContent = 'Copy' ;
15
+ } , 2000 ) ;
16
+ } ) ;
17
17
}
18
- } )
19
- } )
18
+ } ) ;
19
+ } ) ;
20
20
21
21
return ( ) => {
22
22
copyBtns . forEach ( ( btn ) => {
23
- ( btn as HTMLButtonElement ) . removeEventListener ( 'click' , ( ) => { } )
24
- } )
25
- }
26
- } , [ ] )
23
+ ( btn as HTMLButtonElement ) . removeEventListener ( 'click' , ( ) => { } ) ;
24
+ } ) ;
25
+ } ;
26
+ } , [ ] ) ;
27
27
28
- return null
28
+ return null ;
29
29
}
Original file line number Diff line number Diff line change @@ -76,17 +76,19 @@ const Markdown = ({ markdown }: { markdown: string }) => {
76
76
} ,
77
77
) ;
78
78
79
- return < >
80
- < article
81
- className = "prose dark:prose-invert prose-pre:rounded-2xl prose-pre:bg-secondary/25"
82
- dangerouslySetInnerHTML = { {
83
- __html : DOMPurify . sanitize ( marked . parse ( markdown ) as string , {
84
- USE_PROFILES : { html : true } ,
85
- } ) ,
86
- } }
87
- > </ article >
88
- < MarkdownCopyListener />
89
- </ >
79
+ return (
80
+ < >
81
+ < article
82
+ className = "prose dark:prose-invert prose-pre:rounded-2xl prose-pre:bg-secondary/25"
83
+ dangerouslySetInnerHTML = { {
84
+ __html : DOMPurify . sanitize ( marked . parse ( markdown ) as string , {
85
+ USE_PROFILES : { html : true } ,
86
+ } ) ,
87
+ } }
88
+ > </ article >
89
+ < MarkdownCopyListener />
90
+ </ >
91
+ ) ;
90
92
} ;
91
93
92
94
export default Markdown ;
You can’t perform that action at this time.
0 commit comments