Class: Jekyll::Latex::Pdf::Figure::FigureTag

Inherits:
Liquid::Block
  • Object
show all
Includes:
Utilities
Defined in:
lib/jekyll/latex/pdf/figure/figure.rb

Overview

Overrides the Figure tag from jekyll-figure

Instance Method Summary collapse

Methods included from Utilities

#nomarkdown, #nomarkdown_p, #run_cmds, #set_context_to

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ FigureTag

Returns a new instance of FigureTag.



15
16
17
18
# File 'lib/jekyll/latex/pdf/figure/figure.rb', line 15

def initialize(tag_name, markup, tokens)
  @markup = markup
  super
end

Instance Method Details

#render(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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