Class yii\apidoc\helpers\ApiMarkdownLaTeX

Inheritanceyii\apidoc\helpers\ApiMarkdownLaTeX » cebe\markdown\latex\GithubMarkdown
Uses Traitsyii\apidoc\helpers\ApiMarkdownTrait
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-apidoc/blob/master/helpers/ApiMarkdownLaTeX.php

A Markdown helper with support for class reference links.

Public Methods

Hide inherited methods

Method Description Defined By
process() Converts markdown into HTML yii\apidoc\helpers\ApiMarkdownLaTeX

Property Details

Hide inherited properties

$renderer public static property
$renderingContext protected property

Method Details

Hide inherited methods

consumeQuote() protected method

Defined in: yii\apidoc\helpers\ApiMarkdownTrait::consumeQuote()

Consume lines for a blockquote element

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

                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: ", (string) $parfirst[1], $len = strlen($type) + 2) === 0) {
                    // remove block indicator
                    $block[0]['content'][0]['content'][0][1] = substr((string) $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)

Defined in: yii\apidoc\helpers\ApiMarkdownTrait::parseApiLinkForContext()

Attempts to parse an API link for the given context.

protected array parseApiLinkForContext ( integer $offset, string $object, string|null $title, yii\apidoc\models\TypeDoc|null $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) {
            if (!$context->phpDocContext) {
                throw new BrokenLinkException($object, $context);
            }
            if (isset($context->phpDocContext->getNamespaceAliases()[$typeName])) {
                $typeName = $context->phpDocContext->getNamespaceAliases()[$typeName];
            } else {
                $typeName = $context->phpDocContext->getNamespace() . '\\' . $typeName;
            }
        }
        /** @var TypeDoc|null $type */
        $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,
            ];
        }
        if (!$context->phpDocContext) {
            throw new BrokenLinkException($object, $context);
        }
        if (isset($context->phpDocContext->getNamespaceAliases()[$object])) {
            $object = $context->phpDocContext->getNamespaceAliases()[$object];
        } else {
            $object = $context->phpDocContext->getNamespace() . '\\' . $object;
        }
    }
    if (($type = static::$renderer->apiContext->getType($object)) !== null) {
        return [
            ['apiLink', static::$renderer->createTypeLink($type, null, $title)],
            $offset,
        ];
    }
    if (str_contains((string) $typeLink = static::$renderer->createTypeLink($object, null, $title), '<a href')) {
        return [
            ['apiLink', $typeLink],
            $offset,
        ];
    }
    throw new BrokenLinkException($object, $context);
}

            
parseApiLinks() protected method
protected mixed parseApiLinks ( mixed $text )
$text mixed

process() public static method

Converts markdown into HTML

public static string process ( string $content, yii\apidoc\models\TypeDoc|string|null $context null, boolean $paragraph false )
$content string
$context yii\apidoc\models\TypeDoc|string|null
$paragraph boolean

                public static function process($content, $context = null, $paragraph = false)
{
    if (!isset(Markdown::$flavors['api-latex'])) {
        Markdown::$flavors['api-latex'] = new static();
    }
    if (is_string($context)) {
        $context = static::$renderer->apiContext->getType($context);
    }
    Markdown::$flavors['api-latex']->renderingContext = $context;
    if ($paragraph) {
        return Markdown::processParagraph($content, 'api-latex');
    } else {
        return Markdown::process($content, 'api-latex');
    }
}

            
renderApiLink() protected method

protected renderApiLink ( mixed $block )
$block mixed

renderApiLinkText() protected method
protected null|string renderApiLinkText ( null|string $title )
$title null|string

                protected function renderApiLinkText($title)
{
    if (!$title) {
        return $title;
    }
    $title = Markdown::process($title);
    $title = EncodingHelper::convertToUtf8WithHtmlEntities($title);
    $doc = new DOMDocument();
    $doc->loadHTML($title);
    return $doc->getElementsByTagName('p')[0]->childNodes[0]->c14n();
}

            
renderBrokenApiLink() protected method

protected renderBrokenApiLink ( mixed $block )
$block mixed

renderCode() protected method

protected mixed renderCode ( mixed $block )
$block mixed

                protected function renderCode($block)
{
    $language = $block['language'] ?? 'text';
    // replace No-Break Space characters in code block, which do not render in LaTeX
    $content = preg_replace("/[\x{00a0}\x{202f}]/u", ' ', (string) $block['content']);
    return implode("\n", [
        '\\begin{minted}{' . "$language}",
        $content,
        '\end{minted}',
        '',
    ]);
}

            
renderHeadline() protected method

protected mixed renderHeadline ( mixed $block )
$block mixed

                protected function renderHeadline($block)
{
    foreach ($block['content'] as $i => &$item) {
        if ($item[0] === 'inlineCode') {
            unset($block['content'][$i]);
        }
    }
    return parent::renderHeadline($block);
}

            
renderInlineCode() protected method

protected mixed renderInlineCode ( mixed $block )
$block mixed

                protected function renderInlineCode($block)
{
    // replace No-Break Space characters in code block, which do not render in LaTeX
    $content = preg_replace("/[\x{00a0}\x{202f}]/u", ' ', (string) $block[1]);
    return '\\mintinline{text}{' . str_replace("\n", ' ', $content) . '}';
}

            
renderQuote() protected method

Renders a blockquote

protected mixed renderQuote ( mixed $block )
$block mixed

                protected function renderQuote($block)
{
    return '\begin{quote}' . $this->renderAbsy($block['content']) . "\\end{quote}\n";
}

            
translateBlockType() protected method (available since version 2.0.5)

protected translateBlockType ( mixed $type )
$type mixed

                protected function translateBlockType($type)
{
    $key = ucfirst((string) $type) . ':';
    if (isset(ApiMarkdown::$blockTranslations[$key])) {
        $translation = ApiMarkdown::$blockTranslations[$key];
    } else {
        $translation = $key;
    }
    return "$translation ";
}