sbin/doc/markdown2dokuwiki.py
author veltr
Tue, 05 Jun 2012 20:55:42 +0200
branchnew-model
changeset 910 b9f1bd52df9a
parent 909 aa0e42229784
child 929 a39ff507b050
permissions -rw-r--r--
Simplified Metadataplayer instantiation

import re, sys

inputname = sys.argv[1]
outputname = re.sub("\.\w+$",".dokuwiki",inputname)

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()