Mercurial > hg-stable
changeset 15262:e8076af14498
minirst: add style flag to format
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 15 Oct 2011 00:39:04 -0500 |
parents | e2df5b866d22 |
children | 70d7293c41d6 |
files | mercurial/minirst.py tests/test-minirst.py tests/test-minirst.py.out |
diffstat | 3 files changed, 16 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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: