Commit 8cf34d2
authored
FEAT: Add solution_after_exercise style option (#81)
* 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' title1 parent 6d7859f commit 8cf34d2
File tree
8 files changed
+430
-25
lines changed- docs/source
- sphinx_exercise
- tests
8 files changed
+430
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
5 | 28 | | |
6 | 29 | | |
7 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
348 | 352 | | |
349 | 353 | | |
350 | 354 | | |
| |||
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
410 | 444 | | |
411 | 445 | | |
412 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| |||
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
| |||
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
130 | 236 | | |
131 | 237 | | |
132 | 238 | | |
133 | 239 | | |
134 | 240 | | |
135 | 241 | | |
136 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
137 | 251 | | |
138 | 252 | | |
139 | 253 | | |
140 | 254 | | |
141 | 255 | | |
142 | | - | |
143 | 256 | | |
144 | 257 | | |
145 | 258 | | |
146 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
147 | 274 | | |
148 | 275 | | |
149 | 276 | | |
| 277 | + | |
150 | 278 | | |
151 | 279 | | |
152 | 280 | | |
153 | 281 | | |
154 | 282 | | |
| 283 | + | |
155 | 284 | | |
156 | 285 | | |
157 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 144 | + | |
148 | 145 | | |
149 | 146 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
168 | 183 | | |
169 | 184 | | |
170 | 185 | | |
| |||
0 commit comments