diff options
author | Rob Austein <sra@hactrn.net> | 2021-02-15 07:08:13 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2021-02-15 07:08:13 +0000 |
commit | 3bfd6f7d2c45b44ae3ef0616f40368d59eae0c68 (patch) | |
tree | db830f09cf00b4b1d5c0dfc538f26e5b639aa57e /trac2md.py | |
parent | 6cbd48ea560b2cc4b906efcc13ad3a14a8d8e815 (diff) |
Convert whacky [[span()]] links
[[span()]] is poorly documented, and the Cryptech Wiki only used it
because somebody was trying to force TracWiki to do something it
really didn't want to do. Trying to write a general [[span()]] parser
for this is over the top, just handle this screwball case.
Diffstat (limited to 'trac2md.py')
-rwxr-xr-x | trac2md.py | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -23,6 +23,8 @@ wikilink_3_pattern = re.compile(r"\[\[(?:wiki:)?([^][]+)\]\]|\[wiki:([^][]+)\]") strikethrough_pattern = re.compile(r"~~(.*)~~") camelcase_pattern = re.compile(r"!((?:\w|[#])+)") +span_pattern = re.compile(r"\[\[span\((?:[^][]*,)*\[([^(), ]+)([^(),]+)\]\)\]\]") + wikiheading_patterns = tuple( (level, re.compile("^{} (.*)[ \t]*=*$".format("=" * level))) for level in range(1, 7)) @@ -87,6 +89,7 @@ def convert_strike(line): pass return line + def convert_image(line, slug): image_result = image_pattern.search(line) if image_result: @@ -102,12 +105,14 @@ def convert_image(line, slug): pass return line + def convert_linebreak(line): # Markdown spec says linebreak is <SPACE><SPACE><RETURN>, who am I to argue? if line.endswith("\\\\"): line = line[:-2] + " " return line + def WikiToMD(content, slug): # Line breaks in Markdown must be at end of line, so add newlines as needed @@ -190,7 +195,10 @@ def WikiToMD(content, slug): prev_indent = 0 # Convert CamelCase - line = camelcase_pattern.sub("\\1", line) + line = camelcase_pattern.sub(r"\1", line) + + # Convert (limited subset of) spans + line = span_pattern.sub(r"[[\1|\2]]", line) # Convert headers line = convert_headers(line) |