Trait yii\apidoc\helpers\ApiMarkdownTrait

Implemented byyii\apidoc\helpers\ApiMarkdown, yii\apidoc\helpers\ApiMarkdownLaTeX
Source Code https://github.com/yiisoft/yii2-apidoc/blob/master/helpers/ApiMarkdownTrait.php

Class ApiMarkdownTrait

Property Details

Hide inherited properties

$renderingContext public property

Method Details

Hide inherited methods

consumeQuote() protected method

Consume lines for a blockquote element

protected void consumeQuote ( $lines, $current )
$lines
$current

                protected function consumeQuote($lines, $current)
{
    $block = parent::consumeQuote($lines, $current);
    $blockTypes = [
        'warning',
        'note',
        'info',
        'tip',
    ];
    // check whether this is a special Info, Note, Warning, Tip block
    $content = $block[0]['content'];
    $first = reset($content);
    if (isset($first[0]) && $first[0] === 'paragraph') {
        $parfirst = reset($first['content']);
        if (isset($parfirst[0]) && $parfirst[0] === 'text') {
            foreach ($blockTypes as $type) {
                if (strncasecmp("$type: ", $parfirst[1], $len = strlen($type) + 2) === 0) {
                    // remove block indicator
                    $block[0]['content'][0]['content'][0][1] = substr($parfirst[1], $len);
                    // add translated block indicator as bold text
                    array_unshift($block[0]['content'][0]['content'], [
                        'strong',
                        [
                            ['text', $this->translateBlockType($type)],
                        ],
                    ]);
                    $block[0]['blocktype'] = $type;
                    break;
                }
            }
        }
    }
    return $block;
}

            
parseApiLinkForContext() protected method (available since version 2.1.3)

Attempts to parse an API link for the given context.

protected array parseApiLinkForContext ( $offset, $object, $title, $context )
$offset integer
$object string
$title string|null
$context yii\apidoc\models\TypeDoc|null
throws yii\apidoc\helpers\BrokenLinkException

if the object can't be resolved

                protected function parseApiLinkForContext($offset, $object, $title, $context)
{
    if (($pos = strpos($object, '::')) !== false) {
        $typeName = substr($object, 0, $pos);
        $subjectName = substr($object, $pos + 2);
        if ($context !== null) {
            // Collection resolves relative types
            $typeName = (new Collection([$typeName], $context->phpDocContext))->__toString();
        }
        /** @var $type TypeDoc */
        $type = static::$renderer->apiContext->getType($typeName);
        if ($type === null || $subjectName === '') {
            throw new BrokenLinkException($typeName . '::' . $subjectName, $context);
        }
        if (($subject = $type->findSubject($subjectName)) === null) {
            throw new BrokenLinkException($type->name . '::' . $subjectName, $context);
        }
        if ($title === null) {
            $title = $type->name . '::' . $subject->name;
            if ($subject instanceof MethodDoc) {
                $title .= '()';
            }
        }
        return [
            ['apiLink', static::$renderer->createSubjectLink($subject, $title)],
            $offset
        ];
    }
    if ($context !== null) {
        if (($subject = $context->findSubject($object)) !== null) {
            return [
                ['apiLink', static::$renderer->createSubjectLink($subject, $title)],
                $offset
            ];
        }
        // Collection resolves relative types
        $object = (new Collection([$object], $context->phpDocContext))->__toString();
    }
    if (($type = static::$renderer->apiContext->getType($object)) !== null) {
        return [
            ['apiLink', static::$renderer->createTypeLink($type, null, $title)],
            $offset
        ];
    }
    if (strpos($typeLink = static::$renderer->createTypeLink($object, null, $title), '<a href') !== false) {
        return [
            ['apiLink', $typeLink],
            $offset
        ];
    }
    throw new BrokenLinkException($object, $context);
}

            
parseApiLinks() protected method

protected void parseApiLinks ( $text )
$text

renderApiLink() protected method

Renders API link

protected string renderApiLink ( $block )
$block array

renderBrokenApiLink() protected method

Renders API link that is broken i.e. points nowhere

protected string renderBrokenApiLink ( $block )
$block array

renderQuote() protected method

Renders a blockquote

protected void renderQuote ( $block )
$block

                protected function renderQuote($block)
{
    $class = '';
    if (isset($block['blocktype'])) {
        $class = ' class="' . $block['blocktype'] . '"';
    }
    return "<blockquote{$class}>" . $this->renderAbsy($block['content']) . "</blockquote>\n";
}

            
translateBlockType() protected abstract method (available since version 2.0.5)

protected abstract void translateBlockType ( $type )
$type

                protected abstract function translateBlockType($type);