summaryrefslogtreecommitdiff
path: root/sphinx/writers/html5.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-01-08 01:37:53 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-01-08 01:37:53 +0900
commitaf2a3c0ddeb2f81c8f685e4d266adefc749a2642 (patch)
treef4b5f634fcc3e2315bf5eedaceed11a16ba0ff14 /sphinx/writers/html5.py
parent92a204284b98510b3bfdd2a6391e9855c564a6a0 (diff)
parent8e1cbd24c61934df7eb426aad0dc48830789b096 (diff)
downloadsphinx-git-af2a3c0ddeb2f81c8f685e4d266adefc749a2642.tar.gz
Merge branch '2.0'
Diffstat (limited to 'sphinx/writers/html5.py')
-rw-r--r--sphinx/writers/html5.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/sphinx/writers/html5.py b/sphinx/writers/html5.py
index 4d6089718..b8adb7ea3 100644
--- a/sphinx/writers/html5.py
+++ b/sphinx/writers/html5.py
@@ -519,6 +519,21 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
node['uri'] = posixpath.join(self.builder.imgpath,
self.builder.images[olduri])
+ if 'scale' in node:
+ # Try to figure out image height and width. Docutils does that too,
+ # but it tries the final file name, which does not necessarily exist
+ # yet at the time the HTML file is written.
+ if not ('width' in node and 'height' in node):
+ size = get_image_size(os.path.join(self.builder.srcdir, olduri))
+ if size is None:
+ logger.warning(__('Could not obtain image size. :scale: option is ignored.'), # NOQA
+ location=node)
+ else:
+ if 'width' not in node:
+ node['width'] = str(size[0])
+ if 'height' not in node:
+ node['height'] = str(size[1])
+
uri = node['uri']
if uri.lower().endswith(('svg', 'svgz')):
atts = {'src': uri}
@@ -526,6 +541,12 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
atts['width'] = node['width']
if 'height' in node:
atts['height'] = node['height']
+ if 'scale' in node:
+ scale = node['scale'] / 100.0
+ if 'width' in atts:
+ atts['width'] = int(atts['width']) * scale
+ if 'height' in atts:
+ atts['height'] = int(atts['height']) * scale
atts['alt'] = node.get('alt', uri)
if 'align' in node:
self.body.append('<div align="%s" class="align-%s">' %
@@ -536,20 +557,6 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
self.body.append(self.emptytag(node, 'img', '', **atts))
return
- if 'scale' in node:
- # Try to figure out image height and width. Docutils does that too,
- # but it tries the final file name, which does not necessarily exist
- # yet at the time the HTML file is written.
- if not ('width' in node and 'height' in node):
- size = get_image_size(os.path.join(self.builder.srcdir, olduri))
- if size is None:
- logger.warning(__('Could not obtain image size. :scale: option is ignored.'), # NOQA
- location=node)
- else:
- if 'width' not in node:
- node['width'] = str(size[0])
- if 'height' not in node:
- node['height'] = str(size[1])
super().visit_image(node)
# overwritten