/usr/share/doc/python-pygments-doc/html/docs/java.html is in python-pygments-doc 2.0.1+dfsg-1.1+deb8u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | <!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="Content-Type" content="text/html; charset=utf-8" />
<title>Use Pygments in Java — Pygments 2.0.1 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</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="top" title="Pygments 2.0.1 documentation" href="../index.html" />
<link rel="up" title="Pygments documentation" href="index.html" />
<link rel="next" title="Using Pygments in various scenarios" href="integrate.html" />
<link rel="prev" title="Using Pygments with MoinMoin" href="moinmoin.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="integrate.html" title="Using Pygments in various scenarios"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="moinmoin.html" title="Using Pygments with MoinMoin"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">Pygments 2.0.1 documentation</a> »</li>
<li><a href="index.html" accesskey="U">Pygments documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="use-pygments-in-java">
<h1>Use Pygments in Java<a class="headerlink" href="#use-pygments-in-java" title="Permalink to this headline">ΒΆ</a></h1>
<p>Thanks to <a class="reference external" href="http://www.jython.org">Jython</a> it is possible to use Pygments in
Java.</p>
<p>This page is a simple tutorial to get an idea of how this is working. You can
then look at the <a class="reference external" href="http://www.jython.org/docs/">Jython documentation</a> for more
advanced use.</p>
<p>Since version 1.5, Pygments is deployed on <a class="reference external" href="http://repo1.maven.org/maven2/org/pygments/pygments/">Maven Central</a> as a JAR so is Jython
which makes it a lot easier to create the Java project.</p>
<p>Here is an example of a <a class="reference external" href="http://www.maven.org">Maven</a> <tt class="docutils literal"><span class="pre">pom.xml</span></tt> file for a
project running Pygments:</p>
<div class="highlight-xml"><div class="highlight"><pre><span class="cp"><?xml version="1.0" encoding="UTF-8"?></span>
<span class="nt"><project</span> <span class="na">xmlns=</span><span class="s">"http://maven.apache.org/POM/4.0.0"</span>
<span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span>
<span class="na">xsi:schemaLocation=</span><span class="s">"http://maven.apache.org/POM/4.0.0</span>
<span class="s"> http://maven.apache.org/maven-v4_0_0.xsd"</span><span class="nt">></span>
<span class="nt"><modelVersion></span>4.0.0<span class="nt"></modelVersion></span>
<span class="nt"><groupId></span>example<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>example<span class="nt"></artifactId></span>
<span class="nt"><version></span>1.0-SNAPSHOT<span class="nt"></version></span>
<span class="nt"><dependencies></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.python<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>jython-standalone<span class="nt"></artifactId></span>
<span class="nt"><version></span>2.5.3<span class="nt"></version></span>
<span class="nt"></dependency></span>
<span class="nt"><dependency></span>
<span class="nt"><groupId></span>org.pygments<span class="nt"></groupId></span>
<span class="nt"><artifactId></span>pygments<span class="nt"></artifactId></span>
<span class="nt"><version></span>1.5<span class="nt"></version></span>
<span class="nt"><scope></span>runtime<span class="nt"></scope></span>
<span class="nt"></dependency></span>
<span class="nt"></dependencies></span>
<span class="nt"></project></span>
</pre></div>
</div>
<p>The following Java example:</p>
<div class="highlight-java"><div class="highlight"><pre><span class="n">PythonInterpreter</span> <span class="n">interpreter</span> <span class="o">=</span> <span class="k">new</span> <span class="n">PythonInterpreter</span><span class="o">();</span>
<span class="c1">// Set a variable with the content you want to work with</span>
<span class="n">interpreter</span><span class="o">.</span><span class="na">set</span><span class="o">(</span><span class="s">"code"</span><span class="o">,</span> <span class="n">code</span><span class="o">);</span>
<span class="c1">// Simple use Pygments as you would in Python</span>
<span class="n">interpreter</span><span class="o">.</span><span class="na">exec</span><span class="o">(</span><span class="s">"from pygments import highlight\n"</span>
<span class="o">+</span> <span class="s">"from pygments.lexers import PythonLexer\n"</span>
<span class="o">+</span> <span class="s">"from pygments.formatters import HtmlFormatter\n"</span>
<span class="o">+</span> <span class="s">"\nresult = highlight(code, PythonLexer(), HtmlFormatter())"</span><span class="o">);</span>
<span class="c1">// Get the result that has been set in a variable</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">interpreter</span><span class="o">.</span><span class="na">get</span><span class="o">(</span><span class="s">"result"</span><span class="o">,</span> <span class="n">String</span><span class="o">.</span><span class="na">class</span><span class="o">));</span>
</pre></div>
</div>
<p>will print something like:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt"><div</span> <span class="na">class=</span><span class="s">"highlight"</span><span class="nt">></span>
<span class="nt"><pre><span</span> <span class="na">class=</span><span class="s">"k"</span><span class="nt">></span>print<span class="nt"></span></span> <span class="nt"><span</span> <span class="na">class=</span><span class="s">"s"</span><span class="nt">></span><span class="ni">&quot;</span>Hello World<span class="ni">&quot;</span><span class="nt"></span></pre></span>
<span class="nt"></div></span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="moinmoin.html"
title="previous chapter">Using Pygments with MoinMoin</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="integrate.html"
title="next chapter">Using Pygments in various scenarios</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/docs/java.txt"
rel="nofollow">Show Source</a></li>
</ul>
<strong>« <a href="index.html">Back to docs index</a></strong>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<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>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="integrate.html" title="Using Pygments in various scenarios"
>next</a> |</li>
<li class="right" >
<a href="moinmoin.html" title="Using Pygments with MoinMoin"
>previous</a> |</li>
<li><a href="../index.html">Pygments 2.0.1 documentation</a> »</li>
<li><a href="index.html" >Pygments documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2014, Georg Brandl.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>
|