diff --git a/CHANGES b/CHANGES index d0ff30d50..bdb141f07 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,9 @@ New features added the directive -- this allows you to define your document structure, but place the links yourself. + - Image paths can now be absolute (like ``/images/foo.png``). + They are treated as relative to the top source directory. + - #52: There is now a ``hlist`` directive, creating a compact list by placing distributing items into multiple columns. @@ -49,8 +52,8 @@ New features added - #23: Added a ``classmethod`` directive along with ``method`` and ``staticmethod``. - - Added a ``toctree`` variable to the templates, and the ability to - include external links in toctrees. + - Added a ``toctree`` callable to the templates, and the ability + to include external links in toctrees. * Configuration: diff --git a/sphinx/environment.py b/sphinx/environment.py index 36009f80a..d49356d1e 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -647,7 +647,11 @@ class BuildEnvironment: candidates['?'] = imguri continue # imgpath is the image path *from srcdir* - imgpath = path.normpath(path.join(docdir, imguri)) + if imguri.startswith('/') or imguri.startswith(os.sep): + # absolute path (= relative to srcdir) + imgpath = path.normpath(imguri[1:]) + else: + imgpath = path.normpath(path.join(docdir, imguri)) # set imgpath as default URI node['uri'] = imgpath if imgpath.endswith(os.extsep + '*'): diff --git a/tests/root/subdir/images.txt b/tests/root/subdir/images.txt index 33adf5b56..f2adf88d3 100644 --- a/tests/root/subdir/images.txt +++ b/tests/root/subdir/images.txt @@ -2,3 +2,5 @@ Image including source in subdir ================================ .. image:: img.* + +.. image:: /rimg.png diff --git a/tests/test_build.py b/tests/test_build.py index 9c8698c45..6e8c5c245 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -61,6 +61,7 @@ HTML_XPATH = { }, 'subdir/images.html': { ".//img[@src='../_images/img1.png']": '', + ".//img[@src='../_images/rimg.png']": '', }, 'includes.html': { ".//pre": u'Max Strauß',