aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2019-03-19 17:20:12 +0000
committerRob Austein <sra@hactrn.net>2019-03-19 17:20:12 +0000
commit97fc9ee04159bb55554310cf65a5843a7a5f8847 (patch)
treeca9f50b0486fbbba17b519110e1752d321c23342 /tools
parent6ae4982696652c6cde8a9167b18a85f8d08be63f (diff)
tags and theoretically better verbatim text handling
Diffstat (limited to 'tools')
-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())