File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change
1
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
2
+ document . querySelectorAll ( ".copybtn" ) . forEach ( ( btn ) => {
3
+ btn . addEventListener ( "click" , async function ( event ) {
4
+ event . preventDefault ( ) ;
5
+
6
+ const codeBlock = btn . closest ( "div.highlight" ) ;
7
+ if ( ! codeBlock ) return ;
8
+
9
+ const clone = codeBlock . cloneNode ( true ) ;
10
+
11
+ // Remove spans with data-hidden="true"
12
+ clone . querySelectorAll ( "span.copybutton" ) . forEach ( ( el ) => {
13
+ if ( el . getAttribute ( "data-hidden" ) === "true" ) {
14
+ el . remove ( ) ;
15
+ }
16
+ } ) ;
17
+
18
+ const text = clone . innerText ;
19
+
20
+ try {
21
+ await navigator . clipboard . writeText ( text ) ;
22
+ console . log ( "Copied cleaned code to clipboard." ) ;
23
+ } catch ( err ) {
24
+ console . warn ( "Clipboard API failed, using fallback." ) ;
25
+ fallbackCopy ( text ) ;
26
+ }
27
+ } ) ;
28
+ } ) ;
29
+
30
+ function fallbackCopy ( text ) {
31
+ const textarea = document . createElement ( "textarea" ) ;
32
+ textarea . value = text ;
33
+ document . body . appendChild ( textarea ) ;
34
+ textarea . select ( ) ;
35
+ try {
36
+ document . execCommand ( "copy" ) ;
37
+ console . log ( "Copied using fallback." ) ;
38
+ } catch ( err ) {
39
+ console . error ( "Fallback copy failed:" , err ) ;
40
+ }
41
+ document . body . removeChild ( textarea ) ;
42
+ }
43
+ } ) ;
Original file line number Diff line number Diff line change 57
57
"matplotlib.sphinxext.plot_directive" ,
58
58
"numpydoc" ,
59
59
"sphinx_copybutton" ,
60
+ 'sphinx_toggleprompt' ,
60
61
"sphinx_design" ,
61
62
"sphinx.ext.autodoc" ,
62
63
"sphinx.ext.autosummary" ,
296
297
"css/pandas.css" ,
297
298
]
298
299
300
+ html_js_files = [
301
+ 'js/custom-copy.js'
302
+ ]
303
+
299
304
# The name of an image file (within the static path) to use as favicon of the
300
305
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
301
306
# pixels large.
462
467
# latex_use_modindex = True
463
468
464
469
# Configure copybutton to strip Python REPL prompts and output when copying
465
- copybutton_prompt_text = r">>> |\.\.\.:|In \[\d+\]:?|Out\[\d+\]:?"
466
- copybutton_prompt_is_regexp = True
470
+ toggleprompt_prompt_text = r">>> |\.\.\.:|In \[\d+\]:|Out\[\d+\]:"
471
+ toggleprompt_is_regexp = True
472
+
473
+ copybutton_prompt_text = ''
474
+ copybutton_is_regexp = False
467
475
468
476
if include_api :
469
477
intersphinx_mapping = {
You can’t perform that action at this time.
0 commit comments