minirst: make format() simply return a formatted text
authorYuya Nishihara <yuya@tcha.org>
Sun, 05 Aug 2018 12:11:19 +0900
changeset 39310 a2a5d4ad5276
parent 39309 0a766cb1092a
child 39311 57f9b3d91abc
minirst: make format() simply return a formatted text It's a source of bugs to change the type of the return value conditionally.
mercurial/minirst.py
mercurial/templatefuncs.py
tests/test-minirst.py
--- a/mercurial/minirst.py	Sun Aug 05 12:20:43 2018 +0900
+++ b/mercurial/minirst.py	Sun Aug 05 12:11:19 2018 +0900
@@ -673,13 +673,9 @@
     if section:
         blocks = filtersections(blocks, section)
     if style == 'html':
-        text = formathtml(blocks)
+        return formathtml(blocks)
     else:
-        text = formatplain(blocks, width=width)
-    if keep is None:
-        return text
-    else:
-        return text, pruned
+        return formatplain(blocks, width=width)
 
 def filtersections(blocks, section):
     """Select parsed blocks under the specified section"""
--- a/mercurial/templatefuncs.py	Sun Aug 05 12:20:43 2018 +0900
+++ b/mercurial/templatefuncs.py	Sun Aug 05 12:11:19 2018 +0900
@@ -575,7 +575,7 @@
     text = evalstring(context, mapping, args[0])
     style = evalstring(context, mapping, args[1])
 
-    return minirst.format(text, style=style, keep=['verbose'])[0]
+    return minirst.format(text, style=style, keep=['verbose'])
 
 @templatefunc('separate(sep, args...)', argspec='sep *args')
 def separate(context, mapping, args):
--- a/tests/test-minirst.py	Sun Aug 05 12:20:43 2018 +0900
+++ b/tests/test-minirst.py	Sun Aug 05 12:11:19 2018 +0900
@@ -7,6 +7,7 @@
 )
 
 def debugformat(text, form, **kwargs):
+    blocks, pruned = minirst.parse(text, **kwargs)
     if form == b'html':
         print("html format:")
         out = minirst.format(text, style=form, **kwargs)
@@ -15,12 +16,10 @@
         out = minirst.format(text, width=form, **kwargs)
 
     print("-" * 70)
-    if type(out) == tuple:
-        print(out[0][:-1].decode('utf8'))
+    print(out[:-1].decode('utf8'))
+    if kwargs.get('keep'):
         print("-" * 70)
-        print(stringutil.pprint(out[1]).decode('utf8'))
-    else:
-        print(out[:-1].decode('utf8'))
+        print(stringutil.pprint(pruned).decode('utf8'))
     print("-" * 70)
     print()