mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix image handling.
This commit is contained in:
parent
99f8c79f0a
commit
326ca06e1b
@ -128,20 +128,19 @@ class Builder(object):
|
||||
Pick the best candidate for all image URIs.
|
||||
"""
|
||||
for node in doctree.traverse(nodes.image):
|
||||
uri = node['candidates'].get('*', None)
|
||||
if not uri:
|
||||
if '*' not in node['candidates']:
|
||||
for imgtype in self.supported_image_types:
|
||||
uri = node['candidates'].get(imgtype, None)
|
||||
if uri:
|
||||
node['uri'] = uri
|
||||
candidate = node['candidates'].get(imgtype, None)
|
||||
if candidate:
|
||||
break
|
||||
else:
|
||||
self.warn('%s:%s: %s' %
|
||||
(node.source, node.lineno,
|
||||
'No matching candidate for uri: %(uri)s' % node))
|
||||
self.warn('%s:%s: no matching candidate for image URI %r' %
|
||||
(node.source, node.lineno, node['uri']))
|
||||
continue
|
||||
if uri in self.env.images:
|
||||
self.images[uri] = self.env.images[uri][1]
|
||||
node['uri'] = candidate
|
||||
else:
|
||||
candidate = node['uri']
|
||||
self.images[candidate] = self.env.images[candidate][1]
|
||||
|
||||
# build methods
|
||||
|
||||
|
@ -63,7 +63,7 @@ default_settings = {
|
||||
|
||||
# This is increased every time an environment attribute is added
|
||||
# or changed to properly invalidate pickle files.
|
||||
ENV_VERSION = 23
|
||||
ENV_VERSION = 24
|
||||
|
||||
|
||||
default_substitutions = set([
|
||||
@ -535,6 +535,7 @@ class BuildEnvironment:
|
||||
candidates['*'] = imguri
|
||||
continue
|
||||
imgpath = path.normpath(path.join(docdir, imguri))
|
||||
node['uri'] = imgpath
|
||||
if imgpath.endswith(os.extsep + '*'):
|
||||
for filename in glob(imgpath):
|
||||
basename, ext = os.path.splitext(filename)
|
||||
@ -543,7 +544,11 @@ class BuildEnvironment:
|
||||
elif ext == '.svg':
|
||||
candidates['image/svg+xml'] = filename
|
||||
else:
|
||||
imgtype = imghdr.what(filename)
|
||||
f = open(filename, 'rb')
|
||||
try:
|
||||
imgtype = imghdr.what(f)
|
||||
finally:
|
||||
f.close()
|
||||
if imgtype:
|
||||
candidates['image/' + imgtype] = filename
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user