353 lines
14 KiB
HTML
353 lines
14 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Command Line Interface — 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: #333333 } /* 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: #666666 } /* 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">Command Line Interface</h2>
|
|
|
|
<a id="backlink" href="index.html">« Back To Index</a>
|
|
|
|
|
|
<div class="toc">
|
|
<h2>Contents</h2>
|
|
<ul class="contents">
|
|
|
|
<li><a href="#options-and-filters">Options and filters</a></li>
|
|
|
|
<li><a href="#generating-styles">Generating styles</a></li>
|
|
|
|
<li><a href="#getting-lexer-names">Getting lexer names</a></li>
|
|
|
|
<li><a href="#getting-help">Getting help</a></li>
|
|
|
|
<li><a href="#a-note-on-encodings">A note on encodings</a></li>
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- -*- mode: rst -*- -->
|
|
<p>You can use Pygments from the shell, provided you installed the <cite>pygmentize</cite>
|
|
script:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize test.py
|
|
print "Hello World"
|
|
</pre>
|
|
<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>
|
|
<pre class="literal-block">
|
|
$ pygmentize -f html -l python -o test.html test.py
|
|
</pre>
|
|
<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 <tt class="docutils literal"><span class="pre">-o</span></tt> option gives an output file name. If it is not given, output is
|
|
written to stdout.</p>
|
|
<p>The <tt class="docutils literal"><span class="pre">-f</span></tt> option selects a formatter (as with <tt class="docutils literal"><span class="pre">-l</span></tt>, 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 <tt class="docutils literal"><span class="pre">-f</span></tt> is omitted, the
|
|
<cite>TerminalFormatter</cite> is used.</p>
|
|
<p>The above command could therefore also be given as:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -o test.html test.py
|
|
</pre>
|
|
<p>To create a full HTML document, including line numbers and stylesheet (using the
|
|
"emacs" style), highlighting the Python file <tt class="docutils literal">test.py</tt> to <tt class="docutils literal">test.html</tt>:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -O full,style=emacs -o test.html test.py
|
|
</pre>
|
|
<div class="section" id="options-and-filters">
|
|
<h3>Options and filters</h3>
|
|
<p>Lexer and formatter options can be given using the <tt class="docutils literal"><span class="pre">-O</span></tt> option:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -f html -O style=colorful,linenos=1 -l python test.py
|
|
</pre>
|
|
<p>Be sure to enclose the option string in quotes if it contains any special shell
|
|
characters, such as spaces or expansion wildcards like <tt class="docutils literal">*</tt>. 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 <tt class="docutils literal"><span class="pre">-O</span></tt> option argument is split at commas and expects the split values
|
|
to be of the form <tt class="docutils literal">name=value</tt>, you can't give an option value that contains
|
|
commas or equals signs. Therefore, an option <tt class="docutils literal"><span class="pre">-P</span></tt> is provided (as of Pygments
|
|
0.9) that works like <tt class="docutils literal"><span class="pre">-O</span></tt> but can only pass one option per <tt class="docutils literal"><span class="pre">-P</span></tt>. Its value
|
|
can then contain all characters:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -P "heading=Pygments, the Python highlighter" ...
|
|
</pre>
|
|
<p>Filters are added to the token stream using the <tt class="docutils literal"><span class="pre">-F</span></tt> option:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -f html -l pascal -F keywordcase:case=upper main.pas
|
|
</pre>
|
|
<p>As you see, options for the filter are given after a colon. As for <tt class="docutils literal"><span class="pre">-O</span></tt>, 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">
|
|
<h3>Generating styles</h3>
|
|
<p>Formatters normally don't output full style information. For example, the HTML
|
|
formatter by default only outputs <tt class="docutils literal"><span></tt> tags with <tt class="docutils literal">class</tt> attributes.
|
|
Therefore, there's a special <tt class="docutils literal"><span class="pre">-S</span></tt> option for generating style definitions.
|
|
Usage is as follows:</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -f html -S colorful -a .syntax
|
|
</pre>
|
|
<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 <tt class="docutils literal"><span class="pre">-a</span></tt> means for <a class="reference external" href="./formatters.html">a particular formatter</a>, look for
|
|
the <cite>arg</cite> argument for the formatter's <cite>get_style_defs()</cite> method.</p>
|
|
</div>
|
|
<div class="section" id="getting-lexer-names">
|
|
<h3>Getting lexer names</h3>
|
|
<p><em>New in Pygments 1.0.</em></p>
|
|
<p>The <tt class="docutils literal"><span class="pre">-N</span></tt> option guesses a lexer name for a given filename, so that</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -N setup.py
|
|
</pre>
|
|
<p>will print out <tt class="docutils literal">python</tt>. It won't highlight anything yet. If no specific
|
|
lexer is known for that filename, <tt class="docutils literal">text</tt> is printed.</p>
|
|
</div>
|
|
<div class="section" id="getting-help">
|
|
<h3>Getting help</h3>
|
|
<p>The <tt class="docutils literal"><span class="pre">-L</span></tt> 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>
|
|
<pre class="literal-block">
|
|
$ pygmentize -L filters
|
|
</pre>
|
|
<p>will list only all installed filters.</p>
|
|
<p>The <tt class="docutils literal"><span class="pre">-H</span></tt> 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>
|
|
<pre class="literal-block">
|
|
$ pygmentize -H formatter html
|
|
</pre>
|
|
<p>will print the help for the HTML formatter, while</p>
|
|
<pre class="literal-block">
|
|
$ pygmentize -H lexer python
|
|
</pre>
|
|
<p>will print the help for the Python lexer, etc.</p>
|
|
</div>
|
|
<div class="section" id="a-note-on-encodings">
|
|
<h3>A note on encodings</h3>
|
|
<p><em>New in Pygments 0.9.</em></p>
|
|
<p>Pygments tries to be smart regarding encodings in the formatting process:</p>
|
|
<ul class="simple">
|
|
<li>If you give an <tt class="docutils literal">encoding</tt> option, it will be used as the input and
|
|
output encoding.</li>
|
|
<li>If you give an <tt class="docutils literal">outencoding</tt> option, it will override <tt class="docutils literal">encoding</tt>
|
|
as the output encoding.</li>
|
|
<li>If you don't give an encoding and have given an output file, the default
|
|
encoding for lexer and formatter is <tt class="docutils literal">latin1</tt> (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 (<cite>sys.stdout.encoding</cite>).</li>
|
|
</ul>
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
<!-- generated on: 2013-01-09 17:48:42.595138
|
|
file id: cmdline -->
|
|
</html> |