mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7062 from tk0miya/7032_no-scaled_link
Close #7032: html_scaled_image_link is disabled for individual image
This commit is contained in:
commit
8987f3c031
2
CHANGES
2
CHANGES
@ -53,6 +53,8 @@ Features added
|
||||
in the documentation.
|
||||
* #1027: Support backslash line continuation in :rst:dir:`productionlist`.
|
||||
* #7108: config: Allow to show an error message from conf.py via ``ConfigError``
|
||||
* #7032: html: :confval:`html_scaled_image_link` will be disabled for images having
|
||||
``no-scaled-link`` class
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -1357,8 +1357,21 @@ that use Sphinx's HTMLWriter class.
|
||||
'target' option or scale related options: 'scale', 'width', 'height'.
|
||||
The default is ``True``.
|
||||
|
||||
Document authors can this feature manually with giving ``no-scaled-link``
|
||||
class to the image:
|
||||
|
||||
.. code-block:: rst
|
||||
|
||||
.. image:: sphinx.png
|
||||
:scale: 50%
|
||||
:class: no-scaled-link
|
||||
|
||||
.. versionadded:: 1.3
|
||||
|
||||
.. versionchanged:: 2.4
|
||||
|
||||
It is disabled for images having ``no-scaled-link`` class
|
||||
|
||||
.. confval:: html_math_renderer
|
||||
|
||||
The name of math_renderer extension for HTML output. The default is
|
||||
|
@ -807,13 +807,17 @@ class StandaloneHTMLBuilder(Builder):
|
||||
|
||||
if self.config.html_scaled_image_link and self.html_scaled_image_link:
|
||||
for node in doctree.traverse(nodes.image):
|
||||
scale_keys = ('scale', 'width', 'height')
|
||||
if not any((key in node) for key in scale_keys) or \
|
||||
isinstance(node.parent, nodes.reference):
|
||||
# docutils does unfortunately not preserve the
|
||||
# ``target`` attribute on images, so we need to check
|
||||
# the parent node here.
|
||||
if not any((key in node) for key in ['scale', 'width', 'height']):
|
||||
# resizing options are not given. scaled image link is available
|
||||
# only for resized images.
|
||||
continue
|
||||
elif isinstance(node.parent, nodes.reference):
|
||||
# A image having hyperlink target
|
||||
continue
|
||||
elif 'no-scaled-link' in node['classes']:
|
||||
# scaled image link is disabled for this node
|
||||
continue
|
||||
|
||||
uri = node['uri']
|
||||
reference = nodes.reference('', '', internal=True)
|
||||
if uri in self.images:
|
||||
|
0
tests/roots/test-html_scaled_image_link/conf.py
Normal file
0
tests/roots/test-html_scaled_image_link/conf.py
Normal file
BIN
tests/roots/test-html_scaled_image_link/img.png
Normal file
BIN
tests/roots/test-html_scaled_image_link/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
11
tests/roots/test-html_scaled_image_link/index.rst
Normal file
11
tests/roots/test-html_scaled_image_link/index.rst
Normal file
@ -0,0 +1,11 @@
|
||||
test-html_scaled_image_link
|
||||
===========================
|
||||
|
||||
.. image:: img.png
|
||||
|
||||
.. image:: img.png
|
||||
:scale: 50%
|
||||
|
||||
.. image:: img.png
|
||||
:scale: 50%
|
||||
:class: no-scaled-link
|
@ -1542,3 +1542,22 @@ def test_validate_html_static_path(app):
|
||||
]
|
||||
validate_html_static_path(app, app.config)
|
||||
assert app.config.html_static_path == ['_static']
|
||||
|
||||
|
||||
@pytest.mark.sphinx(testroot='html_scaled_image_link')
|
||||
def test_html_scaled_image_link(app):
|
||||
app.build()
|
||||
context = (app.outdir / 'index.html').text()
|
||||
|
||||
# no scaled parameters
|
||||
assert re.search('\n<img alt="_images/img.png" src="_images/img.png" />', context)
|
||||
|
||||
# scaled_image_link
|
||||
assert re.search('\n<a class="reference internal image-reference" href="_images/img.png">'
|
||||
'<img alt="_images/img.png" src="_images/img.png" style="[^"]+" /></a>',
|
||||
context)
|
||||
|
||||
# no-scaled-link class disables the feature
|
||||
assert re.search('\n<img alt="_images/img.png" class="no-scaled-link"'
|
||||
' src="_images/img.png" style="[^"]+" />',
|
||||
context)
|
||||
|
Loading…
Reference in New Issue
Block a user