I'd like to be able to create a glossary-style TOC where you don't have

  1. A

  2. B

  3. C

... but rather

for each letter. See http://bcm-specs.sipsolutions.net/Definitions for an example.

I've implemented this using this patch:

--- orig/wiki/htdocs/modern/css/common.css
+++ mod/wiki/htdocs/modern/css/common.css
@@ -112,6 +112,11 @@
        padding: 0;
 }
 
+ol.glossarylist li {
+       list-style: none;
+       display: inline;
+}
+
 .footnotes div {
        width: 5em;
        border-top: 1pt solid gray;
--- orig/MoinMoin/formatter/text_html.py
+++ mod/MoinMoin/formatter/text_html.py
@@ -530,7 +530,7 @@
 
     # Lists ##############################################################
 
-    def number_list(self, on, type=None, start=None):
+    def number_list(self, on, type=None, start=None, css_class=None):
         tag = 'ol'
         if on:
             attr = {}
@@ -538,6 +538,8 @@
                 attr['type'] = type
             if start is not None:
                 attr['start'] = start
+            if css_class is not None:
+                attr['class'] = css_class
             return self.open(tag, newline=1, attr=attr)
         return self.close(tag)
     
--- orig/MoinMoin/macro/TableOfContents.py
+++ mod/MoinMoin/macro/TableOfContents.py
@@ -58,6 +58,11 @@
             self.mindepth = 1
 
         try:
+            self.glossary = int(macro.request.getPragma('glossary', None))
+        except (ValueError, TypeError):
+            self.glossary = None
+
+        try:
             self.maxdepth = max(int(args), 1)
         except (ValueError, TypeError):
             self.maxdepth = 99
@@ -129,6 +134,10 @@
             self.baseindent = newindent - 1
             self.indent = self.baseindent
 
+        glist = False
+        if newindent == self.glossary:
+          glist = True
+
         # Close lists
         for i in range(0,self.indent-newindent):
             self.result.append(self.macro.formatter.listitem(0))
@@ -136,6 +145,9 @@
 
         # Open Lists
         for i in range(0,newindent-self.indent):
+          if glist:
+            self.result.append(self.macro.formatter.number_list(1, css_class="glossarylist"))
+          else:
             self.result.append(self.macro.formatter.number_list(1))
 
         # Add the heading

With it, you add to the page a pragma

#pragma glossary X

where X denotes the level you'd like to have the alternative list style on (this allows for having such a thing within a normal TOC), and then call the normal TableOfContents macro. I can submit patches for the other themes moinmoin ships if required. -- JohannesBerg DateTime(2005-08-05T14:58:41Z)

Discussion

Nice feature! But it can be activated in other ways, for example, adding an argument to toc macro, using Glossary macro, using special Glossary page name, etc. Can we have a more general solution that can be useful for other needs? For example, someone wanted to have a toc where only the first level items are numbered, and the rest uses bullets.

How does this work with more then one level of headings? seems that the glossary level argument is not needed.

Using [[Glossary]] macro instead of [[TableOfContents]] is easier. This macro can create a horizontal list of links from the first level headings. Isn't it enough?

Does the glossary meta data affect other page elements or rendering or it affect only the toc? can we use this meta data in other places?

Can we do this with only css? put a css class on the toc div or ol, then have different classes for glossary, custom numbering styles etc, all defined in css.

We can't add arguments to text_html formatter only, any addition must be done in all formatters. If we add arguments, should we add only css class, or more general attributes dict?


CategoryFeatureRequest CategoryMoinMoinPatch

MoinMoin: FeatureRequests/GlossaryStyleTOC (last edited 2007-10-29 19:20:45 by localhost)