File manager - Edit - /usr/share/doc/python3-pygments/html/docs/filters.html
Back
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Filters — Pygments 2.2.0 documentation</title> <link rel="stylesheet" href="../_static/pygments14.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/favicon.ico"/> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="Available formatters" href="formatters.html" /> <link rel="prev" title="Available lexers" href="lexers.html" /> <link href='http://fonts.googleapis.com/css?family=PT+Sans:300,400,700' rel='stylesheet' type='text/css'> <style type="text/css"> table.right { float: right; margin-left: 20px; } table.right td { border: 1px solid #ccc; } </style> <script type="text/javascript"> // intelligent scrolling of the sidebar content $(window).scroll(function() { var sb = $('.sphinxsidebarwrapper'); var win = $(window); var sbh = sb.height(); var offset = $('.sphinxsidebar').position()['top']; var wintop = win.scrollTop(); var winbot = wintop + win.innerHeight(); var curtop = sb.position()['top']; var curbot = curtop + sbh; // does sidebar fit in window? if (sbh < win.innerHeight()) { // yes: easy case -- always keep at the top sb.css('top', $u.min([$u.max([0, wintop - offset - 10]), $(document).height() - sbh - 200])); } else { // no: only scroll if top/bottom edge of sidebar is at // top/bottom edge of window if (curtop > wintop && curbot > winbot) { sb.css('top', $u.max([wintop - offset - 10, 0])); } else if (curtop < wintop && curbot < winbot) { sb.css('top', $u.min([winbot - sbh - offset - 20, $(document).height() - sbh - 200])); } } }); </script> </head><body> <div class="outerwrapper"> <div class="pageheader"> <ul> <li><a href="../index.html">Home</a></li> <li><a href="../languages.html">Languages</a></li> <li><a href="../faq.html">FAQ</a></li> <li><a href="../download.html">Get it</a></li> <li><a href="index.html">Docs</a></li> </ul> <div> <a href="../index.html"> <img src="../_static/logo.png" alt="Pygments logo" /> </a> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Filters</a><ul> <li><a class="reference internal" href="#builtin-filters">Builtin Filters</a></li> </ul> </li> </ul> <strong>« <a href="index.html">Back to docs index</a></strong> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="filters"> <h1>Filters<a class="headerlink" href="#filters" title="Permalink to this headline">¶</a></h1> <div class="versionadded"> <p><span class="versionmodified">New in version 0.7.</span></p> </div> <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="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </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">>>> </span><span class="n">l</span> <span class="o">=</span> <span class="n">PythonLexer</span><span class="p">()</span> <span class="gp">>>> </span><span class="c1"># add a filter given by a string and options</span> <span class="gp">>>> </span><span class="n">l</span><span class="o">.</span><span class="n">add_filter</span><span class="p">(</span><span class="s1">'codetagify'</span><span class="p">,</span> <span class="n">case</span><span class="o">=</span><span class="s1">'lower'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">l</span><span class="o">.</span><span class="n">filters</span> <span class="go">[<pygments.filters.CodeTagFilter object at 0xb785decc>]</span> <span class="gp">>>> </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">>>> </span><span class="c1"># or give an instance</span> <span class="gp">>>> </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="s1">'lower'</span><span class="p">))</span> </pre></div> </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 internal" href="filterdevelopment.html"><span class="doc">Write your own filter</span></a>.</p> <div class="section" id="builtin-filters"> <h2>Builtin Filters<a class="headerlink" href="#builtin-filters" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="CodeTagFilter"> <em class="property">class </em><code class="descname">CodeTagFilter</code><a class="headerlink" href="#CodeTagFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">codetagify</td> </tr> </tbody> </table> <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 <code class="docutils literal notranslate"><span class="pre">XXX</span></code>, <code class="docutils literal notranslate"><span class="pre">TODO</span></code>, <code class="docutils literal notranslate"><span class="pre">BUG</span></code> and <code class="docutils literal notranslate"><span class="pre">NOTE</span></code>.</dd> </dl> </dd></dl> <dl class="class"> <dt id="KeywordCaseFilter"> <em class="property">class </em><code class="descname">KeywordCaseFilter</code><a class="headerlink" href="#KeywordCaseFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">keywordcase</td> </tr> </tbody> </table> <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 <code class="docutils literal notranslate"><span class="pre">'lower'</span></code>, <code class="docutils literal notranslate"><span class="pre">'upper'</span></code> or <code class="docutils literal notranslate"><span class="pre">'capitalize'</span></code>. The default is <code class="docutils literal notranslate"><span class="pre">'lower'</span></code>.</dd> </dl> </dd></dl> <dl class="class"> <dt id="NameHighlightFilter"> <em class="property">class </em><code class="descname">NameHighlightFilter</code><a class="headerlink" href="#NameHighlightFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">highlight</td> </tr> </tbody> </table> <p>Highlight a normal Name (and Name.*) token with a different token type.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">filter</span> <span class="o">=</span> <span class="n">NameHighlightFilter</span><span class="p">(</span> <span class="n">names</span><span class="o">=</span><span class="p">[</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">,</span> <span class="s1">'baz'</span><span class="p">],</span> <span class="n">tokentype</span><span class="o">=</span><span class="n">Name</span><span class="o">.</span><span class="n">Function</span><span class="p">,</span> <span class="p">)</span> </pre></div> </div> <p>This would highlight the names “foo”, “bar” and “baz” 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> </dd></dl> <dl class="class"> <dt id="RaiseOnErrorTokenFilter"> <em class="property">class </em><code class="descname">RaiseOnErrorTokenFilter</code><a class="headerlink" href="#RaiseOnErrorTokenFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">raiseonerror</td> </tr> </tbody> </table> <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> <div class="versionadded"> <p><span class="versionmodified">New in version 0.8.</span></p> </div> </dd></dl> <dl class="class"> <dt id="VisibleWhitespaceFilter"> <em class="property">class </em><code class="descname">VisibleWhitespaceFilter</code><a class="headerlink" href="#VisibleWhitespaceFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">whitespace</td> </tr> </tbody> </table> <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 <code class="docutils literal notranslate"><span class="pre">·</span></code> (unicode MIDDLE DOT). If it is a false value, spaces will not be replaced. The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</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 <code class="docutils literal notranslate"><span class="pre">»</span></code> (unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value is <code class="docutils literal notranslate"><span class="pre">False</span></code>. 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 <code class="docutils literal notranslate"><span class="pre">8</span></code>.</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 <code class="docutils literal notranslate"><span class="pre">¶</span></code> (unicode PILCROW SIGN). The default value is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</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 <code class="docutils literal notranslate"><span class="pre">True</span></code>.</dd> </dl> <div class="versionadded"> <p><span class="versionmodified">New in version 0.8.</span></p> </div> </dd></dl> <dl class="class"> <dt id="GobbleFilter"> <em class="property">class </em><code class="descname">GobbleFilter</code><a class="headerlink" href="#GobbleFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">gobble</td> </tr> </tbody> </table> <p>Gobbles source code lines (eats initial characters).</p> <p>This filter drops the first <code class="docutils literal notranslate"><span class="pre">n</span></code> 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> <div class="versionadded"> <p><span class="versionmodified">New in version 1.2.</span></p> </div> </dd></dl> <dl class="class"> <dt id="TokenMergeFilter"> <em class="property">class </em><code class="descname">TokenMergeFilter</code><a class="headerlink" href="#TokenMergeFilter" title="Permalink to this definition">¶</a></dt> <dd><table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Name:</th><td class="field-body">tokenmerge</td> </tr> </tbody> </table> <p>Merges consecutive tokens with the same token type in the output stream of a lexer.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 1.2.</span></p> </div> </dd></dl> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="footer" role="contentinfo"> © Copyright 2006-2017, Georg Brandl and Pygments contributors. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.6. <br/> Pygments logo created by <a href="http://joelunger.com">Joel Unger</a>. Backgrounds from <a href="http://subtlepatterns.com">subtlepatterns.com</a>. </div> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 8.2.30 | Generation time: 0 |
proxy
|
phpinfo
|
Settings