from StringIO import StringIO from trac.util import escape from trac.WikiFormatter import wiki_to_oneliner def unescape(text): """Un-escapes &, <, > and \"""" if not text: return '' return str(text).replace('&', '&') \ .replace('<', '<') \ .replace('>', '>') \ .replace('"', '"') footnote_set = 1 footnotes = [] def execute(hdf, args, env): global footnotes, footnote_set # Display and clear footnotes... if not args: out = StringIO() out.write('
\n'); out.write('
\n'); out.write('
    \n') for i, v in enumerate(footnotes): id = "%i.%i" % (footnote_set, i + 1) out.write('
  1. %i. %s
  2. \n' % (id, id, i + 1, wiki_to_oneliner(unescape(v), hdf, env, env.get_db_cnx()))) out.write('
\n') out.write('
\n'); footnotes = [] footnote_set += 1 return out.getvalue() else: id = len(footnotes) + 1 try: id = int(args) except ValueError: existing = None for index, note in enumerate(footnotes): if args == note: existing = note id = index + 1 break if not existing: footnotes.append(args) full_id = "%i.%i" % (footnote_set, id) return '%i' % (args[:16] + "...", full_id, full_id, id)