diff --git a/CHANGELOG.md b/CHANGELOG.md index f7565f762..8ac3860bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,13 @@ * Improved `authorize` Twig extension to accept a nested array of authorizations [#948](https://github.com/getgrav/grav/issues/948) * Don't add timestamps on remote assets as it can cause conflicts * Grav now looks at types from `media.yaml` when retrieving page mime types [#966](https://github.com/getgrav/grav/issues/966) + * Added support for dumping exceptions in the Debugger 1. [](#bugfix) * Fixed `Folder::delete` method to recursively remove files and folders and causing Upgrade to fail. * Fix [#952](https://github.com/getgrav/grav/issues/952) hypenize the session name. * If no parent is set and siblings collection is called, return a new and empty collection [grav-plugin-sitemap/issues/22](https://github.com/getgrav/grav-plugin-sitemap/issues/22) * Prevent exception being thrown when calling the Collator constructor failed in a Windows environment with the Intl PHP Extension enabled [#961](https://github.com/getgrav/grav/issues/961) + * Fix for markdown images not properly rendering `id` attribute [#956](https://github.com/getgrav/grav/issues/956) # v1.1.1 ## 07/16/2016 diff --git a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php index d0eae55e2..9b491c22c 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -212,6 +212,7 @@ trait ParsedownGravTrait $alt = $excerpt['element']['attributes']['alt'] ?: ''; $title = $excerpt['element']['attributes']['title'] ?: ''; $class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : ''; + $id = isset($excerpt['element']['attributes']['id']) ? $excerpt['element']['attributes']['id'] : ''; //get the url and parse it $url = parse_url(htmlspecialchars_decode($excerpt['element']['attributes']['src'])); @@ -264,7 +265,7 @@ trait ParsedownGravTrait $medium->urlHash($url['fragment']); } - $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true); + $excerpt['element'] = $medium->parseDownElement($title, $alt, $class, $id, true); } else { // not a current page media file, see if it needs converting to relative diff --git a/system/src/Grav/Common/Page/Medium/Link.php b/system/src/Grav/Common/Page/Medium/Link.php index 1b7663567..dc01f1401 100644 --- a/system/src/Grav/Common/Page/Medium/Link.php +++ b/system/src/Grav/Common/Page/Medium/Link.php @@ -36,12 +36,13 @@ class Link implements RenderableInterface * @param string $title * @param string $alt * @param string $class + * @param string $id * @param boolean $reset * @return array */ - public function parsedownElement($title = null, $alt = null, $class = null, $reset = true) + public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true) { - $innerElement = $this->source->parsedownElement($title, $alt, $class, $reset); + $innerElement = $this->source->parsedownElement($title, $alt, $class, $id, $reset); return [ 'name' => 'a', diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index 029583832..20f0d297c 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -199,10 +199,11 @@ class Medium extends Data implements RenderableInterface * @param string $title * @param string $alt * @param string $class + * @param string $id * @param boolean $reset * @return array */ - public function parsedownElement($title = null, $alt = null, $class = null, $reset = true) + public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true) { $attributes = $this->attributes; @@ -241,6 +242,14 @@ class Medium extends Data implements RenderableInterface } } + if (empty($attributes['id'])) { + if (!empty($id)) { + $attributes['id'] = $id; + } elseif (!empty($this->items['id'])) { + $attributes['id'] = $this->items['id']; + } + } + switch ($this->mode) { case 'text': $element = $this->textParsedownElement($attributes, false); @@ -417,6 +426,7 @@ class Medium extends Data implements RenderableInterface */ public function id($id) { + xdebug_break(); if (is_string($id)) { $this->attributes['id'] = trim($id); } diff --git a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php index 1337daa26..b51b427f2 100644 --- a/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php +++ b/system/src/Grav/Common/Page/Medium/ParsedownHtmlTrait.php @@ -21,13 +21,15 @@ trait ParsedownHtmlTrait * Return HTML markup from the medium. * * @param string $title + * @param string $alt * @param string $class + * @param string $id * @param bool $reset * @return string */ - public function html($title = null, $alt = null, $class = null, $reset = true) + public function html($title = null, $alt = null, $class = null, $id = null, $reset = true) { - $element = $this->parsedownElement($title, $alt, $class, $reset); + $element = $this->parsedownElement($title, $alt, $class, $id, $reset); if (!$this->parsedown) { $this->parsedown = new Parsedown(null, null); diff --git a/system/src/Grav/Common/Page/Medium/RenderableInterface.php b/system/src/Grav/Common/Page/Medium/RenderableInterface.php index 522abe13a..b9ea37e77 100644 --- a/system/src/Grav/Common/Page/Medium/RenderableInterface.php +++ b/system/src/Grav/Common/Page/Medium/RenderableInterface.php @@ -27,8 +27,9 @@ interface RenderableInterface * @param string $title * @param string $alt * @param string $class + * @param string $id * @param bool $reset * @return string */ - public function parsedownElement($title = null, $alt = null, $class = null, $reset = true); + public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true); } diff --git a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php index 3296fc757..8115cbe7f 100644 --- a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php @@ -34,15 +34,16 @@ class ThumbnailImageMedium extends ImageMedium /** * Get an element (is array) that can be rendered by the Parsedown engine * - * @param string $title - * @param string $alt - * @param string $class + * @param string $title + * @param string $alt + * @param string $class + * @param string $id * @param boolean $reset * @return array */ - public function parsedownElement($title = null, $alt = null, $class = null, $reset = true) + public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true) { - return $this->bubble('parsedownElement', [$title, $alt, $class, $reset]); + return $this->bubble('parsedownElement', [$title, $alt, $class, $id, $reset]); } /** diff --git a/tests/unit/Grav/Common/Markdown/ParsedownTest.php b/tests/unit/Grav/Common/Markdown/ParsedownTest.php index 28069b14d..ec4521b4d 100644 --- a/tests/unit/Grav/Common/Markdown/ParsedownTest.php +++ b/tests/unit/Grav/Common/Markdown/ParsedownTest.php @@ -148,6 +148,27 @@ class ParsedownTest extends \Codeception\TestCase\Test $this->parsedown->text('![](/home-missing-image.jpg)')); } + public function testImagesAttributes() + { + $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init(); + + $this->assertSame('

', + $this->parsedown->text('![](sample-image.jpg "My Title")')); + $this->assertSame('

', + $this->parsedown->text('![](sample-image.jpg?classes=foo)')); + $this->assertSame('

', + $this->parsedown->text('![](sample-image.jpg?classes=foo,bar)')); + $this->assertSame('

', + $this->parsedown->text('![](sample-image.jpg?id=foo)')); + $this->assertSame('

Alt Text

', + $this->parsedown->text('![Alt Text](sample-image.jpg?id=foo)')); + $this->assertSame('

Alt Text

', + $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo)')); + $this->assertSame('

Alt Text

', + $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo "My Title")')); + } + + public function testRootImages() { $this->uri->initializeWithURL('http://testing.dev/')->init();