Attachment 'ContentsAndAppendices-1.0.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - ContentsAndAppendices Macro Version 1.0, 26.10.2012
4
5 Inserts a combined table of contents and appendices (subpages) in the same format as a talbe of contents.
6
7 Usage: <<TableOfAppendices>>
8 <<TableOfAppendices(maxdpeth)>> where maxdepth limits the heading level included
9
10 @copyright: 2012 Ian Riley <ian.riley@internode.on.net>
11
12 Based on:
13 TableOfContents macro @copyright: 2007 MoinMoin:JohannesBerg
14 PageList macro @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
15 2003-2008 MoinMoin:ThomasWaldmann
16 2008 MoinMoin:ReimarBauer
17
18 @license: GNU GPL, see COPYING for details.
19 """
20
21 Dependencies = ["namespace"]
22 from MoinMoin import search, wikiutil
23
24 def execute(macro, maxdepth=int):
25 _ = macro._
26
27 maxdepth = maxdepth or 99
28
29 tocMacro = wikiutil.importPlugin(macro.cfg, u'macro', u'TableOfContents',
30 u'macro_TableOfContents')
31 result = tocMacro(macro, int(maxdepth))
32
33 pname = macro.formatter.page.page_name
34 subpnames = pname + u'/.+'
35
36 # Get sorted and formated list of subpages, sorted by name.
37 plist = search.searchPages(macro.request, subpnames,
38 titlesearch=1, case= 0, sort='page_name')
39 flist = plist.pageList(macro.request, macro.formatter, paging=False)
40
41 if flist != '<div class="searchresults">\n\n</div>':
42 result = [
43 result.replace(macro.formatter.div(0), ''),
44 '\n',
45 macro.formatter.paragraph(1),
46 macro.formatter.paragraph(0),
47 macro.formatter.paragraph(1, css_class="table-of-contents-heading"),
48 macro.formatter.text(_('Appendices')),
49 macro.formatter.paragraph(0),
50 ]
51 # Rework formated list
52 flist = flist.replace('<a', '\n<a')\
53 .replace('<strong>', '').replace('</strong>', '')\
54 .replace('>' + pname + '/', '>')
55 result.extend([
56 flist,
57 macro.formatter.div(0),
58 ])
59
60 return ''.join(result)
You are not allowed to attach a file to this page.