trilbymedia / grav-plugin-image-captions

MIT License
10 stars 3 forks source link

Link tag does not get wrapped by figure #2

Closed talu-zz closed 5 years ago

talu-zz commented 6 years ago

Hi,

it seems like a linked image lost its link when using the image caption plugin since the link is not wrapped by the figure tag.

The markdown

![](Foto-aussen.jpg?lightbox=1200&classes=caption "Some caption")

produces the following html

<p><a rel="lightbox" href="/Foto-aussen.jpg"></a></p>
<figure class="image-caption">
  <img title="Some caption" alt="" class="caption" src="/Foto-aussen.jpg">
  <figcaption class="">Some caption</figcaption>
</figure>

I think if the image is wrapped by a link, the link element and not the image itself should be used as figure children.

rhukster commented 6 years ago

When i wrap an image in a link i get this:

[![My Image Alt Text](P.jpg?classes=caption,figure-right "My Image Caption")](http://www.google.com)
<p>
<a href="http://www.google.com">
<figure class="image-caption figure-right">
<img title="My Image Caption" alt="My Image Alt Text" class="caption figure-right" src="/grav-demo-sampler/user/pages/06.core/01.markdown/P.jpg">
<figcaption class="">My Image Caption</figcaption>
</figure>
</a>
</p>
alexsoin commented 5 years ago

I have the same problem, I write:

[![My Image Alt Text](ico.png?classes=caption,figure-right "My Image Caption")](http://www.google.com)
[![My Image Alt Text](ico.png?classes=caption,figure-right "My Image Caption")](http://www.google.com)

I get the output:

<p><a href="http://www.google.com"></a></p>
<figure class="image-caption figure-right"><a href="http://www.google.com"><img title="My Image Caption" alt="My Image Alt Text"
            class="caption figure-right" src="/user/pages/01.home/ico.png">
        <figcaption class="">My Image Caption</figcaption>
    </a></figure>
<a href="http://www.google.com">
    <figure class="image-caption figure-right"><img title="My Image Caption" alt="My Image Alt Text" class="caption figure-right"
            src="/user/pages/01.home/ico.png">
        <figcaption class="">My Image Caption</figcaption>
    </figure>
</a>
<p></p>

if I disable the plugin, then the output:

<p>
    <a href="http://www.google.com"><img title="My Image Caption" alt="My Image Alt Text" class="caption figure-right" src="/user/pages/01.home/ico.png"></a>
    <a href="http://www.google.com"><img title="My Image Caption" alt="My Image Alt Text" class="caption figure-right" src="/user/pages/01.home/ico.png"></a>
</p>
alexsoin commented 5 years ago

This fix does not work. I updated the file image-captions.php, but nothing has changed

rhukster commented 5 years ago

Did you clear cache?

If that doesn’t help, please zip up a sample page for me as my fix sorts all my test cases.

rhukster commented 5 years ago

Ok, made another fix that does seem to work with your content

alexsoin commented 5 years ago

No, all the same. I have already tried to completely remove and clone the plugin, nothing has changed

rhukster commented 5 years ago

Ok, fixed your problem. It was related to the extra spacing you had in your links:

[ ![Шпаргалка: команды в линуксе](ico.png?classes=caption "Шпаргалка: команды в линуксе") ](/articles/bash-cribs)

rather than:

[![Шпаргалка: команды в линуксе](ico.png?classes=caption "Шпаргалка: команды в линуксе")](/articles/bash-cribs)

That I had in my testing

rhukster commented 5 years ago

BTW released 2.0.0 which contains this.