IndexFileAnalyzer.php 1.76 KB
Newer Older
1 2
<?php
/**
3 4 5
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
6 7 8 9 10 11 12 13
 */

namespace yii\apidoc\helpers;

use cebe\markdown\Markdown;

class IndexFileAnalyzer extends Markdown
{
14 15 16
    public $title;
    public $introduction;

17 18 19
    private $_chapter = 0;
    private $_chapters = [];

20

21 22 23 24 25 26 27 28 29
    public function analyze($text)
    {
        $this->parse($text);

        return $this->_chapters;
    }

    protected function renderHeadline($block)
    {
30
        if ($this->_chapter === 0) {
31
            $this->title = $this->renderAbsy($block['content']);
32 33 34 35 36
            $this->introduction = '';
            $this->_chapter++;
        } else {
            $this->_chapter++;
            $this->_chapters[$this->_chapter] = [
37
                'headline' => $this->renderAbsy($block['content']),
38 39 40
                'content' => [],
            ];
        }
41 42 43
        return parent::renderHeadline($block);
    }

44 45 46
    protected function renderParagraph($block)
    {
        if ($this->_chapter < 1) {
47
            $this->introduction .= $this->renderAbsy($block['content']);
48 49 50 51
        }
        return parent::renderParagraph($block);
    }

52 53
    protected function renderList($block)
    {
54
        if ($this->_chapter > 0) {
Carsten Brandt committed
55 56 57 58 59 60 61 62
            foreach ($block['items'] as $item => $absyElements) {
                foreach($absyElements as $element) {
                    if ($element[0] === 'link') {
                        $this->_chapters[$this->_chapter]['content'][] = [
                            'headline' => $this->renderAbsy($element['text']),
                            'file' => $element['url'],
                        ];
                    }
63
                }
64 65 66 67
            }
        }
        return parent::renderList($block);
    }
68
}