diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-12-21 02:51:59 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-12-21 02:51:59 +0900 |
commit | e3ee8b378a37958f48d97d74a5c264f1f02e153e (patch) | |
tree | 4103003b153cc0d77b77c5614f2c18de50e41936 | |
parent | 40db5694faf8d74d34675a686960ca76d984042b (diff) | |
download | sphinx-git-e3ee8b378a37958f48d97d74a5c264f1f02e153e.tar.gz |
Close #9993: std domain: Allow to refer an inline target via ref role
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | sphinx/domains/std.py | 8 | ||||
-rw-r--r-- | tests/test_domain_std.py | 9 |
3 files changed, 16 insertions, 3 deletions
@@ -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 7660f84c9..d08c65668 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -770,10 +770,11 @@ class StandardDomain(Domain): 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 @@ class StandardDomain(Domain): 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 011c82f6a..c464ea008 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') |