diff --git a/CHANGELOG.md b/CHANGELOG.md index f7565f762f..8ac3860bb7 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 d0eae55e23..9b491c22c1 100644 --- a/system/src/Grav/Common/Markdown/ParsedownGravTrait.php +++ b/system/src/Grav/Common/Markdown/ParsedownGravTrait.php @@ -212,6 +212,7 @@ protected function inlineImage($excerpt) $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 @@ protected function inlineImage($excerpt) $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 1b76635672..dc01f14011 100644 --- a/system/src/Grav/Common/Page/Medium/Link.php +++ b/system/src/Grav/Common/Page/Medium/Link.php @@ -36,12 +36,13 @@ public function __construct(array $attributes, Medium $medium) * @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 029583832c..20f0d297c8 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -199,10 +199,11 @@ public function urlHash($hash = null, $withHash = true) * @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 @@ public function parsedownElement($title = null, $alt = null, $class = null, $res } } + 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 @@ public function classes() */ 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 1337daa265..b51b427f23 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 522abe13a8..b9ea37e779 100644 --- a/system/src/Grav/Common/Page/Medium/RenderableInterface.php +++ b/system/src/Grav/Common/Page/Medium/RenderableInterface.php @@ -27,8 +27,9 @@ public function html($title = null, $alt = null, $class = null, $reset = true); * @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 3296fc757f..8115cbe7f1 100644 --- a/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ThumbnailImageMedium.php @@ -34,15 +34,16 @@ public function srcset($reset = true) /** * 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 28069b14d0..ec4521b4d4 100644 --- a/tests/unit/Grav/Common/Markdown/ParsedownTest.php +++ b/tests/unit/Grav/Common/Markdown/ParsedownTest.php @@ -148,6 +148,27 @@ public function testImagesSubDirAbsoluteUrls() $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();