Attachment 'Color2-1.9.3-1.py'

Download

   1 """
   2     MoinMoin - Color2 Macro
   3 
   4     @copyright: 2006 by Clif Kussmaul <clif@kussmaul.org>
   5                 2008 by Clif Kussmaul, Dave Hein (MoinMoin:DaveHein)
   6                 2011 by Clif Kussmaul, Dave Hein (MoinMoin:DaveHein), Gregor Mirai
   7     @license:   GNU GPL, see COPYING for details
   8 
   9     Usage: <<Color2(text,col=color,bcol=bgcolor,font=_font_)>>
  10            <<Color2(text,bcol=bgcolor)>>
  11            <<Color2(text,color)>>
  12 
  13     History:
  14     - 2011.02.23: [Moin 1.9] updated for Moin 1.9 by Gregor Mirai,
  15                   code simplified due to new parameter parsing and lots of other improvements in Moin code.
  16                   MiniPage functionality for the text parameter has been preserved.
  17     - 2008.01.25: [Moin 1.6] updated for Moin 1.6 by Dave Hein,
  18                   no functional changes.
  19     - 2006: [Moin 1.5] written by Clif Kussmaul
  20     - originally based on Color Macro
  21       Copyright (c) 2002 by Markus Gritsch <gritsch@iue.tuwien.ac.at>
  22 """
  23 
  24 from MoinMoin import wikiutil
  25 from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
  26 
  27 """
  28     Parameters that macro accepts are:
  29         - text (the text to be colored)
  30         - col  (optional text color)
  31         - bcol (optional background text color)
  32         - font (optional font)
  33 
  34     Examples:
  35 
  36     <<Color2(Hello World!,col=red,bcol=blue,font=18px courier)>>
  37     <<Color2(Hello World!,bcol=blue)>>
  38     <<Color2(Hello World!,orange)>>
  39 """
  40 
  41 def macro_Color2(macro, text=None, col=None, bcol=None, font=None):
  42     f = macro.formatter
  43 
  44     if not text:
  45         return f.strong(1) + \
  46                f.text('Color2 examples : ') + \
  47                f.text('<<Color2(Hello World!,red,blue,18px courier)>>, ') + \
  48                f.text('<<Color2(Hello World!,col=red,bcol=blue,font=18px courier)>>, ') + \
  49                f.text('<<Color2(Hello World!,#8844AA)>>') + \
  50                f.strong(0) + f.linebreak(0)
  51 
  52     style = ''
  53     if col:
  54         style += 'color:%s; '            % col
  55     if bcol:
  56         style += 'background-color:%s; ' % bcol
  57     if font:
  58         style += 'font:%s; '             % font
  59 
  60     # Escape HTML stuff.
  61     text = wikiutil.escape(text)
  62     text = wikiutil.renderText(macro.request, WikiParser, text)
  63     text = text.strip()
  64 
  65     return f.rawHTML('<span style="%s">' % style) + text + f.rawHTML('</span>')

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] (2008-01-26 14:27:02, 4.9 KB) [[attachment:Color2-1.6.py]]
  • [get | view] (2011-03-01 17:09:31, 2.3 KB) [[attachment:Color2-1.9.3-1.py]]
  • [get | view] (2011-02-23 16:33:05, 2.1 KB) [[attachment:Color2-1.9.3.py]]
  • [get | view] (2017-05-18 01:43:16, 16.3 KB) [[attachment:Color2-1.9.9.py]]
  • [get | view] (2006-09-19 15:41:58, 4.7 KB) [[attachment:Color2.py]]
  • [get | view] (2008-08-11 16:41:33, 9.8 KB) [[attachment:Color2_Example.png]]
  • [get | view] (2008-08-11 16:42:00, 20.6 KB) [[attachment:Color2_ExampleTables.png]]
  • [get | view] (2009-08-08 00:18:45, 4.9 KB) [[attachment:Color2_bar.py]]
  • [get | view] (2009-08-08 02:07:07, 1.0 KB) [[attachment:Color2_bar_example.png]]
  • [get | view] (2017-05-18 02:28:07, 80.2 KB) [[attachment:Color2_example-1.9.9-at-2017-05-17.png]]
 All files | Selected Files: delete move to page copy to page

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