parent
a0867ce33a
commit
55d3818ebb
|
@ -6,10 +6,13 @@ namespace Icinga\Module\Doc;
|
|||
|
||||
require_once 'IcingaVendor/Parsedown/Parsedown.php';
|
||||
|
||||
use Icinga\Module\Doc\Exception\ChapterNotFoundException;
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use RecursiveIteratorIterator;
|
||||
use Parsedown;
|
||||
use Zend_View_Helper_Url;
|
||||
use Icinga\Module\Doc\Exception\ChapterNotFoundException;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\View;
|
||||
|
||||
/**
|
||||
|
@ -156,6 +159,24 @@ class SectionRenderer extends Renderer
|
|||
return '<pre>' . highlight_string(htmlspecialchars_decode($match[1]), true) . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace img src tags
|
||||
*
|
||||
* @param $match
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function replaceImg($match)
|
||||
{
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($match[0]);
|
||||
$xpath = new DOMXPath($doc);
|
||||
$img = $xpath->query('//img[1]')->item(0);
|
||||
/* @var $img \DOMElement */
|
||||
$img->setAttribute('src', Url::fromPath($img->getAttribute('src'))->getAbsoluteUrl());
|
||||
return substr_replace($doc->saveXML($img), '', -2, 1); // Replace '/>' with '>'
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the section
|
||||
*
|
||||
|
@ -181,6 +202,11 @@ class SectionRenderer extends Renderer
|
|||
array($this, 'highlightPhp'),
|
||||
$this->parsedown->text(implode('', $section->getContent()))
|
||||
);
|
||||
$html = preg_replace_callback(
|
||||
'/<img[^>]+>/',
|
||||
array($this, 'replaceImg'),
|
||||
$html
|
||||
);
|
||||
$content[] = preg_replace_callback(
|
||||
'/<a\s+(?P<attribs>[^>]*?\s+)?href="#(?P<fragment>[^"]+)"/',
|
||||
array($callback, 'render'),
|
||||
|
|
Loading…
Reference in New Issue