summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2021-02-14 01:55:38 +0000
committerRob Austein <sra@hactrn.net>2021-02-14 01:55:38 +0000
commitb58c60bcc4a6f3d3ccf4194ef862a808fdc3313b (patch)
treead43c2b937db286c2b3320b57066a9581264444a /tools
parent23bb68fe7e9cc8af176ff60b56e8a51a70f05a89 (diff)
Hack images, store outputs in git again for now
Easier to track what each script change does if we keep the before and after versions of the markdown in git too. Clean this up eventually, but simplifies development.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/trac2md.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/trac2md.py b/tools/trac2md.py
index 838a36f..214471f 100755
--- a/tools/trac2md.py
+++ b/tools/trac2md.py
@@ -17,6 +17,7 @@ wikilink_pattern = re.compile('\[http(.*)\]')
wikilink_extract = re.compile('\[(.*)\]')
strikethrough_pattern = re.compile('~~(.*)~~')
camelcase_pattern = re.compile("!(\w+)")
+image_pattern = re.compile("\[\[Image\((.*)\)\]\]")
wikiheading_patterns = tuple((level, re.compile("^{} (.*)[ \t]*=*$".format("=" * level)))
for level in range(1, 7))
@@ -104,6 +105,18 @@ def convert_strike(line):
pass
return line
+def convert_image(line):
+ image_result = image_pattern.search(line)
+ if image_result:
+ try:
+ image_text = image_result.group(1).split(",")[0].strip()
+ old_text = image_result.group(0)
+ new_text = "<img src=\"{}\">".format(image_text)
+ line = line.replace(old_text, new_text)
+ except:
+ pass
+ return line
+
def WikiToMD(content):
''' Convert wiki/RST format to Markdown. Code blocks, bold/italics,
wiki links, lists, striked text, and headers. '''
@@ -196,6 +209,9 @@ def WikiToMD(content):
# Convert striked through text
line = convert_strike(line)
+ # Convert images
+ line = convert_image(line)
+
# Convert bold and italic text (do this last)
line = line.replace("'''", "**") # Convert bold text
line = line.replace("''", "*") # Convert italic text
@@ -204,11 +220,3 @@ def WikiToMD(content):
new_content.extend(tail)
return "".join(new_content)
-
-if __name__ == "__main__":
- for f in sys.argv[1:]:
- d = WikiToMD(open(f, "r").read())
- newf = f.replace(".trac", ".md")
- with open(newf, "w") as fp:
- fp.write(d)
- pass