Mercurial > hg-stable
changeset 15012:ee766af457ed
minirst: add parse method to get document structure
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Tue, 02 Aug 2011 14:54:38 -0500 |
parents | 5e44e4b3a0a3 |
children | 4a1e3c761ec7 |
files | mercurial/minirst.py |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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