Created
April 29, 2016 21:13
-
-
Save martior/ee2a1ed3e7522103f33cf13a4570456e to your computer and use it in GitHub Desktop.
Convert Trac WikiFormating to markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# based on: https://gist.github.com/sgk/1286682 | |
text = """ | |
""" | |
import datetime | |
import re | |
text = re.sub('\r\n', '\n', text) | |
text = re.sub(r'{{{(.*?)}}}', r'`\1`', text) | |
def indent4(m): | |
return '\n ' + m.group(1).replace('\n', '\n ') | |
text = re.sub(r'(?sm){{{\n(.*?)\n}}}', indent4, text) | |
text = re.sub(r'(?m)^====\s+(.*?)\s+====$', r'#### \1', text) | |
text = re.sub(r'(?m)^===\s+(.*?)\s+===$', r'### \1', text) | |
text = re.sub(r'(?m)^==\s+(.*?)\s+==$', r'## \1', text) | |
text = re.sub(r'(?m)^=\s+(.*?)\s+=$', r'# \1', text) | |
text = re.sub(r'^ * ', r'****', text) | |
text = re.sub(r'^ * ', r'***', text) | |
text = re.sub(r'^ * ', r'**', text) | |
text = re.sub(r'^ * ', r'*', text) | |
text = re.sub(r'^ \d+. ', r'1.', text) | |
a = [] | |
for line in text.split('\n'): | |
if not line.startswith(' '): | |
line = re.sub(r'\[(https?://[^\s\[\]]+)\s([^\[\]]+)\]', r'[\2](\1)', line) | |
line = re.sub(r'\[(wiki:[^\s\[\]]+)\s([^\[\]]+)\]', r'[\2](/\1/)', line) | |
line = re.sub(r'\!(([A-Z][a-z0-9]+){2,})', r'\1', line) | |
line = re.sub(r'\'\'\'(.*?)\'\'\'', r'*\1*', line) | |
line = re.sub(r'\'\'(.*?)\'\'', r'_\1_', line) | |
a.append(line) | |
print '\n'.join(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment