summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-12-23 03:01:05 +0900
committerGitHub <noreply@github.com>2021-12-23 03:01:05 +0900
commit94acb1921c05dff9462fec50f3a80814dad659d3 (patch)
treefa1d0a35c69bb57205e53afd863d50da8e0b3c71
parent7d59c4060871b206e567c9ca55f4667e5bc44d8a (diff)
parente3ee8b378a37958f48d97d74a5c264f1f02e153e (diff)
downloadsphinx-git-94acb1921c05dff9462fec50f3a80814dad659d3.tar.gz
Merge pull request #9998 from tk0miya/9993_inline_target
Close #9993: std domain: Allow to refer an inline target via ref role
-rw-r--r--CHANGES2
-rw-r--r--sphinx/domains/std.py8
-rw-r--r--tests/test_domain_std.py9
3 files changed, 16 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index f3b1ccb48..77a901e85 100644
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,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')