00001 """
00002
00003 NEEDS REVIEW - refactor into Parser page
00004
00005 Hello World parser for MoinMoin wiki.
00006
00007 This hopefully gives a basic idea of what a parser looks like and what
00008 the parts of it mean.
00009
00010 Parsers are kind of in flux. The whole moinmoin thing is being refactored
00011 a lot. But for right now, 1.3, Parsers sort of work like this:
00012
00013 A parser gets created by a Page object, is given the text its supposed
00014 to format and an HTTPRequest object. It mucks around with the text,
00015 and writes the result to the HTTPRequest object it was given.
00016
00017 To install:
00018
00019 Copy this file into data/plugins/parser in your moinmoin wiki instance.
00020 Restart the wiki if necessary.
00021 Edit a page and type in
00022
00023 {{{#!HelloWorld 1 2 3
00024 rabbit
00025 }}}
00026
00027 The result should be something like this inserted in your page:
00028
00029 hello world begin
00030 raw: rabbit
00031 kw: 1 2 3
00032 hello world end
00033
00034
00035 You can get more ideas by looking in the
00036 'python\Lib\site-packages\MoinMoin\parser' directory on your computer,
00037 or by looking at http://moinmoin.wikiwikiweb.de/ParserMarket
00038 at the parsers that others have written.
00039 """
00040
00041 from MoinMoin.Page import Page
00042 from MoinMoin import wikiutil
00043 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
00044
00045 import neo_cgi, neo_util, neo_cs
00046
00047
00048
00049
00050 class Parser:
00051 """ Hello World parser for MoinMoin wiki """
00052
00053 def __init__(self, raw, request, **kw):
00054
00055
00056
00057
00058 self.raw = raw
00059
00060
00061
00062
00063 self.request = request
00064
00065
00066
00067
00068
00069 self.kw=kw
00070
00071
00072
00073
00074
00075 def format(self, formatter):
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 page_name = formatter.page.page_name
00096 cs_template_page = wikiutil.AbsPageName(page_name, self.kw["format_args"])
00097 cs_template = Page(self.request, cs_template_page).getPageText()
00098
00099 hdf = neo_util.HDF()
00100 hdf.readString(self.raw)
00101 hdf.setValue("Config.WhiteSpaceStrip", "0")
00102
00103 cs = neo_cs.CS(hdf)
00104 cs.parseStr(cs_template)
00105 body = cs.render()
00106 body = wikiutil.renderText(self.request, WikiParser, body)
00107 self.request.write(formatter.rawHTML(body))
00108
00109
00110