Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
132 changed files
with
8,423 additions
and
1,413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
changelog | ||
=========== | ||
|
||
Version 0.3.4 (Dec 28, 2012) | ||
|
||
* Add support for Windows | ||
* Add MIT license | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
157c9feaccb8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
===================== | ||
Use Pygments in Java | ||
===================== | ||
|
||
Thanks to `Jython <http://www.jython.org>`__ it is possible to use Pygments in | ||
Java. | ||
|
||
This page is a simple tutorial to get an idea of how this is working. You can | ||
then look at the `Jython documentation <http://www.jython.org/docs/>`__ for more | ||
advanced use. | ||
|
||
Since version 1.5, Pygments is deployed on `Maven Central | ||
<http://repo1.maven.org/maven2/org/pygments/pygments/>`__ as a JAR so is Jython | ||
which makes it a lot easier to create the Java project. | ||
|
||
Here is an example of a `Maven <http://www.maven.org>`__ ``pom.xml`` file for a | ||
project running Pygments: | ||
|
||
.. sourcecode:: xml | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>example</groupId> | ||
<artifactId>example</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.python</groupId> | ||
<artifactId>jython-standalone</artifactId> | ||
<version>2.5.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.pygments</groupId> | ||
<artifactId>pygments</artifactId> | ||
<version>1.5</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
|
||
The following Java example: | ||
|
||
.. sourcecode:: java | ||
|
||
PythonInterpreter interpreter = new PythonInterpreter(); | ||
|
||
// Set a variable with the content you want to work with | ||
interpreter.set("code", code); | ||
|
||
// Simple use Pygments as you would in Python | ||
interpreter.exec("from pygments import highlight\n" | ||
+ "from pygments.lexers import PythonLexer\n" | ||
+ "from pygments.formatters import HtmlFormatter\n" | ||
+ "\nresult = highlight(code, PythonLexer(), HtmlFormatter())"); | ||
|
||
// Get the result that has been set in a variable | ||
System.out.println(interpreter.get("result", String.class)); | ||
|
||
will print something like: | ||
|
||
.. sourcecode:: html | ||
|
||
<div class="highlight"> | ||
<pre><span class="k">print</span> <span class="s">"Hello World"</span></pre> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/sh | ||
# Best effort auto-pygmentization with transparent decompression | ||
# (c) Reuben Thomas 2012-2013 | ||
# This program is in the public domain. | ||
|
||
# Strategy: first see if pygmentize can find a lexer; if not, ask file; if that finds nothing, fail | ||
# Set the environment variable PYGMENTIZE_OPTS to configure pygments. | ||
|
||
# This program can be used as a .lessfilter for the less pager to auto-color less's output | ||
|
||
lexer=`pygmentize -N "$1"` | ||
if [ "$lexer" = "text" ]; then | ||
file_common_opts="--brief --dereference --uncompress" | ||
|
||
unset lexer | ||
case `file --mime-type $file_common_opts "$1"` in | ||
application/xml|image/svg+xml) lexer=xml;; | ||
text/html) lexer=html;; | ||
text/troff) lexer=nroff;; | ||
text/x-asm) lexer=nasm;; | ||
text/x-awk) lexer=awk;; | ||
text/x-c) lexer=c;; | ||
text/x-c++) lexer=cpp;; | ||
text/x-diff) lexer=diff;; | ||
text/x-fortran) lexer=fortran;; | ||
text/x-gawk) lexer=gawk;; | ||
text/x-java) lexer=java;; | ||
text/x-lisp) lexer=common-lisp;; | ||
text/x-lua) lexer=lua;; | ||
text/x-makefile) lexer=make;; | ||
text/x-msdos-batch) lexer=bat;; | ||
text/x-nawk) lexer=nawk;; | ||
text/x-pascal) lexer=pascal;; | ||
text/x-perl) lexer=perl;; | ||
text/x-php) lexer=php;; | ||
text/x-po) lexer=po;; | ||
text/x-python) lexer=python;; | ||
text/x-ruby) lexer=ruby;; | ||
text/x-shellscript) lexer=sh;; | ||
text/x-tcl) lexer=tcl;; | ||
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer | ||
|
||
# Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.6rc1 | ||
# text/calendar | ||
# text/PGP | ||
# text/rtf | ||
# text/texmacs | ||
# text/x-bcpl | ||
# text/x-info | ||
# text/x-m4 | ||
# text/x-vcard | ||
# text/x-xmcd | ||
esac | ||
fi | ||
|
||
encoding=`file --brief --mime-encoding $file_common_opts "$1"` | ||
|
||
if [ -n "$lexer" ]; then | ||
# FIXME: Specify input encoding rather than output encoding https://bitbucket.org/birkenfeld/pygments-main/issue/800 | ||
zcat "$1" | pygmentize -O encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS -l $lexer | ||
exit 0 | ||
fi | ||
|
||
exit 1 |
Oops, something went wrong.