mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #4611: epub: Show warning for duplicated ToC entries
This commit is contained in:
parent
c70dfcd390
commit
b950480218
1
CHANGES
1
CHANGES
@ -166,6 +166,7 @@ Features added
|
|||||||
* C++: add ``cpp:struct`` to complement ``cpp:class``.
|
* C++: add ``cpp:struct`` to complement ``cpp:class``.
|
||||||
* #1341 the HTML search considers words that contain a search term of length
|
* #1341 the HTML search considers words that contain a search term of length
|
||||||
three or longer a match.
|
three or longer a match.
|
||||||
|
* #4611: epub: Show warning for duplicated ToC entries
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -35,7 +35,7 @@ except ImportError:
|
|||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# 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
|
from sphinx.application import Sphinx # NOQA
|
||||||
|
|
||||||
|
|
||||||
@ -213,6 +213,15 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
|||||||
result = self.get_refnodes(elem, result)
|
result = self.get_refnodes(elem, result)
|
||||||
return 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):
|
def get_toc(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""Get the total table of contents, containing the master_doc
|
"""Get the total table of contents, containing the master_doc
|
||||||
@ -726,6 +735,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
|||||||
else:
|
else:
|
||||||
# 'includehidden'
|
# 'includehidden'
|
||||||
refnodes = self.refnodes
|
refnodes = self.refnodes
|
||||||
|
self.check_refnodes(refnodes)
|
||||||
navpoints = self.build_navpoints(refnodes)
|
navpoints = self.build_navpoints(refnodes)
|
||||||
level = max(item['level'] for item in self.refnodes)
|
level = max(item['level'] for item in self.refnodes)
|
||||||
level = min(level, self.config.epub_tocdepth)
|
level = min(level, self.config.epub_tocdepth)
|
||||||
|
@ -24,7 +24,6 @@ Contents:
|
|||||||
math
|
math
|
||||||
autodoc
|
autodoc
|
||||||
extensions
|
extensions
|
||||||
extensions
|
|
||||||
footnote
|
footnote
|
||||||
lists
|
lists
|
||||||
otherext
|
otherext
|
||||||
|
0
tests/roots/test-toctree-duplicated/conf.py
Normal file
0
tests/roots/test-toctree-duplicated/conf.py
Normal file
2
tests/roots/test-toctree-duplicated/foo.rst
Normal file
2
tests/roots/test-toctree-duplicated/foo.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
foo
|
||||||
|
===
|
7
tests/roots/test-toctree-duplicated/index.rst
Normal file
7
tests/roots/test-toctree-duplicated/index.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
test-toctree-duplicated
|
||||||
|
=======================
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
|
||||||
|
foo
|
||||||
|
foo
|
@ -367,6 +367,12 @@ def test_html_download_role(app, status, warning):
|
|||||||
'/_static/sphinxheader.png]</span></p></li>' in content)
|
'/_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,
|
@pytest.mark.skipif('DO_EPUBCHECK' not in os.environ,
|
||||||
reason='Skipped because DO_EPUBCHECK is not set')
|
reason='Skipped because DO_EPUBCHECK is not set')
|
||||||
@pytest.mark.sphinx('epub')
|
@pytest.mark.sphinx('epub')
|
||||||
|
Loading…
Reference in New Issue
Block a user