Skip to content

Commit 86bdf60

Browse files
authored
Merge pull request #161 from agriyakhetarpal/feat/add-default-global-button-text
Allow usage of global configuration values for `TryExamples` directive if provided by user
2 parents cb9426c + cd542e3 commit 86bdf60

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

docs/directives/try_examples.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ positioning of the button. The css for the example above is
117117

118118

119119
The `try_examples` directive has options
120-
* `:height:` To set a specific value for the height of the [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) containing the embeddednotebook.
120+
* `:height:` To set a specific value for the height of the [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) containing the embedded notebook.
121121
* `:button_text` To customize the text of the button that replaces the rendered examples with an embedded notebook.
122122
* `:theme:` This works the same as for the other JupyterLite-Sphinx directives.
123123
* `:example_class:` An html class to attach to the outer container for the rendered
@@ -204,7 +204,9 @@ allowing for specification of examples sections which should not be made interac
204204

205205

206206
The button text, theme, and warning text can be set globally with the config variables
207-
`try_examples_global_button_text`, `try_examples_global_theme`, and `try_examples_global_warning_text`.
207+
`try_examples_global_button_text`, `try_examples_global_theme`, and `try_examples_global_warning_text` in `conf.py`;
208+
these apply both to automatically and manually inserted directives. Options set explicitly in a directive will
209+
override the global configuration.
208210

209211
```python
210212
global_enable_try_examples = True

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,25 @@ def run(self):
387387
directive_key
388388
)
389389

390-
button_text = self.options.pop("button_text", "Try it with Jupyterlite!")
390+
# Use global configuration values from conf.py in manually inserted directives
391+
# if they are provided and the user has not specified a config value in the
392+
# directive itself.
393+
394+
default_button_text = self.env.config.try_examples_global_button_text
395+
if default_button_text is None:
396+
default_button_text = "Try it with JupyterLite!"
397+
button_text = self.options.pop("button_text", default_button_text)
398+
399+
default_warning_text = self.env.config.try_examples_global_warning_text
400+
warning_text = self.options.pop("warning_text", default_warning_text)
401+
402+
default_example_class = self.env.config.try_examples_global_theme
403+
if default_example_class is None:
404+
default_example_class = ""
405+
example_class = self.options.pop("example_class", default_example_class)
406+
407+
# A global height cannot be set in conf.py
391408
height = self.options.pop("height", None)
392-
example_class = self.options.pop("example_class", "")
393-
warning_text = self.options.pop("warning_text", None)
394409

395410
# We need to get the relative path back to the documentation root from
396411
# whichever file the docstring content is in.
@@ -611,7 +626,7 @@ def jupyterlite_build(app: Sphinx, error):
611626
if completed_process.returncode != 0:
612627
if app.env.config.jupyterlite_silence:
613628
print(
614-
"`jupyterlite build` failed but it's output has been silenced."
629+
"`jupyterlite build` failed but its output has been silenced."
615630
" stdout and stderr are reproduced below.\n"
616631
)
617632
print("stdout:", completed_process.stdout.decode())

0 commit comments

Comments
 (0)