File manager - Edit - /usr/share/doc/python3-pygments/html/docs/cmdline.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>Command Line Interface — 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 lexers" href="lexers.html" /> <link rel="prev" title="Introduction and Quickstart" href="quickstart.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="#">Command Line Interface</a><ul> <li><a class="reference internal" href="#options-and-filters">Options and filters</a></li> <li><a class="reference internal" href="#generating-styles">Generating styles</a></li> <li><a class="reference internal" href="#getting-lexer-names">Getting lexer names</a></li> <li><a class="reference internal" href="#custom-lexers-and-formatters">Custom Lexers and Formatters</a></li> <li><a class="reference internal" href="#getting-help">Getting help</a></li> <li><a class="reference internal" href="#a-note-on-encodings">A note on encodings</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="command-line-interface"> <h1>Command Line Interface<a class="headerlink" href="#command-line-interface" title="Permalink to this headline">¶</a></h1> <p>You can use Pygments from the shell, provided you installed the <strong class="program">pygmentize</strong> script:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize test.py print "Hello World" </pre></div> </div> <p>will print the file test.py to standard output, using the Python lexer (inferred from the file name extension) and the terminal formatter (because you didn’t give an explicit formatter name).</p> <p>If you want HTML output:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -f html -l python -o test.html test.py </pre></div> </div> <p>As you can see, the -l option explicitly selects a lexer. As seen above, if you give an input file name and it has an extension that Pygments recognizes, you can omit this option.</p> <p>The <code class="docutils literal notranslate"><span class="pre">-o</span></code> option gives an output file name. If it is not given, output is written to stdout.</p> <p>The <code class="docutils literal notranslate"><span class="pre">-f</span></code> option selects a formatter (as with <code class="docutils literal notranslate"><span class="pre">-l</span></code>, it can also be omitted if an output file name is given and has a supported extension). If no output file name is given and <code class="docutils literal notranslate"><span class="pre">-f</span></code> is omitted, the <a class="reference internal" href="formatters.html#TerminalFormatter" title="TerminalFormatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">TerminalFormatter</span></code></a> is used.</p> <p>The above command could therefore also be given as:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -o test.html test.py </pre></div> </div> <p>To create a full HTML document, including line numbers and stylesheet (using the “emacs” style), highlighting the Python file <code class="docutils literal notranslate"><span class="pre">test.py</span></code> to <code class="docutils literal notranslate"><span class="pre">test.html</span></code>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -O full,style=emacs -o test.html test.py </pre></div> </div> <div class="section" id="options-and-filters"> <h2>Options and filters<a class="headerlink" href="#options-and-filters" title="Permalink to this headline">¶</a></h2> <p>Lexer and formatter options can be given using the <code class="docutils literal notranslate"><span class="pre">-O</span></code> option:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -f html -O style=colorful,linenos=1 -l python test.py </pre></div> </div> <p>Be sure to enclose the option string in quotes if it contains any special shell characters, such as spaces or expansion wildcards like <code class="docutils literal notranslate"><span class="pre">*</span></code>. If an option expects a list value, separate the list entries with spaces (you’ll have to quote the option value in this case too, so that the shell doesn’t split it).</p> <p>Since the <code class="docutils literal notranslate"><span class="pre">-O</span></code> option argument is split at commas and expects the split values to be of the form <code class="docutils literal notranslate"><span class="pre">name=value</span></code>, you can’t give an option value that contains commas or equals signs. Therefore, an option <code class="docutils literal notranslate"><span class="pre">-P</span></code> is provided (as of Pygments 0.9) that works like <code class="docutils literal notranslate"><span class="pre">-O</span></code> but can only pass one option per <code class="docutils literal notranslate"><span class="pre">-P</span></code>. Its value can then contain all characters:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -P "heading=Pygments, the Python highlighter" ... </pre></div> </div> <p>Filters are added to the token stream using the <code class="docutils literal notranslate"><span class="pre">-F</span></code> option:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -f html -l pascal -F keywordcase:case=upper main.pas </pre></div> </div> <p>As you see, options for the filter are given after a colon. As for <code class="docutils literal notranslate"><span class="pre">-O</span></code>, the filter name and options must be one shell word, so there may not be any spaces around the colon.</p> </div> <div class="section" id="generating-styles"> <h2>Generating styles<a class="headerlink" href="#generating-styles" title="Permalink to this headline">¶</a></h2> <p>Formatters normally don’t output full style information. For example, the HTML formatter by default only outputs <code class="docutils literal notranslate"><span class="pre"><span></span></code> tags with <code class="docutils literal notranslate"><span class="pre">class</span></code> attributes. Therefore, there’s a special <code class="docutils literal notranslate"><span class="pre">-S</span></code> option for generating style definitions. Usage is as follows:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -f html -S colorful -a .syntax </pre></div> </div> <p>generates a CSS style sheet (because you selected the HTML formatter) for the “colorful” style prepending a “.syntax” selector to all style rules.</p> <p>For an explanation what <code class="docutils literal notranslate"><span class="pre">-a</span></code> means for <a class="reference internal" href="formatters.html"><span class="doc">a particular formatter</span></a>, look for the <cite>arg</cite> argument for the formatter’s <a class="reference internal" href="api.html#pygments.formatter.Formatter.get_style_defs" title="pygments.formatter.Formatter.get_style_defs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_style_defs()</span></code></a> method.</p> </div> <div class="section" id="getting-lexer-names"> <h2>Getting lexer names<a class="headerlink" href="#getting-lexer-names" title="Permalink to this headline">¶</a></h2> <div class="versionadded"> <p><span class="versionmodified">New in version 1.0.</span></p> </div> <p>The <code class="docutils literal notranslate"><span class="pre">-N</span></code> option guesses a lexer name for a given filename, so that</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -N setup.py </pre></div> </div> <p>will print out <code class="docutils literal notranslate"><span class="pre">python</span></code>. It won’t highlight anything yet. If no specific lexer is known for that filename, <code class="docutils literal notranslate"><span class="pre">text</span></code> is printed.</p> </div> <div class="section" id="custom-lexers-and-formatters"> <h2>Custom Lexers and Formatters<a class="headerlink" href="#custom-lexers-and-formatters" title="Permalink to this headline">¶</a></h2> <div class="versionadded"> <p><span class="versionmodified">New in version 2.2.</span></p> </div> <p>The <code class="docutils literal notranslate"><span class="pre">-x</span></code> flag enables custom lexers and formatters to be loaded from files relative to the current directory. Create a file with a class named CustomLexer or CustomFormatter, then specify it on the command line:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -l your_lexer.py -f your_formatter.py -x </pre></div> </div> <p>You can also specify the name of your class with a colon:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -l your_lexer.py:SomeLexer -x </pre></div> </div> <p>For more information, see <a class="reference internal" href="lexerdevelopment.html"><span class="doc">the Pygments documentation on Lexer development</span></a>.</p> </div> <div class="section" id="getting-help"> <h2>Getting help<a class="headerlink" href="#getting-help" title="Permalink to this headline">¶</a></h2> <p>The <code class="docutils literal notranslate"><span class="pre">-L</span></code> option lists lexers, formatters, along with their short names and supported file name extensions, styles and filters. If you want to see only one category, give it as an argument:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -L filters </pre></div> </div> <p>will list only all installed filters.</p> <p>The <code class="docutils literal notranslate"><span class="pre">-H</span></code> option will give you detailed information (the same that can be found in this documentation) about a lexer, formatter or filter. Usage is as follows:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -H formatter html </pre></div> </div> <p>will print the help for the HTML formatter, while</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pygmentize -H lexer python </pre></div> </div> <p>will print the help for the Python lexer, etc.</p> </div> <div class="section" id="a-note-on-encodings"> <h2>A note on encodings<a class="headerlink" href="#a-note-on-encodings" title="Permalink to this headline">¶</a></h2> <div class="versionadded"> <p><span class="versionmodified">New in version 0.9.</span></p> </div> <p>Pygments tries to be smart regarding encodings in the formatting process:</p> <ul class="simple"> <li>If you give an <code class="docutils literal notranslate"><span class="pre">encoding</span></code> option, it will be used as the input and output encoding.</li> <li>If you give an <code class="docutils literal notranslate"><span class="pre">outencoding</span></code> option, it will override <code class="docutils literal notranslate"><span class="pre">encoding</span></code> as the output encoding.</li> <li>If you give an <code class="docutils literal notranslate"><span class="pre">inencoding</span></code> option, it will override <code class="docutils literal notranslate"><span class="pre">encoding</span></code> as the input encoding.</li> <li>If you don’t give an encoding and have given an output file, the default encoding for lexer and formatter is the terminal encoding or the default locale encoding of the system. As a last resort, <code class="docutils literal notranslate"><span class="pre">latin1</span></code> is used (which will pass through all non-ASCII characters).</li> <li>If you don’t give an encoding and haven’t given an output file (that means output is written to the console), the default encoding for lexer and formatter is the terminal encoding (<code class="docutils literal notranslate"><span class="pre">sys.stdout.encoding</span></code>).</li> </ul> </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