Module: Jazzy::Markdown::Footnotes
- Included in:
- JazzyHTML
- Defined in:
- lib/jazzy/jazzy_markdown.rb
Instance Attribute Summary collapse
-
#footnotes_hash ⇒ Object
Per-render map from user to global ID.
Class Method Summary collapse
-
.next_footnote ⇒ Object
Global unique footnote ID.
Instance Method Summary collapse
-
#footnote_def(text, num) ⇒ Object
follow native redcarpet: backlink goes before the first </p> tag.
- #footnote_ref(num) ⇒ Object
- #map_footnote(user_num) ⇒ Object
- #reset ⇒ Object
Instance Attribute Details
#footnotes_hash ⇒ Object
Per-render map from user to global ID
18 19 20 |
# File 'lib/jazzy/jazzy_markdown.rb', line 18 def footnotes_hash @footnotes_hash end |
Class Method Details
.next_footnote ⇒ Object
Global unique footnote ID
12 13 14 15 |
# File 'lib/jazzy/jazzy_markdown.rb', line 12 def self.next_footnote @next_footnote ||= 0 @next_footnote += 1 end |
Instance Method Details
#footnote_def(text, num) ⇒ Object
follow native redcarpet: backlink goes before the first </p> tag
37 38 39 40 41 42 |
# File 'lib/jazzy/jazzy_markdown.rb', line 37 def footnote_def(text, num) mapped = map_footnote(num) "\n<li><div class='footnote-def' id=\"fn#{mapped}\">" + text.sub(%r{(?=</p>)}, " <a href=\"#fnref#{mapped}\">↩</a></div></li>") end |
#footnote_ref(num) ⇒ Object
30 31 32 33 34 |
# File 'lib/jazzy/jazzy_markdown.rb', line 30 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) ⇒ Object
24 25 26 27 28 |
# File 'lib/jazzy/jazzy_markdown.rb', line 24 def map_footnote(user_num) footnotes_hash.fetch(user_num) do footnotes_hash[user_num] = Footnotes.next_footnote end end |
#reset ⇒ Object
20 21 22 |
# File 'lib/jazzy/jazzy_markdown.rb', line 20 def reset @footnotes_hash = {} end |