lib/jekyll-bits/picture.rb in jekyll-bits-0.5 vs lib/jekyll-bits/picture.rb in jekyll-bits-0.6

- old
+ new

@@ -20,10 +20,11 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +require 'digest/md5' require 'liquid' # Jekyll module module Jekyll # All our custom filters @@ -51,23 +52,30 @@ end html += "' src='" if yaml.is_a?(Hash) raise "src is absent for jb_picture in #{page.url}" unless yaml['src'] html += CGI.escapeElement(yaml['src']) + md5 = Digest::MD5.new.hexdigest(yaml['src']) else html += yaml + md5 = Digest::MD5.new.hexdigest(yaml) end + md5 = md5[0, 8] html += "'" + html += " longdesc='##{md5}'" \ + if yaml.is_a?(Hash) && yaml['caption'] html += " width='#{yaml['width']}'" \ if yaml.is_a?(Hash) && yaml['width'] html += " height='#{yaml['height']}'" \ if yaml.is_a?(Hash) && yaml['height'] html += '/>' html = "<a href='#{CGI.escapeHTML(yaml['href'])}'>#{html}</a>" \ if yaml.is_a?(Hash) && yaml['href'] html = "<figure class='jb_picture'>" + html - html += "<figcaption>#{CGI.escapeHTML(yaml['caption'])}</figcaption>" \ - if yaml.is_a?(Hash) && yaml['caption'] + if yaml.is_a?(Hash) && yaml['caption'] + html += "<figcaption id='#{md5}'>" \ + "#{CGI.escapeHTML(yaml['caption'])}</figcaption>" + end html + '</figure>' end end # Box for testing and calling static methods.