1 """
   2 Places acronym tags in html to explain words. Explanations are taken from
   3 an extra page, which is set with #pragma acronym-definitions PageName. That page
   4 must be in WikiDict format.
   5 
   6 Example:
   7 #FORMAT acronyms
   8 #pragma acronym-definitions TestDefs
   9 
  10 Explains this word: ^group^
  11 Explains the word 'groups' with the explanation from 'group': ^groups|group^ or ^group:s^
  12 
  13 TODO: If possible invalidate cache when definition page is changed.
  14 """
  15 
  16 from MoinMoin.parser import wiki
  17 from MoinMoin.wikidicts import Dict
  18 import re
  19 
  20 class Parser(wiki.Parser):
  21     def __init__(self, raw, request, **kw):
  22         self.formatting_rules = ur"(?P<acronym>\^[^\^]*\^)"+"\n" + self.formatting_rules
  23         wiki.Parser.__init__(self, raw, request, **kw)
  24         self.acronym_dict = Dict(request, request.getPragma('acronym-definitions'))
  25 
  26     def _acronym_repl(self, word):
  27         word = word[1:-1]
  28         key = word
  29         tmp = word.split('|', 1)
  30         if len(tmp) == 2:
  31             key = tmp[1]
  32             word = tmp[0]
  33         else:
  34             tmp = word.split(':', 1)
  35             if len(tmp) == 2:
  36                 key = tmp[0]
  37                 word = key + tmp[1]
  38 
  39         if not self.acronym_dict.has_key(key):
  40             return word
  41         else:
  42             return '<acronym title="%s">%s</acronym>' % (self.request.formatter.text(self.acronym_dict[key]).replace('"','&quot;'), word)
  43             

MoinMoin: parser/acronyms.py (last edited 2007-10-29 19:11:00 by localhost)