File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 44
55The **Copy To Clipboard** button will appear on all code blocks:
66
7+
8+ [source,shell]
9+ ----
10+ Copy me!
11+ Do something else
12+ Callout # <1>
13+ Callout # <2>
14+ Callout tab # <3>
15+ Comment # Just a regular comment after some code
16+ ----
17+
18+ <1> Callout
19+ <2> Callout
20+ <3> Callout after a tab
21+
22+
23+
724[source,adoc]
825----
926[source,adoc]
Original file line number Diff line number Diff line change @@ -35,6 +35,10 @@ import { createElement } from './modules/dom'
3535 }
3636} ) ( )
3737
38+ var cleanCallouts = function ( code ) {
39+ return code . replace ( / [ | \t ] + \n / g, '\n' ) . trimEnd ( )
40+ }
41+
3842document . addEventListener ( 'DOMContentLoaded' , function ( ) {
3943 var body = document . querySelectorAll ( 'body' )
4044 var ignore = [ 'gram' ]
@@ -45,7 +49,7 @@ document.addEventListener('DOMContentLoaded', function () {
4549 if ( language === 'bash' || language === 'sh' || language === 'shell' || language === 'console' ) {
4650 input = window . neo4jDocs . copyableCommand ( input )
4751 }
48-
52+ input = cleanCallouts ( input )
4953 return input
5054 }
5155
@@ -73,6 +77,16 @@ document.addEventListener('DOMContentLoaded', function () {
7377 }
7478 }
7579
80+ // capture copy command
81+ const copyThis = document . querySelectorAll ( 'pre code' )
82+ copyThis . forEach ( ( code ) => {
83+ code . addEventListener ( 'copy' , ( e ) => {
84+ const selection = document . getSelection ( )
85+ e . clipboardData . setData ( 'text/plain' , cleanCallouts ( selection . toString ( ) ) )
86+ e . preventDefault ( )
87+ } )
88+ } )
89+
7690 function capitalizeFirstLetter ( string ) {
7791 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 )
7892 }
You can’t perform that action at this time.
0 commit comments