minirst: end all blocks with newlines
authorMatt Mackall <mpm@selenic.com>
Sat, 17 Sep 2011 14:17:09 -0500
changeset 15125 bdc595059108
parent 15124 8542a9c9f679
child 15126 d3ad0e9d4be2
minirst: end all blocks with newlines Formerly RST blocks were formatted without a trailing newline, which wasn't particularly helpful. Now everything that comes back from the formatter has a trailing newline so remove all the extra ones added by users.
mercurial/commands.py
mercurial/minirst.py
tests/test-minirst.py.out
--- a/mercurial/commands.py	Mon Sep 19 14:19:26 2011 +0200
+++ b/mercurial/commands.py	Sat Sep 17 14:17:09 2011 -0500
@@ -2782,7 +2782,7 @@
             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 @@
             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 @@
         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 @@
         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 @@
         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"))
--- a/mercurial/minirst.py	Mon Sep 19 14:19:26 2011 +0200
+++ b/mercurial/minirst.py	Sat Sep 17 14:17:09 2011 -0500
@@ -398,7 +398,7 @@
     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 @@
 
         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 @@
         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 @@
     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 @@
     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:
--- a/tests/test-minirst.py.out	Mon Sep 19 14:19:26 2011 +0200
+++ b/tests/test-minirst.py.out	Sat Sep 17 14:17:09 2011 -0500
@@ -6,6 +6,7 @@
   containing random whitespace.
 
 The third and final paragraph.
+
 ----------------------------------------------------------------------
 
 paragraphs formatted to fit within 30 characters:
@@ -19,6 +20,7 @@
   whitespace.
 
 The third and final paragraph.
+
 ----------------------------------------------------------------------
 
 definitions formatted to fit within 60 characters:
@@ -33,6 +35,7 @@
 
   A Nested/Indented Term
     Definition.
+
 ----------------------------------------------------------------------
 
 definitions formatted to fit within 30 characters:
@@ -52,6 +55,7 @@
 
   A Nested/Indented Term
     Definition.
+
 ----------------------------------------------------------------------
 
 literals formatted to fit within 60 characters:
@@ -72,6 +76,7 @@
   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 @@
   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 @@
 
 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 @@
 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 @@
 paragraph:
 
 --foo bar baz
+
 ----------------------------------------------------------------------
 
 options formatted to fit within 30 characters:
@@ -272,6 +281,7 @@
 normal paragraph:
 
 --foo bar baz
+
 ----------------------------------------------------------------------
 
 fields formatted to fit within 60 characters:
@@ -286,6 +296,7 @@
             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 @@
             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 @@
 Normal output.
 
 Verbose output.
+
 ----------------------------------------------------------------------
 ['debug', 'debug']
 ----------------------------------------------------------------------
@@ -326,6 +340,7 @@
 Normal output.
 
 Initial debug output.
+
 ----------------------------------------------------------------------
 ['verbose']
 ----------------------------------------------------------------------
@@ -339,6 +354,7 @@
 Verbose output.
 
 Debug output.
+
 ----------------------------------------------------------------------
 []
 ----------------------------------------------------------------------
@@ -346,6 +362,7 @@
 roles formatted to fit within 60 characters:
 ----------------------------------------------------------------------
 Please see "hg add".
+
 ----------------------------------------------------------------------
 
 sections formatted to fit within 20 characters:
@@ -361,6 +378,7 @@
 
 Markup: "foo" and "hg help"
 ---------------------------
+
 ----------------------------------------------------------------------
 
 admonitions formatted to fit within 30 characters:
@@ -377,6 +395,7 @@
 
 !Danger!
    This is danger
+
 ----------------------------------------------------------------------
 
 comments formatted to fit within 30 characters:
@@ -386,6 +405,7 @@
    Some indented text.
 
 Empty comment above
+
 ----------------------------------------------------------------------
 
   === === ========================================