comparison MoinMoin/macro/FootNote.py @ 3243:1ad6243cdf06

macros: refactor for new arg parser
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 12 Mar 2008 00:23:45 +0100
parents b7914fb12243
children a799b224389f
comparison
equal deleted inserted replaced
3242:924a9abe5689 3243:1ad6243cdf06
16 from MoinMoin import config, wikiutil 16 from MoinMoin import config, wikiutil
17 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser 17 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
18 18
19 Dependencies = ["time"] # footnote macro cannot be cached 19 Dependencies = ["time"] # footnote macro cannot be cached
20 20
21 def execute(macro, args): 21 def macro_FootNote(macro, text=u''):
22 request = macro.request 22 request = macro.request
23 formatter = macro.formatter 23 formatter = macro.formatter
24 24
25 # create storage for footnotes 25 # create storage for footnotes
26 if not hasattr(request, 'footnotes'): 26 if not hasattr(request, 'footnotes'):
27 request.footnotes = {} 27 request.footnotes = {}
28 request.footnote_ctr = 0 28 request.footnote_ctr = 0
29 request.footnote_show_ctr = 0 29 request.footnote_show_ctr = 0
30 30
31 if not args: 31 if not text:
32 return emit_footnotes(request, formatter) 32 return emit_footnotes(request, formatter)
33 else: 33 else:
34 # grab new footnote backref number 34 # grab new footnote backref number
35 idx = request.footnote_ctr 35 idx = request.footnote_ctr
36 request.footnote_ctr += 1 36 request.footnote_ctr += 1
37 37
38 shahex = sha.new(args.encode(config.charset)).hexdigest() 38 shahex = sha.new(text.encode(config.charset)).hexdigest()
39 backlink_id = "fndef-%s-%d" % (shahex, idx) 39 backlink_id = "fndef-%s-%d" % (shahex, idx)
40 fwdlink_id = "fnref-%s" % shahex 40 fwdlink_id = "fnref-%s" % shahex
41 41
42 if not args in request.footnotes: 42 if not text in request.footnotes:
43 showidx = request.footnote_show_ctr 43 showidx = request.footnote_show_ctr
44 request.footnote_show_ctr += 1 44 request.footnote_show_ctr += 1
45 request.footnotes[args] = ([], fwdlink_id, showidx) 45 request.footnotes[text] = ([], fwdlink_id, showidx)
46 flist, dummy, showidx = request.footnotes[args] 46 flist, dummy, showidx = request.footnotes[text]
47 request.footnotes[args] = (flist + [(backlink_id, idx)], fwdlink_id, showidx) 47 request.footnotes[text] = (flist + [(backlink_id, idx)], fwdlink_id, showidx)
48 48
49 # do index -> text mapping in the same dict, that's fine because 49 # do index -> text mapping in the same dict, that's fine because
50 # args is always a string and idx alwas a number. 50 # text is always a string and idx alwas a number.
51 request.footnotes[idx] = args 51 request.footnotes[idx] = text
52 52
53 return "%s%s%s%s%s" % ( 53 return "%s%s%s%s%s" % (
54 formatter.sup(1), 54 formatter.sup(1),
55 formatter.anchorlink(1, fwdlink_id, id=backlink_id), 55 formatter.anchorlink(1, fwdlink_id, id=backlink_id),
56 formatter.text(str(showidx+1)), 56 formatter.text(str(showidx+1)),