diff --git a/docs/sphinxext/mantiddoc/directives/base.py b/docs/sphinxext/mantiddoc/directives/base.py
index 135186d2d9bbb6c385413ae7d392b0027cbc0a52..ce943c66bff8ea569f188e2c0484785f9bc83203 100644
--- a/docs/sphinxext/mantiddoc/directives/base.py
+++ b/docs/sphinxext/mantiddoc/directives/base.py
@@ -73,9 +73,15 @@ class BaseDirective(Directive):
         """
         Inserts the currently tracked rst lines into the state_machine
         """
-        self.state_machine.insert_input(self.rst_lines, "")
+        self.state_machine.insert_input(self.rst_lines, self.source())
         self.rst_lines = []
 
+    def source(self):
+        """
+        Returns the full path to the source document
+        """
+        return self.state.document.settings.env.docname
+
     def make_header(self, name, pagetitle=False):
         """
         Makes a ReStructuredText title from the algorithm's name.
@@ -207,5 +213,4 @@ class AlgorithmBaseDirective(BaseDirective):
         document. The expected name of the document is "AlgorithmName-v?", which
         is the name of the file with the extension removed
         """
-        env = self.state.document.settings.env
-        (self.algm_name, self.algm_version) = algorithm_name_and_version(env.docname)
+        (self.algm_name, self.algm_version) = algorithm_name_and_version(self.source())