Fix #6: Don't generate redundant `<ul>` for top-level TOC tree

items, which leads to a visual separation of TOC entries.
This commit is contained in:
Georg Brandl 2008-12-28 21:56:22 +01:00
parent d271cc57b2
commit 5d05ffc883
2 changed files with 13 additions and 3 deletions

View File

@ -32,6 +32,9 @@ New features added
- #77: If a description environment with info field list only - #77: If a description environment with info field list only
contains one ``:param:`` entry, no bullet list is generated. contains one ``:param:`` entry, no bullet list is generated.
- #6: Don't generate redundant ``<ul>`` for top-level TOC tree
items, which leads to a visual separation of TOC entries.
* Configuration: * Configuration:
- The new ``html_add_permalinks`` config value can be used to - The new ``html_add_permalinks`` config value can be used to

View File

@ -917,7 +917,7 @@ class BuildEnvironment:
else: else:
_walk_depth(subnode, depth+1, maxdepth, titleoverrides) _walk_depth(subnode, depth+1, maxdepth, titleoverrides)
def _entries_from_toctree(toctreenode, separate=False): def _entries_from_toctree(toctreenode, separate=False, subtree=False):
"""Return TOC entries for a toctree node.""" """Return TOC entries for a toctree node."""
includefiles = map(str, toctreenode['includefiles']) includefiles = map(str, toctreenode['includefiles'])
@ -947,7 +947,7 @@ class BuildEnvironment:
# resolve all sub-toctrees # resolve all sub-toctrees
for toctreenode in toc.traverse(addnodes.toctree): for toctreenode in toc.traverse(addnodes.toctree):
i = toctreenode.parent.index(toctreenode) + 1 i = toctreenode.parent.index(toctreenode) + 1
for item in _entries_from_toctree(toctreenode): for item in _entries_from_toctree(toctreenode, subtree=True):
toctreenode.parent.insert(i, item) toctreenode.parent.insert(i, item)
i += 1 i += 1
toctreenode.parent.remove(toctreenode) toctreenode.parent.remove(toctreenode)
@ -955,12 +955,19 @@ class BuildEnvironment:
entries.append(toc) entries.append(toc)
else: else:
entries.extend(toc.children) entries.extend(toc.children)
if not subtree and not separate:
ret = nodes.bullet_list()
ret += entries
return [ret]
return entries return entries
maxdepth = maxdepth or toctree.get('maxdepth', -1) maxdepth = maxdepth or toctree.get('maxdepth', -1)
titleoverrides = toctree.get('includetitles', {}) titleoverrides = toctree.get('includetitles', {})
tocentries = _entries_from_toctree(toctree, separate=True) # NOTE: previously, this was separate=True, but that leads to artificial
# separation when two or more toctree entries form a logical unit, so
# separating mode is no longer used -- it's kept here for history's sake
tocentries = _entries_from_toctree(toctree, separate=False)
if not tocentries: if not tocentries:
return None return None