class Jekyll::Latex::Pdf::Figure::FigureTag

Overrides the Figure tag from jekyll-figure

Public Class Methods

new(tag_name, markup, tokens) click to toggle source
Calls superclass method
# File lib/jekyll/latex/pdf/figure/figure.rb, line 15
def initialize(tag_name, markup, tokens)
  @markup = markup
  super
end

Public Instance Methods

render(context) click to toggle source
Calls superclass method
# File lib/jekyll/latex/pdf/figure/figure.rb, line 20
def render(context)
  # Render any liquid variables
  markup = Liquid::Template.parse(@markup).render(context)

  # Extract tag attributes
  attributes = {}
  markup.scan(Liquid::TagAttributes) do |key, value|
    attributes[key] = value
  end

  @caption = attributes["caption"] if attributes.include? "caption"
  @label = attributes["label"] if attributes.include? "label"

  # Caption: convert markdown and remove paragraphs
  unless @caption.nil?
    figure_caption = @caption.gsub!(/\A"|"\Z/, "")
    figure_caption = Kramdown::Document.new(figure_caption).to_latex.strip
    figure_caption = "\\caption{#{figure_caption}}\n"
  end

  figure_main = super context

  # render figure
  figure_latex = nomarkdown_p "\\begin{figure}"
  figure_latex += nomarkdown_p "\\centering"
  figure_latex += figure_main.to_s
  figure_latex += nomarkdown_p figure_caption.to_s
  figure_latex += nomarkdown_p "\\label{#{@label}}" unless @label.nil?
  figure_latex + nomarkdown_p("\\end{figure}")
end