[Tutor] split by wiki format - was: wiki madness- it's contagious,
want to get infected?
Michael Janssen
Janssen at rz.uni-frankfurt.de
Thu Aug 14 13:05:27 EDT 2003
On Sat, 2 Aug 2003, Kirk Bailey wrote:
> ok, this means it's time for me to learn some re lore, I expect.
> What is holding me back is parsing the wikicode into html. SOME of this
> code uses unique flags, so can be swapped with a strong.replace
> statement for that- in effect, a rule.
>
> But some of this demands that a tag be replaced 2 different ways,
> turning on or off a function. For instance, "'''" (3 'singlequotes') not
> only turns ON bold print, it turns it off again- it is a state toggle.
>
> Therefore, the guts of a page must be read through sequentially,
> previous state alters response to a detected tag.
Hi Kirk,
I havn't followed every bit of the "wiki" threads so I can't say for
shure nobody else has already postet a similar solution or if you got
something better by now. Anyway:
*split* the text by your format string and decorate every odd element
with the appropriate html tags:
s = "A '''wiki''' text"
split_list = s.split("'''")
for n in range(1, len(split_list), 2):
split_list[n] = '<b>' + split_list[n] +'</b>'
html = ' '.join(split_list)
[this is not extensivly tested]
Just put it into a function and call it with three arguments
wiki_format, html_start_tag, html_end_tag. This way, you can iterate
through different formats (format with longest wiki string first). You
will need to do it also for combined bold+italic (7 singlequotes in
wiki?), otherwise you will end with <i><b>ugly</i></b> html with
incorrect nesting.
Note that this is not efficient in terms of memory consumption. In case
you're already in the state-machine an text processing technology, keep
going (as long as you are not interested in writing a wiki with mimimal
code complexity, which would be a nice goal).
reagards
Michael
More information about the Tutor
mailing list