minirst: support all recommended title adornments
authorMartin Geisler <mg@lazybytes.net>
Sun, 25 Apr 2010 18:19:54 +0200
changeset 10984 68b7d2d668ce
parent 10983 287a5cdf7743
child 10988 f2340d699e79
minirst: support all recommended title adornments
mercurial/minirst.py
tests/test-minirst.py
tests/test-minirst.py.out
--- a/mercurial/minirst.py	Sun Apr 25 17:48:26 2010 +0200
+++ b/mercurial/minirst.py	Sun Apr 25 18:19:54 2010 +0200
@@ -225,6 +225,8 @@
     return blocks, pruned
 
 
+_sectionre = re.compile(r"""^([-=`:.'"~^_*+#])\1+$""")
+
 def findsections(blocks):
     """Finds sections.
 
@@ -240,7 +242,8 @@
         # +------------------------------+
         if (block['type'] == 'paragraph' and
             len(block['lines']) == 2 and
-            block['lines'][1] == '-' * len(block['lines'][0])):
+            len(block['lines'][0]) == len(block['lines'][1]) and
+            _sectionre.match(block['lines'][1])):
             block['underline'] = block['lines'][1][0]
             block['type'] = 'section'
             del block['lines'][1]
--- a/tests/test-minirst.py	Sun Apr 25 17:48:26 2010 +0200
+++ b/tests/test-minirst.py	Sun Apr 25 18:19:54 2010 +0200
@@ -184,8 +184,14 @@
 
 
 sections = """
-A Somewhat Wide Section Header
-------------------------------
+Title
+=====
+
+Section
+-------
+
+Subsection
+''''''''''
 
 Markup: ``foo`` and :hg:`help`
 ------------------------------
--- a/tests/test-minirst.py.out	Sun Apr 25 17:48:26 2010 +0200
+++ b/tests/test-minirst.py.out	Sun Apr 25 18:19:54 2010 +0200
@@ -305,8 +305,14 @@
 
 sections formatted to fit within 20 characters:
 ----------------------------------------------------------------------
-A Somewhat Wide Section Header
-------------------------------
+Title
+=====
+
+Section
+-------
+
+Subsection
+''''''''''
 
 Markup: "foo" and "hg help"
 ---------------------------