Skip to content

Commit 94acb19

Browse files
authored
Merge pull request #9998 from tk0miya/9993_inline_target
Close #9993: std domain: Allow to refer an inline target via ref role
2 parents 7d59c40 + e3ee8b3 commit 94acb19

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Features added
3131
checking in matched documents.
3232
* #9793: sphinx-build: Allow to use the parallel build feature in macOS on macOS
3333
and Python3.8+
34+
* #9993: std domain: Allow to refer an inline target (ex. ``_`target name```)
35+
via :rst:role:`ref` role
3436
* #9391: texinfo: improve variable in ``samp`` role
3537
* #9578: texinfo: Add :confval:`texinfo_cross_references` to disable cross
3638
references for readability with standalone readers

sphinx/domains/std.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,18 +770,20 @@ def process_doc(self, env: "BuildEnvironment", docname: str, document: nodes.doc
770770
sectname = clean_astext(title)
771771
elif node.tagname == 'rubric':
772772
sectname = clean_astext(node)
773+
elif node.tagname == 'target' and len(node) > 0:
774+
# inline target (ex: blah _`blah` blah)
775+
sectname = clean_astext(node)
773776
elif self.is_enumerable_node(node):
774777
sectname = self.get_numfig_title(node)
775-
if not sectname:
776-
continue
777778
else:
778779
toctree = next(iter(node.traverse(addnodes.toctree)), None)
779780
if toctree and toctree.get('caption'):
780781
sectname = toctree.get('caption')
781782
else:
782783
# anonymous-only labels
783784
continue
784-
self.labels[name] = docname, labelid, sectname
785+
if sectname:
786+
self.labels[name] = docname, labelid, sectname
785787

786788
def add_program_option(self, program: str, name: str, docname: str, labelid: str) -> None:
787789
self.progoptions[program, name] = (docname, labelid)

tests/test_domain_std.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,12 @@ def test_labeled_rubric(app):
452452
domain = app.env.get_domain("std")
453453
assert 'label' in domain.labels
454454
assert domain.labels['label'] == ('index', 'label', 'blah blah blah')
455+
456+
457+
def test_inline_target(app):
458+
text = "blah _`inline target` blah\n"
459+
restructuredtext.parse(app, text)
460+
461+
domain = app.env.get_domain("std")
462+
assert 'inline target' in domain.labels
463+
assert domain.labels['inline target'] == ('index', 'inline-target', 'inline target')

0 commit comments

Comments
 (0)