From 156b5673fe5d0e6abccd53792817800ae87ca117 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Thu, 21 Mar 2019 13:17:23 +0000 Subject: Fix headers, handle CamelCase escapes --- tools/trac2md.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tools/trac2md.py') diff --git a/tools/trac2md.py b/tools/trac2md.py index 43e167a..377cf20 100755 --- a/tools/trac2md.py +++ b/tools/trac2md.py @@ -15,10 +15,11 @@ from datetime import datetime wikilink_pattern = re.compile('\[http(.*)\]') wikilink_extract = re.compile('\[(.*)\]') -wikiheading1_pattern = re.compile('^= (.*) =$') -wikiheading2_pattern = re.compile('^== (.*) ==$') -wikiheading3_pattern = re.compile('^=== (.*) ===$') strikethrough_pattern = re.compile('~~(.*)~~') +camelcase_pattern = re.compile("!(\w+)") + +wikiheading_patterns = tuple((level, re.compile("^{} (.*)[ \t]*=*$".format("=" * level))) + for level in xrange(1, 7)) def to_timestamp(tm): ''' Convert to timestamp which can be jsonified ''' @@ -54,19 +55,15 @@ def strip_wikilink(content): def convert_headers(line): ''' Convert wikiformat headers ''' - level_count = 1 - for header in [wikiheading1_pattern, - wikiheading2_pattern, - wikiheading3_pattern]: + for level_count, header in wikiheading_patterns: try: level = header.search(line).group(1) if level: - line = "%s %s" % ('#' * level_count, level) + line = "%s %s" % ('#' * level_count, level.rstrip("= \r\t")) break # No need to check other heading levels except: # Try the next heading level pass - level_count += 1 return line @@ -203,6 +200,9 @@ def WikiToMD(content): nested_level = 0 prev_indent = 0 + # Convert CamelCase + line = camelcase_pattern.sub("\\1", line) + # Convert headers line = convert_headers(line) -- cgit v1.2.3