4

I'm using WebLinkValidator to validate broken links and images in my website. But I'm using lazy loading for my images. All image source path saved in data-source attribute in the HTML tag as follows. But weblink validator doesn't validate my original image path.

<img src="default-image.png" data-source="original-image.png"/>

To overcome this issue I've planned to wrap a anchor tag around this image tag like below.

<a href="original-image.png">
   <img src="default-image.png" data-source="original-image.png"/>
</a>

For this I've used the below code in Jekyll plugin, but I cannot get the results

```

require 'kramdown' require 'nokogiri' module Jekyll class UpcaseConverter < Converter safe true priority :low

def matches(ext)
  ext =~ /^\.md$/i
end

def output_ext(ext)
  ".html"
end

def convert(content)
    content = convert(super(content))
end

def convert(content)
    doc = Nokogiri::HTML.fragment(content)
    doc.css('img').each do |image|
        image.wrap("<a href='"+ image['data-source'] +"'></a>")
    end

    return doc.to_s
end

end end

```

Arasu RRK
  • 1,078
  • 16
  • 28

0 Answers0