Fix #4611: epub: Show warning for duplicated ToC entries

This commit is contained in:
Takeshi KOMIYA 2019-02-03 20:35:00 +09:00
parent c70dfcd390
commit b950480218
7 changed files with 27 additions and 2 deletions

View File

@ -166,6 +166,7 @@ Features added
* C++: add ``cpp:struct`` to complement ``cpp:class``.
* #1341 the HTML search considers words that contain a search term of length
three or longer a match.
* #4611: epub: Show warning for duplicated ToC entries
Bugs fixed
----------

View File

@ -35,7 +35,7 @@ except ImportError:
if False:
# For type annotation
from typing import Any, Dict, List, Tuple # NOQA
from typing import Any, Dict, List, Set, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
@ -213,6 +213,15 @@ class EpubBuilder(StandaloneHTMLBuilder):
result = self.get_refnodes(elem, result)
return result
def check_refnodes(self, nodes):
# type: (List[Dict[str, Any]]) -> None
appeared = set() # type: Set[str]
for node in nodes:
if node['refuri'] in appeared:
logger.warning(__('duplicated ToC entry found: %s'), node['refuri'])
else:
appeared.add(node['refuri'])
def get_toc(self):
# type: () -> None
"""Get the total table of contents, containing the master_doc
@ -726,6 +735,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
else:
# 'includehidden'
refnodes = self.refnodes
self.check_refnodes(refnodes)
navpoints = self.build_navpoints(refnodes)
level = max(item['level'] for item in self.refnodes)
level = min(level, self.config.epub_tocdepth)

View File

@ -24,7 +24,6 @@ Contents:
math
autodoc
extensions
extensions
footnote
lists
otherext

View File

@ -0,0 +1,2 @@
foo
===

View File

@ -0,0 +1,7 @@
test-toctree-duplicated
=======================
.. toctree::
foo
foo

View File

@ -367,6 +367,12 @@ def test_html_download_role(app, status, warning):
'/_static/sphinxheader.png]</span></p></li>' in content)
@pytest.mark.sphinx('epub', testroot='toctree-duplicated')
def test_duplicated_toctree_entry(app, status, warning):
app.build()
assert 'WARNING: duplicated ToC entry found: foo.xhtml' in warning.getvalue()
@pytest.mark.skipif('DO_EPUBCHECK' not in os.environ,
reason='Skipped because DO_EPUBCHECK is not set')
@pytest.mark.sphinx('epub')