File manager - Edit - /usr/share/doc/python3-pygments/html/docs/api.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>The full Pygments API — 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="Write your own lexer" href="lexerdevelopment.html" /> <link rel="prev" title="Builtin Tokens" href="tokens.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="#">The full Pygments API</a><ul> <li><a class="reference internal" href="#module-pygments">High-level API</a></li> <li><a class="reference internal" href="#lexers">Lexers</a></li> <li><a class="reference internal" href="#formatters">Formatters</a></li> <li><a class="reference internal" href="#option-processing">Option processing</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="the-full-pygments-api"> <h1>The full Pygments API<a class="headerlink" href="#the-full-pygments-api" title="Permalink to this headline">¶</a></h1> <p>This page describes the Pygments API.</p> <div class="section" id="module-pygments"> <span id="high-level-api"></span><h2>High-level API<a class="headerlink" href="#module-pygments" title="Permalink to this headline">¶</a></h2> <p>Functions from the <a class="reference internal" href="#module-pygments" title="pygments"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygments</span></code></a> module:</p> <dl class="function"> <dt id="pygments.lex"> <code class="descclassname">pygments.</code><code class="descname">lex</code><span class="sig-paren">(</span><em>code</em>, <em>lexer</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lex" title="Permalink to this definition">¶</a></dt> <dd><p>Lex <cite>code</cite> with the <cite>lexer</cite> (must be a <cite>Lexer</cite> instance) and return an iterable of tokens. Currently, this only calls <cite>lexer.get_tokens()</cite>.</p> </dd></dl> <dl class="function"> <dt id="pygments.format"> <code class="descclassname">pygments.</code><code class="descname">format</code><span class="sig-paren">(</span><em>tokens</em>, <em>formatter</em>, <em>outfile=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.format" title="Permalink to this definition">¶</a></dt> <dd><p>Format a token stream (iterable of tokens) <cite>tokens</cite> with the <cite>formatter</cite> (must be a <cite>Formatter</cite> instance). The result is written to <cite>outfile</cite>, or if that is <code class="docutils literal notranslate"><span class="pre">None</span></code>, returned as a string.</p> </dd></dl> <dl class="function"> <dt id="pygments.highlight"> <code class="descclassname">pygments.</code><code class="descname">highlight</code><span class="sig-paren">(</span><em>code</em>, <em>lexer</em>, <em>formatter</em>, <em>outfile=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.highlight" title="Permalink to this definition">¶</a></dt> <dd><p>This is the most high-level highlighting function. It combines <cite>lex</cite> and <cite>format</cite> in one function.</p> </dd></dl> <span class="target" id="module-pygments.lexers"></span><p>Functions from <a class="reference internal" href="#module-pygments.lexers" title="pygments.lexers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygments.lexers</span></code></a>:</p> <dl class="function"> <dt id="pygments.lexers.get_lexer_by_name"> <code class="descclassname">pygments.lexers.</code><code class="descname">get_lexer_by_name</code><span class="sig-paren">(</span><em>alias</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.get_lexer_by_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return an instance of a <cite>Lexer</cite> subclass that has <cite>alias</cite> in its aliases list. The lexer is given the <cite>options</cite> at its instantiation.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no lexer with that alias is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.lexers.get_lexer_for_filename"> <code class="descclassname">pygments.lexers.</code><code class="descname">get_lexer_for_filename</code><span class="sig-paren">(</span><em>fn</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.get_lexer_for_filename" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <cite>Lexer</cite> subclass instance that has a filename pattern matching <cite>fn</cite>. The lexer is given the <cite>options</cite> at its instantiation.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no lexer for that filename is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.lexers.get_lexer_for_mimetype"> <code class="descclassname">pygments.lexers.</code><code class="descname">get_lexer_for_mimetype</code><span class="sig-paren">(</span><em>mime</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.get_lexer_for_mimetype" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <cite>Lexer</cite> subclass instance that has <cite>mime</cite> in its mimetype list. The lexer is given the <cite>options</cite> at its instantiation.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if not lexer for that mimetype is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.lexers.load_lexer_from_file"> <code class="descclassname">pygments.lexers.</code><code class="descname">load_lexer_from_file</code><span class="sig-paren">(</span><em>filename</em>, <em>lexername="CustomLexer"</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.load_lexer_from_file" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <cite>Lexer</cite> subclass instance loaded from the provided file, relative to the current directory. The file is expected to contain a Lexer class named <cite>lexername</cite> (by default, CustomLexer). Users should be very careful with the input, because this method is equivalent to running eval on the input file. The lexer is given the <cite>options</cite> at its instantiation.</p> <p><code class="xref py py-exc docutils literal notranslate"><span class="pre">ClassNotFound</span></code> is raised if there are any errors loading the Lexer</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.2.</span></p> </div> </dd></dl> <dl class="function"> <dt id="pygments.lexers.guess_lexer"> <code class="descclassname">pygments.lexers.</code><code class="descname">guess_lexer</code><span class="sig-paren">(</span><em>text</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.guess_lexer" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <cite>Lexer</cite> subclass instance that’s guessed from the text in <cite>text</cite>. For that, the <a class="reference internal" href="#pygments.lexer.Lexer.analyse_text" title="pygments.lexer.Lexer.analyse_text"><code class="xref py py-meth docutils literal notranslate"><span class="pre">analyse_text()</span></code></a> method of every known lexer class is called with the text as argument, and the lexer which returned the highest value will be instantiated and returned.</p> <p><code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> is raised if no lexer thinks it can handle the content.</p> </dd></dl> <dl class="function"> <dt id="pygments.lexers.guess_lexer_for_filename"> <code class="descclassname">pygments.lexers.</code><code class="descname">guess_lexer_for_filename</code><span class="sig-paren">(</span><em>filename</em>, <em>text</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.guess_lexer_for_filename" title="Permalink to this definition">¶</a></dt> <dd><p>As <a class="reference internal" href="#pygments.lexers.guess_lexer" title="pygments.lexers.guess_lexer"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_lexer()</span></code></a>, but only lexers which have a pattern in <cite>filenames</cite> or <cite>alias_filenames</cite> that matches <cite>filename</cite> are taken into consideration.</p> <p><code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> is raised if no lexer thinks it can handle the content.</p> </dd></dl> <dl class="function"> <dt id="pygments.lexers.get_all_lexers"> <code class="descclassname">pygments.lexers.</code><code class="descname">get_all_lexers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.get_all_lexers" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterable over all registered lexers, yielding tuples in the format:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">longname</span><span class="p">,</span> <span class="nb">tuple</span> <span class="n">of</span> <span class="n">aliases</span><span class="p">,</span> <span class="nb">tuple</span> <span class="n">of</span> <span class="n">filename</span> <span class="n">patterns</span><span class="p">,</span> <span class="nb">tuple</span> <span class="n">of</span> <span class="n">mimetypes</span><span class="p">)</span> </pre></div> </div> <div class="versionadded"> <p><span class="versionmodified">New in version 0.6.</span></p> </div> </dd></dl> <dl class="function"> <dt id="pygments.lexers.find_lexer_class_by_name"> <code class="descclassname">pygments.lexers.</code><code class="descname">find_lexer_class_by_name</code><span class="sig-paren">(</span><em>alias</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.find_lexer_class_by_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <cite>Lexer</cite> subclass that has <cite>alias</cite> in its aliases list, without instantiating it.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no lexer with that alias is found.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.2.</span></p> </div> </dd></dl> <dl class="function"> <dt id="pygments.lexers.find_lexer_class"> <code class="descclassname">pygments.lexers.</code><code class="descname">find_lexer_class</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexers.find_lexer_class" title="Permalink to this definition">¶</a></dt> <dd><p>Return the <cite>Lexer</cite> subclass that with the <em>name</em> attribute as given by the <em>name</em> argument.</p> </dd></dl> <span class="target" id="module-pygments.formatters"></span><p>Functions from <a class="reference internal" href="#module-pygments.formatters" title="pygments.formatters"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygments.formatters</span></code></a>:</p> <dl class="function"> <dt id="pygments.formatters.get_formatter_by_name"> <code class="descclassname">pygments.formatters.</code><code class="descname">get_formatter_by_name</code><span class="sig-paren">(</span><em>alias</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatters.get_formatter_by_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return an instance of a <a class="reference internal" href="#pygments.formatter.Formatter" title="pygments.formatter.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> subclass that has <cite>alias</cite> in its aliases list. The formatter is given the <cite>options</cite> at its instantiation.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no formatter with that alias is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.formatters.get_formatter_for_filename"> <code class="descclassname">pygments.formatters.</code><code class="descname">get_formatter_for_filename</code><span class="sig-paren">(</span><em>fn</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatters.get_formatter_for_filename" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <a class="reference internal" href="#pygments.formatter.Formatter" title="pygments.formatter.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> subclass instance that has a filename pattern matching <cite>fn</cite>. The formatter is given the <cite>options</cite> at its instantiation.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no formatter for that filename is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.formatters.load_formatter_from_file"> <code class="descclassname">pygments.formatters.</code><code class="descname">load_formatter_from_file</code><span class="sig-paren">(</span><em>filename</em>, <em>formattername="CustomFormatter"</em>, <em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatters.load_formatter_from_file" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <cite>Formatter</cite> subclass instance loaded from the provided file, relative to the current directory. The file is expected to contain a Formatter class named <code class="docutils literal notranslate"><span class="pre">formattername</span></code> (by default, CustomFormatter). Users should be very careful with the input, because this method is equivalent to running eval on the input file. The formatter is given the <cite>options</cite> at its instantiation.</p> <p><code class="xref py py-exc docutils literal notranslate"><span class="pre">ClassNotFound</span></code> is raised if there are any errors loading the Formatter</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.2.</span></p> </div> </dd></dl> <span class="target" id="module-pygments.styles"></span><p>Functions from <a class="reference internal" href="#module-pygments.styles" title="pygments.styles"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygments.styles</span></code></a>:</p> <dl class="function"> <dt id="pygments.styles.get_style_by_name"> <code class="descclassname">pygments.styles.</code><code class="descname">get_style_by_name</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.styles.get_style_by_name" title="Permalink to this definition">¶</a></dt> <dd><p>Return a style class by its short name. The names of the builtin styles are listed in <code class="xref py py-data docutils literal notranslate"><span class="pre">pygments.styles.STYLE_MAP</span></code>.</p> <p>Will raise <code class="xref py py-exc docutils literal notranslate"><span class="pre">pygments.util.ClassNotFound</span></code> if no style of that name is found.</p> </dd></dl> <dl class="function"> <dt id="pygments.styles.get_all_styles"> <code class="descclassname">pygments.styles.</code><code class="descname">get_all_styles</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygments.styles.get_all_styles" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterable over all registered styles, yielding their names.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 0.6.</span></p> </div> </dd></dl> <span class="target" id="module-pygments.lexer"></span></div> <div class="section" id="lexers"> <h2>Lexers<a class="headerlink" href="#lexers" title="Permalink to this headline">¶</a></h2> <p>The base lexer class from which all lexers are derived is:</p> <dl class="class"> <dt id="pygments.lexer.Lexer"> <em class="property">class </em><code class="descclassname">pygments.lexer.</code><code class="descname">Lexer</code><span class="sig-paren">(</span><em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexer.Lexer" title="Permalink to this definition">¶</a></dt> <dd><p>The constructor takes a **keywords dictionary of options. Every subclass must first process its own options and then call the <cite>Lexer</cite> constructor, since it processes the <cite>stripnl</cite>, <cite>stripall</cite> and <cite>tabsize</cite> options.</p> <p>An example looks like this:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">compress</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'compress'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> <span class="n">Lexer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span> </pre></div> </div> <p>As these options must all be specifiable as strings (due to the command line usage), there are various utility functions available to help with that, see <a class="reference internal" href="#option-processing">Option processing</a>.</p> <dl class="method"> <dt id="pygments.lexer.Lexer.get_tokens"> <code class="descname">get_tokens</code><span class="sig-paren">(</span><em>text</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexer.Lexer.get_tokens" title="Permalink to this definition">¶</a></dt> <dd><p>This method is the basic interface of a lexer. It is called by the <cite>highlight()</cite> function. It must process the text and return an iterable of <code class="docutils literal notranslate"><span class="pre">(tokentype,</span> <span class="pre">value)</span></code> pairs from <cite>text</cite>.</p> <p>Normally, you don’t need to override this method. The default implementation processes the <cite>stripnl</cite>, <cite>stripall</cite> and <cite>tabsize</cite> options and then yields all tokens from <cite>get_tokens_unprocessed()</cite>, with the <code class="docutils literal notranslate"><span class="pre">index</span></code> dropped.</p> </dd></dl> <dl class="method"> <dt id="pygments.lexer.Lexer.get_tokens_unprocessed"> <code class="descname">get_tokens_unprocessed</code><span class="sig-paren">(</span><em>text</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexer.Lexer.get_tokens_unprocessed" title="Permalink to this definition">¶</a></dt> <dd><p>This method should process the text and return an iterable of <code class="docutils literal notranslate"><span class="pre">(index,</span> <span class="pre">tokentype,</span> <span class="pre">value)</span></code> tuples where <code class="docutils literal notranslate"><span class="pre">index</span></code> is the starting position of the token within the input text.</p> <p>This method must be overridden by subclasses.</p> </dd></dl> <dl class="staticmethod"> <dt id="pygments.lexer.Lexer.analyse_text"> <em class="property">static </em><code class="descname">analyse_text</code><span class="sig-paren">(</span><em>text</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.lexer.Lexer.analyse_text" title="Permalink to this definition">¶</a></dt> <dd><p>A static method which is called for lexer guessing. It should analyse the text and return a float in the range from <code class="docutils literal notranslate"><span class="pre">0.0</span></code> to <code class="docutils literal notranslate"><span class="pre">1.0</span></code>. If it returns <code class="docutils literal notranslate"><span class="pre">0.0</span></code>, the lexer will not be selected as the most probable one, if it returns <code class="docutils literal notranslate"><span class="pre">1.0</span></code>, it will be selected immediately.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">You don’t have to add <code class="docutils literal notranslate"><span class="pre">@staticmethod</span></code> to the definition of this method, this will be taken care of by the Lexer’s metaclass.</p> </div> </dd></dl> <p>For a list of known tokens have a look at the <a class="reference internal" href="tokens.html"><span class="doc">Builtin Tokens</span></a> page.</p> <p>A lexer also can have the following attributes (in fact, they are mandatory except <cite>alias_filenames</cite>) that are used by the builtin lookup mechanism.</p> <dl class="attribute"> <dt id="pygments.lexer.Lexer.name"> <code class="descname">name</code><a class="headerlink" href="#pygments.lexer.Lexer.name" title="Permalink to this definition">¶</a></dt> <dd><p>Full name for the lexer, in human-readable form.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.lexer.Lexer.aliases"> <code class="descname">aliases</code><a class="headerlink" href="#pygments.lexer.Lexer.aliases" title="Permalink to this definition">¶</a></dt> <dd><p>A list of short, unique identifiers that can be used to lookup the lexer from a list, e.g. using <cite>get_lexer_by_name()</cite>.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.lexer.Lexer.filenames"> <code class="descname">filenames</code><a class="headerlink" href="#pygments.lexer.Lexer.filenames" title="Permalink to this definition">¶</a></dt> <dd><p>A list of <cite>fnmatch</cite> patterns that match filenames which contain content for this lexer. The patterns in this list should be unique among all lexers.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.lexer.Lexer.alias_filenames"> <code class="descname">alias_filenames</code><a class="headerlink" href="#pygments.lexer.Lexer.alias_filenames" title="Permalink to this definition">¶</a></dt> <dd><p>A list of <cite>fnmatch</cite> patterns that match filenames which may or may not contain content for this lexer. This list is used by the <a class="reference internal" href="#pygments.lexers.guess_lexer_for_filename" title="pygments.lexers.guess_lexer_for_filename"><code class="xref py py-func docutils literal notranslate"><span class="pre">guess_lexer_for_filename()</span></code></a> function, to determine which lexers are then included in guessing the correct one. That means that e.g. every lexer for HTML and a template language should include <code class="docutils literal notranslate"><span class="pre">\*.html</span></code> in this list.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.lexer.Lexer.mimetypes"> <code class="descname">mimetypes</code><a class="headerlink" href="#pygments.lexer.Lexer.mimetypes" title="Permalink to this definition">¶</a></dt> <dd><p>A list of MIME types for content that can be lexed with this lexer.</p> </dd></dl> </dd></dl> <span class="target" id="module-pygments.formatter"></span></div> <div class="section" id="formatters"> <h2>Formatters<a class="headerlink" href="#formatters" title="Permalink to this headline">¶</a></h2> <p>A formatter is derived from this class:</p> <dl class="class"> <dt id="pygments.formatter.Formatter"> <em class="property">class </em><code class="descclassname">pygments.formatter.</code><code class="descname">Formatter</code><span class="sig-paren">(</span><em>**options</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatter.Formatter" title="Permalink to this definition">¶</a></dt> <dd><p>As with lexers, this constructor processes options and then must call the base class <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code>.</p> <p>The <a class="reference internal" href="#pygments.formatter.Formatter" title="pygments.formatter.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> class recognizes the options <cite>style</cite>, <cite>full</cite> and <cite>title</cite>. It is up to the formatter class whether it uses them.</p> <dl class="method"> <dt id="pygments.formatter.Formatter.get_style_defs"> <code class="descname">get_style_defs</code><span class="sig-paren">(</span><em>arg=''</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatter.Formatter.get_style_defs" title="Permalink to this definition">¶</a></dt> <dd><p>This method must return statements or declarations suitable to define the current style for subsequent highlighted text (e.g. CSS classes in the <cite>HTMLFormatter</cite>).</p> <p>The optional argument <cite>arg</cite> can be used to modify the generation and is formatter dependent (it is standardized because it can be given on the command line).</p> <p>This method is called by the <code class="docutils literal notranslate"><span class="pre">-S</span></code> <a class="reference internal" href="cmdline.html"><span class="doc">command-line option</span></a>, the <cite>arg</cite> is then given by the <code class="docutils literal notranslate"><span class="pre">-a</span></code> option.</p> </dd></dl> <dl class="method"> <dt id="pygments.formatter.Formatter.format"> <code class="descname">format</code><span class="sig-paren">(</span><em>tokensource</em>, <em>outfile</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.formatter.Formatter.format" title="Permalink to this definition">¶</a></dt> <dd><p>This method must format the tokens from the <cite>tokensource</cite> iterable and write the formatted version to the file object <cite>outfile</cite>.</p> <p>Formatter options can control how exactly the tokens are converted.</p> </dd></dl> <div class="versionadded"> <p><span class="versionmodified">New in version 0.7: </span>A formatter must have the following attributes that are used by the builtin lookup mechanism.</p> </div> <dl class="attribute"> <dt id="pygments.formatter.Formatter.name"> <code class="descname">name</code><a class="headerlink" href="#pygments.formatter.Formatter.name" title="Permalink to this definition">¶</a></dt> <dd><p>Full name for the formatter, in human-readable form.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.formatter.Formatter.aliases"> <code class="descname">aliases</code><a class="headerlink" href="#pygments.formatter.Formatter.aliases" title="Permalink to this definition">¶</a></dt> <dd><p>A list of short, unique identifiers that can be used to lookup the formatter from a list, e.g. using <a class="reference internal" href="#pygments.formatters.get_formatter_by_name" title="pygments.formatters.get_formatter_by_name"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_formatter_by_name()</span></code></a>.</p> </dd></dl> <dl class="attribute"> <dt id="pygments.formatter.Formatter.filenames"> <code class="descname">filenames</code><a class="headerlink" href="#pygments.formatter.Formatter.filenames" title="Permalink to this definition">¶</a></dt> <dd><p>A list of <code class="xref py py-mod docutils literal notranslate"><span class="pre">fnmatch</span></code> patterns that match filenames for which this formatter can produce output. The patterns in this list should be unique among all formatters.</p> </dd></dl> </dd></dl> <span class="target" id="module-pygments.util"></span></div> <div class="section" id="option-processing"> <h2>Option processing<a class="headerlink" href="#option-processing" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#module-pygments.util" title="pygments.util"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygments.util</span></code></a> module has some utility functions usable for option processing:</p> <dl class="exception"> <dt id="pygments.util.OptionError"> <em class="property">exception </em><code class="descclassname">pygments.util.</code><code class="descname">OptionError</code><a class="headerlink" href="#pygments.util.OptionError" title="Permalink to this definition">¶</a></dt> <dd><p>This exception will be raised by all option processing functions if the type or value of the argument is not correct.</p> </dd></dl> <dl class="function"> <dt id="pygments.util.get_bool_opt"> <code class="descclassname">pygments.util.</code><code class="descname">get_bool_opt</code><span class="sig-paren">(</span><em>options</em>, <em>optname</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.util.get_bool_opt" title="Permalink to this definition">¶</a></dt> <dd><p>Interpret the key <cite>optname</cite> from the dictionary <cite>options</cite> as a boolean and return it. Return <cite>default</cite> if <cite>optname</cite> is not in <cite>options</cite>.</p> <p>The valid string values for <code class="docutils literal notranslate"><span class="pre">True</span></code> are <code class="docutils literal notranslate"><span class="pre">1</span></code>, <code class="docutils literal notranslate"><span class="pre">yes</span></code>, <code class="docutils literal notranslate"><span class="pre">true</span></code> and <code class="docutils literal notranslate"><span class="pre">on</span></code>, the ones for <code class="docutils literal notranslate"><span class="pre">False</span></code> are <code class="docutils literal notranslate"><span class="pre">0</span></code>, <code class="docutils literal notranslate"><span class="pre">no</span></code>, <code class="docutils literal notranslate"><span class="pre">false</span></code> and <code class="docutils literal notranslate"><span class="pre">off</span></code> (matched case-insensitively).</p> </dd></dl> <dl class="function"> <dt id="pygments.util.get_int_opt"> <code class="descclassname">pygments.util.</code><code class="descname">get_int_opt</code><span class="sig-paren">(</span><em>options</em>, <em>optname</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.util.get_int_opt" title="Permalink to this definition">¶</a></dt> <dd><p>As <a class="reference internal" href="#pygments.util.get_bool_opt" title="pygments.util.get_bool_opt"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_bool_opt()</span></code></a>, but interpret the value as an integer.</p> </dd></dl> <dl class="function"> <dt id="pygments.util.get_list_opt"> <code class="descclassname">pygments.util.</code><code class="descname">get_list_opt</code><span class="sig-paren">(</span><em>options</em>, <em>optname</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.util.get_list_opt" title="Permalink to this definition">¶</a></dt> <dd><p>If the key <cite>optname</cite> from the dictionary <cite>options</cite> is a string, split it at whitespace and return it. If it is already a list or a tuple, it is returned as a list.</p> </dd></dl> <dl class="function"> <dt id="pygments.util.get_choice_opt"> <code class="descclassname">pygments.util.</code><code class="descname">get_choice_opt</code><span class="sig-paren">(</span><em>options</em>, <em>optname</em>, <em>allowed</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#pygments.util.get_choice_opt" title="Permalink to this definition">¶</a></dt> <dd><p>If the key <cite>optname</cite> from the dictionary is not in the sequence <cite>allowed</cite>, raise an error, otherwise return it.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 0.8.</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