diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index b31d99fe0..cd7653803 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -255,7 +255,7 @@ trait ParsedownGravTrait $medium->urlHash($url['fragment']); } - $excerpt['element'] = $medium->parseDownElement($title, $alt, $class); + $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true); } else { // not a current page media file, see if it needs converting to relative diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 85de365d3..7beed6c3e 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -1,6 +1,7 @@ saveImage()); + $pages_dir = self::$grav['locator']->findResource('page://'); + $image_path = self::$grav['locator']->findResource('cache://images', true); + $image_dir = self::$grav['locator']->findResource('cache://images', false); + + $output = preg_replace('|^' . preg_quote($pages_dir) . '|', '', $this->saveImage()); + + if (Utils::startsWith($output, $image_path)) { + $output = '/' . $image_dir . preg_replace('|^' . preg_quote($image_path) . '|', '', $output); + } if ($reset) { $this->reset(); @@ -155,6 +164,7 @@ class ImageMedium extends Medium if (!$this->image) { $this->image(); } + return $this; } @@ -261,6 +271,7 @@ class ImageMedium extends Medium if ($this->image) { $this->image(); $this->image->clearOperations(); // Clear previously applied operations + $this->querystring(''); $this->filter(); } diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index f1ce336fd..33e734e20 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -155,7 +155,7 @@ class Medium extends Data implements RenderableInterface */ public function querystring($querystring = null, $withQuestionmark = true) { - if ($querystring) { + if (!is_null($querystring)) { $this->set('querystring', ltrim($querystring, '?&')); foreach ($this->alternatives as $alt) { diff --git a/tests/fake/nested-site/user/pages/01.item1/sample-image.jpg b/tests/fake/nested-site/user/pages/01.item1/home-cache-image.jpg similarity index 100% rename from tests/fake/nested-site/user/pages/01.item1/sample-image.jpg rename to tests/fake/nested-site/user/pages/01.item1/home-cache-image.jpg diff --git a/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg b/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg new file mode 100644 index 000000000..3170ac497 Binary files /dev/null and b/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg differ diff --git a/tests/fake/nested-site/user/pages/02.item2/02.item2-2/cache-image.jpg b/tests/fake/nested-site/user/pages/02.item2/02.item2-2/cache-image.jpg new file mode 100644 index 000000000..3170ac497 Binary files /dev/null and b/tests/fake/nested-site/user/pages/02.item2/02.item2-2/cache-image.jpg differ diff --git a/tests/unit/Grav/Common/MarkdownLinksTest.php b/tests/unit/Grav/Common/MarkdownLinksTest.php index 4384bb741..3924eb963 100644 --- a/tests/unit/Grav/Common/MarkdownLinksTest.php +++ b/tests/unit/Grav/Common/MarkdownLinksTest.php @@ -71,19 +71,63 @@ class MarkdownTest extends \Codeception\TestCase\Test { } - public function testSlugRelativeImages() + public function testImages() { $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); -// * up and down with anchor  -// * up more and down more  -// * just down  -// * down more  + $this->assertSame('

<\/p>|',
+ $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->assertSame('

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

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