code: def serialize_endnote(ctx, document, el, root):
      "Serializes endnotes."
  
      footnote_num = el.rid
  
      if el.rid not in ctx.endnote_list:
          ctx.endnote_id += 1
          ctx.endnote_list[el.rid] = ctx.endnote_id
  
      footnote_num = ctx.endnote_list[el.rid]
  
      note = etree.SubElement(root, 'sup')
      link = etree.SubElement(note, 'a')
      link.set('href', '#')
      link.text = u'{}'.format(footnote_num)
  
      fire_hooks(ctx, document, el, note, ctx.get_hook('endnote'))
  
      return roof serialize_endnote(ctx, document, el, root):
      "Serializes endnotes."
  
      footnote_num = el.rid
  
      if el.rid not in ctx.endnote_list:
          ctx.endnote_id += 1
          ctx.endnote_list[el.rid] = ctx.endnote_id
  
      footnote_num = ctx.endnote_list[el.rid]
  
      note = etree.SubElement(root, 'sup')
      link = etree.SubElement(note, 'a')
      link.set('href', '#')
      link.text = u'{}'.format(footnote_num)
  
      fire_hooks(ctx, document, el, note, ctx.get_hook('endnote'))
  
      return root
docs: Serializes endnotes.