protected function flush()
{
$node = null;
$this->isCode = false;
if ($this->buffer) {
switch ($this->state) {
case self::STATE_TITLE:
$data = implode("\n", $this->buffer);
$level = $this->environment->getLevel($this->specialLetter);
$token = $this->environment->createTitle($level);
$node = $this->kernel->build('Nodes\\TitleNode', $this->createSpan($data), $level, $token);
break;
case self::STATE_SEPARATOR:
$level = $this->environment->getLevel($this->specialLetter);
$node = $this->kernel->build('Nodes\\SeparatorNode', $level);
break;
case self::STATE_CODE:
$node = $this->kernel->build('Nodes\\CodeNode', $this->buffer);
break;
case self::STATE_BLOCK:
$node = $this->kernel->build('Nodes\\QuoteNode', $this->buffer);
$data = $node->getValue();
$subParser = $this->getSubParser();
$document = $subParser->parseLocal($data);
$node->setValue($document);
break;
case self::STATE_LIST:
$this->pushListLine(null, true);
$node = $this->buffer;
break;
case self::STATE_TABLE:
$node = $this->buffer;
$node->finalize($this);
break;
case self::STATE_NORMAL:
$this->isCode = $this->prepareCode();
$node = $this->kernel->build('Nodes\\ParagraphNode', $this->createSpan($this->buffer));
break;
}
}
if ($this->directive) {
$currentDirective = $this->getCurrentDirective();
if ($currentDirective) {
$currentDirective->process($this, $node, $this->directive['variable'], $this->directive['data'], $this->directive['options']);
}
$node = null;
}
$this->directive = null;
if ($node) {
$this->document->addNode($node);
}
$this->init();
}