lib/jekyll-figure.rb in jekyll-figure-0.1.0 vs lib/jekyll-figure.rb in jekyll-figure-0.2.0

- old
+ new

@@ -1,9 +1,14 @@ +require 'utils' +require 'jekyll-figure-ref' + module Jekyll module Figure class FigureTag < Liquid::Block + include Utils + def initialize(tag_name, markup, tokens) @markup = markup super end @@ -22,24 +27,29 @@ end @settings = site.config["jekyll-figure"] @caption = attributes["caption"] @class = attributes["class"] + @label = attributes["label"] + @context = context # Caption: convert markdown and remove paragraphs unless @caption.nil? figure_caption = @caption.gsub!(/\A"|"\Z/, "") figure_caption = converter.convert(figure_caption).gsub(/<\/?p[^>]*>/, "").chomp + figure_caption = print_figure_counter(@label) + figure_caption unless @label.nil? || @label.empty? figure_caption = " <figcaption>#{figure_caption}</figcaption>\n" end # Class name(s) unless @class.nil? figure_class = @class.gsub!(/\A"|"\Z/, "") figure_class = " class\=\"#{figure_class}\"" end + figure_label = @label.nil? || @label.empty? ? "" : ' id="' + @label.gsub(/A"|"\Z/, "") + '"' + # Content if @settings && @settings["paragraphs"] == false # Strip paragraphs figure_main = converter.convert(super(context)).gsub(/<\/?p[^>]*>/, "") else @@ -49,10 +59,10 @@ # Used to escape markdown parsing rendering markdown_escape = "\ " # Render <figure> - figure_tag = "<figure#{figure_class}>" + figure_tag = "<figure#{figure_class}#{figure_label}>" figure_tag += "#{figure_main}" figure_tag += "#{figure_caption}" figure_tag += "</figure>" end end