Merge branch 'master' of https://github.com/eteeselink/daux.io into development

* 'master' of https://github.com/eteeselink/daux.io:
  Add support for anchors on internal links

# Conflicts:
#	libs/ContentTypes/Markdown/LinkRenderer.php
This commit is contained in:
Stéphane Goetz 2016-09-21 21:49:55 +02:00
bovenliggende 519e85b5dc 047610f314
commit f8806b18b7
2 gewijzigde bestanden met toevoegingen van 17 en 3 verwijderingen

Bestand weergeven

@ -58,11 +58,13 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
throw new LinkNotFoundException("Could not locate file '$url'");
}
protected function isValidUrl($url) {
protected function isValidUrl($url)
{
return !empty($url) && $url[0] != '#';
}
protected function isExternalUrl($url) {
protected function isExternalUrl($url)
{
return preg_match('|^(?:[a-z]+:)?//|', $url);
}
@ -101,10 +103,15 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
return $element;
}
// if there's a hash component in the url, ensure we
// don't put that part through the resolver.
$urlAndHash = explode("#", $url);
$url = $urlAndHash[0];
try {
$file = $this->resolveInternalFile($url);
$url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
} catch(LinkNotFoundException $e) {
} catch (LinkNotFoundException $e) {
if ($this->daux->isStatic()) {
throw $e;
}
@ -112,6 +119,10 @@ class LinkRenderer extends \League\CommonMark\Inline\Renderer\LinkRenderer
$element->setAttribute('class', 'broken');
}
if (isset($urlAndHash[1])) {
$url .= "#" . $urlAndHash[1];
}
$element->setAttribute('href', $url);
return $element;

Bestand weergeven

@ -45,6 +45,9 @@ class LinkRendererTest extends \PHPUnit_Framework_TestCase
['<a href="Button.html">Link</a>', '[Link](./Button)', 'Widgets/Page.html'],
['<a href="Button.html">Link</a>', '[Link](!Widgets/Button)', 'Widgets/Page.html'],
['<a href="Button.html#Test">Link</a>', '[Link](./Button#Test)', 'Widgets/Page.html'],
['<a href="Button.html#Test">Link</a>', '[Link](!Widgets/Button#Test)', 'Widgets/Page.html'],
// /Content/Page
['<a href="../Widgets/Button.html">Link</a>', '[Link](../Widgets/Button.md)', 'Content/Page.html'],
['<a href="../Widgets/Button.html">Link</a>', '[Link](!Widgets/Button)', 'Content/Page.html'],