summaryrefslogtreecommitdiff
path: root/sphinx/directives/other.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-05-30 12:59:42 +0200
committerGeorg Brandl <georg@python.org>2010-05-30 12:59:42 +0200
commit4318d9e17f3713d6439c2431189e120ec2eb554c (patch)
tree99639c539e733cf96e176cb3d6cc7f740f999071 /sphinx/directives/other.py
parentcb36e3e37b9edb6302e36c85f3f95e9754bb786d (diff)
downloadsphinx-4318d9e17f3713d6439c2431189e120ec2eb554c.tar.gz
The ``include`` directive now supports absolute paths, which are interpreted as relative to the source directory.
Diffstat (limited to 'sphinx/directives/other.py')
-rw-r--r--sphinx/directives/other.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index 138d10c8..5ce1ce1a 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -7,6 +7,8 @@
:license: BSD, see LICENSE for details.
"""
+import os
+
from docutils import nodes
from docutils.parsers.rst import Directive, directives
@@ -367,6 +369,22 @@ class Only(Directive):
return [node]
+from docutils.parsers.rst.directives.misc import Include as BaseInclude
+
+class Include(BaseInclude):
+ """
+ Like the standard "Include" directive, but interprets absolute paths
+ correctly.
+ """
+
+ def run(self):
+ if self.arguments[0].startswith('/') or \
+ self.arguments[0].startswith(os.sep):
+ env = self.state.document.settings.env
+ self.arguments[0] = os.path.join(env.srcdir, self.arguments[0][1:])
+ return BaseInclude.run(self)
+
+
directives.register_directive('toctree', TocTree)
directives.register_directive('sectionauthor', Author)
directives.register_directive('moduleauthor', Author)
@@ -381,6 +399,7 @@ directives.register_directive('centered', Centered)
directives.register_directive('acks', Acks)
directives.register_directive('hlist', HList)
directives.register_directive('only', Only)
+directives.register_directive('include', Include)
# register the standard rst class directive under a different name
from docutils.parsers.rst.directives.misc import Class