# HG changeset patch # User Martin Geisler # Date 1260744593 -3600 # Node ID a1ae0ed78d1a614709c0622dea10e5f4aecfa606 # Parent 6f30c35766d6dd69fc7f9075c2dd099d832fae67 minirst: improve layout of field lists Before, we used the padding following the key to compute where to wrap the text. Long keys would thus give a big indentation. It also required careful alignment of the source text, making it cumbersome to items to the list. We now compute the maximum key length and use that for all items in the list. We also put a cap on the indentation: keys longer than 10 characters are put on their own line. This is similar to how rst2html handles large keys: it uses 14 as the cutoff point, but I felt that 10 was better for monospaced text in the console. diff -r 6f30c35766d6 -r a1ae0ed78d1a mercurial/minirst.py --- a/mercurial/minirst.py Sun Dec 13 22:37:30 2009 +0100 +++ b/mercurial/minirst.py Sun Dec 13 23:49:53 2009 +0100 @@ -113,7 +113,7 @@ _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 @@ 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 @@ 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 -r 6f30c35766d6 -r a1ae0ed78d1a tests/test-dispatch.out --- a/tests/test-dispatch.out Sun Dec 13 22:37:30 2009 +0100 +++ b/tests/test-dispatch.out Sun Dec 13 23:49:53 2009 +0100 @@ -13,9 +13,9 @@ 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 -r 6f30c35766d6 -r a1ae0ed78d1a tests/test-minirst.py --- a/tests/test-minirst.py Sun Dec 13 22:37:30 2009 +0100 +++ b/tests/test-minirst.py Sun Dec 13 23:49:53 2009 +0100 @@ -134,13 +134,14 @@ 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 -r 6f30c35766d6 -r a1ae0ed78d1a tests/test-minirst.py.out --- a/tests/test-minirst.py.out Sun Dec 13 22:37:30 2009 +0100 +++ b/tests/test-minirst.py.out Sun Dec 13 23:49:53 2009 +0100 @@ -215,29 +215,34 @@ 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. ----------------------------------------------------------------------