]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
fix table of contents parsing.
authorKarim Hamidou <khamidou@gmail.com>
Sat, 26 Mar 2016 17:30:44 +0000 (10:30 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Sat, 26 Mar 2016 17:30:44 +0000 (10:30 -0700)
src/render_rfc.py

index b215159f753dc780f292d893ff260ad17a7f366e..d644a60ac22d691e6f6b67bdf76c2613c0dafddc 100644 (file)
@@ -40,10 +40,9 @@ def cleanup_author_header(data, **kwargs):
 def cleanup_toc(data, **kwargs):
     # Clean up the table of contents
     #toc_regexp = re.compile(r'^\s+([\d\.]+)\s+(.+)(\.+)\s*(\d+)$', re.MULTILINE)
-    toc_regexp = re.compile(r"^\s+(.+)\s+\.+\s+(\d+)$", re.MULTILINE)
-    submatch_rx = re.compile(r"([\w\d\.]+)\s(.+)")
+    toc_regexp = re.compile(r"^\s+(.+?)\s*\.+\s*(\d+)$", re.MULTILINE)
+    submatch_rx = re.compile(r"([\w\d\.]+)\s+(.+)")
 
-    raise
     def format_match(match):
         submatch = submatch_rx.match(match.group(1))
         if submatch:
@@ -54,8 +53,11 @@ def cleanup_toc(data, **kwargs):
             title = match.group(1)
 
         anchor = section_name
-        if anchor and anchor[-1] == '.':
-            anchor = "#section-" + anchor[:-1]
+        if anchor:
+            if anchor[-1] == '.':
+                anchor = "#section-" + anchor[:-1]
+            else:
+                anchor = "#section-" + anchor
 
         indent = ''
         # Indent parts depending on their section number.