diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2782,7 +2782,7 @@ def help_(ui, name=None, unknowncmd=Fals doc = doc.splitlines()[0] keep = ui.verbose and ['verbose'] or [] formatted, pruned = minirst.format(doc, textwidth, keep=keep) - ui.write("\n%s\n" % formatted) + ui.write("\n%s" % formatted) if pruned: ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name) @@ -2862,7 +2862,7 @@ def help_(ui, name=None, unknowncmd=Fals doc = doc() ui.write("%s\n\n" % header) - ui.write("%s\n" % minirst.format(doc, textwidth, indent=4)) + ui.write("%s" % minirst.format(doc, textwidth, indent=4)) try: cmdutil.findcmd(name, table) ui.write(_('\nuse "hg help -c %s" to see help for ' @@ -2887,7 +2887,7 @@ def help_(ui, name=None, unknowncmd=Fals ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) if tail: ui.write(minirst.format(tail, textwidth)) - ui.status('\n\n') + ui.status('\n') if mod: try: @@ -2907,7 +2907,7 @@ def help_(ui, name=None, unknowncmd=Fals msg = help.listexts(_("'%s' is provided by the following " "extension:") % cmd, {ext: doc}, indent=4) ui.write(minirst.format(msg, textwidth)) - ui.write('\n\n') + ui.write('\n') ui.write(_('use "hg help extensions" for information on enabling ' 'extensions\n')) @@ -2946,7 +2946,7 @@ def help_(ui, name=None, unknowncmd=Fals if name != 'shortlist': text = help.listexts(_('enabled extensions:'), extensions.enabled()) if text: - ui.write("\n%s\n" % minirst.format(text, textwidth)) + ui.write("\n%s" % minirst.format(text, textwidth)) if not name: ui.write(_("\nadditional help topics:\n\n")) diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -398,7 +398,7 @@ def formatoption(block, width): hanging = block['optstrwidth'] initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth))) hangindent = ' ' * (encoding.colwidth(initindent) + 1) - return ' %s' % (util.wrap(desc, usablewidth, + return ' %s\n' % (util.wrap(desc, usablewidth, initindent=initindent, hangindent=hangindent)) @@ -413,17 +413,18 @@ def formatblock(block, width): defindent = indent + hang * ' ' text = ' '.join(map(str.strip, block['lines'])) - return '%s\n%s' % (indent + admonition, util.wrap(text, width=width, - initindent=defindent, - hangindent=defindent)) + return '%s\n%s\n' % (indent + admonition, + util.wrap(text, width=width, + initindent=defindent, + hangindent=defindent)) if block['type'] == 'margin': - return '' + return '\n' if block['type'] == 'literal': indent += ' ' - return indent + ('\n' + indent).join(block['lines']) + return indent + ('\n' + indent).join(block['lines']) + '\n' if block['type'] == 'section': underline = encoding.colwidth(block['lines'][0]) * block['underline'] - return "%s%s\n%s%s" % (indent, block['lines'][0],indent, underline) + return "%s%s\n%s%s\n" % (indent, block['lines'][0],indent, underline) if block['type'] == 'table': table = block['table'] # compute column widths @@ -447,9 +448,9 @@ def formatblock(block, width): hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip()) defindent = indent + hang * ' ' text = ' '.join(map(str.strip, block['lines'][1:])) - return '%s\n%s' % (term, util.wrap(text, width=width, - initindent=defindent, - hangindent=defindent)) + return '%s\n%s\n' % (term, util.wrap(text, width=width, + initindent=defindent, + hangindent=defindent)) subindent = indent if block['type'] == 'bullet': if block['lines'][0].startswith('| '): @@ -481,7 +482,7 @@ def formatblock(block, width): text = ' '.join(map(str.strip, block['lines'])) return util.wrap(text, width=width, initindent=indent, - hangindent=subindent) + hangindent=subindent) + '\n' def parse(text, indent=0, keep=None): """Parse text into a list of blocks""" @@ -504,13 +505,13 @@ def parse(text, indent=0, keep=None): return blocks, pruned def formatblocks(blocks, width): - text = '\n'.join(formatblock(b, width) for b in blocks) + text = ''.join(formatblock(b, width) for b in blocks) return text 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) + text = ''.join(formatblock(b, width) for b in blocks) if keep is None: return text else: 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 @@ -6,6 +6,7 @@ This is some text in the first paragraph containing random whitespace. The third and final paragraph. + ---------------------------------------------------------------------- paragraphs formatted to fit within 30 characters: @@ -19,6 +20,7 @@ paragraph. whitespace. The third and final paragraph. + ---------------------------------------------------------------------- definitions formatted to fit within 60 characters: @@ -33,6 +35,7 @@ Another Term A Nested/Indented Term Definition. + ---------------------------------------------------------------------- definitions formatted to fit within 30 characters: @@ -52,6 +55,7 @@ Another Term A Nested/Indented Term Definition. + ---------------------------------------------------------------------- literals formatted to fit within 60 characters: @@ -72,6 +76,7 @@ space-double-colon. This literal block is started with '::', the so-called expanded form. The paragraph with '::' disappears in the final output. + ---------------------------------------------------------------------- literals formatted to fit within 30 characters: @@ -94,6 +99,7 @@ with space-double-colon. This literal block is started with '::', the so-called expanded form. The paragraph with '::' disappears in the final output. + ---------------------------------------------------------------------- lists formatted to fit within 60 characters: @@ -129,6 +135,7 @@ Line blocks are also a form of list: This is the first line. The line continues here. This is the second line. + ---------------------------------------------------------------------- lists formatted to fit within 30 characters: @@ -173,6 +180,7 @@ list: This is the first line. The line continues here. This is the second line. + ---------------------------------------------------------------------- options formatted to fit within 60 characters: @@ -200,6 +208,7 @@ two-space marker after the option. It is paragraph: --foo bar baz + ---------------------------------------------------------------------- options formatted to fit within 30 characters: @@ -272,6 +281,7 @@ option. It is treated as a normal paragraph: --foo bar baz + ---------------------------------------------------------------------- fields formatted to fit within 60 characters: @@ -286,6 +296,7 @@ small The larger key below trigger here. much too large This key is big enough to get its own line. + ---------------------------------------------------------------------- fields formatted to fit within 30 characters: @@ -305,11 +316,13 @@ much too large This key is big enough to get its own line. + ---------------------------------------------------------------------- containers (normal) formatted to fit within 60 characters: ---------------------------------------------------------------------- Normal output. + ---------------------------------------------------------------------- containers (verbose) formatted to fit within 60 characters: @@ -317,6 +330,7 @@ containers (verbose) formatted to fit wi Normal output. Verbose output. + ---------------------------------------------------------------------- ['debug', 'debug'] ---------------------------------------------------------------------- @@ -326,6 +340,7 @@ containers (debug) formatted to fit with Normal output. Initial debug output. + ---------------------------------------------------------------------- ['verbose'] ---------------------------------------------------------------------- @@ -339,6 +354,7 @@ Initial debug output. Verbose output. Debug output. + ---------------------------------------------------------------------- [] ---------------------------------------------------------------------- @@ -346,6 +362,7 @@ Debug output. roles formatted to fit within 60 characters: ---------------------------------------------------------------------- Please see "hg add". + ---------------------------------------------------------------------- sections formatted to fit within 20 characters: @@ -361,6 +378,7 @@ Subsection Markup: "foo" and "hg help" --------------------------- + ---------------------------------------------------------------------- admonitions formatted to fit within 30 characters: @@ -377,6 +395,7 @@ Note: !Danger! This is danger + ---------------------------------------------------------------------- comments formatted to fit within 30 characters: @@ -386,6 +405,7 @@ Some text. Some indented text. Empty comment above + ---------------------------------------------------------------------- === === ========================================