minirst: add style flag to format
authorMatt Mackall <mpm@selenic.com>
Sat, 15 Oct 2011 00:39:04 -0500
changeset 15262 e8076af14498
parent 15261 e2df5b866d22
child 15263 70d7293c41d6
minirst: add style flag to format
mercurial/minirst.py
tests/test-minirst.py
tests/test-minirst.py.out
--- a/mercurial/minirst.py	Sat Oct 15 00:39:01 2011 -0500
+++ b/mercurial/minirst.py	Sat Oct 15 00:39:04 2011 -0500
@@ -608,10 +608,13 @@
     text = ''.join(formatblock(b, width) for b in blocks)
     return text
 
-def format(text, width, indent=0, keep=None):
+def format(text, width=80, indent=0, keep=None, style='plain'):
     """Parse and format the text according to width."""
     blocks, pruned = parse(text, indent, keep or [])
-    text = ''.join(formatblock(b, width) for b in blocks)
+    if style == 'html':
+        text = formathtml(blocks)
+    else:
+        text = ''.join(formatblock(b, width) for b in blocks)
     if keep is None:
         return text
     else:
--- a/tests/test-minirst.py	Sat Oct 15 00:39:01 2011 -0500
+++ b/tests/test-minirst.py	Sat Oct 15 00:39:04 2011 -0500
@@ -4,16 +4,18 @@
 def debugformat(title, text, width, **kwargs):
     print "%s formatted to fit within %d characters:" % (title, width)
     formatted = minirst.format(text, width, **kwargs)
-    html = minirst.formathtml(minirst.parse(text, **kwargs)[0])
+    html = minirst.format(text, width, style='html', **kwargs)
     print "-" * 70
     if type(formatted) == tuple:
         print formatted[0]
         print "-" * 70
+        print html
+        print "-" * 70
         pprint(formatted[1])
     else:
         print formatted
-    print "-" * 70
-    print html
+        print "-" * 70
+        print html
     print "-" * 70
     print
 
--- a/tests/test-minirst.py.out	Sat Oct 15 00:39:01 2011 -0500
+++ b/tests/test-minirst.py.out	Sat Oct 15 00:39:04 2011 -0500
@@ -615,15 +615,9 @@
 Verbose output.
 
 ----------------------------------------------------------------------
-['debug', 'debug']
+('<p>\nNormal output.\n</p>\n<p>\nVerbose output.\n</p>\n', ['debug', 'debug'])
 ----------------------------------------------------------------------
-<p>
-Normal output.
-</p>
-<p>
-Verbose output.
-</p>
-
+['debug', 'debug']
 ----------------------------------------------------------------------
 
 containers (debug) formatted to fit within 60 characters:
@@ -633,15 +627,9 @@
 Initial debug output.
 
 ----------------------------------------------------------------------
-['verbose']
+('<p>\nNormal output.\n</p>\n<p>\nInitial debug output.\n</p>\n', ['verbose'])
 ----------------------------------------------------------------------
-<p>
-Normal output.
-</p>
-<p>
-Initial debug output.
-</p>
-
+['verbose']
 ----------------------------------------------------------------------
 
 containers (verbose debug) formatted to fit within 60 characters:
@@ -655,21 +643,9 @@
 Debug output.
 
 ----------------------------------------------------------------------
-[]
+('<p>\nNormal output.\n</p>\n<p>\nInitial debug output.\n</p>\n<p>\nVerbose output.\n</p>\n<p>\nDebug output.\n</p>\n', [])
 ----------------------------------------------------------------------
-<p>
-Normal output.
-</p>
-<p>
-Initial debug output.
-</p>
-<p>
-Verbose output.
-</p>
-<p>
-Debug output.
-</p>
-
+[]
 ----------------------------------------------------------------------
 
 roles formatted to fit within 60 characters: