James wrote regarding 'RE: [OT] what about "wiki"' on Tue, Jan 24 at 15:37:
> Now, the bold and underline would have been no easier in a wiki. They would
> still require the [b][u] and the ending tags in reverse order [/u][/b] after
> that.
Actually, the wiki I use does ''bold'' and '''underline''', and
most I've worked with don't use bbcode in general. ;)
> If people really want, I can add a little translator that converts any lines
> starting with a * into a
and puts a
> after the last.... Finding the first and last may be a bit tricky... Lets
> see...
It'd be easier if you used a state machine which remembers whether or
not it's in a list. If it's not in a list, it appends a to the
first line it finds that begins with *, and proceeds to do a
s/^\s*\*(.*)$/- $1<\/li>/ (presuming perl processing a line at a
time) until that doesn't do a replacement, in which case you put a
in front of the line which wasn't subject to replacement and
switch state back to "not in a list".
> Replace $\* with $\ which is dead easy
>
> Then replace $[^<][^L][^I][^>](.*)\n\ with $1\<\/UL\>\
>
> and replace \(.*)\n[^<][^L][^I][^>] with \$1\n\<\/UL\>
>
> Does that look right? Regexp gurus?
Does your regexp environment of choice not support negative
assertions? Using three extra chars for each negative entity seems
bad, if for no other reason than legibility. :) Either way, the second
one will throw away a non- tag preceding a line with an . You
probably want to include the tag in the group both in regexp2 and 3 as
well as including the newline in regexp2, like this:
replace \*([^\n]+) with $1
replace ([^<][^L][^I][^>].*\n) with $1-
replace (
- .*)\n[^<][^L][^I][^>] with $1\n
Though that'd look prettier if you used line start 'n end anchors and
found a way to do a negative assertion - kinda like (!). Of
course, then you'd have to use $1$2 instead of $1, etc...
--Danny, amused that he complained about someone making a regular
expression illegible...
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist