Update vendor'd Pygments to 2.1.3

This commit is contained in:
Mark McGranaghan 2016-12-27 08:10:47 -08:00
parent cca7879dce
commit 6165952ce2
524 changed files with 106264 additions and 46754 deletions

19
vendor/pygments/.hgignore vendored Normal file
View File

@ -0,0 +1,19 @@
syntax: glob
*.egg
*.pyc
*.pyo
.*.sw[op]
.idea/
.ropeproject
.project
.tags
.tox
Pygments.egg-info/*
TAGS
build/*
dist/*
doc/_build
TAGS
tests/.coverage
tests/cover
tests/examplefiles/output

31
vendor/pygments/.hgtags vendored Normal file
View File

@ -0,0 +1,31 @@
634420aa4221cc1eb2b3753bd571166bd9e611d4 0.9
942ecbb5c84ca5d57ae82f5697775973f4e12717 0.10
63632d0340958d891176db20fe9a32a56abcd5ea 0.11
13834ec94d2c5a90a68bc2c2a327abd962c486bc 0.11.1
a5748745272afffd725570e068a560d46e28dc1f 1.0
5a794a620dc711a219722a7af94d9d2e95cda26d 1.1
dd81c35efd95292de4965153c66c8bbfe435f1c4 1.1.1
e7691aa4f473a2cdaa2e5b7bfed8aec196719aca 0.5.1
6f53364d63ddb8bd9532bb6ea402e3af05275b03 0.5
11efe99c11e601071c3a77910b9fca769de66fbf 0.6
99df0a7404d168b05626ffced6fd16edcf58c145 0.7
d0b08fd569d3d9dafec4c045a7d8876442b3ef64 0.7.1
1054522d1dda9c7899516ead3e65e5e363fdf30d 0.8
066e56d8f5caa31e15386fff6f938bedd85a8732 0.8.1
bae0833cae75e5a641abe3c4b430fa384cd9d258 1.2
f6e5acee4f761696676e05a9112c91a5a5670b49 1.2.1
580c5ce755486bc92c79c50f80cfc79924e15140 1.2.2
c62867700c9e98cc2988c62f298ec54cee9b6927 1.3
3a3846c2503db85bb70a243c8bc702629c4bce57 1.3.1
8ad6d35dd2ab0530a1e2c088ab7fe0e00426b5f9 1.4
eff3aee4abff2b72564ddfde77fcc82adbba52ad 1.5
2c262bfc66b05a8aecc1109c3acc5b9447a5213c 1.6rc1
7c962dcb484cb73394aec7f41709940340dc8a9c 1.6
da509a68ea620bbb8ee3f5d5cf7761375d8f4451 2.0rc1
ed3206a773e9cb90a0edeabee8ef6b56b5b9a53c 2.0
94e1e056c92d97e3a54759f9216e8deff22efbdd 2.0.1
142a870bf0f1822414649ae26f433b112a5c92d5 2.0.2
34530db252d35d7ef57a8dbb9fce7bcc46f6ba6b 2.1
2935c3a59672e8ae74ffb7ea66ea6567f49782f6 2.1.1
8e7ebc56153cf899067333bff4f15ae98758a2e1 2.1.2
88527db663dce0729c2cd6e3bc2f3c657ae39254 2.1.3

View File

@ -6,76 +6,117 @@ Major developers are Tim Hatch <tim@timhatch.com> and Armin Ronacher
Other contributors, listed alphabetically, are: Other contributors, listed alphabetically, are:
* Sam Aaron -- Ioke lexer * Sam Aaron -- Ioke lexer
* Kumar Appaiah -- Debian control lexer
* Ali Afshar -- image formatter * Ali Afshar -- image formatter
* Thomas Aglassinger -- Easytrieve, JCL and Rexx lexers
* Muthiah Annamalai -- Ezhil lexer
* Kumar Appaiah -- Debian control lexer
* Andreas Amann -- AppleScript lexer * Andreas Amann -- AppleScript lexer
* Timothy Armstrong -- Dart lexer fixes * Timothy Armstrong -- Dart lexer fixes
* Jeffrey Arnold -- R/S, Rd, BUGS, Jags, and Stan lexers * Jeffrey Arnold -- R/S, Rd, BUGS, Jags, and Stan lexers
* Jeremy Ashkenas -- CoffeeScript lexer * Jeremy Ashkenas -- CoffeeScript lexer
* José Joaquín Atria -- Praat lexer
* Stefan Matthias Aust -- Smalltalk lexer * Stefan Matthias Aust -- Smalltalk lexer
* Lucas Bajolet -- Nit lexer
* Ben Bangert -- Mako lexers * Ben Bangert -- Mako lexers
* Max Battcher -- Darcs patch lexer * Max Battcher -- Darcs patch lexer
* Thomas Baruchel -- APL lexer
* Tim Baumann -- (Literate) Agda lexer
* Paul Baumgart, 280 North, Inc. -- Objective-J lexer * Paul Baumgart, 280 North, Inc. -- Objective-J lexer
* Michael Bayer -- Myghty lexers * Michael Bayer -- Myghty lexers
* Thomas Beale -- Archetype lexers
* John Benediktsson -- Factor lexer * John Benediktsson -- Factor lexer
* Trevor Bergeron -- mIRC formatter
* Vincent Bernat -- LessCSS lexer
* Christopher Bertels -- Fancy lexer * Christopher Bertels -- Fancy lexer
* Sébastien Bigaret -- QVT Operational lexer
* Jarrett Billingsley -- MiniD lexer * Jarrett Billingsley -- MiniD lexer
* Adam Blinkinsop -- Haskell, Redcode lexers * Adam Blinkinsop -- Haskell, Redcode lexers
* Frits van Bommel -- assembler lexers * Frits van Bommel -- assembler lexers
* Pierre Bourdon -- bugfixes * Pierre Bourdon -- bugfixes
* chebee7i -- Python traceback lexer improvements
* Hiram Chirino -- Scaml and Jade lexers * Hiram Chirino -- Scaml and Jade lexers
* Ian Cooper -- VGL lexer * Ian Cooper -- VGL lexer
* David Corbett -- Inform, Jasmin, and TADS 3 lexers
* Leaf Corcoran -- MoonScript lexer * Leaf Corcoran -- MoonScript lexer
* Christian Jann -- ShellSession lexer
* Christopher Creutzig -- MuPAD lexer * Christopher Creutzig -- MuPAD lexer
* Daniël W. Crompton -- Pike lexer
* Pete Curry -- bugfixes * Pete Curry -- bugfixes
* Owen Durni -- haXe lexer * Bryan Davis -- EBNF lexer
* Bruno Deferrari -- Shen lexer
* Giedrius Dubinskas -- HTML formatter improvements
* Owen Durni -- Haxe lexer
* Alexander Dutton, Oxford University Computing Services -- SPARQL lexer
* James Edwards -- Terraform lexer
* Nick Efford -- Python 3 lexer * Nick Efford -- Python 3 lexer
* Sven Efftinge -- Xtend lexer * Sven Efftinge -- Xtend lexer
* Artem Egorkine -- terminal256 formatter * Artem Egorkine -- terminal256 formatter
* Matthew Fernandez -- CAmkES lexer
* Michael Ficarra -- CPSA lexer
* James H. Fisher -- PostScript lexer * James H. Fisher -- PostScript lexer
* William S. Fulton -- SWIG lexer
* Carlos Galdino -- Elixir and Elixir Console lexers * Carlos Galdino -- Elixir and Elixir Console lexers
* Michael Galloy -- IDL lexer * Michael Galloy -- IDL lexer
* Naveen Garg -- Autohotkey lexer * Naveen Garg -- Autohotkey lexer
* Laurent Gautier -- R/S lexer * Laurent Gautier -- R/S lexer
* Alex Gaynor -- PyPy log lexer * Alex Gaynor -- PyPy log lexer
* Richard Gerkin -- Igor Pro lexer
* Alain Gilbert -- TypeScript lexer * Alain Gilbert -- TypeScript lexer
* Alex Gilding -- BlitzBasic lexer
* Bertrand Goetzmann -- Groovy lexer * Bertrand Goetzmann -- Groovy lexer
* Krzysiek Goj -- Scala lexer * Krzysiek Goj -- Scala lexer
* Matt Good -- Genshi, Cheetah lexers * Matt Good -- Genshi, Cheetah lexers
* Michał Górny -- vim modeline support
* Alex Gosse -- TrafficScript lexer
* Patrick Gotthardt -- PHP namespaces support * Patrick Gotthardt -- PHP namespaces support
* Olivier Guibe -- Asymptote lexer * Olivier Guibe -- Asymptote lexer
* Jordi Gutiérrez Hermoso -- Octave lexer * Jordi Gutiérrez Hermoso -- Octave lexer
* Florian Hahn -- Boogie lexer
* Martin Harriman -- SNOBOL lexer * Martin Harriman -- SNOBOL lexer
* Matthew Harrison -- SVG formatter * Matthew Harrison -- SVG formatter
* Steven Hazel -- Tcl lexer * Steven Hazel -- Tcl lexer
* Dan Michael Heggø -- Turtle lexer
* Aslak Hellesøy -- Gherkin lexer * Aslak Hellesøy -- Gherkin lexer
* Greg Hendershott -- Racket lexer * Greg Hendershott -- Racket lexer
* Justin Hendrick -- ParaSail lexer
* David Hess, Fish Software, Inc. -- Objective-J lexer * David Hess, Fish Software, Inc. -- Objective-J lexer
* Varun Hiremath -- Debian control lexer * Varun Hiremath -- Debian control lexer
* Rob Hoelz -- Perl 6 lexer
* Doug Hogan -- Mscgen lexer * Doug Hogan -- Mscgen lexer
* Ben Hollis -- Mason lexer * Ben Hollis -- Mason lexer
* Dustin Howett -- Logos lexer * Max Horn -- GAP lexer
* Alastair Houghton -- Lexer inheritance facility * Alastair Houghton -- Lexer inheritance facility
* Tim Howard -- BlitzMax lexer * Tim Howard -- BlitzMax lexer
* Dustin Howett -- Logos lexer
* Ivan Inozemtsev -- Fantom lexer * Ivan Inozemtsev -- Fantom lexer
* Hiroaki Itoh -- Shell console rewrite, Lexers for PowerShell session, MSDOS session, BC
* Brian R. Jackson -- Tea lexer * Brian R. Jackson -- Tea lexer
* Christian Jann -- ShellSession lexer
* Dennis Kaarsemaker -- sources.list lexer * Dennis Kaarsemaker -- sources.list lexer
* Dmitri Kabak -- Inferno Limbo lexer
* Igor Kalnitsky -- vhdl lexer * Igor Kalnitsky -- vhdl lexer
* Alexander Kit -- MaskJS lexer
* Pekka Klärck -- Robot Framework lexer * Pekka Klärck -- Robot Framework lexer
* Gerwin Klein -- Isabelle lexer
* Eric Knibbe -- Lasso lexer * Eric Knibbe -- Lasso lexer
* Stepan Koltsov -- Clay lexer
* Adam Koprowski -- Opa lexer * Adam Koprowski -- Opa lexer
* Benjamin Kowarsch -- Modula-2 lexer * Benjamin Kowarsch -- Modula-2 lexer
* Domen Kožar -- Nix lexer
* Oleh Krekel -- Emacs Lisp lexer
* Alexander Kriegisch -- Kconfig and AspectJ lexers * Alexander Kriegisch -- Kconfig and AspectJ lexers
* Marek Kubica -- Scheme lexer * Marek Kubica -- Scheme lexer
* Jochen Kupperschmidt -- Markdown processor * Jochen Kupperschmidt -- Markdown processor
* Gerd Kurzbach -- Modelica lexer * Gerd Kurzbach -- Modelica lexer
* Jon Larimer, Google Inc. -- Smali lexer * Jon Larimer, Google Inc. -- Smali lexer
* Olov Lassus -- Dart lexer * Olov Lassus -- Dart lexer
* Matt Layman -- TAP lexer
* Sylvestre Ledru -- Scilab lexer * Sylvestre Ledru -- Scilab lexer
* Mark Lee -- Vala lexer * Mark Lee -- Vala lexer
* Valentin Lorentz -- C++ lexer improvements
* Ben Mabey -- Gherkin lexer * Ben Mabey -- Gherkin lexer
* Angus MacArthur -- QML lexer * Angus MacArthur -- QML lexer
* Louis Mandel -- X10 lexer
* Louis Marchand -- Eiffel lexer
* Simone Margaritelli -- Hybris lexer * Simone Margaritelli -- Hybris lexer
* Kirk McDonald -- D lexer * Kirk McDonald -- D lexer
* Gordon McGregor -- SystemVerilog lexer * Gordon McGregor -- SystemVerilog lexer
@ -83,6 +124,7 @@ Other contributors, listed alphabetically, are:
* Brian McKenna -- F# lexer * Brian McKenna -- F# lexer
* Charles McLaughlin -- Puppet lexer * Charles McLaughlin -- Puppet lexer
* Lukas Meuser -- BBCode formatter, Lua lexer * Lukas Meuser -- BBCode formatter, Lua lexer
* Cat Miller -- Pig lexer
* Paul Miller -- LiveScript lexer * Paul Miller -- LiveScript lexer
* Hong Minhee -- HTTP lexer * Hong Minhee -- HTTP lexer
* Michael Mior -- Awk lexer * Michael Mior -- Awk lexer
@ -91,24 +133,32 @@ Other contributors, listed alphabetically, are:
* Jon Morton -- Rust lexer * Jon Morton -- Rust lexer
* Paulo Moura -- Logtalk lexer * Paulo Moura -- Logtalk lexer
* Mher Movsisyan -- DTD lexer * Mher Movsisyan -- DTD lexer
* Dejan Muhamedagic -- Crmsh lexer
* Ana Nelson -- Ragel, ANTLR, R console lexers * Ana Nelson -- Ragel, ANTLR, R console lexers
* Nam T. Nguyen -- Monokai style * Nam T. Nguyen -- Monokai style
* Jesper Noehr -- HTML formatter "anchorlinenos" * Jesper Noehr -- HTML formatter "anchorlinenos"
* Mike Nolta -- Julia lexer * Mike Nolta -- Julia lexer
* Jonas Obrist -- BBCode lexer * Jonas Obrist -- BBCode lexer
* Edward O'Callaghan -- Cryptol lexer
* David Oliva -- Rebol lexer * David Oliva -- Rebol lexer
* Jon Parise -- Protocol buffers lexer * Pat Pannuto -- nesC lexer
* Ronny Pfannschmidt -- BBCode lexer * Jon Parise -- Protocol buffers and Thrift lexers
* Benjamin Peterson -- Test suite refactoring * Benjamin Peterson -- Test suite refactoring
* Ronny Pfannschmidt -- BBCode lexer
* Dominik Picheta -- Nimrod lexer * Dominik Picheta -- Nimrod lexer
* Andrew Pinkham -- RTF Formatter Refactoring
* Clément Prévost -- UrbiScript lexer * Clément Prévost -- UrbiScript lexer
* Elias Rabel -- Fortran fixed form lexer
* raichoo -- Idris lexer
* Kashif Rasul -- CUDA lexer * Kashif Rasul -- CUDA lexer
* Justin Reidy -- MXML lexer * Justin Reidy -- MXML lexer
* Norman Richards -- JSON lexer * Norman Richards -- JSON lexer
* Corey Richardson -- Rust lexer updates
* Lubomir Rintel -- GoodData MAQL and CL lexers * Lubomir Rintel -- GoodData MAQL and CL lexers
* Andre Roberge -- Tango style * Andre Roberge -- Tango style
* Konrad Rudolph -- LaTeX formatter enhancements * Konrad Rudolph -- LaTeX formatter enhancements
* Mario Ruggier -- Evoque lexers * Mario Ruggier -- Evoque lexers
* Miikka Salminen -- Lovelace style, Hexdump lexer, lexer enhancements
* Stou Sandalski -- NumPy, FORTRAN, tcsh and XSLT lexers * Stou Sandalski -- NumPy, FORTRAN, tcsh and XSLT lexers
* Matteo Sasso -- Common Lisp lexer * Matteo Sasso -- Common Lisp lexer
* Joe Schafer -- Ada lexer * Joe Schafer -- Ada lexer
@ -123,21 +173,30 @@ Other contributors, listed alphabetically, are:
* Jerome St-Louis -- eC lexer * Jerome St-Louis -- eC lexer
* James Strachan -- Kotlin lexer * James Strachan -- Kotlin lexer
* Tom Stuart -- Treetop lexer * Tom Stuart -- Treetop lexer
* Colin Sullivan -- SuperCollider lexer
* Edoardo Tenani -- Arduino lexer
* Tiberius Teng -- default style overhaul * Tiberius Teng -- default style overhaul
* Jeremy Thurgood -- Erlang, Squid config lexers * Jeremy Thurgood -- Erlang, Squid config lexers
* Brian Tiffin -- OpenCOBOL lexer * Brian Tiffin -- OpenCOBOL lexer
* Bob Tolbert -- Hy lexer
* Erick Tryzelaar -- Felix lexer * Erick Tryzelaar -- Felix lexer
* Alexander Udalov -- Kotlin lexer improvements
* Thomas Van Doren -- Chapel lexer
* Daniele Varrazzo -- PostgreSQL lexers * Daniele Varrazzo -- PostgreSQL lexers
* Abe Voelker -- OpenEdge ABL lexer * Abe Voelker -- OpenEdge ABL lexer
* Pepijn de Vos -- HTML formatter CTags support * Pepijn de Vos -- HTML formatter CTags support
* Whitney Young -- ObjectiveC lexer
* Matthias Vallentin -- Bro lexer * Matthias Vallentin -- Bro lexer
* Linh Vu Hong -- RSL lexer
* Nathan Weizenbaum -- Haml and Sass lexers * Nathan Weizenbaum -- Haml and Sass lexers
* Nathan Whetsell -- Csound lexers
* Dietmar Winkler -- Modelica lexer * Dietmar Winkler -- Modelica lexer
* Nils Winter -- Smalltalk lexer * Nils Winter -- Smalltalk lexer
* Davy Wybiral -- Clojure lexer * Davy Wybiral -- Clojure lexer
* Whitney Young -- ObjectiveC lexer
* Diego Zamboni -- CFengine3 lexer * Diego Zamboni -- CFengine3 lexer
* Enrique Zamudio -- Ceylon lexer * Enrique Zamudio -- Ceylon lexer
* Alex Zimin -- Nemerle lexer * Alex Zimin -- Nemerle lexer
* Rob Zimmerman -- Kal lexer
* Vincent Zurczak -- Roboconf lexer
Many thanks for all contributions! Many thanks for all contributions!

View File

@ -2,9 +2,305 @@ Pygments changelog
================== ==================
Issue numbers refer to the tracker at Issue numbers refer to the tracker at
<http://bitbucket.org/birkenfeld/pygments-main/issues>, <https://bitbucket.org/birkenfeld/pygments-main/issues>,
pull request numbers to the requests at pull request numbers to the requests at
<http://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>. <https://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>.
Version 2.1.3
-------------
(released Mar 2, 2016)
- Fixed regression in Bash lexer (PR#563)
Version 2.1.2
-------------
(released Feb 29, 2016)
- Fixed Python 3 regression in image formatter (#1215)
- Fixed regression in Bash lexer (PR#562)
Version 2.1.1
-------------
(relased Feb 14, 2016)
- Fixed Jython compatibility (#1205)
- Fixed HTML formatter output with leading empty lines (#1111)
- Added a mapping table for LaTeX encodings and added utf8 (#1152)
- Fixed image formatter font searching on Macs (#1188)
- Fixed deepcopy-ing of Token instances (#1168)
- Fixed Julia string interpolation (#1170)
- Fixed statefulness of HttpLexer between get_tokens calls
- Many smaller fixes to various lexers
Version 2.1
-----------
(released Jan 17, 2016)
- Added lexers:
* Emacs Lisp (PR#431)
* Arduino (PR#442)
* Modula-2 with multi-dialect support (#1090)
* Fortran fixed format (PR#213)
* Archetype Definition language (PR#483)
* Terraform (PR#432)
* Jcl, Easytrieve (PR#208)
* ParaSail (PR#381)
* Boogie (PR#420)
* Turtle (PR#425)
* Fish Shell (PR#422)
* Roboconf (PR#449)
* Test Anything Protocol (PR#428)
* Shen (PR#385)
* Component Pascal (PR#437)
* SuperCollider (PR#472)
* Shell consoles (Tcsh, PowerShell, MSDOS) (PR#479)
* Elm and J (PR#452)
* Crmsh (PR#440)
* Praat (PR#492)
* CSound (PR#494)
* Ezhil (PR#443)
* Thrift (PR#469)
* QVT Operational (PR#204)
* Hexdump (PR#508)
* CAmkES Configuration (PR#462)
- Added styles:
* Lovelace (PR#456)
* Algol and Algol-nu (#1090)
- Added formatters:
* IRC (PR#458)
* True color (24-bit) terminal ANSI sequences (#1142)
(formatter alias: "16m")
- New "filename" option for HTML formatter (PR#527).
- Improved performance of the HTML formatter for long lines (PR#504).
- Updated autopygmentize script (PR#445).
- Fixed style inheritance for non-standard token types in HTML output.
- Added support for async/await to Python 3 lexer.
- Rewrote linenos option for TerminalFormatter (it's better, but slightly
different output than before) (#1147).
- Javascript lexer now supports most of ES6 (#1100).
- Cocoa builtins updated for iOS 8.1 (PR#433).
- Combined BashSessionLexer and ShellSessionLexer, new version should support
the prompt styles of either.
- Added option to pygmentize to show a full traceback on exceptions.
- Fixed incomplete output on Windows and Python 3 (e.g. when using iPython
Notebook) (#1153).
- Allowed more traceback styles in Python console lexer (PR#253).
- Added decorators to TypeScript (PR#509).
- Fix highlighting of certain IRC logs formats (#1076).
Version 2.0.2
-------------
(released Jan 20, 2015)
- Fix Python tracebacks getting duplicated in the console lexer (#1068).
- Backquote-delimited identifiers are now recognized in F# (#1062).
Version 2.0.1
-------------
(released Nov 10, 2014)
- Fix an encoding issue when using ``pygmentize`` with the ``-o`` option.
Version 2.0
-----------
(released Nov 9, 2014)
- Default lexer encoding is now "guess", i.e. UTF-8 / Locale / Latin1 is
tried in that order.
- Major update to Swift lexer (PR#410).
- Multiple fixes to lexer guessing in conflicting cases:
* recognize HTML5 by doctype
* recognize XML by XML declaration
* don't recognize C/C++ as SystemVerilog
- Simplified regexes and builtin lists.
Version 2.0rc1
--------------
(released Oct 16, 2014)
- Dropped Python 2.4 and 2.5 compatibility. This is in favor of single-source
compatibility between Python 2.6, 2.7 and 3.3+.
- New website and documentation based on Sphinx (finally!)
- Lexers added:
* APL (#969)
* Agda and Literate Agda (PR#203)
* Alloy (PR#355)
* AmbientTalk
* BlitzBasic (PR#197)
* ChaiScript (PR#24)
* Chapel (PR#256)
* Cirru (PR#275)
* Clay (PR#184)
* ColdFusion CFC (PR#283)
* Cryptol and Literate Cryptol (PR#344)
* Cypher (PR#257)
* Docker config files
* EBNF (PR#193)
* Eiffel (PR#273)
* GAP (PR#311)
* Golo (PR#309)
* Handlebars (PR#186)
* Hy (PR#238)
* Idris and Literate Idris (PR#210)
* Igor Pro (PR#172)
* Inform 6/7 (PR#281)
* Intel objdump (PR#279)
* Isabelle (PR#386)
* Jasmin (PR#349)
* JSON-LD (PR#289)
* Kal (PR#233)
* Lean (PR#399)
* LSL (PR#296)
* Limbo (PR#291)
* Liquid (#977)
* MQL (PR#285)
* MaskJS (PR#280)
* Mozilla preprocessors
* Mathematica (PR#245)
* NesC (PR#166)
* Nit (PR#375)
* Nix (PR#267)
* Pan
* Pawn (PR#211)
* Perl 6 (PR#181)
* Pig (PR#304)
* Pike (PR#237)
* QBasic (PR#182)
* Red (PR#341)
* ResourceBundle (#1038)
* Rexx (PR#199)
* Rql (PR#251)
* Rsl
* SPARQL (PR#78)
* Slim (PR#366)
* Swift (PR#371)
* Swig (PR#168)
* TADS 3 (PR#407)
* Todo.txt todo lists
* Twig (PR#404)
- Added a helper to "optimize" regular expressions that match one of many
literal words; this can save 20% and more lexing time with lexers that
highlight many keywords or builtins.
- New styles: "xcode" and "igor", similar to the default highlighting of
the respective IDEs.
- The command-line "pygmentize" tool now tries a little harder to find the
correct encoding for files and the terminal (#979).
- Added "inencoding" option for lexers to override "encoding" analogous
to "outencoding" (#800).
- Added line-by-line "streaming" mode for pygmentize with the "-s" option.
(PR#165) Only fully works for lexers that have no constructs spanning
lines!
- Added an "envname" option to the LaTeX formatter to select a replacement
verbatim environment (PR#235).
- Updated the Makefile lexer to yield a little more useful highlighting.
- Lexer aliases passed to ``get_lexer_by_name()`` are now case-insensitive.
- File name matching in lexers and formatters will now use a regex cache
for speed (PR#205).
- Pygments will now recognize "vim" modelines when guessing the lexer for
a file based on content (PR#118).
- Major restructure of the ``pygments.lexers`` module namespace. There are now
many more modules with less lexers per module. Old modules are still around
and re-export the lexers they previously contained.
- The NameHighlightFilter now works with any Name.* token type (#790).
- Python 3 lexer: add new exceptions from PEP 3151.
- Opa lexer: add new keywords (PR#170).
- Julia lexer: add keywords and underscore-separated number
literals (PR#176).
- Lasso lexer: fix method highlighting, update builtins. Fix
guessing so that plain XML isn't always taken as Lasso (PR#163).
- Objective C/C++ lexers: allow "@" prefixing any expression (#871).
- Ruby lexer: fix lexing of Name::Space tokens (#860) and of symbols
in hashes (#873).
- Stan lexer: update for version 2.4.0 of the language (PR#162, PR#255, PR#377).
- JavaScript lexer: add the "yield" keyword (PR#196).
- HTTP lexer: support for PATCH method (PR#190).
- Koka lexer: update to newest language spec (PR#201).
- Haxe lexer: rewrite and support for Haxe 3 (PR#174).
- Prolog lexer: add different kinds of numeric literals (#864).
- F# lexer: rewrite with newest spec for F# 3.0 (#842), fix a bug with
dotted chains (#948).
- Kotlin lexer: general update (PR#271).
- Rebol lexer: fix comment detection and analyse_text (PR#261).
- LLVM lexer: update keywords to v3.4 (PR#258).
- PHP lexer: add new keywords and binary literals (PR#222).
- external/markdown-processor.py updated to newest python-markdown (PR#221).
- CSS lexer: some highlighting order fixes (PR#231).
- Ceylon lexer: fix parsing of nested multiline comments (#915).
- C family lexers: fix parsing of indented preprocessor directives (#944).
- Rust lexer: update to 0.9 language version (PR#270, PR#388).
- Elixir lexer: update to 0.15 language version (PR#392).
- Fix swallowing incomplete tracebacks in Python console lexer (#874).
Version 1.6 Version 1.6
----------- -----------
@ -259,7 +555,7 @@ Version 1.3
* Ada * Ada
* Coldfusion * Coldfusion
* Modula-2 * Modula-2
* haXe * Haxe
* R console * R console
* Objective-J * Objective-J
* Haml and Sass * Haml and Sass
@ -318,7 +614,7 @@ Version 1.2
* CMake * CMake
* Ooc * Ooc
* Coldfusion * Coldfusion
* haXe * Haxe
* R console * R console
- Added options for rendering LaTeX in source code comments in the - Added options for rendering LaTeX in source code comments in the

View File

@ -1,4 +1,4 @@
Copyright (c) 2006-2013 by the respective authors (see AUTHORS file). Copyright (c) 2006-2015 by the respective authors (see AUTHORS file).
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -2,5 +2,5 @@ include pygmentize
include external/* include external/*
include Makefile CHANGES LICENSE AUTHORS TODO ez_setup.py include Makefile CHANGES LICENSE AUTHORS TODO ez_setup.py
recursive-include tests * recursive-include tests *
recursive-include docs * recursive-include doc *
recursive-include scripts * recursive-include scripts *

View File

@ -4,7 +4,7 @@
# #
# Combines scripts for common tasks. # Combines scripts for common tasks.
# #
# :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. # :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
# :license: BSD, see LICENSE for details. # :license: BSD, see LICENSE for details.
# #
@ -19,9 +19,9 @@ all: clean-pyc check test
check: check:
@$(PYTHON) scripts/detect_missing_analyse_text.py || true @$(PYTHON) scripts/detect_missing_analyse_text.py || true
@pyflakes pygments | grep -v 'but unused' || true
@$(PYTHON) scripts/check_sources.py -i build -i dist -i pygments/lexers/_mapping.py \ @$(PYTHON) scripts/check_sources.py -i build -i dist -i pygments/lexers/_mapping.py \
-i docs/build -i pygments/formatters/_mapping.py -i pygments/unistring.py \ -i docs/build -i pygments/formatters/_mapping.py -i pygments/unistring.py
-i pygments/lexers/_vimbuiltins.py
clean: clean-pyc clean: clean-pyc
-rm -rf build -rm -rf build
@ -36,15 +36,12 @@ codetags:
@$(PYTHON) scripts/find_codetags.py -i tests/examplefiles -i scripts/pylintrc \ @$(PYTHON) scripts/find_codetags.py -i tests/examplefiles -i scripts/pylintrc \
-i scripts/find_codetags.py -o codetags.html . -i scripts/find_codetags.py -o codetags.html .
docs: docs/build docs:
make -C doc html
docs/build: docs/src/*.txt
$(PYTHON) docs/generate.py html docs/build $?
touch docs/build
mapfiles: mapfiles:
(cd pygments/lexers; $(PYTHON) _mapping.py)
(cd pygments/formatters; $(PYTHON) _mapping.py) (cd pygments/formatters; $(PYTHON) _mapping.py)
(cd pygments/lexers; $(PYTHON) _mapping.py)
pylint: pylint:
@pylint --rcfile scripts/pylintrc pygments @pylint --rcfile scripts/pylintrc pygments
@ -53,7 +50,13 @@ reindent:
@$(PYTHON) scripts/reindent.py -r -B . @$(PYTHON) scripts/reindent.py -r -B .
test: test:
@$(PYTHON) tests/run.py $(TESTS) @$(PYTHON) tests/run.py -d $(TEST)
test-coverage: test-coverage:
@$(PYTHON) tests/run.py -C $(TESTS) @$(PYTHON) tests/run.py -d --with-coverage --cover-package=pygments --cover-erase $(TEST)
tox-test:
@tox -- $(TEST)
tox-test-coverage:
@tox -- --with-coverage --cover-package=pygments --cover-erase $(TEST)

View File

@ -1,34 +1,27 @@
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: Pygments Name: Pygments
Version: 1.6 Version: 2.1.3
Summary: Pygments is a syntax highlighting package written in Python. Summary: Pygments is a syntax highlighting package written in Python.
Home-page: http://pygments.org/ Home-page: http://pygments.org/
Author: Georg Brandl Author: Georg Brandl
Author-email: georg@python.org Author-email: georg@python.org
License: BSD License License: BSD License
Description: Description: Pygments
Pygments
~~~~~~~~ ~~~~~~~~
Pygments is a syntax highlighting package written in Python. Pygments is a syntax highlighting package written in Python.
It is a generic syntax highlighter for general use in all kinds of software It is a generic syntax highlighter suitable for use in code hosting, forums,
such as forum systems, wikis or other applications that need to prettify wikis or other applications that need to prettify source code. Highlights
source code. Highlights are: are:
* a wide range of common languages and markup formats is supported * a wide range of over 300 languages and other text formats is supported
* special attention is paid to details, increasing quality by a fair amount * special attention is paid to details, increasing quality by a fair amount
* support for new languages and formats are added easily * support for new languages and formats are added easily
* a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences
* it is usable as a command-line tool and as a library * it is usable as a command-line tool and as a library
* ... and it highlights even Brainfuck!
The `Pygments tip`_ is installable with ``easy_install Pygments==dev``. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
.. _Pygments tip:
http://bitbucket.org/birkenfeld/pygments-main/get/default.zip#egg=Pygments-dev
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
Keywords: syntax highlighting Keywords: syntax highlighting

View File

@ -1,34 +1,27 @@
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: Pygments Name: Pygments
Version: 1.6 Version: 2.1.3
Summary: Pygments is a syntax highlighting package written in Python. Summary: Pygments is a syntax highlighting package written in Python.
Home-page: http://pygments.org/ Home-page: http://pygments.org/
Author: Georg Brandl Author: Georg Brandl
Author-email: georg@python.org Author-email: georg@python.org
License: BSD License License: BSD License
Description: Description: Pygments
Pygments
~~~~~~~~ ~~~~~~~~
Pygments is a syntax highlighting package written in Python. Pygments is a syntax highlighting package written in Python.
It is a generic syntax highlighter for general use in all kinds of software It is a generic syntax highlighter suitable for use in code hosting, forums,
such as forum systems, wikis or other applications that need to prettify wikis or other applications that need to prettify source code. Highlights
source code. Highlights are: are:
* a wide range of common languages and markup formats is supported * a wide range of over 300 languages and other text formats is supported
* special attention is paid to details, increasing quality by a fair amount * special attention is paid to details, increasing quality by a fair amount
* support for new languages and formats are added easily * support for new languages and formats are added easily
* a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences
* it is usable as a command-line tool and as a library * it is usable as a command-line tool and as a library
* ... and it highlights even Brainfuck!
The `Pygments tip`_ is installable with ``easy_install Pygments==dev``. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
.. _Pygments tip:
http://bitbucket.org/birkenfeld/pygments-main/get/default.zip#egg=Pygments-dev
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
Keywords: syntax highlighting Keywords: syntax highlighting

View File

@ -1,69 +1,70 @@
.hgignore
.hgtags
AUTHORS AUTHORS
CHANGES CHANGES
LICENSE LICENSE
MANIFEST.in MANIFEST.in
Makefile Makefile
README.rst
TODO TODO
ez_setup.py ez_setup.py
pygmentize pygmentize
requirements.txt
setup.cfg setup.cfg
setup.py setup.py
tox.ini
Pygments.egg-info/PKG-INFO Pygments.egg-info/PKG-INFO
Pygments.egg-info/SOURCES.txt Pygments.egg-info/SOURCES.txt
Pygments.egg-info/dependency_links.txt Pygments.egg-info/dependency_links.txt
Pygments.egg-info/entry_points.txt Pygments.egg-info/entry_points.txt
Pygments.egg-info/not-zip-safe Pygments.egg-info/not-zip-safe
Pygments.egg-info/top_level.txt Pygments.egg-info/top_level.txt
docs/generate.py doc/Makefile
docs/pygmentize.1 doc/conf.py
docs/build/api.html doc/download.rst
docs/build/authors.html doc/faq.rst
docs/build/changelog.html doc/index.rst
docs/build/cmdline.html doc/languages.rst
docs/build/filterdevelopment.html doc/make.bat
docs/build/filters.html doc/pygmentize.1
docs/build/formatterdevelopment.html doc/_static/favicon.ico
docs/build/formatters.html doc/_static/logo_new.png
docs/build/index.html doc/_static/logo_only.png
docs/build/installation.html doc/_templates/docssidebar.html
docs/build/integrate.html doc/_templates/indexsidebar.html
docs/build/java.html doc/_themes/pygments14/layout.html
docs/build/lexerdevelopment.html doc/_themes/pygments14/theme.conf
docs/build/lexers.html doc/_themes/pygments14/static/bodybg.png
docs/build/moinmoin.html doc/_themes/pygments14/static/docbg.png
docs/build/plugins.html doc/_themes/pygments14/static/listitem.png
docs/build/quickstart.html doc/_themes/pygments14/static/logo.png
docs/build/rstdirective.html doc/_themes/pygments14/static/pocoo.png
docs/build/styles.html doc/_themes/pygments14/static/pygments14.css_t
docs/build/tokens.html doc/docs/api.rst
docs/build/unicode.html doc/docs/authors.rst
docs/src/api.txt doc/docs/changelog.rst
docs/src/authors.txt doc/docs/cmdline.rst
docs/src/changelog.txt doc/docs/filterdevelopment.rst
docs/src/cmdline.txt doc/docs/filters.rst
docs/src/filterdevelopment.txt doc/docs/formatterdevelopment.rst
docs/src/filters.txt doc/docs/formatters.rst
docs/src/formatterdevelopment.txt doc/docs/index.rst
docs/src/formatters.txt doc/docs/integrate.rst
docs/src/index.txt doc/docs/java.rst
docs/src/installation.txt doc/docs/lexerdevelopment.rst
docs/src/integrate.txt doc/docs/lexers.rst
docs/src/java.txt doc/docs/moinmoin.rst
docs/src/lexerdevelopment.txt doc/docs/plugins.rst
docs/src/lexers.txt doc/docs/quickstart.rst
docs/src/moinmoin.txt doc/docs/rstdirective.rst
docs/src/plugins.txt doc/docs/styles.rst
docs/src/quickstart.txt doc/docs/tokens.rst
docs/src/rstdirective.txt doc/docs/unicode.rst
docs/src/styles.txt
docs/src/tokens.txt
docs/src/unicode.txt
external/autopygmentize external/autopygmentize
external/lasso-builtins-generator-9.lasso external/lasso-builtins-generator-9.lasso
external/markdown-processor.py external/markdown-processor.py
external/moin-parser.py external/moin-parser.py
external/pygments.bashcomp external/pygments.bashcomp
external/rst-directive-old.py
external/rst-directive.py external/rst-directive.py
pygments/__init__.py pygments/__init__.py
pygments/cmdline.py pygments/cmdline.py
@ -71,8 +72,11 @@ pygments/console.py
pygments/filter.py pygments/filter.py
pygments/formatter.py pygments/formatter.py
pygments/lexer.py pygments/lexer.py
pygments/modeline.py
pygments/plugin.py pygments/plugin.py
pygments/regexopt.py
pygments/scanner.py pygments/scanner.py
pygments/sphinxext.py
pygments/style.py pygments/style.py
pygments/token.py pygments/token.py
pygments/unistring.py pygments/unistring.py
@ -83,6 +87,7 @@ pygments/formatters/_mapping.py
pygments/formatters/bbcode.py pygments/formatters/bbcode.py
pygments/formatters/html.py pygments/formatters/html.py
pygments/formatters/img.py pygments/formatters/img.py
pygments/formatters/irc.py
pygments/formatters/latex.py pygments/formatters/latex.py
pygments/formatters/other.py pygments/formatters/other.py
pygments/formatters/rtf.py pygments/formatters/rtf.py
@ -90,38 +95,133 @@ pygments/formatters/svg.py
pygments/formatters/terminal.py pygments/formatters/terminal.py
pygments/formatters/terminal256.py pygments/formatters/terminal256.py
pygments/lexers/__init__.py pygments/lexers/__init__.py
pygments/lexers/_asybuiltins.py pygments/lexers/_asy_builtins.py
pygments/lexers/_clbuiltins.py pygments/lexers/_cl_builtins.py
pygments/lexers/_lassobuiltins.py pygments/lexers/_cocoa_builtins.py
pygments/lexers/_luabuiltins.py pygments/lexers/_csound_builtins.py
pygments/lexers/_lasso_builtins.py
pygments/lexers/_lua_builtins.py
pygments/lexers/_mapping.py pygments/lexers/_mapping.py
pygments/lexers/_openedgebuiltins.py pygments/lexers/_mql_builtins.py
pygments/lexers/_phpbuiltins.py pygments/lexers/_openedge_builtins.py
pygments/lexers/_php_builtins.py
pygments/lexers/_postgres_builtins.py pygments/lexers/_postgres_builtins.py
pygments/lexers/_robotframeworklexer.py
pygments/lexers/_scilab_builtins.py pygments/lexers/_scilab_builtins.py
pygments/lexers/_sourcemodbuiltins.py pygments/lexers/_sourcemod_builtins.py
pygments/lexers/_stan_builtins.py pygments/lexers/_stan_builtins.py
pygments/lexers/_vimbuiltins.py pygments/lexers/_vim_builtins.py
pygments/lexers/actionscript.py
pygments/lexers/agile.py pygments/lexers/agile.py
pygments/lexers/algebra.py
pygments/lexers/ambient.py
pygments/lexers/apl.py
pygments/lexers/archetype.py
pygments/lexers/asm.py pygments/lexers/asm.py
pygments/lexers/automation.py
pygments/lexers/basic.py
pygments/lexers/business.py
pygments/lexers/c_cpp.py
pygments/lexers/c_like.py
pygments/lexers/chapel.py
pygments/lexers/compiled.py pygments/lexers/compiled.py
pygments/lexers/configs.py
pygments/lexers/console.py
pygments/lexers/csound.py
pygments/lexers/css.py
pygments/lexers/d.py
pygments/lexers/dalvik.py pygments/lexers/dalvik.py
pygments/lexers/data.py
pygments/lexers/diff.py
pygments/lexers/dotnet.py pygments/lexers/dotnet.py
pygments/lexers/dsls.py
pygments/lexers/dylan.py
pygments/lexers/ecl.py
pygments/lexers/eiffel.py
pygments/lexers/elm.py
pygments/lexers/erlang.py
pygments/lexers/esoteric.py
pygments/lexers/ezhil.py
pygments/lexers/factor.py
pygments/lexers/fantom.py
pygments/lexers/felix.py
pygments/lexers/fortran.py
pygments/lexers/foxpro.py pygments/lexers/foxpro.py
pygments/lexers/functional.py pygments/lexers/functional.py
pygments/lexers/go.py
pygments/lexers/grammar_notation.py
pygments/lexers/graph.py
pygments/lexers/graphics.py
pygments/lexers/haskell.py
pygments/lexers/haxe.py
pygments/lexers/hdl.py pygments/lexers/hdl.py
pygments/lexers/hexdump.py
pygments/lexers/html.py
pygments/lexers/idl.py
pygments/lexers/igor.py
pygments/lexers/inferno.py
pygments/lexers/installers.py
pygments/lexers/int_fiction.py
pygments/lexers/iolang.py
pygments/lexers/j.py
pygments/lexers/javascript.py
pygments/lexers/julia.py
pygments/lexers/jvm.py pygments/lexers/jvm.py
pygments/lexers/lisp.py
pygments/lexers/make.py
pygments/lexers/markup.py
pygments/lexers/math.py pygments/lexers/math.py
pygments/lexers/matlab.py
pygments/lexers/ml.py
pygments/lexers/modeling.py
pygments/lexers/modula2.py
pygments/lexers/nimrod.py
pygments/lexers/nit.py
pygments/lexers/nix.py
pygments/lexers/oberon.py
pygments/lexers/objective.py
pygments/lexers/ooc.py
pygments/lexers/other.py pygments/lexers/other.py
pygments/lexers/parasail.py
pygments/lexers/parsers.py pygments/lexers/parsers.py
pygments/lexers/pascal.py
pygments/lexers/pawn.py
pygments/lexers/perl.py
pygments/lexers/php.py
pygments/lexers/praat.py
pygments/lexers/prolog.py
pygments/lexers/python.py
pygments/lexers/qvt.py
pygments/lexers/r.py
pygments/lexers/rdf.py
pygments/lexers/rebol.py
pygments/lexers/resource.py
pygments/lexers/roboconf.py
pygments/lexers/robotframework.py
pygments/lexers/ruby.py
pygments/lexers/rust.py
pygments/lexers/scripting.py
pygments/lexers/shell.py pygments/lexers/shell.py
pygments/lexers/smalltalk.py
pygments/lexers/snobol.py
pygments/lexers/special.py pygments/lexers/special.py
pygments/lexers/sql.py pygments/lexers/sql.py
pygments/lexers/supercollider.py
pygments/lexers/tcl.py
pygments/lexers/templates.py pygments/lexers/templates.py
pygments/lexers/testing.py
pygments/lexers/text.py pygments/lexers/text.py
pygments/lexers/textedit.py
pygments/lexers/textfmts.py
pygments/lexers/theorem.py
pygments/lexers/trafficscript.py
pygments/lexers/urbi.py
pygments/lexers/web.py pygments/lexers/web.py
pygments/lexers/webmisc.py
pygments/lexers/x10.py
pygments/styles/__init__.py pygments/styles/__init__.py
pygments/styles/algol.py
pygments/styles/algol_nu.py
pygments/styles/arduino.py
pygments/styles/autumn.py pygments/styles/autumn.py
pygments/styles/borland.py pygments/styles/borland.py
pygments/styles/bw.py pygments/styles/bw.py
@ -130,10 +230,14 @@ pygments/styles/default.py
pygments/styles/emacs.py pygments/styles/emacs.py
pygments/styles/friendly.py pygments/styles/friendly.py
pygments/styles/fruity.py pygments/styles/fruity.py
pygments/styles/igor.py
pygments/styles/lovelace.py
pygments/styles/manni.py pygments/styles/manni.py
pygments/styles/monokai.py pygments/styles/monokai.py
pygments/styles/murphy.py pygments/styles/murphy.py
pygments/styles/native.py pygments/styles/native.py
pygments/styles/paraiso_dark.py
pygments/styles/paraiso_light.py
pygments/styles/pastie.py pygments/styles/pastie.py
pygments/styles/perldoc.py pygments/styles/perldoc.py
pygments/styles/rrt.py pygments/styles/rrt.py
@ -141,29 +245,143 @@ pygments/styles/tango.py
pygments/styles/trac.py pygments/styles/trac.py
pygments/styles/vim.py pygments/styles/vim.py
pygments/styles/vs.py pygments/styles/vs.py
pygments/styles/xcode.py
scripts/check_sources.py scripts/check_sources.py
scripts/debug_lexer.py
scripts/detect_missing_analyse_text.py scripts/detect_missing_analyse_text.py
scripts/epydoc.css scripts/epydoc.css
scripts/find_codetags.py
scripts/find_error.py scripts/find_error.py
scripts/get_vimkw.py scripts/get_vimkw.py
scripts/pylintrc scripts/pylintrc
scripts/reindent.py
scripts/vim2pygments.py scripts/vim2pygments.py
tests/old_run.py tests/.coverage
tests/run.py tests/run.py
tests/string_asserts.py
tests/string_asserts.pyc
tests/support.py tests/support.py
tests/support.pyc
tests/test_basic_api.py tests/test_basic_api.py
tests/test_basic_api.pyc
tests/test_cfm.py
tests/test_cfm.pyc
tests/test_clexer.py tests/test_clexer.py
tests/test_clexer.pyc
tests/test_cmdline.py tests/test_cmdline.py
tests/test_cmdline.pyc
tests/test_examplefiles.py tests/test_examplefiles.py
tests/test_examplefiles.pyc
tests/test_ezhil.py
tests/test_ezhil.pyc
tests/test_html_formatter.py tests/test_html_formatter.py
tests/test_html_formatter.pyc
tests/test_inherit.py
tests/test_inherit.pyc
tests/test_irc_formatter.py
tests/test_irc_formatter.pyc
tests/test_java.py
tests/test_java.pyc
tests/test_latex_formatter.py tests/test_latex_formatter.py
tests/test_latex_formatter.pyc
tests/test_lexers_other.py
tests/test_lexers_other.pyc
tests/test_objectiveclexer.py
tests/test_objectiveclexer.pyc
tests/test_perllexer.py tests/test_perllexer.py
tests/test_perllexer.pyc
tests/test_qbasiclexer.py
tests/test_qbasiclexer.pyc
tests/test_regexlexer.py tests/test_regexlexer.py
tests/test_regexlexer.pyc
tests/test_regexopt.py
tests/test_regexopt.pyc
tests/test_rtf_formatter.py
tests/test_rtf_formatter.pyc
tests/test_ruby.py
tests/test_ruby.pyc
tests/test_shell.py
tests/test_shell.pyc
tests/test_smarty.py
tests/test_smarty.pyc
tests/test_string_asserts.py
tests/test_string_asserts.pyc
tests/test_terminal_formatter.py
tests/test_terminal_formatter.pyc
tests/test_textfmts.py
tests/test_textfmts.pyc
tests/test_token.py tests/test_token.py
tests/test_token.pyc
tests/test_unistring.py
tests/test_unistring.pyc
tests/test_using_api.py tests/test_using_api.py
tests/test_using_api.pyc
tests/test_util.py tests/test_util.py
tests/test_util.pyc
tests/__pycache__/string_asserts.cpython-33.pyc
tests/__pycache__/string_asserts.cpython-35.pyc
tests/__pycache__/support.cpython-33.pyc
tests/__pycache__/support.cpython-35.pyc
tests/__pycache__/test_basic_api.cpython-33.pyc
tests/__pycache__/test_basic_api.cpython-35.pyc
tests/__pycache__/test_cfm.cpython-33.pyc
tests/__pycache__/test_cfm.cpython-35.pyc
tests/__pycache__/test_clexer.cpython-33.pyc
tests/__pycache__/test_clexer.cpython-35.pyc
tests/__pycache__/test_cmdline.cpython-33.pyc
tests/__pycache__/test_cmdline.cpython-35.pyc
tests/__pycache__/test_examplefiles.cpython-33.pyc
tests/__pycache__/test_examplefiles.cpython-35.pyc
tests/__pycache__/test_ezhil.cpython-35.pyc
tests/__pycache__/test_html_formatter.cpython-33.pyc
tests/__pycache__/test_html_formatter.cpython-35.pyc
tests/__pycache__/test_inherit.cpython-33.pyc
tests/__pycache__/test_inherit.cpython-35.pyc
tests/__pycache__/test_irc_formatter.cpython-35.pyc
tests/__pycache__/test_java.cpython-33.pyc
tests/__pycache__/test_java.cpython-35.pyc
tests/__pycache__/test_latex_formatter.cpython-33.pyc
tests/__pycache__/test_latex_formatter.cpython-35.pyc
tests/__pycache__/test_lexers_other.cpython-33.pyc
tests/__pycache__/test_lexers_other.cpython-35.pyc
tests/__pycache__/test_objectiveclexer.cpython-33.pyc
tests/__pycache__/test_objectiveclexer.cpython-35.pyc
tests/__pycache__/test_perllexer.cpython-33.pyc
tests/__pycache__/test_perllexer.cpython-35.pyc
tests/__pycache__/test_qbasiclexer.cpython-33.pyc
tests/__pycache__/test_qbasiclexer.cpython-35.pyc
tests/__pycache__/test_regexlexer.cpython-33.pyc
tests/__pycache__/test_regexlexer.cpython-35.pyc
tests/__pycache__/test_regexopt.cpython-33.pyc
tests/__pycache__/test_regexopt.cpython-35.pyc
tests/__pycache__/test_rtf_formatter.cpython-33.pyc
tests/__pycache__/test_rtf_formatter.cpython-35.pyc
tests/__pycache__/test_ruby.cpython-33.pyc
tests/__pycache__/test_ruby.cpython-35.pyc
tests/__pycache__/test_shell.cpython-33.pyc
tests/__pycache__/test_shell.cpython-35.pyc
tests/__pycache__/test_smarty.cpython-33.pyc
tests/__pycache__/test_smarty.cpython-35.pyc
tests/__pycache__/test_string_asserts.cpython-33.pyc
tests/__pycache__/test_string_asserts.cpython-35.pyc
tests/__pycache__/test_terminal_formatter.cpython-35.pyc
tests/__pycache__/test_textfmts.cpython-33.pyc
tests/__pycache__/test_textfmts.cpython-35.pyc
tests/__pycache__/test_token.cpython-33.pyc
tests/__pycache__/test_token.cpython-35.pyc
tests/__pycache__/test_unistring.cpython-33.pyc
tests/__pycache__/test_unistring.cpython-35.pyc
tests/__pycache__/test_using_api.cpython-33.pyc
tests/__pycache__/test_using_api.cpython-35.pyc
tests/__pycache__/test_util.cpython-33.pyc
tests/__pycache__/test_util.cpython-35.pyc
tests/cover/coverage_html.js
tests/cover/jquery.hotkeys.js
tests/cover/jquery.isonscreen.js
tests/cover/jquery.min.js
tests/cover/jquery.tablesorter.min.js
tests/cover/keybd_closed.png
tests/cover/keybd_open.png
tests/cover/status.dat
tests/cover/style.css
tests/dtds/HTML4-f.dtd tests/dtds/HTML4-f.dtd
tests/dtds/HTML4-s.dtd tests/dtds/HTML4-s.dtd
tests/dtds/HTML4.dcl tests/dtds/HTML4.dcl
@ -172,24 +390,36 @@ tests/dtds/HTML4.soc
tests/dtds/HTMLlat1.ent tests/dtds/HTMLlat1.ent
tests/dtds/HTMLspec.ent tests/dtds/HTMLspec.ent
tests/dtds/HTMLsym.ent tests/dtds/HTMLsym.ent
tests/examplefiles/ANTLRv3.g tests/examplefiles/99_bottles_of_beer.chpl
tests/examplefiles/AcidStateAdvanced.hs tests/examplefiles/AcidStateAdvanced.hs
tests/examplefiles/AlternatingGroup.mu tests/examplefiles/AlternatingGroup.mu
tests/examplefiles/BOM.js tests/examplefiles/BOM.js
tests/examplefiles/Blink.ino
tests/examplefiles/CPDictionary.j tests/examplefiles/CPDictionary.j
tests/examplefiles/Config.in.cache tests/examplefiles/Config.in.cache
tests/examplefiles/Constants.mo tests/examplefiles/Constants.mo
tests/examplefiles/DancingSudoku.lhs tests/examplefiles/DancingSudoku.lhs
tests/examplefiles/Deflate.fs
tests/examplefiles/Error.pmod
tests/examplefiles/Errors.scala tests/examplefiles/Errors.scala
tests/examplefiles/File.hy tests/examplefiles/FakeFile.pike
tests/examplefiles/Get-CommandDefinitionHtml.ps1
tests/examplefiles/IPDispatchC.nc
tests/examplefiles/IPDispatchP.nc
tests/examplefiles/Intro.java tests/examplefiles/Intro.java
tests/examplefiles/Makefile tests/examplefiles/Makefile
tests/examplefiles/Object.st tests/examplefiles/Object.st
tests/examplefiles/OrderedMap.hx tests/examplefiles/OrderedMap.hx
tests/examplefiles/RoleQ.pm6
tests/examplefiles/SmallCheck.hs tests/examplefiles/SmallCheck.hs
tests/examplefiles/Sorting.mod tests/examplefiles/Sorting.mod
tests/examplefiles/Sudoku.lhs tests/examplefiles/Sudoku.lhs
tests/examplefiles/abnf_example1.abnf
tests/examplefiles/abnf_example2.abnf
tests/examplefiles/addressbook.proto tests/examplefiles/addressbook.proto
tests/examplefiles/ahcon.f
tests/examplefiles/all.nit
tests/examplefiles/antlr_ANTLRv3.g
tests/examplefiles/antlr_throws tests/examplefiles/antlr_throws
tests/examplefiles/apache2.conf tests/examplefiles/apache2.conf
tests/examplefiles/as3_test.as tests/examplefiles/as3_test.as
@ -197,69 +427,137 @@ tests/examplefiles/as3_test2.as
tests/examplefiles/as3_test3.as tests/examplefiles/as3_test3.as
tests/examplefiles/aspx-cs_example tests/examplefiles/aspx-cs_example
tests/examplefiles/autoit_submit.au3 tests/examplefiles/autoit_submit.au3
tests/examplefiles/automake.mk
tests/examplefiles/badcase.java tests/examplefiles/badcase.java
tests/examplefiles/batchfile.bat
tests/examplefiles/bigtest.nsi tests/examplefiles/bigtest.nsi
tests/examplefiles/bnf_example1.bnf
tests/examplefiles/boot-9.scm tests/examplefiles/boot-9.scm
tests/examplefiles/ca65_example tests/examplefiles/ca65_example
tests/examplefiles/cbmbas_example tests/examplefiles/cbmbas_example
tests/examplefiles/cells.ps tests/examplefiles/cells.ps
tests/examplefiles/ceval.c tests/examplefiles/ceval.c
tests/examplefiles/char.scala
tests/examplefiles/cheetah_example.html tests/examplefiles/cheetah_example.html
tests/examplefiles/classes.dylan tests/examplefiles/classes.dylan
tests/examplefiles/clojure-weird-keywords.clj
tests/examplefiles/condensed_ruby.rb tests/examplefiles/condensed_ruby.rb
tests/examplefiles/coq_RelationClasses tests/examplefiles/coq_RelationClasses
tests/examplefiles/core.cljs
tests/examplefiles/database.pytb tests/examplefiles/database.pytb
tests/examplefiles/de.MoinMoin.po tests/examplefiles/de.MoinMoin.po
tests/examplefiles/demo.ahk tests/examplefiles/demo.ahk
tests/examplefiles/demo.cfm tests/examplefiles/demo.cfm
tests/examplefiles/demo.css.in
tests/examplefiles/demo.hbs
tests/examplefiles/demo.js.in
tests/examplefiles/demo.thrift
tests/examplefiles/demo.xul.in
tests/examplefiles/django_sample.html+django tests/examplefiles/django_sample.html+django
tests/examplefiles/docker.docker
tests/examplefiles/dwarf.cw tests/examplefiles/dwarf.cw
tests/examplefiles/eg_example1.eg
tests/examplefiles/ember.handlebars
tests/examplefiles/erl_session tests/examplefiles/erl_session
tests/examplefiles/es6.js
tests/examplefiles/escape_semicolon.clj tests/examplefiles/escape_semicolon.clj
tests/examplefiles/eval.rs
tests/examplefiles/evil_regex.js tests/examplefiles/evil_regex.js
tests/examplefiles/example.Rd tests/examplefiles/example.Rd
tests/examplefiles/example.als
tests/examplefiles/example.bat
tests/examplefiles/example.bc
tests/examplefiles/example.bug tests/examplefiles/example.bug
tests/examplefiles/example.c tests/examplefiles/example.c
tests/examplefiles/example.ceylon tests/examplefiles/example.ceylon
tests/examplefiles/example.chai
tests/examplefiles/example.clay
tests/examplefiles/example.cls tests/examplefiles/example.cls
tests/examplefiles/example.cob tests/examplefiles/example.cob
tests/examplefiles/example.coffee
tests/examplefiles/example.cpp tests/examplefiles/example.cpp
tests/examplefiles/example.e
tests/examplefiles/example.elm
tests/examplefiles/example.ezt
tests/examplefiles/example.f90
tests/examplefiles/example.feature
tests/examplefiles/example.fish
tests/examplefiles/example.gd
tests/examplefiles/example.gi
tests/examplefiles/example.golo
tests/examplefiles/example.groovy
tests/examplefiles/example.gs tests/examplefiles/example.gs
tests/examplefiles/example.gst tests/examplefiles/example.gst
tests/examplefiles/example.hs
tests/examplefiles/example.hx
tests/examplefiles/example.i6t
tests/examplefiles/example.i7x
tests/examplefiles/example.j
tests/examplefiles/example.jag tests/examplefiles/example.jag
tests/examplefiles/example.java
tests/examplefiles/example.jcl
tests/examplefiles/example.jsonld
tests/examplefiles/example.kal
tests/examplefiles/example.kt tests/examplefiles/example.kt
tests/examplefiles/example.lagda
tests/examplefiles/example.liquid
tests/examplefiles/example.lua tests/examplefiles/example.lua
tests/examplefiles/example.ma
tests/examplefiles/example.mac
tests/examplefiles/example.monkey tests/examplefiles/example.monkey
tests/examplefiles/example.moo tests/examplefiles/example.moo
tests/examplefiles/example.moon tests/examplefiles/example.moon
tests/examplefiles/example.mq4
tests/examplefiles/example.mqh
tests/examplefiles/example.msc tests/examplefiles/example.msc
tests/examplefiles/example.ni
tests/examplefiles/example.nim tests/examplefiles/example.nim
tests/examplefiles/example.nix
tests/examplefiles/example.ns2 tests/examplefiles/example.ns2
tests/examplefiles/example.p
tests/examplefiles/example.pas tests/examplefiles/example.pas
tests/examplefiles/example.pcmk
tests/examplefiles/example.pp
tests/examplefiles/example.praat
tests/examplefiles/example.prg tests/examplefiles/example.prg
tests/examplefiles/example.rb tests/examplefiles/example.rb
tests/examplefiles/example.red
tests/examplefiles/example.reds
tests/examplefiles/example.reg tests/examplefiles/example.reg
tests/examplefiles/example.rexx
tests/examplefiles/example.rhtml tests/examplefiles/example.rhtml
tests/examplefiles/example.rkt tests/examplefiles/example.rkt
tests/examplefiles/example.rpf tests/examplefiles/example.rpf
tests/examplefiles/example.rts
tests/examplefiles/example.scd
tests/examplefiles/example.sh
tests/examplefiles/example.sh-session tests/examplefiles/example.sh-session
tests/examplefiles/example.shell-session tests/examplefiles/example.shell-session
tests/examplefiles/example.slim
tests/examplefiles/example.sls
tests/examplefiles/example.sml tests/examplefiles/example.sml
tests/examplefiles/example.snobol tests/examplefiles/example.snobol
tests/examplefiles/example.stan tests/examplefiles/example.stan
tests/examplefiles/example.tap
tests/examplefiles/example.tea tests/examplefiles/example.tea
tests/examplefiles/example.tf
tests/examplefiles/example.thy
tests/examplefiles/example.todotxt
tests/examplefiles/example.ts tests/examplefiles/example.ts
tests/examplefiles/example.ttl
tests/examplefiles/example.u tests/examplefiles/example.u
tests/examplefiles/example.weechatlog tests/examplefiles/example.weechatlog
tests/examplefiles/example.x10
tests/examplefiles/example.xhtml tests/examplefiles/example.xhtml
tests/examplefiles/example.xtend tests/examplefiles/example.xtend
tests/examplefiles/example.yaml tests/examplefiles/example.yaml
tests/examplefiles/example1.cadl
tests/examplefiles/example2.aspx tests/examplefiles/example2.aspx
tests/examplefiles/example2.msc tests/examplefiles/example2.msc
tests/examplefiles/exampleScript.cfc
tests/examplefiles/exampleTag.cfc
tests/examplefiles/example_coq.v
tests/examplefiles/example_elixir.ex tests/examplefiles/example_elixir.ex
tests/examplefiles/example_file.fy tests/examplefiles/example_file.fy
tests/examplefiles/ezhil_primefactors.n
tests/examplefiles/firefox.mak tests/examplefiles/firefox.mak
tests/examplefiles/flipflop.sv tests/examplefiles/flipflop.sv
tests/examplefiles/foo.sce tests/examplefiles/foo.sce
@ -273,13 +571,28 @@ tests/examplefiles/genshi_example.xml+genshi
tests/examplefiles/genshitext_example.genshitext tests/examplefiles/genshitext_example.genshitext
tests/examplefiles/glsl.frag tests/examplefiles/glsl.frag
tests/examplefiles/glsl.vert tests/examplefiles/glsl.vert
tests/examplefiles/grammar-test.p6
tests/examplefiles/hash_syntax.rb
tests/examplefiles/hello.at
tests/examplefiles/hello.golo
tests/examplefiles/hello.lsl
tests/examplefiles/hello.smali tests/examplefiles/hello.smali
tests/examplefiles/hello.sp tests/examplefiles/hello.sp
tests/examplefiles/hexdump_debugexe
tests/examplefiles/hexdump_hd
tests/examplefiles/hexdump_hexcat
tests/examplefiles/hexdump_hexdump
tests/examplefiles/hexdump_od
tests/examplefiles/hexdump_xxd
tests/examplefiles/html+php_faulty.php tests/examplefiles/html+php_faulty.php
tests/examplefiles/http_request_example tests/examplefiles/http_request_example
tests/examplefiles/http_response_example tests/examplefiles/http_response_example
tests/examplefiles/import.hs tests/examplefiles/hybris_File.hy
tests/examplefiles/idl_sample.pro
tests/examplefiles/iex_example
tests/examplefiles/inet_pton6.dg tests/examplefiles/inet_pton6.dg
tests/examplefiles/inform6_example
tests/examplefiles/interp.scala
tests/examplefiles/intro.ik tests/examplefiles/intro.ik
tests/examplefiles/ints.php tests/examplefiles/ints.php
tests/examplefiles/intsyn.fun tests/examplefiles/intsyn.fun
@ -292,7 +605,9 @@ tests/examplefiles/jbst_example2.jbst
tests/examplefiles/jinjadesignerdoc.rst tests/examplefiles/jinjadesignerdoc.rst
tests/examplefiles/json.lasso tests/examplefiles/json.lasso
tests/examplefiles/json.lasso9 tests/examplefiles/json.lasso9
tests/examplefiles/language.hy
tests/examplefiles/lighttpd_config.conf tests/examplefiles/lighttpd_config.conf
tests/examplefiles/limbo.b
tests/examplefiles/linecontinuation.py tests/examplefiles/linecontinuation.py
tests/examplefiles/livescript-demo.ls tests/examplefiles/livescript-demo.ls
tests/examplefiles/logos_example.xm tests/examplefiles/logos_example.xm
@ -303,9 +618,9 @@ tests/examplefiles/matlab_noreturn
tests/examplefiles/matlab_sample tests/examplefiles/matlab_sample
tests/examplefiles/matlabsession_sample.txt tests/examplefiles/matlabsession_sample.txt
tests/examplefiles/metagrammar.treetop tests/examplefiles/metagrammar.treetop
tests/examplefiles/mg_sample.pro
tests/examplefiles/minehunt.qml tests/examplefiles/minehunt.qml
tests/examplefiles/minimal.ns2 tests/examplefiles/minimal.ns2
tests/examplefiles/modula2_test_cases.def
tests/examplefiles/moin_SyntaxReference.txt tests/examplefiles/moin_SyntaxReference.txt
tests/examplefiles/multiline_regexes.rb tests/examplefiles/multiline_regexes.rb
tests/examplefiles/nanomsg.intr tests/examplefiles/nanomsg.intr
@ -313,104 +628,161 @@ tests/examplefiles/nasm_aoutso.asm
tests/examplefiles/nasm_objexe.asm tests/examplefiles/nasm_objexe.asm
tests/examplefiles/nemerle_sample.n tests/examplefiles/nemerle_sample.n
tests/examplefiles/nginx_nginx.conf tests/examplefiles/nginx_nginx.conf
tests/examplefiles/noexcept.cpp
tests/examplefiles/numbers.c tests/examplefiles/numbers.c
tests/examplefiles/objc_example.m tests/examplefiles/objc_example.m
tests/examplefiles/objc_example2.m tests/examplefiles/openedge_example
tests/examplefiles/pacman.conf
tests/examplefiles/pacman.ijs
tests/examplefiles/pawn_example
tests/examplefiles/perl_misc tests/examplefiles/perl_misc
tests/examplefiles/perl_perl5db tests/examplefiles/perl_perl5db
tests/examplefiles/perl_regex-delims tests/examplefiles/perl_regex-delims
tests/examplefiles/perlfunc.1 tests/examplefiles/perlfunc.1
tests/examplefiles/phpMyAdmin.spec tests/examplefiles/phpMyAdmin.spec
tests/examplefiles/phpcomplete.vim tests/examplefiles/phpcomplete.vim
tests/examplefiles/pkgconfig_example.pc
tests/examplefiles/pleac.in.rb tests/examplefiles/pleac.in.rb
tests/examplefiles/postgresql_test.txt tests/examplefiles/postgresql_test.txt
tests/examplefiles/pppoe.applescript tests/examplefiles/pppoe.applescript
tests/examplefiles/psql_session.txt tests/examplefiles/psql_session.txt
tests/examplefiles/py3_test.txt tests/examplefiles/py3_test.txt
tests/examplefiles/py3tb_test.py3tb
tests/examplefiles/pycon_ctrlc_traceback
tests/examplefiles/pycon_test.pycon tests/examplefiles/pycon_test.pycon
tests/examplefiles/pytb_test2.pytb tests/examplefiles/pytb_test2.pytb
tests/examplefiles/pytb_test3.pytb tests/examplefiles/pytb_test3.pytb
tests/examplefiles/python25-bsd.mak tests/examplefiles/python25-bsd.mak
tests/examplefiles/qbasic_example
tests/examplefiles/qsort.prolog tests/examplefiles/qsort.prolog
tests/examplefiles/r-console-transcript.Rout tests/examplefiles/r-console-transcript.Rout
tests/examplefiles/r6rs-comments.scm
tests/examplefiles/ragel-cpp_rlscan tests/examplefiles/ragel-cpp_rlscan
tests/examplefiles/ragel-cpp_snippet tests/examplefiles/ragel-cpp_snippet
tests/examplefiles/regex.js tests/examplefiles/regex.js
tests/examplefiles/resourcebundle_demo
tests/examplefiles/reversi.lsp tests/examplefiles/reversi.lsp
tests/examplefiles/robotframework.txt tests/examplefiles/roboconf.graph
tests/examplefiles/roboconf.instances
tests/examplefiles/robotframework_test.txt
tests/examplefiles/rql-queries.rql
tests/examplefiles/ruby_func_def.rb tests/examplefiles/ruby_func_def.rb
tests/examplefiles/rust_example.rs tests/examplefiles/sample.qvto
tests/examplefiles/scilab.sci tests/examplefiles/scilab.sci
tests/examplefiles/scope.cirru
tests/examplefiles/session.dylan-console tests/examplefiles/session.dylan-console
tests/examplefiles/sibling.prolog tests/examplefiles/sibling.prolog
tests/examplefiles/simple.md tests/examplefiles/simple.camkes
tests/examplefiles/simple.croc
tests/examplefiles/smarty_example.html tests/examplefiles/smarty_example.html
tests/examplefiles/source.lgt tests/examplefiles/source.lgt
tests/examplefiles/sources.list tests/examplefiles/sources.list
tests/examplefiles/sparql.rq
tests/examplefiles/sphere.pov tests/examplefiles/sphere.pov
tests/examplefiles/sqlite3.sqlite3-console tests/examplefiles/sqlite3.sqlite3-console
tests/examplefiles/squid.conf tests/examplefiles/squid.conf
tests/examplefiles/string.jl tests/examplefiles/string.jl
tests/examplefiles/string_delimiters.d tests/examplefiles/string_delimiters.d
tests/examplefiles/stripheredoc.sh tests/examplefiles/stripheredoc.sh
tests/examplefiles/subr.el
tests/examplefiles/swig_java.swg
tests/examplefiles/swig_std_vector.i
tests/examplefiles/tads3_example.t
tests/examplefiles/termcap
tests/examplefiles/terminfo
tests/examplefiles/test-3.0.xq
tests/examplefiles/test-exist-update.xq
tests/examplefiles/test.R tests/examplefiles/test.R
tests/examplefiles/test.adb tests/examplefiles/test.adb
tests/examplefiles/test.adls
tests/examplefiles/test.agda
tests/examplefiles/test.apl
tests/examplefiles/test.asy tests/examplefiles/test.asy
tests/examplefiles/test.awk tests/examplefiles/test.awk
tests/examplefiles/test.bas tests/examplefiles/test.bb
tests/examplefiles/test.bmx tests/examplefiles/test.bmx
tests/examplefiles/test.boo tests/examplefiles/test.boo
tests/examplefiles/test.bpl
tests/examplefiles/test.bro tests/examplefiles/test.bro
tests/examplefiles/test.cadl
tests/examplefiles/test.cs tests/examplefiles/test.cs
tests/examplefiles/test.csd
tests/examplefiles/test.css tests/examplefiles/test.css
tests/examplefiles/test.cu tests/examplefiles/test.cu
tests/examplefiles/test.cyp
tests/examplefiles/test.d tests/examplefiles/test.d
tests/examplefiles/test.dart tests/examplefiles/test.dart
tests/examplefiles/test.dtd tests/examplefiles/test.dtd
tests/examplefiles/test.ebnf
tests/examplefiles/test.ec tests/examplefiles/test.ec
tests/examplefiles/test.ecl
tests/examplefiles/test.eh tests/examplefiles/test.eh
tests/examplefiles/test.erl tests/examplefiles/test.erl
tests/examplefiles/test.evoque tests/examplefiles/test.evoque
tests/examplefiles/test.fan tests/examplefiles/test.fan
tests/examplefiles/test.flx tests/examplefiles/test.flx
tests/examplefiles/test.gdc tests/examplefiles/test.gdc
tests/examplefiles/test.gradle
tests/examplefiles/test.groovy tests/examplefiles/test.groovy
tests/examplefiles/test.html tests/examplefiles/test.html
tests/examplefiles/test.idr
tests/examplefiles/test.ini tests/examplefiles/test.ini
tests/examplefiles/test.java tests/examplefiles/test.java
tests/examplefiles/test.jsp tests/examplefiles/test.jsp
tests/examplefiles/test.lean
tests/examplefiles/test.maql tests/examplefiles/test.maql
tests/examplefiles/test.mask
tests/examplefiles/test.mod tests/examplefiles/test.mod
tests/examplefiles/test.moo tests/examplefiles/test.moo
tests/examplefiles/test.myt tests/examplefiles/test.myt
tests/examplefiles/test.nim tests/examplefiles/test.nim
tests/examplefiles/test.odin
tests/examplefiles/test.opa tests/examplefiles/test.opa
tests/examplefiles/test.orc
tests/examplefiles/test.p6
tests/examplefiles/test.pan
tests/examplefiles/test.pas tests/examplefiles/test.pas
tests/examplefiles/test.php tests/examplefiles/test.php
tests/examplefiles/test.pig
tests/examplefiles/test.plot tests/examplefiles/test.plot
tests/examplefiles/test.ps1 tests/examplefiles/test.ps1
tests/examplefiles/test.psl
tests/examplefiles/test.pwn
tests/examplefiles/test.pypylog tests/examplefiles/test.pypylog
tests/examplefiles/test.r3 tests/examplefiles/test.r3
tests/examplefiles/test.rb tests/examplefiles/test.rb
tests/examplefiles/test.rhtml tests/examplefiles/test.rhtml
tests/examplefiles/test.rsl
tests/examplefiles/test.scaml tests/examplefiles/test.scaml
tests/examplefiles/test.sco
tests/examplefiles/test.shen
tests/examplefiles/test.ssp tests/examplefiles/test.ssp
tests/examplefiles/test.swift
tests/examplefiles/test.tcsh tests/examplefiles/test.tcsh
tests/examplefiles/test.vb tests/examplefiles/test.vb
tests/examplefiles/test.vhdl tests/examplefiles/test.vhdl
tests/examplefiles/test.xqy tests/examplefiles/test.xqy
tests/examplefiles/test.xsl tests/examplefiles/test.xsl
tests/examplefiles/test.zep
tests/examplefiles/test2.odin
tests/examplefiles/test2.pypylog tests/examplefiles/test2.pypylog
tests/examplefiles/test_basic.adls
tests/examplefiles/truncated.pytb tests/examplefiles/truncated.pytb
tests/examplefiles/twig_test
tests/examplefiles/type.lisp tests/examplefiles/type.lisp
tests/examplefiles/underscore.coffee tests/examplefiles/underscore.coffee
tests/examplefiles/unicode.applescript tests/examplefiles/unicode.applescript
tests/examplefiles/unicode.go
tests/examplefiles/unicode.js
tests/examplefiles/unicodedoc.py tests/examplefiles/unicodedoc.py
tests/examplefiles/unix-io.lid tests/examplefiles/unix-io.lid
tests/examplefiles/vbnet_test.bas
tests/examplefiles/vctreestatus_hg
tests/examplefiles/vimrc
tests/examplefiles/vpath.mk
tests/examplefiles/webkit-transition.css tests/examplefiles/webkit-transition.css
tests/examplefiles/while.pov tests/examplefiles/while.pov
tests/examplefiles/wiki.factor tests/examplefiles/wiki.factor
tests/examplefiles/xml_example tests/examplefiles/xml_example
tests/examplefiles/yahalom.cpsa
tests/examplefiles/zmlrpc.f90 tests/examplefiles/zmlrpc.f90
tests/support/tags tests/support/tags

39
vendor/pygments/README.rst vendored Normal file
View File

@ -0,0 +1,39 @@
README for Pygments
===================
This is the source of Pygments. It is a generic syntax highlighter that
supports over 300 languages and text formats, for use in code hosting, forums,
wikis or other applications that need to prettify source code.
Installing
----------
... works as usual, use ``python setup.py install``.
Documentation
-------------
... can be found online at http://pygments.org/ or created by ::
cd doc
make html
Development
-----------
... takes place on `Bitbucket
<https://bitbucket.org/birkenfeld/pygments-main>`_, where the Mercurial
repository, tickets and pull requests can be viewed.
Continuous testing runs on drone.io:
.. image:: https://drone.io/bitbucket.org/birkenfeld/pygments-main/status.png
:target: https://drone.io/bitbucket.org/birkenfeld/pygments-main
The authors
-----------
Pygments is maintained by **Georg Brandl**, e-mail address *georg*\ *@*\ *python.org*.
Many lexers and fixes have been contributed by **Armin Ronacher**, the rest of
the `Pocoo <http://dev.pocoo.org/>`_ team and **Tim Hatch**.

View File

@ -1,9 +1,6 @@
Todo Todo
==== ====
- suggested new lexers
* IPython sessions
- lexers that need work: - lexers that need work:
* review perl lexer (numerous bugs, but so far no one had complaints ;) * review perl lexer (numerous bugs, but so far no one had complaints ;)
* readd property support for C# lexer? that is, find a regex that doesn't * readd property support for C# lexer? that is, find a regex that doesn't

153
vendor/pygments/doc/Makefile vendored Normal file
View File

@ -0,0 +1,153 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = PYTHONPATH=.. sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Pygments.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Pygments.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/Pygments"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Pygments"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

BIN
vendor/pygments/doc/_static/favicon.ico vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
vendor/pygments/doc/_static/logo_new.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,3 @@
{% if pagename != 'docs/index' %}
<strong>&laquo; <a href="{{ pathto('docs/index') }}">Back to docs index</a></strong>
{% endif %}

View File

@ -0,0 +1,25 @@
<h3>Download</h3>
{% if version.endswith('(hg)') %}
<p>This documentation is for version <b>{{ version }}</b>, which is
not released yet.</p>
<p>You can use it from the
<a href="http://bitbucket.org/birkenfeld/sphinx/">Mercurial repo</a> or look for
released versions in the <a href="http://pypi.python.org/pypi/Sphinx">Python
Package Index</a>.</p>
{% else %}
<p>Current version: <b>{{ version }}</b></p>
<p>Get Pygments from the <a href="http://pypi.python.org/pypi/Pygments">Python Package
Index</a>, or install it with:</p>
<pre>pip install Pygments</pre>
{% endif %}
<h3>Questions? Suggestions?</h3>
<p>Clone at <a href="https://bitbucket.org/birkenfeld/pygments-main">Bitbucket</a>
or come to the <tt>#pocoo</tt> channel on FreeNode.</p>
<p>You can also open an issue at the
<a href="https://www.bitbucket.org/birkenfeld/pygments-main/issues/">tracker</a>.</p>
<p class="logo">A <a href="http://pocoo.org/">
<img src="{{ pathto("_static/pocoo.png", 1) }}" /></a> project</a></p>

View File

@ -0,0 +1,98 @@
{#
sphinxdoc/layout.html
~~~~~~~~~~~~~~~~~~~~~
Sphinx layout template for the sphinxdoc theme.
:copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- extends "basic/layout.html" %}
{# put the sidebar before the body #}
{% block sidebar1 %}{{ sidebar() }}{% endblock %}
{% block sidebar2 %}{% endblock %}
{% block relbar1 %}{% endblock %}
{% block relbar2 %}{% endblock %}
{% block extrahead %}
<link href='http://fonts.googleapis.com/css?family={{ theme_font|replace(' ', '+') }}:300,400,700'
rel='stylesheet' type='text/css'>
{{ super() }}
{%- if not embedded %}
<style type="text/css">
table.right { float: right; margin-left: 20px; }
table.right td { border: 1px solid #ccc; }
{% if pagename == 'index' %}
.related { display: none; }
{% endif %}
</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>
{%- endif %}
{% endblock %}
{% block header %}
<div class="outerwrapper">
<div class="pageheader">
<ul>
<li><a href="{{ pathto('index') }}">Home</a></li>
{% if demo_active %}
<li><a href="{{ pathto('demo') }}">Demo</a></li>
{% endif %}
<li><a href="{{ pathto('languages') }}">Languages</a></li>
<li><a href="{{ pathto('faq') }}">FAQ</a></li>
<li><a href="{{ pathto('download') }}">Get it</a></li>
<li><a href="{{ pathto('docs/index') }}">Docs</a></li>
</ul>
<div>
<a href="{{ pathto('index') }}">
<img src="{{ pathto('_static/logo.png', 1) }}" alt="Pygments logo" />
</a>
</div>
</div>
{% endblock %}
{% block footer %}
<div class="footer" role="contentinfo">
&copy; Copyright 2006-2015, Georg Brandl and Pygments contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> {{
sphinx_version }}. <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> {# closes "outerwrapper" div #}
{% endblock %}
{% block sidebarrel %}
{% endblock %}
{% block sidebarsourcelink %}
{% endblock %}

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,401 @@
/*
* pygments14.css
* ~~~~~~~~~~~~~~
*
* Sphinx stylesheet -- pygments14 theme. Heavily copied from sphinx13.
*
* :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
@import url("basic.css");
/* -- page layout ----------------------------------------------------------- */
body {
font-family: {{ theme_font }}, 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
'Verdana', sans-serif;
font-size: 14px;
text-align: center;
background-image: url(bodybg.png);
background-color: {{ theme_background }};
color: black;
padding: 0;
/*
border-right: 1px solid {{ theme_border }};
border-left: 1px solid {{ theme_border }};
*/
margin: 0 auto;
min-width: 780px;
max-width: 1080px;
}
.outerwrapper {
background-image: url(docbg.png);
background-attachment: fixed;
}
.pageheader {
text-align: left;
padding: 10px 15px;
}
.pageheader ul {
float: right;
color: white;
list-style-type: none;
padding-left: 0;
margin-top: 40px;
margin-right: 10px;
}
.pageheader li {
float: left;
margin: 0 0 0 10px;
}
.pageheader li a {
border-radius: 3px;
padding: 8px 12px;
color: {{ theme_darkgray }};
text-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
.pageheader li a:hover {
background-color: {{ theme_yellow }};
color: black;
text-shadow: none;
}
div.document {
text-align: left;
/*border-left: 1em solid {{ theme_lightyellow }};*/
}
div.bodywrapper {
margin: 0 12px 0 240px;
background-color: white;
/* border-right: 1px solid {{ theme_border }}; */
}
div.body {
margin: 0;
padding: 0.5em 20px 20px 20px;
}
div.related {
font-size: 1em;
color: {{ theme_darkgray }};
}
div.related ul {
background-image: url(relbg.png);
background-repeat: repeat-y;
background-color: {{ theme_yellow }};
height: 1.9em;
/*
border-top: 1px solid {{ theme_border }};
border-bottom: 1px solid {{ theme_border }};
*/
}
div.related ul li {
margin: 0 5px 0 0;
padding: 0;
float: left;
}
div.related ul li.right {
float: right;
margin-right: 5px;
}
div.related ul li a {
margin: 0;
padding: 0 5px 0 5px;
line-height: 1.75em;
color: {{ theme_darkgray }};
/*text-shadow: 0px 0px 1px rgba(0, 0, 0, 0.5);*/
}
div.related ul li a:hover {
text-decoration: underline;
text-shadow: 0px 0px 1px rgba(255, 255, 255, 0.5);
}
div.sphinxsidebarwrapper {
position: relative;
top: 0px;
padding: 0;
}
div.sphinxsidebar {
margin: 0;
padding: 0 0px 15px 15px;
width: 210px;
float: left;
font-size: 1em;
text-align: left;
}
div.sphinxsidebar .logo {
font-size: 1.8em;
color: #666;
font-weight: 300;
text-align: center;
}
div.sphinxsidebar .logo img {
vertical-align: middle;
}
div.sphinxsidebar input {
border: 1px solid #aaa;
font-family: {{ theme_font }}, 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
'Verdana', sans-serif;
font-size: 1em;
}
div.sphinxsidebar h3 {
font-size: 1.5em;
/* border-top: 1px solid {{ theme_border }}; */
margin-top: 1em;
margin-bottom: 0.5em;
padding-top: 0.5em;
}
div.sphinxsidebar h4 {
font-size: 1.2em;
margin-bottom: 0;
}
div.sphinxsidebar h3, div.sphinxsidebar h4 {
margin-right: -15px;
margin-left: -15px;
padding-right: 14px;
padding-left: 14px;
color: #333;
font-weight: 300;
/*text-shadow: 0px 0px 0.5px rgba(0, 0, 0, 0.4);*/
}
div.sphinxsidebarwrapper > h3:first-child {
margin-top: 0.5em;
border: none;
}
div.sphinxsidebar h3 a {
color: #333;
}
div.sphinxsidebar ul {
color: #444;
margin-top: 7px;
padding: 0;
line-height: 130%;
}
div.sphinxsidebar ul ul {
margin-left: 20px;
list-style-image: url(listitem.png);
}
div.footer {
color: {{ theme_darkgray }};
text-shadow: 0 0 .2px rgba(255, 255, 255, 0.8);
padding: 2em;
text-align: center;
clear: both;
font-size: 0.8em;
}
/* -- body styles ----------------------------------------------------------- */
p {
margin: 0.8em 0 0.5em 0;
}
a {
color: {{ theme_darkgreen }};
text-decoration: none;
}
a:hover {
color: {{ theme_darkyellow }};
}
div.body a {
text-decoration: underline;
}
h1 {
margin: 10px 0 0 0;
font-size: 2.4em;
color: {{ theme_darkgray }};
font-weight: 300;
}
h2 {
margin: 1.em 0 0.2em 0;
font-size: 1.5em;
font-weight: 300;
padding: 0;
color: {{ theme_darkgreen }};
}
h3 {
margin: 1em 0 -0.3em 0;
font-size: 1.3em;
font-weight: 300;
}
div.body h1 a, div.body h2 a, div.body h3 a, div.body h4 a, div.body h5 a, div.body h6 a {
text-decoration: none;
}
div.body h1 a tt, div.body h2 a tt, div.body h3 a tt, div.body h4 a tt, div.body h5 a tt, div.body h6 a tt {
color: {{ theme_darkgreen }} !important;
font-size: inherit !important;
}
a.headerlink {
color: {{ theme_green }} !important;
font-size: 12px;
margin-left: 6px;
padding: 0 4px 0 4px;
text-decoration: none !important;
float: right;
}
a.headerlink:hover {
background-color: #ccc;
color: white!important;
}
cite, code, tt {
font-family: 'Consolas', 'DejaVu Sans Mono',
'Bitstream Vera Sans Mono', monospace;
font-size: 14px;
letter-spacing: -0.02em;
}
tt {
background-color: #f2f2f2;
border: 1px solid #ddd;
border-radius: 2px;
color: #333;
padding: 1px;
}
tt.descname, tt.descclassname, tt.xref {
border: 0;
}
hr {
border: 1px solid #abc;
margin: 2em;
}
a tt {
border: 0;
color: {{ theme_darkgreen }};
}
a tt:hover {
color: {{ theme_darkyellow }};
}
pre {
font-family: 'Consolas', 'DejaVu Sans Mono',
'Bitstream Vera Sans Mono', monospace;
font-size: 13px;
letter-spacing: 0.015em;
line-height: 120%;
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 2px;
background-color: #f8f8f8;
}
pre a {
color: inherit;
text-decoration: underline;
}
td.linenos pre {
padding: 0.5em 0;
}
div.quotebar {
background-color: #f8f8f8;
max-width: 250px;
float: right;
padding: 0px 7px;
border: 1px solid #ccc;
margin-left: 1em;
}
div.topic {
background-color: #f8f8f8;
}
table {
border-collapse: collapse;
margin: 0 -0.5em 0 -0.5em;
}
table td, table th {
padding: 0.2em 0.5em 0.2em 0.5em;
}
div.admonition, div.warning {
font-size: 0.9em;
margin: 1em 0 1em 0;
border: 1px solid #86989B;
border-radius: 2px;
background-color: #f7f7f7;
padding: 0;
}
div.admonition p, div.warning p {
margin: 0.5em 1em 0.5em 1em;
padding: 0;
}
div.admonition pre, div.warning pre {
margin: 0.4em 1em 0.4em 1em;
}
div.admonition p.admonition-title,
div.warning p.admonition-title {
margin-top: 1em;
padding-top: 0.5em;
font-weight: bold;
}
div.warning {
border: 1px solid #940000;
/* background-color: #FFCCCF;*/
}
div.warning p.admonition-title {
}
div.admonition ul, div.admonition ol,
div.warning ul, div.warning ol {
margin: 0.1em 0.5em 0.5em 3em;
padding: 0;
}
.viewcode-back {
font-family: {{ theme_font }}, 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva',
'Verdana', sans-serif;
}
div.viewcode-block:target {
background-color: #f4debf;
border-top: 1px solid #ac9;
border-bottom: 1px solid #ac9;
}

View File

@ -0,0 +1,15 @@
[theme]
inherit = basic
stylesheet = pygments14.css
pygments_style = friendly
[options]
green = #66b55e
darkgreen = #36852e
darkgray = #666666
border = #66b55e
yellow = #f4cd00
darkyellow = #d4ad00
lightyellow = #fffbe3
background = #f9f9f9
font = PT Sans

241
vendor/pygments/doc/conf.py vendored Normal file
View File

@ -0,0 +1,241 @@
# -*- coding: utf-8 -*-
#
# Pygments documentation build configuration file
#
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
import pygments
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'pygments.sphinxext']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Pygments'
copyright = u'2015, Georg Brandl'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = pygments.__version__
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
#pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'pygments14'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ['_themes']
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = '_static/favicon.ico'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
html_sidebars = {'index': 'indexsidebar.html',
'docs/*': 'docssidebar.html'}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'Pygmentsdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'Pygments.tex', u'Pygments Documentation',
u'Georg Brandl', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pygments', u'Pygments Documentation',
[u'Georg Brandl'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Pygments', u'Pygments Documentation',
u'Georg Brandl', 'Pygments', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# Example configuration for intersphinx: refer to the Python standard library.
#intersphinx_mapping = {'http://docs.python.org/': None}

316
vendor/pygments/doc/docs/api.rst vendored Normal file
View File

@ -0,0 +1,316 @@
.. -*- mode: rst -*-
=====================
The full Pygments API
=====================
This page describes the Pygments API.
High-level API
==============
.. module:: pygments
Functions from the :mod:`pygments` module:
.. function:: lex(code, lexer)
Lex `code` with the `lexer` (must be a `Lexer` instance)
and return an iterable of tokens. Currently, this only calls
`lexer.get_tokens()`.
.. function:: format(tokens, formatter, outfile=None)
Format a token stream (iterable of tokens) `tokens` with the
`formatter` (must be a `Formatter` instance). The result is
written to `outfile`, or if that is ``None``, returned as a
string.
.. function:: highlight(code, lexer, formatter, outfile=None)
This is the most high-level highlighting function.
It combines `lex` and `format` in one function.
.. module:: pygments.lexers
Functions from :mod:`pygments.lexers`:
.. function:: get_lexer_by_name(alias, **options)
Return an instance of a `Lexer` subclass that has `alias` in its
aliases list. The lexer is given the `options` at its
instantiation.
Will raise :exc:`pygments.util.ClassNotFound` if no lexer with that alias is
found.
.. function:: get_lexer_for_filename(fn, **options)
Return a `Lexer` subclass instance that has a filename pattern
matching `fn`. The lexer is given the `options` at its
instantiation.
Will raise :exc:`pygments.util.ClassNotFound` if no lexer for that filename
is found.
.. function:: get_lexer_for_mimetype(mime, **options)
Return a `Lexer` subclass instance that has `mime` in its mimetype
list. The lexer is given the `options` at its instantiation.
Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype
is found.
.. function:: guess_lexer(text, **options)
Return a `Lexer` subclass instance that's guessed from the text in
`text`. For that, the :meth:`.analyse_text()` 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.
:exc:`pygments.util.ClassNotFound` is raised if no lexer thinks it can
handle the content.
.. function:: guess_lexer_for_filename(filename, text, **options)
As :func:`guess_lexer()`, but only lexers which have a pattern in `filenames`
or `alias_filenames` that matches `filename` are taken into consideration.
:exc:`pygments.util.ClassNotFound` is raised if no lexer thinks it can
handle the content.
.. function:: get_all_lexers()
Return an iterable over all registered lexers, yielding tuples in the
format::
(longname, tuple of aliases, tuple of filename patterns, tuple of mimetypes)
.. versionadded:: 0.6
.. module:: pygments.formatters
Functions from :mod:`pygments.formatters`:
.. function:: get_formatter_by_name(alias, **options)
Return an instance of a :class:`.Formatter` subclass that has `alias` in its
aliases list. The formatter is given the `options` at its instantiation.
Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that
alias is found.
.. function:: get_formatter_for_filename(fn, **options)
Return a :class:`.Formatter` subclass instance that has a filename pattern
matching `fn`. The formatter is given the `options` at its instantiation.
Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename
is found.
.. module:: pygments.styles
Functions from :mod:`pygments.styles`:
.. function:: get_style_by_name(name)
Return a style class by its short name. The names of the builtin styles
are listed in :data:`pygments.styles.STYLE_MAP`.
Will raise :exc:`pygments.util.ClassNotFound` if no style of that name is
found.
.. function:: get_all_styles()
Return an iterable over all registered styles, yielding their names.
.. versionadded:: 0.6
.. module:: pygments.lexer
Lexers
======
The base lexer class from which all lexers are derived is:
.. class:: Lexer(**options)
The constructor takes a \*\*keywords dictionary of options.
Every subclass must first process its own options and then call
the `Lexer` constructor, since it processes the `stripnl`,
`stripall` and `tabsize` options.
An example looks like this:
.. sourcecode:: python
def __init__(self, **options):
self.compress = options.get('compress', '')
Lexer.__init__(self, **options)
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 `Option processing`_.
.. method:: get_tokens(text)
This method is the basic interface of a lexer. It is called by
the `highlight()` function. It must process the text and return an
iterable of ``(tokentype, value)`` pairs from `text`.
Normally, you don't need to override this method. The default
implementation processes the `stripnl`, `stripall` and `tabsize`
options and then yields all tokens from `get_tokens_unprocessed()`,
with the ``index`` dropped.
.. method:: get_tokens_unprocessed(text)
This method should process the text and return an iterable of
``(index, tokentype, value)`` tuples where ``index`` is the starting
position of the token within the input text.
This method must be overridden by subclasses.
.. staticmethod:: analyse_text(text)
A static method which is called for lexer guessing. It should analyse
the text and return a float in the range from ``0.0`` to ``1.0``.
If it returns ``0.0``, the lexer will not be selected as the most
probable one, if it returns ``1.0``, it will be selected immediately.
.. note:: You don't have to add ``@staticmethod`` to the definition of
this method, this will be taken care of by the Lexer's metaclass.
For a list of known tokens have a look at the :doc:`tokens` page.
A lexer also can have the following attributes (in fact, they are mandatory
except `alias_filenames`) that are used by the builtin lookup mechanism.
.. attribute:: name
Full name for the lexer, in human-readable form.
.. attribute:: aliases
A list of short, unique identifiers that can be used to lookup
the lexer from a list, e.g. using `get_lexer_by_name()`.
.. attribute:: filenames
A list of `fnmatch` patterns that match filenames which contain
content for this lexer. The patterns in this list should be unique among
all lexers.
.. attribute:: alias_filenames
A list of `fnmatch` patterns that match filenames which may or may not
contain content for this lexer. This list is used by the
:func:`.guess_lexer_for_filename()` 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
``\*.html`` in this list.
.. attribute:: mimetypes
A list of MIME types for content that can be lexed with this
lexer.
.. module:: pygments.formatter
Formatters
==========
A formatter is derived from this class:
.. class:: Formatter(**options)
As with lexers, this constructor processes options and then must call the
base class :meth:`__init__`.
The :class:`Formatter` class recognizes the options `style`, `full` and
`title`. It is up to the formatter class whether it uses them.
.. method:: get_style_defs(arg='')
This method must return statements or declarations suitable to define
the current style for subsequent highlighted text (e.g. CSS classes
in the `HTMLFormatter`).
The optional argument `arg` can be used to modify the generation and
is formatter dependent (it is standardized because it can be given on
the command line).
This method is called by the ``-S`` :doc:`command-line option <cmdline>`,
the `arg` is then given by the ``-a`` option.
.. method:: format(tokensource, outfile)
This method must format the tokens from the `tokensource` iterable and
write the formatted version to the file object `outfile`.
Formatter options can control how exactly the tokens are converted.
.. versionadded:: 0.7
A formatter must have the following attributes that are used by the
builtin lookup mechanism.
.. attribute:: name
Full name for the formatter, in human-readable form.
.. attribute:: aliases
A list of short, unique identifiers that can be used to lookup
the formatter from a list, e.g. using :func:`.get_formatter_by_name()`.
.. attribute:: filenames
A list of :mod:`fnmatch` patterns that match filenames for which this
formatter can produce output. The patterns in this list should be unique
among all formatters.
.. module:: pygments.util
Option processing
=================
The :mod:`pygments.util` module has some utility functions usable for option
processing:
.. exception:: OptionError
This exception will be raised by all option processing functions if
the type or value of the argument is not correct.
.. function:: get_bool_opt(options, optname, default=None)
Interpret the key `optname` from the dictionary `options` as a boolean and
return it. Return `default` if `optname` is not in `options`.
The valid string values for ``True`` are ``1``, ``yes``, ``true`` and
``on``, the ones for ``False`` are ``0``, ``no``, ``false`` and ``off``
(matched case-insensitively).
.. function:: get_int_opt(options, optname, default=None)
As :func:`get_bool_opt`, but interpret the value as an integer.
.. function:: get_list_opt(options, optname, default=None)
If the key `optname` from the dictionary `options` 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.
.. function:: get_choice_opt(options, optname, allowed, default=None)
If the key `optname` from the dictionary is not in the sequence
`allowed`, raise an error, otherwise return it.
.. versionadded:: 0.8

4
vendor/pygments/doc/docs/authors.rst vendored Normal file
View File

@ -0,0 +1,4 @@
Full contributor list
=====================
.. include:: ../../AUTHORS

View File

@ -0,0 +1 @@
.. include:: ../../CHANGES

View File

@ -4,8 +4,8 @@
Command Line Interface Command Line Interface
====================== ======================
You can use Pygments from the shell, provided you installed the `pygmentize` You can use Pygments from the shell, provided you installed the
script:: :program:`pygmentize` script::
$ pygmentize test.py $ pygmentize test.py
print "Hello World" print "Hello World"
@ -28,7 +28,7 @@ written to stdout.
The ``-f`` option selects a formatter (as with ``-l``, it can also be omitted The ``-f`` option selects a formatter (as with ``-l``, it can also be omitted
if an output file name is given and has a supported extension). if an output file name is given and has a supported extension).
If no output file name is given and ``-f`` is omitted, the If no output file name is given and ``-f`` is omitted, the
`TerminalFormatter` is used. :class:`.TerminalFormatter` is used.
The above command could therefore also be given as:: The above command could therefore also be given as::
@ -82,14 +82,15 @@ Usage is as follows::
generates a CSS style sheet (because you selected the HTML formatter) for generates a CSS style sheet (because you selected the HTML formatter) for
the "colorful" style prepending a ".syntax" selector to all style rules. the "colorful" style prepending a ".syntax" selector to all style rules.
For an explanation what ``-a`` means for `a particular formatter`_, look for For an explanation what ``-a`` means for :doc:`a particular formatter
the `arg` argument for the formatter's `get_style_defs()` method. <formatters>`, look for the `arg` argument for the formatter's
:meth:`.get_style_defs()` method.
Getting lexer names Getting lexer names
------------------- -------------------
*New in Pygments 1.0.* .. versionadded:: 1.0
The ``-N`` option guesses a lexer name for a given filename, so that :: The ``-N`` option guesses a lexer name for a given filename, so that ::
@ -125,7 +126,7 @@ will print the help for the Python lexer, etc.
A note on encodings A note on encodings
------------------- -------------------
*New in Pygments 0.9.* .. versionadded:: 0.9
Pygments tries to be smart regarding encodings in the formatting process: Pygments tries to be smart regarding encodings in the formatting process:
@ -135,13 +136,14 @@ Pygments tries to be smart regarding encodings in the formatting process:
* If you give an ``outencoding`` option, it will override ``encoding`` * If you give an ``outencoding`` option, it will override ``encoding``
as the output encoding. as the output encoding.
* If you give an ``inencoding`` option, it will override ``encoding``
as the input encoding.
* If you don't give an encoding and have given an output file, the default * If you don't give an encoding and have given an output file, the default
encoding for lexer and formatter is ``latin1`` (which will pass through encoding for lexer and formatter is the terminal encoding or the default
all non-ASCII characters). locale encoding of the system. As a last resort, ``latin1`` is used (which
will pass through all non-ASCII characters).
* If you don't give an encoding and haven't given an output file (that means * 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 output is written to the console), the default encoding for lexer and
formatter is the terminal encoding (`sys.stdout.encoding`). formatter is the terminal encoding (``sys.stdout.encoding``).
.. _a particular formatter: formatters.txt

View File

@ -4,11 +4,11 @@
Write your own filter Write your own filter
===================== =====================
*New in Pygments 0.7.* .. versionadded:: 0.7
Writing own filters is very easy. All you have to do is to subclass Writing own filters is very easy. All you have to do is to subclass
the `Filter` class and override the `filter` method. Additionally a the `Filter` class and override the `filter` method. Additionally a
filter is instanciated with some keyword arguments you can use to filter is instantiated with some keyword arguments you can use to
adjust the behavior of your filter. adjust the behavior of your filter.
@ -58,7 +58,7 @@ You can also use the `simplefilter` decorator from the `pygments.filter` module:
@simplefilter @simplefilter
def uncolor(lexer, stream, options): def uncolor(self, lexer, stream, options):
class_too = get_bool_opt(options, 'classtoo') class_too = get_bool_opt(options, 'classtoo')
for ttype, value in stream: for ttype, value in stream:
if ttype is Name.Function or (class_too and if ttype is Name.Function or (class_too and
@ -67,4 +67,5 @@ You can also use the `simplefilter` decorator from the `pygments.filter` module:
yield ttype, value yield ttype, value
The decorator automatically subclasses an internal filter class and uses the The decorator automatically subclasses an internal filter class and uses the
decorated function for filtering. decorated function as a method for filtering. (That's why there is a `self`
argument that you probably won't end up using in the method.)

View File

@ -4,7 +4,7 @@
Filters Filters
======= =======
*New in Pygments 0.7.* .. versionadded:: 0.7
You can filter token streams coming from lexers to improve or annotate the You can filter token streams coming from lexers to improve or annotate the
output. For example, you can highlight special words in comments, convert output. For example, you can highlight special words in comments, convert
@ -31,12 +31,11 @@ To get a list of all registered filters by name, you can use the
`get_all_filters()` function from the `pygments.filters` module that returns an `get_all_filters()` function from the `pygments.filters` module that returns an
iterable for all known filters. iterable for all known filters.
If you want to write your own filter, have a look at `Write your own filter`_. If you want to write your own filter, have a look at :doc:`Write your own filter
<filterdevelopment>`.
.. _Write your own filter: filterdevelopment.txt
Builtin Filters Builtin Filters
=============== ===============
[builtin_filter_docs] .. pygmentsdoc:: filters

View File

@ -4,7 +4,7 @@
Write your own formatter Write your own formatter
======================== ========================
As well as creating `your own lexer <lexerdevelopment.txt>`_, writing a new As well as creating :doc:`your own lexer <lexerdevelopment>`, writing a new
formatter for Pygments is easy and straightforward. formatter for Pygments is easy and straightforward.
A formatter is a class that is initialized with some keyword arguments (the A formatter is a class that is initialized with some keyword arguments (the

View File

@ -12,8 +12,6 @@ Common options
All formatters support these options: All formatters support these options:
`encoding` `encoding`
*New in Pygments 0.6.*
If given, must be an encoding name (such as ``"utf-8"``). This will If given, must be an encoding name (such as ``"utf-8"``). This will
be used to convert the token strings (which are Unicode strings) be used to convert the token strings (which are Unicode strings)
to byte strings in the output (default: ``None``). to byte strings in the output (default: ``None``).
@ -30,19 +28,21 @@ All formatters support these options:
supports Unicode arguments to `write()`. Using a regular file object supports Unicode arguments to `write()`. Using a regular file object
wouldn't work. wouldn't work.
`outencoding` .. versionadded:: 0.6
*New in Pygments 0.7.*
`outencoding`
When using Pygments from the command line, any `encoding` option given is When using Pygments from the command line, any `encoding` option given is
passed to the lexer and the formatter. This is sometimes not desirable, passed to the lexer and the formatter. This is sometimes not desirable,
for example if you want to set the input encoding to ``"guess"``. for example if you want to set the input encoding to ``"guess"``.
Therefore, `outencoding` has been introduced which overrides `encoding` Therefore, `outencoding` has been introduced which overrides `encoding`
for the formatter if given. for the formatter if given.
.. versionadded:: 0.7
Formatter classes Formatter classes
================= =================
All these classes are importable from `pygments.formatters`. All these classes are importable from :mod:`pygments.formatters`.
[builtin_formatter_docs] .. pygmentsdoc:: formatters

66
vendor/pygments/doc/docs/index.rst vendored Normal file
View File

@ -0,0 +1,66 @@
Pygments documentation
======================
**Starting with Pygments**
.. toctree::
:maxdepth: 1
../download
quickstart
cmdline
**Builtin components**
.. toctree::
:maxdepth: 1
lexers
filters
formatters
styles
**Reference**
.. toctree::
:maxdepth: 1
unicode
tokens
api
**Hacking for Pygments**
.. toctree::
:maxdepth: 1
lexerdevelopment
formatterdevelopment
filterdevelopment
plugins
**Hints and tricks**
.. toctree::
:maxdepth: 1
rstdirective
moinmoin
java
integrate
**About Pygments**
.. toctree::
:maxdepth: 1
changelog
authors
If you find bugs or have suggestions for the documentation, please look
:ref:`here <contribute>` for info on how to contact the team.
.. XXX You can download an offline version of this documentation from the
:doc:`download page </download>`.

View File

@ -4,27 +4,13 @@
Using Pygments in various scenarios Using Pygments in various scenarios
=================================== ===================================
PyGtk
-----
Armin has written a piece of sample code that shows how to create a Gtk
`TextBuffer` object containing Pygments-highlighted text.
See the article here: http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-gtk-rendering/
Wordpress
---------
He also has a snippet that shows how to use Pygments in WordPress:
http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-in-wordpress/
Markdown Markdown
-------- --------
Since Pygments 0.9, the distribution ships Markdown_ preprocessor sample code Since Pygments 0.9, the distribution ships Markdown_ preprocessor sample code
that uses Pygments to render source code in `external/markdown-processor.py`. that uses Pygments to render source code in
You can copy and adapt it to your liking. :file:`external/markdown-processor.py`. You can copy and adapt it to your
liking.
.. _Markdown: http://www.freewisdom.org/projects/python-markdown/ .. _Markdown: http://www.freewisdom.org/projects/python-markdown/
@ -42,7 +28,13 @@ Bash completion
The source distribution contains a file ``external/pygments.bashcomp`` that The source distribution contains a file ``external/pygments.bashcomp`` that
sets up completion for the ``pygmentize`` command in bash. sets up completion for the ``pygmentize`` command in bash.
Java Wrappers for other languages
---- ----------------------------
See the `Java quickstart <java.txt>`_ document. These libraries provide Pygments highlighting for users of other languages
than Python:
* `pygments.rb <https://github.com/tmm1/pygments.rb>`_, a pygments wrapper for Ruby
* `Clygments <https://github.com/bfontaine/clygments>`_, a pygments wrapper for
Clojure
* `PHPygments <https://github.com/capynet/PHPygments>`_, a pygments wrapper for PHP

View File

@ -2,18 +2,18 @@
Use Pygments in Java Use Pygments in Java
===================== =====================
Thanks to `Jython <http://www.jython.org>`__ it is possible to use Pygments in Thanks to `Jython <http://www.jython.org>`_ it is possible to use Pygments in
Java. Java.
This page is a simple tutorial to get an idea of how this is working. You can This page is a simple tutorial to get an idea of how this works. You can
then look at the `Jython documentation <http://www.jython.org/docs/>`__ for more then look at the `Jython documentation <http://www.jython.org/docs/>`_ for more
advanced use. advanced uses.
Since version 1.5, Pygments is deployed on `Maven Central Since version 1.5, Pygments is deployed on `Maven Central
<http://repo1.maven.org/maven2/org/pygments/pygments/>`__ as a JAR so is Jython <http://repo1.maven.org/maven2/org/pygments/pygments/>`_ as a JAR, as is Jython
which makes it a lot easier to create the Java project. which makes it a lot easier to create a Java project.
Here is an example of a `Maven <http://www.maven.org>`__ ``pom.xml`` file for a Here is an example of a `Maven <http://www.maven.org>`_ ``pom.xml`` file for a
project running Pygments: project running Pygments:
.. sourcecode:: xml .. sourcecode:: xml

View File

@ -0,0 +1,681 @@
.. -*- mode: rst -*-
.. highlight:: python
====================
Write your own lexer
====================
If a lexer for your favorite language is missing in the Pygments package, you
can easily write your own and extend Pygments.
All you need can be found inside the :mod:`pygments.lexer` module. As you can
read in the :doc:`API documentation <api>`, a lexer is a class that is
initialized with some keyword arguments (the lexer options) and that provides a
:meth:`.get_tokens_unprocessed()` method which is given a string or unicode
object with the data to lex.
The :meth:`.get_tokens_unprocessed()` method must return an iterator or iterable
containing tuples in the form ``(index, token, value)``. Normally you don't
need to do this since there are base lexers that do most of the work and that
you can subclass.
RegexLexer
==========
The lexer base class used by almost all of Pygments' lexers is the
:class:`RegexLexer`. This class allows you to define lexing rules in terms of
*regular expressions* for different *states*.
States are groups of regular expressions that are matched against the input
string at the *current position*. If one of these expressions matches, a
corresponding action is performed (such as yielding a token with a specific
type, or changing state), the current position is set to where the last match
ended and the matching process continues with the first regex of the current
state.
Lexer states are kept on a stack: each time a new state is entered, the new
state is pushed onto the stack. The most basic lexers (like the `DiffLexer`)
just need one state.
Each state is defined as a list of tuples in the form (`regex`, `action`,
`new_state`) where the last item is optional. In the most basic form, `action`
is a token type (like `Name.Builtin`). That means: When `regex` matches, emit a
token with the match text and type `tokentype` and push `new_state` on the state
stack. If the new state is ``'#pop'``, the topmost state is popped from the
stack instead. To pop more than one state, use ``'#pop:2'`` and so on.
``'#push'`` is a synonym for pushing the current state on the stack.
The following example shows the `DiffLexer` from the builtin lexers. Note that
it contains some additional attributes `name`, `aliases` and `filenames` which
aren't required for a lexer. They are used by the builtin lexer lookup
functions. ::
from pygments.lexer import RegexLexer
from pygments.token import *
class DiffLexer(RegexLexer):
name = 'Diff'
aliases = ['diff']
filenames = ['*.diff']
tokens = {
'root': [
(r' .*\n', Text),
(r'\+.*\n', Generic.Inserted),
(r'-.*\n', Generic.Deleted),
(r'@.*\n', Generic.Subheading),
(r'Index.*\n', Generic.Heading),
(r'=.*\n', Generic.Heading),
(r'.*\n', Text),
]
}
As you can see this lexer only uses one state. When the lexer starts scanning
the text, it first checks if the current character is a space. If this is true
it scans everything until newline and returns the data as a `Text` token (which
is the "no special highlighting" token).
If this rule doesn't match, it checks if the current char is a plus sign. And
so on.
If no rule matches at the current position, the current char is emitted as an
`Error` token that indicates a lexing error, and the position is increased by
one.
Adding and testing a new lexer
==============================
To make Pygments aware of your new lexer, you have to perform the following
steps:
First, change to the current directory containing the Pygments source code:
.. code-block:: console
$ cd .../pygments-main
Select a matching module under ``pygments/lexers``, or create a new module for
your lexer class.
Next, make sure the lexer is known from outside of the module. All modules in
the ``pygments.lexers`` specify ``__all__``. For example, ``esoteric.py`` sets::
__all__ = ['BrainfuckLexer', 'BefungeLexer', ...]
Simply add the name of your lexer class to this list.
Finally the lexer can be made publicly known by rebuilding the lexer mapping:
.. code-block:: console
$ make mapfiles
To test the new lexer, store an example file with the proper extension in
``tests/examplefiles``. For example, to test your ``DiffLexer``, add a
``tests/examplefiles/example.diff`` containing a sample diff output.
Now you can use pygmentize to render your example to HTML:
.. code-block:: console
$ ./pygmentize -O full -f html -o /tmp/example.html tests/examplefiles/example.diff
Note that this explicitly calls the ``pygmentize`` in the current directory
by preceding it with ``./``. This ensures your modifications are used.
Otherwise a possibly already installed, unmodified version without your new
lexer would have been called from the system search path (``$PATH``).
To view the result, open ``/tmp/example.html`` in your browser.
Once the example renders as expected, you should run the complete test suite:
.. code-block:: console
$ make test
It also tests that your lexer fulfills the lexer API and certain invariants,
such as that the concatenation of all token text is the same as the input text.
Regex Flags
===========
You can either define regex flags locally in the regex (``r'(?x)foo bar'``) or
globally by adding a `flags` attribute to your lexer class. If no attribute is
defined, it defaults to `re.MULTILINE`. For more information about regular
expression flags see the page about `regular expressions`_ in the Python
documentation.
.. _regular expressions: http://docs.python.org/library/re.html#regular-expression-syntax
Scanning multiple tokens at once
================================
So far, the `action` element in the rule tuple of regex, action and state has
been a single token type. Now we look at the first of several other possible
values.
Here is a more complex lexer that highlights INI files. INI files consist of
sections, comments and ``key = value`` pairs::
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
class IniLexer(RegexLexer):
name = 'INI'
aliases = ['ini', 'cfg']
filenames = ['*.ini', '*.cfg']
tokens = {
'root': [
(r'\s+', Text),
(r';.*?$', Comment),
(r'\[.*?\]$', Keyword),
(r'(.*?)(\s*)(=)(\s*)(.*?)$',
bygroups(Name.Attribute, Text, Operator, Text, String))
]
}
The lexer first looks for whitespace, comments and section names. Later it
looks for a line that looks like a key, value pair, separated by an ``'='``
sign, and optional whitespace.
The `bygroups` helper yields each capturing group in the regex with a different
token type. First the `Name.Attribute` token, then a `Text` token for the
optional whitespace, after that a `Operator` token for the equals sign. Then a
`Text` token for the whitespace again. The rest of the line is returned as
`String`.
Note that for this to work, every part of the match must be inside a capturing
group (a ``(...)``), and there must not be any nested capturing groups. If you
nevertheless need a group, use a non-capturing group defined using this syntax:
``(?:some|words|here)`` (note the ``?:`` after the beginning parenthesis).
If you find yourself needing a capturing group inside the regex which shouldn't
be part of the output but is used in the regular expressions for backreferencing
(eg: ``r'(<(foo|bar)>)(.*?)(</\2>)'``), you can pass `None` to the bygroups
function and that group will be skipped in the output.
Changing states
===============
Many lexers need multiple states to work as expected. For example, some
languages allow multiline comments to be nested. Since this is a recursive
pattern it's impossible to lex just using regular expressions.
Here is a lexer that recognizes C++ style comments (multi-line with ``/* */``
and single-line with ``//`` until end of line)::
from pygments.lexer import RegexLexer
from pygments.token import *
class CppCommentLexer(RegexLexer):
name = 'Example Lexer with states'
tokens = {
'root': [
(r'[^/]+', Text),
(r'/\*', Comment.Multiline, 'comment'),
(r'//.*?$', Comment.Singleline),
(r'/', Text)
],
'comment': [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
]
}
This lexer starts lexing in the ``'root'`` state. It tries to match as much as
possible until it finds a slash (``'/'``). If the next character after the slash
is an asterisk (``'*'``) the `RegexLexer` sends those two characters to the
output stream marked as `Comment.Multiline` and continues lexing with the rules
defined in the ``'comment'`` state.
If there wasn't an asterisk after the slash, the `RegexLexer` checks if it's a
Singleline comment (i.e. followed by a second slash). If this also wasn't the
case it must be a single slash, which is not a comment starter (the separate
regex for a single slash must also be given, else the slash would be marked as
an error token).
Inside the ``'comment'`` state, we do the same thing again. Scan until the
lexer finds a star or slash. If it's the opening of a multiline comment, push
the ``'comment'`` state on the stack and continue scanning, again in the
``'comment'`` state. Else, check if it's the end of the multiline comment. If
yes, pop one state from the stack.
Note: If you pop from an empty stack you'll get an `IndexError`. (There is an
easy way to prevent this from happening: don't ``'#pop'`` in the root state).
If the `RegexLexer` encounters a newline that is flagged as an error token, the
stack is emptied and the lexer continues scanning in the ``'root'`` state. This
can help producing error-tolerant highlighting for erroneous input, e.g. when a
single-line string is not closed.
Advanced state tricks
=====================
There are a few more things you can do with states:
- You can push multiple states onto the stack if you give a tuple instead of a
simple string as the third item in a rule tuple. For example, if you want to
match a comment containing a directive, something like:
.. code-block:: text
/* <processing directive> rest of comment */
you can use this rule::
tokens = {
'root': [
(r'/\* <', Comment, ('comment', 'directive')),
...
],
'directive': [
(r'[^>]*', Comment.Directive),
(r'>', Comment, '#pop'),
],
'comment': [
(r'[^*]+', Comment),
(r'\*/', Comment, '#pop'),
(r'\*', Comment),
]
}
When this encounters the above sample, first ``'comment'`` and ``'directive'``
are pushed onto the stack, then the lexer continues in the directive state
until it finds the closing ``>``, then it continues in the comment state until
the closing ``*/``. Then, both states are popped from the stack again and
lexing continues in the root state.
.. versionadded:: 0.9
The tuple can contain the special ``'#push'`` and ``'#pop'`` (but not
``'#pop:n'``) directives.
- You can include the rules of a state in the definition of another. This is
done by using `include` from `pygments.lexer`::
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import *
class ExampleLexer(RegexLexer):
tokens = {
'comments': [
(r'/\*.*?\*/', Comment),
(r'//.*?\n', Comment),
],
'root': [
include('comments'),
(r'(function )(\w+)( {)',
bygroups(Keyword, Name, Keyword), 'function'),
(r'.', Text),
],
'function': [
(r'[^}/]+', Text),
include('comments'),
(r'/', Text),
(r'\}', Keyword, '#pop'),
]
}
This is a hypothetical lexer for a language that consist of functions and
comments. Because comments can occur at toplevel and in functions, we need
rules for comments in both states. As you can see, the `include` helper saves
repeating rules that occur more than once (in this example, the state
``'comment'`` will never be entered by the lexer, as it's only there to be
included in ``'root'`` and ``'function'``).
- Sometimes, you may want to "combine" a state from existing ones. This is
possible with the `combined` helper from `pygments.lexer`.
If you, instead of a new state, write ``combined('state1', 'state2')`` as the
third item of a rule tuple, a new anonymous state will be formed from state1
and state2 and if the rule matches, the lexer will enter this state.
This is not used very often, but can be helpful in some cases, such as the
`PythonLexer`'s string literal processing.
- If you want your lexer to start lexing in a different state you can modify the
stack by overriding the `get_tokens_unprocessed()` method::
from pygments.lexer import RegexLexer
class ExampleLexer(RegexLexer):
tokens = {...}
def get_tokens_unprocessed(self, text, stack=('root', 'otherstate')):
for item in RegexLexer.get_tokens_unprocessed(text, stack):
yield item
Some lexers like the `PhpLexer` use this to make the leading ``<?php``
preprocessor comments optional. Note that you can crash the lexer easily by
putting values into the stack that don't exist in the token map. Also
removing ``'root'`` from the stack can result in strange errors!
- In some lexers, a state should be popped if anything is encountered that isn't
matched by a rule in the state. You could use an empty regex at the end of
the state list, but Pygments provides a more obvious way of spelling that:
``default('#pop')`` is equivalent to ``('', Text, '#pop')``.
.. versionadded:: 2.0
Subclassing lexers derived from RegexLexer
==========================================
.. versionadded:: 1.6
Sometimes multiple languages are very similar, but should still be lexed by
different lexer classes.
When subclassing a lexer derived from RegexLexer, the ``tokens`` dictionaries
defined in the parent and child class are merged. For example::
from pygments.lexer import RegexLexer, inherit
from pygments.token import *
class BaseLexer(RegexLexer):
tokens = {
'root': [
('[a-z]+', Name),
(r'/\*', Comment, 'comment'),
('"', String, 'string'),
('\s+', Text),
],
'string': [
('[^"]+', String),
('"', String, '#pop'),
],
'comment': [
...
],
}
class DerivedLexer(BaseLexer):
tokens = {
'root': [
('[0-9]+', Number),
inherit,
],
'string': [
(r'[^"\\]+', String),
(r'\\.', String.Escape),
('"', String, '#pop'),
],
}
The `BaseLexer` defines two states, lexing names and strings. The
`DerivedLexer` defines its own tokens dictionary, which extends the definitions
of the base lexer:
* The "root" state has an additional rule and then the special object `inherit`,
which tells Pygments to insert the token definitions of the parent class at
that point.
* The "string" state is replaced entirely, since there is not `inherit` rule.
* The "comment" state is inherited entirely.
Using multiple lexers
=====================
Using multiple lexers for the same input can be tricky. One of the easiest
combination techniques is shown here: You can replace the action entry in a rule
tuple with a lexer class. The matched text will then be lexed with that lexer,
and the resulting tokens will be yielded.
For example, look at this stripped-down HTML lexer::
from pygments.lexer import RegexLexer, bygroups, using
from pygments.token import *
from pygments.lexers.javascript import JavascriptLexer
class HtmlLexer(RegexLexer):
name = 'HTML'
aliases = ['html']
filenames = ['*.html', '*.htm']
flags = re.IGNORECASE | re.DOTALL
tokens = {
'root': [
('[^<&]+', Text),
('&.*?;', Name.Entity),
(r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
(r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
(r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
],
'script-content': [
(r'(.+?)(<\s*/\s*script\s*>)',
bygroups(using(JavascriptLexer), Name.Tag),
'#pop'),
]
}
Here the content of a ``<script>`` tag is passed to a newly created instance of
a `JavascriptLexer` and not processed by the `HtmlLexer`. This is done using
the `using` helper that takes the other lexer class as its parameter.
Note the combination of `bygroups` and `using`. This makes sure that the
content up to the ``</script>`` end tag is processed by the `JavascriptLexer`,
while the end tag is yielded as a normal token with the `Name.Tag` type.
Also note the ``(r'<\s*script\s*', Name.Tag, ('script-content', 'tag'))`` rule.
Here, two states are pushed onto the state stack, ``'script-content'`` and
``'tag'``. That means that first ``'tag'`` is processed, which will lex
attributes and the closing ``>``, then the ``'tag'`` state is popped and the
next state on top of the stack will be ``'script-content'``.
Since you cannot refer to the class currently being defined, use `this`
(imported from `pygments.lexer`) to refer to the current lexer class, i.e.
``using(this)``. This construct may seem unnecessary, but this is often the
most obvious way of lexing arbitrary syntax between fixed delimiters without
introducing deeply nested states.
The `using()` helper has a special keyword argument, `state`, which works as
follows: if given, the lexer to use initially is not in the ``"root"`` state,
but in the state given by this argument. This does not work with advanced
`RegexLexer` subclasses such as `ExtendedRegexLexer` (see below).
Any other keywords arguments passed to `using()` are added to the keyword
arguments used to create the lexer.
Delegating Lexer
================
Another approach for nested lexers is the `DelegatingLexer` which is for example
used for the template engine lexers. It takes two lexers as arguments on
initialisation: a `root_lexer` and a `language_lexer`.
The input is processed as follows: First, the whole text is lexed with the
`language_lexer`. All tokens yielded with the special type of ``Other`` are
then concatenated and given to the `root_lexer`. The language tokens of the
`language_lexer` are then inserted into the `root_lexer`'s token stream at the
appropriate positions. ::
from pygments.lexer import DelegatingLexer
from pygments.lexers.web import HtmlLexer, PhpLexer
class HtmlPhpLexer(DelegatingLexer):
def __init__(self, **options):
super(HtmlPhpLexer, self).__init__(HtmlLexer, PhpLexer, **options)
This procedure ensures that e.g. HTML with template tags in it is highlighted
correctly even if the template tags are put into HTML tags or attributes.
If you want to change the needle token ``Other`` to something else, you can give
the lexer another token type as the third parameter::
DelegatingLexer.__init__(MyLexer, OtherLexer, Text, **options)
Callbacks
=========
Sometimes the grammar of a language is so complex that a lexer would be unable
to process it just by using regular expressions and stacks.
For this, the `RegexLexer` allows callbacks to be given in rule tuples, instead
of token types (`bygroups` and `using` are nothing else but preimplemented
callbacks). The callback must be a function taking two arguments:
* the lexer itself
* the match object for the last matched rule
The callback must then return an iterable of (or simply yield) ``(index,
tokentype, value)`` tuples, which are then just passed through by
`get_tokens_unprocessed()`. The ``index`` here is the position of the token in
the input string, ``tokentype`` is the normal token type (like `Name.Builtin`),
and ``value`` the associated part of the input string.
You can see an example here::
from pygments.lexer import RegexLexer
from pygments.token import Generic
class HypotheticLexer(RegexLexer):
def headline_callback(lexer, match):
equal_signs = match.group(1)
text = match.group(2)
yield match.start(), Generic.Headline, equal_signs + text + equal_signs
tokens = {
'root': [
(r'(=+)(.*?)(\1)', headline_callback)
]
}
If the regex for the `headline_callback` matches, the function is called with
the match object. Note that after the callback is done, processing continues
normally, that is, after the end of the previous match. The callback has no
possibility to influence the position.
There are not really any simple examples for lexer callbacks, but you can see
them in action e.g. in the `SMLLexer` class in `ml.py`_.
.. _ml.py: http://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/ml.py
The ExtendedRegexLexer class
============================
The `RegexLexer`, even with callbacks, unfortunately isn't powerful enough for
the funky syntax rules of languages such as Ruby.
But fear not; even then you don't have to abandon the regular expression
approach: Pygments has a subclass of `RegexLexer`, the `ExtendedRegexLexer`.
All features known from RegexLexers are available here too, and the tokens are
specified in exactly the same way, *except* for one detail:
The `get_tokens_unprocessed()` method holds its internal state data not as local
variables, but in an instance of the `pygments.lexer.LexerContext` class, and
that instance is passed to callbacks as a third argument. This means that you
can modify the lexer state in callbacks.
The `LexerContext` class has the following members:
* `text` -- the input text
* `pos` -- the current starting position that is used for matching regexes
* `stack` -- a list containing the state stack
* `end` -- the maximum position to which regexes are matched, this defaults to
the length of `text`
Additionally, the `get_tokens_unprocessed()` method can be given a
`LexerContext` instead of a string and will then process this context instead of
creating a new one for the string argument.
Note that because you can set the current position to anything in the callback,
it won't be automatically be set by the caller after the callback is finished.
For example, this is how the hypothetical lexer above would be written with the
`ExtendedRegexLexer`::
from pygments.lexer import ExtendedRegexLexer
from pygments.token import Generic
class ExHypotheticLexer(ExtendedRegexLexer):
def headline_callback(lexer, match, ctx):
equal_signs = match.group(1)
text = match.group(2)
yield match.start(), Generic.Headline, equal_signs + text + equal_signs
ctx.pos = match.end()
tokens = {
'root': [
(r'(=+)(.*?)(\1)', headline_callback)
]
}
This might sound confusing (and it can really be). But it is needed, and for an
example look at the Ruby lexer in `ruby.py`_.
.. _ruby.py: https://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/ruby.py
Handling Lists of Keywords
==========================
For a relatively short list (hundreds) you can construct an optimized regular
expression directly using ``words()`` (longer lists, see next section). This
function handles a few things for you automatically, including escaping
metacharacters and Python's first-match rather than longest-match in
alternations. Feel free to put the lists themselves in
``pygments/lexers/_$lang_builtins.py`` (see examples there), and generated by
code if possible.
An example of using ``words()`` is something like::
from pygments.lexer import RegexLexer, words, Name
class MyLexer(RegexLexer):
tokens = {
'root': [
(words(('else', 'elseif'), suffix=r'\b'), Name.Builtin),
(r'\w+', Name),
],
}
As you can see, you can add ``prefix`` and ``suffix`` parts to the constructed
regex.
Modifying Token Streams
=======================
Some languages ship a lot of builtin functions (for example PHP). The total
amount of those functions differs from system to system because not everybody
has every extension installed. In the case of PHP there are over 3000 builtin
functions. That's an incredibly huge amount of functions, much more than you
want to put into a regular expression.
But because only `Name` tokens can be function names this is solvable by
overriding the ``get_tokens_unprocessed()`` method. The following lexer
subclasses the `PythonLexer` so that it highlights some additional names as
pseudo keywords::
from pygments.lexers.python import PythonLexer
from pygments.token import Name, Keyword
class MyPythonLexer(PythonLexer):
EXTRA_KEYWORDS = set(('foo', 'bar', 'foobar', 'barfoo', 'spam', 'eggs'))
def get_tokens_unprocessed(self, text):
for index, token, value in PythonLexer.get_tokens_unprocessed(self, text):
if token is Name and value in self.EXTRA_KEYWORDS:
yield index, Keyword.Pseudo, value
else:
yield index, token, value
The `PhpLexer` and `LuaLexer` use this method to resolve builtin functions.

View File

@ -18,35 +18,37 @@ Currently, **all lexers** support these options:
`ensurenl` `ensurenl`
Make sure that the input ends with a newline (default: ``True``). This Make sure that the input ends with a newline (default: ``True``). This
is required for some lexers that consume input linewise. is required for some lexers that consume input linewise.
*New in Pygments 1.3.*
.. versionadded:: 1.3
`tabsize` `tabsize`
If given and greater than 0, expand tabs in the input (default: ``0``). If given and greater than 0, expand tabs in the input (default: ``0``).
`encoding` `encoding`
*New in Pygments 0.6.*
If given, must be an encoding name (such as ``"utf-8"``). This encoding If given, must be an encoding name (such as ``"utf-8"``). This encoding
will be used to convert the input string to Unicode (if it is not already will be used to convert the input string to Unicode (if it is not already
a Unicode string). The default is ``"latin1"``. a Unicode string). The default is ``"guess"``.
If this option is set to ``"guess"``, a simple UTF-8 vs. Latin-1 If this option is set to ``"guess"``, a simple UTF-8 vs. Latin-1
detection is used, if it is set to ``"chardet"``, the detection is used, if it is set to ``"chardet"``, the
`chardet library <http://chardet.feedparser.org/>`__ is used to `chardet library <http://chardet.feedparser.org/>`_ is used to
guess the encoding of the input. guess the encoding of the input.
.. versionadded:: 0.6
The "Short Names" field lists the identifiers that can be used with the The "Short Names" field lists the identifiers that can be used with the
`get_lexer_by_name()` function. `get_lexer_by_name()` function.
These lexers are builtin and can be imported from `pygments.lexers`: These lexers are builtin and can be imported from `pygments.lexers`:
[builtin_lexer_docs] .. pygmentsdoc:: lexers
Iterating over all lexers Iterating over all lexers
------------------------- -------------------------
*New in Pygments 0.6.* .. versionadded:: 0.6
To get all lexers (both the builtin and the plugin ones), you can To get all lexers (both the builtin and the plugin ones), you can
use the `get_all_lexers()` function from the `pygments.lexers` use the `get_all_lexers()` function from the `pygments.lexers`

View File

@ -58,8 +58,8 @@ can be produced by:
print HtmlFormatter().get_style_defs('.highlight') print HtmlFormatter().get_style_defs('.highlight')
The argument to `get_style_defs` is used as an additional CSS selector: the output The argument to :func:`get_style_defs` is used as an additional CSS selector:
may look like this: the output may look like this:
.. sourcecode:: css .. sourcecode:: css
@ -71,9 +71,9 @@ may look like this:
Options Options
======= =======
The `highlight()` function supports a fourth argument called `outfile`, it must be The :func:`highlight()` function supports a fourth argument called *outfile*, it
a file object if given. The formatted output will then be written to this file must be a file object if given. The formatted output will then be written to
instead of being returned as a string. this file instead of being returned as a string.
Lexers and formatters both support options. They are given to them as keyword Lexers and formatters both support options. They are given to them as keyword
arguments either to the class or to the lookup method: arguments either to the class or to the lookup method:
@ -103,9 +103,9 @@ Important options include:
For an overview of builtin lexers and formatters and their options, visit the For an overview of builtin lexers and formatters and their options, visit the
`lexer <lexers.txt>`_ and `formatters <formatters.txt>`_ lists. :doc:`lexer <lexers>` and :doc:`formatters <formatters>` lists.
For a documentation on filters, see `this page <filters.txt>`_. For a documentation on filters, see :doc:`this page <filters>`.
Lexer and formatter lookup Lexer and formatter lookup
@ -131,9 +131,9 @@ one of the following methods:
All these functions accept keyword arguments; they will be passed to the lexer All these functions accept keyword arguments; they will be passed to the lexer
as options. as options.
A similar API is available for formatters: use `get_formatter_by_name()` and A similar API is available for formatters: use :func:`.get_formatter_by_name()`
`get_formatter_for_filename()` from the `pygments.formatters` module and :func:`.get_formatter_for_filename()` from the :mod:`pygments.formatters`
for this purpose. module for this purpose.
Guessing lexers Guessing lexers
@ -153,16 +153,17 @@ or some template tags), use these functions:
>>> guess_lexer_for_filename('test.py', 'print "Hello World!"') >>> guess_lexer_for_filename('test.py', 'print "Hello World!"')
<pygments.lexers.PythonLexer> <pygments.lexers.PythonLexer>
`guess_lexer()` passes the given content to the lexer classes' `analyse_text()` :func:`.guess_lexer()` passes the given content to the lexer classes'
method and returns the one for which it returns the highest number. :meth:`analyse_text()` method and returns the one for which it returns the
highest number.
All lexers have two different filename pattern lists: the primary and the All lexers have two different filename pattern lists: the primary and the
secondary one. The `get_lexer_for_filename()` function only uses the primary secondary one. The :func:`.get_lexer_for_filename()` function only uses the
list, whose entries are supposed to be unique among all lexers. primary list, whose entries are supposed to be unique among all lexers.
`guess_lexer_for_filename()`, however, will first loop through all lexers and :func:`.guess_lexer_for_filename()`, however, will first loop through all lexers
look at the primary and secondary filename patterns if the filename matches. and look at the primary and secondary filename patterns if the filename matches.
If only one lexer matches, it is returned, else the guessing mechanism of If only one lexer matches, it is returned, else the guessing mechanism of
`guess_lexer()` is used with the matching lexers. :func:`.guess_lexer()` is used with the matching lexers.
As usual, keyword arguments to these functions are given to the created lexer As usual, keyword arguments to these functions are given to the created lexer
as options. as options.
@ -171,7 +172,8 @@ as options.
Command line usage Command line usage
================== ==================
You can use Pygments from the command line, using the `pygmentize` script:: You can use Pygments from the command line, using the :program:`pygmentize`
script::
$ pygmentize test.py $ pygmentize test.py
@ -199,4 +201,5 @@ it can be created with::
where ``default`` is the style name. where ``default`` is the style name.
More options and tricks and be found in the `command line reference <cmdline.txt>`_. More options and tricks and be found in the :doc:`command line reference
<cmdline>`.

View File

@ -21,6 +21,7 @@ option in form of a string:
.. sourcecode:: pycon .. sourcecode:: pycon
>>> from pygments.styles import get_style_by_name >>> from pygments.styles import get_style_by_name
>>> from pygments.formatters import HtmlFormatter
>>> HtmlFormatter(style='colorful').style >>> HtmlFormatter(style='colorful').style
<class 'pygments.styles.colorful.ColorfulStyle'> <class 'pygments.styles.colorful.ColorfulStyle'>
@ -30,6 +31,7 @@ Or you can also import your own style (which must be a subclass of
.. sourcecode:: pycon .. sourcecode:: pycon
>>> from yourapp.yourmodule import YourStyle >>> from yourapp.yourmodule import YourStyle
>>> from pygments.formatters import HtmlFormatter
>>> HtmlFormatter(style=YourStyle).style >>> HtmlFormatter(style=YourStyle).style
<class 'yourapp.yourmodule.YourStyle'> <class 'yourapp.yourmodule.YourStyle'>
@ -68,7 +70,7 @@ they can be used for a variety of formatters.)
To make the style usable for Pygments, you must To make the style usable for Pygments, you must
* either register it as a plugin (see `the plugin docs <plugins.txt>`_) * either register it as a plugin (see :doc:`the plugin docs <plugins>`)
* or drop it into the `styles` subpackage of your Pygments distribution one style * or drop it into the `styles` subpackage of your Pygments distribution one style
class per style, where the file name is the style name and the class name is class per style, where the file name is the style name and the class name is
`StylenameClass`. For example, if your style should be called `StylenameClass`. For example, if your style should be called
@ -132,7 +134,7 @@ To get a list of known styles you can use this snippet:
Getting a list of available styles Getting a list of available styles
================================== ==================================
*New in Pygments 0.6.* .. versionadded:: 0.6
Because it could be that a plugin registered a style, there is Because it could be that a plugin registered a style, there is
a way to iterate over all styles: a way to iterate over all styles:

View File

@ -4,7 +4,9 @@
Builtin Tokens Builtin Tokens
============== ==============
Inside the `pygments.token` module, there is a special object called `Token` .. module:: pygments.token
In the :mod:`pygments.token` module, there is a special object called `Token`
that is used to create token types. that is used to create token types.
You can create a new token type by accessing an attribute of `Token`: You can create a new token type by accessing an attribute of `Token`:
@ -30,8 +32,8 @@ As of Pygments 0.7 you can also use the ``in`` operator to perform set tests:
>>> Comment in Comment.Multi >>> Comment in Comment.Multi
False False
This can be useful in `filters`_ and if you write lexers on your own without This can be useful in :doc:`filters <filters>` and if you write lexers on your
using the base lexers. own without using the base lexers.
You can also split a token type into a hierarchy, and get the parent of it: You can also split a token type into a hierarchy, and get the parent of it:
@ -55,7 +57,7 @@ For some tokens aliases are already defined:
>>> String >>> String
Token.Literal.String Token.Literal.String
Inside the `pygments.token` module the following aliases are defined: Inside the :mod:`pygments.token` module the following aliases are defined:
============= ============================ ==================================== ============= ============================ ====================================
`Text` `Token.Text` for any type of text data `Text` `Token.Text` for any type of text data
@ -87,7 +89,7 @@ The `is_token_subtype()` function in the `pygments.token` module can be used to
test if a token type is a subtype of another (such as `Name.Tag` and `Name`). test if a token type is a subtype of another (such as `Name.Tag` and `Name`).
(This is the same as ``Name.Tag in Name``. The overloaded `in` operator was newly (This is the same as ``Name.Tag in Name``. The overloaded `in` operator was newly
introduced in Pygments 0.7, the function still exists for backwards introduced in Pygments 0.7, the function still exists for backwards
compatiblity.) compatibility.)
With Pygments 0.7, it's also possible to convert strings to token types (for example With Pygments 0.7, it's also possible to convert strings to token types (for example
if you want to supply a token from the command line): if you want to supply a token from the command line):
@ -158,7 +160,7 @@ Name Tokens
other languages constants are uppercase by definition (Ruby). other languages constants are uppercase by definition (Ruby).
`Name.Decorator` `Name.Decorator`
Token type for decorators. Decorators are synatic elements in the Python Token type for decorators. Decorators are syntactic elements in the Python
language. Similar syntax elements exist in C# and Java. language. Similar syntax elements exist in C# and Java.
`Name.Entity` `Name.Entity`
@ -251,6 +253,9 @@ Literals
`Number` `Number`
Token type for any number literal. Token type for any number literal.
`Number.Bin`
Token type for binary literals (e.g. ``0b101010``).
`Number.Float` `Number.Float`
Token type for float literals (e.g. ``42.0``). Token type for float literals (e.g. ``42.0``).
@ -280,7 +285,7 @@ Operators
Punctuation Punctuation
=========== ===========
*New in Pygments 0.7.* .. versionadded:: 0.7
`Punctuation` `Punctuation`
For any punctuation which is not an operator (e.g. ``[``, ``(``...) For any punctuation which is not an operator (e.g. ``[``, ``(``...)
@ -292,6 +297,10 @@ Comments
`Comment` `Comment`
Token type for any comment. Token type for any comment.
`Comment.Hashbang`
Token type for hashbang comments (i.e. first lines of files that start with
``#!``).
`Comment.Multiline` `Comment.Multiline`
Token type for multiline comments. Token type for multiline comments.
@ -345,5 +354,3 @@ highlight a programming language but a patch file.
`Generic.Traceback` `Generic.Traceback`
Marks the token value as a part of an error traceback. Marks the token value as a part of an error traceback.
.. _filters: filters.txt

View File

@ -3,15 +3,23 @@ Unicode and Encodings
===================== =====================
Since Pygments 0.6, all lexers use unicode strings internally. Because of that Since Pygments 0.6, all lexers use unicode strings internally. Because of that
you might encounter the occasional `UnicodeDecodeError` if you pass strings with the you might encounter the occasional :exc:`UnicodeDecodeError` if you pass strings
wrong encoding. with the wrong encoding.
Per default all lexers have their input encoding set to `latin1`. Per default all lexers have their input encoding set to `guess`. This means
If you pass a lexer a string object (not unicode), it tries to decode the data that the following encodings are tried:
using this encoding.
You can override the encoding using the `encoding` lexer option. If you have the * UTF-8 (including BOM handling)
`chardet`_ library installed and set the encoding to ``chardet`` if will ananlyse * The locale encoding (i.e. the result of `locale.getpreferredencoding()`)
the text and use the encoding it thinks is the right one automatically: * As a last resort, `latin1`
If you pass a lexer a byte string object (not unicode), it tries to decode the
data using this encoding.
You can override the encoding using the `encoding` or `inencoding` lexer
options. If you have the `chardet`_ library installed and set the encoding to
``chardet`` if will analyse the text and use the encoding it thinks is the
right one automatically:
.. sourcecode:: python .. sourcecode:: python
@ -39,11 +47,12 @@ Unicode string with this encoding before writing it. This is the case for
`sys.stdout`, for example. The other formatters don't have that behavior. `sys.stdout`, for example. The other formatters don't have that behavior.
Another note: If you call Pygments via the command line (`pygmentize`), Another note: If you call Pygments via the command line (`pygmentize`),
encoding is handled differently, see `the command line docs <cmdline.txt>`_. encoding is handled differently, see :doc:`the command line docs <cmdline>`.
*New in Pygments 0.7*: the formatters now also accept an `outencoding` option .. versionadded:: 0.7
which will override the `encoding` option if given. This makes it possible to The formatters now also accept an `outencoding` option which will override
use a single options dict with lexers and formatters, and still have different the `encoding` option if given. This makes it possible to use a single
input and output encodings. options dict with lexers and formatters, and still have different input and
output encodings.
.. _chardet: http://chardet.feedparser.org/ .. _chardet: http://chardet.feedparser.org/

41
vendor/pygments/doc/download.rst vendored Normal file
View File

@ -0,0 +1,41 @@
Download and installation
=========================
The current release is version |version|.
Packaged versions
-----------------
You can download it `from the Python Package Index
<http://pypi.python.org/pypi/Pygments>`_. For installation of packages from
PyPI, we recommend `Pip <http://www.pip-installer.org>`_, which works on all
major platforms.
Under Linux, most distributions include a package for Pygments, usually called
``pygments`` or ``python-pygments``. You can install it with the package
manager as usual.
Development sources
-------------------
We're using the `Mercurial <http://selenic.com/mercurial>`_ version control
system. You can get the development source using this command::
hg clone http://bitbucket.org/birkenfeld/pygments-main pygments
Development takes place at `Bitbucket
<http://bitbucket.org/birkenfeld/pygments-main>`_, you can browse the source
online `here <http://bitbucket.org/birkenfeld/pygments-main/src>`_.
The latest changes in the development source code are listed in the `changelog
<http://bitbucket.org/birkenfeld/pygments-main/src/tip/CHANGES>`_.
.. Documentation
-------------
.. XXX todo
You can download the <a href="/docs/">documentation</a> either as
a bunch of rst files from the Mercurial repository, see above, or
as a tar.gz containing rendered HTML files:</p>
<p><a href="/docs/download/pygmentsdocs.tar.gz">pygmentsdocs.tar.gz</a></p>

139
vendor/pygments/doc/faq.rst vendored Normal file
View File

@ -0,0 +1,139 @@
:orphan:
Pygments FAQ
=============
What is Pygments?
-----------------
Pygments is a syntax highlighting engine written in Python. That means, it will
take source code (or other markup) in a supported language and output a
processed version (in different formats) containing syntax highlighting markup.
Its features include:
* a wide range of common :doc:`languages and markup formats <languages>` is supported
* new languages and formats are added easily
* a number of output formats is available, including:
- HTML
- ANSI sequences (console output)
- LaTeX
- RTF
* it is usable as a command-line tool and as a library
* parsing and formatting is fast
Pygments is licensed under the BSD license.
Where does the name Pygments come from?
---------------------------------------
*Py* of course stands for Python, while *pigments* are used for coloring paint,
and in this case, source code!
What are the system requirements?
---------------------------------
Pygments only needs a standard Python install, version 2.6 or higher or version
3.3 or higher for Python 3. No additional libraries are needed.
How can I use Pygments?
-----------------------
Pygments is usable as a command-line tool as well as a library.
From the command-line, usage looks like this (assuming the pygmentize script is
properly installed)::
pygmentize -f html /path/to/file.py
This will print a HTML-highlighted version of /path/to/file.py to standard output.
For a complete help, please run ``pygmentize -h``.
Usage as a library is thoroughly demonstrated in the Documentation section.
How do I make a new style?
--------------------------
Please see the :doc:`documentation on styles <docs/styles>`.
How can I report a bug or suggest a feature?
--------------------------------------------
Please report bugs and feature wishes in the tracker at Bitbucket.
You can also e-mail the author or use IRC, see the contact details.
I want this support for this language!
--------------------------------------
Instead of waiting for others to include language support, why not write it
yourself? All you have to know is :doc:`outlined in the docs
<docs/lexerdevelopment>`.
Can I use Pygments for programming language processing?
-------------------------------------------------------
The Pygments lexing machinery is quite powerful can be used to build lexers for
basically all languages. However, parsing them is not possible, though some
lexers go some steps in this direction in order to e.g. highlight function names
differently.
Also, error reporting is not the scope of Pygments. It focuses on correctly
highlighting syntactically valid documents, not finding and compensating errors.
Who uses Pygments?
------------------
This is an (incomplete) list of projects and sites known to use the Pygments highlighter.
* `Wikipedia <http://en.wikipedia.org>`_
* `BitBucket <http://bitbucket.org/>`_, a Mercurial and Git hosting site
* `The Sphinx documentation builder <http://sphinx.pocoo.org/>`_, for embedded source examples
* `rst2pdf <http://code.google.com/p/rst2pdf/>`_, a reStructuredText to PDF converter
* `Codecov <http://codecov.io/>`_, a code coverage CI service
* `Trac <http://trac.edgewall.org/>`_, the universal project management tool
* `AsciiDoc <http://www.methods.co.nz/asciidoc/>`_, a text-based documentation generator
* `ActiveState Code <http://code.activestate.com/>`_, the Python Cookbook successor
* `ViewVC <http://viewvc.org/>`_, a web-based version control repository browser
* `BzrFruit <http://repo.or.cz/w/bzrfruit.git>`_, a Bazaar branch viewer
* `QBzr <http://bazaar-vcs.org/QBzr>`_, a cross-platform Qt-based GUI front end for Bazaar
* `Review Board <http://www.review-board.org/>`_, a collaborative code reviewing tool
* `Diamanda <http://code.google.com/p/diamanda/>`_, a Django powered wiki system with support for Pygments
* `Progopedia <http://progopedia.ru/>`_ (`English <http://progopedia.com/>`_),
an encyclopedia of programming languages
* `Bruce <http://r1chardj0n3s.googlepages.com/bruce>`_, a reStructuredText presentation tool
* `PIDA <http://pida.co.uk/>`_, a universal IDE written in Python
* `BPython <http://www.noiseforfree.com/bpython/>`_, a curses-based intelligent Python shell
* `PuDB <http://pypi.python.org/pypi/pudb>`_, a console Python debugger
* `XWiki <http://www.xwiki.org/>`_, a wiki-based development framework in Java, using Jython
* `roux <http://ananelson.com/software/roux/>`_, a script for running R scripts
and creating beautiful output including graphs
* `hurl <http://hurl.it/>`_, a web service for making HTTP requests
* `wxHTMLPygmentizer <http://colinbarnette.net/projects/wxHTMLPygmentizer>`_ is
a GUI utility, used to make code-colorization easier
* `Postmarkup <http://code.google.com/p/postmarkup/>`_, a BBCode to XHTML generator
* `WpPygments <http://blog.mirotin.net/?page_id=49>`_, and `WPygments
<https://github.com/capynet/WPygments>`_, highlighter plugins for WordPress
* `Siafoo <http://siafoo.net>`_, a tool for sharing and storing useful code and programming experience
* `D source <http://www.dsource.org/>`_, a community for the D programming language
* `dpaste.com <http://dpaste.com/>`_, another Django pastebin
* `Django snippets <http://www.djangosnippets.org/>`_, a pastebin for Django code
* `Fayaa <http://www.fayaa.com/code/>`_, a Chinese pastebin
* `Incollo.com <http://incollo.com>`_, a free collaborative debugging tool
* `PasteBox <http://p.boxnet.eu/>`_, a pastebin focused on privacy
* `hilite.me <http://www.hilite.me/>`_, a site to highlight code snippets
* `patx.me <http://patx.me/paste>`_, a pastebin
* `Fluidic <https://github.com/richsmith/fluidic>`_, an experiment in
integrating shells with a GUI
* `pygments.rb <https://github.com/tmm1/pygments.rb>`_, a pygments wrapper for Ruby
* `Clygments <https://github.com/bfontaine/clygments>`_, a pygments wrapper for
Clojure
* `PHPygments <https://github.com/capynet/PHPygments>`_, a pygments wrapper for PHP
If you have a project or web site using Pygments, drop me a line, and I'll add a
link here.

54
vendor/pygments/doc/index.rst vendored Normal file
View File

@ -0,0 +1,54 @@
Welcome!
========
This is the home of Pygments. It is a generic syntax highlighter suitable for
use in code hosting, forums, wikis or other applications that need to prettify
source code. Highlights are:
* a wide range of over 300 languages and other text formats is supported
* special attention is paid to details that increase highlighting quality
* support for new languages and formats are added easily; most languages use a
simple regex-based lexing mechanism
* a number of output formats is available, among them HTML, RTF, LaTeX and ANSI
sequences
* it is usable as a command-line tool and as a library
* ... and it highlights even Perl 6!
Read more in the :doc:`FAQ list <faq>` or the :doc:`documentation <docs/index>`,
or `download the latest release <http://pypi.python.org/pypi/Pygments>`_.
.. _contribute:
Contribute
----------
Like every open-source project, we are always looking for volunteers to help us
with programming. Python knowledge is required, but don't fear: Python is a very
clear and easy to learn language.
Development takes place on `Bitbucket
<https://bitbucket.org/birkenfeld/pygments-main>`_, where the Mercurial
repository, tickets and pull requests can be viewed.
Our primary communication instrument is the IRC channel **#pocoo** on the
Freenode network. To join it, let your IRC client connect to
``irc.freenode.net`` and do ``/join #pocoo``.
If you found a bug, just open a ticket in the Bitbucket tracker. Be sure to log
in to be notified when the issue is fixed -- development is not fast-paced as
the library is quite stable. You can also send an e-mail to the developers, see
below.
The authors
-----------
Pygments is maintained by **Georg Brandl**, e-mail address *georg*\ *@*\ *python.org*.
Many lexers and fixes have been contributed by **Armin Ronacher**, the rest of
the `Pocoo <http://dev.pocoo.org/>`_ team and **Tim Hatch**.
.. toctree::
:maxdepth: 1
:hidden:
docs/index

152
vendor/pygments/doc/languages.rst vendored Normal file
View File

@ -0,0 +1,152 @@
:orphan:
Supported languages
===================
Pygments supports an ever-growing range of languages. Watch this space...
Programming languages
---------------------
* ActionScript
* Ada
* ANTLR
* AppleScript
* Assembly (various)
* Asymptote
* Awk
* Befunge
* Boo
* BrainFuck
* C, C++
* C#
* Clojure
* CoffeeScript
* ColdFusion
* Common Lisp
* Coq
* Cryptol (incl. Literate Cryptol)
* `Cython <http://cython.org>`_
* `D <http://dlang.org>`_
* Dart
* Delphi
* Dylan
* Erlang
* `Ezhil <http://ezhillang.org>`_ Ezhil - A Tamil programming language
* Factor
* Fancy
* Fortran
* F#
* GAP
* Gherkin (Cucumber)
* GL shaders
* Groovy
* `Haskell <http://www.haskell.org>`_ (incl. Literate Haskell)
* IDL
* Io
* Java
* JavaScript
* Lasso
* LLVM
* Logtalk
* `Lua <http://www.lua.org>`_
* Matlab
* MiniD
* Modelica
* Modula-2
* MuPad
* Nemerle
* Nimrod
* Objective-C
* Objective-J
* Octave
* OCaml
* PHP
* `Perl <http://perl.org>`_
* PovRay
* PostScript
* PowerShell
* Prolog
* `Python <http://www.python.org>`_ 2.x and 3.x (incl. console sessions and tracebacks)
* `REBOL <http://www.rebol.com>`_
* `Red <http://www.red-lang.org>`_
* Redcode
* `Ruby <http://www.ruby-lang.org>`_ (incl. irb sessions)
* Rust
* S, S-Plus, R
* Scala
* Scheme
* Scilab
* Smalltalk
* SNOBOL
* Tcl
* Vala
* Verilog
* VHDL
* Visual Basic.NET
* Visual FoxPro
* XQuery
* Zephir
Template languages
------------------
* Cheetah templates
* `Django <http://www.djangoproject.com>`_ / `Jinja
<http://jinja.pocoo.org/jinja>`_ templates
* ERB (Ruby templating)
* `Genshi <http://genshi.edgewall.org>`_ (the Trac template language)
* JSP (Java Server Pages)
* `Myghty <http://www.myghty.org>`_ (the HTML::Mason based framework)
* `Mako <http://www.makotemplates.org>`_ (the Myghty successor)
* `Smarty <http://www.smarty.net>`_ templates (PHP templating)
* Tea
Other markup
------------
* Apache config files
* Bash shell scripts
* BBCode
* CMake
* CSS
* Debian control files
* Diff files
* DTD
* Gettext catalogs
* Gnuplot script
* Groff markup
* HTML
* HTTP sessions
* INI-style config files
* IRC logs (irssi style)
* Lighttpd config files
* Makefiles
* MoinMoin/Trac Wiki markup
* MySQL
* Nginx config files
* POV-Ray scenes
* Ragel
* Redcode
* ReST
* Robot Framework
* RPM spec files
* SQL, also MySQL, SQLite
* Squid configuration
* TeX
* tcsh
* Vim Script
* Windows batch files
* XML
* XSLT
* YAML
... that's all?
---------------
Well, why not write your own? Contributing to Pygments is easy and fun. Take a look at the
:doc:`docs on lexer development <docs/lexerdevelopment>` and
:ref:`contact details <contribute>`.
Note: the languages listed here are supported in the development version. The
latest release may lack a few of them.

190
vendor/pygments/doc/make.bat vendored Normal file
View File

@ -0,0 +1,190 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Pygments.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Pygments.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
:end

View File

@ -1,458 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>The full Pygments API &mdash; 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">The full Pygments API</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#high-level-api">High-level API</a></li>
<li><a href="#lexers">Lexers</a></li>
<li><a href="#formatters">Formatters</a></li>
<li><a href="#option-processing">Option processing</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>This page describes the Pygments API.</p>
<div class="section" id="high-level-api">
<h3>High-level API</h3>
<p>Functions from the <cite>pygments</cite> module:</p>
<dl class="docutils">
<dt>def <cite>lex(code, lexer):</cite></dt>
<dd>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>.</dd>
<dt>def <cite>format(tokens, formatter, outfile=None):</cite></dt>
<dd>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 <tt class="docutils literal">None</tt>, returned as a
string.</dd>
<dt>def <cite>highlight(code, lexer, formatter, outfile=None):</cite></dt>
<dd>This is the most high-level highlighting function.
It combines <cite>lex</cite> and <cite>format</cite> in one function.</dd>
</dl>
<p>Functions from <cite>pygments.lexers</cite>:</p>
<dl class="docutils">
<dt>def <cite>get_lexer_by_name(alias, **options):</cite></dt>
<dd><p class="first">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 class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if no lexer with that alias is
found.</p>
</dd>
<dt>def <cite>get_lexer_for_filename(fn, **options):</cite></dt>
<dd><p class="first">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 class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if no lexer for that filename is
found.</p>
</dd>
<dt>def <cite>get_lexer_for_mimetype(mime, **options):</cite></dt>
<dd><p class="first">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 class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if not lexer for that mimetype is
found.</p>
</dd>
<dt>def <cite>guess_lexer(text, **options):</cite></dt>
<dd><p class="first">Return a <cite>Lexer</cite> subclass instance that's guessed from the text
in <cite>text</cite>. For that, the <cite>analyse_text()</cite> 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 class="last"><cite>pygments.util.ClassNotFound</cite> is raised if no lexer thinks it can handle the
content.</p>
</dd>
<dt>def <cite>guess_lexer_for_filename(filename, text, **options):</cite></dt>
<dd><p class="first">As <cite>guess_lexer()</cite>, 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 class="last"><cite>pygments.util.ClassNotFound</cite> is raised if no lexer thinks it can handle the
content.</p>
</dd>
<dt>def <cite>get_all_lexers():</cite></dt>
<dd><p class="first">Return an iterable over all registered lexers, yielding tuples in the
format:</p>
<pre class="literal-block">
(longname, tuple of aliases, tuple of filename patterns, tuple of mimetypes)
</pre>
<p class="last"><em>New in Pygments 0.6.</em></p>
</dd>
</dl>
<p>Functions from <cite>pygments.formatters</cite>:</p>
<dl class="docutils">
<dt>def <cite>get_formatter_by_name(alias, **options):</cite></dt>
<dd><p class="first">Return an instance of a <cite>Formatter</cite> subclass that has <cite>alias</cite> in its
aliases list. The formatter is given the <cite>options</cite> at its
instantiation.</p>
<p class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if no formatter with that alias is
found.</p>
</dd>
<dt>def <cite>get_formatter_for_filename(fn, **options):</cite></dt>
<dd><p class="first">Return a <cite>Formatter</cite> subclass instance that has a filename pattern
matching <cite>fn</cite>. The formatter is given the <cite>options</cite> at its
instantiation.</p>
<p class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if no formatter for that filename
is found.</p>
</dd>
</dl>
<p>Functions from <cite>pygments.styles</cite>:</p>
<dl class="docutils">
<dt>def <cite>get_style_by_name(name):</cite></dt>
<dd><p class="first">Return a style class by its short name. The names of the builtin styles
are listed in <cite>pygments.styles.STYLE_MAP</cite>.</p>
<p class="last">Will raise <cite>pygments.util.ClassNotFound</cite> if no style of that name is found.</p>
</dd>
<dt>def <cite>get_all_styles():</cite></dt>
<dd><p class="first">Return an iterable over all registered styles, yielding their names.</p>
<p class="last"><em>New in Pygments 0.6.</em></p>
</dd>
</dl>
</div>
<div class="section" id="lexers">
<h3>Lexers</h3>
<p>A lexer (derived from <cite>pygments.lexer.Lexer</cite>) has the following functions:</p>
<dl class="docutils">
<dt>def <cite>__init__(self, **options):</cite></dt>
<dd><p class="first">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="syntax"><pre><span class="k">def</span> <span class="nf">__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="s">&#39;compress&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
<span class="n">Lexer</span><span class="o">.</span><span class="n">__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>
<p class="last">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>
</dd>
<dt>def <cite>get_tokens(self, text):</cite></dt>
<dd><p class="first">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 <tt class="docutils literal">(tokentype, value)</tt> pairs from <cite>text</cite>.</p>
<p class="last">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 <tt class="docutils literal">index</tt> dropped.</p>
</dd>
<dt>def <cite>get_tokens_unprocessed(self, text):</cite></dt>
<dd><p class="first">This method should process the text and return an iterable of
<tt class="docutils literal">(index, tokentype, value)</tt> tuples where <tt class="docutils literal">index</tt> is the starting
position of the token within the input text.</p>
<p class="last">This method must be overridden by subclasses.</p>
</dd>
<dt>def <cite>analyse_text(text):</cite></dt>
<dd>A static method which is called for lexer guessing. It should analyse
the text and return a float in the range from <tt class="docutils literal">0.0</tt> to <tt class="docutils literal">1.0</tt>.
If it returns <tt class="docutils literal">0.0</tt>, the lexer will not be selected as the most
probable one, if it returns <tt class="docutils literal">1.0</tt>, it will be selected immediately.</dd>
</dl>
<p>For a list of known tokens have a look at the <a class="reference external" href="./tokens.html">Tokens</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="docutils">
<dt><cite>name</cite></dt>
<dd>Full name for the lexer, in human-readable form.</dd>
<dt><cite>aliases</cite></dt>
<dd>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>.</dd>
<dt><cite>filenames</cite></dt>
<dd>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.</dd>
<dt><cite>alias_filenames</cite></dt>
<dd>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
<cite>guess_lexer_for_filename()</cite> 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 <tt class="docutils literal"><span class="pre">\*.html</span></tt> in
this list.</dd>
<dt><cite>mimetypes</cite></dt>
<dd>A list of MIME types for content that can be lexed with this
lexer.</dd>
</dl>
</div>
<div class="section" id="formatters">
<h3>Formatters</h3>
<p>A formatter (derived from <cite>pygments.formatter.Formatter</cite>) has the following
functions:</p>
<dl class="docutils">
<dt>def <cite>__init__(self, **options):</cite></dt>
<dd><p class="first">As with lexers, this constructor processes options and then must call
the base class <cite>__init__</cite>.</p>
<p class="last">The <cite>Formatter</cite> 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>
</dd>
<dt>def <cite>get_style_defs(self, arg=''):</cite></dt>
<dd><p class="first">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 class="last">This method is called by the <tt class="docutils literal"><span class="pre">-S</span></tt> <a class="reference external" href="./cmdline.html">command-line option</a>, the <cite>arg</cite>
is then given by the <tt class="docutils literal"><span class="pre">-a</span></tt> option.</p>
</dd>
<dt>def <cite>format(self, tokensource, outfile):</cite></dt>
<dd><p class="first">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 class="last">Formatter options can control how exactly the tokens are converted.</p>
</dd>
</dl>
<p>A formatter must have the following attributes that are used by the
builtin lookup mechanism. (<em>New in Pygments 0.7.</em>)</p>
<dl class="docutils">
<dt><cite>name</cite></dt>
<dd>Full name for the formatter, in human-readable form.</dd>
<dt><cite>aliases</cite></dt>
<dd>A list of short, unique identifiers that can be used to lookup
the formatter from a list, e.g. using <cite>get_formatter_by_name()</cite>.</dd>
<dt><cite>filenames</cite></dt>
<dd>A list of <cite>fnmatch</cite> patterns that match filenames for which this formatter
can produce output. The patterns in this list should be unique among
all formatters.</dd>
</dl>
</div>
<div class="section" id="option-processing">
<h3>Option processing</h3>
<p>The <cite>pygments.util</cite> module has some utility functions usable for option
processing:</p>
<dl class="docutils">
<dt>class <cite>OptionError</cite></dt>
<dd>This exception will be raised by all option processing functions if
the type or value of the argument is not correct.</dd>
<dt>def <cite>get_bool_opt(options, optname, default=None):</cite></dt>
<dd><p class="first">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 class="last">The valid string values for <tt class="docutils literal">True</tt> are <tt class="docutils literal">1</tt>, <tt class="docutils literal">yes</tt>,
<tt class="docutils literal">true</tt> and <tt class="docutils literal">on</tt>, the ones for <tt class="docutils literal">False</tt> are <tt class="docutils literal">0</tt>,
<tt class="docutils literal">no</tt>, <tt class="docutils literal">false</tt> and <tt class="docutils literal">off</tt> (matched case-insensitively).</p>
</dd>
<dt>def <cite>get_int_opt(options, optname, default=None):</cite></dt>
<dd>As <cite>get_bool_opt</cite>, but interpret the value as an integer.</dd>
<dt>def <cite>get_list_opt(options, optname, default=None):</cite></dt>
<dd>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.</dd>
<dt>def <cite>get_choice_opt(options, optname, allowed, default=None):</cite></dt>
<dd>If the key <cite>optname</cite> from the dictionary is not in the sequence
<cite>allowed</cite>, raise an error, otherwise return it. <em>New in Pygments 0.8.</em></dd>
</dl>
</div>
</div>
</body>
<!-- generated on: 2013-02-03 10:39:02.580045
file id: api -->
</html>

View File

@ -1,355 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Authors &mdash; 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">Authors</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<p>Pygments is written and maintained by Georg Brandl &lt;<a class="reference external" href="mailto:georg&#64;python.org">georg&#64;python.org</a>&gt;.</p>
<p>Major developers are Tim Hatch &lt;<a class="reference external" href="mailto:tim&#64;timhatch.com">tim&#64;timhatch.com</a>&gt; and Armin Ronacher
&lt;<a class="reference external" href="mailto:armin.ronacher&#64;active-4.com">armin.ronacher&#64;active-4.com</a>&gt;.</p>
<p>Other contributors, listed alphabetically, are:</p>
<ul class="simple">
<li>Sam Aaron -- Ioke lexer</li>
<li>Kumar Appaiah -- Debian control lexer</li>
<li>Ali Afshar -- image formatter</li>
<li>Andreas Amann -- AppleScript lexer</li>
<li>Jeffrey Arnold -- R/S, Rd, BUGS, Jags, and Stan lexers</li>
<li>Jeremy Ashkenas -- CoffeeScript lexer</li>
<li>Stefan Matthias Aust -- Smalltalk lexer</li>
<li>Ben Bangert -- Mako lexers</li>
<li>Max Battcher -- Darcs patch lexer</li>
<li>Paul Baumgart, 280 North, Inc. -- Objective-J lexer</li>
<li>Michael Bayer -- Myghty lexers</li>
<li>John Benediktsson -- Factor lexer</li>
<li>Christopher Bertels -- Fancy lexer</li>
<li>Jarrett Billingsley -- MiniD lexer</li>
<li>Adam Blinkinsop -- Haskell, Redcode lexers</li>
<li>Frits van Bommel -- assembler lexers</li>
<li>Pierre Bourdon -- bugfixes</li>
<li>Hiram Chirino -- Scaml and Jade lexers</li>
<li>Ian Cooper -- VGL lexer</li>
<li>Leaf Corcoran -- MoonScript lexer</li>
<li>Christopher Creutzig -- MuPAD lexer</li>
<li>Pete Curry -- bugfixes</li>
<li>Owen Durni -- haXe lexer</li>
<li>Nick Efford -- Python 3 lexer</li>
<li>Sven Efftinge -- Xtend lexer</li>
<li>Artem Egorkine -- terminal256 formatter</li>
<li>James H. Fisher -- PostScript lexer</li>
<li>Carlos Galdino -- Elixir and Elixir Console lexers</li>
<li>Michael Galloy -- IDL lexer</li>
<li>Naveen Garg -- Autohotkey lexer</li>
<li>Laurent Gautier -- R/S lexer</li>
<li>Alex Gaynor -- PyPy log lexer</li>
<li>Alain Gilbert -- TypeScript lexer</li>
<li>Bertrand Goetzmann -- Groovy lexer</li>
<li>Krzysiek Goj -- Scala lexer</li>
<li>Matt Good -- Genshi, Cheetah lexers</li>
<li>Patrick Gotthardt -- PHP namespaces support</li>
<li>Olivier Guibe -- Asymptote lexer</li>
<li>Jordi Gutiérrez Hermoso -- Octave lexer</li>
<li>Martin Harriman -- SNOBOL lexer</li>
<li>Matthew Harrison -- SVG formatter</li>
<li>Steven Hazel -- Tcl lexer</li>
<li>Aslak Hellesøy -- Gherkin lexer</li>
<li>Greg Hendershott -- Racket lexer</li>
<li>David Hess, Fish Software, Inc. -- Objective-J lexer</li>
<li>Varun Hiremath -- Debian control lexer</li>
<li>Doug Hogan -- Mscgen lexer</li>
<li>Ben Hollis -- Mason lexer</li>
<li>Alastair Houghton -- Lexer inheritance facility</li>
<li>Tim Howard -- BlitzMax lexer</li>
<li>Ivan Inozemtsev -- Fantom lexer</li>
<li>Brian R. Jackson -- Tea lexer</li>
<li>Dennis Kaarsemaker -- sources.list lexer</li>
<li>Igor Kalnitsky -- vhdl lexer</li>
<li>Pekka Klärck -- Robot Framework lexer</li>
<li>Eric Knibbe -- Lasso lexer</li>
<li>Adam Koprowski -- Opa lexer</li>
<li>Benjamin Kowarsch -- Modula-2 lexer</li>
<li>Alexander Kriegisch -- Kconfig and AspectJ lexers</li>
<li>Marek Kubica -- Scheme lexer</li>
<li>Jochen Kupperschmidt -- Markdown processor</li>
<li>Gerd Kurzbach -- Modelica lexer</li>
<li>Jon Larimer, Google Inc. -- Smali lexer</li>
<li>Olov Lassus -- Dart lexer</li>
<li>Sylvestre Ledru -- Scilab lexer</li>
<li>Mark Lee -- Vala lexer</li>
<li>Ben Mabey -- Gherkin lexer</li>
<li>Angus MacArthur -- QML lexer</li>
<li>Simone Margaritelli -- Hybris lexer</li>
<li>Kirk McDonald -- D lexer</li>
<li>Gordon McGregor -- SystemVerilog lexer</li>
<li>Stephen McKamey -- Duel/JBST lexer</li>
<li>Brian McKenna -- F# lexer</li>
<li>Charles McLaughlin -- Puppet lexer</li>
<li>Lukas Meuser -- BBCode formatter, Lua lexer</li>
<li>Paul Miller -- LiveScript lexer</li>
<li>Hong Minhee -- HTTP lexer</li>
<li>Michael Mior -- Awk lexer</li>
<li>Bruce Mitchener -- Dylan lexer rewrite</li>
<li>Reuben Morais -- SourcePawn lexer</li>
<li>Jon Morton -- Rust lexer</li>
<li>Paulo Moura -- Logtalk lexer</li>
<li>Mher Movsisyan -- DTD lexer</li>
<li>Ana Nelson -- Ragel, ANTLR, R console lexers</li>
<li>Nam T. Nguyen -- Monokai style</li>
<li>Jesper Noehr -- HTML formatter &quot;anchorlinenos&quot;</li>
<li>Mike Nolta -- Julia lexer</li>
<li>Jonas Obrist -- BBCode lexer</li>
<li>David Oliva -- Rebol lexer</li>
<li>Jon Parise -- Protocol buffers lexer</li>
<li>Ronny Pfannschmidt -- BBCode lexer</li>
<li>Benjamin Peterson -- Test suite refactoring</li>
<li>Dominik Picheta -- Nimrod lexer</li>
<li>Clément Prévost -- UrbiScript lexer</li>
<li>Kashif Rasul -- CUDA lexer</li>
<li>Justin Reidy -- MXML lexer</li>
<li>Norman Richards -- JSON lexer</li>
<li>Lubomir Rintel -- GoodData MAQL and CL lexers</li>
<li>Andre Roberge -- Tango style</li>
<li>Konrad Rudolph -- LaTeX formatter enhancements</li>
<li>Mario Ruggier -- Evoque lexers</li>
<li>Stou Sandalski -- NumPy, FORTRAN, tcsh and XSLT lexers</li>
<li>Matteo Sasso -- Common Lisp lexer</li>
<li>Joe Schafer -- Ada lexer</li>
<li>Ken Schutte -- Matlab lexers</li>
<li>Tassilo Schweyer -- Io, MOOCode lexers</li>
<li>Ted Shaw -- AutoIt lexer</li>
<li>Joerg Sieker -- ABAP lexer</li>
<li>Robert Simmons -- Standard ML lexer</li>
<li>Kirill Simonov -- YAML lexer</li>
<li>Alexander Smishlajev -- Visual FoxPro lexer</li>
<li>Steve Spigarelli -- XQuery lexer</li>
<li>Jerome St-Louis -- eC lexer</li>
<li>James Strachan -- Kotlin lexer</li>
<li>Tom Stuart -- Treetop lexer</li>
<li>Tiberius Teng -- default style overhaul</li>
<li>Jeremy Thurgood -- Erlang, Squid config lexers</li>
<li>Brian Tiffin -- OpenCOBOL lexer</li>
<li>Erick Tryzelaar -- Felix lexer</li>
<li>Daniele Varrazzo -- PostgreSQL lexers</li>
<li>Abe Voelker -- OpenEdge ABL lexer</li>
<li>Pepijn de Vos -- HTML formatter CTags support</li>
<li>Whitney Young -- ObjectiveC lexer</li>
<li>Matthias Vallentin -- Bro lexer</li>
<li>Nathan Weizenbaum -- Haml and Sass lexers</li>
<li>Dietmar Winkler -- Modelica lexer</li>
<li>Nils Winter -- Smalltalk lexer</li>
<li>Davy Wybiral -- Clojure lexer</li>
<li>Diego Zamboni -- CFengine3 lexer</li>
<li>Enrique Zamudio -- Ceylon lexer</li>
<li>Alex Zimin -- Nemerle lexer</li>
</ul>
<p>Many thanks for all contributions!</p>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.283022
file id: authors -->
</html>

View File

@ -1,930 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Changelog &mdash; 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">Changelog</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#version-1-6rc1">Version 1.6rc1</a></li>
<li><a href="#version-1-5">Version 1.5</a></li>
<li><a href="#version-1-4">Version 1.4</a></li>
<li><a href="#version-1-3-1">Version 1.3.1</a></li>
<li><a href="#version-1-3">Version 1.3</a></li>
<li><a href="#version-1-2-2">Version 1.2.2</a></li>
<li><a href="#version-1-2-1">Version 1.2.1</a></li>
<li><a href="#version-1-2">Version 1.2</a></li>
<li><a href="#version-1-1-1">Version 1.1.1</a></li>
<li><a href="#version-1-1">Version 1.1</a></li>
<li><a href="#version-1-0">Version 1.0</a></li>
<li><a href="#version-0-11-1">Version 0.11.1</a></li>
<li><a href="#version-0-11">Version 0.11</a></li>
<li><a href="#version-0-10">Version 0.10</a></li>
<li><a href="#version-0-9">Version 0.9</a></li>
<li><a href="#version-0-8-1">Version 0.8.1</a></li>
<li><a href="#version-0-8">Version 0.8</a></li>
<li><a href="#version-0-7-1">Version 0.7.1</a></li>
<li><a href="#version-0-7">Version 0.7</a></li>
<li><a href="#version-0-6">Version 0.6</a></li>
<li><a href="#version-0-5-1">Version 0.5.1</a></li>
<li><a href="#version-0-5">Version 0.5</a></li>
</ul>
</div>
<p>Issue numbers refer to the tracker at
&lt;<a class="reference external" href="http://bitbucket.org/birkenfeld/pygments-main/issues">http://bitbucket.org/birkenfeld/pygments-main/issues</a>&gt;,
pull request numbers to the requests at
&lt;<a class="reference external" href="http://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged">http://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged</a>&gt;.</p>
<div class="section" id="version-1-6rc1">
<h3>Version 1.6rc1</h3>
<p>(released Jan 9, 2013)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>AspectJ (PR#90)</li>
<li>AutoIt (PR#122)</li>
<li>BUGS-like languages (PR#89)</li>
<li>Ceylon (PR#86)</li>
<li>Croc (new name for MiniD)</li>
<li>CUDA (PR#75)</li>
<li>Dg (PR#116)</li>
<li>IDL (PR#115)</li>
<li>Jags (PR#89)</li>
<li>Julia (PR#61)</li>
<li>Kconfig (#711)</li>
<li>Lasso (PR#95, PR#113)</li>
<li>LiveScript (PR#84)</li>
<li>Monkey (PR#117)</li>
<li>Mscgen (PR#80)</li>
<li>NSIS scripts (PR#136)</li>
<li>OpenCOBOL (PR#72)</li>
<li>QML (PR#123)</li>
<li>Puppet (PR#133)</li>
<li>Racket (PR#94)</li>
<li>Rdoc (PR#99)</li>
<li>Robot Framework (PR#137)</li>
<li>RPM spec files (PR#124)</li>
<li>Rust (PR#67)</li>
<li>Smali (Dalvik assembly)</li>
<li>SourcePawn (PR#39)</li>
<li>Stan (PR#89)</li>
<li>Treetop (PR#125)</li>
<li>TypeScript (PR#114)</li>
<li>VGL (PR#12)</li>
<li>Visual FoxPro (#762)</li>
<li>Windows Registry (#819)</li>
<li>Xtend (PR#68)</li>
</ul>
</li>
<li>The HTML formatter now supports linking to tags using CTags files, when the
python-ctags package is installed (PR#87).</li>
<li>The HTML formatter now has a &quot;linespans&quot; option that wraps every line in a
&lt;span&gt; tag with a specific id (PR#82).</li>
<li>When deriving a lexer from another lexer with token definitions, definitions
for states not in the child lexer are now inherited. If you override a state
in the child lexer, an &quot;inherit&quot; keyword has been added to insert the base
state at that position (PR#141).</li>
<li>The C family lexers now inherit token definitions from a common base class,
removing code duplication (PR#141).</li>
<li>Use &quot;colorama&quot; on Windows for console color output (PR#142).</li>
<li>Fix Template Haskell highlighting (PR#63).</li>
<li>Fix some S/R lexer errors (PR#91).</li>
<li>Fix a bug in the Prolog lexer with names that start with 'is' (#810).</li>
<li>Rewrite Dylan lexer, add Dylan LID lexer (PR#147).</li>
<li>Add a Java quickstart document (PR#146).</li>
<li>Add a &quot;external/autopygmentize&quot; file that can be used as .lessfilter (#802).</li>
</ul>
</div>
<div class="section" id="version-1-5">
<h3>Version 1.5</h3>
<p>(codename Zeitdilatation, released Mar 10, 2012)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Awk (#630)</li>
<li>Fancy (#633)</li>
<li>PyPy Log</li>
<li>eC</li>
<li>Nimrod</li>
<li>Nemerle (#667)</li>
<li>F# (#353)</li>
<li>Groovy (#501)</li>
<li>PostgreSQL (#660)</li>
<li>DTD</li>
<li>Gosu (#634)</li>
<li>Octave (PR#22)</li>
<li>Standard ML (PR#14)</li>
<li>CFengine3 (#601)</li>
<li>Opa (PR#37)</li>
<li>HTTP sessions (PR#42)</li>
<li>JSON (PR#31)</li>
<li>SNOBOL (PR#30)</li>
<li>MoonScript (PR#43)</li>
<li>ECL (PR#29)</li>
<li>Urbiscript (PR#17)</li>
<li>OpenEdge ABL (PR#27)</li>
<li>SystemVerilog (PR#35)</li>
<li>Coq (#734)</li>
<li>PowerShell (#654)</li>
<li>Dart (#715)</li>
<li>Fantom (PR#36)</li>
<li>Bro (PR#5)</li>
<li>NewLISP (PR#26)</li>
<li>VHDL (PR#45)</li>
<li>Scilab (#740)</li>
<li>Elixir (PR#57)</li>
<li>Tea (PR#56)</li>
<li>Kotlin (PR#58)</li>
</ul>
</li>
<li>Fix Python 3 terminal highlighting with pygmentize (#691).</li>
<li>In the LaTeX formatter, escape special &amp;, &lt; and &gt; chars (#648).</li>
<li>In the LaTeX formatter, fix display problems for styles with token
background colors (#670).</li>
<li>Enhancements to the Squid conf lexer (#664).</li>
<li>Several fixes to the reStructuredText lexer (#636).</li>
<li>Recognize methods in the ObjC lexer (#638).</li>
<li>Fix Lua &quot;class&quot; highlighting: it does not have classes (#665).</li>
<li>Fix degenerate regex in Scala lexer (#671) and highlighting bugs (#713, 708).</li>
<li>Fix number pattern order in Ocaml lexer (#647).</li>
<li>Fix generic type highlighting in ActionScript 3 (#666).</li>
<li>Fixes to the Clojure lexer (PR#9).</li>
<li>Fix degenerate regex in Nemerle lexer (#706).</li>
<li>Fix infinite looping in CoffeeScript lexer (#729).</li>
<li>Fix crashes and analysis with ObjectiveC lexer (#693, #696).</li>
<li>Add some Fortran 2003 keywords.</li>
<li>Fix Boo string regexes (#679).</li>
<li>Add &quot;rrt&quot; style (#727).</li>
<li>Fix infinite looping in Darcs Patch lexer.</li>
<li>Lots of misc fixes to character-eating bugs and ordering problems in many
different lexers.</li>
</ul>
</div>
<div class="section" id="version-1-4">
<h3>Version 1.4</h3>
<p>(codename Unschärfe, released Jan 03, 2011)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Factor (#520)</li>
<li>PostScript (#486)</li>
<li>Verilog (#491)</li>
<li>BlitzMax Basic (#478)</li>
<li>Ioke (#465)</li>
<li>Java properties, split out of the INI lexer (#445)</li>
<li>Scss (#509)</li>
<li>Duel/JBST</li>
<li>XQuery (#617)</li>
<li>Mason (#615)</li>
<li>GoodData (#609)</li>
<li>SSP (#473)</li>
<li>Autohotkey (#417)</li>
<li>Google Protocol Buffers</li>
<li>Hybris (#506)</li>
</ul>
</li>
<li>Do not fail in analyse_text methods (#618).</li>
<li>Performance improvements in the HTML formatter (#523).</li>
<li>With the <tt class="docutils literal">noclasses</tt> option in the HTML formatter, some styles
present in the stylesheet were not added as inline styles.</li>
<li>Four fixes to the Lua lexer (#480, #481, #482, #497).</li>
<li>More context-sensitive Gherkin lexer with support for more i18n translations.</li>
<li>Support new OO keywords in Matlab lexer (#521).</li>
<li>Small fix in the CoffeeScript lexer (#519).</li>
<li>A bugfix for backslashes in ocaml strings (#499).</li>
<li>Fix unicode/raw docstrings in the Python lexer (#489).</li>
<li>Allow PIL to work without PIL.pth (#502).</li>
<li>Allow seconds as a unit in CSS (#496).</li>
<li>Support <tt class="docutils literal">application/javascript</tt> as a JavaScript mime type (#504).</li>
<li>Support <a class="reference external" href="http://offload.codeplay.com">Offload</a> C++ Extensions as
keywords in the C++ lexer (#484).</li>
<li>Escape more characters in LaTeX output (#505).</li>
<li>Update Haml/Sass lexers to version 3 (#509).</li>
<li>Small PHP lexer string escaping fix (#515).</li>
<li>Support comments before preprocessor directives, and unsigned/
long long literals in C/C++ (#613, #616).</li>
<li>Support line continuations in the INI lexer (#494).</li>
<li>Fix lexing of Dylan string and char literals (#628).</li>
<li>Fix class/procedure name highlighting in VB.NET lexer (#624).</li>
</ul>
</div>
<div class="section" id="version-1-3-1">
<h3>Version 1.3.1</h3>
<p>(bugfix release, released Mar 05, 2010)</p>
<ul class="simple">
<li>The <tt class="docutils literal">pygmentize</tt> script was missing from the distribution.</li>
</ul>
</div>
<div class="section" id="version-1-3">
<h3>Version 1.3</h3>
<p>(codename Schneeglöckchen, released Mar 01, 2010)</p>
<ul class="simple">
<li>Added the <tt class="docutils literal">ensurenl</tt> lexer option, which can be used to suppress the
automatic addition of a newline to the lexer input.</li>
<li>Lexers added:<ul>
<li>Ada</li>
<li>Coldfusion</li>
<li>Modula-2</li>
<li>haXe</li>
<li>R console</li>
<li>Objective-J</li>
<li>Haml and Sass</li>
<li>CoffeeScript</li>
</ul>
</li>
<li>Enhanced reStructuredText highlighting.</li>
<li>Added support for PHP 5.3 namespaces in the PHP lexer.</li>
<li>Added a bash completion script for <cite>pygmentize</cite>, to the external/
directory (#466).</li>
<li>Fixed a bug in <cite>do_insertions()</cite> used for multi-lexer languages.</li>
<li>Fixed a Ruby regex highlighting bug (#476).</li>
<li>Fixed regex highlighting bugs in Perl lexer (#258).</li>
<li>Add small enhancements to the C lexer (#467) and Bash lexer (#469).</li>
<li>Small fixes for the Tcl, Debian control file, Nginx config,
Smalltalk, Objective-C, Clojure, Lua lexers.</li>
<li>Gherkin lexer: Fixed single apostrophe bug and added new i18n keywords.</li>
</ul>
</div>
<div class="section" id="version-1-2-2">
<h3>Version 1.2.2</h3>
<p>(bugfix release, released Jan 02, 2010)</p>
<ul class="simple">
<li>Removed a backwards incompatibility in the LaTeX formatter that caused
Sphinx to produce invalid commands when writing LaTeX output (#463).</li>
<li>Fixed a forever-backtracking regex in the BashLexer (#462).</li>
</ul>
</div>
<div class="section" id="version-1-2-1">
<h3>Version 1.2.1</h3>
<p>(bugfix release, released Jan 02, 2010)</p>
<ul class="simple">
<li>Fixed mishandling of an ellipsis in place of the frames in a Python
console traceback, resulting in clobbered output.</li>
</ul>
</div>
<div class="section" id="version-1-2">
<h3>Version 1.2</h3>
<p>(codename Neujahr, released Jan 01, 2010)</p>
<ul class="simple">
<li>Dropped Python 2.3 compatibility.</li>
<li>Lexers added:<ul>
<li>Asymptote</li>
<li>Go</li>
<li>Gherkin (Cucumber)</li>
<li>CMake</li>
<li>Ooc</li>
<li>Coldfusion</li>
<li>haXe</li>
<li>R console</li>
</ul>
</li>
<li>Added options for rendering LaTeX in source code comments in the
LaTeX formatter (#461).</li>
<li>Updated the Logtalk lexer.</li>
<li>Added <cite>line_number_start</cite> option to image formatter (#456).</li>
<li>Added <cite>hl_lines</cite> and <cite>hl_color</cite> options to image formatter (#457).</li>
<li>Fixed the HtmlFormatter's handling of noclasses=True to not output any
classes (#427).</li>
<li>Added the Monokai style (#453).</li>
<li>Fixed LLVM lexer identifier syntax and added new keywords (#442).</li>
<li>Fixed the PythonTracebackLexer to handle non-traceback data in header or
trailer, and support more partial tracebacks that start on line 2 (#437).</li>
<li>Fixed the CLexer to not highlight ternary statements as labels.</li>
<li>Fixed lexing of some Ruby quoting peculiarities (#460).</li>
<li>A few ASM lexer fixes (#450).</li>
</ul>
</div>
<div class="section" id="version-1-1-1">
<h3>Version 1.1.1</h3>
<p>(bugfix release, released Sep 15, 2009)</p>
<ul class="simple">
<li>Fixed the BBCode lexer (#435).</li>
<li>Added support for new Jinja2 keywords.</li>
<li>Fixed test suite failures.</li>
<li>Added Gentoo-specific suffixes to Bash lexer.</li>
</ul>
</div>
<div class="section" id="version-1-1">
<h3>Version 1.1</h3>
<p>(codename Brillouin, released Sep 11, 2009)</p>
<ul class="simple">
<li>Ported Pygments to Python 3. This needed a few changes in the way
encodings are handled; they may affect corner cases when used with
Python 2 as well.</li>
<li>Lexers added:<ul>
<li>Antlr/Ragel, thanks to Ana Nelson</li>
<li>(Ba)sh shell</li>
<li>Erlang shell</li>
<li>GLSL</li>
<li>Prolog</li>
<li>Evoque</li>
<li>Modelica</li>
<li>Rebol</li>
<li>MXML</li>
<li>Cython</li>
<li>ABAP</li>
<li>ASP.net (VB/C#)</li>
<li>Vala</li>
<li>Newspeak</li>
</ul>
</li>
<li>Fixed the LaTeX formatter's output so that output generated for one style
can be used with the style definitions of another (#384).</li>
<li>Added &quot;anchorlinenos&quot; and &quot;noclobber_cssfile&quot; (#396) options to HTML
formatter.</li>
<li>Support multiline strings in Lua lexer.</li>
<li>Rewrite of the JavaScript lexer by Pumbaa80 to better support regular
expression literals (#403).</li>
<li>When pygmentize is asked to highlight a file for which multiple lexers
match the filename, use the analyse_text guessing engine to determine the
winner (#355).</li>
<li>Fixed minor bugs in the JavaScript lexer (#383), the Matlab lexer (#378),
the Scala lexer (#392), the INI lexer (#391), the Clojure lexer (#387)
and the AS3 lexer (#389).</li>
<li>Fixed three Perl heredoc lexing bugs (#379, #400, #422).</li>
<li>Fixed a bug in the image formatter which misdetected lines (#380).</li>
<li>Fixed bugs lexing extended Ruby strings and regexes.</li>
<li>Fixed a bug when lexing git diffs.</li>
<li>Fixed a bug lexing the empty commit in the PHP lexer (#405).</li>
<li>Fixed a bug causing Python numbers to be mishighlighted as floats (#397).</li>
<li>Fixed a bug when backslashes are used in odd locations in Python (#395).</li>
<li>Fixed various bugs in Matlab and S-Plus lexers, thanks to Winston Chang (#410,
#411, #413, #414) and fmarc (#419).</li>
<li>Fixed a bug in Haskell single-line comment detection (#426).</li>
<li>Added new-style reStructuredText directive for docutils 0.5+ (#428).</li>
</ul>
</div>
<div class="section" id="version-1-0">
<h3>Version 1.0</h3>
<p>(codename Dreiundzwanzig, released Nov 23, 2008)</p>
<ul>
<li><p class="first">Don't use join(splitlines()) when converting newlines to <tt class="docutils literal">\n</tt>,
because that doesn't keep all newlines at the end when the
<tt class="docutils literal">stripnl</tt> lexer option is False.</p>
</li>
<li><p class="first">Added <tt class="docutils literal"><span class="pre">-N</span></tt> option to command-line interface to get a lexer name
for a given filename.</p>
</li>
<li><p class="first">Added Tango style, written by Andre Roberge for the Crunchy project.</p>
</li>
<li><p class="first">Added Python3TracebackLexer and <tt class="docutils literal">python3</tt> option to
PythonConsoleLexer.</p>
</li>
<li><p class="first">Fixed a few bugs in the Haskell lexer.</p>
</li>
<li><p class="first">Fixed PythonTracebackLexer to be able to recognize SyntaxError and
KeyboardInterrupt (#360).</p>
</li>
<li><p class="first">Provide one formatter class per image format, so that surprises like:</p>
<pre class="literal-block">
pygmentize -f gif -o foo.gif foo.py
</pre>
<p>creating a PNG file are avoided.</p>
</li>
<li><p class="first">Actually use the <cite>font_size</cite> option of the image formatter.</p>
</li>
<li><p class="first">Fixed numpy lexer that it doesn't listen for <cite>*.py</cite> any longer.</p>
</li>
<li><p class="first">Fixed HTML formatter so that text options can be Unicode
strings (#371).</p>
</li>
<li><p class="first">Unified Diff lexer supports the &quot;udiff&quot; alias now.</p>
</li>
<li><p class="first">Fixed a few issues in Scala lexer (#367).</p>
</li>
<li><p class="first">RubyConsoleLexer now supports simple prompt mode (#363).</p>
</li>
<li><p class="first">JavascriptLexer is smarter about what constitutes a regex (#356).</p>
</li>
<li><p class="first">Add Applescript lexer, thanks to Andreas Amann (#330).</p>
</li>
<li><p class="first">Make the codetags more strict about matching words (#368).</p>
</li>
<li><p class="first">NginxConfLexer is a little more accurate on mimetypes and
variables (#370).</p>
</li>
</ul>
</div>
<div class="section" id="version-0-11-1">
<h3>Version 0.11.1</h3>
<p>(released Aug 24, 2008)</p>
<ul class="simple">
<li>Fixed a Jython compatibility issue in pygments.unistring (#358).</li>
</ul>
</div>
<div class="section" id="version-0-11">
<h3>Version 0.11</h3>
<p>(codename Straußenei, released Aug 23, 2008)</p>
<p>Many thanks go to Tim Hatch for writing or integrating most of the bug
fixes and new features.</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Nasm-style assembly language, thanks to delroth</li>
<li>YAML, thanks to Kirill Simonov</li>
<li>ActionScript 3, thanks to Pierre Bourdon</li>
<li>Cheetah/Spitfire templates, thanks to Matt Good</li>
<li>Lighttpd config files</li>
<li>Nginx config files</li>
<li>Gnuplot plotting scripts</li>
<li>Clojure</li>
<li>POV-Ray scene files</li>
<li>Sqlite3 interactive console sessions</li>
<li>Scala source files, thanks to Krzysiek Goj</li>
</ul>
</li>
<li>Lexers improved:<ul>
<li>C lexer highlights standard library functions now and supports C99
types.</li>
<li>Bash lexer now correctly highlights heredocs without preceding
whitespace.</li>
<li>Vim lexer now highlights hex colors properly and knows a couple
more keywords.</li>
<li>Irc logs lexer now handles xchat's default time format (#340) and
correctly highlights lines ending in <tt class="docutils literal">&gt;</tt>.</li>
<li>Support more delimiters for perl regular expressions (#258).</li>
<li>ObjectiveC lexer now supports 2.0 features.</li>
</ul>
</li>
<li>Added &quot;Visual Studio&quot; style.</li>
<li>Updated markdown processor to Markdown 1.7.</li>
<li>Support roman/sans/mono style defs and use them in the LaTeX
formatter.</li>
<li>The RawTokenFormatter is no longer registered to <tt class="docutils literal">*.raw</tt> and it's
documented that tokenization with this lexer may raise exceptions.</li>
<li>New option <tt class="docutils literal">hl_lines</tt> to HTML formatter, to highlight certain
lines.</li>
<li>New option <tt class="docutils literal">prestyles</tt> to HTML formatter.</li>
<li>New option <em>-g</em> to pygmentize, to allow lexer guessing based on
filetext (can be slowish, so file extensions are still checked
first).</li>
<li><tt class="docutils literal">guess_lexer()</tt> now makes its decision much faster due to a cache
of whether data is xml-like (a check which is used in several
versions of <tt class="docutils literal">analyse_text()</tt>. Several lexers also have more
accurate <tt class="docutils literal">analyse_text()</tt> now.</li>
</ul>
</div>
<div class="section" id="version-0-10">
<h3>Version 0.10</h3>
<p>(codename Malzeug, released May 06, 2008)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Io</li>
<li>Smalltalk</li>
<li>Darcs patches</li>
<li>Tcl</li>
<li>Matlab</li>
<li>Matlab sessions</li>
<li>FORTRAN</li>
<li>XSLT</li>
<li>tcsh</li>
<li>NumPy</li>
<li>Python 3</li>
<li>S, S-plus, R statistics languages</li>
<li>Logtalk</li>
</ul>
</li>
<li>In the LatexFormatter, the <em>commandprefix</em> option is now by default
'PY' instead of 'C', since the latter resulted in several collisions
with other packages. Also, the special meaning of the <em>arg</em>
argument to <tt class="docutils literal">get_style_defs()</tt> was removed.</li>
<li>Added ImageFormatter, to format code as PNG, JPG, GIF or BMP.
(Needs the Python Imaging Library.)</li>
<li>Support doc comments in the PHP lexer.</li>
<li>Handle format specifications in the Perl lexer.</li>
<li>Fix comment handling in the Batch lexer.</li>
<li>Add more file name extensions for the C++, INI and XML lexers.</li>
<li>Fixes in the IRC and MuPad lexers.</li>
<li>Fix function and interface name highlighting in the Java lexer.</li>
<li>Fix at-rule handling in the CSS lexer.</li>
<li>Handle KeyboardInterrupts gracefully in pygmentize.</li>
<li>Added BlackWhiteStyle.</li>
<li>Bash lexer now correctly highlights math, does not require
whitespace after semicolons, and correctly highlights boolean
operators.</li>
<li>Makefile lexer is now capable of handling BSD and GNU make syntax.</li>
</ul>
</div>
<div class="section" id="version-0-9">
<h3>Version 0.9</h3>
<p>(codename Herbstzeitlose, released Oct 14, 2007)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Erlang</li>
<li>ActionScript</li>
<li>Literate Haskell</li>
<li>Common Lisp</li>
<li>Various assembly languages</li>
<li>Gettext catalogs</li>
<li>Squid configuration</li>
<li>Debian control files</li>
<li>MySQL-style SQL</li>
<li>MOOCode</li>
</ul>
</li>
<li>Lexers improved:<ul>
<li>Greatly improved the Haskell and OCaml lexers.</li>
<li>Improved the Bash lexer's handling of nested constructs.</li>
<li>The C# and Java lexers exhibited abysmal performance with some
input code; this should now be fixed.</li>
<li>The IRC logs lexer is now able to colorize weechat logs too.</li>
<li>The Lua lexer now recognizes multi-line comments.</li>
<li>Fixed bugs in the D and MiniD lexer.</li>
</ul>
</li>
<li>The encoding handling of the command line mode (pygmentize) was
enhanced. You shouldn't get UnicodeErrors from it anymore if you
don't give an encoding option.</li>
<li>Added a <tt class="docutils literal"><span class="pre">-P</span></tt> option to the command line mode which can be used to
give options whose values contain commas or equals signs.</li>
<li>Added 256-color terminal formatter.</li>
<li>Added an experimental SVG formatter.</li>
<li>Added the <tt class="docutils literal">lineanchors</tt> option to the HTML formatter, thanks to
Ian Charnas for the idea.</li>
<li>Gave the line numbers table a CSS class in the HTML formatter.</li>
<li>Added a Vim 7-like style.</li>
</ul>
</div>
<div class="section" id="version-0-8-1">
<h3>Version 0.8.1</h3>
<p>(released Jun 27, 2007)</p>
<ul class="simple">
<li>Fixed POD highlighting in the Ruby lexer.</li>
<li>Fixed Unicode class and namespace name highlighting in the C# lexer.</li>
<li>Fixed Unicode string prefix highlighting in the Python lexer.</li>
<li>Fixed a bug in the D and MiniD lexers.</li>
<li>Fixed the included MoinMoin parser.</li>
</ul>
</div>
<div class="section" id="version-0-8">
<h3>Version 0.8</h3>
<p>(codename Maikäfer, released May 30, 2007)</p>
<ul class="simple">
<li>Lexers added:<ul>
<li>Haskell, thanks to Adam Blinkinsop</li>
<li>Redcode, thanks to Adam Blinkinsop</li>
<li>D, thanks to Kirk McDonald</li>
<li>MuPad, thanks to Christopher Creutzig</li>
<li>MiniD, thanks to Jarrett Billingsley</li>
<li>Vim Script, by Tim Hatch</li>
</ul>
</li>
<li>The HTML formatter now has a second line-numbers mode in which it
will just integrate the numbers in the same <tt class="docutils literal">&lt;pre&gt;</tt> tag as the
code.</li>
<li>The <cite>CSharpLexer</cite> now is Unicode-aware, which means that it has an
option that can be set so that it correctly lexes Unicode
identifiers allowed by the C# specs.</li>
<li>Added a <cite>RaiseOnErrorTokenFilter</cite> that raises an exception when the
lexer generates an error token, and a <cite>VisibleWhitespaceFilter</cite> that
converts whitespace (spaces, tabs, newlines) into visible
characters.</li>
<li>Fixed the <cite>do_insertions()</cite> helper function to yield correct
indices.</li>
<li>The ReST lexer now automatically highlights source code blocks in
&quot;.. sourcecode:: language&quot; and &quot;.. code:: language&quot; directive
blocks.</li>
<li>Improved the default style (thanks to Tiberius Teng). The old
default is still available as the &quot;emacs&quot; style (which was an alias
before).</li>
<li>The <cite>get_style_defs</cite> method of HTML formatters now uses the
<cite>cssclass</cite> option as the default selector if it was given.</li>
<li>Improved the ReST and Bash lexers a bit.</li>
<li>Fixed a few bugs in the Makefile and Bash lexers, thanks to Tim
Hatch.</li>
<li>Fixed a bug in the command line code that disallowed <tt class="docutils literal"><span class="pre">-O</span></tt> options
when using the <tt class="docutils literal"><span class="pre">-S</span></tt> option.</li>
<li>Fixed a bug in the <cite>RawTokenFormatter</cite>.</li>
</ul>
</div>
<div class="section" id="version-0-7-1">
<h3>Version 0.7.1</h3>
<p>(released Feb 15, 2007)</p>
<ul class="simple">
<li>Fixed little highlighting bugs in the Python, Java, Scheme and
Apache Config lexers.</li>
<li>Updated the included manpage.</li>
<li>Included a built version of the documentation in the source tarball.</li>
</ul>
</div>
<div class="section" id="version-0-7">
<h3>Version 0.7</h3>
<p>(codename Faschingskrapfn, released Feb 14, 2007)</p>
<ul class="simple">
<li>Added a MoinMoin parser that uses Pygments. With it, you get
Pygments highlighting in Moin Wiki pages.</li>
<li>Changed the exception raised if no suitable lexer, formatter etc. is
found in one of the <cite>get_*_by_*</cite> functions to a custom exception,
<cite>pygments.util.ClassNotFound</cite>. It is, however, a subclass of
<cite>ValueError</cite> in order to retain backwards compatibility.</li>
<li>Added a <cite>-H</cite> command line option which can be used to get the
docstring of a lexer, formatter or filter.</li>
<li>Made the handling of lexers and formatters more consistent. The
aliases and filename patterns of formatters are now attributes on
them.</li>
<li>Added an OCaml lexer, thanks to Adam Blinkinsop.</li>
<li>Made the HTML formatter more flexible, and easily subclassable in
order to make it easy to implement custom wrappers, e.g. alternate
line number markup. See the documentation.</li>
<li>Added an <cite>outencoding</cite> option to all formatters, making it possible
to override the <cite>encoding</cite> (which is used by lexers and formatters)
when using the command line interface. Also, if using the terminal
formatter and the output file is a terminal and has an encoding
attribute, use it if no encoding is given.</li>
<li>Made it possible to just drop style modules into the <cite>styles</cite>
subpackage of the Pygments installation.</li>
<li>Added a &quot;state&quot; keyword argument to the <cite>using</cite> helper.</li>
<li>Added a <cite>commandprefix</cite> option to the <cite>LatexFormatter</cite> which allows
to control how the command names are constructed.</li>
<li>Added quite a few new lexers, thanks to Tim Hatch:<ul>
<li>Java Server Pages</li>
<li>Windows batch files</li>
<li>Trac Wiki markup</li>
<li>Python tracebacks</li>
<li>ReStructuredText</li>
<li>Dylan</li>
<li>and the Befunge esoteric programming language (yay!)</li>
</ul>
</li>
<li>Added Mako lexers by Ben Bangert.</li>
<li>Added &quot;fruity&quot; style, another dark background originally vim-based
theme.</li>
<li>Added sources.list lexer by Dennis Kaarsemaker.</li>
<li>Added token stream filters, and a pygmentize option to use them.</li>
<li>Changed behavior of <cite>in</cite> Operator for tokens.</li>
<li>Added mimetypes for all lexers.</li>
<li>Fixed some problems lexing Python strings.</li>
<li>Fixed tickets: #167, #178, #179, #180, #185, #201.</li>
</ul>
</div>
<div class="section" id="version-0-6">
<h3>Version 0.6</h3>
<p>(codename Zimtstern, released Dec 20, 2006)</p>
<ul class="simple">
<li>Added option for the HTML formatter to write the CSS to an external
file in &quot;full document&quot; mode.</li>
<li>Added RTF formatter.</li>
<li>Added Bash and Apache configuration lexers (thanks to Tim Hatch).</li>
<li>Improved guessing methods for various lexers.</li>
<li>Added <cite>&#64;media</cite> support to CSS lexer (thanks to Tim Hatch).</li>
<li>Added a Groff lexer (thanks to Tim Hatch).</li>
<li>License change to BSD.</li>
<li>Added lexers for the Myghty template language.</li>
<li>Added a Scheme lexer (thanks to Marek Kubica).</li>
<li>Added some functions to iterate over existing lexers, formatters and
lexers.</li>
<li>The HtmlFormatter's <cite>get_style_defs()</cite> can now take a list as an
argument to generate CSS with multiple prefixes.</li>
<li>Support for guessing input encoding added.</li>
<li>Encoding support added: all processing is now done with Unicode
strings, input and output are converted from and optionally to byte
strings (see the <tt class="docutils literal">encoding</tt> option of lexers and formatters).</li>
<li>Some improvements in the C(++) lexers handling comments and line
continuations.</li>
</ul>
</div>
<div class="section" id="version-0-5-1">
<h3>Version 0.5.1</h3>
<p>(released Oct 30, 2006)</p>
<ul class="simple">
<li>Fixed traceback in <tt class="docutils literal">pygmentize <span class="pre">-L</span></tt> (thanks to Piotr Ozarowski).</li>
</ul>
</div>
<div class="section" id="version-0-5">
<h3>Version 0.5</h3>
<p>(codename PyKleur, released Oct 30, 2006)</p>
<ul class="simple">
<li>Initial public release.</li>
</ul>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:44.022954
file id: changelog -->
</html>

View File

@ -1,353 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Command Line Interface &mdash; 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">&laquo; 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 &quot;Hello World&quot;
</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
&quot;emacs&quot; 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 &quot;heading=Pygments, the Python highlighter&quot; ...
</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">&lt;span&gt;</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 &quot;colorful&quot; style prepending a &quot;.syntax&quot; 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>

View File

@ -1,282 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Write your own filter &mdash; 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">Write your own filter</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#subclassing-filters">Subclassing Filters</a></li>
<li><a href="#using-a-decorator">Using a decorator</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p><em>New in Pygments 0.7.</em></p>
<p>Writing own filters is very easy. All you have to do is to subclass
the <cite>Filter</cite> class and override the <cite>filter</cite> method. Additionally a
filter is instanciated with some keyword arguments you can use to
adjust the behavior of your filter.</p>
<div class="section" id="subclassing-filters">
<h3>Subclassing Filters</h3>
<p>As an example, we write a filter that converts all <cite>Name.Function</cite> tokens
to normal <cite>Name</cite> tokens to make the output less colorful.</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.util</span> <span class="kn">import</span> <span class="n">get_bool_opt</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Name</span>
<span class="kn">from</span> <span class="nn">pygments.filter</span> <span class="kn">import</span> <span class="n">Filter</span>
<span class="k">class</span> <span class="nc">UncolorFilter</span><span class="p">(</span><span class="n">Filter</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__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="n">Filter</span><span class="o">.</span><span class="n">__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">class_too</span> <span class="o">=</span> <span class="n">get_bool_opt</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="s">&#39;classtoo&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lexer</span><span class="p">,</span> <span class="n">stream</span><span class="p">):</span>
<span class="k">for</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">stream</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ttype</span> <span class="ow">is</span> <span class="n">Name</span><span class="o">.</span><span class="n">Function</span> <span class="ow">or</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">class_too</span> <span class="ow">and</span>
<span class="n">ttype</span> <span class="ow">is</span> <span class="n">Name</span><span class="o">.</span><span class="n">Class</span><span class="p">):</span>
<span class="n">ttype</span> <span class="o">=</span> <span class="n">Name</span>
<span class="k">yield</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span>
</pre></div>
<p>Some notes on the <cite>lexer</cite> argument: that can be quite confusing since it doesn't
need to be a lexer instance. If a filter was added by using the <cite>add_filter()</cite>
function of lexers, that lexer is registered for the filter. In that case
<cite>lexer</cite> will refer to the lexer that has registered the filter. It <em>can</em> be used
to access options passed to a lexer. Because it could be <cite>None</cite> you always have
to check for that case if you access it.</p>
</div>
<div class="section" id="using-a-decorator">
<h3>Using a decorator</h3>
<p>You can also use the <cite>simplefilter</cite> decorator from the <cite>pygments.filter</cite> module:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.util</span> <span class="kn">import</span> <span class="n">get_bool_opt</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Name</span>
<span class="kn">from</span> <span class="nn">pygments.filter</span> <span class="kn">import</span> <span class="n">simplefilter</span>
<span class="nd">@simplefilter</span>
<span class="k">def</span> <span class="nf">uncolor</span><span class="p">(</span><span class="n">lexer</span><span class="p">,</span> <span class="n">stream</span><span class="p">,</span> <span class="n">options</span><span class="p">):</span>
<span class="n">class_too</span> <span class="o">=</span> <span class="n">get_bool_opt</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="s">&#39;classtoo&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">stream</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ttype</span> <span class="ow">is</span> <span class="n">Name</span><span class="o">.</span><span class="n">Function</span> <span class="ow">or</span> <span class="p">(</span><span class="n">class_too</span> <span class="ow">and</span>
<span class="n">ttype</span> <span class="ow">is</span> <span class="n">Name</span><span class="o">.</span><span class="n">Class</span><span class="p">):</span>
<span class="n">ttype</span> <span class="o">=</span> <span class="n">Name</span>
<span class="k">yield</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span>
</pre></div>
<p>The decorator automatically subclasses an internal filter class and uses the
decorated function for filtering.</p>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.509423
file id: filterdevelopment -->
</html>

View File

@ -1,412 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Filters &mdash; 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">Filters</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#builtin-filters">Builtin Filters</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p><em>New in Pygments 0.7.</em></p>
<p>You can filter token streams coming from lexers to improve or annotate the
output. For example, you can highlight special words in comments, convert
keywords to upper or lowercase to enforce a style guide etc.</p>
<p>To apply a filter, you can use the <cite>add_filter()</cite> method of a lexer:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">PythonLexer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span> <span class="o">=</span> <span class="n">PythonLexer</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># add a filter given by a string and options</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">add_filter</span><span class="p">(</span><span class="s">&#39;codetagify&#39;</span><span class="p">,</span> <span class="n">case</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">filters</span>
<span class="go">[&lt;pygments.filters.CodeTagFilter object at 0xb785decc&gt;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.filters</span> <span class="kn">import</span> <span class="n">KeywordCaseFilter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># or give an instance</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">l</span><span class="o">.</span><span class="n">add_filter</span><span class="p">(</span><span class="n">KeywordCaseFilter</span><span class="p">(</span><span class="n">case</span><span class="o">=</span><span class="s">&#39;lower&#39;</span><span class="p">))</span>
</pre></div>
<p>The <cite>add_filter()</cite> method takes keyword arguments which are forwarded to
the constructor of the filter.</p>
<p>To get a list of all registered filters by name, you can use the
<cite>get_all_filters()</cite> function from the <cite>pygments.filters</cite> module that returns an
iterable for all known filters.</p>
<p>If you want to write your own filter, have a look at <a class="reference external" href="./filterdevelopment.html">Write your own filter</a>.</p>
<div class="section" id="builtin-filters">
<h3>Builtin Filters</h3>
<p><cite>RaiseOnErrorTokenFilter</cite></p>
<blockquote>
<p>Raise an exception when the lexer generates an error token.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>excclass</cite> <span class="classifier-delimiter">:</span> <span class="classifier">Exception class</span></dt>
<dd>The exception class to raise.
The default is <cite>pygments.filters.ErrorToken</cite>.</dd>
</dl>
<p><em>New in Pygments 0.8.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">raiseonerror</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>VisibleWhitespaceFilter</cite></p>
<blockquote>
<p>Convert tabs, newlines and/or spaces to visible characters.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>spaces</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>If this is a one-character string, spaces will be replaces by this string.
If it is another true value, spaces will be replaced by <tt class="docutils literal">·</tt> (unicode
MIDDLE DOT). If it is a false value, spaces will not be replaced. The
default is <tt class="docutils literal">False</tt>.</dd>
<dt><cite>tabs</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>The same as for <cite>spaces</cite>, but the default replacement character is <tt class="docutils literal">»</tt>
(unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value
is <tt class="docutils literal">False</tt>. Note: this will not work if the <cite>tabsize</cite> option for the
lexer is nonzero, as tabs will already have been expanded then.</dd>
<dt><cite>tabsize</cite> <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd>If tabs are to be replaced by this filter (see the <cite>tabs</cite> option), this
is the total number of characters that a tab should be expanded to.
The default is <tt class="docutils literal">8</tt>.</dd>
<dt><cite>newlines</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string or bool</span></dt>
<dd>The same as for <cite>spaces</cite>, but the default replacement character is <tt class="docutils literal"></tt>
(unicode PILCROW SIGN). The default value is <tt class="docutils literal">False</tt>.</dd>
<dt><cite>wstokentype</cite> <span class="classifier-delimiter">:</span> <span class="classifier">bool</span></dt>
<dd>If true, give whitespace the special <cite>Whitespace</cite> token type. This allows
styling the visible whitespace differently (e.g. greyed out), but it can
disrupt background colors. The default is <tt class="docutils literal">True</tt>.</dd>
</dl>
<p><em>New in Pygments 0.8.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">whitespace</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>TokenMergeFilter</cite></p>
<blockquote>
<p>Merges consecutive tokens with the same token type in the output stream of a
lexer.</p>
<p><em>New in Pygments 1.2.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">tokenmerge</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>NameHighlightFilter</cite></p>
<blockquote>
<p>Highlight a normal Name token with a different token type.</p>
<p>Example:</p>
<pre class="literal-block">
filter = NameHighlightFilter(
names=['foo', 'bar', 'baz'],
tokentype=Name.Function,
)
</pre>
<p>This would highlight the names &quot;foo&quot;, &quot;bar&quot; and &quot;baz&quot;
as functions. <cite>Name.Function</cite> is the default token type.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>names</cite> <span class="classifier-delimiter">:</span> <span class="classifier">list of strings</span></dt>
<dd>A list of names that should be given the different token type.
There is no default.</dd>
<dt><cite>tokentype</cite> <span class="classifier-delimiter">:</span> <span class="classifier">TokenType or string</span></dt>
<dd>A token type or a string containing a token type name that is
used for highlighting the strings in <cite>names</cite>. The default is
<cite>Name.Function</cite>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">highlight</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>GobbleFilter</cite></p>
<blockquote>
<p>Gobbles source code lines (eats initial characters).</p>
<p>This filter drops the first <tt class="docutils literal">n</tt> characters off every line of code. This
may be useful when the source code fed to the lexer is indented by a fixed
amount of space that isn't desired in the output.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>n</cite> <span class="classifier-delimiter">:</span> <span class="classifier">int</span></dt>
<dd>The number of characters to gobble.</dd>
</dl>
<p><em>New in Pygments 1.2.</em></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">gobble</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>CodeTagFilter</cite></p>
<blockquote>
<p>Highlight special code tags in comments and docstrings.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>codetags</cite> <span class="classifier-delimiter">:</span> <span class="classifier">list of strings</span></dt>
<dd>A list of strings that are flagged as code tags. The default is to
highlight <tt class="docutils literal">XXX</tt>, <tt class="docutils literal">TODO</tt>, <tt class="docutils literal">BUG</tt> and <tt class="docutils literal">NOTE</tt>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">codetagify</td>
</tr>
</tbody>
</table>
</blockquote>
<p><cite>KeywordCaseFilter</cite></p>
<blockquote>
<p>Convert keywords to lowercase or uppercase or capitalize them, which
means first letter uppercase, rest lowercase.</p>
<p>This can be useful e.g. if you highlight Pascal code and want to adapt the
code to your styleguide.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>case</cite> <span class="classifier-delimiter">:</span> <span class="classifier">string</span></dt>
<dd>The casing to convert keywords to. Must be one of <tt class="docutils literal">'lower'</tt>,
<tt class="docutils literal">'upper'</tt> or <tt class="docutils literal">'capitalize'</tt>. The default is <tt class="docutils literal">'lower'</tt>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Name:</th><td class="field-body">keywordcase</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.414990
file id: filters -->
</html>

View File

@ -1,374 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Write your own formatter &mdash; 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">Write your own formatter</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#quickstart">Quickstart</a></li>
<li><a href="#styles">Styles</a></li>
<li><a href="#html-3-2-formatter">HTML 3.2 Formatter</a></li>
<li><a href="#generating-style-definitions">Generating Style Definitions</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>As well as creating <a class="reference external" href="./lexerdevelopment.html">your own lexer</a>, writing a new
formatter for Pygments is easy and straightforward.</p>
<p>A formatter is a class that is initialized with some keyword arguments (the
formatter options) and that must provides a <cite>format()</cite> method.
Additionally a formatter should provide a <cite>get_style_defs()</cite> method that
returns the style definitions from the style in a form usable for the
formatter's output format.</p>
<div class="section" id="quickstart">
<h3>Quickstart</h3>
<p>The most basic formatter shipped with Pygments is the <cite>NullFormatter</cite>. It just
sends the value of a token to the output stream:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.formatter</span> <span class="kn">import</span> <span class="n">Formatter</span>
<span class="k">class</span> <span class="nc">NullFormatter</span><span class="p">(</span><span class="n">Formatter</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">format</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tokensource</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="k">for</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">tokensource</span><span class="p">:</span>
<span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
</pre></div>
<p>As you can see, the <cite>format()</cite> method is passed two parameters: <cite>tokensource</cite>
and <cite>outfile</cite>. The first is an iterable of <tt class="docutils literal">(token_type, value)</tt> tuples,
the latter a file like object with a <cite>write()</cite> method.</p>
<p>Because the formatter is that basic it doesn't overwrite the <cite>get_style_defs()</cite>
method.</p>
</div>
<div class="section" id="styles">
<h3>Styles</h3>
<p>Styles aren't instantiated but their metaclass provides some class functions
so that you can access the style definitions easily.</p>
<p>Styles are iterable and yield tuples in the form <tt class="docutils literal">(ttype, d)</tt> where <cite>ttype</cite>
is a token and <cite>d</cite> is a dict with the following keys:</p>
<dl class="docutils">
<dt><tt class="docutils literal">'color'</tt></dt>
<dd>Hexadecimal color value (eg: <tt class="docutils literal">'ff0000'</tt> for red) or <cite>None</cite> if not
defined.</dd>
<dt><tt class="docutils literal">'bold'</tt></dt>
<dd><cite>True</cite> if the value should be bold</dd>
<dt><tt class="docutils literal">'italic'</tt></dt>
<dd><cite>True</cite> if the value should be italic</dd>
<dt><tt class="docutils literal">'underline'</tt></dt>
<dd><cite>True</cite> if the value should be underlined</dd>
<dt><tt class="docutils literal">'bgcolor'</tt></dt>
<dd>Hexadecimal color value for the background (eg: <tt class="docutils literal">'eeeeeee'</tt> for light
gray) or <cite>None</cite> if not defined.</dd>
<dt><tt class="docutils literal">'border'</tt></dt>
<dd>Hexadecimal color value for the border (eg: <tt class="docutils literal">'0000aa'</tt> for a dark
blue) or <cite>None</cite> for no border.</dd>
</dl>
<p>Additional keys might appear in the future, formatters should ignore all keys
they don't support.</p>
</div>
<div class="section" id="html-3-2-formatter">
<h3>HTML 3.2 Formatter</h3>
<p>For an more complex example, let's implement a HTML 3.2 Formatter. We don't
use CSS but inline markup (<tt class="docutils literal">&lt;u&gt;</tt>, <tt class="docutils literal">&lt;font&gt;</tt>, etc). Because this isn't good
style this formatter isn't in the standard library ;-)</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.formatter</span> <span class="kn">import</span> <span class="n">Formatter</span>
<span class="k">class</span> <span class="nc">OldHtmlFormatter</span><span class="p">(</span><span class="n">Formatter</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__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="n">Formatter</span><span class="o">.</span><span class="n">__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="c"># create a dict of (start, end) tuples that wrap the</span>
<span class="c"># value of a token so that we can use it in the format</span>
<span class="c"># method later</span>
<span class="bp">self</span><span class="o">.</span><span class="n">styles</span> <span class="o">=</span> <span class="p">{}</span>
<span class="c"># we iterate over the `_styles` attribute of a style item</span>
<span class="c"># that contains the parsed style values.</span>
<span class="k">for</span> <span class="n">token</span><span class="p">,</span> <span class="n">style</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">style</span><span class="p">:</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">end</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
<span class="c"># a style item is a tuple in the following form:</span>
<span class="c"># colors are readily specified in hex: &#39;RRGGBB&#39;</span>
<span class="k">if</span> <span class="n">style</span><span class="p">[</span><span class="s">&#39;color&#39;</span><span class="p">]:</span>
<span class="n">start</span> <span class="o">+=</span> <span class="s">&#39;&lt;font color=&quot;#</span><span class="si">%s</span><span class="s">&quot;&gt;&#39;</span> <span class="o">%</span> <span class="n">style</span><span class="p">[</span><span class="s">&#39;color&#39;</span><span class="p">]</span>
<span class="n">end</span> <span class="o">=</span> <span class="s">&#39;&lt;/font&gt;&#39;</span> <span class="o">+</span> <span class="n">end</span>
<span class="k">if</span> <span class="n">style</span><span class="p">[</span><span class="s">&#39;bold&#39;</span><span class="p">]:</span>
<span class="n">start</span> <span class="o">+=</span> <span class="s">&#39;&lt;b&gt;&#39;</span>
<span class="n">end</span> <span class="o">=</span> <span class="s">&#39;&lt;/b&gt;&#39;</span> <span class="o">+</span> <span class="n">end</span>
<span class="k">if</span> <span class="n">style</span><span class="p">[</span><span class="s">&#39;italic&#39;</span><span class="p">]:</span>
<span class="n">start</span> <span class="o">+=</span> <span class="s">&#39;&lt;i&gt;&#39;</span>
<span class="n">end</span> <span class="o">=</span> <span class="s">&#39;&lt;/i&gt;&#39;</span> <span class="o">+</span> <span class="n">end</span>
<span class="k">if</span> <span class="n">style</span><span class="p">[</span><span class="s">&#39;underline&#39;</span><span class="p">]:</span>
<span class="n">start</span> <span class="o">+=</span> <span class="s">&#39;&lt;u&gt;&#39;</span>
<span class="n">end</span> <span class="o">=</span> <span class="s">&#39;&lt;/u&gt;&#39;</span> <span class="o">+</span> <span class="n">end</span>
<span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="n">token</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">format</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tokensource</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="c"># lastval is a string we use for caching</span>
<span class="c"># because it&#39;s possible that an lexer yields a number</span>
<span class="c"># of consecutive tokens with the same token type.</span>
<span class="c"># to minimize the size of the generated html markup we</span>
<span class="c"># try to join the values of same-type tokens here</span>
<span class="n">lastval</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
<span class="n">lasttype</span> <span class="o">=</span> <span class="bp">None</span>
<span class="c"># wrap the whole output with &lt;pre&gt;</span>
<span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;&lt;pre&gt;&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ttype</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">tokensource</span><span class="p">:</span>
<span class="c"># if the token type doesn&#39;t exist in the stylemap</span>
<span class="c"># we try it with the parent of the token type</span>
<span class="c"># eg: parent of Token.Literal.String.Double is</span>
<span class="c"># Token.Literal.String</span>
<span class="k">while</span> <span class="n">ttype</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">:</span>
<span class="n">ttype</span> <span class="o">=</span> <span class="n">ttype</span><span class="o">.</span><span class="n">parent</span>
<span class="k">if</span> <span class="n">ttype</span> <span class="o">==</span> <span class="n">lasttype</span><span class="p">:</span>
<span class="c"># the current token type is the same of the last</span>
<span class="c"># iteration. cache it</span>
<span class="n">lastval</span> <span class="o">+=</span> <span class="n">value</span>
<span class="k">else</span><span class="p">:</span>
<span class="c"># not the same token as last iteration, but we</span>
<span class="c"># have some data in the buffer. wrap it with the</span>
<span class="c"># defined style and write it to the output file</span>
<span class="k">if</span> <span class="n">lastval</span><span class="p">:</span>
<span class="n">stylebegin</span><span class="p">,</span> <span class="n">styleend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="n">lasttype</span><span class="p">]</span>
<span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">stylebegin</span> <span class="o">+</span> <span class="n">lastval</span> <span class="o">+</span> <span class="n">styleend</span><span class="p">)</span>
<span class="c"># set lastval/lasttype to current values</span>
<span class="n">lastval</span> <span class="o">=</span> <span class="n">value</span>
<span class="n">lasttype</span> <span class="o">=</span> <span class="n">ttype</span>
<span class="c"># if something is left in the buffer, write it to the</span>
<span class="c"># output file, then close the opened &lt;pre&gt; tag</span>
<span class="k">if</span> <span class="n">lastval</span><span class="p">:</span>
<span class="n">stylebegin</span><span class="p">,</span> <span class="n">styleend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">styles</span><span class="p">[</span><span class="n">lasttype</span><span class="p">]</span>
<span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">stylebegin</span> <span class="o">+</span> <span class="n">lastval</span> <span class="o">+</span> <span class="n">styleend</span><span class="p">)</span>
<span class="n">outfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;&lt;/pre&gt;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
</pre></div>
<p>The comments should explain it. Again, this formatter doesn't override the
<cite>get_style_defs()</cite> method. If we would have used CSS classes instead of
inline HTML markup, we would need to generate the CSS first. For that
purpose the <cite>get_style_defs()</cite> method exists:</p>
</div>
<div class="section" id="generating-style-definitions">
<h3>Generating Style Definitions</h3>
<p>Some formatters like the <cite>LatexFormatter</cite> and the <cite>HtmlFormatter</cite> don't
output inline markup but reference either macros or css classes. Because
the definitions of those are not part of the output, the <cite>get_style_defs()</cite>
method exists. It is passed one parameter (if it's used and how it's used
is up to the formatter) and has to return a string or <tt class="docutils literal">None</tt>.</p>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:42.995351
file id: formatterdevelopment -->
</html>

View File

@ -1,927 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Available formatters &mdash; 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">Available formatters</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#common-options">Common options</a></li>
<li><a href="#formatter-classes">Formatter classes</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>This page lists all builtin formatters.</p>
<div class="section" id="common-options">
<h3>Common options</h3>
<p>All formatters support these options:</p>
<dl class="docutils">
<dt><cite>encoding</cite></dt>
<dd><p class="first"><em>New in Pygments 0.6.</em></p>
<p>If given, must be an encoding name (such as <tt class="docutils literal"><span class="pre">&quot;utf-8&quot;</span></tt>). This will
be used to convert the token strings (which are Unicode strings)
to byte strings in the output (default: <tt class="docutils literal">None</tt>).
It will also be written in an encoding declaration suitable for the
document format if the <cite>full</cite> option is given (e.g. a <tt class="docutils literal">meta
<span class="pre">content-type</span></tt> directive in HTML or an invocation of the <cite>inputenc</cite>
package in LaTeX).</p>
<p class="last">If this is <tt class="docutils literal">&quot;&quot;</tt> or <tt class="docutils literal">None</tt>, Unicode strings will be written
to the output file, which most file-like objects do not support.
For example, <cite>pygments.highlight()</cite> will return a Unicode string if
called with no <cite>outfile</cite> argument and a formatter that has <cite>encoding</cite>
set to <tt class="docutils literal">None</tt> because it uses a <cite>StringIO.StringIO</cite> object that
supports Unicode arguments to <cite>write()</cite>. Using a regular file object
wouldn't work.</p>
</dd>
<dt><cite>outencoding</cite></dt>
<dd><p class="first"><em>New in Pygments 0.7.</em></p>
<p class="last">When using Pygments from the command line, any <cite>encoding</cite> option given is
passed to the lexer and the formatter. This is sometimes not desirable,
for example if you want to set the input encoding to <tt class="docutils literal">&quot;guess&quot;</tt>.
Therefore, <cite>outencoding</cite> has been introduced which overrides <cite>encoding</cite>
for the formatter if given.</p>
</dd>
</dl>
</div>
<div class="section" id="formatter-classes">
<h3>Formatter classes</h3>
<p>All these classes are importable from <cite>pygments.formatters</cite>.</p>
<div class="section" id="bbcodeformatter">
<h4><cite>BBCodeFormatter</cite></h4>
<blockquote>
<p>Format tokens with BBcodes. These formatting codes are used by many
bulletin boards, so you can highlight your sourcecode with pygments before
posting it there.</p>
<p>This formatter has no support for background colors and borders, as there
are no common BBcode tags for that.</p>
<p>Some board systems (e.g. phpBB) don't support colors in their [code] tag,
so you can't use the highlighting together with that tag.
Text in a [code] tag usually is shown with a monospace font (which this
formatter can do with the <tt class="docutils literal">monofont</tt> option) and no spaces (which you
need for indentation) are removed.</p>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>style</cite></dt>
<dd>The style to use, can be a string or a Style subclass (default:
<tt class="docutils literal">'default'</tt>).</dd>
<dt><cite>codetag</cite></dt>
<dd>If set to true, put the output into <tt class="docutils literal">[code]</tt> tags (default:
<tt class="docutils literal">false</tt>)</dd>
<dt><cite>monofont</cite></dt>
<dd>If set to true, add a tag to show the code with a monospace font
(default: <tt class="docutils literal">false</tt>).</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">bbcode, bb</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="bmpimageformatter">
<h4><cite>BmpImageFormatter</cite></h4>
<blockquote>
<p>Create a bitmap image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.</p>
<p><em>New in Pygments 1.0.</em> (You could create bitmap images before by passing a
suitable <cite>image_format</cite> option to the <cite>ImageFormatter</cite>.)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">bmp, bitmap</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.bmp</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="gifimageformatter">
<h4><cite>GifImageFormatter</cite></h4>
<blockquote>
<p>Create a GIF image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.</p>
<p><em>New in Pygments 1.0.</em> (You could create GIF images before by passing a
suitable <cite>image_format</cite> option to the <cite>ImageFormatter</cite>.)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">gif</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.gif</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="htmlformatter">
<h4><cite>HtmlFormatter</cite></h4>
<blockquote>
<p>Format tokens as HTML 4 <tt class="docutils literal">&lt;span&gt;</tt> tags within a <tt class="docutils literal">&lt;pre&gt;</tt> tag, wrapped
in a <tt class="docutils literal">&lt;div&gt;</tt> tag. The <tt class="docutils literal">&lt;div&gt;</tt>'s CSS class can be set by the <cite>cssclass</cite>
option.</p>
<p>If the <cite>linenos</cite> option is set to <tt class="docutils literal">&quot;table&quot;</tt>, the <tt class="docutils literal">&lt;pre&gt;</tt> is
additionally wrapped inside a <tt class="docutils literal">&lt;table&gt;</tt> which has one row and two
cells: one containing the line numbers and one containing the code.
Example:</p>
<div class="syntax"><pre><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;highlight&quot;</span> <span class="nt">&gt;</span>
<span class="nt">&lt;table&gt;&lt;tr&gt;</span>
<span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;linenos&quot;</span> <span class="na">title=</span><span class="s">&quot;click to toggle&quot;</span>
<span class="na">onclick=</span><span class="s">&quot;with (this.firstChild.style)</span>
<span class="s"> { display = (display == &#39;&#39;) ? &#39;none&#39; : &#39;&#39; }&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;pre&gt;</span>1
2<span class="nt">&lt;/pre&gt;</span>
<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;td</span> <span class="na">class=</span><span class="s">&quot;code&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;pre&gt;&lt;span</span> <span class="na">class=</span><span class="s">&quot;Ke&quot;</span><span class="nt">&gt;</span>def <span class="nt">&lt;/span&gt;&lt;span</span> <span class="na">class=</span><span class="s">&quot;NaFu&quot;</span><span class="nt">&gt;</span>foo<span class="nt">&lt;/span&gt;</span>(bar):
<span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;Ke&quot;</span><span class="nt">&gt;</span>pass<span class="nt">&lt;/span&gt;</span>
<span class="nt">&lt;/pre&gt;</span>
<span class="nt">&lt;/td&gt;</span>
<span class="nt">&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;</span>
</pre></div>
<p>(whitespace added to improve clarity).</p>
<p>Wrapping can be disabled using the <cite>nowrap</cite> option.</p>
<p>A list of lines can be specified using the <cite>hl_lines</cite> option to make these
lines highlighted (as of Pygments 0.11).</p>
<p>With the <cite>full</cite> option, a complete HTML 4 document is output, including
the style definitions inside a <tt class="docutils literal">&lt;style&gt;</tt> tag, or in a separate file if
the <cite>cssfile</cite> option is given.</p>
<p>When <cite>tagsfile</cite> is set to the path of a ctags index file, it is used to
generate hyperlinks from names to their definition. You must enable
<cite>anchorlines</cite> and run ctags with the <cite>-n</cite> option for this to work. The
<cite>python-ctags</cite> module from PyPI must be installed to use this feature;
otherwise a <cite>RuntimeError</cite> will be raised.</p>
<p>The <cite>get_style_defs(arg='')</cite> method of a <cite>HtmlFormatter</cite> returns a string
containing CSS rules for the CSS classes used by the formatter. The
argument <cite>arg</cite> can be used to specify additional CSS selectors that
are prepended to the classes. A call <cite>fmter.get_style_defs('td .code')</cite>
would result in the following CSS classes:</p>
<div class="syntax"><pre><span class="nt">td</span> <span class="nc">.code</span> <span class="nc">.kw</span> <span class="p">{</span> <span class="k">font-weight</span><span class="o">:</span> <span class="k">bold</span><span class="p">;</span> <span class="k">color</span><span class="o">:</span> <span class="m">#00FF00</span> <span class="p">}</span>
<span class="nt">td</span> <span class="nc">.code</span> <span class="nc">.cm</span> <span class="p">{</span> <span class="k">color</span><span class="o">:</span> <span class="m">#999999</span> <span class="p">}</span>
<span class="o">...</span>
</pre></div>
<p>If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
<cite>get_style_defs()</cite> method to request multiple prefixes for the tokens:</p>
<div class="syntax"><pre><span class="n">formatter</span><span class="o">.</span><span class="n">get_style_defs</span><span class="p">([</span><span class="s">&#39;div.syntax pre&#39;</span><span class="p">,</span> <span class="s">&#39;pre.syntax&#39;</span><span class="p">])</span>
</pre></div>
<p>The output would then look like this:</p>
<div class="syntax"><pre><span class="nt">div</span><span class="nc">.syntax</span> <span class="nt">pre</span> <span class="nc">.kw</span><span class="o">,</span>
<span class="nt">pre</span><span class="nc">.syntax</span> <span class="nc">.kw</span> <span class="p">{</span> <span class="k">font-weight</span><span class="o">:</span> <span class="k">bold</span><span class="p">;</span> <span class="k">color</span><span class="o">:</span> <span class="m">#00FF00</span> <span class="p">}</span>
<span class="nt">div</span><span class="nc">.syntax</span> <span class="nt">pre</span> <span class="nc">.cm</span><span class="o">,</span>
<span class="nt">pre</span><span class="nc">.syntax</span> <span class="nc">.cm</span> <span class="p">{</span> <span class="k">color</span><span class="o">:</span> <span class="m">#999999</span> <span class="p">}</span>
<span class="o">...</span>
</pre></div>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>nowrap</cite></dt>
<dd>If set to <tt class="docutils literal">True</tt>, don't wrap the tokens at all, not even inside a <tt class="docutils literal">&lt;pre&gt;</tt>
tag. This disables most other options (default: <tt class="docutils literal">False</tt>).</dd>
<dt><cite>full</cite></dt>
<dd>Tells the formatter to output a &quot;full&quot; document, i.e. a complete
self-contained document (default: <tt class="docutils literal">False</tt>).</dd>
<dt><cite>title</cite></dt>
<dd>If <cite>full</cite> is true, the title that should be used to caption the
document (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>style</cite></dt>
<dd>The style to use, can be a string or a Style subclass (default:
<tt class="docutils literal">'default'</tt>). This option has no effect if the <cite>cssfile</cite>
and <cite>noclobber_cssfile</cite> option are given and the file specified in
<cite>cssfile</cite> exists.</dd>
<dt><cite>noclasses</cite></dt>
<dd>If set to true, token <tt class="docutils literal">&lt;span&gt;</tt> tags will not use CSS classes, but
inline styles. This is not recommended for larger pieces of code since
it increases output size by quite a bit (default: <tt class="docutils literal">False</tt>).</dd>
<dt><cite>classprefix</cite></dt>
<dd>Since the token types use relatively short class names, they may clash
with some of your own class names. In this case you can use the
<cite>classprefix</cite> option to give a string to prepend to all Pygments-generated
CSS class names for token types.
Note that this option also affects the output of <cite>get_style_defs()</cite>.</dd>
<dt><cite>cssclass</cite></dt>
<dd><p class="first">CSS class for the wrapping <tt class="docutils literal">&lt;div&gt;</tt> tag (default: <tt class="docutils literal">'highlight'</tt>).
If you set this option, the default selector for <cite>get_style_defs()</cite>
will be this class.</p>
<p class="last"><em>New in Pygments 0.9:</em> If you select the <tt class="docutils literal">'table'</tt> line numbers, the
wrapping table will have a CSS class of this string plus <tt class="docutils literal">'table'</tt>,
the default is accordingly <tt class="docutils literal">'highlighttable'</tt>.</p>
</dd>
<dt><cite>cssstyles</cite></dt>
<dd>Inline CSS styles for the wrapping <tt class="docutils literal">&lt;div&gt;</tt> tag (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>prestyles</cite></dt>
<dd>Inline CSS styles for the <tt class="docutils literal">&lt;pre&gt;</tt> tag (default: <tt class="docutils literal">''</tt>). <em>New in
Pygments 0.11.</em></dd>
<dt><cite>cssfile</cite></dt>
<dd>If the <cite>full</cite> option is true and this option is given, it must be the
name of an external file. If the filename does not include an absolute
path, the file's path will be assumed to be relative to the main output
file's path, if the latter can be found. The stylesheet is then written
to this file instead of the HTML file. <em>New in Pygments 0.6.</em></dd>
<dt><cite>noclobber_cssfile</cite></dt>
<dd>If <cite>cssfile</cite> is given and the specified file exists, the css file will
not be overwritten. This allows the use of the <cite>full</cite> option in
combination with a user specified css file. Default is <tt class="docutils literal">False</tt>.
<em>New in Pygments 1.1.</em></dd>
<dt><cite>linenos</cite></dt>
<dd><p class="first">If set to <tt class="docutils literal">'table'</tt>, output line numbers as a table with two cells,
one containing the line numbers, the other the whole code. This is
copy-and-paste-friendly, but may cause alignment problems with some
browsers or fonts. If set to <tt class="docutils literal">'inline'</tt>, the line numbers will be
integrated in the <tt class="docutils literal">&lt;pre&gt;</tt> tag that contains the code (that setting
is <em>new in Pygments 0.8</em>).</p>
<p>For compatibility with Pygments 0.7 and earlier, every true value
except <tt class="docutils literal">'inline'</tt> means the same as <tt class="docutils literal">'table'</tt> (in particular, that
means also <tt class="docutils literal">True</tt>).</p>
<p>The default value is <tt class="docutils literal">False</tt>, which means no line numbers at all.</p>
<p class="last"><strong>Note:</strong> with the default (&quot;table&quot;) line number mechanism, the line
numbers and code can have different line heights in Internet Explorer
unless you give the enclosing <tt class="docutils literal">&lt;pre&gt;</tt> tags an explicit <tt class="docutils literal"><span class="pre">line-height</span></tt>
CSS property (you get the default line spacing with <tt class="docutils literal"><span class="pre">line-height:</span>
125%</tt>).</p>
</dd>
<dt><cite>hl_lines</cite></dt>
<dd>Specify a list of lines to be highlighted. <em>New in Pygments 0.11.</em></dd>
<dt><cite>linenostart</cite></dt>
<dd>The line number for the first line (default: <tt class="docutils literal">1</tt>).</dd>
<dt><cite>linenostep</cite></dt>
<dd>If set to a number n &gt; 1, only every nth line number is printed.</dd>
<dt><cite>linenospecial</cite></dt>
<dd>If set to a number n &gt; 0, every nth line number is given the CSS
class <tt class="docutils literal">&quot;special&quot;</tt> (default: <tt class="docutils literal">0</tt>).</dd>
<dt><cite>nobackground</cite></dt>
<dd>If set to <tt class="docutils literal">True</tt>, the formatter won't output the background color
for the wrapping element (this automatically defaults to <tt class="docutils literal">False</tt>
when there is no wrapping element [eg: no argument for the
<cite>get_syntax_defs</cite> method given]) (default: <tt class="docutils literal">False</tt>). <em>New in
Pygments 0.6.</em></dd>
<dt><cite>lineseparator</cite></dt>
<dd>This string is output between lines of code. It defaults to <tt class="docutils literal">&quot;\n&quot;</tt>,
which is enough to break a line inside <tt class="docutils literal">&lt;pre&gt;</tt> tags, but you can
e.g. set it to <tt class="docutils literal">&quot;&lt;br&gt;&quot;</tt> to get HTML line breaks. <em>New in Pygments
0.7.</em></dd>
<dt><cite>lineanchors</cite></dt>
<dd>If set to a nonempty string, e.g. <tt class="docutils literal">foo</tt>, the formatter will wrap each
output line in an anchor tag with a <tt class="docutils literal">name</tt> of <tt class="docutils literal"><span class="pre">foo-linenumber</span></tt>.
This allows easy linking to certain lines. <em>New in Pygments 0.9.</em></dd>
<dt><cite>linespans</cite></dt>
<dd>If set to a nonempty string, e.g. <tt class="docutils literal">foo</tt>, the formatter will wrap each
output line in a span tag with an <tt class="docutils literal">id</tt> of <tt class="docutils literal"><span class="pre">foo-linenumber</span></tt>.
This allows easy access to lines via javascript. <em>New in Pygments 1.6.</em></dd>
<dt><cite>anchorlinenos</cite></dt>
<dd>If set to <cite>True</cite>, will wrap line numbers in &lt;a&gt; tags. Used in
combination with <cite>linenos</cite> and <cite>lineanchors</cite>.</dd>
<dt><cite>tagsfile</cite></dt>
<dd>If set to the path of a ctags file, wrap names in anchor tags that
link to their definitions. <cite>lineanchors</cite> should be used, and the
tags file should specify line numbers (see the <cite>-n</cite> option to ctags).
<em>New in Pygments 1.6.</em></dd>
<dt><cite>tagurlformat</cite></dt>
<dd>A string formatting pattern used to generate links to ctags definitions.
Avaliabe variable are <cite>%(path)s</cite>, <cite>%(fname)s</cite> and <cite>%(fext)s</cite>.
Defaults to an empty string, resulting in just <cite>#prefix-number</cite> links.
<em>New in Pygments 1.6.</em></dd>
</dl>
<p><strong>Subclassing the HTML formatter</strong></p>
<p><em>New in Pygments 0.7.</em></p>
<p>The HTML formatter is now built in a way that allows easy subclassing, thus
customizing the output HTML code. The <cite>format()</cite> method calls
<cite>self._format_lines()</cite> which returns a generator that yields tuples of <tt class="docutils literal">(1,
line)</tt>, where the <tt class="docutils literal">1</tt> indicates that the <tt class="docutils literal">line</tt> is a line of the
formatted source code.</p>
<p>If the <cite>nowrap</cite> option is set, the generator is the iterated over and the
resulting HTML is output.</p>
<p>Otherwise, <cite>format()</cite> calls <cite>self.wrap()</cite>, which wraps the generator with
other generators. These may add some HTML code to the one generated by
<cite>_format_lines()</cite>, either by modifying the lines generated by the latter,
then yielding them again with <tt class="docutils literal">(1, line)</tt>, and/or by yielding other HTML
code before or after the lines, with <tt class="docutils literal">(0, html)</tt>. The distinction between
source lines and other code makes it possible to wrap the generator multiple
times.</p>
<p>The default <cite>wrap()</cite> implementation adds a <tt class="docutils literal">&lt;div&gt;</tt> and a <tt class="docutils literal">&lt;pre&gt;</tt> tag.</p>
<p>A custom <cite>HtmlFormatter</cite> subclass could look like this:</p>
<div class="syntax"><pre><span class="k">class</span> <span class="nc">CodeHtmlFormatter</span><span class="p">(</span><span class="n">HtmlFormatter</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">wrap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_wrap_code</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_wrap_code</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">):</span>
<span class="k">yield</span> <span class="mi">0</span><span class="p">,</span> <span class="s">&#39;&lt;code&gt;&#39;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">source</span><span class="p">:</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="c"># it&#39;s a line of formatted code</span>
<span class="n">t</span> <span class="o">+=</span> <span class="s">&#39;&lt;br&gt;&#39;</span>
<span class="k">yield</span> <span class="n">i</span><span class="p">,</span> <span class="n">t</span>
<span class="k">yield</span> <span class="mi">0</span><span class="p">,</span> <span class="s">&#39;&lt;/code&gt;&#39;</span>
</pre></div>
<p>This results in wrapping the formatted lines with a <tt class="docutils literal">&lt;code&gt;</tt> tag, where the
source lines are broken using <tt class="docutils literal">&lt;br&gt;</tt> tags.</p>
<p>After calling <cite>wrap()</cite>, the <cite>format()</cite> method also adds the &quot;line numbers&quot;
and/or &quot;full document&quot; wrappers if the respective options are set. Then, all
HTML yielded by the wrapped generator is output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">html</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.html, *.htm</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="imageformatter">
<h4><cite>ImageFormatter</cite></h4>
<blockquote>
<p>Create a PNG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.</p>
<p><em>New in Pygments 0.10.</em></p>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>image_format</cite></dt>
<dd><p class="first">An image format to output to that is recognised by PIL, these include:</p>
<ul class="last simple">
<li>&quot;PNG&quot; (default)</li>
<li>&quot;JPEG&quot;</li>
<li>&quot;BMP&quot;</li>
<li>&quot;GIF&quot;</li>
</ul>
</dd>
<dt><cite>line_pad</cite></dt>
<dd><p class="first">The extra spacing (in pixels) between each line of text.</p>
<p class="last">Default: 2</p>
</dd>
<dt><cite>font_name</cite></dt>
<dd><p class="first">The font name to be used as the base font from which others, such as
bold and italic fonts will be generated. This really should be a
monospace font to look sane.</p>
<p class="last">Default: &quot;Bitstream Vera Sans Mono&quot;</p>
</dd>
<dt><cite>font_size</cite></dt>
<dd><p class="first">The font size in points to be used.</p>
<p class="last">Default: 14</p>
</dd>
<dt><cite>image_pad</cite></dt>
<dd><p class="first">The padding, in pixels to be used at each edge of the resulting image.</p>
<p class="last">Default: 10</p>
</dd>
<dt><cite>line_numbers</cite></dt>
<dd><p class="first">Whether line numbers should be shown: True/False</p>
<p class="last">Default: True</p>
</dd>
<dt><cite>line_number_start</cite></dt>
<dd><p class="first">The line number of the first line.</p>
<p class="last">Default: 1</p>
</dd>
<dt><cite>line_number_step</cite></dt>
<dd><p class="first">The step used when printing line numbers.</p>
<p class="last">Default: 1</p>
</dd>
<dt><cite>line_number_bg</cite></dt>
<dd><p class="first">The background colour (in &quot;#123456&quot; format) of the line number bar, or
None to use the style background color.</p>
<p class="last">Default: &quot;#eed&quot;</p>
</dd>
<dt><cite>line_number_fg</cite></dt>
<dd><p class="first">The text color of the line numbers (in &quot;#123456&quot;-like format).</p>
<p class="last">Default: &quot;#886&quot;</p>
</dd>
<dt><cite>line_number_chars</cite></dt>
<dd><p class="first">The number of columns of line numbers allowable in the line number
margin.</p>
<p class="last">Default: 2</p>
</dd>
<dt><cite>line_number_bold</cite></dt>
<dd><p class="first">Whether line numbers will be bold: True/False</p>
<p class="last">Default: False</p>
</dd>
<dt><cite>line_number_italic</cite></dt>
<dd><p class="first">Whether line numbers will be italicized: True/False</p>
<p class="last">Default: False</p>
</dd>
<dt><cite>line_number_separator</cite></dt>
<dd><p class="first">Whether a line will be drawn between the line number area and the
source code area: True/False</p>
<p class="last">Default: True</p>
</dd>
<dt><cite>line_number_pad</cite></dt>
<dd><p class="first">The horizontal padding (in pixels) between the line number margin, and
the source code area.</p>
<p class="last">Default: 6</p>
</dd>
<dt><cite>hl_lines</cite></dt>
<dd><p class="first">Specify a list of lines to be highlighted. <em>New in Pygments 1.2.</em></p>
<p class="last">Default: empty list</p>
</dd>
<dt><cite>hl_color</cite></dt>
<dd><p class="first">Specify the color for highlighting lines. <em>New in Pygments 1.2.</em></p>
<p class="last">Default: highlight color of the selected style</p>
</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">img, IMG, png</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.png</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="jpgimageformatter">
<h4><cite>JpgImageFormatter</cite></h4>
<blockquote>
<p>Create a JPEG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code.</p>
<p><em>New in Pygments 1.0.</em> (You could create JPEG images before by passing a
suitable <cite>image_format</cite> option to the <cite>ImageFormatter</cite>.)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">jpg, jpeg</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.jpg</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="latexformatter">
<h4><cite>LatexFormatter</cite></h4>
<blockquote>
<p>Format tokens as LaTeX code. This needs the <cite>fancyvrb</cite> and <cite>color</cite>
standard packages.</p>
<p>Without the <cite>full</cite> option, code is formatted as one <tt class="docutils literal">Verbatim</tt>
environment, like this:</p>
<div class="syntax"><pre><span class="k">\begin</span><span class="nb">{</span>Verbatim<span class="nb">}</span>[commandchars=<span class="k">\\</span><span class="nb">{</span><span class="k">\}</span>]
<span class="k">\PY</span><span class="nb">{</span>k<span class="nb">}{</span>def <span class="nb">}</span><span class="k">\PY</span><span class="nb">{</span>n+nf<span class="nb">}{</span>foo<span class="nb">}</span>(<span class="k">\PY</span><span class="nb">{</span>n<span class="nb">}{</span>bar<span class="nb">}</span>):
<span class="k">\PY</span><span class="nb">{</span>k<span class="nb">}{</span>pass<span class="nb">}</span>
<span class="k">\end</span><span class="nb">{</span>Verbatim<span class="nb">}</span>
</pre></div>
<p>The special command used here (<tt class="docutils literal">\PY</tt>) and all the other macros it needs
are output by the <cite>get_style_defs</cite> method.</p>
<p>With the <cite>full</cite> option, a complete LaTeX document is output, including
the command definitions in the preamble.</p>
<p>The <cite>get_style_defs()</cite> method of a <cite>LatexFormatter</cite> returns a string
containing <tt class="docutils literal">\def</tt> commands defining the macros needed inside the
<tt class="docutils literal">Verbatim</tt> environments.</p>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>style</cite></dt>
<dd>The style to use, can be a string or a Style subclass (default:
<tt class="docutils literal">'default'</tt>).</dd>
<dt><cite>full</cite></dt>
<dd>Tells the formatter to output a &quot;full&quot; document, i.e. a complete
self-contained document (default: <tt class="docutils literal">False</tt>).</dd>
<dt><cite>title</cite></dt>
<dd>If <cite>full</cite> is true, the title that should be used to caption the
document (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>docclass</cite></dt>
<dd>If the <cite>full</cite> option is enabled, this is the document class to use
(default: <tt class="docutils literal">'article'</tt>).</dd>
<dt><cite>preamble</cite></dt>
<dd>If the <cite>full</cite> option is enabled, this can be further preamble commands,
e.g. <tt class="docutils literal">\usepackage</tt> (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>linenos</cite></dt>
<dd>If set to <tt class="docutils literal">True</tt>, output line numbers (default: <tt class="docutils literal">False</tt>).</dd>
<dt><cite>linenostart</cite></dt>
<dd>The line number for the first line (default: <tt class="docutils literal">1</tt>).</dd>
<dt><cite>linenostep</cite></dt>
<dd>If set to a number n &gt; 1, only every nth line number is printed.</dd>
<dt><cite>verboptions</cite></dt>
<dd>Additional options given to the Verbatim environment (see the <em>fancyvrb</em>
docs for possible values) (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>commandprefix</cite></dt>
<dd><p class="first">The LaTeX commands used to produce colored output are constructed
using this prefix and some letters (default: <tt class="docutils literal">'PY'</tt>).
<em>New in Pygments 0.7.</em></p>
<p class="last"><em>New in Pygments 0.10:</em> the default is now <tt class="docutils literal">'PY'</tt> instead of <tt class="docutils literal">'C'</tt>.</p>
</dd>
<dt><cite>texcomments</cite></dt>
<dd>If set to <tt class="docutils literal">True</tt>, enables LaTeX comment lines. That is, LaTex markup
in comment tokens is not escaped so that LaTeX can render it (default:
<tt class="docutils literal">False</tt>). <em>New in Pygments 1.2.</em></dd>
<dt><cite>mathescape</cite></dt>
<dd>If set to <tt class="docutils literal">True</tt>, enables LaTeX math mode escape in comments. That
is, <tt class="docutils literal"><span class="pre">'$...$'</span></tt> inside a comment will trigger math mode (default:
<tt class="docutils literal">False</tt>). <em>New in Pygments 1.2.</em></dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">latex, tex</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.tex</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="nullformatter">
<h4><cite>NullFormatter</cite></h4>
<blockquote>
<p>Output the text unchanged without any formatting.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">text, null</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.txt</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="rawtokenformatter">
<h4><cite>RawTokenFormatter</cite></h4>
<blockquote>
<p>Format tokens as a raw representation for storing token streams.</p>
<p>The format is <tt class="docutils literal"><span class="pre">tokentype&lt;TAB&gt;repr(tokenstring)\n</span></tt>. The output can later
be converted to a token stream with the <cite>RawTokenLexer</cite>, described in the
<a class="reference external" href="./lexers.html">lexer list</a>.</p>
<p>Only two options are accepted:</p>
<dl class="docutils">
<dt><cite>compress</cite></dt>
<dd>If set to <tt class="docutils literal">'gz'</tt> or <tt class="docutils literal">'bz2'</tt>, compress the output with the given
compression algorithm after encoding (default: <tt class="docutils literal">''</tt>).</dd>
<dt><cite>error_color</cite></dt>
<dd>If set to a color name, highlight error tokens using that color. If
set but with no value, defaults to <tt class="docutils literal">'red'</tt>.
<em>New in Pygments 0.11.</em></dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">raw, tokens</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.raw</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="rtfformatter">
<h4><cite>RtfFormatter</cite></h4>
<blockquote>
<p>Format tokens as RTF markup. This formatter automatically outputs full RTF
documents with color information and other useful stuff. Perfect for Copy and
Paste into Microsoft® Word® documents.</p>
<p><em>New in Pygments 0.6.</em></p>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>style</cite></dt>
<dd>The style to use, can be a string or a Style subclass (default:
<tt class="docutils literal">'default'</tt>).</dd>
<dt><cite>fontface</cite></dt>
<dd>The used font famliy, for example <tt class="docutils literal">Bitstream Vera Sans</tt>. Defaults to
some generic font which is supposed to have fixed width.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">rtf</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.rtf</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="svgformatter">
<h4><cite>SvgFormatter</cite></h4>
<blockquote>
<p>Format tokens as an SVG graphics file. This formatter is still experimental.
Each line of code is a <tt class="docutils literal">&lt;text&gt;</tt> element with explicit <tt class="docutils literal">x</tt> and <tt class="docutils literal">y</tt>
coordinates containing <tt class="docutils literal">&lt;tspan&gt;</tt> elements with the individual token styles.</p>
<p>By default, this formatter outputs a full SVG document including doctype
declaration and the <tt class="docutils literal">&lt;svg&gt;</tt> root element.</p>
<p><em>New in Pygments 0.9.</em></p>
<p>Additional options accepted:</p>
<dl class="docutils">
<dt><cite>nowrap</cite></dt>
<dd>Don't wrap the SVG <tt class="docutils literal">&lt;text&gt;</tt> elements in <tt class="docutils literal"><span class="pre">&lt;svg&gt;&lt;g&gt;</span></tt> elements and
don't add a XML declaration and a doctype. If true, the <cite>fontfamily</cite>
and <cite>fontsize</cite> options are ignored. Defaults to <tt class="docutils literal">False</tt>.</dd>
<dt><cite>fontfamily</cite></dt>
<dd>The value to give the wrapping <tt class="docutils literal">&lt;g&gt;</tt> element's <tt class="docutils literal"><span class="pre">font-family</span></tt>
attribute, defaults to <tt class="docutils literal">&quot;monospace&quot;</tt>.</dd>
<dt><cite>fontsize</cite></dt>
<dd>The value to give the wrapping <tt class="docutils literal">&lt;g&gt;</tt> element's <tt class="docutils literal"><span class="pre">font-size</span></tt>
attribute, defaults to <tt class="docutils literal">&quot;14px&quot;</tt>.</dd>
<dt><cite>xoffset</cite></dt>
<dd>Starting offset in X direction, defaults to <tt class="docutils literal">0</tt>.</dd>
<dt><cite>yoffset</cite></dt>
<dd>Starting offset in Y direction, defaults to the font size if it is given
in pixels, or <tt class="docutils literal">20</tt> else. (This is necessary since text coordinates
refer to the text baseline, not the top edge.)</dd>
<dt><cite>ystep</cite></dt>
<dd>Offset to add to the Y coordinate for each subsequent line. This should
roughly be the text size plus 5. It defaults to that value if the text
size is given in pixels, or <tt class="docutils literal">25</tt> else.</dd>
<dt><cite>spacehack</cite></dt>
<dd>Convert spaces in the source to <tt class="docutils literal">&amp;#160;</tt>, which are non-breaking
spaces. SVG provides the <tt class="docutils literal">xml:space</tt> attribute to control how
whitespace inside tags is handled, in theory, the <tt class="docutils literal">preserve</tt> value
could be used to keep all whitespace as-is. However, many current SVG
viewers don't obey that rule, so this option is provided as a workaround
and defaults to <tt class="docutils literal">True</tt>.</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">svg</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">*.svg</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="terminal256formatter">
<h4><cite>Terminal256Formatter</cite></h4>
<blockquote>
<p>Format tokens with ANSI color sequences, for output in a 256-color
terminal or console. Like in <cite>TerminalFormatter</cite> color sequences
are terminated at newlines, so that paging the output works correctly.</p>
<p>The formatter takes colors from a style defined by the <cite>style</cite> option
and converts them to nearest ANSI 256-color escape sequences. Bold and
underline attributes from the style are preserved (and displayed).</p>
<p><em>New in Pygments 0.9.</em></p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>style</cite></dt>
<dd>The style to use, can be a string or a Style subclass (default:
<tt class="docutils literal">'default'</tt>).</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">terminal256, console256, 256</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<div class="section" id="terminalformatter">
<h4><cite>TerminalFormatter</cite></h4>
<blockquote>
<p>Format tokens with ANSI color sequences, for output in a text console.
Color sequences are terminated at newlines, so that paging the output
works correctly.</p>
<p>The <cite>get_style_defs()</cite> method doesn't do anything special since there is
no support for common styles.</p>
<p>Options accepted:</p>
<dl class="docutils">
<dt><cite>bg</cite></dt>
<dd>Set to <tt class="docutils literal">&quot;light&quot;</tt> or <tt class="docutils literal">&quot;dark&quot;</tt> depending on the terminal's background
(default: <tt class="docutils literal">&quot;light&quot;</tt>).</dd>
<dt><cite>colorscheme</cite></dt>
<dd>A dictionary mapping token types to (lightbg, darkbg) color names or
<tt class="docutils literal">None</tt> (default: <tt class="docutils literal">None</tt> = use builtin colorscheme).</dd>
</dl>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Short names:</th><td class="field-body">terminal, console</td>
</tr>
<tr class="field"><th class="field-name">Filename patterns:</th><td class="field-body">None</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:42.651509
file id: formatters -->
</html>

View File

@ -1,261 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Overview &mdash; 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">Overview</h2>
<!-- -*- mode: rst -*- -->
<p>Welcome to the Pygments documentation.</p>
<ul class="simple">
<li>Starting with Pygments<ul>
<li><a class="reference external" href="./installation.html">Installation</a></li>
<li><a class="reference external" href="./quickstart.html">Introduction and Quickstart</a></li>
<li><a class="reference external" href="./cmdline.html">Command line interface</a></li>
</ul>
</li>
<li>Builtin components<ul>
<li><a class="reference external" href="./lexers.html">Lexers</a></li>
<li><a class="reference external" href="./formatters.html">Formatters</a></li>
<li><a class="reference external" href="./filters.html">Filters</a></li>
<li><a class="reference external" href="./styles.html">Styles</a></li>
</ul>
</li>
<li>Reference<ul>
<li><a class="reference external" href="./unicode.html">Unicode and encodings</a></li>
<li><a class="reference external" href="./tokens.html">Builtin tokens</a></li>
<li><a class="reference external" href="./api.html">API documentation</a></li>
</ul>
</li>
<li>Hacking for Pygments<ul>
<li><a class="reference external" href="./lexerdevelopment.html">Write your own lexer</a></li>
<li><a class="reference external" href="./formatterdevelopment.html">Write your own formatter</a></li>
<li><a class="reference external" href="./filterdevelopment.html">Write your own filter</a></li>
<li><a class="reference external" href="./plugins.html">Register plugins</a></li>
</ul>
</li>
<li>Hints and Tricks<ul>
<li><a class="reference external" href="./rstdirective.html">Using Pygments in ReST documents</a></li>
<li><a class="reference external" href="./moinmoin.html">Using Pygments with MoinMoin</a></li>
<li><a class="reference external" href="./integrate.html">Using Pygments in other contexts</a></li>
</ul>
</li>
<li>About Pygments<ul>
<li><a class="reference external" href="./changelog.html">Changelog</a></li>
<li><a class="reference external" href="./authors.html">Authors</a></li>
</ul>
</li>
</ul>
<hr class="docutils" />
<p>If you find bugs or have suggestions for the documentation, please
look <a class="reference external" href="http://pygments.org/contribute/">here</a> for info on how to contact the team.</p>
<p>You can download an offline version of this documentation from the
<a class="reference external" href="http://pygments.org/download/">download page</a>.</p>
</div>
</body>
<!-- generated on: 2013-02-03 10:39:02.732660
file id: index -->
</html>

View File

@ -1,281 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Installation &mdash; 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">Installation</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#installing-a-released-version">Installing a released version</a></li>
<li><a href="#installing-the-development-version">Installing the development version</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>Pygments requires at least Python 2.4 to work correctly. Just to clarify:
there <em>won't</em> ever be support for Python versions below 2.4. However, there
are no other dependencies.</p>
<div class="section" id="installing-a-released-version">
<h3>Installing a released version</h3>
<div class="section" id="as-a-python-egg-via-easy-install">
<h4>As a Python egg (via easy_install)</h4>
<p>You can install the most recent Pygments version using <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a>:</p>
<pre class="literal-block">
sudo easy_install Pygments
</pre>
<p>This will install a Pygments egg in your Python installation's site-packages
directory.</p>
</div>
<div class="section" id="from-the-tarball-release">
<h4>From the tarball release</h4>
<ol class="arabic simple">
<li>Download the most recent tarball from the <a class="reference external" href="http://pygments.org/download/">download page</a></li>
<li>Unpack the tarball</li>
<li><tt class="docutils literal">sudo python setup.py install</tt></li>
</ol>
<p>Note that the last command will automatically download and install
<a class="reference external" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> if you don't already have it installed. This requires a working
internet connection.</p>
<p>This will install Pygments into your Python installation's site-packages directory.</p>
</div>
</div>
<div class="section" id="installing-the-development-version">
<h3>Installing the development version</h3>
<div class="section" id="if-you-want-to-play-around-with-the-code">
<h4>If you want to play around with the code</h4>
<ol class="arabic simple">
<li>Install <a class="reference external" href="http://selenic.com/mercurial/">Mercurial</a></li>
<li><tt class="docutils literal">hg clone <span class="pre">http://bitbucket.org/birkenfeld/pygments-main</span> pygments</tt></li>
<li><tt class="docutils literal">cd pygments</tt></li>
<li><tt class="docutils literal">ln <span class="pre">-s</span> pygments <span class="pre">/usr/lib/python2.X/site-packages</span></tt></li>
<li><tt class="docutils literal">ln <span class="pre">-s</span> pygmentize /usr/local/bin</tt></li>
</ol>
<p>As an alternative to steps 4 and 5 you can also do <tt class="docutils literal">python setup.py develop</tt>
which will install the package via setuptools in development mode.</p>
<!-- If you just want the latest features and use them
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
::
sudo easy_install Pygments==dev
This will install a Pygments egg containing the latest Subversion trunk code
in your Python installation's site-packages directory. Every time the command
is run, the sources are updated from Subversion. -->
</div>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.375552
file id: installation -->
</html>

View File

@ -1,268 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Using Pygments in various scenarios &mdash; 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">Using Pygments in various scenarios</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#pygtk">PyGtk</a></li>
<li><a href="#wordpress">Wordpress</a></li>
<li><a href="#markdown">Markdown</a></li>
<li><a href="#textmate">TextMate</a></li>
<li><a href="#bash-completion">Bash completion</a></li>
<li><a href="#java">Java</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<div class="section" id="pygtk">
<h3>PyGtk</h3>
<p>Armin has written a piece of sample code that shows how to create a Gtk
<cite>TextBuffer</cite> object containing Pygments-highlighted text.</p>
<p>See the article here: <a class="reference external" href="http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-gtk-rendering/">http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-gtk-rendering/</a></p>
</div>
<div class="section" id="wordpress">
<h3>Wordpress</h3>
<p>He also has a snippet that shows how to use Pygments in WordPress:</p>
<p><a class="reference external" href="http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-in-wordpress/">http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-in-wordpress/</a></p>
</div>
<div class="section" id="markdown">
<h3>Markdown</h3>
<p>Since Pygments 0.9, the distribution ships <a class="reference external" href="http://www.freewisdom.org/projects/python-markdown/">Markdown</a> preprocessor sample code
that uses Pygments to render source code in <cite>external/markdown-processor.py</cite>.
You can copy and adapt it to your liking.</p>
</div>
<div class="section" id="textmate">
<h3>TextMate</h3>
<p>Antonio Cangiano has created a Pygments bundle for TextMate that allows to
colorize code via a simple menu option. It can be found <a class="reference external" href="http://antoniocangiano.com/2008/10/28/pygments-textmate-bundle/">here</a>.</p>
</div>
<div class="section" id="bash-completion">
<h3>Bash completion</h3>
<p>The source distribution contains a file <tt class="docutils literal">external/pygments.bashcomp</tt> that
sets up completion for the <tt class="docutils literal">pygmentize</tt> command in bash.</p>
</div>
<div class="section" id="java">
<h3>Java</h3>
<p>See the <a class="reference external" href="./java.html">Java quickstart</a> document.</p>
</div>
</div>
</body>
<!-- generated on: 2013-02-03 10:39:02.461007
file id: integrate -->
</html>

View File

@ -1,271 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Use Pygments in Java &mdash; 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">Use Pygments in Java</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<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">pom.xml</tt> file for a
project running Pygments:</p>
<div class="syntax"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="nt">&lt;project</span> <span class="na">xmlns=</span><span class="s">&quot;http://maven.apache.org/POM/4.0.0&quot;</span>
<span class="na">xmlns:xsi=</span><span class="s">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
<span class="na">xsi:schemaLocation=</span><span class="s">&quot;http://maven.apache.org/POM/4.0.0</span>
<span class="s"> http://maven.apache.org/maven-v4_0_0.xsd&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;modelVersion&gt;</span>4.0.0<span class="nt">&lt;/modelVersion&gt;</span>
<span class="nt">&lt;groupId&gt;</span>example<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>example<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>1.0-SNAPSHOT<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;dependencies&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.python<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>jython-standalone<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>2.5.3<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;dependency&gt;</span>
<span class="nt">&lt;groupId&gt;</span>org.pygments<span class="nt">&lt;/groupId&gt;</span>
<span class="nt">&lt;artifactId&gt;</span>pygments<span class="nt">&lt;/artifactId&gt;</span>
<span class="nt">&lt;version&gt;</span>1.5<span class="nt">&lt;/version&gt;</span>
<span class="nt">&lt;scope&gt;</span>runtime<span class="nt">&lt;/scope&gt;</span>
<span class="nt">&lt;/dependency&gt;</span>
<span class="nt">&lt;/dependencies&gt;</span>
<span class="nt">&lt;/project&gt;</span>
</pre></div>
<p>The following Java example:</p>
<div class="syntax"><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">&quot;code&quot;</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">&quot;from pygments import highlight\n&quot;</span>
<span class="o">+</span> <span class="s">&quot;from pygments.lexers import PythonLexer\n&quot;</span>
<span class="o">+</span> <span class="s">&quot;from pygments.formatters import HtmlFormatter\n&quot;</span>
<span class="o">+</span> <span class="s">&quot;\nresult = highlight(code, PythonLexer(), HtmlFormatter())&quot;</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">&quot;result&quot;</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>
<p>will print something like:</p>
<div class="syntax"><pre><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;highlight&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;pre&gt;&lt;span</span> <span class="na">class=</span><span class="s">&quot;k&quot;</span><span class="nt">&gt;</span>print<span class="nt">&lt;/span&gt;</span> <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;s&quot;</span><span class="nt">&gt;</span><span class="ni">&amp;quot;</span>Hello World<span class="ni">&amp;quot;</span><span class="nt">&lt;/span&gt;&lt;/pre&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</pre></div>
</div>
</body>
<!-- generated on: 2013-02-03 10:39:02.521367
file id: java -->
</html>

View File

@ -1,691 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Write your own lexer &mdash; 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">Write your own lexer</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#regexlexer">RegexLexer</a></li>
<li><a href="#regex-flags">Regex Flags</a></li>
<li><a href="#scanning-multiple-tokens-at-once">Scanning multiple tokens at once</a></li>
<li><a href="#changing-states">Changing states</a></li>
<li><a href="#advanced-state-tricks">Advanced state tricks</a></li>
<li><a href="#using-multiple-lexers">Using multiple lexers</a></li>
<li><a href="#delegating-lexer">Delegating Lexer</a></li>
<li><a href="#callbacks">Callbacks</a></li>
<li><a href="#the-extendedregexlexer-class">The ExtendedRegexLexer class</a></li>
<li><a href="#filtering-token-streams">Filtering Token Streams</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>If a lexer for your favorite language is missing in the Pygments package, you can
easily write your own and extend Pygments.</p>
<p>All you need can be found inside the <cite>pygments.lexer</cite> module. As you can read in
the <a class="reference external" href="./api.html">API documentation</a>, a lexer is a class that is initialized with
some keyword arguments (the lexer options) and that provides a
<cite>get_tokens_unprocessed()</cite> method which is given a string or unicode object with
the data to parse.</p>
<p>The <cite>get_tokens_unprocessed()</cite> method must return an iterator or iterable
containing tuples in the form <tt class="docutils literal">(index, token, value)</tt>. Normally you don't need
to do this since there are numerous base lexers you can subclass.</p>
<div class="section" id="regexlexer">
<h3>RegexLexer</h3>
<p>A very powerful (but quite easy to use) lexer is the <cite>RegexLexer</cite>. This lexer
base class allows you to define lexing rules in terms of <em>regular expressions</em>
for different <em>states</em>.</p>
<p>States are groups of regular expressions that are matched against the input
string at the <em>current position</em>. If one of these expressions matches, a
corresponding action is performed (normally yielding a token with a specific
type), the current position is set to where the last match ended and the
matching process continues with the first regex of the current state.</p>
<p>Lexer states are kept in a state stack: each time a new state is entered, the
new state is pushed onto the stack. The most basic lexers (like the
<cite>DiffLexer</cite>) just need one state.</p>
<p>Each state is defined as a list of tuples in the form (<cite>regex</cite>, <cite>action</cite>,
<cite>new_state</cite>) where the last item is optional. In the most basic form, <cite>action</cite>
is a token type (like <cite>Name.Builtin</cite>). That means: When <cite>regex</cite> matches, emit a
token with the match text and type <cite>tokentype</cite> and push <cite>new_state</cite> on the state
stack. If the new state is <tt class="docutils literal">'#pop'</tt>, the topmost state is popped from the
stack instead. (To pop more than one state, use <tt class="docutils literal">'#pop:2'</tt> and so on.)
<tt class="docutils literal">'#push'</tt> is a synonym for pushing the current state on the
stack.</p>
<p>The following example shows the <cite>DiffLexer</cite> from the builtin lexers. Note that
it contains some additional attributes <cite>name</cite>, <cite>aliases</cite> and <cite>filenames</cite> which
aren't required for a lexer. They are used by the builtin lexer lookup
functions.</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">class</span> <span class="nc">DiffLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">&#39;Diff&#39;</span>
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;diff&#39;</span><span class="p">]</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;*.diff&#39;</span><span class="p">]</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39; .*\n&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;\+.*\n&#39;</span><span class="p">,</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Inserted</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;-.*\n&#39;</span><span class="p">,</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Deleted</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;@.*\n&#39;</span><span class="p">,</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Subheading</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;Index.*\n&#39;</span><span class="p">,</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Heading</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;=.*\n&#39;</span><span class="p">,</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Heading</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;.*\n&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>As you can see this lexer only uses one state. When the lexer starts scanning
the text, it first checks if the current character is a space. If this is true
it scans everything until newline and returns the parsed data as <cite>Text</cite> token.</p>
<p>If this rule doesn't match, it checks if the current char is a plus sign. And
so on.</p>
<p>If no rule matches at the current position, the current char is emitted as an
<cite>Error</cite> token that indicates a parsing error, and the position is increased by
1.</p>
</div>
<div class="section" id="regex-flags">
<h3>Regex Flags</h3>
<p>You can either define regex flags in the regex (<tt class="docutils literal"><span class="pre">r'(?x)foo</span> bar'</tt>) or by adding
a <cite>flags</cite> attribute to your lexer class. If no attribute is defined, it defaults
to <cite>re.MULTILINE</cite>. For more informations about regular expression flags see the
<a class="reference external" href="http://docs.python.org/lib/re-syntax.html">regular expressions</a> help page in the python documentation.</p>
</div>
<div class="section" id="scanning-multiple-tokens-at-once">
<h3>Scanning multiple tokens at once</h3>
<p>Here is a more complex lexer that highlights INI files. INI files consist of
sections, comments and key = value pairs:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span><span class="p">,</span> <span class="n">bygroups</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">class</span> <span class="nc">IniLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">&#39;INI&#39;</span>
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;ini&#39;</span><span class="p">,</span> <span class="s">&#39;cfg&#39;</span><span class="p">]</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;*.ini&#39;</span><span class="p">,</span> <span class="s">&#39;*.cfg&#39;</span><span class="p">]</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;\s+&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;;.*?$&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;\[.*?\]$&#39;</span><span class="p">,</span> <span class="n">Keyword</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;(.*?)(\s*)(=)(\s*)(.*?)$&#39;</span><span class="p">,</span>
<span class="n">bygroups</span><span class="p">(</span><span class="n">Name</span><span class="o">.</span><span class="n">Attribute</span><span class="p">,</span> <span class="n">Text</span><span class="p">,</span> <span class="n">Operator</span><span class="p">,</span> <span class="n">Text</span><span class="p">,</span> <span class="n">String</span><span class="p">))</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>The lexer first looks for whitespace, comments and section names. And later it
looks for a line that looks like a key, value pair, separated by an <tt class="docutils literal">'='</tt>
sign, and optional whitespace.</p>
<p>The <cite>bygroups</cite> helper makes sure that each group is yielded with a different
token type. First the <cite>Name.Attribute</cite> token, then a <cite>Text</cite> token for the
optional whitespace, after that a <cite>Operator</cite> token for the equals sign. Then a
<cite>Text</cite> token for the whitespace again. The rest of the line is returned as
<cite>String</cite>.</p>
<p>Note that for this to work, every part of the match must be inside a capturing
group (a <tt class="docutils literal"><span class="pre">(...)</span></tt>), and there must not be any nested capturing groups. If you
nevertheless need a group, use a non-capturing group defined using this syntax:
<tt class="docutils literal"><span class="pre">r'(?:some|words|here)'</span></tt> (note the <tt class="docutils literal"><span class="pre">?:</span></tt> after the beginning parenthesis).</p>
<p>If you find yourself needing a capturing group inside the regex which
shouldn't be part of the output but is used in the regular expressions for
backreferencing (eg: <tt class="docutils literal"><span class="pre">r'(&lt;(foo|bar)&gt;)(.*?)(&lt;/\2&gt;)'</span></tt>), you can pass <cite>None</cite>
to the bygroups function and it will skip that group will be skipped in the
output.</p>
</div>
<div class="section" id="changing-states">
<h3>Changing states</h3>
<p>Many lexers need multiple states to work as expected. For example, some
languages allow multiline comments to be nested. Since this is a recursive
pattern it's impossible to lex just using regular expressions.</p>
<p>Here is the solution:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">class</span> <span class="nc">ExampleLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">&#39;Example Lexer with states&#39;</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;[^/]+&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;/\*&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multiline</span><span class="p">,</span> <span class="s">&#39;comment&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;//.*?$&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Singleline</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;/&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">)</span>
<span class="p">],</span>
<span class="s">&#39;comment&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;[^*/]&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multiline</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;/\*&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multiline</span><span class="p">,</span> <span class="s">&#39;#push&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;\*/&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multiline</span><span class="p">,</span> <span class="s">&#39;#pop&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;[*/]&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multiline</span><span class="p">)</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>This lexer starts lexing in the <tt class="docutils literal">'root'</tt> state. It tries to match as much as
possible until it finds a slash (<tt class="docutils literal">'/'</tt>). If the next character after the slash
is a star (<tt class="docutils literal">'*'</tt>) the <cite>RegexLexer</cite> sends those two characters to the output
stream marked as <cite>Comment.Multiline</cite> and continues parsing with the rules
defined in the <tt class="docutils literal">'comment'</tt> state.</p>
<p>If there wasn't a star after the slash, the <cite>RegexLexer</cite> checks if it's a
singleline comment (eg: followed by a second slash). If this also wasn't the
case it must be a single slash (the separate regex for a single slash must also
be given, else the slash would be marked as an error token).</p>
<p>Inside the <tt class="docutils literal">'comment'</tt> state, we do the same thing again. Scan until the lexer
finds a star or slash. If it's the opening of a multiline comment, push the
<tt class="docutils literal">'comment'</tt> state on the stack and continue scanning, again in the
<tt class="docutils literal">'comment'</tt> state. Else, check if it's the end of the multiline comment. If
yes, pop one state from the stack.</p>
<p>Note: If you pop from an empty stack you'll get an <cite>IndexError</cite>. (There is an
easy way to prevent this from happening: don't <tt class="docutils literal">'#pop'</tt> in the root state).</p>
<p>If the <cite>RegexLexer</cite> encounters a newline that is flagged as an error token, the
stack is emptied and the lexer continues scanning in the <tt class="docutils literal">'root'</tt> state. This
helps producing error-tolerant highlighting for erroneous input, e.g. when a
single-line string is not closed.</p>
</div>
<div class="section" id="advanced-state-tricks">
<h3>Advanced state tricks</h3>
<p>There are a few more things you can do with states:</p>
<ul>
<li><p class="first">You can push multiple states onto the stack if you give a tuple instead of a
simple string as the third item in a rule tuple. For example, if you want to
match a comment containing a directive, something like:</p>
<pre class="literal-block">
/* &lt;processing directive&gt; rest of comment */
</pre>
<p>you can use this rule:</p>
<div class="syntax"><pre><span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;/\* &lt;&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">,</span> <span class="p">(</span><span class="s">&#39;comment&#39;</span><span class="p">,</span> <span class="s">&#39;directive&#39;</span><span class="p">)),</span>
<span class="o">...</span>
<span class="p">],</span>
<span class="s">&#39;directive&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;[^&gt;]*&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Directive</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;&gt;&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">,</span> <span class="s">&#39;#pop&#39;</span><span class="p">),</span>
<span class="p">],</span>
<span class="s">&#39;comment&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;[^*]+&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;\*/&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">,</span> <span class="s">&#39;#pop&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;\*&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">),</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>When this encounters the above sample, first <tt class="docutils literal">'comment'</tt> and <tt class="docutils literal">'directive'</tt>
are pushed onto the stack, then the lexer continues in the directive state
until it finds the closing <tt class="docutils literal">&gt;</tt>, then it continues in the comment state until
the closing <tt class="docutils literal">*/</tt>. Then, both states are popped from the stack again and
lexing continues in the root state.</p>
<p><em>New in Pygments 0.9:</em> The tuple can contain the special <tt class="docutils literal">'#push'</tt> and
<tt class="docutils literal">'#pop'</tt> (but not <tt class="docutils literal">'#pop:n'</tt>) directives.</p>
</li>
<li><p class="first">You can include the rules of a state in the definition of another. This is
done by using <cite>include</cite> from <cite>pygments.lexer</cite>:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span><span class="p">,</span> <span class="n">bygroups</span><span class="p">,</span> <span class="n">include</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="o">*</span>
<span class="k">class</span> <span class="nc">ExampleLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;comments&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;/\*.*?\*/&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;//.*?\n&#39;</span><span class="p">,</span> <span class="n">Comment</span><span class="p">),</span>
<span class="p">],</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="n">include</span><span class="p">(</span><span class="s">&#39;comments&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;(function )(\w+)( {)&#39;</span><span class="p">,</span>
<span class="n">bygroups</span><span class="p">(</span><span class="n">Keyword</span><span class="p">,</span> <span class="n">Name</span><span class="p">,</span> <span class="n">Keyword</span><span class="p">),</span> <span class="s">&#39;function&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;.&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">],</span>
<span class="s">&#39;function&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;[^}/]+&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="n">include</span><span class="p">(</span><span class="s">&#39;comments&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;/&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;}&#39;</span><span class="p">,</span> <span class="n">Keyword</span><span class="p">,</span> <span class="s">&#39;#pop&#39;</span><span class="p">),</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>This is a hypothetical lexer for a language that consist of functions and
comments. Because comments can occur at toplevel and in functions, we need
rules for comments in both states. As you can see, the <cite>include</cite> helper saves
repeating rules that occur more than once (in this example, the state
<tt class="docutils literal">'comment'</tt> will never be entered by the lexer, as it's only there to be
included in <tt class="docutils literal">'root'</tt> and <tt class="docutils literal">'function'</tt>).</p>
</li>
<li><p class="first">Sometimes, you may want to &quot;combine&quot; a state from existing ones. This is
possible with the <cite>combine</cite> helper from <cite>pygments.lexer</cite>.</p>
<p>If you, instead of a new state, write <tt class="docutils literal"><span class="pre">combined('state1',</span> 'state2')</tt> as the
third item of a rule tuple, a new anonymous state will be formed from state1
and state2 and if the rule matches, the lexer will enter this state.</p>
<p>This is not used very often, but can be helpful in some cases, such as the
<cite>PythonLexer</cite>'s string literal processing.</p>
</li>
<li><p class="first">If you want your lexer to start lexing in a different state you can modify
the stack by overloading the <cite>get_tokens_unprocessed()</cite> method:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span>
<span class="k">class</span> <span class="nc">MyLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span><span class="o">...</span><span class="p">}</span>
<span class="k">def</span> <span class="nf">get_tokens_unprocessed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
<span class="n">stack</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;root&#39;</span><span class="p">,</span> <span class="s">&#39;otherstate&#39;</span><span class="p">]</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">RegexLexer</span><span class="o">.</span><span class="n">get_tokens_unprocessed</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">stack</span><span class="p">):</span>
<span class="k">yield</span> <span class="n">item</span>
</pre></div>
<p>Some lexers like the <cite>PhpLexer</cite> use this to make the leading <tt class="docutils literal"><span class="pre">&lt;?php</span></tt>
preprocessor comments optional. Note that you can crash the lexer easily
by putting values into the stack that don't exist in the token map. Also
removing <tt class="docutils literal">'root'</tt> from the stack can result in strange errors!</p>
</li>
<li><p class="first">An empty regex at the end of a state list, combined with <tt class="docutils literal">'#pop'</tt>, can
act as a return point from a state that doesn't have a clear end marker.</p>
</li>
</ul>
</div>
<div class="section" id="using-multiple-lexers">
<h3>Using multiple lexers</h3>
<p>Using multiple lexers for the same input can be tricky. One of the easiest
combination techniques is shown here: You can replace the token type entry in a
rule tuple (the second item) with a lexer class. The matched text will then be
lexed with that lexer, and the resulting tokens will be yielded.</p>
<p>For example, look at this stripped-down HTML lexer:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span><span class="p">,</span> <span class="n">bygroups</span><span class="p">,</span> <span class="n">using</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">pygments.lexers.web</span> <span class="kn">import</span> <span class="n">JavascriptLexer</span>
<span class="k">class</span> <span class="nc">HtmlLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">&#39;HTML&#39;</span>
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;html&#39;</span><span class="p">]</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;*.html&#39;</span><span class="p">,</span> <span class="s">&#39;*.htm&#39;</span><span class="p">]</span>
<span class="n">flags</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">IGNORECASE</span> <span class="o">|</span> <span class="n">re</span><span class="o">.</span><span class="n">DOTALL</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">&#39;[^&lt;&amp;]+&#39;</span><span class="p">,</span> <span class="n">Text</span><span class="p">),</span>
<span class="p">(</span><span class="s">&#39;&amp;.*?;&#39;</span><span class="p">,</span> <span class="n">Name</span><span class="o">.</span><span class="n">Entity</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;&lt;\s*script\s*&#39;</span><span class="p">,</span> <span class="n">Name</span><span class="o">.</span><span class="n">Tag</span><span class="p">,</span> <span class="p">(</span><span class="s">&#39;script-content&#39;</span><span class="p">,</span> <span class="s">&#39;tag&#39;</span><span class="p">)),</span>
<span class="p">(</span><span class="s">r&#39;&lt;\s*[a-zA-Z0-9:]+&#39;</span><span class="p">,</span> <span class="n">Name</span><span class="o">.</span><span class="n">Tag</span><span class="p">,</span> <span class="s">&#39;tag&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s">r&#39;&lt;\s*/\s*[a-zA-Z0-9:]+\s*&gt;&#39;</span><span class="p">,</span> <span class="n">Name</span><span class="o">.</span><span class="n">Tag</span><span class="p">),</span>
<span class="p">],</span>
<span class="s">&#39;script-content&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;(.+?)(&lt;\s*/\s*script\s*&gt;)&#39;</span><span class="p">,</span>
<span class="n">bygroups</span><span class="p">(</span><span class="n">using</span><span class="p">(</span><span class="n">JavascriptLexer</span><span class="p">),</span> <span class="n">Name</span><span class="o">.</span><span class="n">Tag</span><span class="p">),</span>
<span class="s">&#39;#pop&#39;</span><span class="p">),</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>Here the content of a <tt class="docutils literal">&lt;script&gt;</tt> tag is passed to a newly created instance of
a <cite>JavascriptLexer</cite> and not processed by the <cite>HtmlLexer</cite>. This is done using the
<cite>using</cite> helper that takes the other lexer class as its parameter.</p>
<p>Note the combination of <cite>bygroups</cite> and <cite>using</cite>. This makes sure that the content
up to the <tt class="docutils literal">&lt;/script&gt;</tt> end tag is processed by the <cite>JavascriptLexer</cite>, while the
end tag is yielded as a normal token with the <cite>Name.Tag</cite> type.</p>
<p>As an additional goodie, if the lexer class is replaced by <cite>this</cite> (imported from
<cite>pygments.lexer</cite>), the &quot;other&quot; lexer will be the current one (because you cannot
refer to the current class within the code that runs at class definition time).</p>
<p>Also note the <tt class="docutils literal"><span class="pre">(r'&lt;\s*script\s*',</span> Name.Tag, <span class="pre">('script-content',</span> <span class="pre">'tag'))</span></tt> rule.
Here, two states are pushed onto the state stack, <tt class="docutils literal"><span class="pre">'script-content'</span></tt> and
<tt class="docutils literal">'tag'</tt>. That means that first <tt class="docutils literal">'tag'</tt> is processed, which will parse
attributes and the closing <tt class="docutils literal">&gt;</tt>, then the <tt class="docutils literal">'tag'</tt> state is popped and the
next state on top of the stack will be <tt class="docutils literal"><span class="pre">'script-content'</span></tt>.</p>
<p>The <cite>using()</cite> helper has a special keyword argument, <cite>state</cite>, which works as
follows: if given, the lexer to use initially is not in the <tt class="docutils literal">&quot;root&quot;</tt> state,
but in the state given by this argument. This <em>only</em> works with a <cite>RegexLexer</cite>.</p>
<p>Any other keywords arguments passed to <cite>using()</cite> are added to the keyword
arguments used to create the lexer.</p>
</div>
<div class="section" id="delegating-lexer">
<h3>Delegating Lexer</h3>
<p>Another approach for nested lexers is the <cite>DelegatingLexer</cite> which is for
example used for the template engine lexers. It takes two lexers as
arguments on initialisation: a <cite>root_lexer</cite> and a <cite>language_lexer</cite>.</p>
<p>The input is processed as follows: First, the whole text is lexed with the
<cite>language_lexer</cite>. All tokens yielded with a type of <tt class="docutils literal">Other</tt> are then
concatenated and given to the <cite>root_lexer</cite>. The language tokens of the
<cite>language_lexer</cite> are then inserted into the <cite>root_lexer</cite>'s token stream
at the appropriate positions.</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">DelegatingLexer</span>
<span class="kn">from</span> <span class="nn">pygments.lexers.web</span> <span class="kn">import</span> <span class="n">HtmlLexer</span><span class="p">,</span> <span class="n">PhpLexer</span>
<span class="k">class</span> <span class="nc">HtmlPhpLexer</span><span class="p">(</span><span class="n">DelegatingLexer</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__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="nb">super</span><span class="p">(</span><span class="n">HtmlPhpLexer</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">HtmlLexer</span><span class="p">,</span> <span class="n">PhpLexer</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
</pre></div>
<p>This procedure ensures that e.g. HTML with template tags in it is highlighted
correctly even if the template tags are put into HTML tags or attributes.</p>
<p>If you want to change the needle token <tt class="docutils literal">Other</tt> to something else, you can
give the lexer another token type as the third parameter:</p>
<div class="syntax"><pre><span class="n">DelegatingLexer</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">MyLexer</span><span class="p">,</span> <span class="n">OtherLexer</span><span class="p">,</span> <span class="n">Text</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="callbacks">
<h3>Callbacks</h3>
<p>Sometimes the grammar of a language is so complex that a lexer would be unable
to parse it just by using regular expressions and stacks.</p>
<p>For this, the <cite>RegexLexer</cite> allows callbacks to be given in rule tuples, instead
of token types (<cite>bygroups</cite> and <cite>using</cite> are nothing else but preimplemented
callbacks). The callback must be a function taking two arguments:</p>
<ul class="simple">
<li>the lexer itself</li>
<li>the match object for the last matched rule</li>
</ul>
<p>The callback must then return an iterable of (or simply yield) <tt class="docutils literal">(index,
tokentype, value)</tt> tuples, which are then just passed through by
<cite>get_tokens_unprocessed()</cite>. The <tt class="docutils literal">index</tt> here is the position of the token in
the input string, <tt class="docutils literal">tokentype</tt> is the normal token type (like <cite>Name.Builtin</cite>),
and <tt class="docutils literal">value</tt> the associated part of the input string.</p>
<p>You can see an example here:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">RegexLexer</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Generic</span>
<span class="k">class</span> <span class="nc">HypotheticLexer</span><span class="p">(</span><span class="n">RegexLexer</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">headline_callback</span><span class="p">(</span><span class="n">lexer</span><span class="p">,</span> <span class="n">match</span><span class="p">):</span>
<span class="n">equal_signs</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">text</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">yield</span> <span class="n">match</span><span class="o">.</span><span class="n">start</span><span class="p">(),</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Headline</span><span class="p">,</span> <span class="n">equal_signs</span> <span class="o">+</span> <span class="n">text</span> <span class="o">+</span> <span class="n">equal_signs</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;(=+)(.*?)(\1)&#39;</span><span class="p">,</span> <span class="n">headline_callback</span><span class="p">)</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>If the regex for the <cite>headline_callback</cite> matches, the function is called with the
match object. Note that after the callback is done, processing continues
normally, that is, after the end of the previous match. The callback has no
possibility to influence the position.</p>
<p>There are not really any simple examples for lexer callbacks, but you can see
them in action e.g. in the <a class="reference external" href="http://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/compiled.py">compiled.py</a> source code in the <cite>CLexer</cite> and
<cite>JavaLexer</cite> classes.</p>
</div>
<div class="section" id="the-extendedregexlexer-class">
<h3>The ExtendedRegexLexer class</h3>
<p>The <cite>RegexLexer</cite>, even with callbacks, unfortunately isn't powerful enough for
the funky syntax rules of some languages that will go unnamed, such as Ruby.</p>
<p>But fear not; even then you don't have to abandon the regular expression
approach. For Pygments has a subclass of <cite>RegexLexer</cite>, the <cite>ExtendedRegexLexer</cite>.
All features known from RegexLexers are available here too, and the tokens are
specified in exactly the same way, <em>except</em> for one detail:</p>
<p>The <cite>get_tokens_unprocessed()</cite> method holds its internal state data not as local
variables, but in an instance of the <cite>pygments.lexer.LexerContext</cite> class, and
that instance is passed to callbacks as a third argument. This means that you
can modify the lexer state in callbacks.</p>
<p>The <cite>LexerContext</cite> class has the following members:</p>
<ul class="simple">
<li><cite>text</cite> -- the input text</li>
<li><cite>pos</cite> -- the current starting position that is used for matching regexes</li>
<li><cite>stack</cite> -- a list containing the state stack</li>
<li><cite>end</cite> -- the maximum position to which regexes are matched, this defaults to
the length of <cite>text</cite></li>
</ul>
<p>Additionally, the <cite>get_tokens_unprocessed()</cite> method can be given a
<cite>LexerContext</cite> instead of a string and will then process this context instead of
creating a new one for the string argument.</p>
<p>Note that because you can set the current position to anything in the callback,
it won't be automatically be set by the caller after the callback is finished.
For example, this is how the hypothetical lexer above would be written with the
<cite>ExtendedRegexLexer</cite>:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexer</span> <span class="kn">import</span> <span class="n">ExtendedRegexLexer</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Generic</span>
<span class="k">class</span> <span class="nc">ExHypotheticLexer</span><span class="p">(</span><span class="n">ExtendedRegexLexer</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">headline_callback</span><span class="p">(</span><span class="n">lexer</span><span class="p">,</span> <span class="n">match</span><span class="p">,</span> <span class="n">ctx</span><span class="p">):</span>
<span class="n">equal_signs</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">text</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">yield</span> <span class="n">match</span><span class="o">.</span><span class="n">start</span><span class="p">(),</span> <span class="n">Generic</span><span class="o">.</span><span class="n">Headline</span><span class="p">,</span> <span class="n">equal_signs</span> <span class="o">+</span> <span class="n">text</span> <span class="o">+</span> <span class="n">equal_signs</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">pos</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">end</span><span class="p">()</span>
<span class="n">tokens</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">&#39;root&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="p">(</span><span class="s">r&#39;(=+)(.*?)(\1)&#39;</span><span class="p">,</span> <span class="n">headline_callback</span><span class="p">)</span>
<span class="p">]</span>
<span class="p">}</span>
</pre></div>
<p>This might sound confusing (and it can really be). But it is needed, and for an
example look at the Ruby lexer in <a class="reference external" href="https://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/agile.py">agile.py</a>.</p>
</div>
<div class="section" id="filtering-token-streams">
<h3>Filtering Token Streams</h3>
<p>Some languages ship a lot of builtin functions (for example PHP). The total
amount of those functions differs from system to system because not everybody
has every extension installed. In the case of PHP there are over 3000 builtin
functions. That's an incredible huge amount of functions, much more than you
can put into a regular expression.</p>
<p>But because only <cite>Name</cite> tokens can be function names it's solvable by overriding
the <tt class="docutils literal">get_tokens_unprocessed()</tt> method. The following lexer subclasses the
<cite>PythonLexer</cite> so that it highlights some additional names as pseudo keywords:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexers.agile</span> <span class="kn">import</span> <span class="n">PythonLexer</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Name</span><span class="p">,</span> <span class="n">Keyword</span>
<span class="k">class</span> <span class="nc">MyPythonLexer</span><span class="p">(</span><span class="n">PythonLexer</span><span class="p">):</span>
<span class="n">EXTRA_KEYWORDS</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;foo&#39;</span><span class="p">,</span> <span class="s">&#39;bar&#39;</span><span class="p">,</span> <span class="s">&#39;foobar&#39;</span><span class="p">,</span> <span class="s">&#39;barfoo&#39;</span><span class="p">,</span> <span class="s">&#39;spam&#39;</span><span class="p">,</span> <span class="s">&#39;eggs&#39;</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">get_tokens_unprocessed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">PythonLexer</span><span class="o">.</span><span class="n">get_tokens_unprocessed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
<span class="k">if</span> <span class="n">token</span> <span class="ow">is</span> <span class="n">Name</span> <span class="ow">and</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">EXTRA_KEYWORDS</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">index</span><span class="p">,</span> <span class="n">Keyword</span><span class="o">.</span><span class="n">Pseudo</span><span class="p">,</span> <span class="n">value</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">index</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">value</span>
</pre></div>
<p>The <cite>PhpLexer</cite> and <cite>LuaLexer</cite> use this method to resolve builtin functions.</p>
<p><strong>Note</strong> Do not confuse this with the <a class="reference external" href="./filters.html">filter</a> system.</p>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:42.356609
file id: lexerdevelopment -->
</html>

File diff suppressed because it is too large Load Diff

View File

@ -1,245 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Using Pygments with MoinMoin &mdash; 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">Using Pygments with MoinMoin</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<!-- -*- mode: rst -*- -->
<p>From Pygments 0.7, the source distribution ships a <a class="reference external" href="http://moinmoin.wikiwikiweb.de/">Moin</a> parser plugin that
can be used to get Pygments highlighting in Moin wiki pages.</p>
<p>To use it, copy the file <cite>external/moin-parser.py</cite> from the Pygments
distribution to the <cite>data/plugin/parser</cite> subdirectory of your Moin instance.
Edit the options at the top of the file (currently <tt class="docutils literal">ATTACHMENTS</tt> and
<tt class="docutils literal">INLINESTYLES</tt>) and rename the file to the name that the parser directive
should have. For example, if you name the file <tt class="docutils literal">code.py</tt>, you can get a
highlighted Python code sample with this Wiki markup:</p>
<pre class="literal-block">
{{{
#!code python
[...]
}}}
</pre>
<p>where <tt class="docutils literal">python</tt> is the Pygments name of the lexer to use.</p>
<p>Additionally, if you set the <tt class="docutils literal">ATTACHMENTS</tt> option to True, Pygments will also
be called for all attachments for whose filenames there is no other parser
registered.</p>
<p>You are responsible for including CSS rules that will map the Pygments CSS
classes to colors. You can output a stylesheet file with <cite>pygmentize</cite>, put it
into the <cite>htdocs</cite> directory of your Moin instance and then include it in the
<cite>stylesheets</cite> configuration option in the Moin config, e.g.:</p>
<pre class="literal-block">
stylesheets = [('screen', '/htdocs/pygments.css')]
</pre>
<p>If you do not want to do that and are willing to accept larger HTML output, you
can set the <tt class="docutils literal">INLINESTYLES</tt> option to True.</p>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.122842
file id: moinmoin -->
</html>

View File

@ -1,294 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Register Plugins &mdash; 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">Register Plugins</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#entrypoints">Entrypoints</a></li>
<li><a href="#how-to-use-entrypoints">How To Use Entrypoints</a></li>
<li><a href="#extending-the-core">Extending The Core</a></li>
</ul>
</div>
<p>If you want to extend Pygments without hacking the sources, but want to
use the lexer/formatter/style/filter lookup functions (<cite>lexers.get_lexer_by_name</cite>
et al.), you can use <a class="reference external" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> entrypoints to add new lexers, formatters
or styles as if they were in the Pygments core.</p>
<p>That means you can use your highlighter modules with the <cite>pygmentize</cite> script,
which relies on the mentioned functions.</p>
<div class="section" id="entrypoints">
<h3>Entrypoints</h3>
<p>Here is a list of setuptools entrypoints that Pygments understands:</p>
<p><cite>pygments.lexers</cite></p>
<blockquote>
<p>This entrypoint is used for adding new lexers to the Pygments core.
The name of the entrypoint values doesn't really matter, Pygments extracts
required metadata from the class definition:</p>
<div class="syntax"><pre><span class="k">[pygments.lexers]</span>
<span class="na">yourlexer</span> <span class="o">=</span> <span class="s">yourmodule:YourLexer</span>
</pre></div>
<p>Note that you have to define <tt class="docutils literal">name</tt>, <tt class="docutils literal">aliases</tt> and <tt class="docutils literal">filename</tt>
attributes so that you can use the highlighter from the command line:</p>
<div class="syntax"><pre><span class="k">class</span> <span class="nc">YourLexer</span><span class="p">(</span><span class="o">...</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s">&#39;Name Of Your Lexer&#39;</span>
<span class="n">aliases</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;alias&#39;</span><span class="p">]</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;*.ext&#39;</span><span class="p">]</span>
</pre></div>
</blockquote>
<p><cite>pygments.formatters</cite></p>
<blockquote>
<p>You can use this entrypoint to add new formatters to Pygments. The
name of an entrypoint item is the name of the formatter. If you
prefix the name with a slash it's used as a filename pattern:</p>
<div class="syntax"><pre><span class="k">[pygments.formatters]</span>
<span class="na">yourformatter</span> <span class="o">=</span> <span class="s">yourmodule:YourFormatter</span>
<span class="na">/.ext</span> <span class="o">=</span> <span class="s">yourmodule:YourFormatter</span>
</pre></div>
</blockquote>
<p><cite>pygments.styles</cite></p>
<blockquote>
<p>To add a new style you can use this entrypoint. The name of the entrypoint
is the name of the style:</p>
<div class="syntax"><pre><span class="k">[pygments.styles]</span>
<span class="na">yourstyle</span> <span class="o">=</span> <span class="s">yourmodule:YourStyle</span>
</pre></div>
</blockquote>
<p><cite>pygments.filters</cite></p>
<blockquote>
<p>Use this entrypoint to register a new filter. The name of the
entrypoint is the name of the filter:</p>
<div class="syntax"><pre><span class="k">[pygments.filters]</span>
<span class="na">yourfilter</span> <span class="o">=</span> <span class="s">yourmodule:YourFilter</span>
</pre></div>
</blockquote>
</div>
<div class="section" id="how-to-use-entrypoints">
<h3>How To Use Entrypoints</h3>
<p>This documentation doesn't explain how to use those entrypoints because this is
covered in the <a class="reference external" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools documentation</a>. That page should cover everything
you need to write a plugin.</p>
</div>
<div class="section" id="extending-the-core">
<h3>Extending The Core</h3>
<p>If you have written a Pygments plugin that is open source, please inform us
about that. There is a high chance that we'll add it to the Pygments
distribution.</p>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.232227
file id: plugins -->
</html>

View File

@ -1,390 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Introduction and Quickstart &mdash; 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">Introduction and Quickstart</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#architecture">Architecture</a></li>
<li><a href="#example">Example</a></li>
<li><a href="#options">Options</a></li>
<li><a href="#lexer-and-formatter-lookup">Lexer and formatter lookup</a></li>
<li><a href="#guessing-lexers">Guessing lexers</a></li>
<li><a href="#command-line-usage">Command line usage</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>Welcome to Pygments! This document explains the basic concepts and terms and
gives a few examples of how to use the library.</p>
<div class="section" id="architecture">
<h3>Architecture</h3>
<p>There are four types of components that work together highlighting a piece of
code:</p>
<ul class="simple">
<li>A <strong>lexer</strong> splits the source into tokens, fragments of the source that
have a token type that determines what the text represents semantically
(e.g., keyword, string, or comment). There is a lexer for every language
or markup format that Pygments supports.</li>
<li>The token stream can be piped through <strong>filters</strong>, which usually modify
the token types or text fragments, e.g. uppercasing all keywords.</li>
<li>A <strong>formatter</strong> then takes the token stream and writes it to an output
file, in a format such as HTML, LaTeX or RTF.</li>
<li>While writing the output, a <strong>style</strong> determines how to highlight all the
different token types. It maps them to attributes like &quot;red and bold&quot;.</li>
</ul>
</div>
<div class="section" id="example">
<h3>Example</h3>
<p>Here is a small example for highlighting Python code:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments</span> <span class="kn">import</span> <span class="n">highlight</span>
<span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">PythonLexer</span>
<span class="kn">from</span> <span class="nn">pygments.formatters</span> <span class="kn">import</span> <span class="n">HtmlFormatter</span>
<span class="n">code</span> <span class="o">=</span> <span class="s">&#39;print &quot;Hello World&quot;&#39;</span>
<span class="k">print</span> <span class="n">highlight</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">PythonLexer</span><span class="p">(),</span> <span class="n">HtmlFormatter</span><span class="p">())</span>
</pre></div>
<p>which prints something like this:</p>
<div class="syntax"><pre><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;highlight&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;pre&gt;&lt;span</span> <span class="na">class=</span><span class="s">&quot;k&quot;</span><span class="nt">&gt;</span>print<span class="nt">&lt;/span&gt;</span> <span class="nt">&lt;span</span> <span class="na">class=</span><span class="s">&quot;s&quot;</span><span class="nt">&gt;</span><span class="ni">&amp;quot;</span>Hello World<span class="ni">&amp;quot;</span><span class="nt">&lt;/span&gt;&lt;/pre&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</pre></div>
<p>As you can see, Pygments uses CSS classes (by default, but you can change that)
instead of inline styles in order to avoid outputting redundant style information over
and over. A CSS stylesheet that contains all CSS classes possibly used in the output
can be produced by:</p>
<div class="syntax"><pre><span class="k">print</span> <span class="n">HtmlFormatter</span><span class="p">()</span><span class="o">.</span><span class="n">get_style_defs</span><span class="p">(</span><span class="s">&#39;.highlight&#39;</span><span class="p">)</span>
</pre></div>
<p>The argument to <cite>get_style_defs</cite> is used as an additional CSS selector: the output
may look like this:</p>
<div class="syntax"><pre><span class="nc">.highlight</span> <span class="nc">.k</span> <span class="p">{</span> <span class="k">color</span><span class="o">:</span> <span class="m">#AA22FF</span><span class="p">;</span> <span class="k">font-weight</span><span class="o">:</span> <span class="k">bold</span> <span class="p">}</span>
<span class="nc">.highlight</span> <span class="nc">.s</span> <span class="p">{</span> <span class="k">color</span><span class="o">:</span> <span class="m">#BB4444</span> <span class="p">}</span>
<span class="o">...</span>
</pre></div>
</div>
<div class="section" id="options">
<h3>Options</h3>
<p>The <cite>highlight()</cite> function supports a fourth argument called <cite>outfile</cite>, it must be
a file object if given. The formatted output will then be written to this file
instead of being returned as a string.</p>
<p>Lexers and formatters both support options. They are given to them as keyword
arguments either to the class or to the lookup method:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments</span> <span class="kn">import</span> <span class="n">highlight</span>
<span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">get_lexer_by_name</span>
<span class="kn">from</span> <span class="nn">pygments.formatters</span> <span class="kn">import</span> <span class="n">HtmlFormatter</span>
<span class="n">lexer</span> <span class="o">=</span> <span class="n">get_lexer_by_name</span><span class="p">(</span><span class="s">&quot;python&quot;</span><span class="p">,</span> <span class="n">stripall</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">formatter</span> <span class="o">=</span> <span class="n">HtmlFormatter</span><span class="p">(</span><span class="n">linenos</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">cssclass</span><span class="o">=</span><span class="s">&quot;source&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">highlight</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">lexer</span><span class="p">,</span> <span class="n">formatter</span><span class="p">)</span>
</pre></div>
<p>This makes the lexer strip all leading and trailing whitespace from the input
(<cite>stripall</cite> option), lets the formatter output line numbers (<cite>linenos</cite> option),
and sets the wrapping <tt class="docutils literal">&lt;div&gt;</tt>'s class to <tt class="docutils literal">source</tt> (instead of
<tt class="docutils literal">highlight</tt>).</p>
<p>Important options include:</p>
<dl class="docutils">
<dt><cite>encoding</cite> <span class="classifier-delimiter">:</span> <span class="classifier">for lexers and formatters</span></dt>
<dd>Since Pygments uses Unicode strings internally, this determines which
encoding will be used to convert to or from byte strings.</dd>
<dt><cite>style</cite> <span class="classifier-delimiter">:</span> <span class="classifier">for formatters</span></dt>
<dd>The name of the style to use when writing the output.</dd>
</dl>
<p>For an overview of builtin lexers and formatters and their options, visit the
<a class="reference external" href="./lexers.html">lexer</a> and <a class="reference external" href="./formatters.html">formatters</a> lists.</p>
<p>For a documentation on filters, see <a class="reference external" href="./filters.html">this page</a>.</p>
</div>
<div class="section" id="lexer-and-formatter-lookup">
<h3>Lexer and formatter lookup</h3>
<p>If you want to lookup a built-in lexer by its alias or a filename, you can use
one of the following methods:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="p">(</span><span class="n">get_lexer_by_name</span><span class="p">,</span>
<span class="gp">... </span> <span class="n">get_lexer_for_filename</span><span class="p">,</span> <span class="n">get_lexer_for_mimetype</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_lexer_by_name</span><span class="p">(</span><span class="s">&#39;python&#39;</span><span class="p">)</span>
<span class="go">&lt;pygments.lexers.PythonLexer&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_lexer_for_filename</span><span class="p">(</span><span class="s">&#39;spam.rb&#39;</span><span class="p">)</span>
<span class="go">&lt;pygments.lexers.RubyLexer&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_lexer_for_mimetype</span><span class="p">(</span><span class="s">&#39;text/x-perl&#39;</span><span class="p">)</span>
<span class="go">&lt;pygments.lexers.PerlLexer&gt;</span>
</pre></div>
<p>All these functions accept keyword arguments; they will be passed to the lexer
as options.</p>
<p>A similar API is available for formatters: use <cite>get_formatter_by_name()</cite> and
<cite>get_formatter_for_filename()</cite> from the <cite>pygments.formatters</cite> module
for this purpose.</p>
</div>
<div class="section" id="guessing-lexers">
<h3>Guessing lexers</h3>
<p>If you don't know the content of the file, or you want to highlight a file
whose extension is ambiguous, such as <tt class="docutils literal">.html</tt> (which could contain plain HTML
or some template tags), use these functions:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">guess_lexer</span><span class="p">,</span> <span class="n">guess_lexer_for_filename</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">guess_lexer</span><span class="p">(</span><span class="s">&#39;#!/usr/bin/python</span><span class="se">\n</span><span class="s">print &quot;Hello World!&quot;&#39;</span><span class="p">)</span>
<span class="go">&lt;pygments.lexers.PythonLexer&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">guess_lexer_for_filename</span><span class="p">(</span><span class="s">&#39;test.py&#39;</span><span class="p">,</span> <span class="s">&#39;print &quot;Hello World!&quot;&#39;</span><span class="p">)</span>
<span class="go">&lt;pygments.lexers.PythonLexer&gt;</span>
</pre></div>
<p><cite>guess_lexer()</cite> passes the given content to the lexer classes' <cite>analyse_text()</cite>
method and returns the one for which it returns the highest number.</p>
<p>All lexers have two different filename pattern lists: the primary and the
secondary one. The <cite>get_lexer_for_filename()</cite> function only uses the primary
list, whose entries are supposed to be unique among all lexers.
<cite>guess_lexer_for_filename()</cite>, however, will first loop through all lexers and
look at the primary and secondary filename patterns if the filename matches.
If only one lexer matches, it is returned, else the guessing mechanism of
<cite>guess_lexer()</cite> is used with the matching lexers.</p>
<p>As usual, keyword arguments to these functions are given to the created lexer
as options.</p>
</div>
<div class="section" id="command-line-usage">
<h3>Command line usage</h3>
<p>You can use Pygments from the command line, using the <cite>pygmentize</cite> script:</p>
<pre class="literal-block">
$ pygmentize test.py
</pre>
<p>will highlight the Python file test.py using ANSI escape sequences
(a.k.a. terminal colors) and print the result to standard output.</p>
<p>To output HTML, use the <tt class="docutils literal"><span class="pre">-f</span></tt> option:</p>
<pre class="literal-block">
$ pygmentize -f html -o test.html test.py
</pre>
<p>to write an HTML-highlighted version of test.py to the file test.html.
Note that it will only be a snippet of HTML, if you want a full HTML document,
use the &quot;full&quot; option:</p>
<pre class="literal-block">
$ pygmentize -f html -O full -o test.html test.py
</pre>
<p>This will produce a full HTML document with included stylesheet.</p>
<p>A style can be selected with <tt class="docutils literal"><span class="pre">-O</span> <span class="pre">style=&lt;name&gt;</span></tt>.</p>
<p>If you need a stylesheet for an existing HTML file using Pygments CSS classes,
it can be created with:</p>
<pre class="literal-block">
$ pygmentize -S default -f html &gt; style.css
</pre>
<p>where <tt class="docutils literal">default</tt> is the style name.</p>
<p>More options and tricks and be found in the <a class="reference external" href="./cmdline.html">command line reference</a>.</p>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.152015
file id: quickstart -->
</html>

View File

@ -1,229 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Using Pygments in ReST documents &mdash; 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">Using Pygments in ReST documents</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<!-- -*- mode: rst -*- -->
<p>Many Python people use <a class="reference external" href="http://docutils.sf.net/rst.html">ReST</a> for documentation their sourcecode, programs,
scripts et cetera. This also means that documentation often includes sourcecode
samples or snippets.</p>
<p>You can easily enable Pygments support for your ReST texts using a custom
directive -- this is also how this documentation displays source code.</p>
<p>From Pygments 0.9, the directive is shipped in the distribution as
<cite>external/rst-directive.py</cite>. You can copy and adapt this code to your liking.</p>
<!-- removed - - too confusing
*Loosely related note:* The ReST lexer now recognizes ``.. sourcecode::`` and
``.. code::`` directives and highlights the contents in the specified language
if the `handlecodeblocks` option is true. -->
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.959525
file id: rstdirective -->
</html>

View File

@ -1,341 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Styles &mdash; 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">Styles</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#creating-own-styles">Creating Own Styles</a></li>
<li><a href="#style-rules">Style Rules</a></li>
<li><a href="#builtin-styles">Builtin Styles</a></li>
<li><a href="#getting-a-list-of-available-styles">Getting a list of available styles</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>Pygments comes with some builtin styles that work for both the HTML and
LaTeX formatter.</p>
<p>The builtin styles can be looked up with the <cite>get_style_by_name</cite> function:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.styles</span> <span class="kn">import</span> <span class="n">get_style_by_name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_style_by_name</span><span class="p">(</span><span class="s">&#39;colorful&#39;</span><span class="p">)</span>
<span class="go">&lt;class &#39;pygments.styles.colorful.ColorfulStyle&#39;&gt;</span>
</pre></div>
<p>You can pass a instance of a <cite>Style</cite> class to a formatter as the <cite>style</cite>
option in form of a string:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.styles</span> <span class="kn">import</span> <span class="n">get_style_by_name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">HtmlFormatter</span><span class="p">(</span><span class="n">style</span><span class="o">=</span><span class="s">&#39;colorful&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">style</span>
<span class="go">&lt;class &#39;pygments.styles.colorful.ColorfulStyle&#39;&gt;</span>
</pre></div>
<p>Or you can also import your own style (which must be a subclass of
<cite>pygments.style.Style</cite>) and pass it to the formatter:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">yourapp.yourmodule</span> <span class="kn">import</span> <span class="n">YourStyle</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">HtmlFormatter</span><span class="p">(</span><span class="n">style</span><span class="o">=</span><span class="n">YourStyle</span><span class="p">)</span><span class="o">.</span><span class="n">style</span>
<span class="go">&lt;class &#39;yourapp.yourmodule.YourStyle&#39;&gt;</span>
</pre></div>
<div class="section" id="creating-own-styles">
<h3>Creating Own Styles</h3>
<p>So, how to create a style? All you have to do is to subclass <cite>Style</cite> and
define some styles:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.style</span> <span class="kn">import</span> <span class="n">Style</span>
<span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Keyword</span><span class="p">,</span> <span class="n">Name</span><span class="p">,</span> <span class="n">Comment</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">Error</span><span class="p">,</span> \
<span class="n">Number</span><span class="p">,</span> <span class="n">Operator</span><span class="p">,</span> <span class="n">Generic</span>
<span class="k">class</span> <span class="nc">YourStyle</span><span class="p">(</span><span class="n">Style</span><span class="p">):</span>
<span class="n">default_style</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="n">styles</span> <span class="o">=</span> <span class="p">{</span>
<span class="n">Comment</span><span class="p">:</span> <span class="s">&#39;italic #888&#39;</span><span class="p">,</span>
<span class="n">Keyword</span><span class="p">:</span> <span class="s">&#39;bold #005&#39;</span><span class="p">,</span>
<span class="n">Name</span><span class="p">:</span> <span class="s">&#39;#f00&#39;</span><span class="p">,</span>
<span class="n">Name</span><span class="o">.</span><span class="n">Function</span><span class="p">:</span> <span class="s">&#39;#0f0&#39;</span><span class="p">,</span>
<span class="n">Name</span><span class="o">.</span><span class="n">Class</span><span class="p">:</span> <span class="s">&#39;bold #0f0&#39;</span><span class="p">,</span>
<span class="n">String</span><span class="p">:</span> <span class="s">&#39;bg:#eee #111&#39;</span>
<span class="p">}</span>
</pre></div>
<p>That's it. There are just a few rules. When you define a style for <cite>Name</cite>
the style automatically also affects <cite>Name.Function</cite> and so on. If you
defined <tt class="docutils literal">'bold'</tt> and you don't want boldface for a subtoken use <tt class="docutils literal">'nobold'</tt>.</p>
<p>(Philosophy: the styles aren't written in CSS syntax since this way
they can be used for a variety of formatters.)</p>
<p><cite>default_style</cite> is the style inherited by all token types.</p>
<p>To make the style usable for Pygments, you must</p>
<ul class="simple">
<li>either register it as a plugin (see <a class="reference external" href="./plugins.html">the plugin docs</a>)</li>
<li>or drop it into the <cite>styles</cite> subpackage of your Pygments distribution one style
class per style, where the file name is the style name and the class name is
<cite>StylenameClass</cite>. For example, if your style should be called
<tt class="docutils literal">&quot;mondrian&quot;</tt>, name the class <cite>MondrianStyle</cite>, put it into the file
<tt class="docutils literal">mondrian.py</tt> and this file into the <tt class="docutils literal">pygments.styles</tt> subpackage
directory.</li>
</ul>
</div>
<div class="section" id="style-rules">
<h3>Style Rules</h3>
<p>Here a small overview of all allowed styles:</p>
<dl class="docutils">
<dt><tt class="docutils literal">bold</tt></dt>
<dd>render text as bold</dd>
<dt><tt class="docutils literal">nobold</tt></dt>
<dd>don't render text as bold (to prevent subtokens being highlighted bold)</dd>
<dt><tt class="docutils literal">italic</tt></dt>
<dd>render text italic</dd>
<dt><tt class="docutils literal">noitalic</tt></dt>
<dd>don't render text as italic</dd>
<dt><tt class="docutils literal">underline</tt></dt>
<dd>render text underlined</dd>
<dt><tt class="docutils literal">nounderline</tt></dt>
<dd>don't render text underlined</dd>
<dt><tt class="docutils literal">bg:</tt></dt>
<dd>transparent background</dd>
<dt><tt class="docutils literal"><span class="pre">bg:#000000</span></tt></dt>
<dd>background color (black)</dd>
<dt><tt class="docutils literal">border:</tt></dt>
<dd>no border</dd>
<dt><tt class="docutils literal"><span class="pre">border:#ffffff</span></tt></dt>
<dd>border color (white)</dd>
<dt><tt class="docutils literal">#ff0000</tt></dt>
<dd>text color (red)</dd>
<dt><tt class="docutils literal">noinherit</tt></dt>
<dd>don't inherit styles from supertoken</dd>
</dl>
<p>Note that there may not be a space between <tt class="docutils literal">bg:</tt> and the color value
since the style definition string is split at whitespace.
Also, using named colors is not allowed since the supported color names
vary for different formatters.</p>
<p>Furthermore, not all lexers might support every style.</p>
</div>
<div class="section" id="builtin-styles">
<h3>Builtin Styles</h3>
<p>Pygments ships some builtin styles which are maintained by the Pygments team.</p>
<p>To get a list of known styles you can use this snippet:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.styles</span> <span class="kn">import</span> <span class="n">STYLE_MAP</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">STYLE_MAP</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;default&#39;, &#39;emacs&#39;, &#39;friendly&#39;, &#39;colorful&#39;]</span>
</pre></div>
</div>
<div class="section" id="getting-a-list-of-available-styles">
<h3>Getting a list of available styles</h3>
<p><em>New in Pygments 0.6.</em></p>
<p>Because it could be that a plugin registered a style, there is
a way to iterate over all styles:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.styles</span> <span class="kn">import</span> <span class="n">get_all_styles</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">styles</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">get_all_styles</span><span class="p">())</span>
</pre></div>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.728566
file id: styles -->
</html>

View File

@ -1,541 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Builtin Tokens &mdash; 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">Builtin Tokens</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
<li><a href="#keyword-tokens">Keyword Tokens</a></li>
<li><a href="#name-tokens">Name Tokens</a></li>
<li><a href="#literals">Literals</a></li>
<li><a href="#operators">Operators</a></li>
<li><a href="#punctuation">Punctuation</a></li>
<li><a href="#comments">Comments</a></li>
<li><a href="#generic-tokens">Generic Tokens</a></li>
</ul>
</div>
<!-- -*- mode: rst -*- -->
<p>Inside the <cite>pygments.token</cite> module, there is a special object called <cite>Token</cite>
that is used to create token types.</p>
<p>You can create a new token type by accessing an attribute of <cite>Token</cite>:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Token</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Token</span><span class="o">.</span><span class="n">String</span>
<span class="go">Token.String</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Token</span><span class="o">.</span><span class="n">String</span> <span class="ow">is</span> <span class="n">Token</span><span class="o">.</span><span class="n">String</span>
<span class="go">True</span>
</pre></div>
<p>Note that tokens are singletons so you can use the <tt class="docutils literal">is</tt> operator for comparing
token types.</p>
<p>As of Pygments 0.7 you can also use the <tt class="docutils literal">in</tt> operator to perform set tests:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">Comment</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Comment</span><span class="o">.</span><span class="n">Single</span> <span class="ow">in</span> <span class="n">Comment</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Comment</span> <span class="ow">in</span> <span class="n">Comment</span><span class="o">.</span><span class="n">Multi</span>
<span class="go">False</span>
</pre></div>
<p>This can be useful in <a class="reference external" href="./filters.html">filters</a> and if you write lexers on your own without
using the base lexers.</p>
<p>You can also split a token type into a hierarchy, and get the parent of it:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">String</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
<span class="go">[Token, Token.Literal, Token.Literal.String]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">String</span><span class="o">.</span><span class="n">parent</span>
<span class="go">Token.Literal</span>
</pre></div>
<p>In principle, you can create an unlimited number of token types but nobody can
guarantee that a style would define style rules for a token type. Because of
that, Pygments proposes some global token types defined in the
<cite>pygments.token.STANDARD_TYPES</cite> dict.</p>
<p>For some tokens aliases are already defined:</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">String</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">String</span>
<span class="go">Token.Literal.String</span>
</pre></div>
<p>Inside the <cite>pygments.token</cite> module the following aliases are defined:</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="36%" />
<col width="47%" />
</colgroup>
<tbody valign="top">
<tr><td><cite>Text</cite></td>
<td><cite>Token.Text</cite></td>
<td>for any type of text data</td>
</tr>
<tr><td><cite>Whitespace</cite></td>
<td><cite>Token.Text.Whitespace</cite></td>
<td>for specially highlighted whitespace</td>
</tr>
<tr><td><cite>Error</cite></td>
<td><cite>Token.Error</cite></td>
<td>represents lexer errors</td>
</tr>
<tr><td><cite>Other</cite></td>
<td><cite>Token.Other</cite></td>
<td>special token for data not
matched by a parser (e.g. HTML
markup in PHP code)</td>
</tr>
<tr><td><cite>Keyword</cite></td>
<td><cite>Token.Keyword</cite></td>
<td>any kind of keywords</td>
</tr>
<tr><td><cite>Name</cite></td>
<td><cite>Token.Name</cite></td>
<td>variable/function names</td>
</tr>
<tr><td><cite>Literal</cite></td>
<td><cite>Token.Literal</cite></td>
<td>Any literals</td>
</tr>
<tr><td><cite>String</cite></td>
<td><cite>Token.Literal.String</cite></td>
<td>string literals</td>
</tr>
<tr><td><cite>Number</cite></td>
<td><cite>Token.Literal.Number</cite></td>
<td>number literals</td>
</tr>
<tr><td><cite>Operator</cite></td>
<td><cite>Token.Operator</cite></td>
<td>operators (<tt class="docutils literal">+</tt>, <tt class="docutils literal">not</tt>...)</td>
</tr>
<tr><td><cite>Punctuation</cite></td>
<td><cite>Token.Punctuation</cite></td>
<td>punctuation (<tt class="docutils literal">[</tt>, <tt class="docutils literal">(</tt>...)</td>
</tr>
<tr><td><cite>Comment</cite></td>
<td><cite>Token.Comment</cite></td>
<td>any kind of comments</td>
</tr>
<tr><td><cite>Generic</cite></td>
<td><cite>Token.Generic</cite></td>
<td>generic tokens (have a look at
the explanation below)</td>
</tr>
</tbody>
</table>
<p>The <cite>Whitespace</cite> token type is new in Pygments 0.8. It is used only by the
<cite>VisibleWhitespaceFilter</cite> currently.</p>
<p>Normally you just create token types using the already defined aliases. For each
of those token aliases, a number of subtypes exists (excluding the special tokens
<cite>Token.Text</cite>, <cite>Token.Error</cite> and <cite>Token.Other</cite>)</p>
<p>The <cite>is_token_subtype()</cite> function in the <cite>pygments.token</cite> module can be used to
test if a token type is a subtype of another (such as <cite>Name.Tag</cite> and <cite>Name</cite>).
(This is the same as <tt class="docutils literal">Name.Tag in Name</tt>. The overloaded <cite>in</cite> operator was newly
introduced in Pygments 0.7, the function still exists for backwards
compatiblity.)</p>
<p>With Pygments 0.7, it's also possible to convert strings to token types (for example
if you want to supply a token from the command line):</p>
<div class="syntax"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pygments.token</span> <span class="kn">import</span> <span class="n">String</span><span class="p">,</span> <span class="n">string_to_tokentype</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">string_to_tokentype</span><span class="p">(</span><span class="s">&quot;String&quot;</span><span class="p">)</span>
<span class="go">Token.Literal.String</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">string_to_tokentype</span><span class="p">(</span><span class="s">&quot;Token.Literal.String&quot;</span><span class="p">)</span>
<span class="go">Token.Literal.String</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">string_to_tokentype</span><span class="p">(</span><span class="n">String</span><span class="p">)</span>
<span class="go">Token.Literal.String</span>
</pre></div>
<div class="section" id="keyword-tokens">
<h3>Keyword Tokens</h3>
<dl class="docutils">
<dt><cite>Keyword</cite></dt>
<dd>For any kind of keyword (especially if it doesn't match any of the
subtypes of course).</dd>
<dt><cite>Keyword.Constant</cite></dt>
<dd>For keywords that are constants (e.g. <tt class="docutils literal">None</tt> in future Python versions).</dd>
<dt><cite>Keyword.Declaration</cite></dt>
<dd>For keywords used for variable declaration (e.g. <tt class="docutils literal">var</tt> in some programming
languages like JavaScript).</dd>
<dt><cite>Keyword.Namespace</cite></dt>
<dd>For keywords used for namespace declarations (e.g. <tt class="docutils literal">import</tt> in Python and
Java and <tt class="docutils literal">package</tt> in Java).</dd>
<dt><cite>Keyword.Pseudo</cite></dt>
<dd>For keywords that aren't really keywords (e.g. <tt class="docutils literal">None</tt> in old Python
versions).</dd>
<dt><cite>Keyword.Reserved</cite></dt>
<dd>For reserved keywords.</dd>
<dt><cite>Keyword.Type</cite></dt>
<dd>For builtin types that can't be used as identifiers (e.g. <tt class="docutils literal">int</tt>,
<tt class="docutils literal">char</tt> etc. in C).</dd>
</dl>
</div>
<div class="section" id="name-tokens">
<h3>Name Tokens</h3>
<dl class="docutils">
<dt><cite>Name</cite></dt>
<dd>For any name (variable names, function names, classes).</dd>
<dt><cite>Name.Attribute</cite></dt>
<dd>For all attributes (e.g. in HTML tags).</dd>
<dt><cite>Name.Builtin</cite></dt>
<dd>Builtin names; names that are available in the global namespace.</dd>
<dt><cite>Name.Builtin.Pseudo</cite></dt>
<dd>Builtin names that are implicit (e.g. <tt class="docutils literal">self</tt> in Ruby, <tt class="docutils literal">this</tt> in Java).</dd>
<dt><cite>Name.Class</cite></dt>
<dd>Class names. Because no lexer can know if a name is a class or a function
or something else this token is meant for class declarations.</dd>
<dt><cite>Name.Constant</cite></dt>
<dd>Token type for constants. In some languages you can recognise a token by the
way it's defined (the value after a <tt class="docutils literal">const</tt> keyword for example). In
other languages constants are uppercase by definition (Ruby).</dd>
<dt><cite>Name.Decorator</cite></dt>
<dd>Token type for decorators. Decorators are synatic elements in the Python
language. Similar syntax elements exist in C# and Java.</dd>
<dt><cite>Name.Entity</cite></dt>
<dd>Token type for special entities. (e.g. <tt class="docutils literal">&amp;nbsp;</tt> in HTML).</dd>
<dt><cite>Name.Exception</cite></dt>
<dd>Token type for exception names (e.g. <tt class="docutils literal">RuntimeError</tt> in Python). Some languages
define exceptions in the function signature (Java). You can highlight
the name of that exception using this token then.</dd>
<dt><cite>Name.Function</cite></dt>
<dd>Token type for function names.</dd>
<dt><cite>Name.Label</cite></dt>
<dd>Token type for label names (e.g. in languages that support <tt class="docutils literal">goto</tt>).</dd>
<dt><cite>Name.Namespace</cite></dt>
<dd>Token type for namespaces. (e.g. import paths in Java/Python), names following
the <tt class="docutils literal">module</tt>/<tt class="docutils literal">namespace</tt> keyword in other languages.</dd>
<dt><cite>Name.Other</cite></dt>
<dd>Other names. Normally unused.</dd>
<dt><cite>Name.Tag</cite></dt>
<dd>Tag names (in HTML/XML markup or configuration files).</dd>
<dt><cite>Name.Variable</cite></dt>
<dd>Token type for variables. Some languages have prefixes for variable names
(PHP, Ruby, Perl). You can highlight them using this token.</dd>
<dt><cite>Name.Variable.Class</cite></dt>
<dd>same as <cite>Name.Variable</cite> but for class variables (also static variables).</dd>
<dt><cite>Name.Variable.Global</cite></dt>
<dd>same as <cite>Name.Variable</cite> but for global variables (used in Ruby, for
example).</dd>
<dt><cite>Name.Variable.Instance</cite></dt>
<dd>same as <cite>Name.Variable</cite> but for instance variables.</dd>
</dl>
</div>
<div class="section" id="literals">
<h3>Literals</h3>
<dl class="docutils">
<dt><cite>Literal</cite></dt>
<dd>For any literal (if not further defined).</dd>
<dt><cite>Literal.Date</cite></dt>
<dd>for date literals (e.g. <tt class="docutils literal">42d</tt> in Boo).</dd>
<dt><cite>String</cite></dt>
<dd>For any string literal.</dd>
<dt><cite>String.Backtick</cite></dt>
<dd>Token type for strings enclosed in backticks.</dd>
<dt><cite>String.Char</cite></dt>
<dd>Token type for single characters (e.g. Java, C).</dd>
<dt><cite>String.Doc</cite></dt>
<dd>Token type for documentation strings (for example Python).</dd>
<dt><cite>String.Double</cite></dt>
<dd>Double quoted strings.</dd>
<dt><cite>String.Escape</cite></dt>
<dd>Token type for escape sequences in strings.</dd>
<dt><cite>String.Heredoc</cite></dt>
<dd>Token type for &quot;heredoc&quot; strings (e.g. in Ruby or Perl).</dd>
<dt><cite>String.Interpol</cite></dt>
<dd>Token type for interpolated parts in strings (e.g. <tt class="docutils literal">#{foo}</tt> in Ruby).</dd>
<dt><cite>String.Other</cite></dt>
<dd>Token type for any other strings (for example <tt class="docutils literal">%q{foo}</tt> string constructs
in Ruby).</dd>
<dt><cite>String.Regex</cite></dt>
<dd>Token type for regular expression literals (e.g. <tt class="docutils literal">/foo/</tt> in JavaScript).</dd>
<dt><cite>String.Single</cite></dt>
<dd>Token type for single quoted strings.</dd>
<dt><cite>String.Symbol</cite></dt>
<dd>Token type for symbols (e.g. <tt class="docutils literal">:foo</tt> in LISP or Ruby).</dd>
<dt><cite>Number</cite></dt>
<dd>Token type for any number literal.</dd>
<dt><cite>Number.Float</cite></dt>
<dd>Token type for float literals (e.g. <tt class="docutils literal">42.0</tt>).</dd>
<dt><cite>Number.Hex</cite></dt>
<dd>Token type for hexadecimal number literals (e.g. <tt class="docutils literal">0xdeadbeef</tt>).</dd>
<dt><cite>Number.Integer</cite></dt>
<dd>Token type for integer literals (e.g. <tt class="docutils literal">42</tt>).</dd>
<dt><cite>Number.Integer.Long</cite></dt>
<dd>Token type for long integer literals (e.g. <tt class="docutils literal">42L</tt> in Python).</dd>
<dt><cite>Number.Oct</cite></dt>
<dd>Token type for octal literals.</dd>
</dl>
</div>
<div class="section" id="operators">
<h3>Operators</h3>
<dl class="docutils">
<dt><cite>Operator</cite></dt>
<dd>For any punctuation operator (e.g. <tt class="docutils literal">+</tt>, <tt class="docutils literal">-</tt>).</dd>
<dt><cite>Operator.Word</cite></dt>
<dd>For any operator that is a word (e.g. <tt class="docutils literal">not</tt>).</dd>
</dl>
</div>
<div class="section" id="punctuation">
<h3>Punctuation</h3>
<p><em>New in Pygments 0.7.</em></p>
<dl class="docutils">
<dt><cite>Punctuation</cite></dt>
<dd>For any punctuation which is not an operator (e.g. <tt class="docutils literal">[</tt>, <tt class="docutils literal">(</tt>...)</dd>
</dl>
</div>
<div class="section" id="comments">
<h3>Comments</h3>
<dl class="docutils">
<dt><cite>Comment</cite></dt>
<dd>Token type for any comment.</dd>
<dt><cite>Comment.Multiline</cite></dt>
<dd>Token type for multiline comments.</dd>
<dt><cite>Comment.Preproc</cite></dt>
<dd>Token type for preprocessor comments (also <tt class="docutils literal"><span class="pre">&lt;?php</span></tt>/<tt class="docutils literal">&lt;%</tt> constructs).</dd>
<dt><cite>Comment.Single</cite></dt>
<dd>Token type for comments that end at the end of a line (e.g. <tt class="docutils literal"># foo</tt>).</dd>
<dt><cite>Comment.Special</cite></dt>
<dd>Special data in comments. For example code tags, author and license
information, etc.</dd>
</dl>
</div>
<div class="section" id="generic-tokens">
<h3>Generic Tokens</h3>
<p>Generic tokens are for special lexers like the <cite>DiffLexer</cite> that doesn't really
highlight a programming language but a patch file.</p>
<dl class="docutils">
<dt><cite>Generic</cite></dt>
<dd>A generic, unstyled token. Normally you don't use this token type.</dd>
<dt><cite>Generic.Deleted</cite></dt>
<dd>Marks the token value as deleted.</dd>
<dt><cite>Generic.Emph</cite></dt>
<dd>Marks the token value as emphasized.</dd>
<dt><cite>Generic.Error</cite></dt>
<dd>Marks the token value as an error message.</dd>
<dt><cite>Generic.Heading</cite></dt>
<dd>Marks the token value as headline.</dd>
<dt><cite>Generic.Inserted</cite></dt>
<dd>Marks the token value as inserted.</dd>
<dt><cite>Generic.Output</cite></dt>
<dd>Marks the token value as program output (e.g. for python cli lexer).</dd>
<dt><cite>Generic.Prompt</cite></dt>
<dd>Marks the token value as command prompt (e.g. bash lexer).</dd>
<dt><cite>Generic.Strong</cite></dt>
<dd>Marks the token value as bold (e.g. for rst lexer).</dd>
<dt><cite>Generic.Subheading</cite></dt>
<dd>Marks the token value as subheadline.</dd>
<dt><cite>Generic.Traceback</cite></dt>
<dd>Marks the token value as a part of an error traceback.</dd>
</dl>
</div>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.797189
file id: tokens -->
</html>

View File

@ -1,249 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Unicode and Encodings &mdash; 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">Unicode and Encodings</h2>
<a id="backlink" href="index.html">&laquo; Back To Index</a>
<p>Since Pygments 0.6, all lexers use unicode strings internally. Because of that
you might encounter the occasional <cite>UnicodeDecodeError</cite> if you pass strings with the
wrong encoding.</p>
<p>Per default all lexers have their input encoding set to <cite>latin1</cite>.
If you pass a lexer a string object (not unicode), it tries to decode the data
using this encoding.
You can override the encoding using the <cite>encoding</cite> lexer option. If you have the
<a class="reference external" href="http://chardet.feedparser.org/">chardet</a> library installed and set the encoding to <tt class="docutils literal">chardet</tt> if will ananlyse
the text and use the encoding it thinks is the right one automatically:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.lexers</span> <span class="kn">import</span> <span class="n">PythonLexer</span>
<span class="n">lexer</span> <span class="o">=</span> <span class="n">PythonLexer</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s">&#39;chardet&#39;</span><span class="p">)</span>
</pre></div>
<p>The best way is to pass Pygments unicode objects. In that case you can't get
unexpected output.</p>
<p>The formatters now send Unicode objects to the stream if you don't set the
output encoding. You can do so by passing the formatters an <cite>encoding</cite> option:</p>
<div class="syntax"><pre><span class="kn">from</span> <span class="nn">pygments.formatters</span> <span class="kn">import</span> <span class="n">HtmlFormatter</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">HtmlFormatter</span><span class="p">(</span><span class="n">encoding</span><span class="o">=</span><span class="s">&#39;utf-8&#39;</span><span class="p">)</span>
</pre></div>
<p><strong>You will have to set this option if you have non-ASCII characters in the
source and the output stream does not accept Unicode written to it!</strong>
This is the case for all regular files and for terminals.</p>
<p>Note: The Terminal formatter tries to be smart: if its output stream has an
<cite>encoding</cite> attribute, and you haven't set the option, it will encode any
Unicode string with this encoding before writing it. This is the case for
<cite>sys.stdout</cite>, for example. The other formatters don't have that behavior.</p>
<p>Another note: If you call Pygments via the command line (<cite>pygmentize</cite>),
encoding is handled differently, see <a class="reference external" href="./cmdline.html">the command line docs</a>.</p>
<p><em>New in Pygments 0.7</em>: the formatters now also accept an <cite>outencoding</cite> option
which will override the <cite>encoding</cite> option if given. This makes it possible to
use a single options dict with lexers and formatters, and still have different
input and output encodings.</p>
</div>
</body>
<!-- generated on: 2013-01-09 17:48:43.988472
file id: unicode -->
</html>

View File

@ -1,472 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Generate Pygments Documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Generates a bunch of html files containing the documentation.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import os
import sys
from datetime import datetime
from cgi import escape
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.core import publish_parts
from docutils.writers import html4css1
from jinja2 import Template
# try to use the right Pygments to build the docs
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from pygments import highlight, __version__
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
LEXERDOC = '''
`%s`
%s
:Short names: %s
:Filename patterns: %s
:Mimetypes: %s
'''
def generate_lexer_docs():
from pygments.lexers import LEXERS
out = []
modules = {}
moduledocstrings = {}
for classname, data in sorted(LEXERS.iteritems(), key=lambda x: x[0]):
module = data[0]
mod = __import__(module, None, None, [classname])
cls = getattr(mod, classname)
if not cls.__doc__:
print "Warning: %s does not have a docstring." % classname
modules.setdefault(module, []).append((
classname,
cls.__doc__,
', '.join(data[2]) or 'None',
', '.join(data[3]).replace('*', '\\*').replace('_', '\\') or 'None',
', '.join(data[4]) or 'None'))
if module not in moduledocstrings:
moduledocstrings[module] = mod.__doc__
for module, lexers in sorted(modules.iteritems(), key=lambda x: x[0]):
heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.')
out.append('\n' + heading + '\n' + '-'*len(heading) + '\n')
for data in lexers:
out.append(LEXERDOC % data)
return ''.join(out).decode('utf-8')
def generate_formatter_docs():
from pygments.formatters import FORMATTERS
out = []
for cls, data in sorted(FORMATTERS.iteritems(),
key=lambda x: x[0].__name__):
heading = cls.__name__
out.append('`' + heading + '`\n' + '-'*(2+len(heading)) + '\n')
out.append(cls.__doc__)
out.append('''
:Short names: %s
:Filename patterns: %s
''' % (', '.join(data[1]) or 'None', ', '.join(data[2]).replace('*', '\\*') or 'None'))
return ''.join(out).decode('utf-8')
def generate_filter_docs():
from pygments.filters import FILTERS
out = []
for name, cls in FILTERS.iteritems():
out.append('''
`%s`
%s
:Name: %s
''' % (cls.__name__, cls.__doc__, name))
return ''.join(out).decode('utf-8')
def generate_changelog():
fn = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
'CHANGES'))
f = file(fn)
result = []
in_header = False
header = True
for line in f:
if header:
if not in_header and line.strip():
in_header = True
elif in_header and not line.strip():
header = False
else:
result.append(line.rstrip())
f.close()
return '\n'.join(result).decode('utf-8')
def generate_authors():
fn = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
'AUTHORS'))
f = file(fn)
r = f.read().rstrip().decode('utf-8')
f.close()
return r
LEXERDOCS = generate_lexer_docs()
FORMATTERDOCS = generate_formatter_docs()
FILTERDOCS = generate_filter_docs()
CHANGELOG = generate_changelog()
AUTHORS = generate_authors()
PYGMENTS_FORMATTER = HtmlFormatter(style='pastie', cssclass='syntax')
USAGE = '''\
Usage: %s <mode> <destination> [<source.txt> ...]
Generate either python or html files out of the documentation.
Mode can either be python or html.\
''' % sys.argv[0]
TEMPLATE = '''\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>{{ title }} &mdash; Pygments</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
{{ style }}
</style>
</head>
<body>
<div id="content">
<h1 class="heading">Pygments</h1>
<h2 class="subheading">{{ title }}</h2>
{% if file_id != "index" %}
<a id="backlink" href="index.html">&laquo; Back To Index</a>
{% endif %}
{% if toc %}
<div class="toc">
<h2>Contents</h2>
<ul class="contents">
{% for key, value in toc %}
<li><a href="{{ key }}">{{ value }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{{ body }}
</div>
</body>
<!-- generated on: {{ generation_date }}
file id: {{ file_id }} -->
</html>\
'''
STYLESHEET = '''\
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;
}
''' #'
def pygments_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
try:
lexer = get_lexer_by_name(arguments[0])
except ValueError:
# no lexer found
lexer = get_lexer_by_name('text')
parsed = highlight(u'\n'.join(content), lexer, PYGMENTS_FORMATTER)
return [nodes.raw('', parsed, format="html")]
pygments_directive.arguments = (1, 0, 1)
pygments_directive.content = 1
directives.register_directive('sourcecode', pygments_directive)
def create_translator(link_style):
class Translator(html4css1.HTMLTranslator):
def visit_reference(self, node):
refuri = node.get('refuri')
if refuri is not None and '/' not in refuri and refuri.endswith('.txt'):
node['refuri'] = link_style(refuri[:-4])
html4css1.HTMLTranslator.visit_reference(self, node)
return Translator
class DocumentationWriter(html4css1.Writer):
def __init__(self, link_style):
html4css1.Writer.__init__(self)
self.translator_class = create_translator(link_style)
def translate(self):
html4css1.Writer.translate(self)
# generate table of contents
contents = self.build_contents(self.document)
contents_doc = self.document.copy()
contents_doc.children = contents
contents_visitor = self.translator_class(contents_doc)
contents_doc.walkabout(contents_visitor)
self.parts['toc'] = self._generated_toc
def build_contents(self, node, level=0):
sections = []
i = len(node) - 1
while i >= 0 and isinstance(node[i], nodes.section):
sections.append(node[i])
i -= 1
sections.reverse()
toc = []
for section in sections:
try:
reference = nodes.reference('', '', refid=section['ids'][0], *section[0])
except IndexError:
continue
ref_id = reference['refid']
text = escape(reference.astext())
toc.append((ref_id, text))
self._generated_toc = [('#%s' % href, caption) for href, caption in toc]
# no further processing
return []
def generate_documentation(data, link_style):
writer = DocumentationWriter(link_style)
data = data.replace('[builtin_lexer_docs]', LEXERDOCS).\
replace('[builtin_formatter_docs]', FORMATTERDOCS).\
replace('[builtin_filter_docs]', FILTERDOCS).\
replace('[changelog]', CHANGELOG).\
replace('[authors]', AUTHORS)
parts = publish_parts(
data,
writer=writer,
settings_overrides={
'initial_header_level': 3,
'field_name_limit': 50,
}
)
return {
'title': parts['title'],
'body': parts['body'],
'toc': parts['toc']
}
def handle_python(filename, fp, dst):
now = datetime.now()
title = os.path.basename(filename)[:-4]
content = fp.read()
def urlize(href):
# create links for the pygments webpage
if href == 'index.txt':
return '/docs/'
else:
return '/docs/%s/' % href
parts = generate_documentation(content, urlize)
result = file(os.path.join(dst, title + '.py'), 'w')
result.write('# -*- coding: utf-8 -*-\n')
result.write('"""\n Pygments Documentation - %s\n' % title)
result.write(' %s\n\n' % ('~' * (24 + len(title))))
result.write(' Generated on: %s\n"""\n\n' % now)
result.write('import datetime\n')
result.write('DATE = %r\n' % now)
result.write('TITLE = %r\n' % parts['title'])
result.write('TOC = %r\n' % parts['toc'])
result.write('BODY = %r\n' % parts['body'])
result.close()
def handle_html(filename, fp, dst):
now = datetime.now()
title = os.path.basename(filename)[:-4]
content = fp.read().decode('utf-8')
c = generate_documentation(content, (lambda x: './%s.html' % x))
result = file(os.path.join(dst, title + '.html'), 'w')
c['style'] = STYLESHEET + PYGMENTS_FORMATTER.get_style_defs('.syntax')
c['generation_date'] = now
c['file_id'] = title
t = Template(TEMPLATE)
result.write(t.render(c).encode('utf-8'))
result.close()
def run(handle_file, dst, sources=()):
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))
if not sources:
sources = [os.path.join(path, fn) for fn in os.listdir(path)]
if not os.path.isdir(dst):
os.makedirs(dst)
print 'Making docs for Pygments %s in %s' % (__version__, dst)
for fn in sources:
if not os.path.isfile(fn):
continue
print 'Processing %s' % fn
f = open(fn)
try:
handle_file(fn, f, dst)
finally:
f.close()
def main(mode, dst='build/', *sources):
try:
handler = {
'html': handle_html,
'python': handle_python
}[mode]
except KeyError:
print 'Error: unknown mode "%s"' % mode
sys.exit(1)
run(handler, os.path.realpath(dst), sources)
if __name__ == '__main__':
if len(sys.argv) == 1:
print USAGE
else:
main(*sys.argv[1:])

View File

@ -1,270 +0,0 @@
.. -*- mode: rst -*-
=====================
The full Pygments API
=====================
This page describes the Pygments API.
High-level API
==============
Functions from the `pygments` module:
def `lex(code, lexer):`
Lex `code` with the `lexer` (must be a `Lexer` instance)
and return an iterable of tokens. Currently, this only calls
`lexer.get_tokens()`.
def `format(tokens, formatter, outfile=None):`
Format a token stream (iterable of tokens) `tokens` with the
`formatter` (must be a `Formatter` instance). The result is
written to `outfile`, or if that is ``None``, returned as a
string.
def `highlight(code, lexer, formatter, outfile=None):`
This is the most high-level highlighting function.
It combines `lex` and `format` in one function.
Functions from `pygments.lexers`:
def `get_lexer_by_name(alias, **options):`
Return an instance of a `Lexer` subclass that has `alias` in its
aliases list. The lexer is given the `options` at its
instantiation.
Will raise `pygments.util.ClassNotFound` if no lexer with that alias is
found.
def `get_lexer_for_filename(fn, **options):`
Return a `Lexer` subclass instance that has a filename pattern
matching `fn`. The lexer is given the `options` at its
instantiation.
Will raise `pygments.util.ClassNotFound` if no lexer for that filename is
found.
def `get_lexer_for_mimetype(mime, **options):`
Return a `Lexer` subclass instance that has `mime` in its mimetype
list. The lexer is given the `options` at its instantiation.
Will raise `pygments.util.ClassNotFound` if not lexer for that mimetype is
found.
def `guess_lexer(text, **options):`
Return a `Lexer` subclass instance that's guessed from the text
in `text`. For that, the `analyse_text()` 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.
`pygments.util.ClassNotFound` is raised if no lexer thinks it can handle the
content.
def `guess_lexer_for_filename(filename, text, **options):`
As `guess_lexer()`, but only lexers which have a pattern in `filenames`
or `alias_filenames` that matches `filename` are taken into consideration.
`pygments.util.ClassNotFound` is raised if no lexer thinks it can handle the
content.
def `get_all_lexers():`
Return an iterable over all registered lexers, yielding tuples in the
format::
(longname, tuple of aliases, tuple of filename patterns, tuple of mimetypes)
*New in Pygments 0.6.*
Functions from `pygments.formatters`:
def `get_formatter_by_name(alias, **options):`
Return an instance of a `Formatter` subclass that has `alias` in its
aliases list. The formatter is given the `options` at its
instantiation.
Will raise `pygments.util.ClassNotFound` if no formatter with that alias is
found.
def `get_formatter_for_filename(fn, **options):`
Return a `Formatter` subclass instance that has a filename pattern
matching `fn`. The formatter is given the `options` at its
instantiation.
Will raise `pygments.util.ClassNotFound` if no formatter for that filename
is found.
Functions from `pygments.styles`:
def `get_style_by_name(name):`
Return a style class by its short name. The names of the builtin styles
are listed in `pygments.styles.STYLE_MAP`.
Will raise `pygments.util.ClassNotFound` if no style of that name is found.
def `get_all_styles():`
Return an iterable over all registered styles, yielding their names.
*New in Pygments 0.6.*
Lexers
======
A lexer (derived from `pygments.lexer.Lexer`) has the following functions:
def `__init__(self, **options):`
The constructor. Takes a \*\*keywords dictionary of options.
Every subclass must first process its own options and then call
the `Lexer` constructor, since it processes the `stripnl`,
`stripall` and `tabsize` options.
An example looks like this:
.. sourcecode:: python
def __init__(self, **options):
self.compress = options.get('compress', '')
Lexer.__init__(self, **options)
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 `Option processing`_.
def `get_tokens(self, text):`
This method is the basic interface of a lexer. It is called by
the `highlight()` function. It must process the text and return an
iterable of ``(tokentype, value)`` pairs from `text`.
Normally, you don't need to override this method. The default
implementation processes the `stripnl`, `stripall` and `tabsize`
options and then yields all tokens from `get_tokens_unprocessed()`,
with the ``index`` dropped.
def `get_tokens_unprocessed(self, text):`
This method should process the text and return an iterable of
``(index, tokentype, value)`` tuples where ``index`` is the starting
position of the token within the input text.
This method must be overridden by subclasses.
def `analyse_text(text):`
A static method which is called for lexer guessing. It should analyse
the text and return a float in the range from ``0.0`` to ``1.0``.
If it returns ``0.0``, the lexer will not be selected as the most
probable one, if it returns ``1.0``, it will be selected immediately.
For a list of known tokens have a look at the `Tokens`_ page.
A lexer also can have the following attributes (in fact, they are mandatory
except `alias_filenames`) that are used by the builtin lookup mechanism.
`name`
Full name for the lexer, in human-readable form.
`aliases`
A list of short, unique identifiers that can be used to lookup
the lexer from a list, e.g. using `get_lexer_by_name()`.
`filenames`
A list of `fnmatch` patterns that match filenames which contain
content for this lexer. The patterns in this list should be unique among
all lexers.
`alias_filenames`
A list of `fnmatch` patterns that match filenames which may or may not
contain content for this lexer. This list is used by the
`guess_lexer_for_filename()` 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 ``\*.html`` in
this list.
`mimetypes`
A list of MIME types for content that can be lexed with this
lexer.
.. _Tokens: tokens.txt
Formatters
==========
A formatter (derived from `pygments.formatter.Formatter`) has the following
functions:
def `__init__(self, **options):`
As with lexers, this constructor processes options and then must call
the base class `__init__`.
The `Formatter` class recognizes the options `style`, `full` and
`title`. It is up to the formatter class whether it uses them.
def `get_style_defs(self, arg=''):`
This method must return statements or declarations suitable to define
the current style for subsequent highlighted text (e.g. CSS classes
in the `HTMLFormatter`).
The optional argument `arg` can be used to modify the generation and
is formatter dependent (it is standardized because it can be given on
the command line).
This method is called by the ``-S`` `command-line option`_, the `arg`
is then given by the ``-a`` option.
def `format(self, tokensource, outfile):`
This method must format the tokens from the `tokensource` iterable and
write the formatted version to the file object `outfile`.
Formatter options can control how exactly the tokens are converted.
.. _command-line option: cmdline.txt
A formatter must have the following attributes that are used by the
builtin lookup mechanism. (*New in Pygments 0.7.*)
`name`
Full name for the formatter, in human-readable form.
`aliases`
A list of short, unique identifiers that can be used to lookup
the formatter from a list, e.g. using `get_formatter_by_name()`.
`filenames`
A list of `fnmatch` patterns that match filenames for which this formatter
can produce output. The patterns in this list should be unique among
all formatters.
Option processing
=================
The `pygments.util` module has some utility functions usable for option
processing:
class `OptionError`
This exception will be raised by all option processing functions if
the type or value of the argument is not correct.
def `get_bool_opt(options, optname, default=None):`
Interpret the key `optname` from the dictionary `options`
as a boolean and return it. Return `default` if `optname`
is not in `options`.
The valid string values for ``True`` are ``1``, ``yes``,
``true`` and ``on``, the ones for ``False`` are ``0``,
``no``, ``false`` and ``off`` (matched case-insensitively).
def `get_int_opt(options, optname, default=None):`
As `get_bool_opt`, but interpret the value as an integer.
def `get_list_opt(options, optname, default=None):`
If the key `optname` from the dictionary `options` 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.
def `get_choice_opt(options, optname, allowed, default=None):`
If the key `optname` from the dictionary is not in the sequence
`allowed`, raise an error, otherwise return it. *New in Pygments 0.8.*

View File

@ -1,5 +0,0 @@
=======
Authors
=======
[authors]

View File

@ -1,5 +0,0 @@
=========
Changelog
=========
[changelog]

View File

@ -1,69 +0,0 @@
.. -*- mode: rst -*-
========
Overview
========
Welcome to the Pygments documentation.
- Starting with Pygments
- `Installation <installation.txt>`_
- `Introduction and Quickstart <quickstart.txt>`_
- `Command line interface <cmdline.txt>`_
- Builtin components
- `Lexers <lexers.txt>`_
- `Formatters <formatters.txt>`_
- `Filters <filters.txt>`_
- `Styles <styles.txt>`_
- Reference
- `Unicode and encodings <unicode.txt>`_
- `Builtin tokens <tokens.txt>`_
- `API documentation <api.txt>`_
- Hacking for Pygments
- `Write your own lexer <lexerdevelopment.txt>`_
- `Write your own formatter <formatterdevelopment.txt>`_
- `Write your own filter <filterdevelopment.txt>`_
- `Register plugins <plugins.txt>`_
- Hints and Tricks
- `Using Pygments in ReST documents <rstdirective.txt>`_
- `Using Pygments with MoinMoin <moinmoin.txt>`_
- `Using Pygments in other contexts <integrate.txt>`_
- About Pygments
- `Changelog <changelog.txt>`_
- `Authors <authors.txt>`_
--------------
If you find bugs or have suggestions for the documentation, please
look `here`_ for info on how to contact the team.
You can download an offline version of this documentation from the
`download page`_.
.. _here: http://pygments.org/contribute/
.. _download page: http://pygments.org/download/

View File

@ -1,71 +0,0 @@
.. -*- mode: rst -*-
============
Installation
============
Pygments requires at least Python 2.4 to work correctly. Just to clarify:
there *won't* ever be support for Python versions below 2.4. However, there
are no other dependencies.
Installing a released version
=============================
As a Python egg (via easy_install)
----------------------------------
You can install the most recent Pygments version using `easy_install`_::
sudo easy_install Pygments
This will install a Pygments egg in your Python installation's site-packages
directory.
From the tarball release
-------------------------
1. Download the most recent tarball from the `download page`_
2. Unpack the tarball
3. ``sudo python setup.py install``
Note that the last command will automatically download and install
`setuptools`_ if you don't already have it installed. This requires a working
internet connection.
This will install Pygments into your Python installation's site-packages directory.
Installing the development version
==================================
If you want to play around with the code
----------------------------------------
1. Install `Mercurial`_
2. ``hg clone http://bitbucket.org/birkenfeld/pygments-main pygments``
3. ``cd pygments``
4. ``ln -s pygments /usr/lib/python2.X/site-packages``
5. ``ln -s pygmentize /usr/local/bin``
As an alternative to steps 4 and 5 you can also do ``python setup.py develop``
which will install the package via setuptools in development mode.
..
If you just want the latest features and use them
-------------------------------------------------
::
sudo easy_install Pygments==dev
This will install a Pygments egg containing the latest Subversion trunk code
in your Python installation's site-packages directory. Every time the command
is run, the sources are updated from Subversion.
.. _download page: http://pygments.org/download/
.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
.. _Mercurial: http://selenic.com/mercurial/

View File

@ -1,551 +0,0 @@
.. -*- mode: rst -*-
====================
Write your own lexer
====================
If a lexer for your favorite language is missing in the Pygments package, you can
easily write your own and extend Pygments.
All you need can be found inside the `pygments.lexer` module. As you can read in
the `API documentation <api.txt>`_, a lexer is a class that is initialized with
some keyword arguments (the lexer options) and that provides a
`get_tokens_unprocessed()` method which is given a string or unicode object with
the data to parse.
The `get_tokens_unprocessed()` method must return an iterator or iterable
containing tuples in the form ``(index, token, value)``. Normally you don't need
to do this since there are numerous base lexers you can subclass.
RegexLexer
==========
A very powerful (but quite easy to use) lexer is the `RegexLexer`. This lexer
base class allows you to define lexing rules in terms of *regular expressions*
for different *states*.
States are groups of regular expressions that are matched against the input
string at the *current position*. If one of these expressions matches, a
corresponding action is performed (normally yielding a token with a specific
type), the current position is set to where the last match ended and the
matching process continues with the first regex of the current state.
Lexer states are kept in a state stack: each time a new state is entered, the
new state is pushed onto the stack. The most basic lexers (like the
`DiffLexer`) just need one state.
Each state is defined as a list of tuples in the form (`regex`, `action`,
`new_state`) where the last item is optional. In the most basic form, `action`
is a token type (like `Name.Builtin`). That means: When `regex` matches, emit a
token with the match text and type `tokentype` and push `new_state` on the state
stack. If the new state is ``'#pop'``, the topmost state is popped from the
stack instead. (To pop more than one state, use ``'#pop:2'`` and so on.)
``'#push'`` is a synonym for pushing the current state on the
stack.
The following example shows the `DiffLexer` from the builtin lexers. Note that
it contains some additional attributes `name`, `aliases` and `filenames` which
aren't required for a lexer. They are used by the builtin lexer lookup
functions.
.. sourcecode:: python
from pygments.lexer import RegexLexer
from pygments.token import *
class DiffLexer(RegexLexer):
name = 'Diff'
aliases = ['diff']
filenames = ['*.diff']
tokens = {
'root': [
(r' .*\n', Text),
(r'\+.*\n', Generic.Inserted),
(r'-.*\n', Generic.Deleted),
(r'@.*\n', Generic.Subheading),
(r'Index.*\n', Generic.Heading),
(r'=.*\n', Generic.Heading),
(r'.*\n', Text),
]
}
As you can see this lexer only uses one state. When the lexer starts scanning
the text, it first checks if the current character is a space. If this is true
it scans everything until newline and returns the parsed data as `Text` token.
If this rule doesn't match, it checks if the current char is a plus sign. And
so on.
If no rule matches at the current position, the current char is emitted as an
`Error` token that indicates a parsing error, and the position is increased by
1.
Regex Flags
===========
You can either define regex flags in the regex (``r'(?x)foo bar'``) or by adding
a `flags` attribute to your lexer class. If no attribute is defined, it defaults
to `re.MULTILINE`. For more informations about regular expression flags see the
`regular expressions`_ help page in the python documentation.
.. _regular expressions: http://docs.python.org/lib/re-syntax.html
Scanning multiple tokens at once
================================
Here is a more complex lexer that highlights INI files. INI files consist of
sections, comments and key = value pairs:
.. sourcecode:: python
from pygments.lexer import RegexLexer, bygroups
from pygments.token import *
class IniLexer(RegexLexer):
name = 'INI'
aliases = ['ini', 'cfg']
filenames = ['*.ini', '*.cfg']
tokens = {
'root': [
(r'\s+', Text),
(r';.*?$', Comment),
(r'\[.*?\]$', Keyword),
(r'(.*?)(\s*)(=)(\s*)(.*?)$',
bygroups(Name.Attribute, Text, Operator, Text, String))
]
}
The lexer first looks for whitespace, comments and section names. And later it
looks for a line that looks like a key, value pair, separated by an ``'='``
sign, and optional whitespace.
The `bygroups` helper makes sure that each group is yielded with a different
token type. First the `Name.Attribute` token, then a `Text` token for the
optional whitespace, after that a `Operator` token for the equals sign. Then a
`Text` token for the whitespace again. The rest of the line is returned as
`String`.
Note that for this to work, every part of the match must be inside a capturing
group (a ``(...)``), and there must not be any nested capturing groups. If you
nevertheless need a group, use a non-capturing group defined using this syntax:
``r'(?:some|words|here)'`` (note the ``?:`` after the beginning parenthesis).
If you find yourself needing a capturing group inside the regex which
shouldn't be part of the output but is used in the regular expressions for
backreferencing (eg: ``r'(<(foo|bar)>)(.*?)(</\2>)'``), you can pass `None`
to the bygroups function and it will skip that group will be skipped in the
output.
Changing states
===============
Many lexers need multiple states to work as expected. For example, some
languages allow multiline comments to be nested. Since this is a recursive
pattern it's impossible to lex just using regular expressions.
Here is the solution:
.. sourcecode:: python
from pygments.lexer import RegexLexer
from pygments.token import *
class ExampleLexer(RegexLexer):
name = 'Example Lexer with states'
tokens = {
'root': [
(r'[^/]+', Text),
(r'/\*', Comment.Multiline, 'comment'),
(r'//.*?$', Comment.Singleline),
(r'/', Text)
],
'comment': [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
]
}
This lexer starts lexing in the ``'root'`` state. It tries to match as much as
possible until it finds a slash (``'/'``). If the next character after the slash
is a star (``'*'``) the `RegexLexer` sends those two characters to the output
stream marked as `Comment.Multiline` and continues parsing with the rules
defined in the ``'comment'`` state.
If there wasn't a star after the slash, the `RegexLexer` checks if it's a
singleline comment (eg: followed by a second slash). If this also wasn't the
case it must be a single slash (the separate regex for a single slash must also
be given, else the slash would be marked as an error token).
Inside the ``'comment'`` state, we do the same thing again. Scan until the lexer
finds a star or slash. If it's the opening of a multiline comment, push the
``'comment'`` state on the stack and continue scanning, again in the
``'comment'`` state. Else, check if it's the end of the multiline comment. If
yes, pop one state from the stack.
Note: If you pop from an empty stack you'll get an `IndexError`. (There is an
easy way to prevent this from happening: don't ``'#pop'`` in the root state).
If the `RegexLexer` encounters a newline that is flagged as an error token, the
stack is emptied and the lexer continues scanning in the ``'root'`` state. This
helps producing error-tolerant highlighting for erroneous input, e.g. when a
single-line string is not closed.
Advanced state tricks
=====================
There are a few more things you can do with states:
- You can push multiple states onto the stack if you give a tuple instead of a
simple string as the third item in a rule tuple. For example, if you want to
match a comment containing a directive, something like::
/* <processing directive> rest of comment */
you can use this rule:
.. sourcecode:: python
tokens = {
'root': [
(r'/\* <', Comment, ('comment', 'directive')),
...
],
'directive': [
(r'[^>]*', Comment.Directive),
(r'>', Comment, '#pop'),
],
'comment': [
(r'[^*]+', Comment),
(r'\*/', Comment, '#pop'),
(r'\*', Comment),
]
}
When this encounters the above sample, first ``'comment'`` and ``'directive'``
are pushed onto the stack, then the lexer continues in the directive state
until it finds the closing ``>``, then it continues in the comment state until
the closing ``*/``. Then, both states are popped from the stack again and
lexing continues in the root state.
*New in Pygments 0.9:* The tuple can contain the special ``'#push'`` and
``'#pop'`` (but not ``'#pop:n'``) directives.
- You can include the rules of a state in the definition of another. This is
done by using `include` from `pygments.lexer`:
.. sourcecode:: python
from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import *
class ExampleLexer(RegexLexer):
tokens = {
'comments': [
(r'/\*.*?\*/', Comment),
(r'//.*?\n', Comment),
],
'root': [
include('comments'),
(r'(function )(\w+)( {)',
bygroups(Keyword, Name, Keyword), 'function'),
(r'.', Text),
],
'function': [
(r'[^}/]+', Text),
include('comments'),
(r'/', Text),
(r'}', Keyword, '#pop'),
]
}
This is a hypothetical lexer for a language that consist of functions and
comments. Because comments can occur at toplevel and in functions, we need
rules for comments in both states. As you can see, the `include` helper saves
repeating rules that occur more than once (in this example, the state
``'comment'`` will never be entered by the lexer, as it's only there to be
included in ``'root'`` and ``'function'``).
- Sometimes, you may want to "combine" a state from existing ones. This is
possible with the `combine` helper from `pygments.lexer`.
If you, instead of a new state, write ``combined('state1', 'state2')`` as the
third item of a rule tuple, a new anonymous state will be formed from state1
and state2 and if the rule matches, the lexer will enter this state.
This is not used very often, but can be helpful in some cases, such as the
`PythonLexer`'s string literal processing.
- If you want your lexer to start lexing in a different state you can modify
the stack by overloading the `get_tokens_unprocessed()` method:
.. sourcecode:: python
from pygments.lexer import RegexLexer
class MyLexer(RegexLexer):
tokens = {...}
def get_tokens_unprocessed(self, text):
stack = ['root', 'otherstate']
for item in RegexLexer.get_tokens_unprocessed(text, stack):
yield item
Some lexers like the `PhpLexer` use this to make the leading ``<?php``
preprocessor comments optional. Note that you can crash the lexer easily
by putting values into the stack that don't exist in the token map. Also
removing ``'root'`` from the stack can result in strange errors!
- An empty regex at the end of a state list, combined with ``'#pop'``, can
act as a return point from a state that doesn't have a clear end marker.
Using multiple lexers
=====================
Using multiple lexers for the same input can be tricky. One of the easiest
combination techniques is shown here: You can replace the token type entry in a
rule tuple (the second item) with a lexer class. The matched text will then be
lexed with that lexer, and the resulting tokens will be yielded.
For example, look at this stripped-down HTML lexer:
.. sourcecode:: python
from pygments.lexer import RegexLexer, bygroups, using
from pygments.token import *
from pygments.lexers.web import JavascriptLexer
class HtmlLexer(RegexLexer):
name = 'HTML'
aliases = ['html']
filenames = ['*.html', '*.htm']
flags = re.IGNORECASE | re.DOTALL
tokens = {
'root': [
('[^<&]+', Text),
('&.*?;', Name.Entity),
(r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
(r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
(r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
],
'script-content': [
(r'(.+?)(<\s*/\s*script\s*>)',
bygroups(using(JavascriptLexer), Name.Tag),
'#pop'),
]
}
Here the content of a ``<script>`` tag is passed to a newly created instance of
a `JavascriptLexer` and not processed by the `HtmlLexer`. This is done using the
`using` helper that takes the other lexer class as its parameter.
Note the combination of `bygroups` and `using`. This makes sure that the content
up to the ``</script>`` end tag is processed by the `JavascriptLexer`, while the
end tag is yielded as a normal token with the `Name.Tag` type.
As an additional goodie, if the lexer class is replaced by `this` (imported from
`pygments.lexer`), the "other" lexer will be the current one (because you cannot
refer to the current class within the code that runs at class definition time).
Also note the ``(r'<\s*script\s*', Name.Tag, ('script-content', 'tag'))`` rule.
Here, two states are pushed onto the state stack, ``'script-content'`` and
``'tag'``. That means that first ``'tag'`` is processed, which will parse
attributes and the closing ``>``, then the ``'tag'`` state is popped and the
next state on top of the stack will be ``'script-content'``.
The `using()` helper has a special keyword argument, `state`, which works as
follows: if given, the lexer to use initially is not in the ``"root"`` state,
but in the state given by this argument. This *only* works with a `RegexLexer`.
Any other keywords arguments passed to `using()` are added to the keyword
arguments used to create the lexer.
Delegating Lexer
================
Another approach for nested lexers is the `DelegatingLexer` which is for
example used for the template engine lexers. It takes two lexers as
arguments on initialisation: a `root_lexer` and a `language_lexer`.
The input is processed as follows: First, the whole text is lexed with the
`language_lexer`. All tokens yielded with a type of ``Other`` are then
concatenated and given to the `root_lexer`. The language tokens of the
`language_lexer` are then inserted into the `root_lexer`'s token stream
at the appropriate positions.
.. sourcecode:: python
from pygments.lexer import DelegatingLexer
from pygments.lexers.web import HtmlLexer, PhpLexer
class HtmlPhpLexer(DelegatingLexer):
def __init__(self, **options):
super(HtmlPhpLexer, self).__init__(HtmlLexer, PhpLexer, **options)
This procedure ensures that e.g. HTML with template tags in it is highlighted
correctly even if the template tags are put into HTML tags or attributes.
If you want to change the needle token ``Other`` to something else, you can
give the lexer another token type as the third parameter:
.. sourcecode:: python
DelegatingLexer.__init__(MyLexer, OtherLexer, Text, **options)
Callbacks
=========
Sometimes the grammar of a language is so complex that a lexer would be unable
to parse it just by using regular expressions and stacks.
For this, the `RegexLexer` allows callbacks to be given in rule tuples, instead
of token types (`bygroups` and `using` are nothing else but preimplemented
callbacks). The callback must be a function taking two arguments:
* the lexer itself
* the match object for the last matched rule
The callback must then return an iterable of (or simply yield) ``(index,
tokentype, value)`` tuples, which are then just passed through by
`get_tokens_unprocessed()`. The ``index`` here is the position of the token in
the input string, ``tokentype`` is the normal token type (like `Name.Builtin`),
and ``value`` the associated part of the input string.
You can see an example here:
.. sourcecode:: python
from pygments.lexer import RegexLexer
from pygments.token import Generic
class HypotheticLexer(RegexLexer):
def headline_callback(lexer, match):
equal_signs = match.group(1)
text = match.group(2)
yield match.start(), Generic.Headline, equal_signs + text + equal_signs
tokens = {
'root': [
(r'(=+)(.*?)(\1)', headline_callback)
]
}
If the regex for the `headline_callback` matches, the function is called with the
match object. Note that after the callback is done, processing continues
normally, that is, after the end of the previous match. The callback has no
possibility to influence the position.
There are not really any simple examples for lexer callbacks, but you can see
them in action e.g. in the `compiled.py`_ source code in the `CLexer` and
`JavaLexer` classes.
.. _compiled.py: http://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/compiled.py
The ExtendedRegexLexer class
============================
The `RegexLexer`, even with callbacks, unfortunately isn't powerful enough for
the funky syntax rules of some languages that will go unnamed, such as Ruby.
But fear not; even then you don't have to abandon the regular expression
approach. For Pygments has a subclass of `RegexLexer`, the `ExtendedRegexLexer`.
All features known from RegexLexers are available here too, and the tokens are
specified in exactly the same way, *except* for one detail:
The `get_tokens_unprocessed()` method holds its internal state data not as local
variables, but in an instance of the `pygments.lexer.LexerContext` class, and
that instance is passed to callbacks as a third argument. This means that you
can modify the lexer state in callbacks.
The `LexerContext` class has the following members:
* `text` -- the input text
* `pos` -- the current starting position that is used for matching regexes
* `stack` -- a list containing the state stack
* `end` -- the maximum position to which regexes are matched, this defaults to
the length of `text`
Additionally, the `get_tokens_unprocessed()` method can be given a
`LexerContext` instead of a string and will then process this context instead of
creating a new one for the string argument.
Note that because you can set the current position to anything in the callback,
it won't be automatically be set by the caller after the callback is finished.
For example, this is how the hypothetical lexer above would be written with the
`ExtendedRegexLexer`:
.. sourcecode:: python
from pygments.lexer import ExtendedRegexLexer
from pygments.token import Generic
class ExHypotheticLexer(ExtendedRegexLexer):
def headline_callback(lexer, match, ctx):
equal_signs = match.group(1)
text = match.group(2)
yield match.start(), Generic.Headline, equal_signs + text + equal_signs
ctx.pos = match.end()
tokens = {
'root': [
(r'(=+)(.*?)(\1)', headline_callback)
]
}
This might sound confusing (and it can really be). But it is needed, and for an
example look at the Ruby lexer in `agile.py`_.
.. _agile.py: https://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/agile.py
Filtering Token Streams
=======================
Some languages ship a lot of builtin functions (for example PHP). The total
amount of those functions differs from system to system because not everybody
has every extension installed. In the case of PHP there are over 3000 builtin
functions. That's an incredible huge amount of functions, much more than you
can put into a regular expression.
But because only `Name` tokens can be function names it's solvable by overriding
the ``get_tokens_unprocessed()`` method. The following lexer subclasses the
`PythonLexer` so that it highlights some additional names as pseudo keywords:
.. sourcecode:: python
from pygments.lexers.agile import PythonLexer
from pygments.token import Name, Keyword
class MyPythonLexer(PythonLexer):
EXTRA_KEYWORDS = ['foo', 'bar', 'foobar', 'barfoo', 'spam', 'eggs']
def get_tokens_unprocessed(self, text):
for index, token, value in PythonLexer.get_tokens_unprocessed(self, text):
if token is Name and value in self.EXTRA_KEYWORDS:
yield index, Keyword.Pseudo, value
else:
yield index, token, value
The `PhpLexer` and `LuaLexer` use this method to resolve builtin functions.
**Note** Do not confuse this with the `filter`_ system.
.. _filter: filters.txt

View File

@ -1,64 +1,83 @@
#!/bin/sh #!/bin/bash
# Best effort auto-pygmentization with transparent decompression # Best effort auto-pygmentization with transparent decompression
# (c) Reuben Thomas 2012-2013 # by Reuben Thomas 2008-2015
# This program is in the public domain. # 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 # 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. # Set the environment variable PYGMENTIZE_OPTS or pass options before the file path to configure pygments.
# This program can be used as a .lessfilter for the less pager to auto-color less's output # This program can be used as a .lessfilter for the less pager to auto-color less's output
lexer=`pygmentize -N "$1"` file="${!#}" # last argument
if [ "$lexer" = "text" ]; then options=${@:1:$(($#-1))} # handle others args as options to pass to pygmentize
file_common_opts="--brief --dereference --uncompress"
unset lexer file_common_opts="--brief --dereference"
case `file --mime-type $file_common_opts "$1"` in
application/xml|image/svg+xml) lexer=xml;; lexer=$(pygmentize -N "$file")
text/html) lexer=html;; if [[ "$lexer" == text ]]; then
text/troff) lexer=nroff;; unset lexer
text/x-asm) lexer=nasm;; case $(file --mime-type --uncompress $file_common_opts "$file") in
text/x-awk) lexer=awk;; application/xml|image/svg+xml) lexer=xml;;
text/x-c) lexer=c;; application/javascript) lexer=javascript;;
text/x-c++) lexer=cpp;; text/html) lexer=html;;
text/x-diff) lexer=diff;; text/troff) lexer=nroff;;
text/x-fortran) lexer=fortran;; text/x-asm) lexer=nasm;;
text/x-gawk) lexer=gawk;; text/x-awk) lexer=awk;;
text/x-java) lexer=java;; text/x-c) lexer=c;;
text/x-lisp) lexer=common-lisp;; text/x-c++) lexer=cpp;;
text/x-lua) lexer=lua;; text/x-diff) lexer=diff;;
text/x-makefile) lexer=make;; text/x-fortran) lexer=fortran;;
text/x-msdos-batch) lexer=bat;; text/x-gawk) lexer=gawk;;
text/x-nawk) lexer=nawk;; text/x-java) lexer=java;;
text/x-pascal) lexer=pascal;; text/x-lisp) lexer=common-lisp;;
text/x-perl) lexer=perl;; text/x-lua) lexer=lua;;
text/x-php) lexer=php;; text/x-makefile) lexer=make;;
text/x-po) lexer=po;; text/x-msdos-batch) lexer=bat;;
text/x-python) lexer=python;; text/x-nawk) lexer=nawk;;
text/x-ruby) lexer=ruby;; text/x-pascal) lexer=pascal;;
text/x-shellscript) lexer=sh;; text/x-perl) lexer=perl;;
text/x-tcl) lexer=tcl;; text/x-php) lexer=php;;
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer text/x-po) lexer=po;;
text/x-python) lexer=python;;
# Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.6rc1 text/x-ruby) lexer=ruby;;
# text/calendar text/x-shellscript) lexer=sh;;
# text/PGP text/x-tcl) lexer=tcl;;
# text/rtf text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
# text/texmacs
# text/x-bcpl # Types that file outputs which pygmentize didn't support as of file 5.20, pygments 2.0
# text/x-info # text/calendar
# text/x-m4 # text/inf
# text/x-vcard # text/PGP
# text/x-xmcd # text/rtf
esac # text/texmacs
# text/vnd.graphviz
# text/x-bcpl
# text/x-info
# text/x-m4
# text/x-vcard
# text/x-xmcd
text/plain) # special filenames. TODO: insert more
case $(basename "$file") in
.zshrc) lexer=sh;;
esac
;;
esac
fi fi
encoding=`file --brief --mime-encoding $file_common_opts "$1"` encoding=$(file --mime-encoding --uncompress $file_common_opts "$file")
if [[ $encoding == "us-asciibinarybinary" ]]; then
encoding="us-ascii"
fi
if [ -n "$lexer" ]; then if [[ -n "$lexer" ]]; then
# FIXME: Specify input encoding rather than output encoding https://bitbucket.org/birkenfeld/pygments-main/issue/800 concat=cat
zcat "$1" | pygmentize -O encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS -l $lexer case $(file $file_common_opts --mime-type "$file") in
exit 0 application/x-gzip) concat=zcat;;
application/x-bzip2) concat=bzcat;;
application/x-xz) concat=xzcat;;
esac
exec $concat "$file" | pygmentize -O inencoding=$encoding $PYGMENTIZE_OPTS $options -l $lexer
fi fi
exit 1 exit 1

View File

@ -4,14 +4,20 @@
Builtins Generator for Lasso 9 Builtins Generator for Lasso 9
This is the shell script that was used to extract Lasso 9's built-in keywords This is the shell script that was used to extract Lasso 9's built-in keywords
and generate most of the _lassobuiltins.py file. When run, it creates a file and generate most of the _lasso_builtins.py file. When run, it creates a file
named "lassobuiltins-9.py" containing the types, traits, and methods of the containing the types, traits, methods, and members of the currently-installed
currently-installed version of Lasso 9. version of Lasso 9.
A partial list of keywords in Lasso 8 can be generated with this code: A list of tags in Lasso 8 can be generated with this code:
<?LassoScript <?LassoScript
local('l8tags' = list); local('l8tags' = list,
'l8libs' = array('Cache','ChartFX','Client','Database','File','HTTP',
'iCal','Lasso','Link','List','PDF','Response','Stock','String',
'Thread','Valid','WAP','XML'));
iterate(#l8libs, local('library'));
local('result' = namespace_load(#library));
/iterate;
iterate(tags_list, local('i')); iterate(tags_list, local('i'));
#l8tags->insert(string_removeleading(#i, -pattern='_global_')); #l8tags->insert(string_removeleading(#i, -pattern='_global_'));
/iterate; /iterate;
@ -23,98 +29,133 @@
*/ */
output("This output statement is required for a complete list of methods.") output("This output statement is required for a complete list of methods.")
local(f) = file("lassobuiltins-9.py") local(f) = file("_lasso_builtins-9.py")
#f->doWithClose => { #f->doWithClose => {
#f->openWrite #f->openTruncate
#f->writeString('# -*- coding: utf-8 -*- #f->writeString('# -*- coding: utf-8 -*-
""" """
pygments.lexers._lassobuiltins pygments.lexers._lasso_builtins
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Built-in Lasso types, traits, and methods. Built-in Lasso types, traits, methods, and members.
:copyright: Copyright 2006-'+date->year+' by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
""" """
') ')
lcapi_loadModules // Load and register contents of $LASSO9_MASTER_HOME/LassoModules/
database_initialize
// Load all of the libraries from builtins and lassoserver // Load all of the libraries from builtins and lassoserver
// This forces all possible available types and methods to be registered // This forces all possible available types and methods to be registered
local(srcs = local(srcs =
tie( (:
dir(sys_masterHomePath + 'LassoLibraries/builtins/')->eachFilePath, dir(sys_masterHomePath + '/LassoLibraries/builtins/')->eachFilePath,
dir(sys_masterHomePath + 'LassoLibraries/lassoserver/')->eachFilePath dir(sys_masterHomePath + '/LassoLibraries/lassoserver/')->eachFilePath
) )
) )
with topLevelDir in #srcs with topLevelDir in delve(#srcs)
where !#topLevelDir->lastComponent->beginsWith('.') where not #topLevelDir->lastComponent->beginsWith('.')
do protect => { do protect => {
handle_error => { handle_error => {
stdoutnl('Unable to load: ' + #topLevelDir + ' ' + error_msg) stdoutnl('Unable to load: ' + #topLevelDir + ' ' + error_msg)
} }
library_thread_loader->loadLibrary(#topLevelDir) library_thread_loader->loadLibrary(#topLevelDir)
stdoutnl('Loaded: ' + #topLevelDir) stdoutnl('Loaded: ' + #topLevelDir)
} }
email_initialize
log_initialize
session_initialize
local( local(
typesList = list(), typesList = set(),
traitsList = list(), traitsList = set(),
methodsList = list() unboundMethodsList = set(),
memberMethodsList = set()
) )
// unbound methods
with method in sys_listUnboundMethods
where !#method->methodName->asString->endsWith('=')
where #method->methodName->asString->isalpha(1)
where #methodsList !>> #method->methodName->asString
do #methodsList->insert(#method->methodName->asString)
// traits
with trait in sys_listTraits
where !#trait->asString->beginsWith('$')
where #traitsList !>> #trait->asString
do {
#traitsList->insert(#trait->asString)
with tmethod in tie(#trait->getType->provides, #trait->getType->requires)
where !#tmethod->methodName->asString->endsWith('=')
where #tmethod->methodName->asString->isalpha(1)
where #methodsList !>> #tmethod->methodName->asString
do #methodsList->insert(#tmethod->methodName->asString)
}
// types // types
with type in sys_listTypes with type in sys_listTypes
where #typesList !>> #type->asString where not #type->asString->endsWith('$') // skip threads
do { do {
#typesList->insert(#type->asString) #typesList->insert(#type)
with tmethod in #type->getType->listMethods
where !#tmethod->methodName->asString->endsWith('=')
where #tmethod->methodName->asString->isalpha(1)
where #methodsList !>> #tmethod->methodName->asString
do #methodsList->insert(#tmethod->methodName->asString)
} }
#f->writeString("BUILTINS = { // traits
'Types': [ with trait in sys_listTraits
") where not #trait->asString->beginsWith('$') // skip combined traits
with t in #typesList do {
do #f->writeString(" '"+string_lowercase(#t)+"',\n") #traitsList->insert(#trait)
}
#f->writeString(" ], // member methods
'Traits': [ with type in #typesList
") do {
with t in #traitsList with method in #type->getType->listMethods
do #f->writeString(" '"+string_lowercase(#t)+"',\n") where #method->typeName == #type // skip inherited methods
let name = #method->methodName
where not #name->asString->endsWith('=') // skip setter methods
where #name->asString->isAlpha(1) // skip unpublished methods
do {
#memberMethodsList->insert(#name)
}
}
with trait in #traitsList
do {
with method in #trait->getType->provides
where #method->typeName == #trait // skip inherited methods
let name = #method->methodName
where not #name->asString->endsWith('=') // skip setter methods
where #name->asString->isAlpha(1) // skip unpublished methods
do {
#memberMethodsList->insert(#name)
}
}
#f->writeString(" ], // unbound methods
'Methods': [ with method in sys_listUnboundMethods
") let name = #method->methodName
with t in #methodsList where not #name->asString->endsWith('=') // skip setter methods
do #f->writeString(" '"+string_lowercase(#t)+"',\n") where #name->asString->isAlpha(1) // skip unpublished methods
where #typesList !>> #name
where #traitsList !>> #name
do {
#unboundMethodsList->insert(#name)
}
#f->writeString(" ], // write to file
with i in (:
pair(#typesList, "BUILTINS = {
'Types': (
"),
pair(#traitsList, " ),
'Traits': (
"),
pair(#unboundMethodsList, " ),
'Unbound Methods': (
"),
pair(#memberMethodsList, " )
}
MEMBERS = {
'Member Methods': (
")
)
do {
#f->writeString(#i->second)
with t in (#i->first)
let ts = #t->asString
order by #ts
do {
#f->writeString(" '"+#ts->lowercase&asString+"',\n")
}
}
#f->writeString(" )
} }
") ")

View File

@ -6,14 +6,9 @@
This fragment is a Markdown_ preprocessor that renders source code This fragment is a Markdown_ preprocessor that renders source code
to HTML via Pygments. To use it, invoke Markdown like so:: to HTML via Pygments. To use it, invoke Markdown like so::
from markdown import Markdown import markdown
md = Markdown() html = markdown.markdown(someText, extensions=[CodeBlockExtension()])
md.textPreprocessors.insert(0, CodeBlockPreprocessor())
html = md.convert(someText)
markdown is then a callable that can be passed to the context of
a template and used in that template, for example.
This uses CSS classes by default, so use This uses CSS classes by default, so use
``pygmentize -S <some style> -f html > pygments.css`` ``pygmentize -S <some style> -f html > pygments.css``
@ -25,9 +20,9 @@
some code some code
[/sourcecode] [/sourcecode]
.. _Markdown: http://www.freewisdom.org/projects/python-markdown/ .. _Markdown: https://pypi.python.org/pypi/Markdown
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
@ -40,17 +35,17 @@ INLINESTYLES = False
import re import re
from markdown import TextPreprocessor from markdown.preprocessors import Preprocessor
from markdown.extensions import Extension
from pygments import highlight from pygments import highlight
from pygments.formatters import HtmlFormatter from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, TextLexer from pygments.lexers import get_lexer_by_name, TextLexer
class CodeBlockPreprocessor(TextPreprocessor): class CodeBlockPreprocessor(Preprocessor):
pattern = re.compile( pattern = re.compile(r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
formatter = HtmlFormatter(noclasses=INLINESTYLES) formatter = HtmlFormatter(noclasses=INLINESTYLES)
@ -63,5 +58,10 @@ class CodeBlockPreprocessor(TextPreprocessor):
code = highlight(m.group(2), lexer, self.formatter) code = highlight(m.group(2), lexer, self.formatter)
code = code.replace('\n\n', '\n&nbsp;\n').replace('\n', '<br />') code = code.replace('\n\n', '\n&nbsp;\n').replace('\n', '<br />')
return '\n\n<div class="code">%s</div>\n\n' % code return '\n\n<div class="code">%s</div>\n\n' % code
return self.pattern.sub( joined_lines = "\n".join(lines)
repl, lines) joined_lines = self.pattern.sub(repl, joined_lines)
return joined_lines.split("\n")
class CodeBlockExtension(Extension):
def extendMarkdown(self, md, md_globals):
md.preprocessors.add('CodeBlockPreprocessor', CodeBlockPreprocessor(), '_begin')

View File

@ -31,7 +31,7 @@
If you do not want to do that and are willing to accept larger HTML If you do not want to do that and are willing to accept larger HTML
output, you can set the INLINESTYLES option below to True. output, you can set the INLINESTYLES option below to True.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """

View File

@ -1,77 +0,0 @@
# -*- coding: utf-8 -*-
"""
The Pygments reStructuredText directive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This fragment is a Docutils_ 0.4 directive that renders source code
(to HTML only, currently) via Pygments.
To use it, adjust the options below and copy the code into a module
that you import on initialization. The code then automatically
registers a ``sourcecode`` directive that you can use instead of
normal code blocks like this::
.. sourcecode:: python
My code goes here.
If you want to have different code styles, e.g. one with line numbers
and one without, add formatters with their names in the VARIANTS dict
below. You can invoke them instead of the DEFAULT one by using a
directive option::
.. sourcecode:: python
:linenos:
My code goes here.
Look at the `directive documentation`_ to get all the gory details.
.. _Docutils: http://docutils.sf.net/
.. _directive documentation:
http://docutils.sourceforge.net/docs/howto/rst-directives.html
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
# Options
# ~~~~~~~
# Set to True if you want inline CSS styles instead of classes
INLINESTYLES = False
from pygments.formatters import HtmlFormatter
# The default formatter
DEFAULT = HtmlFormatter(noclasses=INLINESTYLES)
# Add name -> formatter pairs for every variant you want to use
VARIANTS = {
# 'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),
}
from docutils import nodes
from docutils.parsers.rst import directives
from pygments import highlight
from pygments.lexers import get_lexer_by_name, TextLexer
def pygments_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
try:
lexer = get_lexer_by_name(arguments[0])
except ValueError:
# no lexer found - use the text one instead of an exception
lexer = TextLexer()
# take an arbitrary option if more than one is given
formatter = options and VARIANTS[options.keys()[0]] or DEFAULT
parsed = highlight(u'\n'.join(content), lexer, formatter)
return [nodes.raw('', parsed, format='html')]
pygments_directive.arguments = (1, 0, 1)
pygments_directive.content = 1
pygments_directive.options = dict([(key, directives.flag) for key in VARIANTS])
directives.register_directive('sourcecode', pygments_directive)

View File

@ -31,7 +31,7 @@
.. _directive documentation: .. _directive documentation:
http://docutils.sourceforge.net/docs/howto/rst-directives.html http://docutils.sourceforge.net/docs/howto/rst-directives.html
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
@ -75,9 +75,8 @@ class Pygments(Directive):
# no lexer found - use the text one instead of an exception # no lexer found - use the text one instead of an exception
lexer = TextLexer() lexer = TextLexer()
# take an arbitrary option if more than one is given # take an arbitrary option if more than one is given
formatter = self.options and VARIANTS[self.options.keys()[0]] or DEFAULT formatter = self.options and VARIANTS[list(self.options)[0]] or DEFAULT
parsed = highlight(u'\n'.join(self.content), lexer, formatter) parsed = highlight(u'\n'.join(self.content), lexer, formatter)
return [nodes.raw('', parsed, format='html')] return [nodes.raw('', parsed, format='html')]
directives.register_directive('sourcecode', Pygments) directives.register_directive('sourcecode', Pygments)

564
vendor/pygments/ez_setup.py vendored Executable file → Normal file
View File

@ -13,264 +13,370 @@ the appropriate options to ``use_setuptools()``.
This file can also be run as a script to install or upgrade setuptools. This file can also be run as a script to install or upgrade setuptools.
""" """
import os
import shutil
import sys import sys
DEFAULT_VERSION = "0.6c9" import tempfile
DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] import tarfile
import optparse
import subprocess
import platform
md5_data = { from distutils import log
'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca',
'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb',
'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b',
'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a',
'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618',
'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac',
'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5',
'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4',
'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c',
'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b',
'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27',
'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277',
'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa',
'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e',
'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e',
'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f',
'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2',
'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc',
'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167',
'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64',
'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d',
'setuptools-0.6c6-py2.3.egg': '35686b78116a668847237b69d549ec20',
'setuptools-0.6c6-py2.4.egg': '3c56af57be3225019260a644430065ab',
'setuptools-0.6c6-py2.5.egg': 'b2f8a7520709a5b34f80946de5f02f53',
'setuptools-0.6c7-py2.3.egg': '209fdf9adc3a615e5115b725658e13e2',
'setuptools-0.6c7-py2.4.egg': '5a8f954807d46a0fb67cf1f26c55a82e',
'setuptools-0.6c7-py2.5.egg': '45d2ad28f9750e7434111fde831e8372',
'setuptools-0.6c8-py2.3.egg': '50759d29b349db8cfd807ba8303f1902',
'setuptools-0.6c8-py2.4.egg': 'cba38d74f7d483c06e9daa6070cce6de',
'setuptools-0.6c8-py2.5.egg': '1721747ee329dc150590a58b3e1ac95b',
'setuptools-0.6c9-py2.3.egg': 'a83c4020414807b496e4cfbe08507c03',
'setuptools-0.6c9-py2.4.egg': '260a2be2e5388d66bdaee06abec6342a',
'setuptools-0.6c9-py2.5.egg': 'fe67c3e5a17b12c0e7c541b7ea43a8e6',
'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a',
}
import sys, os try:
try: from hashlib import md5 from site import USER_SITE
except ImportError: from md5 import md5 except ImportError:
USER_SITE = None
def _validate_md5(egg_name, data): DEFAULT_VERSION = "1.4.2"
if egg_name in md5_data: DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
digest = md5(data).hexdigest()
if digest != md5_data[egg_name]:
print >>sys.stderr, (
"md5 validation of %s failed! (Possible download problem?)"
% egg_name
)
sys.exit(2)
return data
def use_setuptools( def _python_cmd(*args):
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, args = (sys.executable,) + args
download_delay=15 return subprocess.call(args) == 0
):
"""Automatically find/download setuptools and make it available on sys.path
`version` should be a valid setuptools version number that is available def _check_call_py24(cmd, *args, **kwargs):
as an egg for download under the `download_base` URL (which should end with res = subprocess.call(cmd, *args, **kwargs)
a '/'). `to_dir` is the directory where setuptools will be downloaded, if class CalledProcessError(Exception):
it is not already available. If `download_delay` is specified, it should pass
be the number of seconds that will be paused before initiating a download, if not res == 0:
should one be required. If an older version of setuptools is installed, msg = "Command '%s' return non-zero exit status %d" % (cmd, res)
this routine will print a message to ``sys.stderr`` and raise SystemExit in raise CalledProcessError(msg)
an attempt to abort the calling script. vars(subprocess).setdefault('check_call', _check_call_py24)
"""
was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules def _install(tarball, install_args=()):
def do_download(): # extracting the tarball
egg = download_setuptools(version, download_base, to_dir, download_delay) tmpdir = tempfile.mkdtemp()
sys.path.insert(0, egg) log.warn('Extracting in %s', tmpdir)
import setuptools; setuptools.bootstrap_install_from = egg old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# installing
log.warn('Installing Setuptools')
if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.')
log.warn('See the error message above.')
# exitcode will be 2
return 2
finally:
os.chdir(old_wd)
shutil.rmtree(tmpdir)
def _build_egg(egg, tarball, to_dir):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
_extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s', subdir)
# building an egg
log.warn('Building a Setuptools egg in %s', to_dir)
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
finally:
os.chdir(old_wd)
shutil.rmtree(tmpdir)
# returning the result
log.warn(egg)
if not os.path.exists(egg):
raise IOError('Could not build the egg.')
def _do_download(version, download_base, to_dir, download_delay):
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
if not os.path.exists(egg):
tarball = download_setuptools(version, download_base,
to_dir, download_delay)
_build_egg(egg, tarball, to_dir)
sys.path.insert(0, egg)
# Remove previously-imported pkg_resources if present (see
# https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
if 'pkg_resources' in sys.modules:
del sys.modules['pkg_resources']
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15):
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \
'setuptools' in sys.modules
try: try:
import pkg_resources import pkg_resources
except ImportError: except ImportError:
return do_download() return _do_download(version, download_base, to_dir, download_delay)
try: try:
pkg_resources.require("setuptools>="+version); return pkg_resources.require("setuptools>=" + version)
except pkg_resources.VersionConflict, e: return
except pkg_resources.VersionConflict:
e = sys.exc_info()[1]
if was_imported: if was_imported:
print >>sys.stderr, ( sys.stderr.write(
"The required version of setuptools (>=%s) is not available, and\n" "The required version of setuptools (>=%s) is not available,\n"
"can't be installed while this script is running. Please install\n" "and can't be installed while this script is running. Please\n"
" a more recent version first, using 'easy_install -U setuptools'." "install a more recent version first, using\n"
"\n\n(Currently using %r)" "'easy_install -U setuptools'."
) % (version, e.args[0]) "\n\n(Currently using %r)\n" % (version, e.args[0]))
sys.exit(2) sys.exit(2)
else: else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok del pkg_resources, sys.modules['pkg_resources'] # reload ok
return do_download() return _do_download(version, download_base, to_dir,
download_delay)
except pkg_resources.DistributionNotFound: except pkg_resources.DistributionNotFound:
return do_download() return _do_download(version, download_base, to_dir,
download_delay)
def download_setuptools( def _clean_check(cmd, target):
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, """
delay = 15 Run the command to download target. If the command fails, clean up before
): re-raising the error.
"""
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
if os.access(target, os.F_OK):
os.unlink(target)
raise
def download_file_powershell(url, target):
"""
Download the file at url to target using Powershell (which will validate
trust). Raise an exception if the command cannot complete.
"""
target = os.path.abspath(target)
cmd = [
'powershell',
'-Command',
"(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(),
]
_clean_check(cmd, target)
def has_powershell():
if platform.system() != 'Windows':
return False
cmd = ['powershell', '-Command', 'echo test']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_powershell.viable = has_powershell
def download_file_curl(url, target):
cmd = ['curl', url, '--silent', '--output', target]
_clean_check(cmd, target)
def has_curl():
cmd = ['curl', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_curl.viable = has_curl
def download_file_wget(url, target):
cmd = ['wget', url, '--quiet', '--output-document', target]
_clean_check(cmd, target)
def has_wget():
cmd = ['wget', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
finally:
devnull.close()
return True
download_file_wget.viable = has_wget
def download_file_insecure(url, target):
"""
Use Python to download the file, even though it cannot authenticate the
connection.
"""
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
src = dst = None
try:
src = urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = src.read()
dst = open(target, "wb")
dst.write(data)
finally:
if src:
src.close()
if dst:
dst.close()
download_file_insecure.viable = lambda: True
def get_best_downloader():
downloaders = [
download_file_powershell,
download_file_curl,
download_file_wget,
download_file_insecure,
]
for dl in downloaders:
if dl.viable():
return dl
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15,
downloader_factory=get_best_downloader):
"""Download setuptools from a specified location and return its filename """Download setuptools from a specified location and return its filename
`version` should be a valid setuptools version number that is available `version` should be a valid setuptools version number that is available
as an egg for download under the `download_base` URL (which should end as an egg for download under the `download_base` URL (which should end
with a '/'). `to_dir` is the directory where the egg will be downloaded. with a '/'). `to_dir` is the directory where the egg will be downloaded.
`delay` is the number of seconds to pause before an actual download attempt. `delay` is the number of seconds to pause before an actual download
attempt.
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
""" """
import urllib2, shutil # making sure we use the absolute path
egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) to_dir = os.path.abspath(to_dir)
url = download_base + egg_name tgz_name = "setuptools-%s.tar.gz" % version
saveto = os.path.join(to_dir, egg_name) url = download_base + tgz_name
src = dst = None saveto = os.path.join(to_dir, tgz_name)
if not os.path.exists(saveto): # Avoid repeated downloads if not os.path.exists(saveto): # Avoid repeated downloads
try: log.warn("Downloading %s", url)
from distutils import log downloader = downloader_factory()
if delay: downloader(url, saveto)
log.warn("""
---------------------------------------------------------------------------
This script requires setuptools version %s to run (even to display
help). I will attempt to download it for you (from
%s), but
you may need to enable firewall access for this script first.
I will start the download in %d seconds.
(Note: if this machine does not have network access, please obtain the file
%s
and place it in this directory before rerunning this script.)
---------------------------------------------------------------------------""",
version, download_base, delay, url
); from time import sleep; sleep(delay)
log.warn("Downloading %s", url)
src = urllib2.urlopen(url)
# Read/write all in one block, so we don't create a corrupt file
# if the download is interrupted.
data = _validate_md5(egg_name, src.read())
dst = open(saveto,"wb"); dst.write(data)
finally:
if src: src.close()
if dst: dst.close()
return os.path.realpath(saveto) return os.path.realpath(saveto)
def _extractall(self, path=".", members=None):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
import copy
import operator
from tarfile import ExtractError
directories = []
if members is None:
members = self
for tarinfo in members:
if tarinfo.isdir():
# Extract directories with a safe mode.
directories.append(tarinfo)
tarinfo = copy.copy(tarinfo)
tarinfo.mode = 448 # decimal for oct 0700
self.extract(tarinfo, path)
# Reverse sort directories.
if sys.version_info < (2, 4):
def sorter(dir1, dir2):
return cmp(dir1.name, dir2.name)
directories.sort(sorter)
directories.reverse()
else:
directories.sort(key=operator.attrgetter('name'), reverse=True)
# Set correct owner, mtime and filemode on directories.
for tarinfo in directories:
dirpath = os.path.join(path, tarinfo.name)
try:
self.chown(tarinfo, dirpath)
self.utime(tarinfo, dirpath)
self.chmod(tarinfo, dirpath)
except ExtractError:
e = sys.exc_info()[1]
if self.errorlevel > 1:
raise
else:
self._dbg(1, "tarfile: %s" % e)
def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package
"""
install_args = []
if options.user_install:
if sys.version_info < (2, 6):
log.warn("--user requires Python 2.6 or later")
raise SystemExit(1)
install_args.append('--user')
return install_args
def _parse_args():
"""
Parse the command line for options
"""
parser = optparse.OptionParser()
parser.add_option(
'--user', dest='user_install', action='store_true', default=False,
help='install in user site package (requires Python 2.6 or later)')
parser.add_option(
'--download-base', dest='download_base', metavar="URL",
default=DEFAULT_URL,
help='alternative URL from where to download the setuptools package')
parser.add_option(
'--insecure', dest='downloader_factory', action='store_const',
const=lambda: download_file_insecure, default=get_best_downloader,
help='Use internal, non-validating downloader'
)
options, args = parser.parse_args()
# positional arguments are ignored
return options
def main(version=DEFAULT_VERSION):
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall""" """Install or upgrade setuptools and EasyInstall"""
try: options = _parse_args()
import setuptools tarball = download_setuptools(download_base=options.download_base,
except ImportError: downloader_factory=options.downloader_factory)
egg = None return _install(tarball, _build_install_args(options))
try:
egg = download_setuptools(version, delay=0)
sys.path.insert(0,egg)
from setuptools.command.easy_install import main
return main(list(argv)+[egg]) # we're done here
finally:
if egg and os.path.exists(egg):
os.unlink(egg)
else:
if setuptools.__version__ == '0.0.1':
print >>sys.stderr, (
"You have an obsolete version of setuptools installed. Please\n"
"remove it from your system entirely before rerunning this script."
)
sys.exit(2)
req = "setuptools>="+version
import pkg_resources
try:
pkg_resources.require(req)
except pkg_resources.VersionConflict:
try:
from setuptools.command.easy_install import main
except ImportError:
from easy_install import main
main(list(argv)+[download_setuptools(delay=0)])
sys.exit(0) # try to force an exit
else:
if argv:
from setuptools.command.easy_install import main
main(argv)
else:
print "Setuptools version",version,"or greater has been installed."
print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def update_md5(filenames):
"""Update our built-in md5 registry"""
import re
for name in filenames:
base = os.path.basename(name)
f = open(name,'rb')
md5_data[base] = md5(f.read()).hexdigest()
f.close()
data = [" %r: %r,\n" % it for it in md5_data.items()]
data.sort()
repl = "".join(data)
import inspect
srcfile = inspect.getsourcefile(sys.modules[__name__])
f = open(srcfile, 'rb'); src = f.read(); f.close()
match = re.search("\nmd5_data = {\n([^}]+)}", src)
if not match:
print >>sys.stderr, "Internal error!"
sys.exit(2)
src = src[:match.start(1)] + repl + src[match.end(1):]
f = open(srcfile,'w')
f.write(src)
f.close()
if __name__=='__main__':
if len(sys.argv)>2 and sys.argv[1]=='--md5update':
update_md5(sys.argv[2:])
else:
main(sys.argv[1:])
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python2
import sys, pygments.cmdline import sys
import pygments.cmdline
try: try:
sys.exit(pygments.cmdline.main(sys.argv)) sys.exit(pygments.cmdline.main(sys.argv))
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -22,11 +22,11 @@
.. _Pygments tip: .. _Pygments tip:
http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
__version__ = '1.6' __version__ = '2.1.3'
__docformat__ = 'restructuredtext' __docformat__ = 'restructuredtext'
__all__ = ['lex', 'format', 'highlight'] __all__ = ['lex', 'format', 'highlight']
@ -43,15 +43,16 @@ def lex(code, lexer):
""" """
try: try:
return lexer.get_tokens(code) return lexer.get_tokens(code)
except TypeError, err: except TypeError as err:
if isinstance(err.args[0], str) and \ if isinstance(err.args[0], str) and \
'unbound method get_tokens' in err.args[0]: ('unbound method get_tokens' in err.args[0] or
'missing 1 required positional argument' in err.args[0]):
raise TypeError('lex() argument must be a lexer instance, ' raise TypeError('lex() argument must be a lexer instance, '
'not a class') 'not a class')
raise raise
def format(tokens, formatter, outfile=None): def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
""" """
Format a tokenlist ``tokens`` with the formatter ``formatter``. Format a tokenlist ``tokens`` with the formatter ``formatter``.
@ -61,15 +62,15 @@ def format(tokens, formatter, outfile=None):
""" """
try: try:
if not outfile: if not outfile:
#print formatter, 'using', formatter.encoding realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
realoutfile = formatter.encoding and BytesIO() or StringIO()
formatter.format(tokens, realoutfile) formatter.format(tokens, realoutfile)
return realoutfile.getvalue() return realoutfile.getvalue()
else: else:
formatter.format(tokens, outfile) formatter.format(tokens, outfile)
except TypeError, err: except TypeError as err:
if isinstance(err.args[0], str) and \ if isinstance(err.args[0], str) and \
'unbound method format' in err.args[0]: ('unbound method format' in err.args[0] or
'missing 1 required positional argument' in err.args[0]):
raise TypeError('format() argument must be a formatter instance, ' raise TypeError('format() argument must be a formatter instance, '
'not a class') 'not a class')
raise raise
@ -86,6 +87,6 @@ def highlight(code, lexer, formatter, outfile=None):
return format(lex(code, lexer), formatter, outfile) return format(lex(code, lexer), formatter, outfile)
if __name__ == '__main__': if __name__ == '__main__': # pragma: no cover
from pygments.cmdline import main from pygments.cmdline import main
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

View File

@ -5,27 +5,33 @@
Command line interface. Command line interface.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
from __future__ import print_function
import sys import sys
import getopt import getopt
from textwrap import dedent from textwrap import dedent
from pygments import __version__, highlight from pygments import __version__, highlight
from pygments.util import ClassNotFound, OptionError, docstring_headline from pygments.util import ClassNotFound, OptionError, docstring_headline, \
from pygments.lexers import get_all_lexers, get_lexer_by_name, get_lexer_for_filename, \ guess_decode, guess_decode_from_terminal, terminal_encoding
find_lexer_class, guess_lexer, TextLexer from pygments.lexers import get_all_lexers, get_lexer_by_name, guess_lexer, \
get_lexer_for_filename, find_lexer_class_for_filename
from pygments.lexers.special import TextLexer
from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter
from pygments.formatters import get_all_formatters, get_formatter_by_name, \ from pygments.formatters import get_all_formatters, get_formatter_by_name, \
get_formatter_for_filename, find_formatter_class, \ get_formatter_for_filename, find_formatter_class
TerminalFormatter # pylint:disable-msg=E0611 from pygments.formatters.terminal import TerminalFormatter
from pygments.filters import get_all_filters, find_filter_class from pygments.filters import get_all_filters, find_filter_class
from pygments.styles import get_all_styles, get_style_by_name from pygments.styles import get_all_styles, get_style_by_name
USAGE = """\ USAGE = """\
Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>] Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>]
[-O <options>] [-P <option=value>] [-o <outfile>] [<infile>] [-O <options>] [-P <option=value>] [-s] [-v] [-o <outfile>] [<infile>]
%s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>] %s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>]
%s -L [<which> ...] %s -L [<which> ...]
@ -37,6 +43,10 @@ Highlight the input file and write the result to <outfile>.
If no input file is given, use stdin, if -o is not given, use stdout. If no input file is given, use stdin, if -o is not given, use stdout.
If -s is passed, lexing will be done in "streaming" mode, reading and
highlighting one line at a time. This will only work properly with
lexers that have no constructs spanning multiple lines!
<lexer> is a lexer name (query all lexer names with -L). If -l is not <lexer> is a lexer name (query all lexer names with -L). If -l is not
given, the lexer is guessed from the extension of the input file name given, the lexer is guessed from the extension of the input file name
(this obviously doesn't work if the input is stdin). If -g is passed, (this obviously doesn't work if the input is stdin). If -g is passed,
@ -76,6 +86,14 @@ If no specific lexer can be determined "text" is returned.
The -H option prints detailed help for the object <name> of type <type>, The -H option prints detailed help for the object <name> of type <type>,
where <type> is one of "lexer", "formatter" or "filter". where <type> is one of "lexer", "formatter" or "filter".
The -s option processes lines one at a time until EOF, rather than
waiting to process the entire file. This only works for stdin, and
is intended for streaming input such as you get from 'tail -f'.
Example usage: "tail -f sql.log | pygmentize -s -l sql"
The -v option prints a detailed traceback on unhandled exceptions,
which is useful for debugging and bug reports.
The -h option prints this help. The -h option prints this help.
The -V option prints the package version. The -V option prints the package version.
""" """
@ -86,13 +104,13 @@ def _parse_options(o_strs):
if not o_strs: if not o_strs:
return opts return opts
for o_str in o_strs: for o_str in o_strs:
if not o_str: if not o_str.strip():
continue continue
o_args = o_str.split(',') o_args = o_str.split(',')
for o_arg in o_args: for o_arg in o_args:
o_arg = o_arg.strip() o_arg = o_arg.strip()
try: try:
o_key, o_val = o_arg.split('=') o_key, o_val = o_arg.split('=', 1)
o_key = o_key.strip() o_key = o_key.strip()
o_val = o_val.strip() o_val = o_val.strip()
except ValueError: except ValueError:
@ -118,26 +136,28 @@ def _parse_filters(f_strs):
def _print_help(what, name): def _print_help(what, name):
try: try:
if what == 'lexer': if what == 'lexer':
cls = find_lexer_class(name) cls = get_lexer_by_name(name)
print "Help on the %s lexer:" % cls.name print("Help on the %s lexer:" % cls.name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
elif what == 'formatter': elif what == 'formatter':
cls = find_formatter_class(name) cls = find_formatter_class(name)
print "Help on the %s formatter:" % cls.name print("Help on the %s formatter:" % cls.name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
elif what == 'filter': elif what == 'filter':
cls = find_filter_class(name) cls = find_filter_class(name)
print "Help on the %s filter:" % name print("Help on the %s filter:" % name)
print dedent(cls.__doc__) print(dedent(cls.__doc__))
except AttributeError: return 0
print >>sys.stderr, "%s not found!" % what except (AttributeError, ValueError):
print("%s not found!" % what, file=sys.stderr)
return 1
def _print_list(what): def _print_list(what):
if what == 'lexer': if what == 'lexer':
print print()
print "Lexers:" print("Lexers:")
print "~~~~~~~" print("~~~~~~~")
info = [] info = []
for fullname, names, exts, _ in get_all_lexers(): for fullname, names, exts, _ in get_all_lexers():
@ -146,12 +166,12 @@ def _print_list(what):
info.append(tup) info.append(tup)
info.sort() info.sort()
for i in info: for i in info:
print ('* %s\n %s %s') % i print(('* %s\n %s %s') % i)
elif what == 'formatter': elif what == 'formatter':
print print()
print "Formatters:" print("Formatters:")
print "~~~~~~~~~~~" print("~~~~~~~~~~~")
info = [] info = []
for cls in get_all_formatters(): for cls in get_all_formatters():
@ -161,50 +181,30 @@ def _print_list(what):
info.append(tup) info.append(tup)
info.sort() info.sort()
for i in info: for i in info:
print ('* %s\n %s %s') % i print(('* %s\n %s %s') % i)
elif what == 'filter': elif what == 'filter':
print print()
print "Filters:" print("Filters:")
print "~~~~~~~~" print("~~~~~~~~")
for name in get_all_filters(): for name in get_all_filters():
cls = find_filter_class(name) cls = find_filter_class(name)
print "* " + name + ':' print("* " + name + ':')
print " %s" % docstring_headline(cls) print(" %s" % docstring_headline(cls))
elif what == 'style': elif what == 'style':
print print()
print "Styles:" print("Styles:")
print "~~~~~~~" print("~~~~~~~")
for name in get_all_styles(): for name in get_all_styles():
cls = get_style_by_name(name) cls = get_style_by_name(name)
print "* " + name + ':' print("* " + name + ':')
print " %s" % docstring_headline(cls) print(" %s" % docstring_headline(cls))
def main(args=sys.argv): def main_inner(popts, args, usage):
"""
Main command line entry point.
"""
# pylint: disable-msg=R0911,R0912,R0915
usage = USAGE % ((args[0],) * 6)
if sys.platform in ['win32', 'cygwin']:
try:
# Provide coloring under Windows, if possible
import colorama
colorama.init()
except ImportError:
pass
try:
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
except getopt.GetoptError, err:
print >>sys.stderr, usage
return 2
opts = {} opts = {}
O_opts = [] O_opts = []
P_opts = [] P_opts = []
@ -218,23 +218,19 @@ def main(args=sys.argv):
F_opts.append(arg) F_opts.append(arg)
opts[opt] = arg opts[opt] = arg
if not opts and not args:
print usage
return 0
if opts.pop('-h', None) is not None: if opts.pop('-h', None) is not None:
print usage print(usage)
return 0 return 0
if opts.pop('-V', None) is not None: if opts.pop('-V', None) is not None:
print 'Pygments version %s, (c) 2006-2013 by Georg Brandl.' % __version__ print('Pygments version %s, (c) 2006-2015 by Georg Brandl.' % __version__)
return 0 return 0
# handle ``pygmentize -L`` # handle ``pygmentize -L``
L_opt = opts.pop('-L', None) L_opt = opts.pop('-L', None)
if L_opt is not None: if L_opt is not None:
if opts: if opts:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
# print version # print version
@ -249,16 +245,15 @@ def main(args=sys.argv):
H_opt = opts.pop('-H', None) H_opt = opts.pop('-H', None)
if H_opt is not None: if H_opt is not None:
if opts or len(args) != 2: if opts or len(args) != 2:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
what, name = args what, name = args # pylint: disable=unbalanced-tuple-unpacking
if what not in ('lexer', 'formatter', 'filter'): if what not in ('lexer', 'formatter', 'filter'):
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
_print_help(what, name) return _print_help(what, name)
return 0
# parse -O options # parse -O options
parsed_opts = _parse_options(O_opts) parsed_opts = _parse_options(O_opts)
@ -274,18 +269,18 @@ def main(args=sys.argv):
parsed_opts[name] = value parsed_opts[name] = value
opts.pop('-P', None) opts.pop('-P', None)
# encodings
inencoding = parsed_opts.get('inencoding', parsed_opts.get('encoding'))
outencoding = parsed_opts.get('outencoding', parsed_opts.get('encoding'))
# handle ``pygmentize -N`` # handle ``pygmentize -N``
infn = opts.pop('-N', None) infn = opts.pop('-N', None)
if infn is not None: if infn is not None:
try: lexer = find_lexer_class_for_filename(infn)
lexer = get_lexer_for_filename(infn, **parsed_opts) if lexer is None:
except ClassNotFound, err: lexer = TextLexer
lexer = TextLexer()
except OptionError, err:
print >>sys.stderr, 'Error:', err
return 1
print lexer.aliases[0] print(lexer.aliases[0])
return 0 return 0
# handle ``pygmentize -S`` # handle ``pygmentize -S``
@ -294,148 +289,241 @@ def main(args=sys.argv):
if S_opt is not None: if S_opt is not None:
f_opt = opts.pop('-f', None) f_opt = opts.pop('-f', None)
if not f_opt: if not f_opt:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
if opts or args: if opts or args:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
try: try:
parsed_opts['style'] = S_opt parsed_opts['style'] = S_opt
fmter = get_formatter_by_name(f_opt, **parsed_opts) fmter = get_formatter_by_name(f_opt, **parsed_opts)
except ClassNotFound, err: except ClassNotFound as err:
print >>sys.stderr, err print(err, file=sys.stderr)
return 1 return 1
arg = a_opt or '' print(fmter.get_style_defs(a_opt or ''))
try:
print fmter.get_style_defs(arg)
except Exception, err:
print >>sys.stderr, 'Error:', err
return 1
return 0 return 0
# if no -S is given, -a is not allowed # if no -S is given, -a is not allowed
if a_opt is not None: if a_opt is not None:
print >>sys.stderr, usage print(usage, file=sys.stderr)
return 2 return 2
# parse -F options # parse -F options
F_opts = _parse_filters(F_opts) F_opts = _parse_filters(F_opts)
opts.pop('-F', None) opts.pop('-F', None)
# select lexer
lexer = None
# given by name?
lexername = opts.pop('-l', None)
if lexername:
try:
lexer = get_lexer_by_name(lexername, **parsed_opts)
except (OptionError, ClassNotFound) as err:
print('Error:', err, file=sys.stderr)
return 1
# read input code
code = None
if args:
if len(args) > 1:
print(usage, file=sys.stderr)
return 2
if '-s' in opts:
print('Error: -s option not usable when input file specified',
file=sys.stderr)
return 2
infn = args[0]
try:
with open(infn, 'rb') as infp:
code = infp.read()
except Exception as err:
print('Error: cannot read infile:', err, file=sys.stderr)
return 1
if not inencoding:
code, inencoding = guess_decode(code)
# do we have to guess the lexer?
if not lexer:
try:
lexer = get_lexer_for_filename(infn, code, **parsed_opts)
except ClassNotFound as err:
if '-g' in opts:
try:
lexer = guess_lexer(code, **parsed_opts)
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
else:
print('Error:', err, file=sys.stderr)
return 1
except OptionError as err:
print('Error:', err, file=sys.stderr)
return 1
elif '-s' not in opts: # treat stdin as full file (-s support is later)
# read code from terminal, always in binary mode since we want to
# decode ourselves and be tolerant with it
if sys.version_info > (3,):
# Python 3: we have to use .buffer to get a binary stream
code = sys.stdin.buffer.read()
else:
code = sys.stdin.read()
if not inencoding:
code, inencoding = guess_decode_from_terminal(code, sys.stdin)
# else the lexer will do the decoding
if not lexer:
try:
lexer = guess_lexer(code, **parsed_opts)
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
else: # -s option needs a lexer with -l
if not lexer:
print('Error: when using -s a lexer has to be selected with -l',
file=sys.stderr)
return 2
# process filters
for fname, fopts in F_opts:
try:
lexer.add_filter(fname, **fopts)
except ClassNotFound as err:
print('Error:', err, file=sys.stderr)
return 1
# select formatter # select formatter
outfn = opts.pop('-o', None) outfn = opts.pop('-o', None)
fmter = opts.pop('-f', None) fmter = opts.pop('-f', None)
if fmter: if fmter:
try: try:
fmter = get_formatter_by_name(fmter, **parsed_opts) fmter = get_formatter_by_name(fmter, **parsed_opts)
except (OptionError, ClassNotFound), err: except (OptionError, ClassNotFound) as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
if outfn: if outfn:
if not fmter: if not fmter:
try: try:
fmter = get_formatter_for_filename(outfn, **parsed_opts) fmter = get_formatter_for_filename(outfn, **parsed_opts)
except (OptionError, ClassNotFound), err: except (OptionError, ClassNotFound) as err:
print >>sys.stderr, 'Error:', err print('Error:', err, file=sys.stderr)
return 1 return 1
try: try:
outfile = open(outfn, 'wb') outfile = open(outfn, 'wb')
except Exception, err: except Exception as err:
print >>sys.stderr, 'Error: cannot open outfile:', err print('Error: cannot open outfile:', err, file=sys.stderr)
return 1 return 1
else: else:
if not fmter: if not fmter:
fmter = TerminalFormatter(**parsed_opts) fmter = TerminalFormatter(**parsed_opts)
outfile = sys.stdout if sys.version_info > (3,):
# Python 3: we have to use .buffer to get a binary stream
# select lexer outfile = sys.stdout.buffer
lexer = opts.pop('-l', None)
if lexer:
try:
lexer = get_lexer_by_name(lexer, **parsed_opts)
except (OptionError, ClassNotFound), err:
print >>sys.stderr, 'Error:', err
return 1
if args:
if len(args) > 1:
print >>sys.stderr, usage
return 2
infn = args[0]
try:
code = open(infn, 'rb').read()
except Exception, err:
print >>sys.stderr, 'Error: cannot read infile:', err
return 1
if not lexer:
try:
lexer = get_lexer_for_filename(infn, code, **parsed_opts)
except ClassNotFound, err:
if '-g' in opts:
try:
lexer = guess_lexer(code, **parsed_opts)
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
else:
print >>sys.stderr, 'Error:', err
return 1
except OptionError, err:
print >>sys.stderr, 'Error:', err
return 1
else:
if '-g' in opts:
code = sys.stdin.read()
try:
lexer = guess_lexer(code, **parsed_opts)
except ClassNotFound:
lexer = TextLexer(**parsed_opts)
elif not lexer:
print >>sys.stderr, 'Error: no lexer name given and reading ' + \
'from stdin (try using -g or -l <lexer>)'
return 2
else: else:
code = sys.stdin.read() outfile = sys.stdout
# No encoding given? Use latin1 if output file given, # determine output encoding if not explicitly selected
# stdin/stdout encoding otherwise. if not outencoding:
# (This is a compromise, I'm not too happy with it...)
if 'encoding' not in parsed_opts and 'outencoding' not in parsed_opts:
if outfn: if outfn:
# encoding pass-through # output file? use lexer encoding for now (can still be None)
fmter.encoding = 'latin1' fmter.encoding = inencoding
else: else:
if sys.version_info < (3,): # else use terminal encoding
# use terminal encoding; Python 3's terminals already do that fmter.encoding = terminal_encoding(sys.stdout)
lexer.encoding = getattr(sys.stdin, 'encoding',
None) or 'ascii' # provide coloring under Windows, if possible
fmter.encoding = getattr(sys.stdout, 'encoding', if not outfn and sys.platform in ('win32', 'cygwin') and \
None) or 'ascii' fmter.name in ('Terminal', 'Terminal256'): # pragma: no cover
elif not outfn and sys.version_info > (3,): # unfortunately colorama doesn't support binary streams on Py3
# output to terminal with encoding -> use .buffer if sys.version_info > (3,):
outfile = sys.stdout.buffer from pygments.util import UnclosingTextIOWrapper
outfile = UnclosingTextIOWrapper(outfile, encoding=fmter.encoding)
fmter.encoding = None
try:
import colorama.initialise
except ImportError:
pass
else:
outfile = colorama.initialise.wrap_stream(
outfile, convert=None, strip=None, autoreset=False, wrap=True)
# When using the LaTeX formatter and the option `escapeinside` is
# specified, we need a special lexer which collects escaped text
# before running the chosen language lexer.
escapeinside = parsed_opts.get('escapeinside', '')
if len(escapeinside) == 2 and isinstance(fmter, LatexFormatter):
left = escapeinside[0]
right = escapeinside[1]
lexer = LatexEmbeddedLexer(left, right, lexer)
# ... and do it! # ... and do it!
try: if '-s' not in opts:
# process filters # process whole input as per normal...
for fname, fopts in F_opts:
lexer.add_filter(fname, **fopts)
highlight(code, lexer, fmter, outfile) highlight(code, lexer, fmter, outfile)
except Exception, err: return 0
else:
# line by line processing of stdin (eg: for 'tail -f')...
try:
while 1:
if sys.version_info > (3,):
# Python 3: we have to use .buffer to get a binary stream
line = sys.stdin.buffer.readline()
else:
line = sys.stdin.readline()
if not line:
break
if not inencoding:
line = guess_decode_from_terminal(line, sys.stdin)[0]
highlight(line, lexer, fmter, outfile)
if hasattr(outfile, 'flush'):
outfile.flush()
return 0
except KeyboardInterrupt: # pragma: no cover
return 0
def main(args=sys.argv):
"""
Main command line entry point.
"""
usage = USAGE % ((args[0],) * 6)
try:
popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgs")
except getopt.GetoptError:
print(usage, file=sys.stderr)
return 2
try:
return main_inner(popts, args, usage)
except Exception:
if '-v' in dict(popts):
print(file=sys.stderr)
print('*' * 65, file=sys.stderr)
print('An unhandled exception occurred while highlighting.',
file=sys.stderr)
print('Please report the whole traceback to the issue tracker at',
file=sys.stderr)
print('<https://bitbucket.org/birkenfeld/pygments-main/issues>.',
file=sys.stderr)
print('*' * 65, file=sys.stderr)
print(file=sys.stderr)
raise
import traceback import traceback
info = traceback.format_exception(*sys.exc_info()) info = traceback.format_exception(*sys.exc_info())
msg = info[-1].strip() msg = info[-1].strip()
if len(info) >= 3: if len(info) >= 3:
# extract relevant file and position info # extract relevant file and position info
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:] msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
print >>sys.stderr print(file=sys.stderr)
print >>sys.stderr, '*** Error while highlighting:' print('*** Error while highlighting:', file=sys.stderr)
print >>sys.stderr, msg print(msg, file=sys.stderr)
print('*** If this is a bug you want to report, please rerun with -v.',
file=sys.stderr)
return 1 return 1
return 0

View File

@ -5,7 +5,7 @@
Format colored console output. Format colored console output.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """

View File

@ -5,7 +5,7 @@
Module that implements the default filter. Module that implements the default filter.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
@ -29,7 +29,7 @@ def simplefilter(f):
Decorator that converts a function into a filter:: Decorator that converts a function into a filter::
@simplefilter @simplefilter
def lowercase(lexer, stream, options): def lowercase(self, lexer, stream, options):
for ttype, value in stream: for ttype, value in stream:
yield ttype, value.lower() yield ttype, value.lower()
""" """
@ -69,6 +69,6 @@ class FunctionFilter(Filter):
Filter.__init__(self, **options) Filter.__init__(self, **options)
def filter(self, lexer, stream): def filter(self, lexer, stream):
# pylint: disable-msg=E1102 # pylint: disable=not-callable
for ttype, value in self.function(lexer, stream, self.options): for ttype, value in self.function(lexer, stream, self.options):
yield ttype, value yield ttype, value

View File

@ -6,7 +6,7 @@
Module containing filter lookup functions and default Module containing filter lookup functions and default
filters. filters.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
@ -16,14 +16,12 @@ from pygments.token import String, Comment, Keyword, Name, Error, Whitespace, \
string_to_tokentype string_to_tokentype
from pygments.filter import Filter from pygments.filter import Filter
from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \ from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \
get_choice_opt, ClassNotFound, OptionError get_choice_opt, ClassNotFound, OptionError, text_type, string_types
from pygments.plugin import find_plugin_filters from pygments.plugin import find_plugin_filters
def find_filter_class(filtername): def find_filter_class(filtername):
""" """Lookup a filter by name. Return None if not found."""
Lookup a filter by name. Return None if not found.
"""
if filtername in FILTERS: if filtername in FILTERS:
return FILTERS[filtername] return FILTERS[filtername]
for name, cls in find_plugin_filters(): for name, cls in find_plugin_filters():
@ -33,9 +31,10 @@ def find_filter_class(filtername):
def get_filter_by_name(filtername, **options): def get_filter_by_name(filtername, **options):
""" """Return an instantiated filter.
Return an instantiated filter. Options are passed to the filter
initializer if wanted. Raise a ClassNotFound if not found. Options are passed to the filter initializer if wanted.
Raise a ClassNotFound if not found.
""" """
cls = find_filter_class(filtername) cls = find_filter_class(filtername)
if cls: if cls:
@ -45,9 +44,7 @@ def get_filter_by_name(filtername, **options):
def get_all_filters(): def get_all_filters():
""" """Return a generator of all filter names."""
Return a generator of all filter names.
"""
for name in FILTERS: for name in FILTERS:
yield name yield name
for name, _ in find_plugin_filters(): for name, _ in find_plugin_filters():
@ -68,8 +65,7 @@ def _replace_special(ttype, value, regex, specialttype,
class CodeTagFilter(Filter): class CodeTagFilter(Filter):
""" """Highlight special code tags in comments and docstrings.
Highlight special code tags in comments and docstrings.
Options accepted: Options accepted:
@ -100,8 +96,7 @@ class CodeTagFilter(Filter):
class KeywordCaseFilter(Filter): class KeywordCaseFilter(Filter):
""" """Convert keywords to lowercase or uppercase or capitalize them, which
Convert keywords to lowercase or uppercase or capitalize them, which
means first letter uppercase, rest lowercase. means first letter uppercase, rest lowercase.
This can be useful e.g. if you highlight Pascal code and want to adapt the This can be useful e.g. if you highlight Pascal code and want to adapt the
@ -116,8 +111,9 @@ class KeywordCaseFilter(Filter):
def __init__(self, **options): def __init__(self, **options):
Filter.__init__(self, **options) Filter.__init__(self, **options)
case = get_choice_opt(options, 'case', ['lower', 'upper', 'capitalize'], 'lower') case = get_choice_opt(options, 'case',
self.convert = getattr(unicode, case) ['lower', 'upper', 'capitalize'], 'lower')
self.convert = getattr(text_type, case)
def filter(self, lexer, stream): def filter(self, lexer, stream):
for ttype, value in stream: for ttype, value in stream:
@ -128,8 +124,7 @@ class KeywordCaseFilter(Filter):
class NameHighlightFilter(Filter): class NameHighlightFilter(Filter):
""" """Highlight a normal Name (and Name.*) token with a different token type.
Highlight a normal Name token with a different token type.
Example:: Example::
@ -163,7 +158,7 @@ class NameHighlightFilter(Filter):
def filter(self, lexer, stream): def filter(self, lexer, stream):
for ttype, value in stream: for ttype, value in stream:
if ttype is Name and value in self.names: if ttype in Name and value in self.names:
yield self.tokentype, value yield self.tokentype, value
else: else:
yield ttype, value yield ttype, value
@ -172,9 +167,9 @@ class NameHighlightFilter(Filter):
class ErrorToken(Exception): class ErrorToken(Exception):
pass pass
class RaiseOnErrorTokenFilter(Filter): class RaiseOnErrorTokenFilter(Filter):
""" """Raise an exception when the lexer generates an error token.
Raise an exception when the lexer generates an error token.
Options accepted: Options accepted:
@ -182,7 +177,7 @@ class RaiseOnErrorTokenFilter(Filter):
The exception class to raise. The exception class to raise.
The default is `pygments.filters.ErrorToken`. The default is `pygments.filters.ErrorToken`.
*New in Pygments 0.8.* .. versionadded:: 0.8
""" """
def __init__(self, **options): def __init__(self, **options):
@ -203,8 +198,7 @@ class RaiseOnErrorTokenFilter(Filter):
class VisibleWhitespaceFilter(Filter): class VisibleWhitespaceFilter(Filter):
""" """Convert tabs, newlines and/or spaces to visible characters.
Convert tabs, newlines and/or spaces to visible characters.
Options accepted: Options accepted:
@ -230,29 +224,31 @@ class VisibleWhitespaceFilter(Filter):
styling the visible whitespace differently (e.g. greyed out), but it can styling the visible whitespace differently (e.g. greyed out), but it can
disrupt background colors. The default is ``True``. disrupt background colors. The default is ``True``.
*New in Pygments 0.8.* .. versionadded:: 0.8
""" """
def __init__(self, **options): def __init__(self, **options):
Filter.__init__(self, **options) Filter.__init__(self, **options)
for name, default in {'spaces': u'·', 'tabs': u'»', 'newlines': u''}.items(): for name, default in [('spaces', u'·'),
('tabs', u'»'),
('newlines', u'')]:
opt = options.get(name, False) opt = options.get(name, False)
if isinstance(opt, basestring) and len(opt) == 1: if isinstance(opt, string_types) and len(opt) == 1:
setattr(self, name, opt) setattr(self, name, opt)
else: else:
setattr(self, name, (opt and default or '')) setattr(self, name, (opt and default or ''))
tabsize = get_int_opt(options, 'tabsize', 8) tabsize = get_int_opt(options, 'tabsize', 8)
if self.tabs: if self.tabs:
self.tabs += ' '*(tabsize-1) self.tabs += ' ' * (tabsize - 1)
if self.newlines: if self.newlines:
self.newlines += '\n' self.newlines += '\n'
self.wstt = get_bool_opt(options, 'wstokentype', True) self.wstt = get_bool_opt(options, 'wstokentype', True)
def filter(self, lexer, stream): def filter(self, lexer, stream):
if self.wstt: if self.wstt:
spaces = self.spaces or ' ' spaces = self.spaces or u' '
tabs = self.tabs or '\t' tabs = self.tabs or u'\t'
newlines = self.newlines or '\n' newlines = self.newlines or u'\n'
regex = re.compile(r'\s') regex = re.compile(r'\s')
def replacefunc(wschar): def replacefunc(wschar):
if wschar == ' ': if wschar == ' ':
@ -281,8 +277,7 @@ class VisibleWhitespaceFilter(Filter):
class GobbleFilter(Filter): class GobbleFilter(Filter):
""" """Gobbles source code lines (eats initial characters).
Gobbles source code lines (eats initial characters).
This filter drops the first ``n`` characters off every line of code. This This filter drops the first ``n`` characters off every line of code. This
may be useful when the source code fed to the lexer is indented by a fixed may be useful when the source code fed to the lexer is indented by a fixed
@ -293,7 +288,7 @@ class GobbleFilter(Filter):
`n` : int `n` : int
The number of characters to gobble. The number of characters to gobble.
*New in Pygments 1.2.* .. versionadded:: 1.2
""" """
def __init__(self, **options): def __init__(self, **options):
Filter.__init__(self, **options) Filter.__init__(self, **options)
@ -303,7 +298,7 @@ class GobbleFilter(Filter):
if left < len(value): if left < len(value):
return value[left:], 0 return value[left:], 0
else: else:
return '', left - len(value) return u'', left - len(value)
def filter(self, lexer, stream): def filter(self, lexer, stream):
n = self.n n = self.n
@ -314,18 +309,17 @@ class GobbleFilter(Filter):
(parts[0], left) = self.gobble(parts[0], left) (parts[0], left) = self.gobble(parts[0], left)
for i in range(1, len(parts)): for i in range(1, len(parts)):
(parts[i], left) = self.gobble(parts[i], n) (parts[i], left) = self.gobble(parts[i], n)
value = '\n'.join(parts) value = u'\n'.join(parts)
if value != '': if value != '':
yield ttype, value yield ttype, value
class TokenMergeFilter(Filter): class TokenMergeFilter(Filter):
""" """Merges consecutive tokens with the same token type in the output
Merges consecutive tokens with the same token type in the output stream of a stream of a lexer.
lexer.
*New in Pygments 1.2.* .. versionadded:: 1.2
""" """
def __init__(self, **options): def __init__(self, **options):
Filter.__init__(self, **options) Filter.__init__(self, **options)

View File

@ -5,20 +5,20 @@
Base formatter class. Base formatter class.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import codecs import codecs
from pygments.util import get_bool_opt from pygments.util import get_bool_opt, string_types
from pygments.styles import get_style_by_name from pygments.styles import get_style_by_name
__all__ = ['Formatter'] __all__ = ['Formatter']
def _lookup_style(style): def _lookup_style(style):
if isinstance(style, basestring): if isinstance(style, string_types):
return get_style_by_name(style) return get_style_by_name(style)
return style return style
@ -68,7 +68,10 @@ class Formatter(object):
self.full = get_bool_opt(options, 'full', False) self.full = get_bool_opt(options, 'full', False)
self.title = options.get('title', '') self.title = options.get('title', '')
self.encoding = options.get('encoding', None) or None self.encoding = options.get('encoding', None) or None
self.encoding = options.get('outencoding', None) or self.encoding if self.encoding in ('guess', 'chardet'):
# can happen for e.g. pygmentize -O encoding=guess
self.encoding = 'utf-8'
self.encoding = options.get('outencoding') or self.encoding
self.options = options self.options = options
def get_style_defs(self, arg=''): def get_style_defs(self, arg=''):

View File

@ -5,64 +5,114 @@
Pygments formatters. Pygments formatters.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import os.path
import re
import sys
import types
import fnmatch import fnmatch
from os.path import basename
from pygments.formatters._mapping import FORMATTERS from pygments.formatters._mapping import FORMATTERS
from pygments.plugin import find_plugin_formatters from pygments.plugin import find_plugin_formatters
from pygments.util import ClassNotFound from pygments.util import ClassNotFound, itervalues
ns = globals()
for fcls in FORMATTERS:
ns[fcls.__name__] = fcls
del fcls
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename', __all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
'get_all_formatters'] + [cls.__name__ for cls in FORMATTERS] 'get_all_formatters'] + list(FORMATTERS)
_formatter_cache = {} # classes by name
_pattern_cache = {}
_formatter_alias_cache = {} def _fn_matches(fn, glob):
_formatter_filename_cache = [] """Return whether the supplied file name fn matches pattern filename."""
if glob not in _pattern_cache:
def _init_formatter_cache(): pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
if _formatter_alias_cache: return pattern.match(fn)
return return _pattern_cache[glob].match(fn)
for cls in get_all_formatters():
for alias in cls.aliases:
_formatter_alias_cache[alias] = cls
for fn in cls.filenames:
_formatter_filename_cache.append((fn, cls))
def find_formatter_class(name): def _load_formatters(module_name):
_init_formatter_cache() """Load a formatter (and all others in the module too)."""
cls = _formatter_alias_cache.get(name, None) mod = __import__(module_name, None, None, ['__all__'])
return cls for formatter_name in mod.__all__:
cls = getattr(mod, formatter_name)
_formatter_cache[cls.name] = cls
def get_formatter_by_name(name, **options): def get_all_formatters():
_init_formatter_cache() """Return a generator for all formatter classes."""
cls = _formatter_alias_cache.get(name, None) # NB: this returns formatter classes, not info like get_all_lexers().
if not cls: for info in itervalues(FORMATTERS):
raise ClassNotFound("No formatter found for name %r" % name) if info[1] not in _formatter_cache:
_load_formatters(info[0])
yield _formatter_cache[info[1]]
for _, formatter in find_plugin_formatters():
yield formatter
def find_formatter_class(alias):
"""Lookup a formatter by alias.
Returns None if not found.
"""
for module_name, name, aliases, _, _ in itervalues(FORMATTERS):
if alias in aliases:
if name not in _formatter_cache:
_load_formatters(module_name)
return _formatter_cache[name]
for _, cls in find_plugin_formatters():
if alias in cls.aliases:
return cls
def get_formatter_by_name(_alias, **options):
"""Lookup and instantiate a formatter by alias.
Raises ClassNotFound if not found.
"""
cls = find_formatter_class(_alias)
if cls is None:
raise ClassNotFound("no formatter found for name %r" % _alias)
return cls(**options) return cls(**options)
def get_formatter_for_filename(fn, **options): def get_formatter_for_filename(fn, **options):
_init_formatter_cache() """Lookup and instantiate a formatter by filename pattern.
fn = os.path.basename(fn)
for pattern, cls in _formatter_filename_cache: Raises ClassNotFound if not found.
if fnmatch.fnmatch(fn, pattern): """
return cls(**options) fn = basename(fn)
raise ClassNotFound("No formatter found for file name %r" % fn) for modname, name, _, filenames, _ in itervalues(FORMATTERS):
for filename in filenames:
if _fn_matches(fn, filename):
if name not in _formatter_cache:
_load_formatters(modname)
return _formatter_cache[name](**options)
for cls in find_plugin_formatters():
for filename in cls.filenames:
if _fn_matches(fn, filename):
return cls(**options)
raise ClassNotFound("no formatter found for file name %r" % fn)
def get_all_formatters(): class _automodule(types.ModuleType):
"""Return a generator for all formatters.""" """Automatically import formatters."""
for formatter in FORMATTERS:
yield formatter def __getattr__(self, name):
for _, formatter in find_plugin_formatters(): info = FORMATTERS.get(name)
yield formatter if info:
_load_formatters(info[0])
cls = _formatter_cache[info[1]]
setattr(self, name, cls)
return cls
raise AttributeError(name)
oldmod = sys.modules[__name__]
newmod = _automodule(__name__)
newmod.__dict__.update(oldmod.__dict__)
sys.modules[__name__] = newmod
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types

View File

@ -3,48 +3,38 @@
pygments.formatters._mapping pygments.formatters._mapping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Formatter mapping defintions. This file is generated by itself. Everytime Formatter mapping definitions. This file is generated by itself. Everytime
you change something on a builtin formatter defintion, run this script from you change something on a builtin formatter definition, run this script from
the formatters folder to update it. the formatters folder to update it.
Do not alter the FORMATTERS dictionary by hand. Do not alter the FORMATTERS dictionary by hand.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
# start from __future__ import print_function
from pygments.formatters.bbcode import BBCodeFormatter
from pygments.formatters.html import HtmlFormatter
from pygments.formatters.img import BmpImageFormatter
from pygments.formatters.img import GifImageFormatter
from pygments.formatters.img import ImageFormatter
from pygments.formatters.img import JpgImageFormatter
from pygments.formatters.latex import LatexFormatter
from pygments.formatters.other import NullFormatter
from pygments.formatters.other import RawTokenFormatter
from pygments.formatters.rtf import RtfFormatter
from pygments.formatters.svg import SvgFormatter
from pygments.formatters.terminal import TerminalFormatter
from pygments.formatters.terminal256 import Terminal256Formatter
FORMATTERS = { FORMATTERS = {
BBCodeFormatter: ('BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'), 'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
BmpImageFormatter: ('img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
GifImageFormatter: ('img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
HtmlFormatter: ('HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."), 'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass` option."),
ImageFormatter: ('img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'),
JpgImageFormatter: ('img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), 'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
LatexFormatter: ('LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'), 'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
NullFormatter: ('Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'), 'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'), 'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
RtfFormatter: ('RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft\xc2\xae Word\xc2\xae documents.'), 'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'), 'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'),
Terminal256Formatter: ('Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'), 'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
TerminalFormatter: ('Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.') 'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
} }
if __name__ == '__main__': if __name__ == '__main__': # pragma: no cover
import sys import sys
import os import os
@ -54,39 +44,42 @@ if __name__ == '__main__':
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from pygments.util import docstring_headline from pygments.util import docstring_headline
for filename in os.listdir('.'): for root, dirs, files in os.walk('.'):
if filename.endswith('.py') and not filename.startswith('_'): for filename in files:
module_name = 'pygments.formatters.%s' % filename[:-3] if filename.endswith('.py') and not filename.startswith('_'):
print module_name module_name = 'pygments.formatters%s.%s' % (
module = __import__(module_name, None, None, ['']) root[1:].replace('/', '.'), filename[:-3])
for formatter_name in module.__all__: print(module_name)
imports.append((module_name, formatter_name)) module = __import__(module_name, None, None, [''])
formatter = getattr(module, formatter_name) for formatter_name in module.__all__:
found_formatters.append( formatter = getattr(module, formatter_name)
'%s: %r' % (formatter_name, found_formatters.append(
(formatter.name, '%r: %r' % (formatter_name,
tuple(formatter.aliases), (module_name,
tuple(formatter.filenames), formatter.name,
docstring_headline(formatter)))) tuple(formatter.aliases),
# sort them, that should make the diff files for svn smaller tuple(formatter.filenames),
docstring_headline(formatter))))
# sort them to make the diff minimal
found_formatters.sort() found_formatters.sort()
imports.sort()
# extract useful sourcecode from this file # extract useful sourcecode from this file
f = open(__file__) with open(__file__) as fp:
try: content = fp.read()
content = f.read() # replace crnl to nl for Windows.
finally: #
f.close() # Note that, originally, contributers should keep nl of master
header = content[:content.find('# start')] # repository, for example by using some kind of automatic
# management EOL, like `EolExtension
# <https://www.mercurial-scm.org/wiki/EolExtension>`.
content = content.replace("\r\n", "\n")
header = content[:content.find('FORMATTERS = {')]
footer = content[content.find("if __name__ == '__main__':"):] footer = content[content.find("if __name__ == '__main__':"):]
# write new file # write new file
f = open(__file__, 'w') with open(__file__, 'w') as fp:
f.write(header) fp.write(header)
f.write('# start\n') fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
f.write('\n'.join(['from %s import %s' % imp for imp in imports])) fp.write(footer)
f.write('\n\n')
f.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters)) print ('=== %d formatters processed.' % len(found_formatters))
f.write(footer)
f.close()

View File

@ -5,7 +5,7 @@
BBcode formatter. BBcode formatter.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """

View File

@ -5,18 +5,20 @@
Formatter for HTML output. Formatter for HTML output.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
from __future__ import print_function
import os import os
import sys import sys
import os.path import os.path
import StringIO
from pygments.formatter import Formatter from pygments.formatter import Formatter
from pygments.token import Token, Text, STANDARD_TYPES from pygments.token import Token, Text, STANDARD_TYPES
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
StringIO, string_types, iteritems
try: try:
import ctags import ctags
@ -34,21 +36,11 @@ _escape_html_table = {
ord("'"): u'&#39;', ord("'"): u'&#39;',
} }
def escape_html(text, table=_escape_html_table): def escape_html(text, table=_escape_html_table):
"""Escape &, <, > as well as single and double quotes for HTML.""" """Escape &, <, > as well as single and double quotes for HTML."""
return text.translate(table) return text.translate(table)
def get_random_id():
"""Return a random id for javascript fields."""
from random import random
from time import time
try:
from hashlib import sha1 as sha
except ImportError:
import sha
sha = sha.new
return sha('%s|%s' % (random(), time())).hexdigest()
def _get_ttype_class(ttype): def _get_ttype_class(ttype):
fname = STANDARD_TYPES.get(ttype) fname = STANDARD_TYPES.get(ttype)
@ -148,7 +140,7 @@ class HtmlFormatter(Formatter):
When `tagsfile` is set to the path of a ctags index file, it is used to When `tagsfile` is set to the path of a ctags index file, it is used to
generate hyperlinks from names to their definition. You must enable generate hyperlinks from names to their definition. You must enable
`anchorlines` and run ctags with the `-n` option for this to work. The `lineanchors` and run ctags with the `-n` option for this to work. The
`python-ctags` module from PyPI must be installed to use this feature; `python-ctags` module from PyPI must be installed to use this feature;
otherwise a `RuntimeError` will be raised. otherwise a `RuntimeError` will be raised.
@ -218,29 +210,34 @@ class HtmlFormatter(Formatter):
If you set this option, the default selector for `get_style_defs()` If you set this option, the default selector for `get_style_defs()`
will be this class. will be this class.
*New in Pygments 0.9:* If you select the ``'table'`` line numbers, the .. versionadded:: 0.9
wrapping table will have a CSS class of this string plus ``'table'``, If you select the ``'table'`` line numbers, the wrapping table will
the default is accordingly ``'highlighttable'``. have a CSS class of this string plus ``'table'``, the default is
accordingly ``'highlighttable'``.
`cssstyles` `cssstyles`
Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``). Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
`prestyles` `prestyles`
Inline CSS styles for the ``<pre>`` tag (default: ``''``). *New in Inline CSS styles for the ``<pre>`` tag (default: ``''``).
Pygments 0.11.*
.. versionadded:: 0.11
`cssfile` `cssfile`
If the `full` option is true and this option is given, it must be the If the `full` option is true and this option is given, it must be the
name of an external file. If the filename does not include an absolute name of an external file. If the filename does not include an absolute
path, the file's path will be assumed to be relative to the main output path, the file's path will be assumed to be relative to the main output
file's path, if the latter can be found. The stylesheet is then written file's path, if the latter can be found. The stylesheet is then written
to this file instead of the HTML file. *New in Pygments 0.6.* to this file instead of the HTML file.
.. versionadded:: 0.6
`noclobber_cssfile` `noclobber_cssfile`
If `cssfile` is given and the specified file exists, the css file will If `cssfile` is given and the specified file exists, the css file will
not be overwritten. This allows the use of the `full` option in not be overwritten. This allows the use of the `full` option in
combination with a user specified css file. Default is ``False``. combination with a user specified css file. Default is ``False``.
*New in Pygments 1.1.*
.. versionadded:: 1.1
`linenos` `linenos`
If set to ``'table'``, output line numbers as a table with two cells, If set to ``'table'``, output line numbers as a table with two cells,
@ -263,7 +260,9 @@ class HtmlFormatter(Formatter):
125%``). 125%``).
`hl_lines` `hl_lines`
Specify a list of lines to be highlighted. *New in Pygments 0.11.* Specify a list of lines to be highlighted.
.. versionadded:: 0.11
`linenostart` `linenostart`
The line number for the first line (default: ``1``). The line number for the first line (default: ``1``).
@ -279,24 +278,30 @@ class HtmlFormatter(Formatter):
If set to ``True``, the formatter won't output the background color If set to ``True``, the formatter won't output the background color
for the wrapping element (this automatically defaults to ``False`` for the wrapping element (this automatically defaults to ``False``
when there is no wrapping element [eg: no argument for the when there is no wrapping element [eg: no argument for the
`get_syntax_defs` method given]) (default: ``False``). *New in `get_syntax_defs` method given]) (default: ``False``).
Pygments 0.6.*
.. versionadded:: 0.6
`lineseparator` `lineseparator`
This string is output between lines of code. It defaults to ``"\n"``, This string is output between lines of code. It defaults to ``"\n"``,
which is enough to break a line inside ``<pre>`` tags, but you can which is enough to break a line inside ``<pre>`` tags, but you can
e.g. set it to ``"<br>"`` to get HTML line breaks. *New in Pygments e.g. set it to ``"<br>"`` to get HTML line breaks.
0.7.*
.. versionadded:: 0.7
`lineanchors` `lineanchors`
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
output line in an anchor tag with a ``name`` of ``foo-linenumber``. output line in an anchor tag with a ``name`` of ``foo-linenumber``.
This allows easy linking to certain lines. *New in Pygments 0.9.* This allows easy linking to certain lines.
.. versionadded:: 0.9
`linespans` `linespans`
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
output line in a span tag with an ``id`` of ``foo-linenumber``. output line in a span tag with an ``id`` of ``foo-linenumber``.
This allows easy access to lines via javascript. *New in Pygments 1.6.* This allows easy access to lines via javascript.
.. versionadded:: 1.6
`anchorlinenos` `anchorlinenos`
If set to `True`, will wrap line numbers in <a> tags. Used in If set to `True`, will wrap line numbers in <a> tags. Used in
@ -306,18 +311,26 @@ class HtmlFormatter(Formatter):
If set to the path of a ctags file, wrap names in anchor tags that If set to the path of a ctags file, wrap names in anchor tags that
link to their definitions. `lineanchors` should be used, and the link to their definitions. `lineanchors` should be used, and the
tags file should specify line numbers (see the `-n` option to ctags). tags file should specify line numbers (see the `-n` option to ctags).
*New in Pygments 1.6.*
.. versionadded:: 1.6
`tagurlformat` `tagurlformat`
A string formatting pattern used to generate links to ctags definitions. A string formatting pattern used to generate links to ctags definitions.
Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`. Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
Defaults to an empty string, resulting in just `#prefix-number` links. Defaults to an empty string, resulting in just `#prefix-number` links.
*New in Pygments 1.6.*
.. versionadded:: 1.6
`filename`
A string used to generate a filename when rendering <pre> blocks,
for example if displaying source code.
.. versionadded:: 2.1
**Subclassing the HTML formatter** **Subclassing the HTML formatter**
*New in Pygments 0.7.* .. versionadded:: 0.7
The HTML formatter is now built in a way that allows easy subclassing, thus The HTML formatter is now built in a way that allows easy subclassing, thus
customizing the output HTML code. The `format()` method calls customizing the output HTML code. The `format()` method calls
@ -381,6 +394,7 @@ class HtmlFormatter(Formatter):
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False) self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
self.tagsfile = self._decodeifneeded(options.get('tagsfile', '')) self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', '')) self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
self.filename = self._decodeifneeded(options.get('filename', ''))
if self.tagsfile: if self.tagsfile:
if not ctags: if not ctags:
@ -421,6 +435,15 @@ class HtmlFormatter(Formatter):
return self.classprefix + ttypeclass return self.classprefix + ttypeclass
return '' return ''
def _get_css_classes(self, ttype):
"""Return the css classes of this token type prefixed with
the classprefix option."""
cls = self._get_css_class(ttype)
while ttype not in STANDARD_TYPES:
ttype = ttype.parent
cls = self._get_css_class(ttype) + ' ' + cls
return cls
def _create_stylesheet(self): def _create_stylesheet(self):
t2c = self.ttype2class = {Token: ''} t2c = self.ttype2class = {Token: ''}
c2s = self.class2style = {} c2s = self.class2style = {}
@ -453,7 +476,7 @@ class HtmlFormatter(Formatter):
""" """
if arg is None: if arg is None:
arg = ('cssclass' in self.options and '.'+self.cssclass or '') arg = ('cssclass' in self.options and '.'+self.cssclass or '')
if isinstance(arg, basestring): if isinstance(arg, string_types):
args = [arg] args = [arg]
else: else:
args = list(arg) args = list(arg)
@ -467,7 +490,7 @@ class HtmlFormatter(Formatter):
return ', '.join(tmp) return ', '.join(tmp)
styles = [(level, ttype, cls, style) styles = [(level, ttype, cls, style)
for cls, (style, ttype, level) in self.class2style.iteritems() for cls, (style, ttype, level) in iteritems(self.class2style)
if cls and style] if cls and style]
styles.sort() styles.sort()
lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:]) lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
@ -505,36 +528,37 @@ class HtmlFormatter(Formatter):
cssfilename = os.path.join(os.path.dirname(filename), cssfilename = os.path.join(os.path.dirname(filename),
self.cssfile) self.cssfile)
except AttributeError: except AttributeError:
print >>sys.stderr, 'Note: Cannot determine output file name, ' \ print('Note: Cannot determine output file name, '
'using current directory as base for the CSS file name' 'using current directory as base for the CSS file name',
file=sys.stderr)
cssfilename = self.cssfile cssfilename = self.cssfile
# write CSS file only if noclobber_cssfile isn't given as an option. # write CSS file only if noclobber_cssfile isn't given as an option.
try: try:
if not os.path.exists(cssfilename) or not self.noclobber_cssfile: if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
cf = open(cssfilename, "w") cf = open(cssfilename, "w")
cf.write(CSSFILE_TEMPLATE % cf.write(CSSFILE_TEMPLATE %
{'styledefs': self.get_style_defs('body')}) {'styledefs': self.get_style_defs('body')})
cf.close() cf.close()
except IOError, err: except IOError as err:
err.strerror = 'Error writing CSS file: ' + err.strerror err.strerror = 'Error writing CSS file: ' + err.strerror
raise raise
yield 0, (DOC_HEADER_EXTERNALCSS % yield 0, (DOC_HEADER_EXTERNALCSS %
dict(title = self.title, dict(title=self.title,
cssfile = self.cssfile, cssfile=self.cssfile,
encoding = self.encoding)) encoding=self.encoding))
else: else:
yield 0, (DOC_HEADER % yield 0, (DOC_HEADER %
dict(title = self.title, dict(title=self.title,
styledefs = self.get_style_defs('body'), styledefs=self.get_style_defs('body'),
encoding = self.encoding)) encoding=self.encoding))
for t, line in inner: for t, line in inner:
yield t, line yield t, line
yield 0, DOC_FOOTER yield 0, DOC_FOOTER
def _wrap_tablelinenos(self, inner): def _wrap_tablelinenos(self, inner):
dummyoutfile = StringIO.StringIO() dummyoutfile = StringIO()
lncount = 0 lncount = 0
for t, line in inner: for t, line in inner:
if t: if t:
@ -606,35 +630,35 @@ class HtmlFormatter(Formatter):
if self.noclasses: if self.noclasses:
if sp: if sp:
for t, line in lines: for t, line in lines:
if num%sp == 0: if num % sp == 0:
style = 'background-color: #ffffc0; padding: 0 5px 0 5px' style = 'background-color: #ffffc0; padding: 0 5px 0 5px'
else: else:
style = 'background-color: #f0f0f0; padding: 0 5px 0 5px' style = 'background-color: #f0f0f0; padding: 0 5px 0 5px'
yield 1, '<span style="%s">%*s</span> ' % ( yield 1, '<span style="%s">%*s </span>' % (
style, mw, (num%st and ' ' or num)) + line style, mw, (num % st and ' ' or num)) + line
num += 1 num += 1
else: else:
for t, line in lines: for t, line in lines:
yield 1, ('<span style="background-color: #f0f0f0; ' yield 1, ('<span style="background-color: #f0f0f0; '
'padding: 0 5px 0 5px">%*s</span> ' % ( 'padding: 0 5px 0 5px">%*s </span>' % (
mw, (num%st and ' ' or num)) + line) mw, (num % st and ' ' or num)) + line)
num += 1 num += 1
elif sp: elif sp:
for t, line in lines: for t, line in lines:
yield 1, '<span class="lineno%s">%*s</span> ' % ( yield 1, '<span class="lineno%s">%*s </span>' % (
num%sp == 0 and ' special' or '', mw, num % sp == 0 and ' special' or '', mw,
(num%st and ' ' or num)) + line (num % st and ' ' or num)) + line
num += 1 num += 1
else: else:
for t, line in lines: for t, line in lines:
yield 1, '<span class="lineno">%*s</span> ' % ( yield 1, '<span class="lineno">%*s </span>' % (
mw, (num%st and ' ' or num)) + line mw, (num % st and ' ' or num)) + line
num += 1 num += 1
def _wrap_lineanchors(self, inner): def _wrap_lineanchors(self, inner):
s = self.lineanchors s = self.lineanchors
i = self.linenostart - 1 # subtract 1 since we have to increment i # subtract 1 since we have to increment i *before* yielding
# *before* yielding i = self.linenostart - 1
for t, line in inner: for t, line in inner:
if t: if t:
i += 1 i += 1
@ -655,14 +679,14 @@ class HtmlFormatter(Formatter):
def _wrap_div(self, inner): def _wrap_div(self, inner):
style = [] style = []
if (self.noclasses and not self.nobackground and if (self.noclasses and not self.nobackground and
self.style.background_color is not None): self.style.background_color is not None):
style.append('background: %s' % (self.style.background_color,)) style.append('background: %s' % (self.style.background_color,))
if self.cssstyles: if self.cssstyles:
style.append(self.cssstyles) style.append(self.cssstyles)
style = '; '.join(style) style = '; '.join(style)
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) +
+ (style and (' style="%s"' % style)) + '>') (style and (' style="%s"' % style)) + '>')
for tup in inner: for tup in inner:
yield tup yield tup
yield 0, '</div>\n' yield 0, '</div>\n'
@ -675,7 +699,12 @@ class HtmlFormatter(Formatter):
style.append('line-height: 125%') style.append('line-height: 125%')
style = '; '.join(style) style = '; '.join(style)
yield 0, ('<pre' + (style and ' style="%s"' % style) + '>') if self.filename:
yield 0, ('<span class="filename">' + self.filename + '</span>')
# the empty span here is to keep leading empty lines from being
# ignored by HTML parsers
yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>')
for tup in inner: for tup in inner:
yield tup yield tup
yield 0, '</pre>' yield 0, '</pre>'
@ -694,7 +723,7 @@ class HtmlFormatter(Formatter):
tagsfile = self.tagsfile tagsfile = self.tagsfile
lspan = '' lspan = ''
line = '' line = []
for ttype, value in tokensource: for ttype, value in tokensource:
if nocls: if nocls:
cclass = getcls(ttype) cclass = getcls(ttype)
@ -703,7 +732,7 @@ class HtmlFormatter(Formatter):
cclass = getcls(ttype) cclass = getcls(ttype)
cspan = cclass and '<span style="%s">' % c2s[cclass][0] or '' cspan = cclass and '<span style="%s">' % c2s[cclass][0] or ''
else: else:
cls = self._get_css_class(ttype) cls = self._get_css_classes(ttype)
cspan = cls and '<span class="%s">' % cls or '' cspan = cls and '<span class="%s">' % cls or ''
parts = value.translate(escape_table).split('\n') parts = value.translate(escape_table).split('\n')
@ -725,30 +754,31 @@ class HtmlFormatter(Formatter):
for part in parts[:-1]: for part in parts[:-1]:
if line: if line:
if lspan != cspan: if lspan != cspan:
line += (lspan and '</span>') + cspan + part + \ line.extend(((lspan and '</span>'), cspan, part,
(cspan and '</span>') + lsep (cspan and '</span>'), lsep))
else: # both are the same else: # both are the same
line += part + (lspan and '</span>') + lsep line.extend((part, (lspan and '</span>'), lsep))
yield 1, line yield 1, ''.join(line)
line = '' line = []
elif part: elif part:
yield 1, cspan + part + (cspan and '</span>') + lsep yield 1, ''.join((cspan, part, (cspan and '</span>'), lsep))
else: else:
yield 1, lsep yield 1, lsep
# for the last line # for the last line
if line and parts[-1]: if line and parts[-1]:
if lspan != cspan: if lspan != cspan:
line += (lspan and '</span>') + cspan + parts[-1] line.extend(((lspan and '</span>'), cspan, parts[-1]))
lspan = cspan lspan = cspan
else: else:
line += parts[-1] line.append(parts[-1])
elif parts[-1]: elif parts[-1]:
line = cspan + parts[-1] line = [cspan, parts[-1]]
lspan = cspan lspan = cspan
# else we neither have to open a new span nor set lspan # else we neither have to open a new span nor set lspan
if line: if line:
yield 1, line + (lspan and '</span>') + lsep line.extend(((lspan and '</span>'), lsep))
yield 1, ''.join(line)
def _lookup_ctag(self, token): def _lookup_ctag(self, token):
entry = ctags.TagEntry() entry = ctags.TagEntry()
@ -767,7 +797,7 @@ class HtmlFormatter(Formatter):
for i, (t, value) in enumerate(tokensource): for i, (t, value) in enumerate(tokensource):
if t != 1: if t != 1:
yield t, value yield t, value
if i + 1 in hls: # i + 1 because Python indexes start at 0 if i + 1 in hls: # i + 1 because Python indexes start at 0
if self.noclasses: if self.noclasses:
style = '' style = ''
if self.style.highlight_color is not None: if self.style.highlight_color is not None:

View File

@ -5,15 +5,17 @@
Formatter for Pixmap output. Formatter for Pixmap output.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import sys import sys
from pygments.formatter import Formatter from pygments.formatter import Formatter
from pygments.util import get_bool_opt, get_int_opt, \ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
get_list_opt, get_choice_opt get_choice_opt, xrange
import subprocess
# Import this carefully # Import this carefully
try: try:
@ -25,7 +27,10 @@ except ImportError:
try: try:
import _winreg import _winreg
except ImportError: except ImportError:
_winreg = None try:
import winreg as _winreg
except ImportError:
_winreg = None
__all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter', __all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
'BmpImageFormatter'] 'BmpImageFormatter']
@ -72,14 +77,18 @@ class FontManager(object):
self._create_nix() self._create_nix()
def _get_nix_font_path(self, name, style): def _get_nix_font_path(self, name, style):
from commands import getstatusoutput proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
exit, out = getstatusoutput('fc-list "%s:style=%s" file' % stdout=subprocess.PIPE, stderr=None)
(name, style)) stdout, _ = proc.communicate()
if not exit: if proc.returncode == 0:
lines = out.splitlines() lines = stdout.splitlines()
if lines: for line in lines:
path = lines[0].strip().strip(':') if line.startswith(b'Fontconfig warning:'):
return path continue
path = line.decode().strip().strip(':')
if path:
return path
return None
def _create_nix(self): def _create_nix(self):
for name in STYLES['NORMAL']: for name in STYLES['NORMAL']:
@ -169,7 +178,7 @@ class ImageFormatter(Formatter):
Create a PNG image from source code. This uses the Python Imaging Library to Create a PNG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code. generate a pixmap from the source code.
*New in Pygments 0.10.* .. versionadded:: 0.10
Additional options accepted: Additional options accepted:
@ -191,7 +200,7 @@ class ImageFormatter(Formatter):
bold and italic fonts will be generated. This really should be a bold and italic fonts will be generated. This really should be a
monospace font to look sane. monospace font to look sane.
Default: "Bitstream Vera Sans Mono" Default: "Bitstream Vera Sans Mono" on Windows, Courier New on \*nix
`font_size` `font_size`
The font size in points to be used. The font size in points to be used.
@ -258,12 +267,16 @@ class ImageFormatter(Formatter):
Default: 6 Default: 6
`hl_lines` `hl_lines`
Specify a list of lines to be highlighted. *New in Pygments 1.2.* Specify a list of lines to be highlighted.
.. versionadded:: 1.2
Default: empty list Default: empty list
`hl_color` `hl_color`
Specify the color for highlighting lines. *New in Pygments 1.2.* Specify the color for highlighting lines.
.. versionadded:: 1.2
Default: highlight color of the selected style Default: highlight color of the selected style
""" """
@ -285,6 +298,7 @@ class ImageFormatter(Formatter):
raise PilNotAvailable( raise PilNotAvailable(
'Python Imaging Library is required for this formatter') 'Python Imaging Library is required for this formatter')
Formatter.__init__(self, **options) Formatter.__init__(self, **options)
self.encoding = 'latin1' # let pygments.format() do the right thing
# Read the style # Read the style
self.styles = dict(self.style) self.styles = dict(self.style)
if self.style.background_color is None: if self.style.background_color is None:
@ -305,20 +319,20 @@ class ImageFormatter(Formatter):
self.line_number_fg = options.get('line_number_fg', '#886') self.line_number_fg = options.get('line_number_fg', '#886')
self.line_number_bg = options.get('line_number_bg', '#eed') self.line_number_bg = options.get('line_number_bg', '#eed')
self.line_number_chars = get_int_opt(options, self.line_number_chars = get_int_opt(options,
'line_number_chars', 2) 'line_number_chars', 2)
self.line_number_bold = get_bool_opt(options, self.line_number_bold = get_bool_opt(options,
'line_number_bold', False) 'line_number_bold', False)
self.line_number_italic = get_bool_opt(options, self.line_number_italic = get_bool_opt(options,
'line_number_italic', False) 'line_number_italic', False)
self.line_number_pad = get_int_opt(options, 'line_number_pad', 6) self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
self.line_numbers = get_bool_opt(options, 'line_numbers', True) self.line_numbers = get_bool_opt(options, 'line_numbers', True)
self.line_number_separator = get_bool_opt(options, self.line_number_separator = get_bool_opt(options,
'line_number_separator', True) 'line_number_separator', True)
self.line_number_step = get_int_opt(options, 'line_number_step', 1) self.line_number_step = get_int_opt(options, 'line_number_step', 1)
self.line_number_start = get_int_opt(options, 'line_number_start', 1) self.line_number_start = get_int_opt(options, 'line_number_start', 1)
if self.line_numbers: if self.line_numbers:
self.line_number_width = (self.fontw * self.line_number_chars + self.line_number_width = (self.fontw * self.line_number_chars +
self.line_number_pad * 2) self.line_number_pad * 2)
else: else:
self.line_number_width = 0 self.line_number_width = 0
self.hl_lines = [] self.hl_lines = []
@ -427,7 +441,7 @@ class ImageFormatter(Formatter):
# quite complex. # quite complex.
value = value.expandtabs(4) value = value.expandtabs(4)
lines = value.splitlines(True) lines = value.splitlines(True)
#print lines # print lines
for i, line in enumerate(lines): for i, line in enumerate(lines):
temp = line.rstrip('\n') temp = line.rstrip('\n')
if temp: if temp:
@ -468,9 +482,8 @@ class ImageFormatter(Formatter):
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
recth = im.size[-1] recth = im.size[-1]
rectw = self.image_pad + self.line_number_width - self.line_number_pad rectw = self.image_pad + self.line_number_width - self.line_number_pad
draw.rectangle([(0, 0), draw.rectangle([(0, 0), (rectw, recth)],
(rectw, recth)], fill=self.line_number_bg)
fill=self.line_number_bg)
draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg) draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
del draw del draw
@ -513,8 +526,7 @@ class GifImageFormatter(ImageFormatter):
Create a GIF image from source code. This uses the Python Imaging Library to Create a GIF image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code. generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create GIF images before by passing a .. versionadded:: 1.0
suitable `image_format` option to the `ImageFormatter`.)
""" """
name = 'img_gif' name = 'img_gif'
@ -528,8 +540,7 @@ class JpgImageFormatter(ImageFormatter):
Create a JPEG image from source code. This uses the Python Imaging Library to Create a JPEG image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code. generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create JPEG images before by passing a .. versionadded:: 1.0
suitable `image_format` option to the `ImageFormatter`.)
""" """
name = 'img_jpg' name = 'img_jpg'
@ -543,8 +554,7 @@ class BmpImageFormatter(ImageFormatter):
Create a bitmap image from source code. This uses the Python Imaging Library to Create a bitmap image from source code. This uses the Python Imaging Library to
generate a pixmap from the source code. generate a pixmap from the source code.
*New in Pygments 1.0.* (You could create bitmap images before by passing a .. versionadded:: 1.0
suitable `image_format` option to the `ImageFormatter`.)
""" """
name = 'img_bmp' name = 'img_bmp'

Some files were not shown because too many files have changed in this diff Show More