2012-06-19 23:22:44 +02:00
|
|
|
#!/usr/bin/python
|
2012-09-18 22:43:36 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-09-22 18:23:47 +02:00
|
|
|
# Setup VIM: ex: noet ts=2 sw=2 :
|
|
|
|
#
|
|
|
|
# Module for doing DokuWiki output conversion.
|
|
|
|
# See README for details.
|
|
|
|
#
|
|
|
|
# Author: Elan Ruusamäe <glen@pld-linux.org>
|
|
|
|
# Version: 1.0
|
2016-01-05 17:13:48 +01:00
|
|
|
#from MoinMoin.web.request import Request as RequestCLI
|
|
|
|
from MoinMoin.web.contexts import ScriptContext
|
|
|
|
from MoinMoin import wikiutil
|
2012-06-19 23:22:44 +02:00
|
|
|
from MoinMoin.Page import Page
|
2016-01-05 17:13:48 +01:00
|
|
|
from MoinMoin.parser.text_moin_wiki import Parser
|
2012-06-19 23:22:44 +02:00
|
|
|
|
|
|
|
from text_dokuwiki import Formatter
|
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
import sys
|
|
|
|
import StringIO
|
|
|
|
|
2016-01-06 16:55:45 +01:00
|
|
|
def moin2doku(pagename, text, randomID=None):
|
2012-09-16 19:40:02 +02:00
|
|
|
parser = Parser(text, request)
|
|
|
|
|
2016-01-06 16:55:45 +01:00
|
|
|
formatter.setRandomID(randomID)
|
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
# this needed for macros
|
|
|
|
request.formatter = formatter
|
2012-06-19 23:22:44 +02:00
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
p = Page(request, pagename)
|
|
|
|
formatter.setPage(p)
|
2012-06-19 23:22:44 +02:00
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
output = StringIO.StringIO()
|
2012-06-19 23:22:44 +02:00
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
# wrap sys.stdout as RequestCLI has no interface to say where to output
|
|
|
|
stdout = sys.stdout
|
|
|
|
sys.stdout = output
|
|
|
|
parser.format(formatter)
|
|
|
|
sys.stdout = stdout
|
2012-06-19 23:22:44 +02:00
|
|
|
|
2012-09-18 22:45:11 +02:00
|
|
|
return unicode(output.getvalue().decode('utf-8'))
|
2012-09-16 19:40:02 +02:00
|
|
|
|
2016-01-05 17:13:48 +01:00
|
|
|
request = ScriptContext()
|
2012-09-16 19:40:02 +02:00
|
|
|
formatter = Formatter(request)
|
2012-06-19 23:22:44 +02:00
|
|
|
|
2012-09-16 19:40:02 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
# pages/playground\(2f\)SyntaxReference/revisions/00000001
|
2012-09-17 11:08:46 +02:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
inputfile = sys.argv[1]
|
|
|
|
else:
|
|
|
|
inputfile = 'syntaxreference.txt'
|
|
|
|
|
2016-01-05 17:13:48 +01:00
|
|
|
f = open(inputfile, 'r')
|
|
|
|
text = f.read()
|
2012-09-16 19:40:02 +02:00
|
|
|
print moin2doku('test', text)
|