raymontag has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I write a script to parse wikicode to latex. Now I search for a way to parse an enumeration. Something like

# foo # bar

should look like this after parsing:

\begin{enumerate} \item foo \item bar \end{enumerate}

I think RegEx is a good way to do that but I don't know how to solve this special problem.

Replies are listed 'Best First'.
Re: RegEx for parsing wiki enumeration
by jethro (Monsignor) on Apr 06, 2011 at 12:24 UTC

    It would have been a good idea to post your script or a relevant part of it here so that we might see where to fit it in. Now you have to see for yourself how this might fit in with your code

    my $ennumerate=0; ... #you probably have a loop like this in your script? while ($line=<$fh>) { #insert this into the loop: if ($ennumerate==1) { if ($line=~/^#(.*)/) { print "\\item $1\n"; } else { $ennumerate=0; print "\\end{enumerate}\n"; } else { if ($line=~/^#(.*)/) { print "\\begin{enumerate}\n"; print "\\item $1"; $ennumerate=1; } } ... }

      Thanks! I hadn't the idea to use a loop but this fits perfectly.

Re: RegEx for parsing wiki enumeration
by andreas1234567 (Vicar) on Apr 06, 2011 at 12:47 UTC
    Unless this is an academic exercise, you might want to have a look at wikipdf (written in Python, released under GPL).

    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

      I write this script for fun and practise.

Re: RegEx for parsing wiki enumeration
by vkon (Curate) on Apr 06, 2011 at 12:55 UTC
    hmm.... is this even possible? :o

    Report your teacher, that, by making it looks like simple task, she gave you unresolvable task.

    However trying to solve such tasks is useful for learning programming languages,
    so maybe she is right....