Attachment 'TableOfContents-1.9.3.py.patch'

Download

   1 --- TableOfContents.py.dist	2010-06-26 23:46:42.000000000 +0200
   2 +++ TableOfContents.py	2010-09-01 18:57:24.000000000 +0200
   3 @@ -167,7 +167,7 @@
   4      _ = macro.request.getText
   5  
   6      result = [
   7 -        macro.formatter.div(1, css_class="table-of-contents"),
   8 +        macro.formatter.div(1, css_class="table-of-contents", id="toc"),
   9          macro.formatter.paragraph(1, css_class="table-of-contents-heading"),
  10          macro.formatter.text(_('Contents')),
  11          macro.formatter.paragraph(0),
  12 @@ -181,21 +181,48 @@
  13          if txt is None:
  14              incl_id = id
  15              continue
  16 -        if lvl < mindepth or lvl > maxdepth or id is None:
  17 +        if lvl > maxdepth or id is None:
  18              continue
  19          if lvl < lastlvl:
  20              lastlvl = lvl
  21  
  22      # headings are 1-based, lastlvl needs to be one less so that one is closed
  23 +    # variables needed to provide with nice, leveled prefixes
  24 +    # (part of the hierarhical TOC prefix code) 
  25 +    levelnumbers = None
  26 +    levelnumbers = {}
  27 +    counter = 1
  28 +    lowest_lvl = None
  29      lastlvl -= 1
  30  
  31      for lvl, id, txt in macro.request._tocfm_collected_headings:
  32          if txt is None:
  33              incl_id = id
  34              continue
  35 -        if lvl < mindepth or lvl > maxdepth or id is None:
  36 +        if lvl > maxdepth or id is None:
  37              continue
  38  
  39 +
  40 +        # determine the lowest level available 
  41 +        # (part of the hierarhical TOC prefix)
  42 +        if lowest_lvl is None or lowest_lvl > lvl:
  43 +                lowest_lvl = lvl
  44 +
  45 +        # determine number prefix for the TOC line 
  46 +        # (part of the hierarhical TOC prefix) 
  47 +        if lvl > lastlvl:
  48 +                levelnumbers[lastlvl] = counter
  49 +                counter = 0
  50 +        elif lvl < lastlvl:
  51 +                counter = levelnumbers[lvl]
  52 +        counter = counter + 1
  53 +        levelnumbers[lvl] = counter
  54 +   
  55 +        line_number = ""
  56 +        for i in range(lowest_lvl, lvl):
  57 +                line_number = line_number + str(levelnumbers[i]) + "."
  58 +        line_number = line_number + str(counter) + "."
  59 +
  60          # will be reset by pop_unique_ids below
  61          macro.request.uid_generator.include_id = incl_id
  62  
  63 @@ -203,12 +230,12 @@
  64          while lastlvl > lvl:
  65              result.extend([
  66                  macro.formatter.listitem(0),
  67 -                macro.formatter.number_list(0),
  68 +                macro.formatter.bullet_list(0),
  69              ])
  70              lastlvl -= 1
  71          while lastlvl < lvl:
  72              result.extend([
  73 -                macro.formatter.number_list(1),
  74 +                macro.formatter.bullet_list(1, type="none"),
  75                  macro.formatter.listitem(1),
  76              ])
  77              lastlvl += 1
  78 @@ -220,13 +247,13 @@
  79          result.extend([
  80              '\n',
  81              macro.formatter.anchorlink(1, id),
  82 -            macro.formatter.text(txt),
  83 +            macro.formatter.text(line_number + " " + txt),
  84              macro.formatter.anchorlink(0),
  85          ])
  86  
  87      while lastlvl > 0:
  88          result.append(macro.formatter.listitem(0))
  89 -        result.append(macro.formatter.number_list(0))
  90 +        result.append(macro.formatter.bullet_list(0))
  91          lastlvl -= 1
  92  
  93      macro.request.uid_generator.pop()

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] (2009-03-27 02:31:52, 8.1 KB) [[attachment:TableOfContents-1.8.py]]
  • [get | view] (2009-03-27 02:27:46, 4.2 KB) [[attachment:TableOfContents-1.8.py.patch]]
  • [get | view] (2010-09-01 17:02:37, 9.0 KB) [[attachment:TableOfContents-1.9.3.py]]
  • [get | view] (2010-09-01 17:02:11, 3.2 KB) [[attachment:TableOfContents-1.9.3.py.patch]]
  • [get | view] (2009-03-27 02:31:20, 8.9 KB) [[attachment:TableOfContents-1.9beta2.py]]
  • [get | view] (2009-03-27 02:28:13, 2.8 KB) [[attachment:TableOfContents-1.9beta2.py.patch]]
 All files | Selected Files: delete move to page copy to page

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