File tree 2 files changed +17
-15
lines changed
2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -826,31 +826,23 @@ progress::-moz-progress-bar {
826
826
height : inherit ;
827
827
}
828
828
829
- pre {
830
- padding : 8 px 12 px ;
829
+ /* Copy button */
830
+ .code-display-wrapper {
831
831
position : relative ;
832
832
833
- /* Copy code to clipboard button */
834
833
.copy {
835
834
background : var (--global-card-bg-color );
836
835
border-color : var (--global-bg-color );
837
836
border-radius : .3rem ;
838
- border-style : solid ;
837
+ border-style : none ;
839
838
color : var (--global-text-color );
840
839
font-size : medium ;
841
840
opacity : 0 ;
842
841
position : absolute ;
843
- right : .25rem ;
844
- top : .25rem ;
845
-
846
- & :active ,
847
- & :focus ,
848
- & :hover {
849
- color : var (--global-hover-color );
850
- opacity : 1 ;
851
- }
842
+ right : .15rem ;
843
+ top : .15rem ;
852
844
}
853
-
845
+
854
846
& :active .copy ,
855
847
& :focus .copy ,
856
848
& :hover .copy {
Original file line number Diff line number Diff line change 2
2
var codeBlocks = document . querySelectorAll ( 'pre' ) ;
3
3
codeBlocks . forEach ( function ( codeBlock ) {
4
4
if ( codeBlock . querySelector ( 'pre:not(.lineno)' ) || codeBlock . querySelector ( 'code' ) ) {
5
+ // create copy button
5
6
var copyButton = document . createElement ( 'button' ) ;
6
7
copyButton . className = 'copy' ;
7
8
copyButton . type = 'button' ;
8
9
copyButton . ariaLabel = 'Copy code to clipboard' ;
9
10
copyButton . innerText = 'Copy' ;
10
11
copyButton . innerHTML = '<i class="fas fa-clipboard"></i>' ;
11
- codeBlock . append ( copyButton ) ;
12
12
13
13
// get code from code block and copy to clipboard
14
14
copyButton . addEventListener ( 'click' , function ( ) {
@@ -32,5 +32,15 @@ codeBlocks.forEach(function (codeBlock) {
32
32
copyButton . innerHTML = '<i class="fas fa-clipboard"></i>' ;
33
33
} , waitFor ) ;
34
34
} ) ;
35
+
36
+ // create wrapper div
37
+ var wrapper = document . createElement ( 'div' ) ;
38
+ wrapper . className = 'code-display-wrapper' ;
39
+
40
+ // add copy button and code block to wrapper div
41
+ const parent = codeBlock . parentElement ;
42
+ parent . insertBefore ( wrapper , codeBlock ) ;
43
+ wrapper . append ( codeBlock ) ;
44
+ wrapper . append ( copyButton ) ;
35
45
}
36
46
} ) ;
You can’t perform that action at this time.
0 commit comments