Ejemplo n.º 1
0
 public function testRewindDouble()
 {
     $stack = new ezcDocumentRstStack();
     $array = array();
     array_unshift($array, 1);
     array_unshift($array, 23);
     $stack->unshift(1);
     $stack->unshift(23);
     $this->assertSame(reset($array), $stack->rewind());
 }
Ejemplo n.º 2
0
 /**
  * Reduce item to bullet list
  *
  * Called for all items, which may be part of bullet lists. Depending on
  * the indentation level we reduce some amount of items to a bullet list.
  *
  * @param ezcDocumentRstNode $node
  * @return void
  */
 protected function reduceList(ezcDocumentRstNode $node)
 {
     $childs = array();
     $lastIndentationLevel = 0;
     $nodeIndentation = $node instanceof ezcDocumentRstBlockNode ? $node->indentation : 0;
     /* DEBUG
        echo "   - Indentation {$nodeIndentation}.\n";
        // /DEBUG */
     // Include all paragraphs, lists and blockquotes
     while ($child = $this->documentStack->shift()) {
         if (!$child instanceof ezcDocumentRstBlockNode || $child->indentation < $nodeIndentation) {
             // We did not find a list to reduce to, so it is time to put
             // the stuff back to the stack and leave.
             /* DEBUG
                echo "   -> No reduction target found, reached ", ezcDocumentRstNode::getTokenName( $child->type ), ".\n";
                // /DEBUG */
             $this->documentStack->unshift($child);
             break;
         }
         if ($child->indentation === $nodeIndentation && $child->type === $node->type && ($child->type === ezcDocumentRstNode::ENUMERATED_LIST || $child->type === ezcDocumentRstNode::BULLET_LIST)) {
             // We found a list on the same level, so this is a new list
             // item.
             /* DEBUG
                echo "   => Found same level list item.\n";
                // /DEBUG */
             $child->nodes = array_merge($child->nodes, $childs);
             $this->documentStack->prepend(array($child));
             return $node;
         }
         if (($child->type === ezcDocumentRstNode::ENUMERATED_LIST || $child->type === ezcDocumentRstNode::BULLET_LIST) && $child->indentation < $lastIndentationLevel) {
             // The indentation level reduced during the processing of
             // childs. We can reduce the found childs to the new child with
             // lowest indentation.
             /* DEBUG
                echo "   -> Reduce subgroup (" . count( $childs ) . " items).\n";
                // /DEBUG */
             $child->nodes = array_merge($child->nodes, array_reverse($childs));
             $childs = array();
         }
         // Else just append item to curernt child list, and update current
         // indentation.
         /* DEBUG
            echo "   -> Appending " . ezcDocumentRstNode::getTokenName( $child->type ) . ".\n";
            // /DEBUG */
         $childs[] = $child;
         $lastIndentationLevel = $child->indentation;
     }
     // Clean up and return node
     /* DEBUG
        echo "   => Done.\n";
        // /DEBUG */
     $this->documentStack->prepend($childs);
     return $node;
 }