aboutsummaryrefslogtreecommitdiff
path: root/tools/trac2md.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/trac2md.py')
-rwxr-xr-xtools/trac2md.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/tools/trac2md.py b/tools/trac2md.py
index 40c09d4..01d7f41 100755
--- a/tools/trac2md.py
+++ b/tools/trac2md.py
@@ -115,16 +115,17 @@ def WikiToMD(content):
in_list = False
nested_level = 0
prev_indent = 0
- new_content = ""
+ new_content = []
for line in content.split('\n'):
line = line.replace("\r", "")
- if "{{{" in line:
- code_block = True
- line = line.replace("{{{", "```")
- if "}}}" in line:
- code_block = False
- line = line.replace("}}}", "```")
+ while "{{{" in line or "}}}" in line:
+ if "{{{" in line:
+ code_block = True
+ line = line.replace("{{{", "```")
+ if "}}}" in line:
+ code_block = False
+ line = line.replace("}}}", "```")
if not code_block:
#
# Convert bullet lists. The start and end of a list needs
@@ -133,14 +134,14 @@ def WikiToMD(content):
#
if line.startswith('* '):
if not in_list:
- new_content = "%s\n" % (new_content)
+ new_content.append("\n")
in_list = True
line = line[1:]
line = '-%s' % (line)
elif line.startswith('- '):
# No need to modify the line, just add the new line
if not in_list:
- new_content = "%s\n" % (new_content)
+ new_content.append("\n")
in_list = True
elif line.startswith(' '):
# Check for nested lists
@@ -161,7 +162,7 @@ def WikiToMD(content):
else:
if in_list:
# Add the closing empty line
- new_content = "%s\n" % (new_content)
+ new_content.append("\n")
in_list = False
nested_level = 0
prev_indent = 0
@@ -179,9 +180,10 @@ def WikiToMD(content):
line = line.replace("'''", "**") # Convert bold text
line = line.replace("''", "*") # Convert italic text
- new_content = "%s%s\n" % (new_content, line)
+ new_content.append(line)
+ new_content.append("\n")
- return new_content
+ return "".join(new_content)
for f in sys.argv[1:]:
d = WikiToMD(open(f, "r").read())