minirst: add parse method to get document structure
authorMatt Mackall <mpm@selenic.com>
Tue, 02 Aug 2011 14:54:38 -0500
changeset 15012 ee766af457ed
parent 15011 5e44e4b3a0a3
child 15013 4a1e3c761ec7
minirst: add parse method to get document structure
mercurial/minirst.py
--- a/mercurial/minirst.py	Tue Aug 02 13:18:56 2011 +0200
+++ b/mercurial/minirst.py	Tue Aug 02 14:54:38 2011 -0500
@@ -433,9 +433,9 @@
                      initindent=indent,
                      hangindent=subindent)
 
-
-def format(text, width, indent=0, keep=None):
-    """Parse and format the text according to width."""
+def parse(text, indent=0, keep=None):
+    """Parse text into a list of blocks"""
+    pruned = []
     blocks = findblocks(text)
     for b in blocks:
         b['indent'] += indent
@@ -450,6 +450,11 @@
     blocks = addmargins(blocks)
     blocks = prunecomments(blocks)
     blocks = findadmonitions(blocks)
+    return blocks, pruned
+
+def format(text, width, indent=0, keep=None):
+    """Parse and format the text according to width."""
+    blocks, pruned = parse(text, indent, keep or [])
     text = '\n'.join(formatblock(b, width) for b in blocks)
     if keep is None:
         return text