# HG changeset patch
# User J. H. Palmieri <palmieri@math.washington.edu>
# Date 1248133056 25200
# Node ID f932bae8490843b82688bfab0d844c09f7fe8f55
# Parent  2498e448496e1b268881a09f406398d526fd759c
fix doctesting: indented double colons (trac #6572)

diff -r 2498e448496e -r f932bae84908 sage-doctest
--- a/sage-doctest	Sun Jul 19 11:41:58 2009 -0700
+++ b/sage-doctest	Mon Jul 20 16:37:36 2009 -0700
@@ -485,19 +485,22 @@
     
     def get_next_verbatim_block(s, pos):
         while True:
-            pos = s.find('\n::', pos)
+            # regular expression search in string s[pos:] for:
+            # whitespace followed by "::" at the start of a line
+            srch = re.search('^(\s*)::', s[pos:], re.M)
 
-            #Return -1 if we can't find any verbatim
-            #blocks
-            if pos == -1:
-                return "", pos, False
+            #Return -1 if we don't find anything.
+            if srch is None:
+               return "", -1, False 
+            
+            pos += srch.start()
 
             prev_line = F.rfind("\n", 0, pos)
             start_of_options = F.rfind("\n", 0, prev_line if prev_line != -1 else 0)
             options = F[start_of_options:pos]
 
-            pos += 3
-            
+            pos += (srch.end() - srch.start())
+
             #Don't return skipped blocks
             if '.. skip' in options:
                 continue
@@ -506,14 +509,18 @@
             #block
             link_previous = True if '.. link' in options else False
 
-            #Find the first line that isn't
-            #indented (i.e., not in the verbatim block)
-            match = re.compile("^\S", re.M).search(s, pos)
+            #Find the first line that isn't indented as much as
+            #whatever followed the double colon.  The whitespace before
+            #the double colon is stored in srch.groups()[0]
+            lw = len(srch.groups()[0])  # length of whitespace before ::
+            #So match anything of the form
+            # beg. of line + whitespace of length at most lw + nonwhitespace
+            no_indent = re.search("^\s{,%s}\S"%lw, s[pos:], re.M)
 
-            if match is None:
+            if no_indent is None:
                 return s[pos:], None, link_previous
 
-            block, pos = s[pos:match.start()], match.start()
+            block, pos = s[pos:pos+no_indent.start()], pos+no_indent.start()
             if re.compile('^\s*sage: ', re.M).search(block) is not None:
                 return block, pos, link_previous
 
