Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes Class Reference
Inheritance diagram for
Inheritance graph
Collaboration diagram for
Collaboration graph

List of all members.

Public Member Functions

def __init__
def filter

Public Attributes


Detailed Description

Convert tabs, newlines and/or spaces to visible characters.

Options accepted:

`spaces` : string or bool
  If this is a one-character string, spaces will be replaces by this string.
  If it is another true value, spaces will be replaced by ``·`` (unicode
  MIDDLE DOT).  If it is a false value, spaces will not be replaced.  The
  default is ``False``.
`tabs` : string or bool
  The same as for `spaces`, but the default replacement character is ``»``
  is ``False``.  Note: this will not work if the `tabsize` option for the
  lexer is nonzero, as tabs will already have been expanded then.
`tabsize` : int
  If tabs are to be replaced by this filter (see the `tabs` option), this
  is the total number of characters that a tab should be expanded to.
  The default is ``8``.
`newlines` : string or bool
  The same as for `spaces`, but the default replacement character is ``¶``
  (unicode PILCROW SIGN).  The default value is ``False``.
`wstokentype` : bool
  If true, give whitespace the special `Whitespace` token type.  This allows
  styling the visible whitespace differently (e.g. greyed out), but it can
  disrupt background colors.  The default is ``True``.

*New in Pygments 0.8.*

Definition at line 208 of file

Constructor & Destructor Documentation

Definition at line 239 of file

00240     def __init__(self, **options):
00241         Filter.__init__(self, **options)
00242         for name, default in {'spaces': u'·', 'tabs': u'»', 'newlines': u'¶'}.items():
00243             opt = options.get(name, False)
00244             if isinstance(opt, basestring) and len(opt) == 1:
00245                 setattr(self, name, opt)
00246             else:
00247                 setattr(self, name, (opt and default or ''))
00248         tabsize = get_int_opt(options, 'tabsize', 8)
00249         if self.tabs:
00250             self.tabs += ' '*(tabsize-1)
00251         if self.newlines:
00252             self.newlines += '\n'
00253         self.wstt = get_bool_opt(options, 'wstokentype', True)

Member Function Documentation

Definition at line 254 of file

00255     def filter(self, lexer, stream):
00256         if self.wstt:
00257             spaces = self.spaces or ' '
00258             tabs = self.tabs or '\t'
00259             newlines = self.newlines or '\n'
00260             regex = re.compile(r'\s')
00261             def replacefunc(wschar):
00262                 if wschar == ' ':
00263                     return spaces
00264                 elif wschar == '\t':
00265                     return tabs
00266                 elif wschar == '\n':
00267                     return newlines
00268                 return wschar
00270             for ttype, value in stream:
00271                 for sttype, svalue in _replace_special(ttype, value, regex,
00272                                                        Whitespace, replacefunc):
00273                     yield sttype, svalue
00274         else:
00275             spaces, tabs, newlines = self.spaces, self.tabs, self.newlines
00276             # simpler processing
00277             for ttype, value in stream:
00278                 if spaces:
00279                     value = value.replace(' ', spaces)
00280                 if tabs:
00281                     value = value.replace('\t', tabs)
00282                 if newlines:
00283                     value = value.replace('\n', newlines)
00284                 yield ttype, value

Here is the call graph for this function:

Member Data Documentation

Definition at line 252 of file

The documentation for this class was generated from the following file: