From: Karim Hamidou Date: Sat, 26 Mar 2016 17:30:44 +0000 (-0700) Subject: fix table of contents parsing. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f70297e5cb302b3bba10f42c85312038a6a0ea5c;p=rfcspot.git fix table of contents parsing. --- diff --git a/src/render_rfc.py b/src/render_rfc.py index b215159f..d644a60a 100644 --- a/src/render_rfc.py +++ b/src/render_rfc.py @@ -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.