Skip to content

Duplicated Title in TOC do not generate correct links with singlehtml #13149

@Agadoul

Description

@Agadoul

Describe the bug

I have a singlehtml file generated from multiple rst.

in index.rst, there is a toctree drective to include other rst file.

Those rsts files contains multiple section. I have enabled autosectionlabel but a correct link is only generated for the main section not for the other section.

For example, the html:

<ul>
<li class="toctree-l1"><a class="reference internal" href="index.html#document-1_introduction">1. Introduction</a><ul>
<li class="toctree-l2"><a class="reference internal" href="index.html#purpose">1.1. Purpose</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#content">1.2. Content</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="index.html#document-2_protocols">2. Protocols</a><ul>
<li class="toctree-l2"><a class="reference internal" href="index.html#purpose">2.1. Purpose</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#content">2.2. Content</a></li>
</ul>

#document-1_ should prefix other item as well.

so when i click on the second content object it will alway go to the first one

any idea ?
Best regards,

How to Reproduce

we need 3 rst files.

index.rst:

================================================================
A
================================================================

.. toctree::
   :maxdepth: 3
   :numbered:
   :caption: Contents:

   1_introduction
   2_protocols

1_introduction.rst

================================================================
Introduction
================================================================

A

----------------------------------------------------------------
Purpose
----------------------------------------------------------------

B

----------------------------------------------------------------
Content
----------------------------------------------------------------

C

2_protocols.rst

================================================================
Protocols
================================================================

C

----------------------------------------------------------------
Purpose
----------------------------------------------------------------

D

----------------------------------------------------------------
Content
----------------------------------------------------------------

E

Environment Information

Platform:              win32; (Windows-11-10.0.22621-SP0)
Python version:        3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)])
Python implementation: CPython
Sphinx version:        8.1.3
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

'sphinx.ext.doctest',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions