minirst: report pruned container types
authorMartin Geisler <mg@lazybytes.net>
Sat, 13 Feb 2010 18:11:08 +0100
changeset 10444 e99e0e077bc4
parent 10443 62d484a81dfe
child 10445 8b45102934e2
minirst: report pruned container types
mercurial/minirst.py
tests/test-minirst.py
tests/test-minirst.py.out
--- a/mercurial/minirst.py	Sun Oct 04 22:03:41 2009 +0200
+++ b/mercurial/minirst.py	Sat Feb 13 18:11:08 2010 +0100
@@ -192,6 +192,7 @@
     The blocks must have a 'type' field, i.e., they should have been
     run through findliteralblocks first.
     """
+    pruned = []
     i = 0
     while i + 1 < len(blocks):
         # Searching for a block that looks like this:
@@ -207,6 +208,8 @@
             adjustment = blocks[i + 1]['indent'] - indent
             containertype = blocks[i]['lines'][0][15:]
             prune = containertype not in keep
+            if prune:
+                pruned.append(containertype)
 
             # Always delete "..container:: type" block
             del blocks[i]
@@ -219,7 +222,7 @@
                     blocks[j]['indent'] -= adjustment
                     j += 1
         i += 1
-    return blocks
+    return blocks, pruned
 
 
 def findsections(blocks):
@@ -317,19 +320,23 @@
                          subsequent_indent=subindent)
 
 
-def format(text, width, indent=0, keep=[]):
+def format(text, width, indent=0, keep=None):
     """Parse and format the text according to width."""
     blocks = findblocks(text)
     for b in blocks:
         b['indent'] += indent
     blocks = findliteralblocks(blocks)
-    blocks = prunecontainers(blocks, keep)
+    blocks, pruned = prunecontainers(blocks, keep or [])
     blocks = inlineliterals(blocks)
     blocks = splitparagraphs(blocks)
     blocks = updatefieldlists(blocks)
     blocks = findsections(blocks)
     blocks = addmargins(blocks)
-    return '\n'.join(formatblock(b, width) for b in blocks)
+    text = '\n'.join(formatblock(b, width) for b in blocks)
+    if keep is None:
+        return text
+    else:
+        return text, pruned
 
 
 if __name__ == "__main__":
--- a/tests/test-minirst.py	Sun Oct 04 22:03:41 2009 +0200
+++ b/tests/test-minirst.py	Sat Feb 13 18:11:08 2010 +0100
@@ -1,11 +1,18 @@
 #!/usr/bin/env python
 
+from pprint import pprint
 from mercurial import minirst
 
 def debugformat(title, text, width, **kwargs):
     print "%s formatted to fit within %d characters:" % (title, width)
     print "-" * 70
-    print minirst.format(text, width, **kwargs)
+    formatted = minirst.format(text, width, **kwargs)
+    if type(formatted) == tuple:
+        print formatted[0]
+        print "-" * 70
+        pprint(formatted[1])
+    else:
+        print formatted
     print "-" * 70
     print
 
--- a/tests/test-minirst.py.out	Sun Oct 04 22:03:41 2009 +0200
+++ b/tests/test-minirst.py.out	Sat Feb 13 18:11:08 2010 +0100
@@ -257,6 +257,8 @@
 
 Verbose output.
 ----------------------------------------------------------------------
+['debug', 'debug']
+----------------------------------------------------------------------
 
 containers (debug) formatted to fit within 60 characters:
 ----------------------------------------------------------------------
@@ -264,6 +266,8 @@
 
 Initial debug output.
 ----------------------------------------------------------------------
+['verbose']
+----------------------------------------------------------------------
 
 containers (verbose debug) formatted to fit within 60 characters:
 ----------------------------------------------------------------------
@@ -275,4 +279,6 @@
 
 Debug output.
 ----------------------------------------------------------------------
+[]
+----------------------------------------------------------------------