lib/hemingway/latex_nodes.rb in hemingway-0.0.3 vs lib/hemingway/latex_nodes.rb in hemingway-1.0.0
- old
+ new
@@ -4,40 +4,51 @@
def html
footnote_content = []
paragraph_html = ""
elements.each do |e|
- paragraph_html += e.html(footnote_content.size)
- footnote_content += e.footnote_html(footnote_content.size)
+ # Time.now.to_f => 123123.1231231
+ time = Time.now.to_f.to_s.gsub(".", "-")
+ paragraph_html += e.html(footnote_content.size, time)
+ footnote_content += e.footnote_html(footnote_content.size, time)
end
footnote_html = footnote_content.join
Build.tag("div", paragraph_html + footnote_html, :class => "entry")
end
end
module ParagraphNode
- def html(footnote_seed)
+
+ # I'm passing in a time variable here to make links unique. You see,
+ # if you parse many of these entries on a single HTML page you'll end up
+ # with multiple #footnote1 divs. To make them unique, we'll pass down
+ # a time variable from above to seed them.
+ def html(footnote_seed, time)
paragraph_content = sequence.elements.map do |element|
if element.respond_to?(:footnote_html)
footnote_seed += 1
- element.html(footnote_seed)
+ element.html(footnote_seed, time)
elsif element.respond_to?(:newline)
element.newline.html
else
element.html
end
end.join
Build.tag("p", paragraph_content)
end
- def footnote_html(footnote_seed)
+ # I'm passing in a time variable here to make links unique. You see,
+ # if you parse many of these entries on a single HTML page you'll end up
+ # with multiple #footnote1 divs. To make them unique, we'll pass down
+ # a time variable from above to seed them.
+ def footnote_html(footnote_seed, time)
footnote_content = sequence.elements.reduce([]) do |memo, element|
if element.respond_to?(:footnote_html)
footnote_seed += 1
- memo + [element.footnote_html(footnote_seed)]
+ memo + [element.footnote_html(footnote_seed, time)]
else
memo
end
end
end
\ No newline at end of file