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: Cheetah.Filters.Filter

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

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/ (since importing pkg_resources was causing issues)

filter(source, **kwargs)

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: Cheetah.Filters.Filter

Markdown will change regular strings to Markdown

Such that:

My Header


<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)
class Cheetah.Filters.MaxLen(template=None)

Bases: Cheetah.Filters.Filter

filter(val, **kw)

Replace None with ‘’ and cut off at maxlen.


alias of Filter

class Cheetah.Filters.Strip(template=None)

Bases: Cheetah.Filters.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)
class Cheetah.Filters.StripSqueeze(template=None)

Bases: Cheetah.Filters.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)
class Cheetah.Filters.WebSafe(template=None)

Bases: Cheetah.Filters.Filter

Escape HTML entities in $placeholders.

filter(val, **kw)