[Moin-user] Application with Moin integration

Wari Wahab wari at celestix.com
Sun Aug 25 19:26:03 EDT 2002


Wari Wahab wrote:

>I've been looking around the moin source code searching high and low for
>ways to use moin as a library (Yup, not as the server).
>Moin is setup to work fine. But I've got an application that would
>benefit Moin's library to format plain text into html.
>Moin is a good library for this and it should not be necessary
>to reinvent the wheel.
>
Now I'm answering my own question as I've not recieved any. But anyway, I've got something working at least, and the best thing about this is the fact that macros, Interwikis and what nots work very well indeed. The only question I have now is: Is this the right way to do it?
----------------------
"""This code assumes that you have moin_config.py easily loadable and
your ./data directory is correct in the configuration"""
from MoinMoin.parser.wiki import Parser
from MoinMoin.formatter.text_html import Formatter
from MoinMoin.request import Request
from MoinMoin.Page import Page
from MoinMoin.user import User
from cStringIO import StringIO
import sys

class WikiText:
    def __init__(self, text = ''):
        self.text = text

    def Wikify(self):
        s = StringIO()
        oldstdout = sys.stdout
        form = None
        page = Page(None)
        page.hilite_re = None
        request = Request()
        request.user = User()
        formatter = Formatter(request)
        formatter.setPage(page)
        # stdout needs to be redirected as MoinMoin uses print
        sys.stdout = s
        Parser(self.text, request).format(formatter, form)
        sys.stdout = oldstdout
        result = s.getvalue()
        s.close()
        return result

if __name__ == '__main__':
        text = """Hello, and welcome to MoinMoin, Refer to HelpOnFormatting for Formatting guidelines"""
        wiki = WikiText(text)
        print wiki.Wikify()

-- 
Regards: Wari Wahab
http://roughingit.subtlehints.net/







More information about the Moin-user mailing list