# Cheetah.Filters module

Filters for the #filter directive as well as #transform

#filter results in output filters Cheetah’s $placeholders . #transform results in a filter on the entirety of the output

class Cheetah.Filters.CodeHighlighter(template=None)

  Bases: `Filter`

  The CodeHighlighter filter depends on the “pygments” module which you can download and install from: http://pygments.org/

  What the CodeHighlighter assumes the string that it’s receiving is source code and uses pygments.lexers.guess_lexer() to try to guess which parser to use when highlighting it.

  CodeHighlighter will return the HTML and CSS to render the code block, syntax highlighted, in a browser

  NOTE: I had an issue installing pygments on Linux/amd64/Python 2.6 dealing with importing of pygments.lexers. I was able to correct the failure by adding:

      raise ImportError

  to line 39 of pygments/plugin.py (since importing pkg_resources was causing issues).

  filter(source, **kwargs)

    Pass Unicode strings through unmolested, unless an encoding is specified.

Cheetah.Filters.EncodeUnicode

  alias of `Filter`

class Cheetah.Filters.Filter(template=None)

  Bases: `object`

  A baseclass for the Cheetah Filters.

  filter(val, encoding=None, str=<class 'str'>, **kw)

    Pass Unicode strings through unmolested, unless an encoding is specified.

class Cheetah.Filters.Markdown(template=None)

  Bases: `Filter`

  Markdown will change regular strings to Markdown

  Such that:

      My Header
      =========

  Becomes:

      <h1>My Header</h1>

  and so on.

  Markdown is meant to be used with the #transform tag, as it’s usefulness with #filter is marginal at best

  filter(value, **kwargs)

    Pass Unicode strings through unmolested, unless an encoding is specified.

class Cheetah.Filters.MaxLen(template=None)

  Bases: `Filter`

  filter(val, **kw)

    Replace None with ‘’ and cut off at maxlen.

Cheetah.Filters.RawOrEncodedUnicode

  alias of `Filter`

class Cheetah.Filters.Strip(template=None)

  Bases: `Filter`

  Strip leading/trailing whitespace but preserve newlines.

  This filter goes through the value line by line, removing leading and trailing whitespace on each line. It does not strip newlines, so every input line corresponds to one output line, with its trailing newline intact.

  We do not use val.split(’n’) because that would squeeze out consecutive blank lines. Instead, we search for each newline individually. This makes us unable to use the fast C .split method, but it makes the filter much more widely useful.

  This filter is intended to be usable both with the #filter directive and with the proposed #sed directive (which has not been ratified yet.)

  filter(val, **kw)

    Pass Unicode strings through unmolested, unless an encoding is specified.

class Cheetah.Filters.StripSqueeze(template=None)

  Bases: `Filter`

  Canonicalizes every chunk of whitespace to a single space.

  Strips leading/trailing whitespace. Removes all newlines, so multi-line input is joined into one ling line with NO trailing newline.

  filter(val, **kw)

    Pass Unicode strings through unmolested, unless an encoding is specified.

class Cheetah.Filters.WebSafe(template=None)

  Bases: `Filter`

  Escape HTML entities in $placeholders.

  filter(val, **kw)

    Pass Unicode strings through unmolested, unless an encoding is specified.

Cheetah.Filters.test()