summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/trac2md.py18
1 files changed, 9 insertions, 9 deletions
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)