1 """
2 MoinMoin - FaqContents Macro
3
4 Copyright (c) 2000 by Jürgen Hermann <jh@web.de>
5 Some portions, Copyright (c) 2001 by Tim Bird <tbird@lineo.com>
6 All rights reserved, see COPYING for details.
7
8 Create a table of contents by reading all "Q." entries on the page
9
10 This is a shameless ripoff of TableOfContents, by Jürgen Hermann.
11
12 This could be improved by:
13 * making the individual entries in the Contents list links to the questions
14 However I think that doing this would require substantially more
15 intrusion into the wiki code. This is simple and works well enough for now.
16 * detecting multi-line questions, and putting a ... in the line for that
17 question.
18
19 $Id$
20 """
21
22
23 import re
24
25
26 def execute(macro, args):
27 heading = re.compile(r"^\s*(?P<hmarker>=+)\s(.*)\s(?P=hmarker)$")
28 question = re.compile(r"^\s*(?:(?:Q\.)|(?:'''Q[.:]?'''[^\s]*))\s(.*)$")
29 result = ""
30 baseindent = 0
31 indent = 0
32 lineno = 0
33
34 for line in macro.parser.lines:
35
36 lineno = lineno + 1
37 match = heading.match(line)
38 if not match:
39 match = question.match(line)
40 if not match:
41 continue
42 result = result + "<p>" + match.group(1) + "</p>"
43 continue
44
45
46 newindent = len(match.group(1))
47 if not indent:
48 baseindent = newindent - 1
49 indent = baseindent
50
51
52 for i in range(0,indent-newindent):
53 result = result + macro.formatter.number_list(0)
54
55
56 for i in range(0,newindent-indent):
57 result = result + macro.formatter.number_list(1)
58
59
60 result = result + macro.formatter.listitem(1)
61 result = result + macro.formatter.anchorlink("line%d" % lineno, match.group(2))
62 result = result + macro.formatter.listitem(0)
63
64
65 indent = newindent
66
67
68 for i in range(baseindent,indent):
69 result = result + macro.formatter.number_list(0)
70
71 return result
MoinMoin: macro/FaqContents.py (last edited 2007-10-29 19:11:11 by localhost)