Fix #5048: crashed with numbered toctree

This commit is contained in:
Takeshi KOMIYA 2018-06-07 00:54:02 +09:00
parent 88cbd6a597
commit 96b9b9a127
3 changed files with 17 additions and 4 deletions

View File

@ -17,6 +17,7 @@ Bugs fixed
----------
* #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian
* #5048: crashed with numbered toctree
Testing
--------

View File

@ -165,13 +165,14 @@ class TocTreeCollector(EnvironmentCollector):
elif isinstance(subnode, addnodes.compact_paragraph):
numstack[-1] += 1
if depth > 0:
number = tuple(numstack)
number = list(numstack)
secnums[subnode[0]['anchorname']] = tuple(numstack)
else:
number = None
secnums[subnode[0]['anchorname']] = number
subnode[0]['secnumber'] = list(number)
secnums[subnode[0]['anchorname']] = None
subnode[0]['secnumber'] = number
if titlenode:
titlenode['secnumber'] = list(number)
titlenode['secnumber'] = number
titlenode = None
elif isinstance(subnode, addnodes.toctree):
_walk_toctree(subnode, depth)

View File

@ -8,6 +8,8 @@
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import pytest
@ -35,3 +37,12 @@ def test_singlehtml_toctree(app, status, warning):
app.builder._get_local_toctree('index')
except AttributeError:
pytest.fail('Unexpected AttributeError in app.builder.fix_refuris')
@pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree")
def test_numbered_toctree(app, status, warning):
# give argument to :numbered: option
index = (app.srcdir / 'index.rst').text()
index = re.sub(':numbered:.*', ':numbered: 1', index)
(app.srcdir / 'index.rst').write_text(index, encoding='utf-8')
app.builder.build_all()