mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #60: "smart" image inclusion in subdirs.
This commit is contained in:
parent
02123d6650
commit
83dba8fc76
2
CHANGES
2
CHANGES
@ -1,6 +1,8 @@
|
|||||||
Release 0.5.1 (in development)
|
Release 0.5.1 (in development)
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
* Fix a bug when including images in sources in subdirectories.
|
||||||
|
|
||||||
* Fix the JavaScript search when html_copy_source is off.
|
* Fix the JavaScript search when html_copy_source is off.
|
||||||
|
|
||||||
* Fix a bug in autodoc when documenting classes with the option.
|
* Fix a bug in autodoc when documenting classes with the option.
|
||||||
|
@ -625,15 +625,17 @@ class BuildEnvironment:
|
|||||||
self.warn(docname, 'Nonlocal image URI found: %s' % imguri, node.line)
|
self.warn(docname, 'Nonlocal image URI found: %s' % imguri, node.line)
|
||||||
candidates['?'] = imguri
|
candidates['?'] = imguri
|
||||||
continue
|
continue
|
||||||
|
# imgpath is the image path *from srcdir*
|
||||||
imgpath = path.normpath(path.join(docdir, imguri))
|
imgpath = path.normpath(path.join(docdir, imguri))
|
||||||
|
# set imgpath as default URI
|
||||||
node['uri'] = imgpath
|
node['uri'] = imgpath
|
||||||
if imgpath.endswith(os.extsep + '*'):
|
if imgpath.endswith(os.extsep + '*'):
|
||||||
for filename in glob(path.join(self.srcdir, imgpath)):
|
for filename in glob(path.join(self.srcdir, imgpath)):
|
||||||
relname = relative_path(self.srcdir, filename)
|
new_imgpath = relative_path(self.srcdir, filename)
|
||||||
if filename.lower().endswith('.pdf'):
|
if filename.lower().endswith('.pdf'):
|
||||||
candidates['application/pdf'] = path.join(docdir, relname)
|
candidates['application/pdf'] = new_imgpath
|
||||||
elif filename.lower().endswith('.svg'):
|
elif filename.lower().endswith('.svg'):
|
||||||
candidates['image/svg+xml'] = path.join(docdir, relname)
|
candidates['image/svg+xml'] = new_imgpath
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
f = open(filename, 'rb')
|
f = open(filename, 'rb')
|
||||||
@ -644,9 +646,11 @@ class BuildEnvironment:
|
|||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
self.warn(docname, 'Image file %s not readable' % filename)
|
self.warn(docname, 'Image file %s not readable' % filename)
|
||||||
if imgtype:
|
if imgtype:
|
||||||
candidates['image/' + imgtype] = path.join(docdir, relname)
|
candidates['image/' + imgtype] = new_imgpath
|
||||||
else:
|
else:
|
||||||
candidates['*'] = imgpath
|
candidates['*'] = imgpath
|
||||||
|
# map image paths to unique image names (so that they can be put
|
||||||
|
# into a single directory)
|
||||||
for imgpath in candidates.itervalues():
|
for imgpath in candidates.itervalues():
|
||||||
self.dependencies.setdefault(docname, set()).add(imgpath)
|
self.dependencies.setdefault(docname, set()).add(imgpath)
|
||||||
if not os.access(path.join(self.srcdir, imgpath), os.R_OK):
|
if not os.access(path.join(self.srcdir, imgpath), os.R_OK):
|
||||||
|
@ -11,6 +11,7 @@ Contents:
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
images
|
images
|
||||||
|
subdir/images
|
||||||
includes
|
includes
|
||||||
markup
|
markup
|
||||||
desc
|
desc
|
||||||
|
4
tests/root/subdir/images.txt
Normal file
4
tests/root/subdir/images.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Image including source in subdir
|
||||||
|
================================
|
||||||
|
|
||||||
|
.. image:: img.*
|
@ -51,6 +51,9 @@ HTML_XPATH = {
|
|||||||
".//img[@src='_images/img1.png']": '',
|
".//img[@src='_images/img1.png']": '',
|
||||||
".//img[@src='_images/simg.png']": '',
|
".//img[@src='_images/simg.png']": '',
|
||||||
},
|
},
|
||||||
|
'subdir/images.html': {
|
||||||
|
".//img[@src='../_images/img1.png']": '',
|
||||||
|
},
|
||||||
'includes.html': {
|
'includes.html': {
|
||||||
".//pre/span[@class='s']": u'üöä',
|
".//pre/span[@class='s']": u'üöä',
|
||||||
".//pre": u'Max Strauß',
|
".//pre": u'Max Strauß',
|
||||||
|
Loading…
Reference in New Issue
Block a user