From f70297e5cb302b3bba10f42c85312038a6a0ea5c Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Sat, 26 Mar 2016 10:30:44 -0700 Subject: [PATCH] fix table of contents parsing. --- src/render_rfc.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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. -- 2.43.0