Commit 6b603c06 by Carsten Brandt

added anchors to ApiMarkdown

fixes #2220
parent 149acbf0
......@@ -240,7 +240,7 @@ the above car dealer website as an example, we may declare the following URL rul
// ...
['class' => 'app\components\CarUrlRule', 'connectionID' => 'db', ...],
['class' => 'app\components\CarUrlRule', 'connectionID' => 'db', /* ... */],
],
],
],
......
......@@ -12,6 +12,7 @@ use phpDocumentor\Reflection\DocBlock\Type\Collection;
use yii\apidoc\models\MethodDoc;
use yii\apidoc\models\TypeDoc;
use yii\apidoc\templates\BaseRenderer;
use yii\helpers\Inflector;
use yii\helpers\Markdown;
/**
......@@ -100,7 +101,7 @@ class ApiMarkdown extends GithubMarkdown
// TODO improve code highlighting
if (strncmp($code, '<?php', 5) === 0) {
$text = highlight_string(trim($code), true);
$text = @highlight_string(trim($code), true);
} else {
$text = highlight_string("<?php ".trim($code), true);
$text = str_replace('&lt;?php', '', $text);
......@@ -201,6 +202,18 @@ class ApiMarkdown extends GithubMarkdown
}
/**
* @inheritDocs
*/
protected function renderHeadline($block)
{
$content = $this->parseInline($block['content']);
$hash = Inflector::slug(strip_tags($content));
$hashLink = "<a href=\"#$hash\" name=\"$hash\">&para;</a>";
$tag = 'h' . $block['level'];
return "<$tag>$content $hashLink</$tag>";
}
/**
* Converts markdown into HTML
*
* @param string $content
......
......@@ -9,6 +9,17 @@ use yii\helpers\Html;
\yii\apidoc\templates\bootstrap\assets\AssetBundle::register($this);
// Navbar hides initial content when jumping to in-page anchor
// https://github.com/twbs/bootstrap/issues/1768
$this->registerJs(<<<JS
var shiftWindow = function() { scrollBy(0, -50) };
if (location.hash) shiftWindow();
window.addEventListener("hashchange", shiftWindow);
JS
,
\yii\web\View::POS_HEAD
);
$this->beginPage();
?>
<!DOCTYPE html>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment