Skip to content

Commit fa14490

Browse files
author
n
committed
allow users to provide a custom label for duplicate names
1 parent eaebbec commit fa14490

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

sphinx/ext/autosectionlabel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
4242
docname = app.env.current_document.docname
4343
title = cast('nodes.title', node[0])
4444
ref_name = getattr(title, 'rawsource', title.astext())
45+
if len(node['ids']) > 1 and node['ids'][-1].startswith('id'):
46+
continue
4547
if app.config.autosectionlabel_prefix_document:
4648
name = nodes.fully_normalize_name(docname + ':' + ref_name)
4749
else:

tests/roots/test-ext-autosectionlabel-prefix-document/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Introduce of Sphinx
99
Installation
1010
============
1111

12+
.. _custom-label:
13+
14+
Installation
15+
============
16+
1217
For Windows users
1318
-----------------
1419

@@ -30,6 +35,7 @@ References
3035

3136
* :ref:`index:Introduce of Sphinx`
3237
* :ref:`index:Installation`
38+
* :ref:`custom-label`
3339
* :ref:`index:For Windows users`
3440
* :ref:`index:For UNIX users`
3541
* :ref:`index:Linux`

tests/roots/test-ext-autosectionlabel/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Introduce of Sphinx
99
Installation
1010
============
1111

12+
.. _custom-label:
13+
14+
Installation
15+
============
16+
1217
For Windows users
1318
-----------------
1419

@@ -30,6 +35,7 @@ References
3035
* :ref:`test-ext-autosectionlabel`
3136
* :ref:`Introduce of Sphinx`
3237
* :ref:`Installation`
38+
* :ref:`custom-label`
3339
* :ref:`For Windows users`
3440
* :ref:`For UNIX users`
3541
* :ref:`Linux`

tests/test_extensions/test_ext_autosectionlabel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def test_autosectionlabel_html(app: SphinxTestApp) -> None:
2828
)
2929
assert re.search(html, content, re.DOTALL)
3030

31+
html = (
32+
'<li><p><a class="reference internal" href="#custom-label">'
33+
'<span class="std std-ref">Installation</span></a></p></li>'
34+
)
35+
assert re.search(html, content, re.DOTALL)
36+
3137
html = (
3238
'<li><p><a class="reference internal" href="#for-windows-users">'
3339
'<span class="std std-ref">For Windows users</span></a></p></li>'

0 commit comments

Comments
 (0)