Attachment 'patch-TableOfContents-mindepth.diff'

Download

   1 # HG changeset patch
   2 # User Paul Boddie <paul@boddie.org.uk>
   3 # Date 1296864641 -3600
   4 # Node ID 6cd0ccfc8dcd328a55fe128de27f4fa51a864394
   5 # Parent  cb354dd67783be0dbc71ff48b4f13c0fa3742374
   6 Added an optional minimum heading depth argument to the TableOfContents macro.
   7 
   8 diff -r cb354dd67783 -r 6cd0ccfc8dcd MoinMoin/macro/TableOfContents.py
   9 --- a/MoinMoin/macro/TableOfContents.py	Sun Oct 03 00:53:07 2010 +0200
  10 +++ b/MoinMoin/macro/TableOfContents.py	Sat Feb 05 01:10:41 2011 +0100
  11 @@ -131,19 +131,31 @@
  12      comment = _anything_return_empty
  13      transclusion = _anything_return_empty
  14  
  15 -def macro_TableOfContents(macro, maxdepth=int):
  16 +def macro_TableOfContents(macro, min_or_maxdepth=int, maxdepth=int):
  17      """
  18  Prints a table of contents.
  19  
  20 + mindepth:: minimum depth the table of contents is generated for (defaults to 1)
  21   maxdepth:: maximum depth the table of contents is generated for (defaults to unlimited)
  22      """
  23 -    try:
  24 -        mindepth = int(macro.request.getPragma('section-numbers', 1))
  25 -    except (ValueError, TypeError):
  26 -        mindepth = 1
  27  
  28 -    if maxdepth is None:
  29 -        maxdepth = 99
  30 +    # if both parameters are specified, they provide the limits of heading
  31 +    # inclusion in the table.
  32 +    if maxdepth is not None:
  33 +        mindepth = min_or_maxdepth
  34 +
  35 +    # if the explicit maxdepth parameter is None, min_or_maxdepth determines
  36 +    # maximum depth.
  37 +    else:
  38 +        try:
  39 +            mindepth = int(macro.request.getPragma('section-numbers', 1))
  40 +        except (ValueError, TypeError):
  41 +            mindepth = 1
  42 +
  43 +        if min_or_maxdepth is None:
  44 +            maxdepth = 99
  45 +        else:
  46 +            maxdepth = min_or_maxdepth
  47  
  48      pname = macro.formatter.page.page_name
  49  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-02-05 00:24:57, 1.7 KB) [[attachment:patch-TableOfContents-mindepth.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.