Permalink
Browse files

Initial import.

  • Loading branch information...
0 parents commit bd8dd575f682c82110d9e77b9e18f56898f2b8b6 Damian Janowski & Michel Martens committed Nov 24, 2010
Showing with 26,306 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +19 −0 LICENSE
  3. +53 −0 README.md
  4. +23 −0 lib/pygments.rb
  5. +11 −0 pygments.gemspec
  6. +21 −0 pygments.gemspec.erb
  7. +19 −0 test/pygments.rb
  8. +7 −0 vendor/pygmentize.py
  9. +73 −0 vendor/pygments/AUTHORS
  10. +25 −0 vendor/pygments/LICENSE
  11. +91 −0 vendor/pygments/__init__.py
  12. BIN vendor/pygments/__init__.pyc
  13. +430 −0 vendor/pygments/cmdline.py
  14. BIN vendor/pygments/cmdline.pyc
  15. +74 −0 vendor/pygments/console.py
  16. BIN vendor/pygments/console.pyc
  17. +74 −0 vendor/pygments/filter.py
  18. BIN vendor/pygments/filter.pyc
  19. +357 −0 vendor/pygments/filters/__init__.py
  20. BIN vendor/pygments/filters/__init__.pyc
  21. +92 −0 vendor/pygments/formatter.py
  22. BIN vendor/pygments/formatter.pyc
  23. +68 −0 vendor/pygments/formatters/__init__.py
  24. BIN vendor/pygments/formatters/__init__.pyc
  25. +92 −0 vendor/pygments/formatters/_mapping.py
  26. BIN vendor/pygments/formatters/_mapping.pyc
  27. +109 −0 vendor/pygments/formatters/bbcode.py
  28. BIN vendor/pygments/formatters/bbcode.pyc
  29. +723 −0 vendor/pygments/formatters/html.py
  30. BIN vendor/pygments/formatters/html.pyc
  31. +553 −0 vendor/pygments/formatters/img.py
  32. BIN vendor/pygments/formatters/img.pyc
  33. +354 −0 vendor/pygments/formatters/latex.py
  34. BIN vendor/pygments/formatters/latex.pyc
  35. +117 −0 vendor/pygments/formatters/other.py
  36. BIN vendor/pygments/formatters/other.pyc
  37. +136 −0 vendor/pygments/formatters/rtf.py
  38. BIN vendor/pygments/formatters/rtf.pyc
  39. +154 −0 vendor/pygments/formatters/svg.py
  40. BIN vendor/pygments/formatters/svg.pyc
  41. +109 −0 vendor/pygments/formatters/terminal.py
  42. BIN vendor/pygments/formatters/terminal.pyc
  43. +219 −0 vendor/pygments/formatters/terminal256.py
  44. BIN vendor/pygments/formatters/terminal256.pyc
  45. +660 −0 vendor/pygments/lexer.py
  46. BIN vendor/pygments/lexer.pyc
  47. +226 −0 vendor/pygments/lexers/__init__.py
  48. BIN vendor/pygments/lexers/__init__.pyc
  49. +1,645 −0 vendor/pygments/lexers/_asybuiltins.py
  50. +232 −0 vendor/pygments/lexers/_clbuiltins.py
  51. +256 −0 vendor/pygments/lexers/_luabuiltins.py
  52. +234 −0 vendor/pygments/lexers/_mapping.py
  53. BIN vendor/pygments/lexers/_mapping.pyc
  54. +3,389 −0 vendor/pygments/lexers/_phpbuiltins.py
  55. +3 −0 vendor/pygments/lexers/_vimbuiltins.py
  56. +1,485 −0 vendor/pygments/lexers/agile.py
  57. BIN vendor/pygments/lexers/agile.pyc
  58. +353 −0 vendor/pygments/lexers/asm.py
  59. +2,365 −0 vendor/pygments/lexers/compiled.py
  60. +355 −0 vendor/pygments/lexers/dotnet.py
  61. +756 −0 vendor/pygments/lexers/functional.py
  62. BIN vendor/pygments/lexers/functional.pyc
  63. +461 −0 vendor/pygments/lexers/math.py
  64. +2,297 −0 vendor/pygments/lexers/other.py
  65. +695 −0 vendor/pygments/lexers/parsers.py
  66. +100 −0 vendor/pygments/lexers/special.py
  67. BIN vendor/pygments/lexers/special.pyc
  68. +1,387 −0 vendor/pygments/lexers/templates.py
  69. +1,586 −0 vendor/pygments/lexers/text.py
  70. +1,619 −0 vendor/pygments/lexers/web.py
  71. BIN vendor/pygments/lexers/web.pyc
  72. +74 −0 vendor/pygments/plugin.py
  73. BIN vendor/pygments/plugin.pyc
  74. +104 −0 vendor/pygments/scanner.py
  75. +117 −0 vendor/pygments/style.py
  76. BIN vendor/pygments/style.pyc
  77. +68 −0 vendor/pygments/styles/__init__.py
  78. BIN vendor/pygments/styles/__init__.pyc
  79. +65 −0 vendor/pygments/styles/autumn.py
  80. +51 −0 vendor/pygments/styles/borland.py
  81. +49 −0 vendor/pygments/styles/bw.py
  82. +81 −0 vendor/pygments/styles/colorful.py
  83. +73 −0 vendor/pygments/styles/default.py
  84. BIN vendor/pygments/styles/default.pyc
  85. +72 −0 vendor/pygments/styles/emacs.py
  86. +72 −0 vendor/pygments/styles/friendly.py
  87. +43 −0 vendor/pygments/styles/fruity.py
  88. +75 −0 vendor/pygments/styles/manni.py
  89. +106 −0 vendor/pygments/styles/monokai.py
  90. +80 −0 vendor/pygments/styles/murphy.py
  91. +65 −0 vendor/pygments/styles/native.py
  92. +75 −0 vendor/pygments/styles/pastie.py
  93. +69 −0 vendor/pygments/styles/perldoc.py
  94. +141 −0 vendor/pygments/styles/tango.py
  95. +63 −0 vendor/pygments/styles/trac.py
  96. +63 −0 vendor/pygments/styles/vim.py
  97. +38 −0 vendor/pygments/styles/vs.py
  98. +198 −0 vendor/pygments/token.py
  99. BIN vendor/pygments/token.pyc
  100. +130 −0 vendor/pygments/unistring.py
  101. BIN vendor/pygments/unistring.pyc
  102. +226 −0 vendor/pygments/util.py
  103. BIN vendor/pygments/util.pyc
1 .gitignore
@@ -0,0 +1 @@
+/pkg
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2010 Damian Janowski & Michel Martens
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
53 README.md
@@ -0,0 +1,53 @@
+Cacho
+=====
+
+Cache aware, Redis based HTTP client.
+
+Description
+-----------
+
+Cacho is a HTTP client that understands cache responses and stores results in Redis.
+
+Usage
+-----
+
+When you try to GET a remote resource, Cacho proxies the request to the original server
+and returns an array of status, headers and body. If possible, it will also store the
+response and serve it in subsequent requests.
+
+ status, headers, body = Cacho.get("http://localhost:4000/cacheable")
+
+You can also supply custom headers:
+
+ status, headers, body = Cacho.get("http://localhost:4000/echo", "Accept" => "text/plain")
+
+Installation
+------------
+
+ $ gem install cacho
+
+License
+-------
+
+Copyright (c) 2010 Damian Janowski & Michel Martens
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
23 lib/pygments.rb
@@ -0,0 +1,23 @@
+require "shellwords"
+
+class Pygments
+ VERSION = "0.0.1"
+
+ def self.bin
+ "/usr/bin/env python #{File.expand_path("../vendor/pygmentize.py", File.dirname(__FILE__))}"
+ end
+
+ def self.pygmentize(source, lexer)
+ args = [
+ "-l", lexer.to_s,
+ "-f", "html",
+ "-O", "encoding=#{source.encoding}"
+ ]
+
+ IO.popen("#{bin} #{Shellwords.shelljoin args}", "r+") do |io|
+ io.write(source)
+ io.close_write
+ io.read
+ end
+ end
+end
11 pygments.gemspec
@@ -0,0 +1,11 @@
+
+Gem::Specification.new do |s|
+ s.name = "pygments"
+ s.version = "0.0.1"
+ s.summary = "A Ruby gem that vendors Pygments"
+ s.description = "A Ruby gem that vendors Pygments"
+ s.authors = ["Damian Janowski", "Michel Martens"]
+ s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
+ s.homepage = "http://github.com/djanowski/pygments"
+ s.files = ["pygments.gemspec", "LICENSE", "lib/pygments.rb", "test/pygments.rb", "vendor/pygmentize.py", "vendor/pygments", "vendor/pygments/__init__.py", "vendor/pygments/__init__.pyc", "vendor/pygments/AUTHORS", "vendor/pygments/cmdline.py", "vendor/pygments/cmdline.pyc", "vendor/pygments/console.py", "vendor/pygments/console.pyc", "vendor/pygments/filter.py", "vendor/pygments/filter.pyc", "vendor/pygments/filters", "vendor/pygments/filters/__init__.py", "vendor/pygments/filters/__init__.pyc", "vendor/pygments/formatter.py", "vendor/pygments/formatter.pyc", "vendor/pygments/formatters", "vendor/pygments/formatters/__init__.py", "vendor/pygments/formatters/__init__.pyc", "vendor/pygments/formatters/_mapping.py", "vendor/pygments/formatters/_mapping.pyc", "vendor/pygments/formatters/bbcode.py", "vendor/pygments/formatters/bbcode.pyc", "vendor/pygments/formatters/html.py", "vendor/pygments/formatters/html.pyc", "vendor/pygments/formatters/img.py", "vendor/pygments/formatters/img.pyc", "vendor/pygments/formatters/latex.py", "vendor/pygments/formatters/latex.pyc", "vendor/pygments/formatters/other.py", "vendor/pygments/formatters/other.pyc", "vendor/pygments/formatters/rtf.py", "vendor/pygments/formatters/rtf.pyc", "vendor/pygments/formatters/svg.py", "vendor/pygments/formatters/svg.pyc", "vendor/pygments/formatters/terminal.py", "vendor/pygments/formatters/terminal.pyc", "vendor/pygments/formatters/terminal256.py", "vendor/pygments/formatters/terminal256.pyc", "vendor/pygments/lexer.py", "vendor/pygments/lexer.pyc", "vendor/pygments/lexers", "vendor/pygments/lexers/__init__.py", "vendor/pygments/lexers/__init__.pyc", "vendor/pygments/lexers/_asybuiltins.py", "vendor/pygments/lexers/_clbuiltins.py", "vendor/pygments/lexers/_luabuiltins.py", "vendor/pygments/lexers/_mapping.py", "vendor/pygments/lexers/_mapping.pyc", "vendor/pygments/lexers/_phpbuiltins.py", "vendor/pygments/lexers/_vimbuiltins.py", "vendor/pygments/lexers/agile.py", "vendor/pygments/lexers/agile.pyc", "vendor/pygments/lexers/asm.py", "vendor/pygments/lexers/compiled.py", "vendor/pygments/lexers/dotnet.py", "vendor/pygments/lexers/functional.py", "vendor/pygments/lexers/functional.pyc", "vendor/pygments/lexers/math.py", "vendor/pygments/lexers/other.py", "vendor/pygments/lexers/parsers.py", "vendor/pygments/lexers/special.py", "vendor/pygments/lexers/special.pyc", "vendor/pygments/lexers/templates.py", "vendor/pygments/lexers/text.py", "vendor/pygments/lexers/web.py", "vendor/pygments/lexers/web.pyc", "vendor/pygments/LICENSE", "vendor/pygments/plugin.py", "vendor/pygments/plugin.pyc", "vendor/pygments/scanner.py", "vendor/pygments/style.py", "vendor/pygments/style.pyc", "vendor/pygments/styles", "vendor/pygments/styles/__init__.py", "vendor/pygments/styles/__init__.pyc", "vendor/pygments/styles/autumn.py", "vendor/pygments/styles/borland.py", "vendor/pygments/styles/bw.py", "vendor/pygments/styles/colorful.py", "vendor/pygments/styles/default.py", "vendor/pygments/styles/default.pyc", "vendor/pygments/styles/emacs.py", "vendor/pygments/styles/friendly.py", "vendor/pygments/styles/fruity.py", "vendor/pygments/styles/manni.py", "vendor/pygments/styles/monokai.py", "vendor/pygments/styles/murphy.py", "vendor/pygments/styles/native.py", "vendor/pygments/styles/pastie.py", "vendor/pygments/styles/perldoc.py", "vendor/pygments/styles/tango.py", "vendor/pygments/styles/trac.py", "vendor/pygments/styles/vim.py", "vendor/pygments/styles/vs.py", "vendor/pygments/token.py", "vendor/pygments/token.pyc", "vendor/pygments/unistring.py", "vendor/pygments/unistring.pyc", "vendor/pygments/util.py", "vendor/pygments/util.pyc"]
+end
21 pygments.gemspec.erb
@@ -0,0 +1,21 @@
+<% require "./lib/pygments" -%>
+
+Gem::Specification.new do |s|
+ s.name = "pygments"
+ s.version = "<%= Pygments::VERSION %>"
+ s.summary = "A Ruby gem that vendors Pygments"
+ s.description = "A Ruby gem that vendors Pygments"
+ s.authors = ["Damian Janowski", "Michel Martens"]
+ s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
+ s.homepage = "http://github.com/djanowski/pygments"
+ s.files = <%= Dir[
+ "*.gemspec",
+ "LICENSE",
+ "README.markdown",
+ "Rakefile",
+ "lib/**/*.rb",
+ "pygmentize.py",
+ "test/*.*",
+ "vendor/**/*",
+ ].inspect %>
+end
19 test/pygments.rb
@@ -0,0 +1,19 @@
+# encoding: UTF-8
+
+require File.expand_path("../lib/pygments", File.dirname(__FILE__))
+require "nokogiri"
+
+test "colorizes output" do
+ output = Pygments.pygmentize(%Q[{foo: "bar"}], :javascript)
+
+ doc = Nokogiri::HTML(output)
+
+ assert doc.at_xpath(".//div[@class='highlight']")
+ assert doc.at_xpath(".//div[@class='highlight']/pre/span[@class='nx' and text()='foo']")
+end
+
+test "handles encodings" do
+ output = Pygments.pygmentize(%Q[{foo: "bar", baz: "qüx"}], :javascript)
+
+ assert output.encoding == Encoding::UTF_8
+end
7 vendor/pygmentize.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+import sys, pygments.cmdline
+try:
+ sys.exit(pygments.cmdline.main(sys.argv))
+except KeyboardInterrupt:
+ sys.exit(1)
73 vendor/pygments/AUTHORS
@@ -0,0 +1,73 @@
+Pygments is written and maintained by Georg Brandl <georg@python.org>.
+
+Major developers are Tim Hatch <tim@timhatch.com> and Armin Ronacher
+<armin.ronacher@active-4.com>.
+
+Other contributors, listed alphabetically, are:
+
+* Kumar Appaiah -- Debian control lexer
+* Ali Afshar -- image formatter
+* Andreas Amann -- AppleScript lexer
+* Jeremy Ashkenas -- CoffeeScript lexer
+* Stefan Matthias Aust -- Smalltalk lexer
+* Ben Bangert -- Mako lexers
+* Max Battcher -- Darcs patch lexer
+* Paul Baumgart, 280 North, Inc. -- Objective-J lexer
+* Michael Bayer -- Myghty lexers
+* Jarrett Billingsley -- MiniD lexer
+* Adam Blinkinsop -- Haskell, Redcode lexers
+* Frits van Bommel -- assembler lexers
+* Pierre Bourdon -- bugfixes
+* Christopher Creutzig -- MuPAD lexer
+* Pete Curry -- bugfixes
+* Owen Durni -- haXe lexer
+* Nick Efford -- Python 3 lexer
+* Artem Egorkine -- terminal256 formatter
+* Laurent Gautier -- R/S lexer
+* Krzysiek Goj -- Scala lexer
+* Matt Good -- Genshi, Cheetah lexers
+* Patrick Gotthardt -- PHP namespaces support
+* Olivier Guibe -- Asymptote lexer
+* Matthew Harrison -- SVG formatter
+* Steven Hazel -- Tcl lexer
+* Aslak Hellesøy -- Gherkin lexer
+* David Hess, Fish Software, Inc. -- Objective-J lexer
+* Varun Hiremath -- Debian control lexer
+* Dennis Kaarsemaker -- sources.list lexer
+* Benjamin Kowarsch -- Modula-2 lexer
+* Marek Kubica -- Scheme lexer
+* Jochen Kupperschmidt -- Markdown processor
+* Gerd Kurzbach -- Modelica lexer
+* Mark Lee -- Vala lexer
+* Ben Mabey -- Gherkin lexer
+* Kirk McDonald -- D lexer
+* Lukas Meuser -- BBCode formatter, Lua lexer
+* Paulo Moura -- Logtalk lexer
+* Ana Nelson -- Ragel, ANTLR, R console lexers
+* Nam T. Nguyen -- Monokai style
+* Jesper Noehr -- HTML formatter "anchorlinenos"
+* Jonas Obrist -- BBCode lexer
+* David Oliva -- Rebol lexer
+* Ronny Pfannschmidt -- BBCode lexer
+* Benjamin Peterson -- Test suite refactoring
+* Justin Reidy -- MXML lexer
+* Andre Roberge -- Tango style
+* Konrad Rudolph -- LaTeX formatter enhancements
+* Mario Ruggier -- Evoque lexers
+* Stou Sandalski -- NumPy, FORTRAN, tcsh and XSLT lexers
+* Matteo Sasso -- Common Lisp lexer
+* Joe Schafer -- Ada lexer
+* Ken Schutte -- Matlab lexers
+* Tassilo Schweyer -- Io, MOOCode lexers
+* Joerg Sieker -- ABAP lexer
+* Kirill Simonov -- YAML lexer
+* Tiberius Teng -- default style overhaul
+* Jeremy Thurgood -- Erlang, Squid config lexers
+* Erick Tryzelaar -- Felix lexer
+* Whitney Young -- ObjectiveC lexer
+* Nathan Weizenbaum -- Haml and Sass lexers
+* Dietmar Winkler -- Modelica lexer
+* Nils Winter -- Smalltalk lexer
+* Davy Wybiral -- Clojure lexer
+
+Many thanks for all contributions!
25 vendor/pygments/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2006-2010 by the respective authors (see AUTHORS file).
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
91 vendor/pygments/__init__.py
@@ -0,0 +1,91 @@
+# -*- coding: utf-8 -*-
+"""
+ Pygments
+ ~~~~~~~~
+
+ Pygments is a syntax highlighting package written in Python.
+
+ It is a generic syntax highlighter for general use in all kinds of software
+ such as forum systems, wikis or other applications that need to prettify
+ source code. Highlights are:
+
+ * a wide range of common languages and markup formats is supported
+ * special attention is paid to details, increasing quality by a fair amount
+ * 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
+ * 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``.
+
+ .. _Pygments tip:
+ http://dev.pocoo.org/hg/pygments-main/archive/tip.tar.gz#egg=Pygments-dev
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+__version__ = '1.3.1'
+__docformat__ = 'restructuredtext'
+
+__all__ = ['lex', 'format', 'highlight']
+
+
+import sys
+
+from pygments.util import StringIO, BytesIO
+
+
+def lex(code, lexer):
+ """
+ Lex ``code`` with ``lexer`` and return an iterable of tokens.
+ """
+ try:
+ return lexer.get_tokens(code)
+ except TypeError, err:
+ if isinstance(err.args[0], str) and \
+ 'unbound method get_tokens' in err.args[0]:
+ raise TypeError('lex() argument must be a lexer instance, '
+ 'not a class')
+ raise
+
+
+def format(tokens, formatter, outfile=None):
+ """
+ Format a tokenlist ``tokens`` with the formatter ``formatter``.
+
+ If ``outfile`` is given and a valid file object (an object
+ with a ``write`` method), the result will be written to it, otherwise
+ it is returned as a string.
+ """
+ try:
+ if not outfile:
+ #print formatter, 'using', formatter.encoding
+ realoutfile = formatter.encoding and BytesIO() or StringIO()
+ formatter.format(tokens, realoutfile)
+ return realoutfile.getvalue()
+ else:
+ formatter.format(tokens, outfile)
+ except TypeError, err:
+ if isinstance(err.args[0], str) and \
+ 'unbound method format' in err.args[0]:
+ raise TypeError('format() argument must be a formatter instance, '
+ 'not a class')
+ raise
+
+
+def highlight(code, lexer, formatter, outfile=None):
+ """
+ Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
+
+ If ``outfile`` is given and a valid file object (an object
+ with a ``write`` method), the result will be written to it, otherwise
+ it is returned as a string.
+ """
+ return format(lex(code, lexer), formatter, outfile)
+
+
+if __name__ == '__main__':
+ from pygments.cmdline import main
+ sys.exit(main(sys.argv))
BIN vendor/pygments/__init__.pyc
Binary file not shown.
430 vendor/pygments/cmdline.py
@@ -0,0 +1,430 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.cmdline
+ ~~~~~~~~~~~~~~~~
+
+ Command line interface.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+import sys
+import getopt
+from textwrap import dedent
+
+from pygments import __version__, highlight
+from pygments.util import ClassNotFound, OptionError, docstring_headline
+from pygments.lexers import get_all_lexers, get_lexer_by_name, get_lexer_for_filename, \
+ find_lexer_class, guess_lexer, TextLexer
+from pygments.formatters import get_all_formatters, get_formatter_by_name, \
+ get_formatter_for_filename, find_formatter_class, \
+ TerminalFormatter # pylint:disable-msg=E0611
+from pygments.filters import get_all_filters, find_filter_class
+from pygments.styles import get_all_styles, get_style_by_name
+
+
+USAGE = """\
+Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>]
+ [-O <options>] [-P <option=value>] [-o <outfile>] [<infile>]
+
+ %s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>]
+ %s -L [<which> ...]
+ %s -N <filename>
+ %s -H <type> <name>
+ %s -h | -V
+
+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.
+
+<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
+(this obviously doesn't work if the input is stdin). If -g is passed,
+attempt to guess the lexer from the file contents, or pass through as
+plain text if this fails (this can work for stdin).
+
+Likewise, <formatter> is a formatter name, and will be guessed from
+the extension of the output file name. If no output file is given,
+the terminal formatter will be used by default.
+
+With the -O option, you can give the lexer and formatter a comma-
+separated list of options, e.g. ``-O bg=light,python=cool``.
+
+The -P option adds lexer and formatter options like the -O option, but
+you can only give one option per -P. That way, the option value may
+contain commas and equals signs, which it can't with -O, e.g.
+``-P "heading=Pygments, the Python highlighter".
+
+With the -F option, you can add filters to the token stream, you can
+give options in the same way as for -O after a colon (note: there must
+not be spaces around the colon).
+
+The -O, -P and -F options can be given multiple times.
+
+With the -S option, print out style definitions for style <style>
+for formatter <formatter>. The argument given by -a is formatter
+dependent.
+
+The -L option lists lexers, formatters, styles or filters -- set
+`which` to the thing you want to list (e.g. "styles"), or omit it to
+list everything.
+
+The -N option guesses and prints out a lexer name based solely on
+the given filename. It does not take input or highlight anything.
+If no specific lexer can be determined "text" is returned.
+
+The -H option prints detailed help for the object <name> of type <type>,
+where <type> is one of "lexer", "formatter" or "filter".
+
+The -h option prints this help.
+The -V option prints the package version.
+"""
+
+
+def _parse_options(o_strs):
+ opts = {}
+ if not o_strs:
+ return opts
+ for o_str in o_strs:
+ if not o_str:
+ continue
+ o_args = o_str.split(',')
+ for o_arg in o_args:
+ o_arg = o_arg.strip()
+ try:
+ o_key, o_val = o_arg.split('=')
+ o_key = o_key.strip()
+ o_val = o_val.strip()
+ except ValueError:
+ opts[o_arg] = True
+ else:
+ opts[o_key] = o_val
+ return opts
+
+
+def _parse_filters(f_strs):
+ filters = []
+ if not f_strs:
+ return filters
+ for f_str in f_strs:
+ if ':' in f_str:
+ fname, fopts = f_str.split(':', 1)
+ filters.append((fname, _parse_options([fopts])))
+ else:
+ filters.append((f_str, {}))
+ return filters
+
+
+def _print_help(what, name):
+ try:
+ if what == 'lexer':
+ cls = find_lexer_class(name)
+ print "Help on the %s lexer:" % cls.name
+ print dedent(cls.__doc__)
+ elif what == 'formatter':
+ cls = find_formatter_class(name)
+ print "Help on the %s formatter:" % cls.name
+ print dedent(cls.__doc__)
+ elif what == 'filter':
+ cls = find_filter_class(name)
+ print "Help on the %s filter:" % name
+ print dedent(cls.__doc__)
+ except AttributeError:
+ print >>sys.stderr, "%s not found!" % what
+
+
+def _print_list(what):
+ if what == 'lexer':
+ print
+ print "Lexers:"
+ print "~~~~~~~"
+
+ info = []
+ for fullname, names, exts, _ in get_all_lexers():
+ tup = (', '.join(names)+':', fullname,
+ exts and '(filenames ' + ', '.join(exts) + ')' or '')
+ info.append(tup)
+ info.sort()
+ for i in info:
+ print ('* %s\n %s %s') % i
+
+ elif what == 'formatter':
+ print
+ print "Formatters:"
+ print "~~~~~~~~~~~"
+
+ info = []
+ for cls in get_all_formatters():
+ doc = docstring_headline(cls)
+ tup = (', '.join(cls.aliases) + ':', doc, cls.filenames and
+ '(filenames ' + ', '.join(cls.filenames) + ')' or '')
+ info.append(tup)
+ info.sort()
+ for i in info:
+ print ('* %s\n %s %s') % i
+
+ elif what == 'filter':
+ print
+ print "Filters:"
+ print "~~~~~~~~"
+
+ for name in get_all_filters():
+ cls = find_filter_class(name)
+ print "* " + name + ':'
+ print " %s" % docstring_headline(cls)
+
+ elif what == 'style':
+ print
+ print "Styles:"
+ print "~~~~~~~"
+
+ for name in get_all_styles():
+ cls = get_style_by_name(name)
+ print "* " + name + ':'
+ print " %s" % docstring_headline(cls)
+
+
+def main(args=sys.argv):
+ """
+ Main command line entry point.
+ """
+ # pylint: disable-msg=R0911,R0912,R0915
+
+ usage = USAGE % ((args[0],) * 6)
+
+ 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 = {}
+ O_opts = []
+ P_opts = []
+ F_opts = []
+ for opt, arg in popts:
+ if opt == '-O':
+ O_opts.append(arg)
+ elif opt == '-P':
+ P_opts.append(arg)
+ elif opt == '-F':
+ F_opts.append(arg)
+ opts[opt] = arg
+
+ if not opts and not args:
+ print usage
+ return 0
+
+ if opts.pop('-h', None) is not None:
+ print usage
+ return 0
+
+ if opts.pop('-V', None) is not None:
+ print 'Pygments version %s, (c) 2006-2008 by Georg Brandl.' % __version__
+ return 0
+
+ # handle ``pygmentize -L``
+ L_opt = opts.pop('-L', None)
+ if L_opt is not None:
+ if opts:
+ print >>sys.stderr, usage
+ return 2
+
+ # print version
+ main(['', '-V'])
+ if not args:
+ args = ['lexer', 'formatter', 'filter', 'style']
+ for arg in args:
+ _print_list(arg.rstrip('s'))
+ return 0
+
+ # handle ``pygmentize -H``
+ H_opt = opts.pop('-H', None)
+ if H_opt is not None:
+ if opts or len(args) != 2:
+ print >>sys.stderr, usage
+ return 2
+
+ what, name = args
+ if what not in ('lexer', 'formatter', 'filter'):
+ print >>sys.stderr, usage
+ return 2
+
+ _print_help(what, name)
+ return 0
+
+ # parse -O options
+ parsed_opts = _parse_options(O_opts)
+ opts.pop('-O', None)
+
+ # parse -P options
+ for p_opt in P_opts:
+ try:
+ name, value = p_opt.split('=', 1)
+ except ValueError:
+ parsed_opts[p_opt] = True
+ else:
+ parsed_opts[name] = value
+ opts.pop('-P', None)
+
+ # handle ``pygmentize -N``
+ infn = opts.pop('-N', None)
+ if infn is not None:
+ try:
+ lexer = get_lexer_for_filename(infn, **parsed_opts)
+ except ClassNotFound, err:
+ lexer = TextLexer()
+ except OptionError, err:
+ print >>sys.stderr, 'Error:', err
+ return 1
+
+ print lexer.aliases[0]
+ return 0
+
+ # handle ``pygmentize -S``
+ S_opt = opts.pop('-S', None)
+ a_opt = opts.pop('-a', None)
+ if S_opt is not None:
+ f_opt = opts.pop('-f', None)
+ if not f_opt:
+ print >>sys.stderr, usage
+ return 2
+ if opts or args:
+ print >>sys.stderr, usage
+ return 2
+
+ try:
+ parsed_opts['style'] = S_opt
+ fmter = get_formatter_by_name(f_opt, **parsed_opts)
+ except ClassNotFound, err:
+ print >>sys.stderr, err
+ return 1
+
+ arg = a_opt or ''
+ try:
+ print fmter.get_style_defs(arg)
+ except Exception, err:
+ print >>sys.stderr, 'Error:', err
+ return 1
+ return 0
+
+ # if no -S is given, -a is not allowed
+ if a_opt is not None:
+ print >>sys.stderr, usage
+ return 2
+
+ # parse -F options
+ F_opts = _parse_filters(F_opts)
+ opts.pop('-F', None)
+
+ # select formatter
+ outfn = opts.pop('-o', None)
+ fmter = opts.pop('-f', None)
+ if fmter:
+ try:
+ fmter = get_formatter_by_name(fmter, **parsed_opts)
+ except (OptionError, ClassNotFound), err:
+ print >>sys.stderr, 'Error:', err
+ return 1
+
+ if outfn:
+ if not fmter:
+ try:
+ fmter = get_formatter_for_filename(outfn, **parsed_opts)
+ except (OptionError, ClassNotFound), err:
+ print >>sys.stderr, 'Error:', err
+ return 1
+ try:
+ outfile = open(outfn, 'wb')
+ except Exception, err:
+ print >>sys.stderr, 'Error: cannot open outfile:', err
+ return 1
+ else:
+ if not fmter:
+ fmter = TerminalFormatter(**parsed_opts)
+ outfile = sys.stdout
+
+ # select lexer
+ 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)
+ except ClassNotFound:
+ lexer = TextLexer()
+ 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)
+ except ClassNotFound:
+ lexer = TextLexer()
+ elif not lexer:
+ print >>sys.stderr, 'Error: no lexer name given and reading ' + \
+ 'from stdin (try using -g or -l <lexer>)'
+ return 2
+ else:
+ code = sys.stdin.read()
+
+ # No encoding given? Use latin1 if output file given,
+ # stdin/stdout encoding otherwise.
+ # (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:
+ # encoding pass-through
+ fmter.encoding = 'latin1'
+ else:
+ if sys.version_info < (3,):
+ # use terminal encoding; Python 3's terminals already do that
+ lexer.encoding = getattr(sys.stdin, 'encoding',
+ None) or 'ascii'
+ fmter.encoding = getattr(sys.stdout, 'encoding',
+ None) or 'ascii'
+
+ # ... and do it!
+ try:
+ # process filters
+ for fname, fopts in F_opts:
+ lexer.add_filter(fname, **fopts)
+ highlight(code, lexer, fmter, outfile)
+ except Exception, err:
+ import traceback
+ info = traceback.format_exception(*sys.exc_info())
+ msg = info[-1].strip()
+ if len(info) >= 3:
+ # extract relevant file and position info
+ msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
+ print >>sys.stderr
+ print >>sys.stderr, '*** Error while highlighting:'
+ print >>sys.stderr, msg
+ return 1
+
+ return 0
BIN vendor/pygments/cmdline.pyc
Binary file not shown.
74 vendor/pygments/console.py
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.console
+ ~~~~~~~~~~~~~~~~
+
+ Format colored console output.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+esc = "\x1b["
+
+codes = {}
+codes[""] = ""
+codes["reset"] = esc + "39;49;00m"
+
+codes["bold"] = esc + "01m"
+codes["faint"] = esc + "02m"
+codes["standout"] = esc + "03m"
+codes["underline"] = esc + "04m"
+codes["blink"] = esc + "05m"
+codes["overline"] = esc + "06m"
+
+dark_colors = ["black", "darkred", "darkgreen", "brown", "darkblue",
+ "purple", "teal", "lightgray"]
+light_colors = ["darkgray", "red", "green", "yellow", "blue",
+ "fuchsia", "turquoise", "white"]
+
+x = 30
+for d, l in zip(dark_colors, light_colors):
+ codes[d] = esc + "%im" % x
+ codes[l] = esc + "%i;01m" % x
+ x += 1
+
+del d, l, x
+
+codes["darkteal"] = codes["turquoise"]
+codes["darkyellow"] = codes["brown"]
+codes["fuscia"] = codes["fuchsia"]
+codes["white"] = codes["bold"]
+
+
+def reset_color():
+ return codes["reset"]
+
+
+def colorize(color_key, text):
+ return codes[color_key] + text + codes["reset"]
+
+
+def ansiformat(attr, text):
+ """
+ Format ``text`` with a color and/or some attributes::
+
+ color normal color
+ *color* bold color
+ _color_ underlined color
+ +color+ blinking color
+ """
+ result = []
+ if attr[:1] == attr[-1:] == '+':
+ result.append(codes['blink'])
+ attr = attr[1:-1]
+ if attr[:1] == attr[-1:] == '*':
+ result.append(codes['bold'])
+ attr = attr[1:-1]
+ if attr[:1] == attr[-1:] == '_':
+ result.append(codes['underline'])
+ attr = attr[1:-1]
+ result.append(codes[attr])
+ result.append(text)
+ result.append(codes['reset'])
+ return ''.join(result)
BIN vendor/pygments/console.pyc
Binary file not shown.
74 vendor/pygments/filter.py
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.filter
+ ~~~~~~~~~~~~~~~
+
+ Module that implements the default filter.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+
+def apply_filters(stream, filters, lexer=None):
+ """
+ Use this method to apply an iterable of filters to
+ a stream. If lexer is given it's forwarded to the
+ filter, otherwise the filter receives `None`.
+ """
+ def _apply(filter_, stream):
+ for token in filter_.filter(lexer, stream):
+ yield token
+ for filter_ in filters:
+ stream = _apply(filter_, stream)
+ return stream
+
+
+def simplefilter(f):
+ """
+ Decorator that converts a function into a filter::
+
+ @simplefilter
+ def lowercase(lexer, stream, options):
+ for ttype, value in stream:
+ yield ttype, value.lower()
+ """
+ return type(f.__name__, (FunctionFilter,), {
+ 'function': f,
+ '__module__': getattr(f, '__module__'),
+ '__doc__': f.__doc__
+ })
+
+
+class Filter(object):
+ """
+ Default filter. Subclass this class or use the `simplefilter`
+ decorator to create own filters.
+ """
+
+ def __init__(self, **options):
+ self.options = options
+
+ def filter(self, lexer, stream):
+ raise NotImplementedError()
+
+
+class FunctionFilter(Filter):
+ """
+ Abstract class used by `simplefilter` to create simple
+ function filters on the fly. The `simplefilter` decorator
+ automatically creates subclasses of this class for
+ functions passed to it.
+ """
+ function = None
+
+ def __init__(self, **options):
+ if not hasattr(self, 'function'):
+ raise TypeError('%r used without bound function' %
+ self.__class__.__name__)
+ Filter.__init__(self, **options)
+
+ def filter(self, lexer, stream):
+ # pylint: disable-msg=E1102
+ for ttype, value in self.function(lexer, stream, self.options):
+ yield ttype, value
BIN vendor/pygments/filter.pyc
Binary file not shown.
357 vendor/pygments/filters/__init__.py
@@ -0,0 +1,357 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.filters
+ ~~~~~~~~~~~~~~~~
+
+ Module containing filter lookup functions and default
+ filters.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import re
+
+from pygments.token import String, Comment, Keyword, Name, Error, Whitespace, \
+ string_to_tokentype
+from pygments.filter import Filter
+from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \
+ get_choice_opt, ClassNotFound, OptionError
+from pygments.plugin import find_plugin_filters
+
+
+def find_filter_class(filtername):
+ """
+ Lookup a filter by name. Return None if not found.
+ """
+ if filtername in FILTERS:
+ return FILTERS[filtername]
+ for name, cls in find_plugin_filters():
+ if name == filtername:
+ return cls
+ return None
+
+
+def get_filter_by_name(filtername, **options):
+ """
+ Return an instantiated filter. Options are passed to the filter
+ initializer if wanted. Raise a ClassNotFound if not found.
+ """
+ cls = find_filter_class(filtername)
+ if cls:
+ return cls(**options)
+ else:
+ raise ClassNotFound('filter %r not found' % filtername)
+
+
+def get_all_filters():
+ """
+ Return a generator of all filter names.
+ """
+ for name in FILTERS:
+ yield name
+ for name, _ in find_plugin_filters():
+ yield name
+
+
+def _replace_special(ttype, value, regex, specialttype,
+ replacefunc=lambda x: x):
+ last = 0
+ for match in regex.finditer(value):
+ start, end = match.start(), match.end()
+ if start != last:
+ yield ttype, value[last:start]
+ yield specialttype, replacefunc(value[start:end])
+ last = end
+ if last != len(value):
+ yield ttype, value[last:]
+
+
+class CodeTagFilter(Filter):
+ """
+ Highlight special code tags in comments and docstrings.
+
+ Options accepted:
+
+ `codetags` : list of strings
+ A list of strings that are flagged as code tags. The default is to
+ highlight ``XXX``, ``TODO``, ``BUG`` and ``NOTE``.
+ """
+
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ tags = get_list_opt(options, 'codetags',
+ ['XXX', 'TODO', 'BUG', 'NOTE'])
+ self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
+ re.escape(tag) for tag in tags if tag
+ ]))
+
+ def filter(self, lexer, stream):
+ regex = self.tag_re
+ for ttype, value in stream:
+ if ttype in String.Doc or \
+ ttype in Comment and \
+ ttype not in Comment.Preproc:
+ for sttype, svalue in _replace_special(ttype, value, regex,
+ Comment.Special):
+ yield sttype, svalue
+ else:
+ yield ttype, value
+
+
+class KeywordCaseFilter(Filter):
+ """
+ Convert keywords to lowercase or uppercase or capitalize them, which
+ means first letter uppercase, rest lowercase.
+
+ This can be useful e.g. if you highlight Pascal code and want to adapt the
+ code to your styleguide.
+
+ Options accepted:
+
+ `case` : string
+ The casing to convert keywords to. Must be one of ``'lower'``,
+ ``'upper'`` or ``'capitalize'``. The default is ``'lower'``.
+ """
+
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ case = get_choice_opt(options, 'case', ['lower', 'upper', 'capitalize'], 'lower')
+ self.convert = getattr(unicode, case)
+
+ def filter(self, lexer, stream):
+ for ttype, value in stream:
+ if ttype in Keyword:
+ yield ttype, self.convert(value)
+ else:
+ yield ttype, value
+
+
+class NameHighlightFilter(Filter):
+ """
+ Highlight a normal Name token with a different token type.
+
+ Example::
+
+ filter = NameHighlightFilter(
+ names=['foo', 'bar', 'baz'],
+ tokentype=Name.Function,
+ )
+
+ This would highlight the names "foo", "bar" and "baz"
+ as functions. `Name.Function` is the default token type.
+
+ Options accepted:
+
+ `names` : list of strings
+ A list of names that should be given the different token type.
+ There is no default.
+ `tokentype` : TokenType or string
+ A token type or a string containing a token type name that is
+ used for highlighting the strings in `names`. The default is
+ `Name.Function`.
+ """
+
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ self.names = set(get_list_opt(options, 'names', []))
+ tokentype = options.get('tokentype')
+ if tokentype:
+ self.tokentype = string_to_tokentype(tokentype)
+ else:
+ self.tokentype = Name.Function
+
+ def filter(self, lexer, stream):
+ for ttype, value in stream:
+ if ttype is Name and value in self.names:
+ yield self.tokentype, value
+ else:
+ yield ttype, value
+
+
+class ErrorToken(Exception):
+ pass
+
+class RaiseOnErrorTokenFilter(Filter):
+ """
+ Raise an exception when the lexer generates an error token.
+
+ Options accepted:
+
+ `excclass` : Exception class
+ The exception class to raise.
+ The default is `pygments.filters.ErrorToken`.
+
+ *New in Pygments 0.8.*
+ """
+
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ self.exception = options.get('excclass', ErrorToken)
+ try:
+ # issubclass() will raise TypeError if first argument is not a class
+ if not issubclass(self.exception, Exception):
+ raise TypeError
+ except TypeError:
+ raise OptionError('excclass option is not an exception class')
+
+ def filter(self, lexer, stream):
+ for ttype, value in stream:
+ if ttype is Error:
+ raise self.exception(value)
+ yield ttype, value
+
+
+class VisibleWhitespaceFilter(Filter):
+ """
+ Convert tabs, newlines and/or spaces to visible characters.
+
+ Options accepted:
+
+ `spaces` : string or bool
+ 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 ``·`` (unicode
+ MIDDLE DOT). If it is a false value, spaces will not be replaced. The
+ default is ``False``.
+ `tabs` : string or bool
+ The same as for `spaces`, but the default replacement character is ``»``
+ (unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value
+ is ``False``. Note: this will not work if the `tabsize` option for the
+ lexer is nonzero, as tabs will already have been expanded then.
+ `tabsize` : int
+ If tabs are to be replaced by this filter (see the `tabs` option), this
+ is the total number of characters that a tab should be expanded to.
+ The default is ``8``.
+ `newlines` : string or bool
+ The same as for `spaces`, but the default replacement character is ``¶``
+ (unicode PILCROW SIGN). The default value is ``False``.
+ `wstokentype` : bool
+ If true, give whitespace the special `Whitespace` token type. This allows
+ styling the visible whitespace differently (e.g. greyed out), but it can
+ disrupt background colors. The default is ``True``.
+
+ *New in Pygments 0.8.*
+ """
+
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ for name, default in {'spaces': u'·', 'tabs': u'»', 'newlines': u''}.items():
+ opt = options.get(name, False)
+ if isinstance(opt, basestring) and len(opt) == 1:
+ setattr(self, name, opt)
+ else:
+ setattr(self, name, (opt and default or ''))
+ tabsize = get_int_opt(options, 'tabsize', 8)
+ if self.tabs:
+ self.tabs += ' '*(tabsize-1)
+ if self.newlines:
+ self.newlines += '\n'
+ self.wstt = get_bool_opt(options, 'wstokentype', True)
+
+ def filter(self, lexer, stream):
+ if self.wstt:
+ spaces = self.spaces or ' '
+ tabs = self.tabs or '\t'
+ newlines = self.newlines or '\n'
+ regex = re.compile(r'\s')
+ def replacefunc(wschar):
+ if wschar == ' ':
+ return spaces
+ elif wschar == '\t':
+ return tabs
+ elif wschar == '\n':
+ return newlines
+ return wschar
+
+ for ttype, value in stream:
+ for sttype, svalue in _replace_special(ttype, value, regex,
+ Whitespace, replacefunc):
+ yield sttype, svalue
+ else:
+ spaces, tabs, newlines = self.spaces, self.tabs, self.newlines
+ # simpler processing
+ for ttype, value in stream:
+ if spaces:
+ value = value.replace(' ', spaces)
+ if tabs:
+ value = value.replace('\t', tabs)
+ if newlines:
+ value = value.replace('\n', newlines)
+ yield ttype, value
+
+
+class GobbleFilter(Filter):
+ """
+ Gobbles source code lines (eats initial characters).
+
+ 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
+ amount of space that isn't desired in the output.
+
+ Options accepted:
+
+ `n` : int
+ The number of characters to gobble.
+
+ *New in Pygments 1.2.*
+ """
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+ self.n = get_int_opt(options, 'n', 0)
+
+ def gobble(self, value, left):
+ if left < len(value):
+ return value[left:], 0
+ else:
+ return '', left - len(value)
+
+ def filter(self, lexer, stream):
+ n = self.n
+ left = n # How many characters left to gobble.
+ for ttype, value in stream:
+ # Remove ``left`` tokens from first line, ``n`` from all others.
+ parts = value.split('\n')
+ (parts[0], left) = self.gobble(parts[0], left)
+ for i in range(1, len(parts)):
+ (parts[i], left) = self.gobble(parts[i], n)
+ value = '\n'.join(parts)
+
+ if value != '':
+ yield ttype, value
+
+
+class TokenMergeFilter(Filter):
+ """
+ Merges consecutive tokens with the same token type in the output stream of a
+ lexer.
+
+ *New in Pygments 1.2.*
+ """
+ def __init__(self, **options):
+ Filter.__init__(self, **options)
+
+ def filter(self, lexer, stream):
+ output = []
+ current_type = None
+ current_value = None
+ for ttype, value in stream:
+ if ttype is current_type:
+ current_value += value
+ else:
+ if current_type is not None:
+ yield current_type, current_value
+ current_type = ttype
+ current_value = value
+ if current_type is not None:
+ yield current_type, current_value
+
+
+FILTERS = {
+ 'codetagify': CodeTagFilter,
+ 'keywordcase': KeywordCaseFilter,
+ 'highlight': NameHighlightFilter,
+ 'raiseonerror': RaiseOnErrorTokenFilter,
+ 'whitespace': VisibleWhitespaceFilter,
+ 'gobble': GobbleFilter,
+ 'tokenmerge': TokenMergeFilter,
+}
BIN vendor/pygments/filters/__init__.pyc
Binary file not shown.
92 vendor/pygments/formatter.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.formatter
+ ~~~~~~~~~~~~~~~~~~
+
+ Base formatter class.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import codecs
+
+from pygments.util import get_bool_opt
+from pygments.styles import get_style_by_name
+
+__all__ = ['Formatter']
+
+
+def _lookup_style(style):
+ if isinstance(style, basestring):
+ return get_style_by_name(style)
+ return style
+
+
+class Formatter(object):
+ """
+ Converts a token stream to text.
+
+ Options accepted:
+
+ ``style``
+ The style to use, can be a string or a Style subclass
+ (default: "default"). Not used by e.g. the
+ TerminalFormatter.
+ ``full``
+ Tells the formatter to output a "full" document, i.e.
+ a complete self-contained document. This doesn't have
+ any effect for some formatters (default: false).
+ ``title``
+ If ``full`` is true, the title that should be used to
+ caption the document (default: '').
+ ``encoding``
+ If given, must be an encoding name. This will be used to
+ convert the Unicode token strings to byte strings in the
+ output. If it is "" or None, Unicode strings will be written
+ to the output file, which most file-like objects do not
+ support (default: None).
+ ``outencoding``
+ Overrides ``encoding`` if given.
+ """
+
+ #: Name of the formatter
+ name = None
+
+ #: Shortcuts for the formatter
+ aliases = []
+
+ #: fn match rules
+ filenames = []
+
+ #: If True, this formatter outputs Unicode strings when no encoding
+ #: option is given.
+ unicodeoutput = True
+
+ def __init__(self, **options):
+ self.style = _lookup_style(options.get('style', 'default'))
+ self.full = get_bool_opt(options, 'full', False)
+ self.title = options.get('title', '')
+ self.encoding = options.get('encoding', None) or None
+ self.encoding = options.get('outencoding', None) or self.encoding
+ self.options = options
+
+ def get_style_defs(self, arg=''):
+ """
+ Return the style definitions for the current style as a string.
+
+ ``arg`` is an additional argument whose meaning depends on the
+ formatter used. Note that ``arg`` can also be a list or tuple
+ for some formatters like the html formatter.
+ """
+ return ''
+
+ def format(self, tokensource, outfile):
+ """
+ Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
+ tuples and write it into ``outfile``.
+ """
+ if self.encoding:
+ # wrap the outfile in a StreamWriter
+ outfile = codecs.lookup(self.encoding)[3](outfile)
+ return self.format_unencoded(tokensource, outfile)
BIN vendor/pygments/formatter.pyc
Binary file not shown.
68 vendor/pygments/formatters/__init__.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.formatters
+ ~~~~~~~~~~~~~~~~~~~
+
+ Pygments formatters.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+import os.path
+import fnmatch
+
+from pygments.formatters._mapping import FORMATTERS
+from pygments.plugin import find_plugin_formatters
+from pygments.util import ClassNotFound
+
+ns = globals()
+for fcls in FORMATTERS:
+ ns[fcls.__name__] = fcls
+del fcls
+
+__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
+ 'get_all_formatters'] + [cls.__name__ for cls in FORMATTERS]
+
+
+_formatter_alias_cache = {}
+_formatter_filename_cache = []
+
+def _init_formatter_cache():
+ if _formatter_alias_cache:
+ return
+ 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):
+ _init_formatter_cache()
+ cls = _formatter_alias_cache.get(name, None)
+ return cls
+
+
+def get_formatter_by_name(name, **options):
+ _init_formatter_cache()
+ cls = _formatter_alias_cache.get(name, None)
+ if not cls:
+ raise ClassNotFound("No formatter found for name %r" % name)
+ return cls(**options)
+
+
+def get_formatter_for_filename(fn, **options):
+ _init_formatter_cache()
+ fn = os.path.basename(fn)
+ for pattern, cls in _formatter_filename_cache:
+ if fnmatch.fnmatch(fn, pattern):
+ return cls(**options)
+ raise ClassNotFound("No formatter found for file name %r" % fn)
+
+
+def get_all_formatters():
+ """Return a generator for all formatters."""
+ for formatter in FORMATTERS:
+ yield formatter
+ for _, formatter in find_plugin_formatters():
+ yield formatter
BIN vendor/pygments/formatters/__init__.pyc
Binary file not shown.
92 vendor/pygments/formatters/_mapping.py
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.formatters._mapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Formatter mapping defintions. This file is generated by itself. Everytime
+ you change something on a builtin formatter defintion, run this script from
+ the formatters folder to update it.
+
+ Do not alter the FORMATTERS dictionary by hand.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from pygments.util import docstring_headline
+
+# start
+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 = {
+ 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.'),
+ 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.'),
+ 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.'),
+ 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."),
+ 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.'),
+ 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.'),
+ LatexFormatter: ('LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
+ NullFormatter: ('Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
+ RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
+ 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.'),
+ 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.'),
+ 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.'),
+ 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.')
+}
+
+if __name__ == '__main__':
+ import sys
+ import os
+
+ # lookup formatters
+ found_formatters = []
+ imports = []
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
+ for filename in os.listdir('.'):
+ if filename.endswith('.py') and not filename.startswith('_'):
+ module_name = 'pygments.formatters.%s' % filename[:-3]
+ print module_name
+ module = __import__(module_name, None, None, [''])
+ for formatter_name in module.__all__:
+ imports.append((module_name, formatter_name))
+ formatter = getattr(module, formatter_name)
+ found_formatters.append(
+ '%s: %r' % (formatter_name,
+ (formatter.name,
+ tuple(formatter.aliases),
+ tuple(formatter.filenames),
+ docstring_headline(formatter))))
+ # sort them, that should make the diff files for svn smaller
+ found_formatters.sort()
+ imports.sort()
+
+ # extract useful sourcecode from this file
+ f = open(__file__)
+ try:
+ content = f.read()
+ finally:
+ f.close()
+ header = content[:content.find('# start')]
+ footer = content[content.find("if __name__ == '__main__':"):]
+
+ # write new file
+ f = open(__file__, 'w')
+ f.write(header)
+ f.write('# start\n')
+ f.write('\n'.join(['from %s import %s' % imp for imp in imports]))
+ f.write('\n\n')
+ f.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
+ f.write(footer)
+ f.close()
BIN vendor/pygments/formatters/_mapping.pyc
Binary file not shown.
109 vendor/pygments/formatters/bbcode.py
@@ -0,0 +1,109 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.formatters.bbcode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ BBcode formatter.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+
+from pygments.formatter import Formatter
+from pygments.util import get_bool_opt
+
+__all__ = ['BBCodeFormatter']
+
+
+class BBCodeFormatter(Formatter):
+ """
+ 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.
+
+ This formatter has no support for background colors and borders, as there
+ are no common BBcode tags for that.
+
+ 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 ``monofont`` option) and no spaces (which you
+ need for indentation) are removed.
+
+ Additional options accepted:
+
+ `style`
+ The style to use, can be a string or a Style subclass (default:
+ ``'default'``).
+
+ `codetag`
+ If set to true, put the output into ``[code]`` tags (default:
+ ``false``)
+
+ `monofont`
+ If set to true, add a tag to show the code with a monospace font
+ (default: ``false``).
+ """
+ name = 'BBCode'
+ aliases = ['bbcode', 'bb']
+ filenames = []
+
+ def __init__(self, **options):
+ Formatter.__init__(self, **options)
+ self._code = get_bool_opt(options, 'codetag', False)
+ self._mono = get_bool_opt(options, 'monofont', False)
+
+ self.styles = {}
+ self._make_styles()
+
+ def _make_styles(self):
+ for ttype, ndef in self.style:
+ start = end = ''
+ if ndef['color']:
+ start += '[color=#%s]' % ndef['color']
+ end = '[/color]' + end
+ if ndef['bold']:
+ start += '[b]'
+ end = '[/b]' + end
+ if ndef['italic']:
+ start += '[i]'
+ end = '[/i]' + end
+ if ndef['underline']:
+ start += '[u]'
+ end = '[/u]' + end
+ # there are no common BBcodes for background-color and border
+
+ self.styles[ttype] = start, end
+
+ def format_unencoded(self, tokensource, outfile):
+ if self._code:
+ outfile.write('[code]')
+ if self._mono:
+ outfile.write('[font=monospace]')
+
+ lastval = ''
+ lasttype = None
+
+ for ttype, value in tokensource:
+ while ttype not in self.styles:
+ ttype = ttype.parent
+ if ttype == lasttype:
+ lastval += value
+ else:
+ if lastval:
+ start, end = self.styles[lasttype]
+ outfile.write(''.join((start, lastval, end)))
+ lastval = value
+ lasttype = ttype
+
+ if lastval:
+ start, end = self.styles[lasttype]
+ outfile.write(''.join((start, lastval, end)))
+
+ if self._mono:
+ outfile.write('[/font]')
+ if self._code:
+ outfile.write('[/code]')
+ if self._code or self._mono:
+ outfile.write('\n')
BIN vendor/pygments/formatters/bbcode.pyc
Binary file not shown.
723 vendor/pygments/formatters/html.py
@@ -0,0 +1,723 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.formatters.html
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Formatter for HTML output.
+
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import os
+import sys
+import StringIO
+
+from pygments.formatter import Formatter
+from pygments.token import Token, Text, STANDARD_TYPES
+from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
+
+
+__all__ = ['HtmlFormatter']
+
+
+def escape_html(text):
+ """Escape &, <, > as well as single and double quotes for HTML."""
+ return text.replace('&', '&amp;'). \
+ replace('<', '&lt;'). \
+ replace('>', '&gt;'). \
+ replace('"', '&quot;'). \
+ replace("'", '&#39;')
+
+
+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):
+ fname = STANDARD_TYPES.get(ttype)
+ if fname:
+ return fname
+ aname = ''
+ while fname is None:
+ aname = '-' + ttype[-1] + aname
+ ttype = ttype.parent
+ fname = STANDARD_TYPES.get(ttype)
+ return fname + aname
+
+
+CSSFILE_TEMPLATE = '''\
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+pre { line-height: 125%%; }
+%(styledefs)s
+'''
+
+DOC_HEADER = '''\
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+<head>
+ <title>%(title)s</title>
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
+ <style type="text/css">
+''' + CSSFILE_TEMPLATE + '''
+ </style>
+</head>
+<body>
+<h2>%(title)s</h2>
+
+'''
+
+DOC_HEADER_EXTERNALCSS = '''\
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+
+<html>
+<head>
+ <title>%(title)s</title>
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
+ <link rel="stylesheet" href="%(cssfile)s" type="text/css">
+</head>
+<body>
+<h2>%(title)s</h2>
+
+'''
+
+DOC_FOOTER = '''\
+</body>
+</html>
+'''
+
+
+class HtmlFormatter(Formatter):
+ r"""
+ 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.
+
+ If the `linenos` option is set to ``"table"``, the ``<pre>`` is
+ additionally wrapped inside a ``<table>`` which has one row and two
+ cells: one containing the line numbers and one containing the code.
+ Example:
+
+ .. sourcecode:: html
+
+ <div class="highlight" >
+ <table><tr>
+ <td class="linenos" title="click to toggle"
+ onclick="with (this.firstChild.style)
+ { display = (display == '') ? 'none' : '' }">
+ <pre>1
+ 2</pre>
+ </td>
+ <td class="code">
+ <pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar):
+ <span class="Ke">pass</span>
+ </pre>
+ </td>
+ </tr></table></div>
+
+ (whitespace added to improve clarity).
+
+ Wrapping can be disabled using the `nowrap` option.
+
+ A list of lines can be specified using the `hl_lines` option to make these
+ lines highlighted (as of Pygments 0.11).
+
+ With the `full` option, a complete HTML 4 document is output, including
+ the style definitions inside a ``<style>`` tag, or in a separate file if
+ the `cssfile` option is given.
+
+ The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
+ containing CSS rules for the CSS classes used by the formatter. The
+ argument `arg` can be used to specify additional CSS selectors that
+ are prepended to the classes. A call `fmter.get_style_defs('td .code')`
+ would result in the following CSS classes:
+
+ .. sourcecode:: css
+
+ td .code .kw { font-weight: bold; color: #00FF00 }
+ td .code .cm { color: #999999 }
+ ...
+
+ If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
+ `get_style_defs()` method to request multiple prefixes for the tokens:
+
+ .. sourcecode:: python
+
+ formatter.get_style_defs(['div.syntax pre', 'pre.syntax'])
+
+ The output would then look like this:
+
+ .. sourcecode:: css
+
+ div.syntax pre .kw,
+ pre.syntax .kw { font-weight: bold; color: #00FF00 }
+ div.syntax pre .cm,
+ pre.syntax .cm { color: #999999 }
+ ...
+
+ Additional options accepted:
+
+ `nowrap`
+ If set to ``True``, don't wrap the tokens at all, not even inside a ``<pre>``
+ tag. This disables most other options (default: ``False``).
+
+ `full`
+ Tells the formatter to output a "full" document, i.e. a complete
+ self-contained document (default: ``False``).
+
+ `title`
+ If `full` is true, the title that should be used to caption the
+ document (default: ``''``).
+
+ `style`
+ The style to use, can be a string or a Style subclass (default:
+ ``'default'``). This option has no effect if the `cssfile`
+ and `noclobber_cssfile` option are given and the file specified in
+ `cssfile` exists.
+
+ `noclasses`
+ If set to true, token ``<span>`` 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: ``False``).
+
+ `classprefix`
+ 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
+ `classprefix` 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 `get_style_defs()`.
+
+ `cssclass`
+ CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``).
+ If you set this option, the default selector for `get_style_defs()`
+ will be this class.
+
+ *New in Pygments 0.9:* If you select the ``'table'`` line numbers, the
+ wrapping table will have a CSS class of this string plus ``'table'``,
+ the default is accordingly ``'highlighttable'``.
+
+ `cssstyles`
+ Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
+
+ `prestyles`
+ Inline CSS styles for the ``<pre>`` tag (default: ``''``). *New in
+ Pygments 0.11.*
+
+ `cssfile`
+ 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
+ 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. *New in Pygments 0.6.*
+
+ `noclobber_cssfile`
+ 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
+ combination with a user specified css file. Default is ``False``.
+ *New in Pygments 1.1.*
+
+ `linenos`
+ If set to ``'table'``, 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 ``'inline'``, the line numbers will be
+ integrated in the ``<pre>`` tag that contains the code (that setting
+ is *new in Pygments 0.8*).
+
+ For compatibility with Pygments 0.7 and earlier, every true value
+ except ``'inline'`` means the same as ``'table'`` (in particular, that
+ means also ``True``).
+
+ The default value is ``False``, which means no line numbers at all.
+
+ **Note:** with the default ("table") line number mechanism, the line
+ numbers and code can have different line heights in Internet Explorer
+ unless you give the enclosing ``<pre>`` tags an explicit ``line-height``
+ CSS property (you get the default line spacing with ``line-height:
+ 125%``).
+
+ `hl_lines`
+ Specify a list of lines to be highlighted. *New in Pygments 0.11.*
+
+ `linenostart`
+ The line number for the first line (default: ``1``).
+
+ `linenostep`
+ If set to a number n > 1, only every nth line number is printed.
+
+ `linenospecial`
+ If set to a number n > 0, every nth line number is given the CSS
+ class ``"special"`` (default: ``0``).
+
+ `nobackground`
+ If set to ``True``, the formatter won't output the background color
+ for the wrapping element (this automatically defaults to ``False``
+ when there is no wrapping element [eg: no argument for the
+ `get_syntax_defs` method given]) (default: ``False``). *New in
+ Pygments 0.6.*
+
+ `lineseparator`
+ 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
+ e.g. set it to ``"<br>"`` to get HTML line breaks. *New in Pygments
+ 0.7.*
+
+ `lineanchors`
+ 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``.
+ This allows easy linking to certain lines. *New in Pygments 0.9.*
+
+ `anchorlinenos`
+ If set to `True`, will wrap line numbers in <a> tags. Used in
+ combination with `linenos` and `lineanchors`.
+
+
+ **Subclassing the HTML formatter**
+
+ *New in Pygments 0.7.*
+
+ The HTML formatter is now built in a way that allows easy subclassing, thus
+ customizing the output HTML code. The `format()` method calls
+ `self._format_lines()` which returns a generator that yields tuples of ``(1,
+ line)``, where the ``1`` indicates that the ``line`` is a line of the
+ formatted source code.
+
+ If the `nowrap` option is set, the generator is the iterated over and the
+ resulting HTML is output.
+
+ Otherwise, `format()` calls `self.wrap()`, which wraps the generator with
+ other generators. These may add some HTML code to the one generated by
+ `_format_lines()`, either by modifying the lines generated by the latter,
+ then yielding them again with ``(1, line)``, and/or by yielding other HTML
+ code before or after the lines, with ``(0, html)``. The distinction between
+ source lines and other code makes it possible to wrap the generator multiple
+ times.
+
+ The default `wrap()` implementation adds a ``<div>`` and a ``<pre>`` tag.
+
+ A custom `HtmlFormatter` subclass could look like this:
+
+ .. sourcecode:: python
+
+ class CodeHtmlFormatter(HtmlFormatter):
+
+ def wrap(self, source, outfile):
+ return self._wrap_code(source)
+
+ def _wrap_code(self, source):
+ yield 0, '<code>'
+ for i, t in source:
+ if i == 1:
+ # it's a line of formatted code
+ t += '<br>'
+ yield i, t
+ yield 0, '</code>'
+
+ This results in wrapping the formatted lines with a ``<code>`` tag, where the
+ source lines are broken using ``<br>`` tags.
+
+ After calling `wrap()`, the `format()` method also adds the "line numbers"
+ and/or "full document" wrappers if the respective options are set. Then, all
+ HTML yielded by the wrapped generator is output.
+ """
+
+ name = 'HTML'
+ aliases = ['html']
+ filenames = ['*.html', '*.htm']
+
+ def __init__(self, **options):
+ Formatter.__init__(self, **options)
+ self.title = self._decodeifneeded(self.title)
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
+ self.noclasses = get_bool_opt(options, 'noclasses', False)
+ self.classprefix = options.get('classprefix', '')
+ self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
+ self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
+ self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
+ self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
+ self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
+
+ linenos = options.get('linenos', False)
+ if linenos == 'inline':
+ self.linenos = 2
+ elif linenos:
+ # compatibility with <= 0.7
+ self.linenos = 1
+ else:
+ self.linenos = 0
+ self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
+ self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
+ self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
+ self.nobackground = get_bool_opt(options, 'nobackground', False)
+ self.lineseparator = options.get('lineseparator', '\n')
+ self.lineanchors = options.get('lineanchors', '')
+ self.anchorlinenos = options.get('anchorlinenos', False)
+ self.hl_lines = set()
+ for lineno in get_list_opt(options, 'hl_lines', []):
+ try:
+ self.hl_lines.add(int(lineno))
+ except ValueError:
+ pass
+
+ self._class_cache = {}
+ self._create_stylesheet()
+
+ def _get_css_class(self, ttype):
+ """Return the css class of this token type prefixed with
+ the classprefix option."""
+ if ttype in self._class_cache:
+ return self._class_cache[ttype]
+ return self.classprefix + _get_ttype_class(ttype)
+
+ def _create_stylesheet(self):
+ t2c = self.ttype2class = {Token: ''}
+ c2s = self.class2style = {}
+ cp = self.classprefix
+ for ttype, ndef in self.style:
+ name = cp + _get_ttype_class(ttype)
+ style = ''
+ if ndef['color']:
+ style += 'color: #%s; ' % ndef['color']
+ if ndef['bold']:
+ style += 'font-weight: bold; '
+ if ndef['italic']:
+ style += 'font-style: italic; '
+ if ndef['underline']:
+ style += 'text-decoration: underline; '
+ if ndef['bgcolor']:
+ style += 'background-color: #%s; ' % ndef['bgcolor']
+ if ndef['border']:
+ style += 'border: 1px solid #%s; ' % ndef['border']
+ if style:
+ t2c[ttype] = name
+ # save len(ttype) to enable ordering the styles by
+ # hierarchy (necessary for CSS cascading rules!)
+ c2s[name] = (style[:-2], ttype, len(ttype))
+
+ def get_style_defs(self, arg=None):
+ """
+ Return CSS style definitions for the classes produced by the current
+ highlighting style. ``arg`` can be a string or list of selectors to
+ insert before the token type classes.
+ """
+ if arg is None:
+ arg = ('cssclass' in self.options and '.'+self.cssclass or '')
+ if isinstance(arg, basestring):
+ args = [arg]
+ else:
+ args = list(arg)
+
+ def prefix(cls):
+ if cls:
+ cls = '.' + cls
+ tmp = []
+ for arg in args:
+ tmp.append((arg and arg + ' ' or '') + cls)
+ return ', '.join(tmp)
+
+ styles = [(level, ttype, cls, style)
+ for cls, (style, ttype, level) in self.class2style.iteritems()
+ if cls and style]
+ styles.sort()
+ lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
+ for (level, ttype, cls, style) in styles]
+ if arg and not self.nobackground and \
+ self.style.background_color is not None:
+ text_style = ''
+ if Text in self.ttype2class:
+ text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
+ lines.insert(0, '%s { background: %s;%s }' %
+ (prefix(''), self.style.background_color, text_style))
+ if self.style.highlight_color is not None:
+ lines.insert(0, '%s.hll { background-color: %s }' %
+ (prefix(''), self.style.highlight_color))
+ return '\n'.join(lines)
+
+ def _decodeifneeded(self, value):
+ if isinstance(value, bytes):
+ if self.encoding:
+ return value.decode(self.encoding)
+ return value.decode()
+ return value
+
+ def _wrap_full(self, inner, outfile):
+ if self.cssfile:
+ if os.path.isabs(self.cssfile):
+ # it's an absolute filename
+ cssfilename = self.cssfile
+ else:
+ try:
+ filename = outfile.name
+ if not filename or filename[0] == '<':
+ # pseudo files, e.g. name == '<fdopen>'
+ raise AttributeError
+ cssfilename = os.path.join(os.path.dirname(filename),
+ self.cssfile)
+ except AttributeError: