diff --git a/CHANGES b/CHANGES index 12f0384c8..593433f92 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ 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 a bug in autodoc when documenting classes with the option. diff --git a/sphinx/environment.py b/sphinx/environment.py index c03da1100..826fe8faa 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -625,15 +625,17 @@ class BuildEnvironment: self.warn(docname, 'Nonlocal image URI found: %s' % imguri, node.line) candidates['?'] = imguri continue + # imgpath is the image path *from srcdir* imgpath = path.normpath(path.join(docdir, imguri)) + # set imgpath as default URI node['uri'] = imgpath if imgpath.endswith(os.extsep + '*'): 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'): - candidates['application/pdf'] = path.join(docdir, relname) + candidates['application/pdf'] = new_imgpath elif filename.lower().endswith('.svg'): - candidates['image/svg+xml'] = path.join(docdir, relname) + candidates['image/svg+xml'] = new_imgpath else: try: f = open(filename, 'rb') @@ -644,9 +646,11 @@ class BuildEnvironment: except (OSError, IOError): self.warn(docname, 'Image file %s not readable' % filename) if imgtype: - candidates['image/' + imgtype] = path.join(docdir, relname) + candidates['image/' + imgtype] = new_imgpath else: candidates['*'] = imgpath + # map image paths to unique image names (so that they can be put + # into a single directory) for imgpath in candidates.itervalues(): self.dependencies.setdefault(docname, set()).add(imgpath) if not os.access(path.join(self.srcdir, imgpath), os.R_OK): diff --git a/tests/root/contents.txt b/tests/root/contents.txt index e8e6a5644..61646f622 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -11,6 +11,7 @@ Contents: :maxdepth: 2 images + subdir/images includes markup desc diff --git a/tests/root/subdir/images.txt b/tests/root/subdir/images.txt new file mode 100644 index 000000000..33adf5b56 --- /dev/null +++ b/tests/root/subdir/images.txt @@ -0,0 +1,4 @@ +Image including source in subdir +================================ + +.. image:: img.* diff --git a/tests/test_build.py b/tests/test_build.py index 938d3c985..bde843b44 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -51,6 +51,9 @@ HTML_XPATH = { ".//img[@src='_images/img1.png']": '', ".//img[@src='_images/simg.png']": '', }, + 'subdir/images.html': { + ".//img[@src='../_images/img1.png']": '', + }, 'includes.html': { ".//pre/span[@class='s']": u'üöä', ".//pre": u'Max Strauß',