So I was writing a post and I got fed up with manually numbering footnotes, and so I created this quick and dirty set of functions to enable footnote auto-numbering. It’s not as clever as I would prefer it to be, but it’s good ‘nuff.
[^FN]
marker in the text body whenever you would want a numbered footnote
=> gemini://url [^FN] Link description
link to the end of the document to correspond with each footnote.
# This the greatest and best song in the world > Could not remember the best song in the world. No, this is just a tribute. [^FN] -- => gemini://gemi.dev/cgi-bin/wp.cgi/view?Tribute+(song) [^FN] Tenacious D - Tribute
Would be rendered as:
# This the greatest and best song in the world > Could not remember the best song in the world. No, this is just a tribute. ¹ -- => gemini://gemi.dev/cgi-bin/wp.cgi/view?Tribute+(song) ¹ Tenacious D - Tribute
It processes footnotes in two passes: it first numbers the ones at the end of the document, then it numbers the ones in the document body. So make sure that the footnotes match up - that they are the right number and in the right order.
(Python)
FOOTNOTE_INLINE = re.compile(r'(\[\^FN\])', re.M) FOOTNOTE_END = re.compile(r'(?P=>\s\S+\s)(?P\[\^FN\])(?P .*)', re.M) def footnote_numbering(n): retstr = "" subs = { "0": "⁰", "1" : "¹", "2" : "²", "3" : "³", "4" : "⁴", "5" : "⁵", "6" : "⁶", "7" : "⁷", "8" : "⁸", "9" : "⁹" } for c in str(n): retstr += subs[c] return retstr endfn_no = 1 def process_end_footnotes(match): global endfn_no retstr = match.group("link") retstr += footnote_numbering(endfn_no) retstr += match.group("desc") endfn_no += 1 return retstr inlnfn_no = 1 def process_inline_footnotes(match): global inlnfn_no retstr = footnote_numbering(inlnfn_no) inlnfn_no += 1 return retstr def prettier_footnotes(body): body.content = re.sub(FOOTNOTE_END, process_end_footnotes, body.content) body.content = re.sub(FOOTNOTE_INLINE, process_inline_footnotes, body.content) return body
text/gemini; charset=utf-8; lang=en-GB
This content has been proxied by September (3851b).