# HG changeset patch # User Martin Geisler # Date 2010-10-23 15:30:08 # Node ID 5082e2f3f8e02d73ca05b6ab989c49d5be73f50f # Parent 019b8e1e0402a754151dd6e7a96ee72dbfc0c515 minirst: ignore comments diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -292,6 +292,17 @@ def addmargins(blocks): i += 2 return blocks +def prunecomments(blocks): + """Remove comments.""" + i = 0 + while i < len(blocks): + b = blocks[i] + if b['type'] == 'paragraph' and b['lines'][0].startswith('.. '): + del blocks[i] + else: + i += 1 + return blocks + _admonitionre = re.compile(r"\.\. (admonition|attention|caution|danger|" r"error|hint|important|note|tip|warning)::", flags=re.IGNORECASE) @@ -405,6 +416,7 @@ def format(text, width, indent=0, keep=N blocks = hgrole(blocks) blocks = splitparagraphs(blocks) blocks = updatefieldlists(blocks) + blocks = prunecomments(blocks) blocks = addmargins(blocks) blocks = findadmonitions(blocks) text = '\n'.join(formatblock(b, width) for b in blocks) @@ -432,6 +444,7 @@ if __name__ == "__main__": blocks = debug(splitparagraphs, blocks) blocks = debug(updatefieldlists, blocks) blocks = debug(findsections, blocks) + blocks = debug(prunecomments, blocks) blocks = debug(addmargins, blocks) blocks = debug(findadmonitions, blocks) print '\n'.join(formatblock(b, 30) for b in blocks) diff --git a/tests/test-minirst.py b/tests/test-minirst.py --- a/tests/test-minirst.py +++ b/tests/test-minirst.py @@ -214,3 +214,15 @@ admonitions = """ """ debugformat('admonitions', admonitions, 30) + +comments = """ +Some text. + +.. A comment + + .. An indented comment + + Some indented text. +""" + +debugformat('comments', comments, 30) 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 @@ -334,3 +334,10 @@ Note: This is danger ---------------------------------------------------------------------- +comments formatted to fit within 30 characters: +---------------------------------------------------------------------- +Some text. + + Some indented text. +---------------------------------------------------------------------- +