mercurial/minirst.py
changeset 15012 ee766af457ed
parent 14433 7658221da551
child 15013 4a1e3c761ec7
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