Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Id attribute on images not working

Started by Muut Archive 10 years ago · 7 replies · 527 views
10 years ago

Hi, there. Just thought I would mention that this markdown is not working:

TXT
![](somephoto.jpg?id=some-photo)

It produces an img tag with no id attribute at all, but also without '?id=some-photo' appended to the img src as a query string (so it is being processed to some extent). Classes work fine. I am using v1.1.1

On a side note, the text area here in the forum posting box has the cursor set to 'pointer' in the css (like a link pointer), which makes it hard to edit. File is moot.css under rule '.m-input-wrap textarea'.

Thanks.

10 years ago

Never tried to output an id but I remember having to enable markdown extra for classes to be outputted. So, maybe make sure that markdown extra is enabled in your site configuration

10 years ago

I have tried it without the hyphen and it makes no difference. Interestingly, when I enable markdown extra and try it with their syntax:

TXT
![](somephoto.jpg){#somephotoid}
or
![](somephoto.jpg){.somephotoclass}

I get the same behavior: classes work, id's don't.

I was looking at some of the source code. In ParsedownGravTrait.php, in the function 'inlineImage', if I dump the variable '$excerpt' near the beginning, after the first if-else block (say line 205), I get the following:

JS
array:2 [  "extent" => 60
  "element" => array:2 [    "name" => "img"
    "attributes" => array:5 [      "src" => "/grav-site/about-me/ArtistPhoto2.jpg"
      "alt" => "Indrani Choudhury"
      "title" => null
      "id" => "indr"
      "class" => "indrani-photo"
    ]
  ]
]

It remains the same until on line 267 there is the following call:
---php
$excerpt['element'] = $medium->parseDownElement($title, $alt, $class, true);

TXT
After that $excerpt looks like this:

array:2 [▼
"extent" => 60
"element" => array:2 [▼
"name" => "img"
"attributes" => array:3 [▼
"alt" => "Indrani Choudhury"
"class" => "indrani-photo"
"src" => "/grav-site/user/pages/02.about-me/ArtistPhoto2.jpg"
]
]
]

TXT

This seems to be where the id is being lost.  It is not being passed along.  Am I missing something?
10 years ago

I just tried it on clean installs, versions 1.1.1 and 1.0.10, and got the same problem.

10 years ago

Please create an issue for this in the Grav issue tracker.

10 years ago

OK, I just did, thanks. Btw, the unit test you linked above only checks links, not img's.

10 years ago

Ah, ok, i will expand our tests to cover id on images too, and i'll dig into this further on monday.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1367 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago