Home » Text » Text_Wiki_Mediawiki » Bug #8451
Inline definition list patch
Details
| Request #8451 | Inline definition list patch |
|---|---|
| Submitted | 2006-08-15 18:21 UTC |
| From | bjs5075 at rit dot edu |
| Assigned | ritzmo |
| Status | Closed |
| Package | Text_Wiki_Mediawiki |
| PHP Version | 5.1.4 |
| OS | Debian etch |
| Roadmaps | (Not assigned) |
Comments
[2006-08-15 18:21 UTC] bjs5075 at rit dot edu
Description:
------------
Here is a patch that looks for definition terms defined
inline and modifies the definition list. It tricks the
parser into treating it as if it were just a normal
multi-line definition.
--- Parse/Mediawiki/Deflist.php (revision 766)
+++ Parse/Mediawiki/Deflist.php (working copy)
@@ -108,11 +108,40 @@
PREG_SET_ORDER
);
+ // 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;
+ }
+
+ $p = strpos($val[3], ' : '); // spot inline
definitions
+ if ($p === false) {
+ continue;
+ }
+
+ $term = substr($val[3], 0, $p);
+ $narr = substr($val[3], $p + 2);
+
+ $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
Test script:
---------------
; something : like this
; or : like this
: needs parsed
Expected result:
----------------
something
like this
or
like this
needs parsed
Actual result:
--------------
something : like this
or : like this
needs parsed
[2006-08-18 12:13 UTC] ritzmo at php dot net
Patch implemented.
I modified it slightly to strip the additional whitespaces and modified the preg_match_all called before to do so too.