在这里详述 ObpLatform/2007-02-06.
1. SimpleWikiPraser
1 #coding=utf-8
2 from MoinMoin.request import RequestCLI, Clock
3 import sys
4
5 class DUMPClass(object):pass
6
7 class EmptyRequest(RequestCLI):
8 def __init__(self, output=sys.stdout, url='CLI', pagename='',
9 properties={}):
10 self.output = output
11 self.saved_cookie = ''
12 self.path_info = '/' + pagename
13 self.query_string = ''
14 self.remote_addr = '127.0.0.1'
15 self.is_ssl = 0
16 self.http_user_agent = 'CLI/Script'
17 self.url = url
18 self.request_method = 'GET'
19 self.request_uri = '/' + pagename # TODO check
20 self.http_host = 'localhost'
21 self.http_referer = ''
22 self.script_name = '.'
23 self.if_modified_since = None
24 self.if_none_match = None
25
26 self.getText = lambda text: text
27 self.form = ''
28 self.cfg = DUMPClass()
29 self.cfg.siteid = ''
30 self.cfg.caching_formats = []
31 self.cfg.macro_names = ''
32 self.cfg.bang_meta = None
33 self.cfg.show_section_numbers = False
34 self.cfg.data_underlay_dir = None
35 self.cfg.url_mappings = {}
36 self.hilite_re = None
37 self.page_name = ''
38 self._page_headings = {}
39 self.pragma = {}
40 self.user = DUMPClass()
41 self.user.show_topbottom = False
42 self.current_lang = ''
43 self.content_lang = ''
44 self.clock = Clock()
45
46 # self.cfg.caching_formats = [] # don't spoil the cache
47 # self.initTheme() # usually request.run() does this, but we don't use it
48
49 def write(self, *data):
50 """ Write to output stream. """
51 self.output.write(self.encode(data))
52
53 o = file('outmoin.html', 'wb')
54 req = EmptyRequest(o)
55
56 #from MoinMoin.formatter import text_plain
57 #html_formatter = text_plain.Formatter(req)
58
59 from MoinMoin.formatter import text_html
60 html_formatter = text_html.Formatter(req)
61
62 html_formatter.setPage(req)
63
64 from MoinMoin.parser.wiki import Parser
65
66 class SimpleWikiParser(Parser):
67 def _word_repl(self, word, text=None):
68 return word
69
70 text = file('moin.txt').read()
71 text = unicode(text, 'utf-8')
72 parser = SimpleWikiParser(text, req)
73 parser.format(html_formatter)
74 o.close()
这个程序可以用。输入文件为moin.txt,输出为outmoin.html。不过,真正要实现定制输出还要看在哪里加入处理点。宏不能使用。表情图不能使用。