Mercurial > hg
comparison mercurial/minirst.py @ 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 | 7658221da551 |
children | 4a1e3c761ec7 |
comparison
equal
deleted
inserted
replaced
15011:5e44e4b3a0a3 | 15012:ee766af457ed |
---|---|
431 text = ' '.join(map(str.strip, block['lines'])) | 431 text = ' '.join(map(str.strip, block['lines'])) |
432 return util.wrap(text, width=width, | 432 return util.wrap(text, width=width, |
433 initindent=indent, | 433 initindent=indent, |
434 hangindent=subindent) | 434 hangindent=subindent) |
435 | 435 |
436 | 436 def parse(text, indent=0, keep=None): |
437 def format(text, width, indent=0, keep=None): | 437 """Parse text into a list of blocks""" |
438 """Parse and format the text according to width.""" | 438 pruned = [] |
439 blocks = findblocks(text) | 439 blocks = findblocks(text) |
440 for b in blocks: | 440 for b in blocks: |
441 b['indent'] += indent | 441 b['indent'] += indent |
442 blocks = findliteralblocks(blocks) | 442 blocks = findliteralblocks(blocks) |
443 blocks, pruned = prunecontainers(blocks, keep or []) | 443 blocks, pruned = prunecontainers(blocks, keep or []) |
448 blocks = updatefieldlists(blocks) | 448 blocks = updatefieldlists(blocks) |
449 blocks = updateoptionlists(blocks) | 449 blocks = updateoptionlists(blocks) |
450 blocks = addmargins(blocks) | 450 blocks = addmargins(blocks) |
451 blocks = prunecomments(blocks) | 451 blocks = prunecomments(blocks) |
452 blocks = findadmonitions(blocks) | 452 blocks = findadmonitions(blocks) |
453 return blocks, pruned | |
454 | |
455 def format(text, width, indent=0, keep=None): | |
456 """Parse and format the text according to width.""" | |
457 blocks, pruned = parse(text, indent, keep or []) | |
453 text = '\n'.join(formatblock(b, width) for b in blocks) | 458 text = '\n'.join(formatblock(b, width) for b in blocks) |
454 if keep is None: | 459 if keep is None: |
455 return text | 460 return text |
456 else: | 461 else: |
457 return text, pruned | 462 return text, pruned |