Skip to content

Commit

Permalink
Merge pull request #9998 from tk0miya/9993_inline_target
Browse files Browse the repository at this point in the history
Close #9993: std domain: Allow to refer an inline target via ref role
  • Loading branch information
tk0miya committed Dec 22, 2021
2 parents 7d59c40 + e3ee8b3 commit 94acb19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions sphinx/domains/std.py
Expand Up @@ -770,18 +770,20 @@ 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'):
sectname = toctree.get('caption')
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)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_domain_std.py
Expand Up @@ -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')

0 comments on commit 94acb19

Please sign in to comment.