"""Collates and generates foot-notes. Call the macro with the foot-note content as the only argument: {{{ [[FootNote(This is a footnote)]] }}} Foot-notes are numbered by the order in which they appear. To create a reference to an existing foot-note, pass the footnote number as argument to the macro: {{{ [[FootNote(1)]] }}} In addition, identical foot-notes are coalesced into one entry. The following will generate one footnote entry with two references: {{{ Some text[[FootNote(A footnote)]] and some more text [[FootNote(A footnote)]]. }}} A list of footnotes generated by one or more of the above commands is produced by calling the macro without arguments: {{{ [[FootNote]] }}} Once a set of footnotes has been displayed, a complete new set of footnotes can be created. This allows multiple sets of footnotes per page. """ from StringIO import StringIO from trac.util import escape from trac.wiki import wiki_to_oneliner def unescape(text): """Un-escapes &, <, > and \"""" if not text: return '' return unicode(text).replace('&', '&') \ .replace('<', '<') \ .replace('>', '>') \ .replace('"', '"') def execute(hdf, args, env): if not hasattr(hdf, 'footnotes'): hdf.footnotes = [] hdf.footnote_set = 1 # Display and clear footnotes... if not args: out = StringIO() out.write('