Commits

Georg Brandl committed 9c0a89f

Move doctest blocks out of blockquotes even if there is more than one.

  • Participants
  • Parent commits 2964c27

Comments (0)

Files changed (2)

File sphinx/environment.py

 from sphinx.util.nodes import clean_astext, make_refnode
 from sphinx.util.osutil import movefile, SEP, ustrftime
 from sphinx.util.matching import compile_matchers
+from sphinx.util.pycompat import all
 from sphinx.errors import SphinxError, ExtensionError
 from sphinx.locale import _
 
 
 class HandleCodeBlocks(Transform):
     """
-    Move doctest blocks out of blockquotes.
+    Several code block related transformations.
     """
     default_priority = 210
 
     def apply(self):
+        # move doctest blocks out of blockquotes
         for node in self.document.traverse(nodes.block_quote):
-            if len(node.children) == 1 and isinstance(node.children[0],
-                                                      nodes.doctest_block):
-                node.replace_self(node.children[0])
+            if all(isinstance(child, nodes.doctest_block) for child
+                     in node.children):
+                node.replace_self(node.children)
+        # combine successive doctest blocks
+        #for node in self.document.traverse(nodes.doctest_block):
+        #    if node not in node.parent.children:
+        #        continue
+        #    parindex = node.parent.index(node)
+        #    while len(node.parent) > parindex+1 and \
+        #            isinstance(node.parent[parindex+1], nodes.doctest_block):
+        #        node[0] = nodes.Text(node[0] + '\n\n' +
+        #                             node.parent[parindex+1][0])
+        #        del node.parent[parindex+1]
 
 
 class SortIds(Transform):

File sphinx/util/pycompat.py

 
 try:
     any = any
+    all = all
 except NameError:
+    def all(gen):
+        for i in gen:
+            if not i:
+                return False
+        return True
+
     def any(gen):
         for i in gen:
             if i: