Skip to content

Commit de754d4

Browse files
authored
Merge pull request #5 from najuzilu/fix-numref-placeholders
👌 IMPROVE: Support numref placeholders
2 parents a675565 + efc37bf commit de754d4

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

sphinx_exercise/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ def _update_numref(self, node, labelid):
272272
node_title = node.get("title", "")
273273

274274
if "{name}" in node_title and self._has_math_child(source_node[0]):
275-
276275
newtitle = nodes.inline()
277276
for item in node_title.split():
278277
if item == "{name}":
278+
# use extend instead?
279279
for _ in self._update_title(source_node[0]):
280280
newtitle += _
281-
elif item == "{number}" or item == "%s":
281+
elif item == "{number}":
282282
source_docname = source_attr.get("docname", "")
283283
source_type = self.domain.get_enumerable_node_type(source_node)
284284
source_number = self.domain.get_fignumber(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
_enum_numref_placeholders
2+
=========================
3+
4+
5+
This reference does not include math :numref:`some {number} text %s test {name} <test-exc-label>`.
6+
7+
This reference does not include math :numref:`some {number} text %s test <test-exc-label>`.
8+
9+
This reference does not include math :numref:`some {name} text %s test <test-exc-label>`.
10+
11+
This reference does not include math :numref:`some {name} text {number} test <test-exc-label>`.
12+
13+
This reference does not include math :numref:`some %s text test <test-exc-label>`.
14+
15+
16+
17+
This reference includes math :numref:`some {number} text %s test {name} <test-exc-label-math>`.
18+
19+
This reference includes math :numref:`some {number} text %s test <test-exc-label-math>`.
20+
21+
This reference includes math :numref:`some {name} text %s test <test-exc-label-math>`.
22+
23+
This reference includes math :numref:`some {name} text {number} test <test-exc-label-math>`.
24+
25+
This reference includes math :numref:`some %s text test <test-exc-label-math>`.

tests/books/test-mybook/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ A Test Program!
2626
exercise/_unenum_numref_notitle
2727
exercise/_unenum_numref_title
2828
exercise/_unenum_numref_mathtitle
29+
exercise/_enum_numref_placeholders
2930

3031
exercise/_enum_duplicate_label
3132

tests/test_exercise.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_exercise(app, idir, file_regression):
4444
"_unenum_numref_mathtitle.html",
4545
"_unenum_numref_notitle.html",
4646
"_unenum_numref_title.html",
47+
"_enum_numref_placeholders.html",
4748
],
4849
)
4950
def test_reference(app, idir, file_regression):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text %s test Test exercise directive</span></a>.</p>
2+
<p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text %s test</span></a>.</p>
3+
<p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some Test exercise directive text %s test</span></a>.</p>
4+
<p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some Test exercise directive text 3 test</span></a>.</p>
5+
<p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text test</span></a>.</p>
6+
<p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span>some 1 text %s test Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span></span></a>.</p>
7+
<p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some 1 text %s test</span></a>.</p>
8+
<p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span>some Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span> text %s test</span></a>.</p>
9+
<p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span>some Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span> text 1 test</span></a>.</p>
10+
<p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some 1 text test</span></a>.</p>

0 commit comments

Comments
 (0)