mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6098 from tk0miya/6096_figure_anchors
Fix #6096: html: Anchor links are not added to figures
This commit is contained in:
commit
ce093636e9
2
CHANGES
2
CHANGES
@ -16,6 +16,8 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #6096: html: Anchor links are not added to figures
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -509,9 +509,7 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
||||||
self.add_permalink_ref(node.parent, _('Permalink to this code'))
|
self.add_permalink_ref(node.parent, _('Permalink to this code'))
|
||||||
elif isinstance(node.parent, nodes.figure):
|
elif isinstance(node.parent, nodes.figure):
|
||||||
image_nodes = node.parent.traverse(nodes.image)
|
self.add_permalink_ref(node.parent, _('Permalink to this image'))
|
||||||
target_node = image_nodes and image_nodes[0] or node.parent
|
|
||||||
self.add_permalink_ref(target_node, _('Permalink to this image'))
|
|
||||||
elif node.parent.get('toctree'):
|
elif node.parent.get('toctree'):
|
||||||
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))
|
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))
|
||||||
|
|
||||||
|
@ -455,9 +455,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
|||||||
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'):
|
||||||
self.add_permalink_ref(node.parent, _('Permalink to this code'))
|
self.add_permalink_ref(node.parent, _('Permalink to this code'))
|
||||||
elif isinstance(node.parent, nodes.figure):
|
elif isinstance(node.parent, nodes.figure):
|
||||||
image_nodes = node.parent.traverse(nodes.image)
|
self.add_permalink_ref(node.parent, _('Permalink to this image'))
|
||||||
target_node = image_nodes and image_nodes[0] or node.parent
|
|
||||||
self.add_permalink_ref(target_node, _('Permalink to this image'))
|
|
||||||
elif node.parent.get('toctree'):
|
elif node.parent.get('toctree'):
|
||||||
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))
|
self.add_permalink_ref(node.parent.parent, _('Permalink to this toctree'))
|
||||||
|
|
||||||
|
@ -1254,6 +1254,15 @@ def test_html_inventory(app):
|
|||||||
'The basic Sphinx documentation for testing')
|
'The basic Sphinx documentation for testing')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='images', confoverrides={'html_sourcelink_suffix': ''})
|
||||||
|
def test_html_anchor_for_figure(app):
|
||||||
|
app.builder.build_all()
|
||||||
|
content = (app.outdir / 'index.html').text()
|
||||||
|
assert ('<p class="caption"><span class="caption-text">The caption of pic</span>'
|
||||||
|
'<a class="headerlink" href="#id1" title="Permalink to this image">¶</a></p>'
|
||||||
|
in content)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='directives-raw')
|
@pytest.mark.sphinx('html', testroot='directives-raw')
|
||||||
def test_html_raw_directive(app, status, warning):
|
def test_html_raw_directive(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
Loading…
Reference in New Issue
Block a user