cvs: pear /Text_Wiki/Text/Wiki/Parse/Mediawiki Deflist.php
| From: | Moritz Venn | Date: | Fri, 18 Aug 2006 12:11:46 +0000 |
| Subject: | cvs: pear /Text_Wiki/Text/Wiki/Parse/Mediawiki Deflist.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41777@lists.php.net to get a copy of this message | ||
ritzmo Fri Aug 18 12:11:46 2006 UTC
Modified files:
/pear/Text_Wiki/Text/Wiki/Parse/Mediawiki Deflist.php
Log:
Implemented Request #8451 (thanks Brian)
http://cvs.php.net/viewvc.cgi/pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php?r1=1.2&r2=1.3&diff_format=u
Index: pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php
diff -u pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php:1.2
pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php:1.3
--- pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php:1.2 Tue Aug 15 16:02:05 2006
+++ pear/Text_Wiki/Text/Wiki/Parse/Mediawiki/Deflist.php Fri Aug 18 12:11:46 2006
@@ -9,7 +9,7 @@
* @author Paul M. Jones <pmjones@php.net>
* @author Moritz Venn <ritzmo@php.net>
* @license LGPL
-* @version $Id: Deflist.php,v 1.2 2006/08/15 16:02:05 ritzmo Exp $
+* @version $Id: Deflist.php,v 1.3 2006/08/18 12:11:46 ritzmo Exp $
*
*/
@@ -67,32 +67,62 @@
{
// the replacement text we will return
$return = '';
-
+
// the list of post-processing matches
$list = array();
-
+
// a stack of list-start and list-end types; we keep this
// so that we know what kind of list we're working with
// (bullet or number) and what indent level we're at.
$stack = array();
-
+
// the item count is the number of list items for any
// given list-type on the stack
$itemcount = array();
-
+
// have we processed the very first list item?
$pastFirst = false;
-
+
// populate $list with this set of matches. $matches[1] is the
// text matched as a list set by parse().
preg_match_all(
- '/^((;|:)+)(.*?)$/ms',
+ '/^((;|:)+)\s?(.*?)$/ms',
$matches[1],
$list,
PREG_SET_ORDER
);
- // loop through each list-item element.
+ // look for same-line definitions and split them
+ // foreach() cannot be used because we are modifying the array directly
+ for ($i = 0; $i < count($list); $i++) {
+ $val = $list[$i];
+
+ // only check definition term lines
+ if ($val[2] != ';') {
+ continue;
+ }
+
+ // spot inline definitions
+ $p = strpos($val[3], ' : ');
+ if ($p === false) {
+ continue;
+ }
+
+ $term = substr($val[3], 0, $p);
+ $narr = substr($val[3], $p + 3);
+
+ $prefix = substr($val[1], 0, -1); // everthing but the last char
+
+ $pair = array(
+ array($prefix . ';' . $term, $prefix . ';', ';',
$term),
+ array($prefix . ':' . $narr, $prefix . ':', ':',
$narr),
+ );
+
+ array_splice($list, $i, 1, $pair);
+ $i++; // skip the newly-added definition
+ }
+
+ // loop through each list-item element.
foreach ($list as $key => $val) {
// $val[0] is the full matched list-item line
// $val[1] is the type (* or #)