Changeset 3720

Show
Ignore:
Timestamp:
05/27/08 01:33:19 (6 months ago)
Author:
pacopablo
Message:

Added the option of specifying the number of columns to use for wrapping. 0.11 branch is tested, 0.10 is untested, though should work fine. Closes #2584

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • emailprocessormacro/0.10/emailprocessor.py

    r3716 r3720  
    1818    """Email wrapping formatter 
    1919 
    20     This macro takes an email message and will wrap lines to 72 characters. 
    21     It will also put the emails inside a preformatted block. 
     20    This macro takes an email message and will wrap lines to  
     21    72 characters (default), or a length specified.  It will 
     22    also put the emails inside a preformatted block. 
    2223 
    2324    Invocation: 
     
    2627    <email stuff here> 
    2728    }}} 
     29    To wrap to a specified length, the line imediately following 
     30    the invocation should contain `cols: ` followed by the number 
     31    of columns at wich we wrap.  For example: 
     32    {{{ 
     33    #!email 
     34    cols: 40 
     35    <email stuff here> 
     36    }}} 
     37    It is important that the `cols:` starts at the beginning of 
     38    the line and that only a number follows it. 
    2839 
    2940    """ 
     
    3546 
    3647    def render_macro(self, req, name, content):  
    37         text = content and wrap(content, cols=72) or '' 
     48        text = '' 
     49        if content: 
     50            lines = content.split('\n') 
     51            if lines[0].startswith('cols:'): 
     52                try: 
     53                    width = int(lines[0][5:].strip()) 
     54                    lines.pop(0) 
     55                except ValueError: 
     56                    width = 72 
     57            else: 
     58                width = 72 
     59            text = wrap('\n'.join(lines), cols=width) 
    3860        return Markup("<pre class='wiki'>%s</pre>" % escape(text)) 
    39      
  • emailprocessormacro/0.11/emailprocessor.py

    r3043 r3720  
    1818    """Email wrapping formatter 
    1919 
    20     This macro takes an email message and will wrap lines to 72 characters. 
    21     It will also put the emails inside a preformatted block. 
     20    This macro takes an email message and will wrap lines to  
     21    72 characters (default), or a length specified.  It will 
     22    also put the emails inside a preformatted block. 
    2223 
    2324    Invocation: 
     
    2627    <email stuff here> 
    2728    }}} 
     29    To wrap to a specified length, the line imediately following 
     30    the invocation should contain `cols: ` followed by the number 
     31    of columns at wich we wrap.  For example: 
     32    {{{ 
     33    #!email 
     34    cols: 40 
     35    <email stuff here> 
     36    }}} 
     37    It is important that the `cols:` starts at the beginning of 
     38    the line and that only a number follows it. 
    2839 
    2940    """ 
     
    3546 
    3647    def expand_macro(self, formatter, name, args): 
    37         text = args and wrap(args, cols=72) or '' 
     48        text = '' 
     49        if args: 
     50            lines = args.split('\n') 
     51            if lines[0].startswith('cols:'): 
     52                try: 
     53                    width = int(lines[0][5:].strip()) 
     54                    lines.pop(0) 
     55                except ValueError: 
     56                    width = 72 
     57            else: 
     58                width = 72 
     59            text = wrap('\n'.join(lines), cols=width) 
    3860        return '<pre class="wiki">%s</pre>' % escape(text) 
    3961