diff options
author | Rob Austein <sra@hactrn.net> | 2021-02-14 23:00:42 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2021-02-14 23:00:42 +0000 |
commit | a1d28e4a70e8ddaec4968766149d61efb76448bc (patch) | |
tree | c21ce2c9932acd7d26bd5acb9edaac9794105a62 /trac2md.py | |
parent | 8428fbcf08f34a3d6714484bf4445c5ec817354b (diff) |
Yet more links
Diffstat (limited to 'trac2md.py')
-rwxr-xr-x | trac2md.py | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -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 |