annotate MoinMoin/macro/TableOfContents.py @ 2564:92a7f41c3cad

don't overwrite rawHTML in toc macro
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jul 2007 14:36:14 +0200
parents 389e427e5bfb
children d5ef57193ccb
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - TableOfContents Macro
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
5 @copyright: 2007 MoinMoin:JohannesBerg
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
9 import re
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
10 from MoinMoin.formatter import FormatterBase
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
11 from MoinMoin.Page import Page
2563
389e427e5bfb fix slight bug with TOC macro vs. built-in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2562
diff changeset
12 from MoinMoin import wikiutil
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
15 Dependencies = ['page']
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
17 class TOCFormatter(FormatterBase):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
18 def __init__(self, request, **kw):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
19 FormatterBase.__init__(self, request, **kw)
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
20 self.in_heading = False
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
21 self.collected_headings = request._tocfm_collected_headings
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 557
diff changeset
22
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
23 def _text(self, text):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
24 if self.in_heading:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
25 self.collected_headings[-1][2] += text
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
26 return text
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
28 def heading(self, on, depth, **kw):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
29 id = kw.get('id', '')
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
30 self.in_heading = on
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
31 if on:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
32 self.collected_headings.append([depth, id, u''])
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
33 return ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
35 def macro(self, macro_obj, name, args):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
36 try:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
37 # plugins that are defined in the macro class itself
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
38 # can't generate headings this way, but that's fine
2563
389e427e5bfb fix slight bug with TOC macro vs. built-in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2562
diff changeset
39 gen_headings = wikiutil.importPlugin(self.request.cfg, 'macro',
389e427e5bfb fix slight bug with TOC macro vs. built-in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2562
diff changeset
40 name, 'generates_headings')
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
41 if gen_headings:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
42 return FormatterBase.macro(self, macro_obj, name, args)
2563
389e427e5bfb fix slight bug with TOC macro vs. built-in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2562
diff changeset
43 except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
44 pass
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
45 return ''
950
4eb66637ccd0 whitespace-only cleanup, small style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 557
diff changeset
46
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
47 def _anything_return_empty(self, *args, **kw):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
48 return ''
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
49
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
50 lang = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
51 sysmsg = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
52 startDocument = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
53 endDocument = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
54 startContent = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
55 endContent = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
56 pagelink = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
57 interwikilink = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
58 url = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
59 attachment_link = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
60 attachment_image = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
61 attachment_drawing = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
62 attachment_inlined = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
63 anchordef = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
64 line_anchordef = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
65 anchorlink = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
66 line_anchorlink = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
67 image = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
68 smiley = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
69 nowikiword = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
70 strong = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
71 emphasis = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
72 underline = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
73 highlight = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
74 sup = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
75 sub = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
76 strike = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
77 code = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
78 preformatted = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
79 small = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
80 big = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
81 code_area = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
82 code_line = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
83 code_token = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
84 linebreak = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
85 paragraph = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
86 rule = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
87 icon = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
88 number_list = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
89 bullet_list = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
90 listitem = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
91 definition_list = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
92 definition_term = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
93 definition_desc = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
94 table = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
95 table_row = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
96 table_cell = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
97 _get_bang_args = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
98 parser = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
99 div = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
100 span = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
101 escapedText = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
102 comment = _anything_return_empty
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
103
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
104 def macro_TableOfContents(macro, maxdepth=int):
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
105 """
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
106 Prints a table of contents.
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
107
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
108 maxdepth:: maximum depth the table of contents is generated for (defaults to unlimited)
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
109 """
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
110 if maxdepth is None:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
111 maxdepth = 99
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
112
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
113 pname = macro.formatter.page.page_name
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
114
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
115 macro.request._tocfm_collected_headings = []
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
116 tocfm = TOCFormatter(macro.request)
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
117 p = Page(macro.request, pname, formatter=tocfm, rev=macro.request.rev)
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
118 output = macro.request.redirectedOutput(p.send_page,
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
119 content_only=True,
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
120 count_hit=False,
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
121 omit_footnotes=True)
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
122
2564
92a7f41c3cad don't overwrite rawHTML in toc macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2563
diff changeset
123 # workaround for include macro
92a7f41c3cad don't overwrite rawHTML in toc macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2563
diff changeset
124 macro.request._page_headings = {}
92a7f41c3cad don't overwrite rawHTML in toc macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2563
diff changeset
125
2562
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
126 _ = macro.request.getText
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
127
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
128 result = [
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
129 macro.formatter.div(1, css_class="table-of-contents"),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
130 macro.formatter.paragraph(1, css_class="table-of-contents-heading"),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
131 macro.formatter.text(_('Contents', formatted=False)),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
132 macro.formatter.paragraph(0),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
133 ]
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
134
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
135 lastlvl = 0
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
136
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
137 for lvl, id, txt in macro.request._tocfm_collected_headings:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
138 if lvl > maxdepth or not id:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
139 continue
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
140 while lastlvl > lvl:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
141 result.append(macro.formatter.number_list(0))
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
142 lastlvl -= 1
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
143 while lastlvl < lvl:
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
144 result.append(macro.formatter.number_list(1))
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
145 lastlvl += 1
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
146 result.extend([
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
147 macro.formatter.listitem(1),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
148 macro.formatter.anchorlink(1, id),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
149 macro.formatter.text(txt),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
150 macro.formatter.anchorlink(0),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
151 macro.formatter.listitem(0),
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
152 ])
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
153
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
154 result.append(macro.formatter.div(0))
b76d66ed0251 new tableofcontents macro using a formatter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
155 return ''.join(result)