Review updates

This commit is contained in:
sethg committed 2020-02-22 16:23:05 +01:00
1 parent d761c81d60
commit b469cc104e
2 files changed
+14 -11

No files matched your search

+5 -4
View File
@@ -75,12 +75,13 @@ class IndexDirective(SphinxDirective):
def run(self) -> List[Node]:
arguments = self.arguments[0].split('\n')
targetid = 'index-%s' % self.env.new_serialno('index')
targetnode = nodes.target('', '', ids=[targetid])
if 'name' in self.options:
targetname = self.options['name']
targetnode['names'].append(targetname)
targetid = self.options['name']
targetnode = nodes.target('', '', names=[targetid])
else:
targetid = 'index-%s' % self.env.new_serialno('index')
targetnode = nodes.target('', '', ids=[targetid])
self.state.document.note_explicit_target(targetnode)
indexnode = addnodes.index()
+9 -7
View File
@@ -116,20 +116,22 @@ def test_create_seealso_index(app):
def test_create_index_with_name(app):
text = (".. index:: single: docutils\n"
" :name: ref1\n"
".. index:: see: Python; interpreter\n"
" :name: ref2\n")
".. index:: single: Python\n"
" :name: ref2\n"
".. index:: Sphinx\n")
restructuredtext.parse(app, text)
index = IndexEntries(app.env).create_index(app.builder)
# check index is created correctly
assert len(index) == 2
assert index[0] == ('D', [('docutils', [[('', '#index-0')], [], None])])
assert index[1] == ('P', [('Python', [[], [('see interpreter', [])], None])])
assert len(index) == 3
assert index[0] == ('D', [('docutils', [[('', '#ref1')], [], None])])
assert index[1] == ('P', [('Python', [[('', '#ref2')], [], None])])
assert index[2] == ('S', [('Sphinx', [[('', '#index-0')], [], None])])
# check the reference labels are created correctly
std = app.env.get_domain('std')
assert std.anonlabels['ref1'] == ('index', 'index-0')
assert std.anonlabels['ref2'] == ('index', 'index-1')
assert std.anonlabels['ref1'] == ('index', 'ref1')
assert std.anonlabels['ref2'] == ('index', 'ref2')
@pytest.mark.sphinx('dummy', freshenv=True)