def footnotes(document):
 footnotes = domhelpers.findElementsWithAttribute(document, 'class', 'footnote')
 if (not footnotes):
  return
 footnoteElement = dom.Element('ol')
 id = 1
 for footnote in footnotes:
  href = dom.parseString(('<a href="#footnote-%(id)d"><super>%(id)d</super></a>' % vars())).documentElement
  text = ' '.join(domhelpers.getNodeText(footnote).split())
  href.setAttribute('title', text)
  target = dom.Element('a')
  target.setAttribute('name', ('footnote-%d' % (id,)))
  target.childNodes = [footnote]
  footnoteContent = dom.Element('li')
  footnoteContent.childNodes = [target]
  footnoteElement.childNodes.append(footnoteContent)
  footnote.parentNode.replaceChild(href, footnote)
  id += 1
 body = domhelpers.findNodesNamed(document, 'body')[0]
 header = dom.parseString('<h2>Footnotes</h2>').documentElement
 body.childNodes.append(header)
 body.childNodes.append(footnoteElement)

def footnotes ( document ) : footnotes = domhelpers . findElementsWithAttribute ( document , 'class' , 'footnote' ) if ( not footnotes ) : return footnoteElement = dom . Element ( 'ol' ) id = 1 for footnote in footnotes : href = dom . parseString ( ( '<a href="#footnote-%(id)d"><super>%(id)d</super></a>' % vars ( ) ) ) . documentElement text = ' ' . join ( domhelpers . getNodeText ( footnote ) . split ( ) ) href . setAttribute ( 'title' , text ) target = dom . Element ( 'a' ) target . setAttribute ( 'name' , ( 'footnote-%d' % ( id , ) ) ) target . childNodes = [ footnote ] footnoteContent = dom . Element ( 'li' ) footnoteContent . childNodes = [ target ] footnoteElement . childNodes . append ( footnoteContent ) footnote . parentNode . replaceChild ( href , footnote ) id += 1 body = domhelpers . findNodesNamed ( document , 'body' ) [ 0 ] header = dom . parseString ( '<h2>Footnotes</h2>' ) . documentElement body . childNodes . append ( header ) body . childNodes . append ( footnoteElement )
find footnotes in the given document .