Skip to content

Commit 75759aa

Browse files
committed
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
1 parent 669fac3 commit 75759aa

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

sphinx_exercise/directive.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ class : str,
222222
solution_node = solution_node
223223

224224
def run(self) -> List[Node]:
225-
self.defaults = {"title_text": f"{translate('Solution to')}"}
225+
# Set default title based on exercise_style config
226+
if self.env.app.config.exercise_style == "solution_follow_exercise":
227+
self.defaults = {"title_text": f"{translate('Solution')}"}
228+
else:
229+
self.defaults = {"title_text": f"{translate('Solution to')}"}
226230
target_label = self.arguments[0]
227231
self.serial_number = self.env.new_serialno()
228232

tests/test_exercise_style.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_solution_no_link(app):
3838
# Check that the title is just "Solution" without exercise reference
3939
title_text = title.get_text()
4040
assert (
41-
title_text.strip() == "Solution to"
42-
), "Solution title should be just 'Solution to' when exercise_style='solution_follow_exercise'"
41+
title_text.strip() == "Solution"
42+
), "Solution title should be just 'Solution' when exercise_style='solution_follow_exercise'"
4343

4444

4545
@pytest.mark.sphinx("html", testroot="mybook", confoverrides={"exercise_style": ""})
@@ -97,5 +97,5 @@ def test_solution_no_link_unenum(app):
9797
# Check that the title is just "Solution" without exercise reference
9898
title_text = title.get_text()
9999
assert (
100-
title_text.strip() == "Solution to"
101-
), "Solution title should be just 'Solution to' when exercise_style='solution_follow_exercise'"
100+
title_text.strip() == "Solution"
101+
), "Solution title should be just 'Solution' when exercise_style='solution_follow_exercise'"

0 commit comments

Comments
 (0)