diff -r f56199193fad -r aa0e42229784 sbin/doc/markdown2dokuwiki.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbin/doc/markdown2dokuwiki.py Tue Jun 05 17:55:24 2012 +0200 @@ -0,0 +1,40 @@ +import re, sys + +inputname = sys.argv[1] +outputname = sys.argv[2] + +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() \ No newline at end of file