Skip to content

Commit

Permalink
Fix test and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 28, 2023
1 parent 6327783 commit 568fc63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
15 changes: 10 additions & 5 deletions sphinx/environment/adapters/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,21 @@ def _entries_from_toctree(toctreenode: addnodes.toctree, parents: list[str],
continue
if is_hidden:
# hidden entries always go last
start_pos = len(sub_toc_node.parent)
sub_toc_node.parent.parent.parent.extend(_entries_from_toctree(
sub_toc_node, [refdoc or ''] + parents, subtree=True))
else:
# visible entries go after the toctree
start_pos = sub_toc_node.parent.index(sub_toc_node) + 1
for i, entry in enumerate(
_entries_from_toctree(sub_toc_node, [refdoc or ''] + parents,
subtree=True), start=start_pos):
sub_toc_node.parent.insert(i, entry)
for i, entry in enumerate(
_entries_from_toctree(sub_toc_node, [refdoc or ''] + parents,
subtree=True), start=start_pos):
sub_toc_node.parent.insert(i, entry)
sub_toc_node.parent.remove(sub_toc_node)

for bl in list(toc.findall(nodes.bullet_list)):
if not bl.children:
bl.parent.remove(bl)

entries.extend(children)
if not subtree:
ret = nodes.bullet_list()
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-toctree-hidden/doc3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Document 3
==========
11 changes: 8 additions & 3 deletions tests/roots/test-toctree-hidden/part.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
Part
====

Section 1
---------

.. toctree::
:hidden:

doc1
doc2

Section 1
---------

Section 2
---------

.. toctree::
:hidden:

doc3
2 changes: 2 additions & 0 deletions tests/test_directive_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ def test_toctree_hidden_section_order(app):

content = (app.outdir / 'index.html').read_text(encoding='utf-8')

# language=HTML
assert """\
<ul>
<li class="toctree-l1"><a class="reference internal" href="part.html">Part</a><ul>
<li class="toctree-l2"><a class="reference internal" href="part.html#section-1">Section 1</a></li>
<li class="toctree-l2"><a class="reference internal" href="part.html#section-2">Section 2</a></li>
<li class="toctree-l2"><a class="reference internal" href="doc1.html">Document 1</a></li>
<li class="toctree-l2"><a class="reference internal" href="doc2.html">Document 2</a></li>
<li class="toctree-l2"><a class="reference internal" href="doc3.html">Document 3</a></li>
</ul>""" in content

0 comments on commit 568fc63

Please sign in to comment.