/
wikitext.py
executable file
·59 lines (52 loc) · 1.74 KB
/
wikitext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/python2
# This utility will convert from MoinMoin wiki text to html
import sys
import os.path
from MoinMoin import log
log.logging_config = log.logging_config.replace("loglevel=INFO",
"loglevel=ERROR")
from MoinMoin.parser.text_moin_wiki import Parser
from MoinMoin.formatter.text_html import Formatter
from MoinMoin.config.multiconfig import DefaultConfig
from MoinMoin.web.contexts import AllContext
from MoinMoin.web.request import TestRequest
from MoinMoin import i18n
class Config(DefaultConfig):
url_prefix_static = "/yesteryears"
theme_default = "ls_stardust"
def __init__(self, id):
DefaultConfig.__init__(self, id)
def _check_directories(self):
pass
def _loadPluginModule(self):
self._plugin_modules = []
class Page(object):
def __init__(self):
self.hilite_re = None
self.page_name = "bliki"
class Context(AllContext):
def __init__(self):
req = TestRequest()
req.given_config = Config
AllContext.__init__(self, req)
self.content_lang = self.current_lang = self.lang = "en"
self.session=None
i18n.i18n_init(self)
def convert(self, text):
del self.response[:]
formatter = Formatter(self)
formatter.setPage(Page())
Parser(text, self).format(formatter)
html = "".join(self.response)
return html
def main():
context = Context()
for wikiFname in sys.argv[1:]:
with open(wikiFname) as f:
text = f.read()
htmlFname = os.path.splitext(wikiFname)[0] + ".html"
print(htmlFname)
with open(htmlFname, "wt") as f:
f.write(context.convert(text))
if __name__ == "__main__":
main()