From 3bfd6f7d2c45b44ae3ef0616f40368d59eae0c68 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Mon, 15 Feb 2021 07:08:13 +0000 Subject: 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. --- trac2md.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'trac2md.py') diff --git a/trac2md.py b/trac2md.py index dd519eb..a8a632b 100755 --- a/trac2md.py +++ b/trac2md.py @@ -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 , 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) -- cgit v1.2.3