Skip to content

Commit

Permalink
Added redcloth style list continuation.
Browse files Browse the repository at this point in the history
  • Loading branch information
netcarver committed Apr 26, 2012
1 parent e7e398a commit b7bf4e1
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
29 changes: 25 additions & 4 deletions classTextile.php
Expand Up @@ -800,7 +800,7 @@ function fTable($matches)
// -------------------------------------------------------------
function lists($text)
{
return preg_replace_callback("/^([#*;:]+$this->lc[ .].*)$(?![^#*;:])/smU", array(&$this, "fList"), $text);
return preg_replace_callback("/^([#*;:]+(?:_|[\d]+)?$this->lc[ .].*)$(?![^#*;:])/smU", array(&$this, "fList"), $text);
}

// -------------------------------------------------------------
Expand All @@ -810,14 +810,35 @@ function fList($m)
$pt = '';
foreach($text as $nr => $line) {
$nextline = isset($text[$nr+1]) ? $text[$nr+1] : false;
if (preg_match("/^([#*;:]+)($this->lc)[ .](.*)$/s", $line, $m)) {
list(, $tl, $atts, $content) = $m;
if (preg_match("/^([#*;:]+)(_|[\d]+)?($this->lc)[ .](.*)$/s", $line, $m)) {
list(, $tl, $st, $atts, $content) = $m;
$content = trim($content);
$nl = '';
$ltype = $this->lT($tl);
$litem = (strpos($tl, ';') !== false) ? 'dt' : ((strpos($tl, ':') !== false) ? 'dd' : 'li');
$showitem = (strlen($content) > 0);

if( 'o' === $ltype ) { // handle list continuation/start attribute on ordered lists...
if( !isset($this->olstarts[$tl]) )
$this->olstarts[$tl] = 1;

if( 0 === $nr ) { // first line of ol -- has a start attribute?
if( '' == $st )
$this->olstarts[$tl] = 1; // no => reset count to 1.
elseif( '_' !== $st )
$this->olstarts[$tl] = (int)$st; // yes, and numeric => reset to given.
// TRICKY: the '_' continuation marker just means
// output the count so don't need to do anything
// here.
}

if(0 === $nr && '' !== $st) // output the start attribute if needed...
$st = ' start="' . $this->olstarts[$tl] . '"';

if( $showitem ) // TRICKY: Only increment the count for list items
$this->olstarts[$tl] += 1;
}

if (preg_match("/^([#*;:]+)($this->lc)[ .].*/", $nextline, $nm))
$nl = $nm[1];

Expand All @@ -828,7 +849,7 @@ function fList($m)
$atts = $this->pba($atts);
if (!isset($lists[$tl])) {
$lists[$tl] = 1;
$line = "\t<" . $ltype . "l$atts>" . (($showitem) ? "\n\t\t<$litem>" . $content : '');
$line = "\t<" . $ltype . "l$atts$st>" . (($showitem) ? "\n\t\t<$litem>" . $content : '');
} else {
$line = ($showitem) ? "\t\t<$litem$atts>" . $content : '';
}
Expand Down
86 changes: 86 additions & 0 deletions test/basic.yaml
Expand Up @@ -830,6 +830,92 @@ Basic Ordered List:
<li>&#8230; aaaaand back out</li>
</ol>
Ordered Lists:
input: |
#_(first#list) one
# two
# three
test
#(ordered#list2).
# one
# two
# three
test
#_(class_4).
# four
# five
# six
test
#_ seven
# eight
# nine
test
# one
# two
# three
test
#22 22
# 23
# 24
expect: |
<ol class="first" id="list" start="1">
<li>one</li>
<li>two</li>
<li>three</li>
</ol>
<p>test</p>
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>
<p>test</p>
<ol start="4">
<li>four</li>
<li>five</li>
<li>six</li>
</ol>
<p>test</p>
<ol start="7">
<li>seven</li>
<li>eight</li>
<li>nine</li>
</ol>
<p>test</p>
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>
<p>test</p>
<ol start="22">
<li>22</li>
<li>23</li>
<li>24</li>
</ol>
Basic Unordered lists:
input: |
h3. How about some unordered goodness?
Expand Down

0 comments on commit b7bf4e1

Please sign in to comment.