Sophie

Sophie

distrib > Mageia > 1 > x86_64 > by-pkgid > 593f4672c8a3b26bf6b59ebe08099984 > files > 147

python-pygments-1.4-2.mga1.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Filters &mdash; Pygments</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <style type="text/css">
    body {
    background-color: #f2f2f2;
    margin: 0;
    padding: 0;
    font-family: 'Georgia', serif;
    color: #111;
}

#content {
    background-color: white;
    padding: 20px;
    margin: 20px auto 20px auto;
    max-width: 800px;
    border: 4px solid #ddd;
}

h1 {
    font-weight: normal;
    font-size: 40px;
    color: #09839A;
}

h2 {
    font-weight: normal;
    font-size: 30px;
    color: #C73F00;
}

h1.heading {
    margin: 0 0 30px 0;
}

h2.subheading {
    margin: -30px 0 0 45px;
}

h3 {
    margin-top: 30px;
}

table.docutils {
    border-collapse: collapse;
    border: 2px solid #aaa;
    margin: 0.5em 1.5em 0.5em 1.5em;
}

table.docutils td {
    padding: 2px;
    border: 1px solid #ddd;
}

p, li, dd, dt, blockquote {
    font-size: 15px;
    color: #333;
}

p {
    line-height: 150%;
    margin-bottom: 0;
    margin-top: 10px;
}

hr {
    border-top: 1px solid #ccc;
    border-bottom: 0;
    border-right: 0;
    border-left: 0;
    margin-bottom: 10px;
    margin-top: 20px;
}

dl {
    margin-left: 10px;
}

li, dt {
    margin-top: 5px;
}

dt {
    font-weight: bold;
}

th {
    text-align: left;
}

a {
    color: #990000;
}

a:hover {
    color: #c73f00;
}

pre {
    background-color: #f9f9f9;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    padding: 5px;
    font-size: 13px;
    font-family: Bitstream Vera Sans Mono,monospace;
}

tt {
    font-size: 13px;
    font-family: Bitstream Vera Sans Mono,monospace;
    color: black;
    padding: 1px 2px 1px 2px;
    background-color: #f0f0f0;
}

cite {
    /* abusing <cite>, it's generated by ReST for `x` */
    font-size: 13px;
    font-family: Bitstream Vera Sans Mono,monospace;
    font-weight: bold;
    font-style: normal;
}

#backlink {
    float: right;
    font-size: 11px;
    color: #888;
}

div.toc {
    margin: 0 0 10px 0;
}

div.toc h2 {
    font-size: 20px;
}
.syntax .hll { background-color: #ffffcc }
.syntax  { background: #ffffff; }
.syntax .c { color: #888888 } /* Comment */
.syntax .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.syntax .k { color: #008800; font-weight: bold } /* Keyword */
.syntax .cm { color: #888888 } /* Comment.Multiline */
.syntax .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.syntax .c1 { color: #888888 } /* Comment.Single */
.syntax .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.syntax .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.syntax .ge { font-style: italic } /* Generic.Emph */
.syntax .gr { color: #aa0000 } /* Generic.Error */
.syntax .gh { color: #303030 } /* Generic.Heading */
.syntax .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.syntax .go { color: #888888 } /* Generic.Output */
.syntax .gp { color: #555555 } /* Generic.Prompt */
.syntax .gs { font-weight: bold } /* Generic.Strong */
.syntax .gu { color: #606060 } /* Generic.Subheading */
.syntax .gt { color: #aa0000 } /* Generic.Traceback */
.syntax .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.syntax .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.syntax .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.syntax .kp { color: #008800 } /* Keyword.Pseudo */
.syntax .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.syntax .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.syntax .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.syntax .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.syntax .na { color: #336699 } /* Name.Attribute */
.syntax .nb { color: #003388 } /* Name.Builtin */
.syntax .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.syntax .no { color: #003366; font-weight: bold } /* Name.Constant */
.syntax .nd { color: #555555 } /* Name.Decorator */
.syntax .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.syntax .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.syntax .nl { color: #336699; font-style: italic } /* Name.Label */
.syntax .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.syntax .py { color: #336699; font-weight: bold } /* Name.Property */
.syntax .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.syntax .nv { color: #336699 } /* Name.Variable */
.syntax .ow { color: #008800 } /* Operator.Word */
.syntax .w { color: #bbbbbb } /* Text.Whitespace */
.syntax .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.syntax .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.syntax .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.syntax .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.syntax .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.syntax .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.syntax .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.syntax .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.syntax .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.syntax .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.syntax .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.syntax .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.syntax .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.syntax .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.syntax .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.syntax .bp { color: #003388 } /* Name.Builtin.Pseudo */
.syntax .vc { color: #336699 } /* Name.Variable.Class */
.syntax .vg { color: #dd7700 } /* Name.Variable.Global */
.syntax .vi { color: #3333bb } /* Name.Variable.Instance */
.syntax .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
  </style>
</head>
<body>
  <div id="content">
    <h1 class="heading">Pygments</h1>
    <h2 class="subheading">Filters</h2>
    
      <a id="backlink" href="index.html">&laquo; Back To Index</a>
    
    
      <div class="toc">
        <h2>Contents</h2>
        <ul class="contents">
        
          <li><a href="#builtin-filters">Builtin Filters</a></li>
        
        </ul>
      </div>
    
    <!-- -*- mode: rst -*- -->
<p><em>New in Pygments 0.7.</em></p>
<p>You can filter token streams coming from lexers to improve or annotate the
output. For example, you can highlight special words in comments, convert
keywords to upper or lowercase to enforce a style guide etc.</p>
<p>To apply a filter, you can use the <cite>add_filter()</cite> method of a lexer:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">PythonLexer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">PythonLexer</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># add a filter given by a string and options</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">add_filter</span><span class="p">(</span><span class="s">&#39;codetagify&#39;</span><span class="p">,</span> <span class="n">case</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">filters</span>
<span class="go">[&lt;pygments.filters.CodeTagFilter object at 0xb785decc&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.filters</span> <span class="kn">import</span> <span class="n">KeywordCaseFilter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># or give an instance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">add_filter</span><span class="p">(</span><span class="n">KeywordCaseFilter</span><span class="p">(</span><span class="n">case</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">))</span>
</pre></div>
<p>The <cite>add_filter()</cite> method takes keyword arguments which are forwarded to
the constructor of the filter.</p>
<p>To get a list of all registered filters by name, you can use the
<cite>get_all_filters()</cite> function from the <cite>pygments.filters</cite> module that returns an
iterable for all known filters.</p>
<p>If you want to write your own filter, have a look at <a class="reference external" href="./filterdevelopment.html">Write your own filter</a>.</p>
<div class="section" id="builtin-filters">
<h3>Builtin Filters</h3>
<p><cite>RaiseOnErrorTokenFilter</cite></p>
<blockquote>
<p>Raise an exception when the lexer generates an error token.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>excclass</cite> <span class="classifier-delimiter">:</span> <span class="classifier">Exception class</span></dt>
<dd>The exception class to raise.
The default is <cite>pygments.filters.ErrorToken</cite>.</dd>
</dl>
<p><em>New in Pygments 0.8.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">raiseonerror</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>VisibleWhitespaceFilter</cite></p>
<blockquote>
<p>Convert tabs, newlines and/or spaces to visible characters.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>spaces</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>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 <tt class="docutils literal">·</tt> (unicode
MIDDLE DOT).  If it is a false value, spaces will not be replaced.  The
default is <tt class="docutils literal">False</tt>.</dd>
<dt><cite>tabs</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>The same as for <cite>spaces</cite>, but the default replacement character is <tt class="docutils literal">»</tt>
(unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK).  The default value
is <tt class="docutils literal">False</tt>.  Note: this will not work if the <cite>tabsize</cite> option for the
lexer is nonzero, as tabs will already have been expanded then.</dd>
<dt><cite>tabsize</cite> <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd>If tabs are to be replaced by this filter (see the <cite>tabs</cite> option), this
is the total number of characters that a tab should be expanded to.
The default is <tt class="docutils literal">8</tt>.</dd>
<dt><cite>newlines</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>The same as for <cite>spaces</cite>, but the default replacement character is <tt class="docutils literal">¶</tt>
(unicode PILCROW SIGN).  The default value is <tt class="docutils literal">False</tt>.</dd>
<dt><cite>wstokentype</cite> <span class="classifier-delimiter">:</span> <span class="classifier">bool</span></dt>
<dd>If true, give whitespace the special <cite>Whitespace</cite> token type.  This allows
styling the visible whitespace differently (e.g. greyed out), but it can
disrupt background colors.  The default is <tt class="docutils literal">True</tt>.</dd>
</dl>
<p><em>New in Pygments 0.8.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">whitespace</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>TokenMergeFilter</cite></p>
<blockquote>
<p>Merges consecutive tokens with the same token type in the output stream of a
lexer.</p>
<p><em>New in Pygments 1.2.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">tokenmerge</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>NameHighlightFilter</cite></p>
<blockquote>
<p>Highlight a normal Name token with a different token type.</p>
<p>Example:</p>
<pre class="literal-block">
filter = NameHighlightFilter(
    names=['foo', 'bar', 'baz'],
    tokentype=Name.Function,
)
</pre>
<p>This would highlight the names &quot;foo&quot;, &quot;bar&quot; and &quot;baz&quot;
as functions. <cite>Name.Function</cite> is the default token type.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>names</cite> <span class="classifier-delimiter">:</span> <span class="classifier">list of strings</span></dt>
<dd>A list of names that should be given the different token type.
There is no default.</dd>
<dt><cite>tokentype</cite> <span class="classifier-delimiter">:</span> <span class="classifier">TokenType or string</span></dt>
<dd>A token type or a string containing a token type name that is
used for highlighting the strings in <cite>names</cite>.  The default is
<cite>Name.Function</cite>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">highlight</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>GobbleFilter</cite></p>
<blockquote>
<p>Gobbles source code lines (eats initial characters).</p>
<p>This filter drops the first <tt class="docutils literal">n</tt> characters off every line of code.  This
may be useful when the source code fed to the lexer is indented by a fixed
amount of space that isn't desired in the output.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>n</cite> <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd>The number of characters to gobble.</dd>
</dl>
<p><em>New in Pygments 1.2.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">gobble</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>CodeTagFilter</cite></p>
<blockquote>
<p>Highlight special code tags in comments and docstrings.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>codetags</cite> <span class="classifier-delimiter">:</span> <span class="classifier">list of strings</span></dt>
<dd>A list of strings that are flagged as code tags.  The default is to
highlight <tt class="docutils literal">XXX</tt>, <tt class="docutils literal">TODO</tt>, <tt class="docutils literal">BUG</tt> and <tt class="docutils literal">NOTE</tt>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">codetagify</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>KeywordCaseFilter</cite></p>
<blockquote>
<p>Convert keywords to lowercase or uppercase or capitalize them, which
means first letter uppercase, rest lowercase.</p>
<p>This can be useful e.g. if you highlight Pascal code and want to adapt the
code to your styleguide.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>case</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string</span></dt>
<dd>The casing to convert keywords to. Must be one of <tt class="docutils literal">'lower'</tt>,
<tt class="docutils literal">'upper'</tt> or <tt class="docutils literal">'capitalize'</tt>.  The default is <tt class="docutils literal">'lower'</tt>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">keywordcase</td>
</tr>
</tbody>
</table>
</blockquote>
</div>

  </div>
</body>
<!-- generated on: 2011-01-03 18:05:49.071135
     file id: filters -->
</html>