Details

Applies to
moin-1.5.7 and moin-1.6.1
Purpose
automatically add a table-of-contents to pages
Description
if a (new) option is set in the wiki config file, then any page that has a level-1 or level-2 heading will automatically show a table-of-contents

Patch

   1 --- ./moin-1.5.7/MoinMoin/Page.py-orig	2006-11-04 00:14:37.000000000 +1300
   2 +++ Page.py	2007-05-02 12:02:24.000000000 +1200
   3 @@ -1249,6 +1249,16 @@
   4          elif not request.user.may.read(self.page_name):
   5              request.write("<strong>%s</strong><br>" % _("You are not allowed to view this page."))
   6          else:
   7 +            # if the config file has the "auto_toc" setting, insert a table
   8 +            # of contents if the page has any headings
   9 +            want_toc = False
  10 +            try:
  11 +                want_toc = self.cfg.auto_toc
  12 +            except:
  13 +                pass
  14 +            if want_toc and pi_format == 'wiki' and not send_missing_page and (body.find("\n= ") >= 0 or body.find("\n== ") >= 0):
  15 +                body = "[[TableOfContents(3)]]\n" + body
  16 +
  17              # parse the text and send the page content
  18              self.send_page_content(request, Parser, body,
  19                                     format_args=pi_formatargs,

autotoc.patch

   1 --- Page.py.orig        Fri Jan 18 21:42:47 2008
   2 +++ Page.py     Wed Mar 26 08:53:50 2008
   3 @@ -1161,6 +1161,16 @@
   4          elif not request.user.may.read(self.page_name):
   5              request.write("<strong>%s</strong><br>" % _("You are not allowed to view this page.", formatted=False))
   6          else:
   7 +            # if the config file has the "auto_toc" setting, insert a table
   8 +            # of contents if the page has any headings
   9 +            want_toc = True
  10 +            try:
  11 +                want_toc = self.cfg.auto_toc
  12 +            except:
  13 +                pass
  14 +            if want_toc and pi['format'] == 'wiki' and not send_missing_page and (body.find("\n= ") >= 0 or body.find("\n== ") >= 0):
  15 +                body = "<<TableOfContents>>\n" + body
  16 +
  17              # start wiki content div
  18              request.write(self.formatter.startContent(content_id))

autotoc-1.6.1.patch

Discussion

see FeatureRequests/AutoToc. I've only just started using moinmoin so maybe this isn't the best place to patch this feature in, and I don't know if it has side effects, but it "works-for-me" :)

Plan


CategoryMoinMoinPatch

MoinMoin: MoinMoinPatch/AutoTableOfContents (last edited 2008-03-26 22:59:33 by ReimarBauer)