Merge pull request #5050 from tk0miya/5048_numbered_toctree

Fix #5048: crashed with numbered toctree
This commit is contained in:
Takeshi KOMIYA 2018-06-08 22:05:17 +09:00 committed by GitHub
commit 738198022c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -21,6 +21,7 @@ Bugs fixed
* #5016: crashed when recommonmark.AutoStrictify is enabled
* #5022: latex: crashed with docutils package provided by Debian/Ubuntu
* #5009: latex: a label for table is vanished if table does not have a caption
* #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()