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
20 21 22 |
# File 'lib/jazzy/jazzy_markdown.rb', line 20 def footnotes_hash @footnotes_hash end |
Class Method Details
.next_footnote ⇒ Object
Global unique footnote ID
14 15 16 17 |
# File 'lib/jazzy/jazzy_markdown.rb', line 14 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
39 40 41 42 43 44 45 |
# 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>)}, " <a href=\"#fnref#{mapped}\">↩</a>") + '</div></li>' end |
#footnote_ref(num) ⇒ Object
32 33 34 35 36 |
# 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) ⇒ Object
26 27 28 29 30 |
# 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 ⇒ Object
22 23 24 |
# File 'lib/jazzy/jazzy_markdown.rb', line 22 def reset @footnotes_hash = {} end |