Class yii\apidoc\helpers\ApiMarkdownLaTeX
Inheritance | yii\apidoc\helpers\ApiMarkdownLaTeX » cebe\markdown\latex\GithubMarkdown |
---|---|
Uses Traits | yii\apidoc\helpers\ApiMarkdownTrait |
Available since extension's version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-apidoc/blob/master/helpers/ApiMarkdownLaTeX.php |
A Markdown helper with support for class reference links.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$renderer | yii\apidoc\renderers\BaseRenderer | yii\apidoc\helpers\ApiMarkdownLaTeX | |
$renderingContext | yii\apidoc\helpers\ApiMarkdownLaTeX |
Public Methods
Method | Description | Defined By |
---|---|---|
process() | Converts markdown into HTML | yii\apidoc\helpers\ApiMarkdownLaTeX |
Protected Methods
Method | Description | Defined By |
---|---|---|
consumeQuote() | Consume lines for a blockquote element | yii\apidoc\helpers\ApiMarkdownTrait |
parseApiLinkForContext() | Attempts to parse an API link for the given context. | yii\apidoc\helpers\ApiMarkdownTrait |
parseApiLinks() | yii\apidoc\helpers\ApiMarkdownTrait | |
renderApiLink() | yii\apidoc\helpers\ApiMarkdownLaTeX | |
renderBrokenApiLink() | yii\apidoc\helpers\ApiMarkdownLaTeX | |
renderQuote() | Renders a blockquote | yii\apidoc\helpers\ApiMarkdownLaTeX |
translateBlockType() | yii\apidoc\helpers\ApiMarkdownLaTeX |
Property Details
Method Details
Defined in: yii\apidoc\helpers\ApiMarkdownTrait::consumeQuote()
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;
}
Defined in: yii\apidoc\helpers\ApiMarkdownTrait::parseApiLinkForContext()
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);
}
protected void parseApiLinks ( $text ) | ||
$text |
protected function parseApiLinks($text)
{
if (!preg_match('/^\[\[([\w\d\\\\\(\):$]+)(\|[^\]]*)?\]\]/', $text, $matches)) {
return [['text', '[['], 2];
}
$offset = strlen($matches[0]);
$object = $matches[1];
$title = (empty($matches[2]) || $matches[2] === '|') ? null : substr($matches[2], 1);
/** @var TypeDoc[] $contexts */
$contexts = [];
$this->_findContexts($this->renderingContext, $contexts);
$contexts = array_unique($contexts, SORT_REGULAR);
$contexts[] = null;
$e = null;
foreach ($contexts as $context) {
/** @var TypeDoc|null $context */
try {
return $this->parseApiLinkForContext($offset, $object, $title, $context);
} catch (BrokenLinkException $e) {
// Keep going if there are more contexts to check
}
}
// If we made it this far, there was a broken link
/** @var BrokenLinkException $e */
static::$renderer->apiContext->errors[] = [
'file' => ($e->context !== null) ? $e->context->sourceFile : null,
'message' => $e->getMessage(),
];
return [
['brokenApiLink', '<span class="broken-link">' . $object . '</span>'],
$offset
];
}
Converts markdown into HTML
public static string process ( $content, $context = null, $paragraph = false ) | ||
$content | string | |
$context | yii\apidoc\models\TypeDoc | |
$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');
}
}
protected void renderApiLink ( $block ) | ||
$block |
protected function renderApiLink($block)
{
// TODO allow break also on camel case
$latex = '\texttt{'.str_replace(['\\textbackslash', '::'], ['\allowbreak{}\\textbackslash', '\allowbreak{}::\allowbreak{}'], $this->escapeLatex(strip_tags($block[1]))).'}';
return $latex;
}
protected void renderBrokenApiLink ( $block ) | ||
$block |
protected function renderBrokenApiLink($block)
{
return $this->renderApiLink($block);
}
Renders a blockquote
protected void renderQuote ( $block ) | ||
$block |
protected function renderQuote($block)
{
if (isset($block['blocktype'])) {
// TODO render nice icon for different block types: note, info, warning, tip
//$class = ' class="' . $block['blocktype'] . '"';
}
return '\begin{quote}' . $this->renderAbsy($block['content']) . "\\end{quote}\n";
}
protected void translateBlockType ( $type ) | ||
$type |
protected function translateBlockType($type)
{
$key = ucfirst($type) . ':';
if (isset(ApiMarkdown::$blockTranslations[$key])) {
$translation = ApiMarkdown::$blockTranslations[$key];
} else {
$translation = $key;
}
return "$translation ";
}