summaryrefslogtreecommitdiff
path: root/trac2md.py
diff options
context:
space:
mode:
Diffstat (limited to 'trac2md.py')
-rwxr-xr-xtrac2md.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/trac2md.py b/trac2md.py
index 0804608..38038f3 100755
--- a/trac2md.py
+++ b/trac2md.py
@@ -70,19 +70,25 @@ def convert_headers(line):
return line
+def make_mdlink(text):
+ for sep in "| ":
+ if sep in text:
+ parts = text.split(sep, 1)
+ break
+ else:
+ parts = [text]
+ parts = [p.strip() for p in parts]
+ if parts[-1].startswith('"') and parts[-1].endswith('"'):
+ parts[-1] = parts[-1][1:-1]
+ return "[{}]({})".format(parts[-1], parts[0])
+
+
def convert_wikilinks_1(line):
''' Convert wikiformat links
'''
m = wikilink_1_pattern.search(line)
if m:
- text = m.group(1) or m.group(2)
- for sep in "| ":
- if sep in text:
- parts = text.split(sep, 1)
- break
- else:
- parts = [text]
- mdlink = "[{}]({})".format(parts[-1], parts[0])
+ mdlink = make_mdlink(m.group(1) or m.group(2))
line = line.replace(m.group(0), mdlink)
return line
@@ -95,13 +101,7 @@ def convert_wikilinks_2(line):
if text.lower() == "pageoutline":
mdlink = ""
else:
- for sep in "| ":
- if sep in text:
- parts = text.split(sep, 1)
- break
- else:
- parts = [text]
- mdlink = "[{}]({})".format(parts[-1], parts[0])
+ mdlink = make_mdlink(text)
line = line.replace(m.group(0), mdlink)
return line