aboutsummaryrefslogtreecommitdiff
path: root/trac2md.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2021-02-15 23:55:13 +0000
committerRob Austein <sra@hactrn.net>2021-02-15 23:55:13 +0000
commit86202308b68db7a6cf299c5fe3cdee4dc1850330 (patch)
tree267929b96cc0f386112b07ab49a4debc0af347dd /trac2md.py
parenta255b67f6d487703db648c58ee1e50c0aa85c2a6 (diff)
Try mapping source: and browser: links
This turns out to be less useful than expected, because somehow for every single link in the wiki, the source repository is not quite in the obvios plae with cgit. Might be a cgit configuration issue, but this gets wonky enough that it's probably simpler just to expand the JSON file we already have for the filter rules so that it includes other magic stuff like a URL map for this kind of link.
Diffstat (limited to 'trac2md.py')
-rwxr-xr-xtrac2md.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/trac2md.py b/trac2md.py
index ab8a558..cf8ecdf 100755
--- a/trac2md.py
+++ b/trac2md.py
@@ -20,7 +20,7 @@ traclink_pattern = re.compile(r"(?<!\[)\[([^][]+)\]")
image_pattern = re.compile(r"\[\[Image\((.*)\)\]\]")
-wikilink_pattern = re.compile(r"\[\[(wiki:|attachment:)?([^]|[]+)(?:[|]([^][]+))?\]\]")
+wikilink_pattern = re.compile(r"\[\[(wiki:|attachment:|source:|browser:)?([^]|[]+)(?:[|]([^][]+))?\]\]")
strikethrough_pattern = re.compile(r"~~([^~]+)~~")
bangquote_pattern = re.compile(r"!((?:\w|[#])+)")
@@ -62,7 +62,12 @@ def convert_traclink_to_creolelink(line):
return line
-def convert_wikilinks(line, slug):
+# Probably most of the non-wiki scheme tests should become a table in an
+# extended JSON config file which maps
+#
+# { "source:fee/fie/foe/fum": "https://git.cryptech.is/blarg/blee/blue" }
+
+def convert_wikilinks(line, slug, giturl):
for m in wikilink_pattern.finditer(line):
scheme, link, text = [p.strip() if p else p for p in m.groups()]
if text is None:
@@ -75,6 +80,8 @@ def convert_wikilinks(line, slug):
mdlink = "<{}>".format(link)
elif scheme == "attachment:":
mdlink = "[{}]({{attach}}{}/{})".format(text, slug, link)
+ elif scheme in ("source:", "browser:"):
+ mdlink = "[{}]({}/{})".format(text, giturl.rstrip("/"), link.lstrip("/"))
elif scheme == "wiki:" or (scheme is None and camelcase_pattern.match(link)):
mdlink = "[{}]({{filename}}{}.md)".format(text, link)
else:
@@ -190,7 +197,7 @@ def WikiToMD(content, slug):
line = delete_pattern.sub("", line)
# Convert wiki links
- line = convert_wikilinks(line, slug)
+ line = convert_wikilinks(line, slug, "https://git.cryptech.is/")
# Convert striked through text
line = strikethrough_pattern.sub(r"<s>\1</s>", line)