diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -113,7 +113,7 @@ def findliteralblocks(blocks): _bulletre = re.compile(r'(-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)) ') _optionre = re.compile(r'^(--[a-z-]+)((?:[ =][a-zA-Z][\w-]*)? +)(.*)$') -_fieldre = re.compile(r':(?![: ])([^:]*)(? _fieldwidth: + # key too large, use full line width + key = key.ljust(width) + elif keywidth + 2 < _fieldwidth: + # all keys are small, add only two spaces + key = key.ljust(keywidth + 2) + subindent = indent + (keywidth + 2) * ' ' + else: + # mixed sizes, use fieldwidth for this one + key = key.ljust(_fieldwidth) + block['lines'][0] = key + block['lines'][0] elif block['type'] == 'option': m = _optionre.match(block['lines'][0]) option, arg, rest = m.groups() @@ -252,6 +289,7 @@ def format(text, width, indent=0): blocks = findliteralblocks(blocks) 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) @@ -272,6 +310,7 @@ if __name__ == "__main__": blocks = debug(findliteralblocks, blocks) blocks = debug(inlineliterals, blocks) blocks = debug(splitparagraphs, blocks) + blocks = debug(updatefieldlists, blocks) blocks = debug(findsections, blocks) blocks = debug(addmargins, blocks) print '\n'.join(formatblock(b, 30) for b in blocks) diff --git a/tests/test-dispatch.out b/tests/test-dispatch.out --- a/tests/test-dispatch.out +++ b/tests/test-dispatch.out @@ -13,9 +13,9 @@ output the current or given revision of a format string. The formatting rules are the same as for the export command, with the following additions: - "%s" basename of file being printed - "%d" dirname of file being printed, or '.' if in repository root - "%p" root-relative path name of file being printed + "%s" basename of file being printed + "%d" dirname of file being printed, or '.' if in repository root + "%p" root-relative path name of file being printed options: diff --git a/tests/test-minirst.py b/tests/test-minirst.py --- a/tests/test-minirst.py +++ b/tests/test-minirst.py @@ -134,13 +134,14 @@ debugformat('options', options, 30) fields = """ -Field lists give a simple two-column layout: +:a: First item. +:ab: Second item. Indentation and wrapping + is handled automatically. -:key: The whitespace following the key is - significant for the wrapping of this text. -:another key: More text. - The indentation on the following - lines is not significant. +Next list: + +:small: The larger key below triggers full indentation here. +:much too large: This key is big enough to get its own line. """ debugformat('fields', fields, 60) diff --git a/tests/test-minirst.py.out b/tests/test-minirst.py.out --- a/tests/test-minirst.py.out +++ b/tests/test-minirst.py.out @@ -215,29 +215,34 @@ normal paragraph: fields formatted to fit within 60 characters: ---------------------------------------------------------------------- -Field lists give a simple two-column layout: +a First item. +ab Second item. Indentation and wrapping is handled + automatically. -key The whitespace following the key is - significant for the wrapping of this text. -another key More text. The indentation on the following - lines is not significant. +Next list: + +small The larger key below triggers full indentation + here. +much too large + This key is big enough to get its own line. ---------------------------------------------------------------------- fields formatted to fit within 30 characters: ---------------------------------------------------------------------- -Field lists give a simple two- -column layout: +a First item. +ab Second item. Indentation + and wrapping is handled + automatically. + +Next list: -key The whitespace - following the - key is - significant for - the wrapping of - this text. -another key More text. The - indentation on - the following - lines is not - significant. +small The larger key + below triggers + full indentation + here. +much too large + This key is big + enough to get its + own line. ----------------------------------------------------------------------