mirror of
https://github.com/getgrav/grav.git
synced 2026-03-18 02:21:11 +01:00
Fix for image not rendering 'id' attribute - #956
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -148,6 +148,27 @@ class ParsedownTest extends \Codeception\TestCase\Test
|
||||
$this->parsedown->text(''));
|
||||
}
|
||||
|
||||
public function testImagesAttributes()
|
||||
{
|
||||
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
|
||||
|
||||
$this->assertSame('<p><img title="My Title" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img class="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img class="foo bar" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img alt="Alt Text" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
$this->assertSame('<p><img title="My Title" alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
|
||||
$this->parsedown->text(''));
|
||||
}
|
||||
|
||||
|
||||
public function testRootImages()
|
||||
{
|
||||
$this->uri->initializeWithURL('http://testing.dev/')->init();
|
||||
|
||||
Reference in New Issue
Block a user