Class: HParser::Inline::Footnote

Inherits:
Object
  • Object
show all
Includes:
Collectable
Defined in:
lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/inline/footnote.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, text) ⇒ Footnote

Returns a new instance of Footnote.



12
13
14
15
# File 'lib/hparser/inline/footnote.rb', line 12

def initialize(index, text)
  @index = index
  @text = text
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/hparser/inline/footnote.rb', line 11

def index
  @index
end

#textObject (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/hparser/inline/footnote.rb', line 11

def text
  @text
end

Class Method Details

.parse(scanner, context) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hparser/inline/footnote.rb', line 17

def self.parse(scanner, context)
  if scanner.scan(/\)\(\(.+?\)\)\(/) then
    # )((xxx))( -> ((xxx))
    Text.new scanner[0][1..-2]
  elsif scanner.scan(/\(\((.+?)\)\)/) then
    index = context.footnotes.length + 1
    f = Footnote.new index, scanner[0][2..-3]
    context.footnotes << f
    f
  end
end

Instance Method Details

#==(o) ⇒ Object



29
30
31
# File 'lib/hparser/inline/footnote.rb', line 29

def ==(o)
  self.class == o.class and @index == o.index and @text == o.text
end

#to_htmlObject



325
326
327
328
# File 'lib/hparser/html.rb', line 325

def to_html
  text = self.text.gsub(/<.*?>/, '')
  %(<span class="footnote"><a href="#f#{self.index}" title="#{text}" name="fn#{self.index}">*#{self.index}</a></span>)
end

#to_latexObject



260
261
262
# File 'lib/hparser/latex.rb', line 260

def to_latex
  %(\\footnote{#{self.text}})
end

#to_textObject



168
169
170
# File 'lib/hparser/text.rb', line 168

def to_text
  "(*#{self.index})"
end