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.
|
Pick the best candidate for all image URIs.
|
||||||
"""
|
"""
|
||||||
for node in doctree.traverse(nodes.image):
|
for node in doctree.traverse(nodes.image):
|
||||||
uri = node['candidates'].get('*', None)
|
if '*' not in node['candidates']:
|
||||||
if not uri:
|
|
||||||
for imgtype in self.supported_image_types:
|
for imgtype in self.supported_image_types:
|
||||||
uri = node['candidates'].get(imgtype, None)
|
candidate = node['candidates'].get(imgtype, None)
|
||||||
if uri:
|
if candidate:
|
||||||
node['uri'] = uri
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.warn('%s:%s: %s' %
|
self.warn('%s:%s: no matching candidate for image URI %r' %
|
||||||
(node.source, node.lineno,
|
(node.source, node.lineno, node['uri']))
|
||||||
'No matching candidate for uri: %(uri)s' % node))
|
|
||||||
continue
|
continue
|
||||||
if uri in self.env.images:
|
node['uri'] = candidate
|
||||||
self.images[uri] = self.env.images[uri][1]
|
else:
|
||||||
|
candidate = node['uri']
|
||||||
|
self.images[candidate] = self.env.images[candidate][1]
|
||||||
|
|
||||||
# build methods
|
# build methods
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ default_settings = {
|
|||||||
|
|
||||||
# This is increased every time an environment attribute is added
|
# This is increased every time an environment attribute is added
|
||||||
# or changed to properly invalidate pickle files.
|
# or changed to properly invalidate pickle files.
|
||||||
ENV_VERSION = 23
|
ENV_VERSION = 24
|
||||||
|
|
||||||
|
|
||||||
default_substitutions = set([
|
default_substitutions = set([
|
||||||
@ -535,6 +535,7 @@ class BuildEnvironment:
|
|||||||
candidates['*'] = imguri
|
candidates['*'] = imguri
|
||||||
continue
|
continue
|
||||||
imgpath = path.normpath(path.join(docdir, imguri))
|
imgpath = path.normpath(path.join(docdir, imguri))
|
||||||
|
node['uri'] = imgpath
|
||||||
if imgpath.endswith(os.extsep + '*'):
|
if imgpath.endswith(os.extsep + '*'):
|
||||||
for filename in glob(imgpath):
|
for filename in glob(imgpath):
|
||||||
basename, ext = os.path.splitext(filename)
|
basename, ext = os.path.splitext(filename)
|
||||||
@ -543,7 +544,11 @@ class BuildEnvironment:
|
|||||||
elif ext == '.svg':
|
elif ext == '.svg':
|
||||||
candidates['image/svg+xml'] = filename
|
candidates['image/svg+xml'] = filename
|
||||||
else:
|
else:
|
||||||
imgtype = imghdr.what(filename)
|
f = open(filename, 'rb')
|
||||||
|
try:
|
||||||
|
imgtype = imghdr.what(f)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
if imgtype:
|
if imgtype:
|
||||||
candidates['image/' + imgtype] = filename
|
candidates['image/' + imgtype] = filename
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user