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

@@ -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)