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
@@ -5,20 +5,20 @@
5
5
 
6
6
  Base formatter class.
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
 
12
12
  import codecs
13
13
 
14
- from pygments.util import get_bool_opt
14
+ from pygments.util import get_bool_opt, string_types
15
15
  from pygments.styles import get_style_by_name
16
16
 
17
17
  __all__ = ['Formatter']
18
18
 
19
19
 
20
20
  def _lookup_style(style):
21
- if isinstance(style, basestring):
21
+ if isinstance(style, string_types):
22
22
  return get_style_by_name(style)
23
23
  return style
24
24
 
@@ -5,11 +5,12 @@
5
5
 
6
6
  Pygments formatters.
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
  import os.path
12
12
  import fnmatch
13
+ import re
13
14
 
14
15
  from pygments.formatters._mapping import FORMATTERS
15
16
  from pygments.plugin import find_plugin_formatters
@@ -34,7 +35,8 @@ def _init_formatter_cache():
34
35
  for alias in cls.aliases:
35
36
  _formatter_alias_cache[alias] = cls
36
37
  for fn in cls.filenames:
37
- _formatter_filename_cache.append((fn, cls))
38
+ _formatter_filename_cache.append((
39
+ re.compile(fnmatch.translate(fn)), cls))
38
40
 
39
41
 
40
42
  def find_formatter_class(name):
@@ -55,7 +57,7 @@ def get_formatter_for_filename(fn, **options):
55
57
  _init_formatter_cache()
56
58
  fn = os.path.basename(fn)
57
59
  for pattern, cls in _formatter_filename_cache:
58
- if fnmatch.fnmatch(fn, pattern):
60
+ if pattern.match(fn):
59
61
  return cls(**options)
60
62
  raise ClassNotFound("No formatter found for file name %r" % fn)
61
63
 
@@ -3,16 +3,25 @@
3
3
  pygments.formatters._mapping
4
4
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
 
6
- Formatter mapping defintions. This file is generated by itself. Everytime
7
- you change something on a builtin formatter defintion, run this script from
6
+ Formatter mapping definitions. This file is generated by itself. Everytime
7
+ you change something on a builtin formatter definition, run this script from
8
8
  the formatters folder to update it.
9
9
 
10
10
  Do not alter the FORMATTERS dictionary by hand.
11
11
 
12
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
12
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
13
13
  :license: BSD, see LICENSE for details.
14
14
  """
15
15
 
16
+ from __future__ import print_function
17
+ try:
18
+ import pygments
19
+ except ImportError:
20
+ # This block makes this mapping work like the lexer one -- not requiring
21
+ # that Pygments already be on your PYTHONPATH.
22
+ import os.path, sys
23
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
24
+
16
25
  # start
17
26
  from pygments.formatters.bbcode import BBCodeFormatter
18
27
  from pygments.formatters.html import HtmlFormatter
@@ -23,6 +32,7 @@ from pygments.formatters.img import JpgImageFormatter
23
32
  from pygments.formatters.latex import LatexFormatter
24
33
  from pygments.formatters.other import NullFormatter
25
34
  from pygments.formatters.other import RawTokenFormatter
35
+ from pygments.formatters.other import TestcaseFormatter
26
36
  from pygments.formatters.rtf import RtfFormatter
27
37
  from pygments.formatters.svg import SvgFormatter
28
38
  from pygments.formatters.terminal import TerminalFormatter
@@ -41,7 +51,8 @@ FORMATTERS = {
41
51
  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.'),
42
52
  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.'),
43
53
  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.'),
44
- 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.')
54
+ 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.'),
55
+ TestcaseFormatter: ('Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
45
56
  }
46
57
 
47
58
  if __name__ == '__main__':
@@ -57,7 +68,7 @@ if __name__ == '__main__':
57
68
  for filename in os.listdir('.'):
58
69
  if filename.endswith('.py') and not filename.startswith('_'):
59
70
  module_name = 'pygments.formatters.%s' % filename[:-3]
60
- print module_name
71
+ print(module_name)
61
72
  module = __import__(module_name, None, None, [''])
62
73
  for formatter_name in module.__all__:
63
74
  imports.append((module_name, formatter_name))
@@ -5,7 +5,7 @@
5
5
 
6
6
  BBcode formatter.
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,18 +5,20 @@
5
5
 
6
6
  Formatter for HTML 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
 
12
+ from __future__ import print_function
13
+
12
14
  import os
13
15
  import sys
14
16
  import os.path
15
- import StringIO
16
17
 
17
18
  from pygments.formatter import Formatter
18
19
  from pygments.token import Token, Text, STANDARD_TYPES
19
- from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
20
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
21
+ StringIO, string_types, iteritems
20
22
 
21
23
  try:
22
24
  import ctags
@@ -218,29 +220,34 @@ class HtmlFormatter(Formatter):
218
220
  If you set this option, the default selector for `get_style_defs()`
219
221
  will be this class.
220
222
 
221
- *New in Pygments 0.9:* If you select the ``'table'`` line numbers, the
222
- wrapping table will have a CSS class of this string plus ``'table'``,
223
- the default is accordingly ``'highlighttable'``.
223
+ .. versionadded:: 0.9
224
+ If you select the ``'table'`` line numbers, the wrapping table will
225
+ have a CSS class of this string plus ``'table'``, the default is
226
+ accordingly ``'highlighttable'``.
224
227
 
225
228
  `cssstyles`
226
229
  Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
227
230
 
228
231
  `prestyles`
229
- Inline CSS styles for the ``<pre>`` tag (default: ``''``). *New in
230
- Pygments 0.11.*
232
+ Inline CSS styles for the ``<pre>`` tag (default: ``''``).
233
+
234
+ .. versionadded:: 0.11
231
235
 
232
236
  `cssfile`
233
237
  If the `full` option is true and this option is given, it must be the
234
238
  name of an external file. If the filename does not include an absolute
235
239
  path, the file's path will be assumed to be relative to the main output
236
240
  file's path, if the latter can be found. The stylesheet is then written
237
- to this file instead of the HTML file. *New in Pygments 0.6.*
241
+ to this file instead of the HTML file.
242
+
243
+ .. versionadded:: 0.6
238
244
 
239
245
  `noclobber_cssfile`
240
246
  If `cssfile` is given and the specified file exists, the css file will
241
247
  not be overwritten. This allows the use of the `full` option in
242
248
  combination with a user specified css file. Default is ``False``.
243
- *New in Pygments 1.1.*
249
+
250
+ .. versionadded:: 1.1
244
251
 
245
252
  `linenos`
246
253
  If set to ``'table'``, output line numbers as a table with two cells,
@@ -263,7 +270,9 @@ class HtmlFormatter(Formatter):
263
270
  125%``).
264
271
 
265
272
  `hl_lines`
266
- Specify a list of lines to be highlighted. *New in Pygments 0.11.*
273
+ Specify a list of lines to be highlighted.
274
+
275
+ .. versionadded:: 0.11
267
276
 
268
277
  `linenostart`
269
278
  The line number for the first line (default: ``1``).
@@ -279,24 +288,30 @@ class HtmlFormatter(Formatter):
279
288
  If set to ``True``, the formatter won't output the background color
280
289
  for the wrapping element (this automatically defaults to ``False``
281
290
  when there is no wrapping element [eg: no argument for the
282
- `get_syntax_defs` method given]) (default: ``False``). *New in
283
- Pygments 0.6.*
291
+ `get_syntax_defs` method given]) (default: ``False``).
292
+
293
+ .. versionadded:: 0.6
284
294
 
285
295
  `lineseparator`
286
296
  This string is output between lines of code. It defaults to ``"\n"``,
287
297
  which is enough to break a line inside ``<pre>`` tags, but you can
288
- e.g. set it to ``"<br>"`` to get HTML line breaks. *New in Pygments
289
- 0.7.*
298
+ e.g. set it to ``"<br>"`` to get HTML line breaks.
299
+
300
+ .. versionadded:: 0.7
290
301
 
291
302
  `lineanchors`
292
303
  If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
293
304
  output line in an anchor tag with a ``name`` of ``foo-linenumber``.
294
- This allows easy linking to certain lines. *New in Pygments 0.9.*
305
+ This allows easy linking to certain lines.
306
+
307
+ .. versionadded:: 0.9
295
308
 
296
309
  `linespans`
297
310
  If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
298
311
  output line in a span tag with an ``id`` of ``foo-linenumber``.
299
- This allows easy access to lines via javascript. *New in Pygments 1.6.*
312
+ This allows easy access to lines via javascript.
313
+
314
+ .. versionadded:: 1.6
300
315
 
301
316
  `anchorlinenos`
302
317
  If set to `True`, will wrap line numbers in <a> tags. Used in
@@ -306,18 +321,20 @@ class HtmlFormatter(Formatter):
306
321
  If set to the path of a ctags file, wrap names in anchor tags that
307
322
  link to their definitions. `lineanchors` should be used, and the
308
323
  tags file should specify line numbers (see the `-n` option to ctags).
309
- *New in Pygments 1.6.*
324
+
325
+ .. versionadded:: 1.6
310
326
 
311
327
  `tagurlformat`
312
328
  A string formatting pattern used to generate links to ctags definitions.
313
329
  Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
314
330
  Defaults to an empty string, resulting in just `#prefix-number` links.
315
- *New in Pygments 1.6.*
331
+
332
+ .. versionadded:: 1.6
316
333
 
317
334
 
318
335
  **Subclassing the HTML formatter**
319
336
 
320
- *New in Pygments 0.7.*
337
+ .. versionadded:: 0.7
321
338
 
322
339
  The HTML formatter is now built in a way that allows easy subclassing, thus
323
340
  customizing the output HTML code. The `format()` method calls
@@ -453,7 +470,7 @@ class HtmlFormatter(Formatter):
453
470
  """
454
471
  if arg is None:
455
472
  arg = ('cssclass' in self.options and '.'+self.cssclass or '')
456
- if isinstance(arg, basestring):
473
+ if isinstance(arg, string_types):
457
474
  args = [arg]
458
475
  else:
459
476
  args = list(arg)
@@ -467,7 +484,7 @@ class HtmlFormatter(Formatter):
467
484
  return ', '.join(tmp)
468
485
 
469
486
  styles = [(level, ttype, cls, style)
470
- for cls, (style, ttype, level) in self.class2style.iteritems()
487
+ for cls, (style, ttype, level) in iteritems(self.class2style)
471
488
  if cls and style]
472
489
  styles.sort()
473
490
  lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
@@ -505,8 +522,9 @@ class HtmlFormatter(Formatter):
505
522
  cssfilename = os.path.join(os.path.dirname(filename),
506
523
  self.cssfile)
507
524
  except AttributeError:
508
- print >>sys.stderr, 'Note: Cannot determine output file name, ' \
509
- 'using current directory as base for the CSS file name'
525
+ print('Note: Cannot determine output file name, ' \
526
+ 'using current directory as base for the CSS file name',
527
+ file=sys.stderr)
510
528
  cssfilename = self.cssfile
511
529
  # write CSS file only if noclobber_cssfile isn't given as an option.
512
530
  try:
@@ -515,7 +533,7 @@ class HtmlFormatter(Formatter):
515
533
  cf.write(CSSFILE_TEMPLATE %
516
534
  {'styledefs': self.get_style_defs('body')})
517
535
  cf.close()
518
- except IOError, err:
536
+ except IOError as err:
519
537
  err.strerror = 'Error writing CSS file: ' + err.strerror
520
538
  raise
521
539
 
@@ -534,7 +552,7 @@ class HtmlFormatter(Formatter):
534
552
  yield 0, DOC_FOOTER
535
553
 
536
554
  def _wrap_tablelinenos(self, inner):
537
- dummyoutfile = StringIO.StringIO()
555
+ dummyoutfile = StringIO()
538
556
  lncount = 0
539
557
  for t, line in inner:
540
558
  if t:
@@ -5,15 +5,15 @@
5
5
 
6
6
  Formatter for Pixmap 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
 
12
12
  import sys
13
13
 
14
14
  from pygments.formatter import Formatter
15
- from pygments.util import get_bool_opt, get_int_opt, \
16
- get_list_opt, get_choice_opt
15
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
16
+ get_choice_opt, xrange
17
17
 
18
18
  # Import this carefully
19
19
  try:
@@ -25,7 +25,10 @@ except ImportError:
25
25
  try:
26
26
  import _winreg
27
27
  except ImportError:
28
- _winreg = None
28
+ try:
29
+ import winreg as _winreg
30
+ except ImportError:
31
+ _winreg = None
29
32
 
30
33
  __all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
31
34
  'BmpImageFormatter']
@@ -72,7 +75,10 @@ class FontManager(object):
72
75
  self._create_nix()
73
76
 
74
77
  def _get_nix_font_path(self, name, style):
75
- from commands import getstatusoutput
78
+ try:
79
+ from commands import getstatusoutput
80
+ except ImportError:
81
+ from subprocess import getstatusoutput
76
82
  exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
77
83
  (name, style))
78
84
  if not exit:
@@ -169,7 +175,7 @@ class ImageFormatter(Formatter):
169
175
  Create a PNG image from source code. This uses the Python Imaging Library to
170
176
  generate a pixmap from the source code.
171
177
 
172
- *New in Pygments 0.10.*
178
+ .. versionadded:: 0.10
173
179
 
174
180
  Additional options accepted:
175
181
 
@@ -258,12 +264,16 @@ class ImageFormatter(Formatter):
258
264
  Default: 6
259
265
 
260
266
  `hl_lines`
261
- Specify a list of lines to be highlighted. *New in Pygments 1.2.*
267
+ Specify a list of lines to be highlighted.
268
+
269
+ .. versionadded:: 1.2
262
270
 
263
271
  Default: empty list
264
272
 
265
273
  `hl_color`
266
- Specify the color for highlighting lines. *New in Pygments 1.2.*
274
+ Specify the color for highlighting lines.
275
+
276
+ .. versionadded:: 1.2
267
277
 
268
278
  Default: highlight color of the selected style
269
279
  """
@@ -513,8 +523,7 @@ class GifImageFormatter(ImageFormatter):
513
523
  Create a GIF image from source code. This uses the Python Imaging Library to
514
524
  generate a pixmap from the source code.
515
525
 
516
- *New in Pygments 1.0.* (You could create GIF images before by passing a
517
- suitable `image_format` option to the `ImageFormatter`.)
526
+ .. versionadded:: 1.0
518
527
  """
519
528
 
520
529
  name = 'img_gif'
@@ -528,8 +537,7 @@ class JpgImageFormatter(ImageFormatter):
528
537
  Create a JPEG image from source code. This uses the Python Imaging Library to
529
538
  generate a pixmap from the source code.
530
539
 
531
- *New in Pygments 1.0.* (You could create JPEG images before by passing a
532
- suitable `image_format` option to the `ImageFormatter`.)
540
+ .. versionadded:: 1.0
533
541
  """
534
542
 
535
543
  name = 'img_jpg'
@@ -543,8 +551,7 @@ class BmpImageFormatter(ImageFormatter):
543
551
  Create a bitmap image from source code. This uses the Python Imaging Library to
544
552
  generate a pixmap from the source code.
545
553
 
546
- *New in Pygments 1.0.* (You could create bitmap images before by passing a
547
- suitable `image_format` option to the `ImageFormatter`.)
554
+ .. versionadded:: 1.0
548
555
  """
549
556
 
550
557
  name = 'img_bmp'
@@ -5,13 +5,17 @@
5
5
 
6
6
  Formatter for LaTeX fancyvrb 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
 
12
+ from __future__ import division
13
+
12
14
  from pygments.formatter import Formatter
15
+ from pygments.lexer import Lexer
13
16
  from pygments.token import Token, STANDARD_TYPES
14
- from pygments.util import get_bool_opt, get_int_opt, StringIO
17
+ from pygments.util import get_bool_opt, get_int_opt, StringIO, xrange, \
18
+ iteritems
15
19
 
16
20
 
17
21
  __all__ = ['LatexFormatter']
@@ -152,7 +156,7 @@ class LatexFormatter(Formatter):
152
156
 
153
157
  .. sourcecode:: latex
154
158
 
155
- \begin{Verbatim}[commandchars=\\{\}]
159
+ \begin{Verbatim}[commandchars=\\\{\}]
156
160
  \PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
157
161
  \PY{k}{pass}
158
162
  \end{Verbatim}
@@ -205,19 +209,33 @@ class LatexFormatter(Formatter):
205
209
  `commandprefix`
206
210
  The LaTeX commands used to produce colored output are constructed
207
211
  using this prefix and some letters (default: ``'PY'``).
208
- *New in Pygments 0.7.*
209
212
 
210
- *New in Pygments 0.10:* the default is now ``'PY'`` instead of ``'C'``.
213
+ .. versionadded:: 0.7
214
+ .. versionchanged:: 0.10
215
+ The default is now ``'PY'`` instead of ``'C'``.
211
216
 
212
217
  `texcomments`
213
218
  If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
214
219
  in comment tokens is not escaped so that LaTeX can render it (default:
215
- ``False``). *New in Pygments 1.2.*
220
+ ``False``).
221
+
222
+ .. versionadded:: 1.2
216
223
 
217
224
  `mathescape`
218
225
  If set to ``True``, enables LaTeX math mode escape in comments. That
219
226
  is, ``'$...$'`` inside a comment will trigger math mode (default:
220
- ``False``). *New in Pygments 1.2.*
227
+ ``False``).
228
+
229
+ .. versionadded:: 1.2
230
+
231
+ `escapeinside`
232
+ If set to a string of length 2, enables escaping to LaTeX. Text
233
+ delimited by these 2 characters is read as LaTeX code and
234
+ typeset accordingly. It has no effect in string literals. It has
235
+ no effect in comments if `texcomments` or `mathescape` is
236
+ set. (default: ``''``).
237
+
238
+ .. versionadded:: 2.0
221
239
  """
222
240
  name = 'LaTeX'
223
241
  aliases = ['latex', 'tex']
@@ -235,6 +253,13 @@ class LatexFormatter(Formatter):
235
253
  self.commandprefix = options.get('commandprefix', 'PY')
236
254
  self.texcomments = get_bool_opt(options, 'texcomments', False)
237
255
  self.mathescape = get_bool_opt(options, 'mathescape', False)
256
+ self.escapeinside = options.get('escapeinside', '')
257
+
258
+ if len(self.escapeinside) == 2:
259
+ self.left = self.escapeinside[0]
260
+ self.right = self.escapeinside[1]
261
+ else:
262
+ self.escapeinside = ''
238
263
 
239
264
  self._create_stylesheet()
240
265
 
@@ -291,7 +316,7 @@ class LatexFormatter(Formatter):
291
316
  """
292
317
  cp = self.commandprefix
293
318
  styles = []
294
- for name, definition in self.cmd2def.iteritems():
319
+ for name, definition in iteritems(self.cmd2def):
295
320
  styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
296
321
  (cp, name, definition))
297
322
  return STYLE_TEMPLATE % {'cp': self.commandprefix,
@@ -306,14 +331,14 @@ class LatexFormatter(Formatter):
306
331
  realoutfile = outfile
307
332
  outfile = StringIO()
308
333
 
309
- outfile.write(ur'\begin{Verbatim}[commandchars=\\\{\}')
334
+ outfile.write(u'\\begin{Verbatim}[commandchars=\\\\\\{\\}')
310
335
  if self.linenos:
311
336
  start, step = self.linenostart, self.linenostep
312
337
  outfile.write(u',numbers=left' +
313
338
  (start and u',firstnumber=%d' % start or u'') +
314
339
  (step and u',stepnumber=%d' % step or u''))
315
- if self.mathescape or self.texcomments:
316
- outfile.write(ur',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
340
+ if self.mathescape or self.texcomments or self.escapeinside:
341
+ outfile.write(u',codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}')
317
342
  if self.verboptions:
318
343
  outfile.write(u',' + self.verboptions)
319
344
  outfile.write(u']\n')
@@ -342,9 +367,22 @@ class LatexFormatter(Formatter):
342
367
  parts[i] = escape_tex(part, self.commandprefix)
343
368
  in_math = not in_math
344
369
  value = '$'.join(parts)
370
+ elif self.escapeinside:
371
+ text = value
372
+ value = ''
373
+ while len(text) > 0:
374
+ a,sep1,text = text.partition(self.left)
375
+ if len(sep1) > 0:
376
+ b,sep2,text = text.partition(self.right)
377
+ if len(sep2) > 0:
378
+ value += escape_tex(a, self.commandprefix) + b
379
+ else:
380
+ value += escape_tex(a + sep1 + b, self.commandprefix)
381
+ else:
382
+ value = value + escape_tex(a, self.commandprefix)
345
383
  else:
346
384
  value = escape_tex(value, self.commandprefix)
347
- else:
385
+ elif ttype not in Token.Escape:
348
386
  value = escape_tex(value, self.commandprefix)
349
387
  styles = []
350
388
  while ttype is not Token:
@@ -376,3 +414,57 @@ class LatexFormatter(Formatter):
376
414
  encoding = self.encoding or 'latin1',
377
415
  styledefs = self.get_style_defs(),
378
416
  code = outfile.getvalue()))
417
+
418
+
419
+ class LatexEmbeddedLexer(Lexer):
420
+ r"""
421
+
422
+ This lexer takes one lexer as argument, the lexer for the language
423
+ being formatted, and the left and right delimiters for escaped text.
424
+
425
+ First everything is scanned using the language lexer to obtain
426
+ strings and comments. All other consecutive tokens are merged and
427
+ the resulting text is scanned for escaped segments, which are given
428
+ the Token.Escape type. Finally text that is not escaped is scanned
429
+ again with the language lexer.
430
+ """
431
+ def __init__(self, left, right, lang, **options):
432
+ self.left = left
433
+ self.right = right
434
+ self.lang = lang
435
+ Lexer.__init__(self, **options)
436
+
437
+ def get_tokens_unprocessed(self, text):
438
+ buf = ''
439
+ for i, t, v in self.lang.get_tokens_unprocessed(text):
440
+ if t in Token.Comment or t in Token.String:
441
+ if buf:
442
+ for x in self.get_tokens_aux(idx, buf):
443
+ yield x
444
+ buf = ''
445
+ yield i, t, v
446
+ else:
447
+ if not buf:
448
+ idx = i
449
+ buf += v
450
+ if buf:
451
+ for x in self.get_tokens_aux(idx, buf):
452
+ yield x
453
+
454
+ def get_tokens_aux(self, index, text):
455
+ while text:
456
+ a, sep1, text = text.partition(self.left)
457
+ if a:
458
+ for i, t, v in self.lang.get_tokens_unprocessed(a):
459
+ yield index + i, t, v
460
+ index += len(a)
461
+ if sep1:
462
+ b, sep2, text = text.partition(self.right)
463
+ if sep2:
464
+ yield index + len(sep1), Token.Escape, b
465
+ index += len(sep1) + len(b) + len(sep2)
466
+ else:
467
+ yield index, Token.Error, sep1
468
+ index += len(sep1)
469
+ text = b
470
+