Class: Jekyll::FootnoteTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
FootnoteUtils
Defined in:
lib/jekyll/footnotes.rb

Instance Method Summary collapse

Methods included from FootnoteUtils

#backlink_id, #footnote_id, #page_hash

Constructor Details

#initialize(tag_name, id, tokens) ⇒ FootnoteTag

Returns a new instance of FootnoteTag.

Raises:

  • (SyntaxError)


21
22
23
24
25
# File 'lib/jekyll/footnotes.rb', line 21

def initialize(tag_name, id, tokens)
  raise(SyntaxError.new("invalid footnote ID")) if ['"', '<', '>'].any? { |c| id.include?(c) }
  @id = id.strip unless id.strip.empty?
  super
end

Instance Method Details

#render(context) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/jekyll/footnotes.rb', line 27

def render(context)
  if @id.nil?
    context.registers[:fn] ||= 0
    context.registers[:fn] = context.registers[:fn].next
    @id = context.registers[:fn]
  end
  "<sup><a href=\"##{footnote_id(context, @id)}\" class=\"footnote\" id=\"#{backlink_id(context, @id)}\">#{@id}</a></sup>"
end