Skip to content

Allow usage of global configuration values for TryExamples directive if provided by user #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/directives/try_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ positioning of the button. The css for the example above is


The `try_examples` directive has options
* `: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.
* `: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.
* `:button_text` To customize the text of the button that replaces the rendered examples with an embedded notebook.
* `:theme:` This works the same as for the other JupyterLite-Sphinx directives.
* `:example_class:` An html class to attach to the outer container for the rendered
Expand Down Expand Up @@ -204,7 +204,9 @@ allowing for specification of examples sections which should not be made interac


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

```python
global_enable_try_examples = True
Expand Down
23 changes: 19 additions & 4 deletions jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,25 @@ def run(self):
directive_key
)

button_text = self.options.pop("button_text", "Try it with Jupyterlite!")
# Use global configuration values from conf.py in manually inserted directives
# if they are provided and the user has not specified a config value in the
# directive itself.

default_button_text = self.env.config.try_examples_global_button_text
if default_button_text is None:
default_button_text = "Try it with JupyterLite!"
button_text = self.options.pop("button_text", default_button_text)

default_warning_text = self.env.config.try_examples_global_warning_text
warning_text = self.options.pop("warning_text", default_warning_text)

default_example_class = self.env.config.try_examples_global_theme
if default_example_class is None:
default_example_class = ""
example_class = self.options.pop("example_class", default_example_class)

# A global height cannot be set in conf.py
height = self.options.pop("height", None)
example_class = self.options.pop("example_class", "")
warning_text = self.options.pop("warning_text", None)

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