(anonymous guest) (logged out)

Copyright (C) by the contributors. Some rights reserved, license BY-SA.

Sponsored by the Wiki Symposium and the Nuveon GmbH.

 

Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-43) was last changed on 17-Dec-2007 18:47 by YaroslavStavnichiy  

This page was created on 28-Aug-2006 11:25 by Christoph

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 496 added 63 lines
I don't use regular expressions.
But here is the algorithm in PHP in anycase, called when the parse has seen \n[*-#], with $i holding the position of the [*-#].
{{{
/*
* $text is the creole text
* $i is the current position in $text
* $l is the strlen($text)
* $doc is the DOM Document
* $node is the current position in the DOM Document
* $listMap = array('-' => 'ul', '*' => 'ul', '#' => 'ol');
*/
// Traverse up the DOM tree, from our current position, looking for open lists.
$lists = array();
for($n = $node; $n; $n = $n->parentNode)
if ($n->nodeName == 'ol' || $n->nodeName == 'ul')
array_unshift($lists, $n);
// See how many lists we can match... from the $text
$j = 0;
while (isset($text[$i + $j], $lists[$j], $listMap[$text[$i + $j]])
&& $listMap[$text[$i + $j]] == $lists[$j]->nodeName)
++$j;
// See how many list markers left...
$k = strspn($text, '-#*', $i + $j);
switch ($k)
{
case 1:
// Going a level deeper..
if (isset($lists[$j - 1]))
$node = $lists[$j - 1]->lastChild;
else if ($j == 0 && $node->nodeName == 'li')
$node = $node->parentNode;
// Create UL or UL...
$node = $this->insertElement($node, $listMap[$text[$i + $j]]);
$node = $node->appendChild($doc->createElement('li'));
$i += $j + $k;
break;
case 0:
// List item of the most recent open list.
$node = $this->insertElement($lists[$j - 1], 'li');
$i += $j;
break;
default:
// Horizontal line...
if (strspn($text, '-', $i) >= 4)
{
$this->insertElement($node, 'hr');
$i += $j + $k;
}
break;
}
}}}
-- [JaredWilliams], 2006-12-30
Version Date Modified Size Author Changes ... Change note
43 17-Dec-2007 18:47 14.815 kB YaroslavStavnichiy to previous
42 26-Sep-2007 09:31 13.154 kB ChuckSmith to previous | to last restore
41 26-Sep-2007 01:04 13.184 kB 207.44.238.95 to previous | to last
« This page (revision-43) was last changed on 17-Dez-2007 18:47 by YaroslavStavnichiy