Doku_Handler_Block::closeParagraph PHP Метод

closeParagraph() публичный Метод

This function makes sure there are no empty paragraphs on the stack
Автор: Andreas Gohr ([email protected])
public closeParagraph ( $pos )
    function closeParagraph($pos)
    {
        if (!$this->inParagraph) {
            return;
        }
        // look back if there was any content - we don't want empty paragraphs
        $content = '';
        $ccount = count($this->calls);
        for ($i = $ccount - 1; $i >= 0; $i--) {
            if ($this->calls[$i][0] == 'p_open') {
                break;
            } elseif ($this->calls[$i][0] == 'cdata') {
                $content .= $this->calls[$i][1][0];
            } else {
                $content = 'found markup';
                break;
            }
        }
        if (trim($content) == '') {
            //remove the whole paragraph
            //array_splice($this->calls,$i); // <- this is much slower than the loop below
            for ($x = $ccount; $x > $i; $x--) {
                array_pop($this->calls);
            }
        } else {
            // remove ending linebreaks in the paragraph
            $i = count($this->calls) - 1;
            if ($this->calls[$i][0] == 'cdata') {
                $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0], DOKU_PARSER_EOL);
            }
            $this->calls[] = array('p_close', array(), $pos);
        }
        $this->inParagraph = false;
        $this->skipEol = true;
    }