pygments.rb 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +3 -0
  4. data/lexers +0 -0
  5. data/lib/pygments/popen.rb +3 -2
  6. data/lib/pygments/version.rb +1 -1
  7. data/pygments.rb.gemspec +2 -1
  8. data/vendor/pygments-main/AUTHORS +20 -1
  9. data/vendor/pygments-main/CHANGES +55 -3
  10. data/vendor/pygments-main/LICENSE +1 -1
  11. data/vendor/pygments-main/MANIFEST.in +1 -1
  12. data/vendor/pygments-main/Makefile +5 -8
  13. data/vendor/pygments-main/REVISION +1 -1
  14. data/vendor/pygments-main/doc/Makefile +153 -0
  15. data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
  16. data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
  17. data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
  18. data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
  19. data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
  20. data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
  21. data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
  22. data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
  23. data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
  24. data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
  25. data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
  26. data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
  27. data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
  28. data/vendor/pygments-main/doc/conf.py +249 -0
  29. data/vendor/pygments-main/doc/docs/api.rst +316 -0
  30. data/vendor/pygments-main/doc/docs/authors.rst +4 -0
  31. data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
  32. data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
  33. data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
  34. data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
  35. data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
  36. data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
  37. data/vendor/pygments-main/doc/docs/index.rst +66 -0
  38. data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
  39. data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
  40. data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
  41. data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
  42. data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
  43. data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
  44. data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
  45. data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
  46. data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
  47. data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
  48. data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
  49. data/vendor/pygments-main/doc/download.rst +41 -0
  50. data/vendor/pygments-main/doc/faq.rst +143 -0
  51. data/vendor/pygments-main/doc/index.rst +53 -0
  52. data/vendor/pygments-main/doc/languages.rst +151 -0
  53. data/vendor/pygments-main/doc/make.bat +190 -0
  54. data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
  55. data/vendor/pygments-main/external/autopygmentize +65 -48
  56. data/vendor/pygments-main/external/markdown-processor.py +15 -15
  57. data/vendor/pygments-main/external/moin-parser.py +1 -1
  58. data/vendor/pygments-main/external/rst-directive.py +2 -3
  59. data/vendor/pygments-main/ez_setup.py +340 -234
  60. data/vendor/pygments-main/pygments/__init__.py +4 -4
  61. data/vendor/pygments-main/pygments/cmdline.py +81 -68
  62. data/vendor/pygments-main/pygments/console.py +1 -1
  63. data/vendor/pygments-main/pygments/filter.py +1 -1
  64. data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
  65. data/vendor/pygments-main/pygments/formatter.py +3 -3
  66. data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
  67. data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
  68. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  69. data/vendor/pygments-main/pygments/formatters/html.py +44 -26
  70. data/vendor/pygments-main/pygments/formatters/img.py +21 -14
  71. data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
  72. data/vendor/pygments-main/pygments/formatters/other.py +53 -6
  73. data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
  74. data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
  75. data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
  76. data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
  77. data/vendor/pygments-main/pygments/lexer.py +59 -39
  78. data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
  79. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
  80. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
  81. data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
  82. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
  83. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
  84. data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
  85. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
  86. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
  87. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
  88. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
  89. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
  90. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
  91. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
  92. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
  93. data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
  94. data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
  95. data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
  96. data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
  97. data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
  98. data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
  99. data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
  100. data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
  101. data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
  102. data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
  103. data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
  104. data/vendor/pygments-main/pygments/lexers/math.py +438 -70
  105. data/vendor/pygments-main/pygments/lexers/other.py +885 -171
  106. data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
  107. data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
  108. data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
  109. data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
  110. data/vendor/pygments-main/pygments/lexers/special.py +7 -8
  111. data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
  112. data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
  113. data/vendor/pygments-main/pygments/lexers/text.py +208 -46
  114. data/vendor/pygments-main/pygments/lexers/web.py +729 -264
  115. data/vendor/pygments-main/pygments/modeline.py +1 -1
  116. data/vendor/pygments-main/pygments/plugin.py +1 -1
  117. data/vendor/pygments-main/pygments/scanner.py +1 -1
  118. data/vendor/pygments-main/pygments/sphinxext.py +153 -0
  119. data/vendor/pygments-main/pygments/style.py +3 -2
  120. data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
  121. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  122. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  123. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  124. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  125. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  126. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  127. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  128. data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
  129. data/vendor/pygments-main/pygments/styles/igor.py +29 -0
  130. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  131. data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
  132. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  133. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  134. data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
  135. data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
  136. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  137. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  138. data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
  139. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  140. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  141. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  142. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  143. data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
  144. data/vendor/pygments-main/pygments/token.py +4 -1
  145. data/vendor/pygments-main/pygments/unistring.py +6 -5
  146. data/vendor/pygments-main/pygments/util.py +35 -21
  147. data/vendor/pygments-main/scripts/check_sources.py +28 -44
  148. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
  149. data/vendor/pygments-main/scripts/find_codetags.py +27 -19
  150. data/vendor/pygments-main/scripts/find_error.py +16 -13
  151. data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
  152. data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
  153. data/vendor/pygments-main/setup.py +19 -19
  154. data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
  155. data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
  156. data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
  157. data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
  158. data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
  159. data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
  160. data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
  161. data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
  162. data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
  163. data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
  164. data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
  165. data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
  166. data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
  167. data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
  168. data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
  169. data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
  170. data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
  171. data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
  172. data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
  173. data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
  174. data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
  175. data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
  176. data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
  177. data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
  178. data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
  179. data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
  180. data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
  181. data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
  182. data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
  183. data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
  184. data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
  185. data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
  186. data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
  187. data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
  188. data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
  189. data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
  190. data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
  191. data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
  192. data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
  193. data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
  194. data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
  195. data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
  196. data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
  197. data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
  198. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
  199. data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
  200. data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
  201. data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
  202. data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
  203. data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
  204. data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
  205. data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
  206. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
  207. data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
  208. data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
  209. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
  210. data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
  211. data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
  212. data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
  213. data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
  214. data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
  215. data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
  216. data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
  217. data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
  218. data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
  219. data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
  220. data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
  221. data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
  222. data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
  223. data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
  224. data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
  225. data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
  226. data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
  227. data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
  228. data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
  229. data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
  230. data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
  231. data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
  232. data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
  233. data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
  234. data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
  235. data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
  236. data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
  237. data/vendor/pygments-main/tests/run.py +14 -19
  238. data/vendor/pygments-main/tests/string_asserts.py +22 -0
  239. data/vendor/pygments-main/tests/test_basic_api.py +28 -14
  240. data/vendor/pygments-main/tests/test_cfm.py +46 -0
  241. data/vendor/pygments-main/tests/test_clexer.py +208 -3
  242. data/vendor/pygments-main/tests/test_cmdline.py +6 -5
  243. data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
  244. data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
  245. data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
  246. data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
  247. data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
  248. data/vendor/pygments-main/tests/test_perllexer.py +1 -1
  249. data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
  250. data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
  251. data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
  252. data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
  253. data/vendor/pygments-main/tests/test_token.py +3 -3
  254. data/vendor/pygments-main/tests/test_using_api.py +1 -1
  255. data/vendor/pygments-main/tests/test_util.py +1 -1
  256. metadata +138 -51
  257. data/vendor/pygments-main/docs/generate.py +0 -472
  258. data/vendor/pygments-main/docs/src/api.txt +0 -270
  259. data/vendor/pygments-main/docs/src/authors.txt +0 -5
  260. data/vendor/pygments-main/docs/src/changelog.txt +0 -5
  261. data/vendor/pygments-main/docs/src/index.txt +0 -69
  262. data/vendor/pygments-main/docs/src/installation.txt +0 -71
  263. data/vendor/pygments-main/external/rst-directive-old.py +0 -77
  264. data/vendor/pygments-main/scripts/reindent.py +0 -291
  265. data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
  266. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
  267. data/vendor/pygments-main/tests/old_run.py +0 -138
@@ -22,11 +22,11 @@
22
22
  .. _Pygments tip:
23
23
  http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev
24
24
 
25
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
25
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
26
26
  :license: BSD, see LICENSE for details.
27
27
  """
28
28
 
29
- __version__ = '1.6'
29
+ __version__ = '2.0pre'
30
30
  __docformat__ = 'restructuredtext'
31
31
 
32
32
  __all__ = ['lex', 'format', 'highlight']
@@ -43,7 +43,7 @@ def lex(code, lexer):
43
43
  """
44
44
  try:
45
45
  return lexer.get_tokens(code)
46
- except TypeError, err:
46
+ except TypeError as err:
47
47
  if isinstance(err.args[0], str) and \
48
48
  'unbound method get_tokens' in err.args[0]:
49
49
  raise TypeError('lex() argument must be a lexer instance, '
@@ -67,7 +67,7 @@ def format(tokens, formatter, outfile=None):
67
67
  return realoutfile.getvalue()
68
68
  else:
69
69
  formatter.format(tokens, outfile)
70
- except TypeError, err:
70
+ except TypeError as err:
71
71
  if isinstance(err.args[0], str) and \
72
72
  'unbound method format' in err.args[0]:
73
73
  raise TypeError('format() argument must be a formatter instance, '
@@ -5,9 +5,12 @@
5
5
 
6
6
  Command line interface.
7
7
 
8
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
+
12
+ from __future__ import print_function
13
+
11
14
  import sys
12
15
  import getopt
13
16
  from textwrap import dedent
@@ -16,6 +19,7 @@ from pygments import __version__, highlight
16
19
  from pygments.util import ClassNotFound, OptionError, docstring_headline
17
20
  from pygments.lexers import get_all_lexers, get_lexer_by_name, get_lexer_for_filename, \
18
21
  find_lexer_class, guess_lexer, TextLexer
22
+ from pygments.formatters.latex import LatexEmbeddedLexer, LatexFormatter
19
23
  from pygments.formatters import get_all_formatters, get_formatter_by_name, \
20
24
  get_formatter_for_filename, find_formatter_class, \
21
25
  TerminalFormatter # pylint:disable-msg=E0611
@@ -92,7 +96,7 @@ def _parse_options(o_strs):
92
96
  for o_arg in o_args:
93
97
  o_arg = o_arg.strip()
94
98
  try:
95
- o_key, o_val = o_arg.split('=')
99
+ o_key, o_val = o_arg.split('=', 1)
96
100
  o_key = o_key.strip()
97
101
  o_val = o_val.strip()
98
102
  except ValueError:
@@ -119,25 +123,25 @@ def _print_help(what, name):
119
123
  try:
120
124
  if what == 'lexer':
121
125
  cls = find_lexer_class(name)
122
- print "Help on the %s lexer:" % cls.name
123
- print dedent(cls.__doc__)
126
+ print("Help on the %s lexer:" % cls.name)
127
+ print(dedent(cls.__doc__))
124
128
  elif what == 'formatter':
125
129
  cls = find_formatter_class(name)
126
- print "Help on the %s formatter:" % cls.name
127
- print dedent(cls.__doc__)
130
+ print("Help on the %s formatter:" % cls.name)
131
+ print(dedent(cls.__doc__))
128
132
  elif what == 'filter':
129
133
  cls = find_filter_class(name)
130
- print "Help on the %s filter:" % name
131
- print dedent(cls.__doc__)
134
+ print("Help on the %s filter:" % name)
135
+ print(dedent(cls.__doc__))
132
136
  except AttributeError:
133
- print >>sys.stderr, "%s not found!" % what
137
+ print("%s not found!" % what, file=sys.stderr)
134
138
 
135
139
 
136
140
  def _print_list(what):
137
141
  if what == 'lexer':
138
- print
139
- print "Lexers:"
140
- print "~~~~~~~"
142
+ print()
143
+ print("Lexers:")
144
+ print("~~~~~~~")
141
145
 
142
146
  info = []
143
147
  for fullname, names, exts, _ in get_all_lexers():
@@ -146,12 +150,12 @@ def _print_list(what):
146
150
  info.append(tup)
147
151
  info.sort()
148
152
  for i in info:
149
- print ('* %s\n %s %s') % i
153
+ print(('* %s\n %s %s') % i)
150
154
 
151
155
  elif what == 'formatter':
152
- print
153
- print "Formatters:"
154
- print "~~~~~~~~~~~"
156
+ print()
157
+ print("Formatters:")
158
+ print("~~~~~~~~~~~")
155
159
 
156
160
  info = []
157
161
  for cls in get_all_formatters():
@@ -161,27 +165,27 @@ def _print_list(what):
161
165
  info.append(tup)
162
166
  info.sort()
163
167
  for i in info:
164
- print ('* %s\n %s %s') % i
168
+ print(('* %s\n %s %s') % i)
165
169
 
166
170
  elif what == 'filter':
167
- print
168
- print "Filters:"
169
- print "~~~~~~~~"
171
+ print()
172
+ print("Filters:")
173
+ print("~~~~~~~~")
170
174
 
171
175
  for name in get_all_filters():
172
176
  cls = find_filter_class(name)
173
- print "* " + name + ':'
174
- print " %s" % docstring_headline(cls)
177
+ print("* " + name + ':')
178
+ print(" %s" % docstring_headline(cls))
175
179
 
176
180
  elif what == 'style':
177
- print
178
- print "Styles:"
179
- print "~~~~~~~"
181
+ print()
182
+ print("Styles:")
183
+ print("~~~~~~~")
180
184
 
181
185
  for name in get_all_styles():
182
186
  cls = get_style_by_name(name)
183
- print "* " + name + ':'
184
- print " %s" % docstring_headline(cls)
187
+ print("* " + name + ':')
188
+ print(" %s" % docstring_headline(cls))
185
189
 
186
190
 
187
191
  def main(args=sys.argv):
@@ -202,8 +206,8 @@ def main(args=sys.argv):
202
206
 
203
207
  try:
204
208
  popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:hVHg")
205
- except getopt.GetoptError, err:
206
- print >>sys.stderr, usage
209
+ except getopt.GetoptError:
210
+ print(usage, file=sys.stderr)
207
211
  return 2
208
212
  opts = {}
209
213
  O_opts = []
@@ -219,22 +223,22 @@ def main(args=sys.argv):
219
223
  opts[opt] = arg
220
224
 
221
225
  if not opts and not args:
222
- print usage
226
+ print(usage)
223
227
  return 0
224
228
 
225
229
  if opts.pop('-h', None) is not None:
226
- print usage
230
+ print(usage)
227
231
  return 0
228
232
 
229
233
  if opts.pop('-V', None) is not None:
230
- print 'Pygments version %s, (c) 2006-2013 by Georg Brandl.' % __version__
234
+ print('Pygments version %s, (c) 2006-2014 by Georg Brandl.' % __version__)
231
235
  return 0
232
236
 
233
237
  # handle ``pygmentize -L``
234
238
  L_opt = opts.pop('-L', None)
235
239
  if L_opt is not None:
236
240
  if opts:
237
- print >>sys.stderr, usage
241
+ print(usage, file=sys.stderr)
238
242
  return 2
239
243
 
240
244
  # print version
@@ -249,12 +253,12 @@ def main(args=sys.argv):
249
253
  H_opt = opts.pop('-H', None)
250
254
  if H_opt is not None:
251
255
  if opts or len(args) != 2:
252
- print >>sys.stderr, usage
256
+ print(usage, file=sys.stderr)
253
257
  return 2
254
258
 
255
259
  what, name = args
256
260
  if what not in ('lexer', 'formatter', 'filter'):
257
- print >>sys.stderr, usage
261
+ print(usage, file=sys.stderr)
258
262
  return 2
259
263
 
260
264
  _print_help(what, name)
@@ -279,13 +283,13 @@ def main(args=sys.argv):
279
283
  if infn is not None:
280
284
  try:
281
285
  lexer = get_lexer_for_filename(infn, **parsed_opts)
282
- except ClassNotFound, err:
286
+ except ClassNotFound as err:
283
287
  lexer = TextLexer()
284
- except OptionError, err:
285
- print >>sys.stderr, 'Error:', err
288
+ except OptionError as err:
289
+ print('Error:', err, file=sys.stderr)
286
290
  return 1
287
291
 
288
- print lexer.aliases[0]
292
+ print(lexer.aliases[0])
289
293
  return 0
290
294
 
291
295
  # handle ``pygmentize -S``
@@ -294,30 +298,30 @@ def main(args=sys.argv):
294
298
  if S_opt is not None:
295
299
  f_opt = opts.pop('-f', None)
296
300
  if not f_opt:
297
- print >>sys.stderr, usage
301
+ print(usage, file=sys.stderr)
298
302
  return 2
299
303
  if opts or args:
300
- print >>sys.stderr, usage
304
+ print(usage, file=sys.stderr)
301
305
  return 2
302
306
 
303
307
  try:
304
308
  parsed_opts['style'] = S_opt
305
309
  fmter = get_formatter_by_name(f_opt, **parsed_opts)
306
- except ClassNotFound, err:
307
- print >>sys.stderr, err
310
+ except ClassNotFound as err:
311
+ print(err, file=sys.stderr)
308
312
  return 1
309
313
 
310
314
  arg = a_opt or ''
311
315
  try:
312
- print fmter.get_style_defs(arg)
313
- except Exception, err:
314
- print >>sys.stderr, 'Error:', err
316
+ print(fmter.get_style_defs(arg))
317
+ except Exception as err:
318
+ print('Error:', err, file=sys.stderr)
315
319
  return 1
316
320
  return 0
317
321
 
318
322
  # if no -S is given, -a is not allowed
319
323
  if a_opt is not None:
320
- print >>sys.stderr, usage
324
+ print(usage, file=sys.stderr)
321
325
  return 2
322
326
 
323
327
  # parse -F options
@@ -330,21 +334,21 @@ def main(args=sys.argv):
330
334
  if fmter:
331
335
  try:
332
336
  fmter = get_formatter_by_name(fmter, **parsed_opts)
333
- except (OptionError, ClassNotFound), err:
334
- print >>sys.stderr, 'Error:', err
337
+ except (OptionError, ClassNotFound) as err:
338
+ print('Error:', err, file=sys.stderr)
335
339
  return 1
336
340
 
337
341
  if outfn:
338
342
  if not fmter:
339
343
  try:
340
344
  fmter = get_formatter_for_filename(outfn, **parsed_opts)
341
- except (OptionError, ClassNotFound), err:
342
- print >>sys.stderr, 'Error:', err
345
+ except (OptionError, ClassNotFound) as err:
346
+ print('Error:', err, file=sys.stderr)
343
347
  return 1
344
348
  try:
345
349
  outfile = open(outfn, 'wb')
346
- except Exception, err:
347
- print >>sys.stderr, 'Error: cannot open outfile:', err
350
+ except Exception as err:
351
+ print('Error: cannot open outfile:', err, file=sys.stderr)
348
352
  return 1
349
353
  else:
350
354
  if not fmter:
@@ -356,36 +360,36 @@ def main(args=sys.argv):
356
360
  if lexer:
357
361
  try:
358
362
  lexer = get_lexer_by_name(lexer, **parsed_opts)
359
- except (OptionError, ClassNotFound), err:
360
- print >>sys.stderr, 'Error:', err
363
+ except (OptionError, ClassNotFound) as err:
364
+ print('Error:', err, file=sys.stderr)
361
365
  return 1
362
366
 
363
367
  if args:
364
368
  if len(args) > 1:
365
- print >>sys.stderr, usage
369
+ print(usage, file=sys.stderr)
366
370
  return 2
367
371
 
368
372
  infn = args[0]
369
373
  try:
370
374
  code = open(infn, 'rb').read()
371
- except Exception, err:
372
- print >>sys.stderr, 'Error: cannot read infile:', err
375
+ except Exception as err:
376
+ print('Error: cannot read infile:', err, file=sys.stderr)
373
377
  return 1
374
378
 
375
379
  if not lexer:
376
380
  try:
377
381
  lexer = get_lexer_for_filename(infn, code, **parsed_opts)
378
- except ClassNotFound, err:
382
+ except ClassNotFound as err:
379
383
  if '-g' in opts:
380
384
  try:
381
385
  lexer = guess_lexer(code, **parsed_opts)
382
386
  except ClassNotFound:
383
387
  lexer = TextLexer(**parsed_opts)
384
388
  else:
385
- print >>sys.stderr, 'Error:', err
389
+ print('Error:', err, file=sys.stderr)
386
390
  return 1
387
- except OptionError, err:
388
- print >>sys.stderr, 'Error:', err
391
+ except OptionError as err:
392
+ print('Error:', err, file=sys.stderr)
389
393
  return 1
390
394
 
391
395
  else:
@@ -396,12 +400,21 @@ def main(args=sys.argv):
396
400
  except ClassNotFound:
397
401
  lexer = TextLexer(**parsed_opts)
398
402
  elif not lexer:
399
- print >>sys.stderr, 'Error: no lexer name given and reading ' + \
400
- 'from stdin (try using -g or -l <lexer>)'
403
+ print('Error: no lexer name given and reading ' + \
404
+ 'from stdin (try using -g or -l <lexer>)', file=sys.stderr)
401
405
  return 2
402
406
  else:
403
407
  code = sys.stdin.read()
404
408
 
409
+ # When using the LaTeX formatter and the option `escapeinside` is
410
+ # specified, we need a special lexer which collects escaped text
411
+ # before running the chosen language lexer.
412
+ escapeinside = parsed_opts.get('escapeinside', '')
413
+ if len(escapeinside) == 2 and isinstance(fmter, LatexFormatter):
414
+ left = escapeinside[0]
415
+ right = escapeinside[1]
416
+ lexer = LatexEmbeddedLexer(left, right, lexer)
417
+
405
418
  # No encoding given? Use latin1 if output file given,
406
419
  # stdin/stdout encoding otherwise.
407
420
  # (This is a compromise, I'm not too happy with it...)
@@ -426,16 +439,16 @@ def main(args=sys.argv):
426
439
  for fname, fopts in F_opts:
427
440
  lexer.add_filter(fname, **fopts)
428
441
  highlight(code, lexer, fmter, outfile)
429
- except Exception, err:
442
+ except Exception:
430
443
  import traceback
431
444
  info = traceback.format_exception(*sys.exc_info())
432
445
  msg = info[-1].strip()
433
446
  if len(info) >= 3:
434
447
  # extract relevant file and position info
435
448
  msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
436
- print >>sys.stderr
437
- print >>sys.stderr, '*** Error while highlighting:'
438
- print >>sys.stderr, msg
449
+ print(file=sys.stderr)
450
+ print('*** Error while highlighting:', file=sys.stderr)
451
+ print(msg, file=sys.stderr)
439
452
  return 1
440
453
 
441
454
  return 0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Format colored console output.
7
7
 
8
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Module that implements the default filter.
7
7
 
8
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9
9
  :license: BSD, see LICENSE for details.
10
10
  """
11
11
 
@@ -6,7 +6,7 @@
6
6
  Module containing filter lookup functions and default
7
7
  filters.
8
8
 
9
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
9
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
10
10
  :license: BSD, see LICENSE for details.
11
11
  """
12
12
 
@@ -16,7 +16,7 @@ from pygments.token import String, Comment, Keyword, Name, Error, Whitespace, \
16
16
  string_to_tokentype
17
17
  from pygments.filter import Filter
18
18
  from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \
19
- get_choice_opt, ClassNotFound, OptionError
19
+ get_choice_opt, ClassNotFound, OptionError, text_type, string_types
20
20
  from pygments.plugin import find_plugin_filters
21
21
 
22
22
 
@@ -117,7 +117,7 @@ class KeywordCaseFilter(Filter):
117
117
  def __init__(self, **options):
118
118
  Filter.__init__(self, **options)
119
119
  case = get_choice_opt(options, 'case', ['lower', 'upper', 'capitalize'], 'lower')
120
- self.convert = getattr(unicode, case)
120
+ self.convert = getattr(text_type, case)
121
121
 
122
122
  def filter(self, lexer, stream):
123
123
  for ttype, value in stream:
@@ -182,7 +182,7 @@ class RaiseOnErrorTokenFilter(Filter):
182
182
  The exception class to raise.
183
183
  The default is `pygments.filters.ErrorToken`.
184
184
 
185
- *New in Pygments 0.8.*
185
+ .. versionadded:: 0.8
186
186
  """
187
187
 
188
188
  def __init__(self, **options):
@@ -230,14 +230,16 @@ class VisibleWhitespaceFilter(Filter):
230
230
  styling the visible whitespace differently (e.g. greyed out), but it can
231
231
  disrupt background colors. The default is ``True``.
232
232
 
233
- *New in Pygments 0.8.*
233
+ .. versionadded:: 0.8
234
234
  """
235
235
 
236
236
  def __init__(self, **options):
237
237
  Filter.__init__(self, **options)
238
- for name, default in {'spaces': u'·', 'tabs': u'»', 'newlines': u'¶'}.items():
238
+ for name, default in [('spaces', u'·'),
239
+ ('tabs', u'»'),
240
+ ('newlines', u'¶')]:
239
241
  opt = options.get(name, False)
240
- if isinstance(opt, basestring) and len(opt) == 1:
242
+ if isinstance(opt, string_types) and len(opt) == 1:
241
243
  setattr(self, name, opt)
242
244
  else:
243
245
  setattr(self, name, (opt and default or ''))
@@ -293,7 +295,7 @@ class GobbleFilter(Filter):
293
295
  `n` : int
294
296
  The number of characters to gobble.
295
297
 
296
- *New in Pygments 1.2.*
298
+ .. versionadded:: 1.2
297
299
  """
298
300
  def __init__(self, **options):
299
301
  Filter.__init__(self, **options)
@@ -325,7 +327,7 @@ class TokenMergeFilter(Filter):
325
327
  Merges consecutive tokens with the same token type in the output stream of a
326
328
  lexer.
327
329
 
328
- *New in Pygments 1.2.*
330
+ .. versionadded:: 1.2
329
331
  """
330
332
  def __init__(self, **options):
331
333
  Filter.__init__(self, **options)