Skip to content

Instantly share code, notes, and snippets.

@bentomas
Created July 30, 2010 06:22
Show Gist options
  • Save bentomas/500015 to your computer and use it in GitHub Desktop.
Save bentomas/500015 to your computer and use it in GitHub Desktop.
def render_footnotes()
div = Element.new 'div'
div.attributes['class'] = 'footnotes'
div << Element.new('hr')
ol = Element.new 'ol'
@doc.footnotes_order.each_with_index do |fid, i| num = i+1
f = self.footnotes[fid]
if f
li = f.wrap_as_element('li')
li.attributes['id'] = "#{get_setting(:doc_prefix)}fn:#{num}"
a = Element.new 'a'
a.attributes['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}"
a.attributes['rev'] = 'footnote'
a<< Text.new('&#8617;', true, nil, true)
last = nil
li.children.each do |child|
if child.node_type != :text
last = child
end
end
if last and last.name == "p"
last.add_text(' ');
last.add(a);
else
li.insert_after(li.children.last, a)
end
ol << li
else
maruku_error "Could not find footnote id '#{fid}' among ["+
self.footnotes.keys.map{|s|"'"+s+"'"}.join(', ')+"]."
end
end
div << ol
div
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment