mirror of
https://github.com/getgrav/grav.git
synced 2025-12-08 08:49:57 +01:00
various fixes
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,38 +81,54 @@ class MarkdownTest extends \Codeception\TestCase\Test
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="/item2/item2-2/missing-image.jpg" alt="" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><img src="/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
}
|
||||
|
||||
public function testImagesSubDir()
|
||||
{
|
||||
$this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
|
||||
|
||||
$this->assertRegexp('|<p><img src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
|
||||
$this->assertSame('<p><img src="/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="/subdir/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><img src="http://testing.dev/images/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
// $this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
|
||||
|
||||
$this->assertSame('<p><img src="http://testing.dev/item2/item2-2/missing-image.jpg" alt="" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><img src="http://testing.dev/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
// $this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-sample-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
// $this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-image.jpe?g" \/><\/p>|',
|
||||
// $this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><img src="/01.item1/home-sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="\/images\/.*-home-cache-image.jpe?g\?foo=1" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><img src="/01.item1/home-sample-image.jpg" /></p>',
|
||||
$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('<p><img src="http://testing.dev/subdir/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertRegexp('|<p><img src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
|
||||
$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('<p><a href="/item1/item1-3">Down a Level</a></p>',
|
||||
$this->parsedown->text('[Down a Level](item1-3)'));
|
||||
|
||||
$this->assertSame('<p><a href="/item2">Peer Page</a></p>',
|
||||
$this->parsedown->text('[Peer Page](../item2)'));
|
||||
|
||||
$this->assertSame('<p><a href="/?foo=bar">With Query</a></p>',
|
||||
$this->parsedown->text('[With Query](?foo=bar)'));
|
||||
$this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
|
||||
$this->parsedown->text('[With Param](/foo:bar)'));
|
||||
$this->assertSame('<p><a href="/#foo">With Anchor</a></p>',
|
||||
$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('<p><a href="/fr/item2">Peer Page</a></p>',
|
||||
$this->parsedown->text('[Peer Page](../item2)'));
|
||||
$this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>',
|
||||
$this->parsedown->text('[Down a Level](item1-3)'));
|
||||
$this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>',
|
||||
$this->parsedown->text('[With Query](?foo=bar)'));
|
||||
$this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
|
||||
$this->parsedown->text('[With Param](/foo:bar)'));
|
||||
$this->assertSame('<p><a href="/fr/#foo">With Anchor</a></p>',
|
||||
$this->parsedown->text('[With Anchor](#foo)'));
|
||||
}
|
||||
|
||||
|
||||
public function testAnchorLinksLangRelativeUrls()
|
||||
{
|
||||
@@ -169,8 +283,6 @@ class MarkdownTest extends \Codeception\TestCase\Test
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function testExternalLinks()
|
||||
{
|
||||
$this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
|
||||
@@ -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('<p><a href="/item2">Peer Page</a></p>',
|
||||
$this->parsedown->text('[Peer Page](../item2)'));
|
||||
// $this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>',
|
||||
// $this->parsedown->text('[Down a Level](item1-3)'));
|
||||
$this->assertSame('<p><a href="/?foo=bar">With Query</a></p>',
|
||||
$this->parsedown->text('[With Query](?foo=bar)'));
|
||||
$this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
|
||||
$this->parsedown->text('[With Param](/foo:bar)'));
|
||||
$this->assertSame('<p><a href="/#foo">With Anchor</a></p>',
|
||||
$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('<p><a href="/fr/item2">Peer Page</a></p>',
|
||||
$this->parsedown->text('[Peer Page](../item2)'));
|
||||
// $this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>',
|
||||
// $this->parsedown->text('[Down a Level](item1-3)'));
|
||||
$this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>',
|
||||
$this->parsedown->text('[With Query](?foo=bar)'));
|
||||
$this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
|
||||
$this->parsedown->text('[With Param](/foo:bar)'));
|
||||
$this->assertSame('<p><a href="/fr/#foo">With Anchor</a></p>',
|
||||
$this->parsedown->text('[With Anchor](#foo)'));
|
||||
}
|
||||
|
||||
public function testAbsoluteLinks()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user