| author | durandn |
| Tue, 22 Sep 2015 17:07:58 +0200 | |
| changeset 1062 | f8adaa2caecb |
| parent 929 | a39ff507b050 |
| permissions | -rw-r--r-- |
import re, sys inputname = sys.argv[1] outputname = re.sub("\.\w+$",".dokuwiki",inputname) print "Converting %s to %s"%(inputname,outputname) inputfile = open(inputname,'r') markdowntext = inputfile.read() # Replacing title levels: #italic# -> ======italic====== wikitext = re.sub("(?m)(^#+|#+$)", lambda matches: "=" * (7 - len(matches.group(1))), markdowntext) # Replacing italics: *italic* -> //italic// wikitext = re.sub("(?m)([^*])\*([^*]+)\*($|[^*])", lambda matches: matches.group(1) + "//" + matches.group(2) + "//" + matches.group(3), wikitext) # Replacing lists: - -> * wikitext = re.sub("(?m)^(\s*)(-)\s", lambda matches: " " * ( 2 + len(matches.group(1)) / 2) + "* ", wikitext) # Replacing lists: 1. -> - wikitext = re.sub("(?m)^(\s*)(\d+\.)\s", lambda matches: " " * ( 2 + len(matches.group(1)) / 2) + "- ", wikitext) # Replacing escaped underscores \_ -> _ wikitext = re.sub("(?m)(\\\_)", "_", wikitext) # Escaping URL templates {{ -> %%{%%{ wikitext = re.sub("(?m)({{)", "%%{%%{", wikitext) outputfile = open(outputname,'w') outputfile.write(wikitext) outputfile.close() inputfile.close()