Page 1 of 1

Wiki List

Posted: Tue May 05, 2009 3:22 pm
by yvkr
Hi,

I'm using PEAR Text_Wiki http://pear.php.net/package/Text_Wiki to convert Wiki Syntax to HTML.
I tried to expand the List Feature to be able to have list-types and starting values.

To make a numbered list you write something like:

Code: Select all

 
# Ex 1
# Ex 2
 # Ex 2.1
# Ex 3
Normal Text
# Next List 1
# Next List 2
 
The original regex used in a php preg_replace_callback is this:

Code: Select all

/^((\*|#) .*\n)(?!\2 |(?: {1,}((?:\*|#) |\n)))/Usm
This does two replacement calls, one on the first list, one on the second one.

I want to realize a list like this:

Code: Select all

 
# Ex 1
 # Ex 1.1
 #i Ex 1.i
 # Ex 1.ii
  #A Ex 1.ii.A
   # Ex 1.ii.A.1
   # Ex 1.ii.A.2
  # Ex 1.ii.B
# Ex 2
----
#i Ex i
# Ex ii
 #a Ex 2.a
# Ex iii
----
#=2 Ex 1 Value 2
#=2 Ex 2 Value 2
----
#i=2 Ex i Value 2
#i=9 Ex i Value 9
----
 
The "i" or "a" after the hash key defines the type the value after the equal sign defines the value for the list
For this I "upgraded" the regex like this:

Code: Select all

/^((\*[1aAiI]?[=]?[0-9]*|#[1aAiI]?[=]?[0-9]*) .*\n)(?!\2 |(?: {1,}((?:\*[1aAiI]?[=]?[0-9]*|#[1aAiI]?[=]?[0-9]*) |\n)))/Usm
It works for the first version but the second list is devided into two seperate ones.
The third example works but the last one is devided into two seperate lists.
I guess this is something about the negative lookahead, but i can't get it working.

I would be pleased, if someone could help me.

Greetings