Attachment 'quote.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Blockquote Parser
   4 
   5     Heavily inspired by Nir Soffer's marvelous Section Parser
   6 
   7     For proper functioning of the parser you need to install
   8     header.py in your MoinMoin/util directory, add some css
   9     formatter stuff to e.g. common.css and provide a
  10     translation for _('Source').
  11 
  12     Header.py is taken from Section Parser and modified for
  13     Blockquote Parser. For having more accessible layout fun
  14     do also install Section Parser which allows to have nice
  15     layout in a simple and maintainable way.
  16 
  17     Section Parser
  18     @copyright: 2005 by Nir Soffer <nirs@freeshell.org>
  19     @license: GNU GPL, see COPYING for details.
  20 
  21     Blockquote Parser
  22     @copyright: 2007 by Oliver Siemoneit
  23     @license: GNU GPL, see COPYING for details.
  24 """
  25 
  26 from MoinMoin import wikiutil, i18n
  27 from MoinMoin.util.header import Header
  28 
  29 Dependencies = []
  30 
  31 class Parser:
  32     """
  33         Outputs wiki markup in a html <blockquote cite=".." lang=".." dir=".."> element.
  34     """
  35 
  36     Dependencies = []
  37     
  38     def __init__(self, raw, request, **kw):
  39         self.raw = raw
  40         self.request = request
  41         self.form = request.form
  42         self._ = request.getText
  43 
  44     def _get_formatterName(self, formatter):
  45         # XXX remove this function again. It's just a workaround since FormatterBase
  46         # has no 'def blockquote' yet.
  47         import inspect
  48         for key, value in inspect.getmembers(formatter, inspect.isclass(formatter)):
  49             if key == '__module__':
  50                 return value
  51         return ''
  52 
  53     def format(self, formatter):
  54         """ Send the text. """
  55         _ = self._
  56         self.header = Header(self.request, self.raw)
  57         # parse header
  58         source = self.header.get('cite', None)
  59         cite = ''
  60         if source:
  61             cite = ' cite="%s"' % wikiutil.escape(source)
  62         lang = ' lang="%s" dir="%s"' % (self.header.get('language', self.request.content_lang),
  63                                         i18n.getDirection(self.header.get('language', self.request.content_lang)))
  64         # ouput blockquote
  65 
  66         # XXX
  67         # do not use "formatter.rawHTML('<blockquote>')" but
  68         # "formatter.blockquote(1, cite=, lang=, dir=)... formatter.blockquote(0)"
  69         # so as not to violate ouput abstraction.
  70         try: 
  71             Parser = wikiutil.importPlugin(self.request.cfg, 'parser', 'text_moin_wiki', 'Parser')
  72             wiki_parser = Parser(self.raw[self.header.length():], self.request)
  73 
  74             if self._get_formatterName(formatter) == 'MoinMoin.formatter.text_html':
  75                 self.request.write(formatter.rawHTML('<blockquote%s%s>' % (cite, lang)))       
  76                 wiki_parser.format(formatter)
  77                 if cite:
  78                     self.request.write(formatter.rawHTML('<p class="quotesource">%s: %s</p>' % (_('Source'),
  79                                                                                                 wikiutil.escape(source))))
  80                 self.request.write(formatter.rawHTML('</blockquote>\n'))
  81             else:
  82                 wiki_parser.format(formatter)
  83         except:
  84             self.request.write(formatter.sysmsg(1) + 
  85                 formatter.text(_('Error while trying to parse blockquote')) +
  86                 formatter.sysmsg(0))
  87  

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] (2007-02-08 23:13:48, 0.7 KB) [[attachment:common.css]]
  • [get | view] (2009-10-12 14:36:42, 4.8 KB) [[attachment:header.py]]
  • [get | view] (2009-10-12 14:36:39, 3.2 KB) [[attachment:quote.py]]
  • [get | view] (2007-02-08 23:13:31, 3.1 KB) [[attachment:quote.zip]]
  • [get | view] (2007-02-08 23:11:02, 57.9 KB) [[attachment:screenshot.jpg]]
 All files | Selected Files: delete move to page copy to page

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