Prevent nested <a> html tags when using nested img and url bbcode tags

Writing something like [url=http://www.google.com/][img]https://www.google.com/images/srpr/logo11w.png[/img][/url] will open two tabs/windows when the image is clicked, one for the image and one for the link.
This fixes it.