summaryrefslogtreecommitdiff
path: root/trac2md.py
diff options
context:
space:
mode:
Diffstat (limited to 'trac2md.py')
-rwxr-xr-xtrac2md.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/trac2md.py b/trac2md.py
index c022899..ee9d80a 100755
--- a/trac2md.py
+++ b/trac2md.py
@@ -12,6 +12,7 @@ import shutil
import os
from base64 import b64decode
from datetime import datetime
+from urllib.parse import quote
wikilink_pattern = re.compile('\[http(.*)\]')
wikilink_extract = re.compile('\[(.*)\]')
@@ -105,13 +106,16 @@ def convert_strike(line):
pass
return line
-def convert_image(line):
+def convert_image(line, slug):
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)
+ if "://" in image_text:
+ new_text = "<img src=\"{}\">".format(image_text)
+ else:
+ new_text = "![{}]({{attach}}{}/{})".format(image_text, slug, quote(image_text, ""))
line = line.replace(old_text, new_text)
except:
pass
@@ -123,7 +127,7 @@ def convert_linebreak(line):
line = line[:-2] + " "
return line
-def WikiToMD(content):
+def WikiToMD(content, slug):
''' Convert wiki/RST format to Markdown. Code blocks, bold/italics,
wiki links, lists, striked text, and headers. '''
@@ -219,7 +223,7 @@ def WikiToMD(content):
line = convert_strike(line)
# Convert images
- line = convert_image(line)
+ line = convert_image(line, slug)
# Convert line breaks
line = convert_linebreak(line)