|
909
|
1 |
import re, sys |
|
|
2 |
|
|
|
3 |
inputname = sys.argv[1] |
|
910
|
4 |
outputname = re.sub("\.\w+$",".dokuwiki",inputname) |
|
909
|
5 |
|
|
|
6 |
inputfile = open(inputname,'r') |
|
|
7 |
|
|
|
8 |
markdowntext = inputfile.read() |
|
|
9 |
|
|
|
10 |
# Replacing title levels: #italic# -> ======italic====== |
|
|
11 |
|
|
|
12 |
wikitext = re.sub("(?m)(^#+|#+$)", lambda matches: "=" * (7 - len(matches.group(1))), markdowntext) |
|
|
13 |
|
|
|
14 |
# Replacing italics: *italic* -> //italic// |
|
|
15 |
|
|
|
16 |
wikitext = re.sub("(?m)([^*])\*([^*]+)\*($|[^*])", lambda matches: matches.group(1) + "//" + matches.group(2) + "//" + matches.group(3), wikitext) |
|
|
17 |
|
|
|
18 |
# Replacing lists: - -> * |
|
|
19 |
|
|
|
20 |
wikitext = re.sub("(?m)^(\s*)(-)\s", lambda matches: " " * ( 2 + len(matches.group(1)) / 2) + "* ", wikitext) |
|
|
21 |
|
|
|
22 |
# Replacing lists: 1. -> - |
|
|
23 |
|
|
|
24 |
wikitext = re.sub("(?m)^(\s*)(\d+\.)\s", lambda matches: " " * ( 2 + len(matches.group(1)) / 2) + "- ", wikitext) |
|
|
25 |
|
|
|
26 |
# Replacing escaped underscores \_ -> _ |
|
|
27 |
|
|
|
28 |
wikitext = re.sub("(?m)(\\\_)", "_", wikitext) |
|
|
29 |
|
|
|
30 |
# Escaping URL templates {{ -> %%{%%{ |
|
|
31 |
|
|
|
32 |
wikitext = re.sub("(?m)({{)", "%%{%%{", wikitext) |
|
|
33 |
|
|
|
34 |
outputfile = open(outputname,'w') |
|
|
35 |
|
|
|
36 |
outputfile.write(wikitext) |
|
|
37 |
|
|
|
38 |
outputfile.close() |
|
|
39 |
|
|
|
40 |
inputfile.close() |