diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
index cd7653803..2c061046e 100644
--- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
+++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php
@@ -23,7 +23,6 @@ trait ParsedownGravTrait
/** @var Uri $uri */
protected $uri;
- protected $base_url;
protected $pages_dir;
protected $special_chars;
protected $twig_link_regex = '/\!*\[(?:.*)\]\((\{([\{%#])\s*(.*?)\s*(?:\2|\})\})\)/';
@@ -46,7 +45,6 @@ trait ParsedownGravTrait
$this->pages = $grav['pages'];
$this->uri = $grav['uri'];
$this->BlockTypes['{'] [] = "TwigTag";
- $this->base_url = rtrim(self::getGrav()['base_url_relative'] . self::getGrav()['pages']->base(), '/');
$this->pages_dir = self::getGrav()['locator']->findResource('page://');
$this->special_chars = ['>' => 'gt', '<' => 'lt', '"' => 'quot'];
@@ -215,17 +213,16 @@ trait ParsedownGravTrait
// get the local path to page media if possible
if ($path_parts['dirname'] == $this->page->url(false, false, false)) {
- $url['path'] = urldecode($path_parts['basename']);
// get the media objects for this page
$media = $this->page->media();
} else {
// see if this is an external page to this one
- $page_route = str_replace($this->base_url, '', $path_parts['dirname']);
+ $base_url = rtrim(self::getGrav()['base_url_relative'] . self::getGrav()['pages']->base(), '/');
+ $page_route = '/' . ltrim(str_replace($base_url, '', $path_parts['dirname']), '/');
$ext_page = $this->pages->dispatch($page_route, true);
if ($ext_page) {
$media = $ext_page->media();
- $url['path'] = urldecode($path_parts['basename']);
}
}
diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php
index 7b36ddcb5..f0fb6ec02 100644
--- a/system/src/Grav/Common/Uri.php
+++ b/system/src/Grav/Common/Uri.php
@@ -765,7 +765,8 @@ class Uri
$normalized_url = Utils::normalizePath($base_url . $url_path);
$normalized_path = Utils::normalizePath($pages_dir . $url_path);
} else {
- $normalized_url = $base_url . Utils::normalizePath($page->route() . '/' . $url_path);
+ $page_route = ($page->home() && !empty($url_path)) ? $page->rawRoute() : $page->route();
+ $normalized_url = $base_url . Utils::normalizePath($page_route . '/' . $url_path);
$normalized_path = Utils::normalizePath($page->path() . '/' . $url_path);
}
diff --git a/tests/unit/Grav/Common/MarkdownLinksTest.php b/tests/unit/Grav/Common/MarkdownLinksTest.php
index 3924eb963..f1f210989 100644
--- a/tests/unit/Grav/Common/MarkdownLinksTest.php
+++ b/tests/unit/Grav/Common/MarkdownLinksTest.php
@@ -81,38 +81,54 @@ class MarkdownTest extends \Codeception\TestCase\Test
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ $this->config->set('system.languages.supported', ['fr','en']);
+ unset($this->grav['language']);
+ $this->grav['language'] = new Language($this->grav);
+ $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
- }
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ }
public function testImagesSubDir()
{
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
$this->assertSame('

',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
-// $this->assertRegexp('|
<\/p>|',
-// $this->parsedown->text(''));
-
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
}
-
public function testImagesAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
-// $this->assertSame('
',
-// $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
$this->assertRegexp('|
<\/p>|',
$this->parsedown->text(''));
-
-
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
}
public function testImagesSubDirAbsoluteUrls()
@@ -120,16 +136,114 @@ class MarkdownTest extends \Codeception\TestCase\Test
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
-// $this->assertSame('
',
-// $this->parsedown->text(''));
-// $this->assertRegexp('|
<\/p>|',
-// $this->parsedown->text(''));
-// $this->assertRegexp('|
<\/p>|',
-// $this->parsedown->text(''));
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ }
+
+ public function testRootImages()
+ {
+ $this->uri->initializeWithURL('http://testing.dev/')->init();
+
+ $defaults = [
+ 'extra' => false,
+ 'auto_line_breaks' => false,
+ 'auto_url_links' => false,
+ 'escape_markup' => false,
+ 'special_chars' => ['>' => 'gt', '<' => 'lt'],
+ ];
+ $page = $this->pages->dispatch('/');
+ $this->parsedown = new Parsedown($page, $defaults);
+
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+
+ $this->config->set('system.languages.supported', ['fr','en']);
+ unset($this->grav['language']);
+ $this->grav['language'] = new Language($this->grav);
+ $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
+
+ $this->assertSame('
',
+ $this->parsedown->text(''));
}
+ public function testRootImagesSubDirAbsoluteUrls()
+ {
+ $this->config->set('system.absolute_urls', true);
+ $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
+
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertRegexp('|
<\/p>|',
+ $this->parsedown->text(''));
+ $this->assertSame('

',
+ $this->parsedown->text(''));
+ $this->assertSame('
',
+ $this->parsedown->text(''));
+ }
+
+ public function testRootAbsoluteLinks()
+ {
+ $this->uri->initializeWithURL('http://testing.dev/')->init();
+
+ $defaults = [
+ 'extra' => false,
+ 'auto_line_breaks' => false,
+ 'auto_url_links' => false,
+ 'escape_markup' => false,
+ 'special_chars' => ['>' => 'gt', '<' => 'lt'],
+ ];
+ $page = $this->pages->dispatch('/');
+ $this->parsedown = new Parsedown($page, $defaults);
+
+
+ $this->assertSame('Down a Level
',
+ $this->parsedown->text('[Down a Level](item1-3)'));
+
+ $this->assertSame('Peer Page
',
+ $this->parsedown->text('[Peer Page](../item2)'));
+
+ $this->assertSame('With Query
',
+ $this->parsedown->text('[With Query](?foo=bar)'));
+ $this->assertSame('With Param
',
+ $this->parsedown->text('[With Param](/foo:bar)'));
+ $this->assertSame('With Anchor
',
+ $this->parsedown->text('[With Anchor](#foo)'));
+
+ $this->config->set('system.languages.supported', ['fr','en']);
+ unset($this->grav['language']);
+ $this->grav['language'] = new Language($this->grav);
+ $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
+
+ $this->assertSame('Peer Page
',
+ $this->parsedown->text('[Peer Page](../item2)'));
+ $this->assertSame('Down a Level
',
+ $this->parsedown->text('[Down a Level](item1-3)'));
+ $this->assertSame('With Query
',
+ $this->parsedown->text('[With Query](?foo=bar)'));
+ $this->assertSame('With Param
',
+ $this->parsedown->text('[With Param](/foo:bar)'));
+ $this->assertSame('With Anchor
',
+ $this->parsedown->text('[With Anchor](#foo)'));
+ }
+
public function testAnchorLinksLangRelativeUrls()
{
@@ -169,8 +283,6 @@ class MarkdownTest extends \Codeception\TestCase\Test
}
-
-
public function testExternalLinks()
{
$this->assertSame('cnn.com
',
@@ -403,48 +515,6 @@ class MarkdownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'));
}
- public function testAbsoluteRootLinks()
- {
- $this->uri->initializeWithURL('http://testing.dev/')->init();
-
- $defaults = [
- 'extra' => false,
- 'auto_line_breaks' => false,
- 'auto_url_links' => false,
- 'escape_markup' => false,
- 'special_chars' => ['>' => 'gt', '<' => 'lt'],
- ];
- $page = $this->pages->dispatch('/');
- $this->parsedown = new Parsedown($page, $defaults);
-
-
- $this->assertSame('Peer Page
',
- $this->parsedown->text('[Peer Page](../item2)'));
-// $this->assertSame('Down a Level
',
-// $this->parsedown->text('[Down a Level](item1-3)'));
- $this->assertSame('With Query
',
- $this->parsedown->text('[With Query](?foo=bar)'));
- $this->assertSame('With Param
',
- $this->parsedown->text('[With Param](/foo:bar)'));
- $this->assertSame('With Anchor
',
- $this->parsedown->text('[With Anchor](#foo)'));
-
- $this->config->set('system.languages.supported', ['fr','en']);
- unset($this->grav['language']);
- $this->grav['language'] = new Language($this->grav);
- $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
-
- $this->assertSame('Peer Page
',
- $this->parsedown->text('[Peer Page](../item2)'));
-// $this->assertSame('Down a Level
',
-// $this->parsedown->text('[Down a Level](item1-3)'));
- $this->assertSame('With Query
',
- $this->parsedown->text('[With Query](?foo=bar)'));
- $this->assertSame('With Param
',
- $this->parsedown->text('[With Param](/foo:bar)'));
- $this->assertSame('With Anchor
',
- $this->parsedown->text('[With Anchor](#foo)'));
- }
public function testAbsoluteLinks()
{