Skip to content

Commit 2decd14

Browse files
committed
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.
1 parent a43c7bf commit 2decd14

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

docs/source/syntax.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,15 @@ sphinx:
411411

412412
### Solution Title Styling
413413

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.
414+
By default, solution titles include a hyperlink to the corresponding exercise. This behavior can be modified using the `exercise_style` configuration option.
415415

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.
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 `exercise_style` to `"solution_follow_exercise"` to display only text without hyperlinks in solution titles.
417417

418418
For Sphinx projects, add the configuration key in the `conf.py` file:
419419

420420
```python
421421
# conf.py
422-
style_solution_after_exercise = True
422+
exercise_style = "solution_follow_exercise"
423423
```
424424

425425
For Jupyter Book projects, set the configuration key in `_config.yml`:
@@ -428,11 +428,11 @@ For Jupyter Book projects, set the configuration key in `_config.yml`:
428428
...
429429
sphinx:
430430
config:
431-
style_solution_after_exercise: True
431+
exercise_style: "solution_follow_exercise"
432432
...
433433
```
434434

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.
435+
When `exercise_style` is set to `"solution_follow_exercise"`, the solution title will display plain text like "Solution to Exercise 1 (Title)" instead of a hyperlink. When empty `""` (default), the exercise reference in the solution title remains clickable.
436436

437437
## Custom CSS or JavaScript
438438

sphinx_exercise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def doctree_read(app: Sphinx, document: Node) -> None:
147147

148148
def setup(app: Sphinx) -> Dict[str, Any]:
149149
app.add_config_value("hide_solutions", False, "env")
150-
app.add_config_value("style_solution_after_exercise", False, "env")
150+
app.add_config_value("exercise_style", "", "env")
151151

152152
app.connect("config-inited", init_numfig) # event order - 1
153153
app.connect("env-purge-doc", purge_exercises) # event order - 5 per file

sphinx_exercise/post_transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def resolve_solution_title(app, node, exercise_node):
148148
# New Title Node
149149
updated_title = docutil_nodes.title()
150150

151-
# Check if style_solution_after_exercise is enabled
152-
if app.config.style_solution_after_exercise:
151+
# Check if exercise_style is set to "solution_follow_exercise"
152+
if app.config.exercise_style == "solution_follow_exercise":
153153
# Don't create hyperlink - just add plain text and nodes
154154
updated_title += docutil_nodes.Text(entry_title_text)
155155
updated_title += docutil_nodes.Text(updated_title_text)

tests/test_style_solution_after_exercise.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212

1313
@pytest.mark.sphinx(
14-
"html", testroot="mybook", confoverrides={"style_solution_after_exercise": True}
14+
"html",
15+
testroot="mybook",
16+
confoverrides={"exercise_style": "solution_follow_exercise"},
1517
)
1618
def test_solution_no_link(app):
17-
"""Test solution directive with style_solution_after_exercise=True removes hyperlink."""
19+
"""Test solution directive with exercise_style='solution_follow_exercise' removes hyperlink."""
1820
app.build()
1921
path_solution_directive = app.outdir / "solution" / "_linked_enum.html"
2022
assert path_solution_directive.exists()
@@ -27,23 +29,21 @@ def test_solution_no_link(app):
2729
sol = soup.select("div.solution")[0]
2830
title = sol.select("p.admonition-title")[0]
2931

30-
# Check that there is NO hyperlink in the title when style_solution_after_exercise=True
32+
# Check that there is NO hyperlink in the title when exercise_style='solution_follow_exercise'
3133
links = title.find_all("a")
3234
assert (
3335
len(links) == 0
34-
), "Solution title should not contain hyperlink when style_solution_after_exercise=True"
36+
), "Solution title should not contain hyperlink when exercise_style='solution_follow_exercise'"
3537

3638
# Check that the title text still contains the exercise reference
3739
title_text = title.get_text()
3840
assert "Exercise" in title_text
3941
assert "This is a title" in title_text
4042

4143

42-
@pytest.mark.sphinx(
43-
"html", testroot="mybook", confoverrides={"style_solution_after_exercise": False}
44-
)
44+
@pytest.mark.sphinx("html", testroot="mybook", confoverrides={"exercise_style": ""})
4545
def test_solution_with_link(app):
46-
"""Test solution directive with style_solution_after_exercise=False keeps hyperlink."""
46+
"""Test solution directive with exercise_style='' (default) keeps hyperlink."""
4747
app.build()
4848
path_solution_directive = app.outdir / "solution" / "_linked_enum.html"
4949
assert path_solution_directive.exists()
@@ -56,11 +56,11 @@ def test_solution_with_link(app):
5656
sol = soup.select("div.solution")[0]
5757
title = sol.select("p.admonition-title")[0]
5858

59-
# Check that there IS a hyperlink in the title when style_solution_after_exercise=False (default)
59+
# Check that there IS a hyperlink in the title when exercise_style='' (default)
6060
links = title.find_all("a")
6161
assert (
6262
len(links) == 1
63-
), "Solution title should contain hyperlink when style_solution_after_exercise=False"
63+
), "Solution title should contain hyperlink when exercise_style='' (default)"
6464

6565
# Check that the link points to the exercise
6666
link = links[0]
@@ -69,10 +69,12 @@ def test_solution_with_link(app):
6969

7070

7171
@pytest.mark.sphinx(
72-
"html", testroot="mybook", confoverrides={"style_solution_after_exercise": True}
72+
"html",
73+
testroot="mybook",
74+
confoverrides={"exercise_style": "solution_follow_exercise"},
7375
)
7476
def test_solution_no_link_unenum(app):
75-
"""Test unnumbered solution directive with style_solution_after_exercise=True removes hyperlink."""
77+
"""Test unnumbered solution directive with exercise_style='solution_follow_exercise' removes hyperlink."""
7678
app.build()
7779
path_solution_directive = app.outdir / "solution" / "_linked_unenum_title.html"
7880
assert path_solution_directive.exists()
@@ -89,7 +91,7 @@ def test_solution_no_link_unenum(app):
8991
links = title.find_all("a")
9092
assert (
9193
len(links) == 0
92-
), "Solution title should not contain hyperlink when style_solution_after_exercise=True"
94+
), "Solution title should not contain hyperlink when exercise_style='solution_follow_exercise'"
9395

9496
# Check that the title text still contains the exercise reference
9597
title_text = title.get_text()

0 commit comments

Comments
 (0)