@@ -119,6 +119,7 @@ def __init__(
119
119
prefix = JUPYTERLITE_DIR ,
120
120
notebook = None ,
121
121
lite_options = {},
122
+ button_text = None ,
122
123
** attributes ,
123
124
):
124
125
app_path = self .lite_app
@@ -133,6 +134,8 @@ def __init__(
133
134
f'{ prefix } /{ app_path } { f"index.html?{ options } " if options else "" } '
134
135
)
135
136
137
+ self .button_text = button_text
138
+
136
139
super ().__init__ (
137
140
rawsource ,
138
141
** attributes ,
@@ -142,7 +145,7 @@ def html(self):
142
145
return (
143
146
'<button class="try_examples_button" '
144
147
f"onclick=\" window.open('{ self .lab_src } ')\" >"
145
- "Open as a notebook </button>"
148
+ f" { self . button_text } </button>"
146
149
)
147
150
148
151
@@ -210,6 +213,7 @@ class BaseNotebookTab(_InTab):
210
213
211
214
lite_app = None
212
215
notebooks_path = None
216
+ default_button_text = "Open as a notebook"
213
217
214
218
215
219
class JupyterLiteTab (BaseNotebookTab ):
@@ -295,6 +299,7 @@ def __init__(
295
299
prefix = JUPYTERLITE_DIR ,
296
300
notebook = None ,
297
301
lite_options = {},
302
+ button_text = None ,
298
303
** attributes ,
299
304
):
300
305
@@ -308,6 +313,8 @@ def __init__(
308
313
# If a notebook is provided, open it in a new tab. Else, we default to the tree view.
309
314
self .lab_src = f'{ prefix } /{ app_path } { f"?{ options } " if options else "" } '
310
315
316
+ self .button_text = button_text
317
+
311
318
super ().__init__ (
312
319
rawsource ,
313
320
** attributes ,
@@ -317,7 +324,7 @@ def html(self):
317
324
return (
318
325
'<button class="try_examples_button" '
319
326
f"onclick=\" window.open('{ self .lab_src } ')\" >"
320
- "Open with Voici </button>"
327
+ f" { self . button_text } </button>"
321
328
)
322
329
323
330
@@ -380,6 +387,7 @@ class _LiteDirective(SphinxDirective):
380
387
"prompt_color" : directives .unchanged ,
381
388
"search_params" : directives .unchanged ,
382
389
"new_tab" : directives .unchanged ,
390
+ "button_text" : directives .unchanged ,
383
391
}
384
392
385
393
def run (self ):
@@ -393,6 +401,8 @@ def run(self):
393
401
394
402
new_tab = self .options .pop ("new_tab" , False )
395
403
404
+ button_text = None
405
+
396
406
source_location = os .path .dirname (self .get_source_info ()[0 ])
397
407
398
408
prefix = os .path .relpath (
@@ -440,6 +450,24 @@ def run(self):
440
450
else :
441
451
notebook_name = None
442
452
453
+ if new_tab :
454
+ directive_button_text = self .options .pop ("button_text" , None )
455
+ if directive_button_text is not None :
456
+ button_text = directive_button_text
457
+ else :
458
+ # If none, we use the appropriate global config based on
459
+ # the type of directive passed.
460
+ if isinstance (self , JupyterLiteDirective ):
461
+ button_text = self .env .config .jupyterlite_button_text
462
+ elif isinstance (self , NotebookLiteDirective ):
463
+ button_text = self .env .config .notebooklite_button_text
464
+ elif isinstance (self , VoiciDirective ):
465
+ button_text = self .env .config .voici_button_text
466
+ elif "button_text" in self .options :
467
+ raise ValueError (
468
+ "'button_text' is only valid if 'new_tab' is True. To modify the prompt text, use 'prompt' and 'prompt_color'."
469
+ )
470
+
443
471
if new_tab :
444
472
return [
445
473
self .newtab_cls (
@@ -451,6 +479,7 @@ def run(self):
451
479
prompt_color = prompt_color ,
452
480
search_params = search_params ,
453
481
lite_options = self .options ,
482
+ button_text = button_text ,
454
483
)
455
484
]
456
485
@@ -482,6 +511,9 @@ class BaseJupyterViewDirective(_LiteDirective):
482
511
"prompt_color" : directives .unchanged ,
483
512
"search_params" : directives .unchanged ,
484
513
"new_tab" : directives .unchanged ,
514
+ # "button_text" below is valid only if "new_tab" is True, otherwise
515
+ # we have "prompt" and "prompt_color" as options already.
516
+ "button_text" : directives .unchanged ,
485
517
}
486
518
487
519
@@ -895,6 +927,16 @@ def setup(app):
895
927
rebuild = "html" ,
896
928
)
897
929
930
+ # Allow customising the button text for each directive (only when "new_tab" is True,
931
+ # error otherwise)
932
+ app .add_config_value (
933
+ "jupyterlite_button_text" , "Open as a notebook" , rebuild = "html"
934
+ )
935
+ app .add_config_value (
936
+ "notebooklite_button_text" , "Open as a notebook" , rebuild = "html"
937
+ )
938
+ app .add_config_value ("voici_button_text" , "Open with Voici" , rebuild = "html" )
939
+
898
940
# Initialize NotebookLite and JupyterLite directives
899
941
app .add_node (
900
942
NotebookLiteIframe ,
0 commit comments