aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/trac2md.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/trac2md.py b/tools/trac2md.py
index 838a36f..214471f 100755
--- a/tools/trac2md.py
+++ b/tools/trac2md.py
@@ -17,6 +17,7 @@ wikilink_pattern = re.compile('\[http(.*)\]')
wikilink_extract = re.compile('\[(.*)\]')
strikethrough_pattern = re.compile('~~(.*)~~')
camelcase_pattern = re.compile("!(\w+)")
+image_pattern = re.compile("\[\[Image\((.*)\)\]\]")
wikiheading_patterns = tuple((level, re.compile("^{} (.*)[ \t]*=*$".format("=" * level)))
for level in range(1, 7))
@@ -104,6 +105,18 @@ def convert_strike(line):
pass
return line
+def convert_image(line):
+ image_result = image_pattern.search(line)
+ if image_result:
+ try:
+ image_text = image_result.group(1).split(",")[0].strip()
+ old_text = image_result.group(0)
+ new_text = "<img src=\"{}\">".format(image_text)
+ line = line.replace(old_text, new_text)
+ except:
+ pass
+ return line
+
def WikiToMD(content):
''' Convert wiki/RST format to Markdown. Code blocks, bold/italics,
wiki links, lists, striked text, and headers. '''
@@ -196,6 +209,9 @@ def WikiToMD(content):
# Convert striked through text
line = convert_strike(line)
+ # Convert images
+ line = convert_image(line)
+
# Convert bold and italic text (do this last)
line = line.replace("'''", "**") # Convert bold text
line = line.replace("''", "*") # Convert italic text
@@ -204,11 +220,3 @@ def WikiToMD(content):
new_content.extend(tail)
return "".join(new_content)
-
-if __name__ == "__main__":
- for f in sys.argv[1:]:
- d = WikiToMD(open(f, "r").read())
- newf = f.replace(".trac", ".md")
- with open(newf, "w") as fp:
- fp.write(d)
- pass