mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
doc: Support fragment-less file links
This commit is contained in:
parent
118055c07d
commit
5f8611ffe5
@ -208,15 +208,49 @@ class DocSectionRenderer extends DocRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace link
|
* Replace chapter link
|
||||||
*
|
*
|
||||||
* @param array $match
|
* @param array $match
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function replaceLink($match)
|
protected function replaceChapterLink($match)
|
||||||
{
|
{
|
||||||
if (($section = $this->tree->getNode($this->decodeAnchor($match['fragment']))) === null) {
|
if (($chapter = $this->tree->getNode($this->decodeAnchor($match['chapter']))) === null) {
|
||||||
|
return $match[0];
|
||||||
|
}
|
||||||
|
/** @var \Icinga\Module\Doc\DocSection $section */
|
||||||
|
$path = $this->getView()->getHelper('Url')->url(
|
||||||
|
array_merge(
|
||||||
|
$this->urlParams,
|
||||||
|
array(
|
||||||
|
'chapter' => $this->encodeUrlParam($chapter->getChapter()->getId())
|
||||||
|
)
|
||||||
|
),
|
||||||
|
$this->url,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
$url = $this->getView()->url($path);
|
||||||
|
/** @var \Icinga\Web\Url $url */
|
||||||
|
return sprintf(
|
||||||
|
'<a %s%shref="%s"',
|
||||||
|
strlen($match['attribs']) ? trim($match['attribs']) . ' ' : '',
|
||||||
|
$chapter->getNoFollow() ? 'rel="nofollow" ' : '',
|
||||||
|
$url->getAbsoluteUrl()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace section link
|
||||||
|
*
|
||||||
|
* @param array $match
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function replaceSectionLink($match)
|
||||||
|
{
|
||||||
|
if (($section = $this->tree->getNode($this->decodeAnchor($match['section']))) === null) {
|
||||||
return $match[0];
|
return $match[0];
|
||||||
}
|
}
|
||||||
/** @var \Icinga\Module\Doc\DocSection $section */
|
/** @var \Icinga\Module\Doc\DocSection $section */
|
||||||
@ -292,8 +326,13 @@ class DocSectionRenderer extends DocRenderer
|
|||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
$html = preg_replace_callback(
|
$html = preg_replace_callback(
|
||||||
'/<a\s+(?P<attribs>[^>]*?\s+)?href="(?:(?!http:\/\/)[^"#]*)#(?P<fragment>[^"]+)"/',
|
'/<a\s+(?P<attribs>[^>]*?\s+)?href="(?:(?!http:\/\/)[^"#]*)#(?P<section>[^"]+)"/',
|
||||||
array($this, 'replaceLink'),
|
array($this, 'replaceSectionLink'),
|
||||||
|
$html
|
||||||
|
);
|
||||||
|
$html = preg_replace_callback(
|
||||||
|
'/<a\s+(?P<attribs>[^>]*?\s+)?href="(?:\d+-)?(?P<chapter>[^\/"#]+).md"/',
|
||||||
|
array($this, 'replaceChapterLink'),
|
||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
if ($search !== null) {
|
if ($search !== null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user