module Jazzy::Markdown::Footnotes

Attributes

footnotes_hash[RW]

Per-render map from user to global ID

Public Class Methods

next_footnote() click to toggle source

Global unique footnote ID

# File lib/jazzy/jazzy_markdown.rb, line 14
def self.next_footnote
  @next_footnote ||= 0
  @next_footnote += 1
end

Public Instance Methods

footnote_def(text, num) click to toggle source

follow native redcarpet: backlink goes before the first </p> tag

# File lib/jazzy/jazzy_markdown.rb, line 39
def footnote_def(text, num)
  mapped = map_footnote(num)
  "\n<li><div class='footnote-def' id=\"fn#{mapped}\">" +
    text.sub(%r{(?=</p>)},
             "&nbsp;<a href=\"#fnref#{mapped}\">&#8617;</a>") +
    '</div></li>'
end
footnote_ref(num) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 32
def footnote_ref(num)
  mapped = map_footnote(num)
  "<span class='footnote-ref' id=\"fnref#{mapped}\">" \
    "<sup><a href=\"#fn#{mapped}\">#{num}</a></sup></span>"
end
map_footnote(user_num) click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 26
def map_footnote(user_num)
  footnotes_hash.fetch(user_num) do
    footnotes_hash[user_num] = Footnotes.next_footnote
  end
end
reset() click to toggle source
# File lib/jazzy/jazzy_markdown.rb, line 22
def reset
  @footnotes_hash = {}
end