Proper replacement for images with classes or wrapped in <a> tags

Fixes image tags detection.
Without this patch, the following:

```
![alt-text](image-url@size-info)
```

Becomes (without being modified by the plugin):

```
<a target="_blank" href="image-url@size-info">
  <img class="img-responsive" alt="alt-text" src="image-url@size-info"/>
</a>
```

After the patch, it becomes:

```
<a target="_blank" href="image-url">
    <img class="img-responsive" alt="alt-text" src="image-url" onload="size-info usage"/>
</a>
```