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.
* Rename config option to exercise_style for clarity
Changed configuration option name from 'style_solution_after_exercise'
to 'exercise_style' to make it clearer that this belongs to sphinx-exercise.
Changes:
- Config option: exercise_style = 'solution_follow_exercise' (was: style_solution_after_exercise = True)
- Default value: '' (empty string) instead of False
- More descriptive and namespaced for clarity in config files
This makes it clearer in configuration files that this is a
sphinx-exercise specific setting, especially when used alongside
other sphinx extensions like sphinx-proof.
Updated:
- sphinx_exercise/__init__.py
- sphinx_exercise/post_transforms.py
- tests/test_style_solution_after_exercise.py
- docs/source/syntax.md
All 113 tests pass.
* Documentation improvements and cleanup
- Renamed test file to test_exercise_style.py for consistency with new config name
- Updated CHANGELOG.md to reflect correct exercise_style configuration
- Fixed install.md to use modern pip editable install instead of deprecated setup.py
- All 113 tests pass across Python 3.11-3.13 and Sphinx 6-8
* Remove dropdown text customization from sphinx-exercise CSS
- Dropdown button text styling is better handled at theme level
- Removes CSS override for toggle-button text from exercise.css
- Updates documentation to suggest theme-level customization
- Updates CHANGELOG to reflect architectural decision
* Simplify solution titles and add order validation
- Simplified solution title to just 'Solution' when exercise_style='solution_follow_exercise'
(instead of 'Solution to Exercise #.#' since solution follows exercise)
- Clean up redundant code in post_transforms.py title building
- Add node order tracking and validation system
- Tracks exercise/solution node order as documents are read
- Validates solutions follow their exercises when config is set
- Reports helpful warnings with line numbers and labels
- Warning messages prefixed with [sphinx-exercise] for clarity
- Warnings include:
- 'Solution X does not follow exercise Y' with line numbers
- Cross-document reference detection
- Only runs when exercise_style='solution_follow_exercise'
- Add comprehensive tests for order validation
- Update test assertions to check for simplified titles
* docs: update CHANGELOG and syntax docs for accuracy
- Update CHANGELOG.md to include order validation system details
- Fix syntax.md to accurately reflect simplified 'Solution' title
- Add validation behavior documentation
* fix: use 'Solution' instead of 'Solution to' when exercise_style is set
When exercise_style='solution_follow_exercise', the solution title
should be just 'Solution' not 'Solution to'. This fix updates the
directive to use the correct default title text based on the config.
- Update SolutionDirective to check exercise_style config
- Set title_text to 'Solution' when config is set
- Keep 'Solution to' for default behavior
- Update tests to expect correct 'Solution' title
Copy file name to clipboardExpand all lines: docs/source/syntax.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -345,6 +345,10 @@ To hide the content, simply add `:class: dropdown` as a directive option.
345
345
346
346
For more use cases see [sphinx-togglebutton](https://sphinx-togglebutton.readthedocs.io/en/latest/#usage).
347
347
348
+
```{tip}
349
+
To customize the dropdown toggle button text (e.g., "Show" instead of "Click to show"), add custom CSS in your theme or project. This is typically handled at the theme level for consistent styling across all toggle buttons.
350
+
```
351
+
348
352
**Example**
349
353
350
354
```{exercise}
@@ -407,6 +411,36 @@ sphinx:
407
411
...
408
412
```
409
413
414
+
### Solution Title Styling
415
+
416
+
By default, solution titles include a hyperlink to the corresponding exercise. This behavior can be modified using the `exercise_style` configuration option.
417
+
418
+
When solutions follow exercises directly in your content (common in lecture notes), you may want to simplify the solution title. Set `exercise_style` to `"solution_follow_exercise"` to display a simplified title without hyperlinks or exercise references.
419
+
420
+
For Sphinx projects, add the configuration key in the `conf.py` file:
421
+
422
+
```python
423
+
# conf.py
424
+
exercise_style ="solution_follow_exercise"
425
+
```
426
+
427
+
For Jupyter Book projects, set the configuration key in `_config.yml`:
428
+
429
+
```yaml
430
+
...
431
+
sphinx:
432
+
config:
433
+
exercise_style: "solution_follow_exercise"
434
+
...
435
+
```
436
+
437
+
When `exercise_style` is set to `"solution_follow_exercise"`:
438
+
- The solution title displays just "Solution" (plain text, no hyperlink)
439
+
- The extension validates that solutions follow their referenced exercises and warns if they don't
440
+
- Solutions must be in the same document as their exercises (warnings if not)
441
+
442
+
When empty `""` (default), the solution title shows "Solution to Exercise #.#" with a clickable hyperlink to the exercise.
443
+
410
444
## Custom CSS or JavaScript
411
445
412
446
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