-
Notifications
You must be signed in to change notification settings - Fork 9
FEAT: Add solution_after_exercise style option #81
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
- 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
- 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
- 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
- Update CHANGELOG.md to include order validation system details - Fix syntax.md to accurately reflect simplified 'Solution' title - Add validation behavior documentation
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
Member
Author
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
exercise_styleconfig option for solution stylingSummary
This PR adds a new configuration option to improve the styling and usability of solution directives, particularly for projects like QuantEcon lectures where solutions immediately follow exercises.
Changes
1. New Configuration Option:
exercise_styleAdds a new configuration option
exercise_style(default:"") that can be enabled inconf.py:Purpose: When set to
"solution_follow_exercise", this simplifies solution titles by:Before (default behavior):
After (with
exercise_style = "solution_follow_exercise"):This is particularly useful when solutions follow exercises directly in the content, reducing visual clutter and avoiding confusion when users click on dropdowns.
2. Order Validation System
When
exercise_style = "solution_follow_exercise"is set, the extension validates that solutions actually follow their referenced exercises and provides helpful warnings:Features:
Warning Examples:
Implementation Details
Modified Files:
sphinx_exercise/__init__.py- Registered config option, added order tracking and validationsphinx_exercise/post_transforms.py- Simplified solution title logic, cleaned up redundant codedocs/source/syntax.md- Documentation for configuration optiondocs/source/install.md- Updated to use modernpip install -e .CHANGELOG.md- Documented all changesNew Files:
tests/test_exercise_style.py- Tests for solution title stylingtests/test_order_validation.py- Tests for order validation warningsFeatures
✅ Backward compatible - Default behavior unchanged (opt-in configuration)
✅ Well-tested - 6 new tests, all 116 tests pass
✅ Properly handles:
Testing
All tests pass across Python 3.10-3.13 and Sphinx 6-8:
New tests verify:
exercise_style='solution_follow_exercise'exercise_style=''(default)Usage Example
Configuration (
conf.py):Content:
:::{exercise} Factorial Function :label: ex-factorial Write a function to calculate the factorial of a number. ::: :::{solution} ex-factorial :class: dropdown Here's the solution... :::With
exercise_style = "solution_follow_exercise":Documentation
docs/source/syntax.mdwith configuration documentationdocs/source/install.mdto use modern pip installCHANGELOG.mdentries for all changesRelated Issues
Addresses user request for QuantEcon lectures where solutions follow exercises, reducing visual clutter and improving UX with the dropdown class.
Breaking Changes
None - this is a fully opt-in feature. Default behavior remains unchanged.