From e3ee8b378a37958f48d97d74a5c264f1f02e153e Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 21 Dec 2021 02:51:59 +0900 Subject: [PATCH] Close #9993: std domain: Allow to refer an inline target via ref role --- CHANGES | 2 ++ sphinx/domains/std.py | 8 +++++--- tests/test_domain_std.py | 9 +++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index d34034f8ca..f18e78cd63 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,8 @@ Features added checking in matched documents. * #9793: sphinx-build: Allow to use the parallel build feature in macOS on macOS and Python3.8+ +* #9993: std domain: Allow to refer an inline target (ex. ``_`target name```) + via :rst:role:`ref` role * #9391: texinfo: improve variable in ``samp`` role * #9578: texinfo: Add :confval:`texinfo_cross_references` to disable cross references for readability with standalone readers diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 7660f84c9b..d08c65668e 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -770,10 +770,11 @@ def process_doc(self, env: "BuildEnvironment", docname: str, document: nodes.doc sectname = clean_astext(title) elif node.tagname == 'rubric': sectname = clean_astext(node) + elif node.tagname == 'target' and len(node) > 0: + # inline target (ex: blah _`blah` blah) + sectname = clean_astext(node) elif self.is_enumerable_node(node): sectname = self.get_numfig_title(node) - if not sectname: - continue else: toctree = next(iter(node.traverse(addnodes.toctree)), None) if toctree and toctree.get('caption'): @@ -781,7 +782,8 @@ def process_doc(self, env: "BuildEnvironment", docname: str, document: nodes.doc else: # anonymous-only labels continue - self.labels[name] = docname, labelid, sectname + if sectname: + self.labels[name] = docname, labelid, sectname def add_program_option(self, program: str, name: str, docname: str, labelid: str) -> None: self.progoptions[program, name] = (docname, labelid) diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index 011c82f6ab..c464ea0084 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -452,3 +452,12 @@ def test_labeled_rubric(app): domain = app.env.get_domain("std") assert 'label' in domain.labels assert domain.labels['label'] == ('index', 'label', 'blah blah blah') + + +def test_inline_target(app): + text = "blah _`inline target` blah\n" + restructuredtext.parse(app, text) + + domain = app.env.get_domain("std") + assert 'inline target' in domain.labels + assert domain.labels['inline target'] == ('index', 'inline-target', 'inline target')