Skip to content

Commit 7e9a206

Browse files
committed
Be more ephemeral (in anchor link title text)
1 parent 0e2ba0a commit 7e9a206

12 files changed

+36
-34
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Bugs fixed
6565
* #10795: Raise a descriptive error if ``graphviz_dot`` is falsy.
6666
* #11546: Translated nodes identical to their original text are now marked
6767
with the ``translated=True`` attribute.
68+
* #10049: html: Change "Permalink" to "Link" for title text in link anchors.
6869

6970
Testing
7071
-------

doc/usage/configuration.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,15 +1278,15 @@ that use Sphinx's HTMLWriter class.
12781278

12791279
.. confval:: html_permalinks
12801280

1281-
If true, Sphinx will add "permalinks" for each heading and description
1282-
environment. Default: ``True``.
1281+
Add link anchors for each heading and description environment.
1282+
Default: ``True``.
12831283

12841284
.. versionadded:: 3.5
12851285

12861286
.. confval:: html_permalinks_icon
12871287

1288-
A text for permalinks for each heading and description environment. HTML
1289-
tags are allowed. Default: a paragraph sign; ````
1288+
Text for link anchors for each heading and description environment.
1289+
HTML entities and Unicode are allowed. Default: a paragraph sign; ````
12901290

12911291
.. versionadded:: 3.5
12921292

sphinx/ext/imgmath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def html_visit_displaymath(self: HTML5Translator, node: nodes.math_block) -> Non
362362
if node['number']:
363363
number = get_node_equation_number(self, node)
364364
self.body.append('<span class="eqno">(%s)' % number)
365-
self.add_permalink_ref(node, _('Permalink to this equation'))
365+
self.add_permalink_ref(node, _('Link to this equation'))
366366
self.body.append('</span>')
367367

368368
if rendered_path is None:

sphinx/ext/mathjax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def html_visit_displaymath(self: HTML5Translator, node: nodes.math_block) -> Non
4646
if node['number']:
4747
number = get_node_equation_number(self, node)
4848
self.body.append('<span class="eqno">(%s)' % number)
49-
self.add_permalink_ref(node, _('Permalink to this equation'))
49+
self.add_permalink_ref(node, _('Link to this equation'))
5050
self.body.append('</span>')
5151
self.body.append(self.builder.config.mathjax_display[0])
5252
parts = [prt for prt in node.astext().split('\n\n') if prt.strip()]

sphinx/writers/html5.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def visit_desc_signature(self, node: Element) -> None:
9696
def depart_desc_signature(self, node: Element) -> None:
9797
self.protect_literal_text -= 1
9898
if not node.get('is_multiline'):
99-
self.add_permalink_ref(node, _('Permalink to this definition'))
99+
self.add_permalink_ref(node, _('Link to this definition'))
100100
self.body.append('</dt>\n')
101101

102102
def visit_desc_signature_line(self, node: Element) -> None:
@@ -105,7 +105,7 @@ def visit_desc_signature_line(self, node: Element) -> None:
105105
def depart_desc_signature_line(self, node: Element) -> None:
106106
if node.get('add_permalink'):
107107
# the permalink info is on the parent desc_signature node
108-
self.add_permalink_ref(node.parent, _('Permalink to this definition'))
108+
self.add_permalink_ref(node.parent, _('Link to this definition'))
109109
self.body.append('<br />')
110110

111111
def visit_desc_content(self, node: Element) -> None:
@@ -409,10 +409,11 @@ def append_fignumber(figtype: str, figure_id: str) -> None:
409409
append_fignumber(figtype, node['ids'][0])
410410

411411
def add_permalink_ref(self, node: Element, title: str) -> None:
412+
icon = self.config.html_permalinks_icon
412413
if node['ids'] and self.config.html_permalinks and self.builder.add_permalinks:
413-
format = '<a class="headerlink" href="#%s" title="%s">%s</a>'
414-
self.body.append(format % (node['ids'][0], title,
415-
self.config.html_permalinks_icon))
414+
self.body.append(
415+
f'<a class="headerlink" href="#{node["ids"][0]}" title="{title}">{icon}</a>',
416+
)
416417

417418
# overwritten
418419
def visit_bullet_list(self, node: Element) -> None:
@@ -457,7 +458,7 @@ def depart_term(self, node: Element) -> None:
457458
else:
458459
if isinstance(node.parent.parent.parent, addnodes.glossary):
459460
# add permalink if glossary terms
460-
self.add_permalink_ref(node, _('Permalink to this term'))
461+
self.add_permalink_ref(node, _('Link to this term'))
461462

462463
self.body.append('</dt>')
463464

@@ -480,16 +481,16 @@ def depart_title(self, node: Element) -> None:
480481
node.parent.hasattr('ids') and node.parent['ids']):
481482
# add permalink anchor
482483
if close_tag.startswith('</h'):
483-
self.add_permalink_ref(node.parent, _('Permalink to this heading'))
484+
self.add_permalink_ref(node.parent, _('Link to this heading'))
484485
elif close_tag.startswith('</a></h'):
485486
self.body.append('</a><a class="headerlink" href="#%s" ' %
486487
node.parent['ids'][0] +
487488
'title="{}">{}'.format(
488-
_('Permalink to this heading'),
489+
_('Link to this heading'),
489490
self.config.html_permalinks_icon))
490491
elif isinstance(node.parent, nodes.table):
491492
self.body.append('</span>')
492-
self.add_permalink_ref(node.parent, _('Permalink to this table'))
493+
self.add_permalink_ref(node.parent, _('Link to this table'))
493494
elif isinstance(node.parent, nodes.table):
494495
self.body.append('</span>')
495496

@@ -532,11 +533,11 @@ def depart_caption(self, node: Element) -> None:
532533

533534
# append permalink if available
534535
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
535-
self.add_permalink_ref(node.parent, _('Permalink to this code'))
536+
self.add_permalink_ref(node.parent, _('Link to this code'))
536537
elif isinstance(node.parent, nodes.figure):
537-
self.add_permalink_ref(node.parent, _('Permalink to this image'))
538+
self.add_permalink_ref(node.parent, _('Link to this image'))
538539
elif node.parent.get('toctree'):
539-
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))
540+
self.add_permalink_ref(node.parent.parent, _('Link to this toctree'))
540541

541542
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
542543
self.body.append('</div>\n')

tests/test_build_html.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ def test_html_anchor_for_figure(app):
13451345
app.builder.build_all()
13461346
content = (app.outdir / 'index.html').read_text(encoding='utf8')
13471347
assert ('<figcaption>\n<p><span class="caption-text">The caption of pic</span>'
1348-
'<a class="headerlink" href="#id1" title="Permalink to this image">¶</a></p>\n</figcaption>'
1348+
'<a class="headerlink" href="#id1" title="Link to this image">¶</a></p>\n</figcaption>'
13491349
in content)
13501350

13511351

@@ -1722,7 +1722,7 @@ def test_html_permalink_icon(app):
17221722

17231723
assert ('<h1>The basic Sphinx documentation for testing<a class="headerlink" '
17241724
'href="#the-basic-sphinx-documentation-for-testing" '
1725-
'title="Permalink to this heading"><span>[PERMALINK]</span></a></h1>' in content)
1725+
'title="Link to this heading"><span>[PERMALINK]</span></a></h1>' in content)
17261726

17271727

17281728
@pytest.mark.sphinx('html', testroot='html_signaturereturn_icon')
@@ -1769,7 +1769,7 @@ def test_option_emphasise_placeholders(app, status, warning):
17691769
'<em><span class="pre">COUNT</span></em>' in content)
17701770
assert '<span class="pre">{{value}}</span>' in content
17711771
assert ('<span class="pre">--plugin.option</span></span>'
1772-
'<a class="headerlink" href="#cmdoption-perl-plugin.option" title="Permalink to this definition">¶</a></dt>') in content
1772+
'<a class="headerlink" href="#cmdoption-perl-plugin.option" title="Link to this definition">¶</a></dt>') in content
17731773

17741774

17751775
@pytest.mark.sphinx('html', testroot='root')
@@ -1781,7 +1781,7 @@ def test_option_emphasise_placeholders_default(app, status, warning):
17811781
assert '<span class="pre">{client_name}</span>' in content
17821782
assert ('<span class="pre">--plugin.option</span></span>'
17831783
'<span class="sig-prename descclassname"></span>'
1784-
'<a class="headerlink" href="#cmdoption-perl-plugin.option" title="Permalink to this definition">¶</a></dt>') in content
1784+
'<a class="headerlink" href="#cmdoption-perl-plugin.option" title="Link to this definition">¶</a></dt>') in content
17851785

17861786

17871787
@pytest.mark.sphinx('html', testroot='root')

tests/test_directive_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_code_block_caption_html(app, status, warning):
323323
'<span class="caption-number">Listing 1 </span>'
324324
'<span class="caption-text">caption <em>test</em> rb'
325325
'</span><a class="headerlink" href="#id1" '
326-
'title="Permalink to this code">\xb6</a></div>')
326+
'title="Link to this code">\xb6</a></div>')
327327
assert caption in html
328328

329329

@@ -443,7 +443,7 @@ def test_literalinclude_caption_html(app, status, warning):
443443
'<span class="caption-number">Listing 2 </span>'
444444
'<span class="caption-text">caption <strong>test</strong> py'
445445
'</span><a class="headerlink" href="#id2" '
446-
'title="Permalink to this code">\xb6</a></div>')
446+
'title="Link to this code">\xb6</a></div>')
447447
assert caption in html
448448

449449

tests/test_domain_c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def test_domain_c_c_maximum_signature_line_length_in_html(app, status, warning):
10561056
</dl>
10571057
10581058
<span class="sig-paren">)</span>\
1059-
<a class="headerlink" href="#c.hello" title="Permalink to this definition">¶</a>\
1059+
<a class="headerlink" href="#c.hello" title="Link to this definition">¶</a>\
10601060
<br />\
10611061
</dt>
10621062
"""

tests/test_domain_js.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_domain_js_javascript_maximum_signature_line_length_in_html(app, status,
424424
</dl>
425425
426426
<span class="sig-paren">)</span>\
427-
<a class="headerlink" href="#hello" title="Permalink to this definition">¶</a>\
427+
<a class="headerlink" href="#hello" title="Link to this definition">¶</a>\
428428
</dt>\
429429
"""
430430
assert expected_parameter_list_hello in content
@@ -463,7 +463,7 @@ def test_domain_js_javascript_maximum_signature_line_length_in_html(app, status,
463463
{}{}{}{}{}{}</dl>
464464
465465
<span class="sig-paren">)</span>\
466-
<a class="headerlink" href="#foo" title="Permalink to this definition">¶</a>\
466+
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
467467
</dt>\
468468
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
469469
assert expected_parameter_list_foo in content

tests/test_domain_py.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ def test_domain_py_python_maximum_signature_line_length_in_html(app, status, war
16861686
<span class="sig-return-icon">&#x2192;</span> \
16871687
<span class="sig-return-typehint"><span class="pre">str</span></span>\
16881688
</span>\
1689-
<a class="headerlink" href="#hello" title="Permalink to this definition">¶</a>\
1689+
<a class="headerlink" href="#hello" title="Link to this definition">¶</a>\
16901690
</dt>\
16911691
"""
16921692
assert expected_parameter_list_hello in content
@@ -1725,7 +1725,7 @@ def test_domain_py_python_maximum_signature_line_length_in_html(app, status, war
17251725
{}{}{}{}{}{}</dl>
17261726
17271727
<span class="sig-paren">)</span>\
1728-
<a class="headerlink" href="#foo" title="Permalink to this definition">¶</a>\
1728+
<a class="headerlink" href="#foo" title="Link to this definition">¶</a>\
17291729
</dt>\
17301730
""".format(expected_a, expected_b, expected_c, expected_d, expected_e, expected_f)
17311731
assert expected_parameter_list_foo in content

tests/test_ext_inheritance_diagram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_inheritance_diagram_png_html(tmp_path, app):
170170
'<img src="_images/inheritance-\\w+.png" alt="Inheritance diagram of test.Foo" '
171171
'class="inheritance graphviz" /></div>\n<figcaption>\n<p>'
172172
'<span class="caption-text">Test Foo!</span><a class="headerlink" href="#id1" '
173-
'title="Permalink to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
173+
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
174174
assert re.search(pattern, content, re.M)
175175

176176
subdir_content = (app.outdir / 'subdir/index.html').read_text(encoding='utf8')
@@ -219,7 +219,7 @@ def test_inheritance_diagram_svg_html(tmp_path, app):
219219
'<p class=\"warning\">Inheritance diagram of test.Foo</p>'
220220
'</object></div>\n<figcaption>\n<p><span class="caption-text">'
221221
'Test Foo!</span><a class="headerlink" href="#id1" '
222-
'title="Permalink to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
222+
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
223223

224224
assert re.search(pattern, content, re.M)
225225

@@ -280,7 +280,7 @@ def test_inheritance_diagram_latex_alias(app, status, warning):
280280
'<img src="_images/inheritance-\\w+.png" alt="Inheritance diagram of test.Foo" '
281281
'class="inheritance graphviz" /></div>\n<figcaption>\n<p>'
282282
'<span class="caption-text">Test Foo!</span><a class="headerlink" href="#id1" '
283-
'title="Permalink to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
283+
'title="Link to this image">\xb6</a></p>\n</figcaption>\n</figure>\n')
284284
assert re.search(pattern, content, re.M)
285285

286286

tests/test_markup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ def get(name):
383383
'.. glossary::\n\n term1\n term2\n description',
384384
('<dl class="simple glossary">\n'
385385
'<dt id="term-term1">term1<a class="headerlink" href="#term-term1"'
386-
' title="Permalink to this term">¶</a></dt>'
386+
' title="Link to this term">¶</a></dt>'
387387
'<dt id="term-term2">term2<a class="headerlink" href="#term-term2"'
388-
' title="Permalink to this term">¶</a></dt>'
388+
' title="Link to this term">¶</a></dt>'
389389
'<dd><p>description</p>\n</dd>\n</dl>'),
390390
None,
391391
),

0 commit comments

Comments
 (0)