You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add style_solution_after_exercise config option and improve dropdown UX
This commit adds two requested features for better solution styling:
1. New configuration option 'style_solution_after_exercise' (default: False)
- When enabled, removes hyperlinks from solution titles
- Displays plain text like 'Solution to Exercise 1 (Title)'
- Useful when solutions follow exercises directly
- Reduces confusion when using dropdown class
2. Improved dropdown button text
- Changed 'Click to show' to 'Show' for cleaner UI
- Changed 'Click to hide' to 'Hide'
- Applied via CSS customization
Features:
- Backward compatible (opt-in configuration)
- Properly handles numbered/unnumbered exercises
- Supports math expressions in titles
- Comprehensive test coverage (3 new tests)
- Full documentation in syntax.md
All 113 tests pass.
Copy file name to clipboardExpand all lines: docs/source/syntax.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -343,6 +343,8 @@ sphinx:
343
343
344
344
To hide the content, simply add `:class: dropdown` as a directive option.
345
345
346
+
**Note:** The dropdown toggle button text has been customized for `sphinx-exercise` directives to display "Show" / "Hide" instead of the default "Click to show" / "Click to hide" for a cleaner visual appearance.
347
+
346
348
For more use cases see [sphinx-togglebutton](https://sphinx-togglebutton.readthedocs.io/en/latest/#usage).
347
349
348
350
**Example**
@@ -407,6 +409,31 @@ sphinx:
407
409
...
408
410
```
409
411
412
+
### Solution Title Styling
413
+
414
+
By default, solution titles include a hyperlink to the corresponding exercise. This behavior can be modified using the `style_solution_after_exercise` configuration option.
415
+
416
+
When solutions follow exercises directly in your content (common in lecture notes), you may want to remove the hyperlink to avoid confusion when using the `dropdown` class. Set `style_solution_after_exercise` to `True` to display only text without hyperlinks in solution titles.
417
+
418
+
For Sphinx projects, add the configuration key in the `conf.py` file:
419
+
420
+
```python
421
+
# conf.py
422
+
style_solution_after_exercise =True
423
+
```
424
+
425
+
For Jupyter Book projects, set the configuration key in `_config.yml`:
426
+
427
+
```yaml
428
+
...
429
+
sphinx:
430
+
config:
431
+
style_solution_after_exercise: True
432
+
...
433
+
```
434
+
435
+
When `style_solution_after_exercise` is `True`, the solution title will display plain text like "Solution to Exercise 1 (Title)" instead of a hyperlink. When `False` (default), the exercise reference in the solution title remains clickable.
436
+
410
437
## Custom CSS or JavaScript
411
438
412
439
Custom JavaScript scripts and CSS rules will allow you to add additional functionality or customize how elements are displayed. If you'd like to include custom CSS or JavaScript scripts in Jupyter Book, simply add any files ending in `.css` or `.js` under a `_static` folder. Any files under this folder will be automatically copied into the built book.
0 commit comments