ptmcg at austin.rr._bogus_.com
Wed Nov 22 16:46:08 CET 2006
"Ant" <antroy at gmail.com> wrote in message
news:1164188646.047093.182390 at f16g2000cwb.googlegroups.com...
>I have a home-grown Wiki that I created as an excercise, with it's own
> wiki markup (actually just a clone of the Trac wiki markup). The wiki
> text parser I wrote works nicely, but makes heavy use of regexes, tags
> and stacks to parse the text. As such it is a bit of a mantainability
> nightmare - adding new wiki constructs can be a bit painful.
> So I thought I'd look into the pyparsing module, but can't find a
> simple example of processing random text. For example, I want to parse
> the following:
> "Some random text and '''some bold text''' and some more random text"
> "Some random text and <strong>some bold text</strong> and some more
> random text"
> I have the following as a starting point:
> from pyparsing import *
> def parse(text):
> italics = QuotedString(quoteChar="''")
> parser = Optional(italics)
> parsed_text = parser.parseString(text)
> print parse("Test this is '''bold''' but this is not.")
> So if you could provide a bit of a starting point, I'd be grateful!
Welcome to pyparsing! The simplest way to implement a markup processor in
pyparsing is to define the grammar of the markup, attach a parse action to
each markup type to convert the original markup to the actual results, and
then use transformString to run through the input and do the conversion.
This discussion topic has some examples:
More information about the Python-list