changeset 10984:68b7d2d668ce

minirst: support all recommended title adornments
author Martin Geisler <mg@lazybytes.net>
date Sun, 25 Apr 2010 18:19:54 +0200
parents 287a5cdf7743
children f2340d699e79
files mercurial/minirst.py tests/test-minirst.py tests/test-minirst.py.out
diffstat 3 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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"
 ---------------------------