minirst: small code cleanup
authorMartin Geisler <mg@lazybytes.net>
Fri, 08 Oct 2010 22:42:32 +0200
changeset 12620 9a9312e84e4e
parent 12619 7178f6fedb9d
child 12621 9a2de8dae27b
minirst: small code cleanup
mercurial/minirst.py
--- a/mercurial/minirst.py	Fri Oct 08 14:02:23 2010 -0500
+++ b/mercurial/minirst.py	Fri Oct 08 22:42:32 2010 +0200
@@ -296,28 +296,25 @@
             i += 2
     return blocks
 
+_admonitionre = re.compile(r"\.\. (admonition|attention|caution|danger|"
+                           r"error|hint|important|note|tip|warning)::",
+                           flags=re.IGNORECASE)
+
 def findadmonitions(blocks):
     """
     Makes the type of the block an admonition block if
     the first line is an admonition directive
     """
-
     i = 0
-
-    pattern = (r"\.\. (admonition|attention|caution|danger|error|hint|"
-               r"important|note|tip|warning)::")
-
-    prog = re.compile(pattern, flags=re.IGNORECASE)
     while i < len(blocks):
-        m = prog.match(blocks[i]['lines'][0])
+        m = _admonitionre.match(blocks[i]['lines'][0])
         if m:
             blocks[i]['type'] = 'admonition'
             admonitiontitle = blocks[i]['lines'][0][3:m.end() - 2].lower()
 
             firstline = blocks[i]['lines'][0][m.end() + 1:]
-            if firstline != '':
-                blocks[i]['lines'].insert(1, '   ' + firstline + '')
-
+            if firstline:
+                blocks[i]['lines'].insert(1, '   ' + firstline)
 
             blocks[i]['admonitiontitle'] = admonitiontitle
             del blocks[i]['lines'][0]