pygments.rb 2.0.0.rc3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +13 -1
  3. data/.gitignore +0 -1
  4. data/.rubocop.yml +16 -0
  5. data/CHANGELOG.adoc +19 -0
  6. data/README.adoc +1 -3
  7. data/Rakefile +0 -14
  8. data/bench.rb +11 -6
  9. data/lib/pygments/lexer.rb +84 -62
  10. data/lib/pygments/mentos.py +7 -49
  11. data/lib/pygments/popen.rb +133 -173
  12. data/lib/pygments/version.rb +1 -1
  13. data/lib/pygments.rb +15 -6
  14. data/pygments.rb.gemspec +16 -11
  15. data/test/test_pygments.rb +19 -40
  16. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/AUTHORS +13 -1
  17. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/INSTALLER +0 -0
  18. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/LICENSE +1 -1
  19. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/METADATA +8 -9
  20. data/vendor/pygments-main/Pygments-2.10.0.dist-info/RECORD +524 -0
  21. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/REQUESTED +0 -0
  22. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/WHEEL +0 -0
  23. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/entry_points.txt +0 -0
  24. data/vendor/pygments-main/{Pygments-2.7.3.dist-info → Pygments-2.10.0.dist-info}/top_level.txt +0 -0
  25. data/vendor/pygments-main/bin/pygmentize +1 -1
  26. data/vendor/pygments-main/pygments/__init__.py +2 -3
  27. data/vendor/pygments-main/pygments/__main__.py +1 -2
  28. data/vendor/pygments-main/pygments/cmdline.py +179 -159
  29. data/vendor/pygments-main/pygments/console.py +1 -2
  30. data/vendor/pygments-main/pygments/filter.py +1 -2
  31. data/vendor/pygments-main/pygments/filters/__init__.py +1 -2
  32. data/vendor/pygments-main/pygments/formatter.py +1 -2
  33. data/vendor/pygments-main/pygments/formatters/__init__.py +2 -3
  34. data/vendor/pygments-main/pygments/formatters/_mapping.py +2 -2
  35. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -2
  36. data/vendor/pygments-main/pygments/formatters/html.py +53 -25
  37. data/vendor/pygments-main/pygments/formatters/img.py +24 -10
  38. data/vendor/pygments-main/pygments/formatters/irc.py +1 -2
  39. data/vendor/pygments-main/pygments/formatters/latex.py +8 -9
  40. data/vendor/pygments-main/pygments/formatters/other.py +7 -10
  41. data/vendor/pygments-main/pygments/formatters/pangomarkup.py +83 -0
  42. data/vendor/pygments-main/pygments/formatters/rtf.py +1 -2
  43. data/vendor/pygments-main/pygments/formatters/svg.py +5 -4
  44. data/vendor/pygments-main/pygments/formatters/terminal.py +1 -2
  45. data/vendor/pygments-main/pygments/formatters/terminal256.py +24 -3
  46. data/vendor/pygments-main/pygments/lexer.py +7 -6
  47. data/vendor/pygments-main/pygments/lexers/__init__.py +2 -3
  48. data/vendor/pygments-main/pygments/lexers/_asy_builtins.py +1 -2
  49. data/vendor/pygments-main/pygments/lexers/_cl_builtins.py +1 -2
  50. data/vendor/pygments-main/pygments/lexers/_cocoa_builtins.py +16 -12
  51. data/vendor/pygments-main/pygments/lexers/_csound_builtins.py +56 -16
  52. data/vendor/pygments-main/pygments/lexers/_julia_builtins.py +401 -0
  53. data/vendor/pygments-main/pygments/lexers/_lasso_builtins.py +1 -2
  54. data/vendor/pygments-main/pygments/lexers/_lua_builtins.py +1 -2
  55. data/vendor/pygments-main/pygments/lexers/_mapping.py +73 -54
  56. data/vendor/pygments-main/pygments/lexers/_mql_builtins.py +1 -2
  57. data/vendor/pygments-main/pygments/lexers/_mysql_builtins.py +2 -3
  58. data/vendor/pygments-main/pygments/lexers/_openedge_builtins.py +439 -386
  59. data/vendor/pygments-main/pygments/lexers/_php_builtins.py +1 -2
  60. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +1 -2
  61. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -2
  62. data/vendor/pygments-main/pygments/lexers/_sourcemod_builtins.py +1 -2
  63. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +1 -2
  64. data/vendor/pygments-main/pygments/lexers/_stata_builtins.py +91 -55
  65. data/vendor/pygments-main/pygments/lexers/_tsql_builtins.py +1 -2
  66. data/vendor/pygments-main/pygments/lexers/_usd_builtins.py +1 -2
  67. data/vendor/pygments-main/pygments/lexers/_vbscript_builtins.py +1 -2
  68. data/vendor/pygments-main/pygments/lexers/_vim_builtins.py +1 -2
  69. data/vendor/pygments-main/pygments/lexers/actionscript.py +9 -10
  70. data/vendor/pygments-main/pygments/lexers/agile.py +1 -2
  71. data/vendor/pygments-main/pygments/lexers/algebra.py +1 -2
  72. data/vendor/pygments-main/pygments/lexers/ambient.py +3 -4
  73. data/vendor/pygments-main/pygments/lexers/amdgpu.py +53 -0
  74. data/vendor/pygments-main/pygments/lexers/ampl.py +1 -2
  75. data/vendor/pygments-main/pygments/lexers/apdlexer.py +448 -0
  76. data/vendor/pygments-main/pygments/lexers/apl.py +7 -5
  77. data/vendor/pygments-main/pygments/lexers/archetype.py +2 -3
  78. data/vendor/pygments-main/pygments/lexers/arrow.py +1 -2
  79. data/vendor/pygments-main/pygments/lexers/asc.py +51 -0
  80. data/vendor/pygments-main/pygments/lexers/asm.py +87 -60
  81. data/vendor/pygments-main/pygments/lexers/automation.py +8 -3
  82. data/vendor/pygments-main/pygments/lexers/bare.py +1 -2
  83. data/vendor/pygments-main/pygments/lexers/basic.py +3 -4
  84. data/vendor/pygments-main/pygments/lexers/bibtex.py +3 -4
  85. data/vendor/pygments-main/pygments/lexers/boa.py +4 -5
  86. data/vendor/pygments-main/pygments/lexers/business.py +3 -4
  87. data/vendor/pygments-main/pygments/lexers/c_cpp.py +61 -36
  88. data/vendor/pygments-main/pygments/lexers/c_like.py +103 -5
  89. data/vendor/pygments-main/pygments/lexers/capnproto.py +1 -2
  90. data/vendor/pygments-main/pygments/lexers/cddl.py +190 -0
  91. data/vendor/pygments-main/pygments/lexers/chapel.py +52 -29
  92. data/vendor/pygments-main/pygments/lexers/clean.py +7 -8
  93. data/vendor/pygments-main/pygments/lexers/compiled.py +1 -2
  94. data/vendor/pygments-main/pygments/lexers/configs.py +139 -48
  95. data/vendor/pygments-main/pygments/lexers/console.py +1 -2
  96. data/vendor/pygments-main/pygments/lexers/crystal.py +53 -79
  97. data/vendor/pygments-main/pygments/lexers/csound.py +3 -4
  98. data/vendor/pygments-main/pygments/lexers/css.py +11 -8
  99. data/vendor/pygments-main/pygments/lexers/d.py +3 -4
  100. data/vendor/pygments-main/pygments/lexers/dalvik.py +1 -2
  101. data/vendor/pygments-main/pygments/lexers/data.py +2 -3
  102. data/vendor/pygments-main/pygments/lexers/devicetree.py +2 -3
  103. data/vendor/pygments-main/pygments/lexers/diff.py +1 -2
  104. data/vendor/pygments-main/pygments/lexers/dotnet.py +7 -8
  105. data/vendor/pygments-main/pygments/lexers/dsls.py +3 -4
  106. data/vendor/pygments-main/pygments/lexers/dylan.py +1 -2
  107. data/vendor/pygments-main/pygments/lexers/ecl.py +4 -6
  108. data/vendor/pygments-main/pygments/lexers/eiffel.py +2 -3
  109. data/vendor/pygments-main/pygments/lexers/elm.py +1 -2
  110. data/vendor/pygments-main/pygments/lexers/email.py +1 -2
  111. data/vendor/pygments-main/pygments/lexers/erlang.py +2 -3
  112. data/vendor/pygments-main/pygments/lexers/esoteric.py +1 -2
  113. data/vendor/pygments-main/pygments/lexers/ezhil.py +1 -2
  114. data/vendor/pygments-main/pygments/lexers/factor.py +3 -4
  115. data/vendor/pygments-main/pygments/lexers/fantom.py +1 -2
  116. data/vendor/pygments-main/pygments/lexers/felix.py +1 -2
  117. data/vendor/pygments-main/pygments/lexers/floscript.py +2 -3
  118. data/vendor/pygments-main/pygments/lexers/forth.py +2 -3
  119. data/vendor/pygments-main/pygments/lexers/fortran.py +9 -7
  120. data/vendor/pygments-main/pygments/lexers/foxpro.py +1 -2
  121. data/vendor/pygments-main/pygments/lexers/freefem.py +1 -2
  122. data/vendor/pygments-main/pygments/lexers/functional.py +1 -2
  123. data/vendor/pygments-main/pygments/lexers/futhark.py +111 -0
  124. data/vendor/pygments-main/pygments/lexers/gcodelexer.py +36 -0
  125. data/vendor/pygments-main/pygments/lexers/gdscript.py +1 -2
  126. data/vendor/pygments-main/pygments/lexers/go.py +3 -4
  127. data/vendor/pygments-main/pygments/lexers/grammar_notation.py +1 -2
  128. data/vendor/pygments-main/pygments/lexers/graph.py +1 -2
  129. data/vendor/pygments-main/pygments/lexers/graphics.py +4 -5
  130. data/vendor/pygments-main/pygments/lexers/graphviz.py +58 -0
  131. data/vendor/pygments-main/pygments/lexers/gsql.py +92 -0
  132. data/vendor/pygments-main/pygments/lexers/haskell.py +5 -6
  133. data/vendor/pygments-main/pygments/lexers/haxe.py +4 -5
  134. data/vendor/pygments-main/pygments/lexers/hdl.py +2 -6
  135. data/vendor/pygments-main/pygments/lexers/hexdump.py +1 -2
  136. data/vendor/pygments-main/pygments/lexers/html.py +7 -8
  137. data/vendor/pygments-main/pygments/lexers/idl.py +1 -2
  138. data/vendor/pygments-main/pygments/lexers/igor.py +1 -2
  139. data/vendor/pygments-main/pygments/lexers/inferno.py +1 -2
  140. data/vendor/pygments-main/pygments/lexers/installers.py +3 -4
  141. data/vendor/pygments-main/pygments/lexers/int_fiction.py +1 -2
  142. data/vendor/pygments-main/pygments/lexers/iolang.py +2 -3
  143. data/vendor/pygments-main/pygments/lexers/j.py +2 -3
  144. data/vendor/pygments-main/pygments/lexers/javascript.py +170 -156
  145. data/vendor/pygments-main/pygments/lexers/jslt.py +94 -0
  146. data/vendor/pygments-main/pygments/lexers/julia.py +136 -185
  147. data/vendor/pygments-main/pygments/lexers/jvm.py +433 -307
  148. data/vendor/pygments-main/pygments/lexers/kuin.py +299 -0
  149. data/vendor/pygments-main/pygments/lexers/lisp.py +25 -23
  150. data/vendor/pygments-main/pygments/lexers/make.py +3 -4
  151. data/vendor/pygments-main/pygments/lexers/markup.py +13 -16
  152. data/vendor/pygments-main/pygments/lexers/math.py +1 -2
  153. data/vendor/pygments-main/pygments/lexers/matlab.py +2666 -93
  154. data/vendor/pygments-main/pygments/lexers/meson.py +155 -0
  155. data/vendor/pygments-main/pygments/lexers/mime.py +7 -23
  156. data/vendor/pygments-main/pygments/lexers/ml.py +8 -9
  157. data/vendor/pygments-main/pygments/lexers/modeling.py +1 -2
  158. data/vendor/pygments-main/pygments/lexers/modula2.py +3 -4
  159. data/vendor/pygments-main/pygments/lexers/monte.py +1 -2
  160. data/vendor/pygments-main/pygments/lexers/mosel.py +1 -2
  161. data/vendor/pygments-main/pygments/lexers/ncl.py +1 -2
  162. data/vendor/pygments-main/pygments/lexers/nimrod.py +2 -3
  163. data/vendor/pygments-main/pygments/lexers/nit.py +1 -2
  164. data/vendor/pygments-main/pygments/lexers/nix.py +1 -2
  165. data/vendor/pygments-main/pygments/lexers/oberon.py +1 -2
  166. data/vendor/pygments-main/pygments/lexers/objective.py +6 -7
  167. data/vendor/pygments-main/pygments/lexers/ooc.py +1 -2
  168. data/vendor/pygments-main/pygments/lexers/other.py +1 -2
  169. data/vendor/pygments-main/pygments/lexers/parasail.py +1 -2
  170. data/vendor/pygments-main/pygments/lexers/parsers.py +26 -27
  171. data/vendor/pygments-main/pygments/lexers/pascal.py +1 -2
  172. data/vendor/pygments-main/pygments/lexers/pawn.py +2 -5
  173. data/vendor/pygments-main/pygments/lexers/perl.py +1 -2
  174. data/vendor/pygments-main/pygments/lexers/php.py +3 -4
  175. data/vendor/pygments-main/pygments/lexers/pointless.py +1 -2
  176. data/vendor/pygments-main/pygments/lexers/pony.py +1 -2
  177. data/vendor/pygments-main/pygments/lexers/praat.py +1 -2
  178. data/vendor/pygments-main/pygments/lexers/procfile.py +43 -0
  179. data/vendor/pygments-main/pygments/lexers/prolog.py +3 -4
  180. data/vendor/pygments-main/pygments/lexers/promql.py +2 -3
  181. data/vendor/pygments-main/pygments/lexers/python.py +38 -17
  182. data/vendor/pygments-main/pygments/lexers/qvt.py +1 -2
  183. data/vendor/pygments-main/pygments/lexers/r.py +1 -2
  184. data/vendor/pygments-main/pygments/lexers/rdf.py +1 -2
  185. data/vendor/pygments-main/pygments/lexers/rebol.py +1 -2
  186. data/vendor/pygments-main/pygments/lexers/resource.py +2 -3
  187. data/vendor/pygments-main/pygments/lexers/ride.py +1 -2
  188. data/vendor/pygments-main/pygments/lexers/rnc.py +2 -3
  189. data/vendor/pygments-main/pygments/lexers/roboconf.py +1 -2
  190. data/vendor/pygments-main/pygments/lexers/robotframework.py +1 -2
  191. data/vendor/pygments-main/pygments/lexers/ruby.py +31 -25
  192. data/vendor/pygments-main/pygments/lexers/rust.py +10 -12
  193. data/vendor/pygments-main/pygments/lexers/sas.py +1 -2
  194. data/vendor/pygments-main/pygments/lexers/scdoc.py +1 -2
  195. data/vendor/pygments-main/pygments/lexers/scripting.py +12 -13
  196. data/vendor/pygments-main/pygments/lexers/sgf.py +1 -2
  197. data/vendor/pygments-main/pygments/lexers/shell.py +15 -17
  198. data/vendor/pygments-main/pygments/lexers/sieve.py +1 -2
  199. data/vendor/pygments-main/pygments/lexers/slash.py +1 -2
  200. data/vendor/pygments-main/pygments/lexers/smalltalk.py +1 -2
  201. data/vendor/pygments-main/pygments/lexers/smithy.py +79 -0
  202. data/vendor/pygments-main/pygments/lexers/smv.py +2 -3
  203. data/vendor/pygments-main/pygments/lexers/snobol.py +1 -2
  204. data/vendor/pygments-main/pygments/lexers/solidity.py +1 -2
  205. data/vendor/pygments-main/pygments/lexers/special.py +44 -30
  206. data/vendor/pygments-main/pygments/lexers/sql.py +8 -13
  207. data/vendor/pygments-main/pygments/lexers/stata.py +1 -2
  208. data/vendor/pygments-main/pygments/lexers/supercollider.py +4 -5
  209. data/vendor/pygments-main/pygments/lexers/tcl.py +4 -5
  210. data/vendor/pygments-main/pygments/lexers/teal.py +88 -0
  211. data/vendor/pygments-main/pygments/lexers/templates.py +34 -35
  212. data/vendor/pygments-main/pygments/lexers/teraterm.py +2 -3
  213. data/vendor/pygments-main/pygments/lexers/testing.py +2 -3
  214. data/vendor/pygments-main/pygments/lexers/text.py +1 -2
  215. data/vendor/pygments-main/pygments/lexers/textedit.py +3 -4
  216. data/vendor/pygments-main/pygments/lexers/textfmts.py +1 -2
  217. data/vendor/pygments-main/pygments/lexers/theorem.py +11 -7
  218. data/vendor/pygments-main/pygments/lexers/thingsdb.py +118 -0
  219. data/vendor/pygments-main/pygments/lexers/tnt.py +26 -17
  220. data/vendor/pygments-main/pygments/lexers/trafficscript.py +2 -3
  221. data/vendor/pygments-main/pygments/lexers/typoscript.py +1 -2
  222. data/vendor/pygments-main/pygments/lexers/unicon.py +1 -2
  223. data/vendor/pygments-main/pygments/lexers/urbi.py +3 -4
  224. data/vendor/pygments-main/pygments/lexers/usd.py +1 -2
  225. data/vendor/pygments-main/pygments/lexers/varnish.py +2 -3
  226. data/vendor/pygments-main/pygments/lexers/verification.py +1 -2
  227. data/vendor/pygments-main/pygments/lexers/web.py +1 -2
  228. data/vendor/pygments-main/pygments/lexers/webassembly.py +120 -0
  229. data/vendor/pygments-main/pygments/lexers/webidl.py +1 -2
  230. data/vendor/pygments-main/pygments/lexers/webmisc.py +5 -5
  231. data/vendor/pygments-main/pygments/lexers/whiley.py +1 -2
  232. data/vendor/pygments-main/pygments/lexers/x10.py +2 -3
  233. data/vendor/pygments-main/pygments/lexers/xorg.py +1 -2
  234. data/vendor/pygments-main/pygments/lexers/yang.py +1 -2
  235. data/vendor/pygments-main/pygments/lexers/zig.py +1 -2
  236. data/vendor/pygments-main/pygments/modeline.py +1 -2
  237. data/vendor/pygments-main/pygments/plugin.py +2 -3
  238. data/vendor/pygments-main/pygments/regexopt.py +2 -3
  239. data/vendor/pygments-main/pygments/scanner.py +1 -2
  240. data/vendor/pygments-main/pygments/sphinxext.py +1 -2
  241. data/vendor/pygments-main/pygments/style.py +4 -5
  242. data/vendor/pygments-main/pygments/styles/__init__.py +5 -2
  243. data/vendor/pygments-main/pygments/styles/abap.py +1 -2
  244. data/vendor/pygments-main/pygments/styles/algol.py +1 -2
  245. data/vendor/pygments-main/pygments/styles/algol_nu.py +1 -2
  246. data/vendor/pygments-main/pygments/styles/arduino.py +1 -2
  247. data/vendor/pygments-main/pygments/styles/autumn.py +1 -2
  248. data/vendor/pygments-main/pygments/styles/borland.py +1 -2
  249. data/vendor/pygments-main/pygments/styles/bw.py +1 -2
  250. data/vendor/pygments-main/pygments/styles/colorful.py +1 -2
  251. data/vendor/pygments-main/pygments/styles/default.py +1 -2
  252. data/vendor/pygments-main/pygments/styles/emacs.py +1 -2
  253. data/vendor/pygments-main/pygments/styles/friendly.py +2 -2
  254. data/vendor/pygments-main/pygments/styles/fruity.py +1 -2
  255. data/vendor/pygments-main/pygments/styles/gruvbox.py +107 -0
  256. data/vendor/pygments-main/pygments/styles/igor.py +1 -2
  257. data/vendor/pygments-main/pygments/styles/inkpot.py +1 -2
  258. data/vendor/pygments-main/pygments/styles/lovelace.py +1 -2
  259. data/vendor/pygments-main/pygments/styles/manni.py +1 -2
  260. data/vendor/pygments-main/pygments/styles/material.py +118 -0
  261. data/vendor/pygments-main/pygments/styles/monokai.py +1 -2
  262. data/vendor/pygments-main/pygments/styles/murphy.py +1 -2
  263. data/vendor/pygments-main/pygments/styles/native.py +2 -2
  264. data/vendor/pygments-main/pygments/styles/paraiso_dark.py +1 -2
  265. data/vendor/pygments-main/pygments/styles/paraiso_light.py +1 -2
  266. data/vendor/pygments-main/pygments/styles/pastie.py +1 -2
  267. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -2
  268. data/vendor/pygments-main/pygments/styles/rainbow_dash.py +1 -2
  269. data/vendor/pygments-main/pygments/styles/rrt.py +1 -2
  270. data/vendor/pygments-main/pygments/styles/sas.py +1 -2
  271. data/vendor/pygments-main/pygments/styles/solarized.py +4 -2
  272. data/vendor/pygments-main/pygments/styles/stata_dark.py +1 -2
  273. data/vendor/pygments-main/pygments/styles/stata_light.py +1 -2
  274. data/vendor/pygments-main/pygments/styles/tango.py +1 -2
  275. data/vendor/pygments-main/pygments/styles/trac.py +1 -2
  276. data/vendor/pygments-main/pygments/styles/vim.py +1 -2
  277. data/vendor/pygments-main/pygments/styles/vs.py +1 -2
  278. data/vendor/pygments-main/pygments/styles/xcode.py +1 -2
  279. data/vendor/pygments-main/pygments/styles/zenburn.py +80 -0
  280. data/vendor/pygments-main/pygments/token.py +1 -2
  281. data/vendor/pygments-main/pygments/unistring.py +1 -2
  282. data/vendor/pygments-main/pygments/util.py +2 -5
  283. metadata +48 -23
  284. data/cache-lexers.rb +0 -9
  285. data/lexers +0 -0
  286. data/vendor/pygments-main/Pygments-2.7.3.dist-info/RECORD +0 -482
@@ -1,17 +1,17 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.cmdline
4
3
  ~~~~~~~~~~~~~~~~
5
4
 
6
5
  Command line interface.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10
 
12
11
  import os
13
12
  import sys
14
- import getopt
13
+ import shutil
14
+ import argparse
15
15
  from textwrap import dedent
16
16
 
17
17
  from pygments import __version__, highlight
@@ -30,84 +30,6 @@ from pygments.filters import get_all_filters, find_filter_class
30
30
  from pygments.styles import get_all_styles, get_style_by_name
31
31
 
32
32
 
33
- USAGE = """\
34
- Usage: %s [-l <lexer> | -g] [-F <filter>[:<options>]] [-f <formatter>]
35
- [-O <options>] [-P <option=value>] [-s] [-v] [-x] [-o <outfile>] [<infile>]
36
-
37
- %s -S <style> -f <formatter> [-a <arg>] [-O <options>] [-P <option=value>]
38
- %s -L [<which> ...]
39
- %s -N <filename>
40
- %s -H <type> <name>
41
- %s -h | -V
42
-
43
- Highlight the input file and write the result to <outfile>.
44
-
45
- If no input file is given, use stdin, if -o is not given, use stdout.
46
-
47
- If -s is passed, lexing will be done in "streaming" mode, reading and
48
- highlighting one line at a time. This will only work properly with
49
- lexers that have no constructs spanning multiple lines!
50
-
51
- <lexer> is a lexer name (query all lexer names with -L). If -l is not
52
- given, the lexer is guessed from the extension of the input file name
53
- (this obviously doesn't work if the input is stdin). If -g is passed,
54
- attempt to guess the lexer from the file contents, or pass through as
55
- plain text if this fails (this can work for stdin).
56
-
57
- Likewise, <formatter> is a formatter name, and will be guessed from
58
- the extension of the output file name. If no output file is given,
59
- the terminal formatter will be used by default.
60
-
61
- The additional option -x allows custom lexers and formatters to be
62
- loaded from a .py file relative to the current working directory. For
63
- example, ``-l ./customlexer.py -x``. By default, this option expects a
64
- file with a class named CustomLexer or CustomFormatter; you can also
65
- specify your own class name with a colon (``-l ./lexer.py:MyLexer``).
66
- Users should be very careful not to use this option with untrusted files,
67
- because it will import and run them.
68
-
69
- With the -O option, you can give the lexer and formatter a comma-
70
- separated list of options, e.g. ``-O bg=light,python=cool``.
71
-
72
- The -P option adds lexer and formatter options like the -O option, but
73
- you can only give one option per -P. That way, the option value may
74
- contain commas and equals signs, which it can't with -O, e.g.
75
- ``-P "heading=Pygments, the Python highlighter".
76
-
77
- With the -F option, you can add filters to the token stream, you can
78
- give options in the same way as for -O after a colon (note: there must
79
- not be spaces around the colon).
80
-
81
- The -O, -P and -F options can be given multiple times.
82
-
83
- With the -S option, print out style definitions for style <style>
84
- for formatter <formatter>. The argument given by -a is formatter
85
- dependent.
86
-
87
- The -L option lists lexers, formatters, styles or filters -- set
88
- `which` to the thing you want to list (e.g. "styles"), or omit it to
89
- list everything.
90
-
91
- The -N option guesses and prints out a lexer name based solely on
92
- the given filename. It does not take input or highlight anything.
93
- If no specific lexer can be determined "text" is returned.
94
-
95
- The -H option prints detailed help for the object <name> of type <type>,
96
- where <type> is one of "lexer", "formatter" or "filter".
97
-
98
- The -s option processes lines one at a time until EOF, rather than
99
- waiting to process the entire file. This only works for stdin, and
100
- is intended for streaming input such as you get from 'tail -f'.
101
- Example usage: "tail -f sql.log | pygmentize -s -l sql"
102
-
103
- The -v option prints a detailed traceback on unhandled exceptions,
104
- which is useful for debugging and bug reports.
105
-
106
- The -h option prints this help.
107
- The -V option prints the package version.
108
- """
109
-
110
-
111
33
  def _parse_options(o_strs):
112
34
  opts = {}
113
35
  if not o_strs:
@@ -213,95 +135,94 @@ def _print_list(what):
213
135
  print(" %s" % docstring_headline(cls))
214
136
 
215
137
 
216
- def main_inner(popts, args, usage):
217
- opts = {}
218
- O_opts = []
219
- P_opts = []
220
- F_opts = []
221
- for opt, arg in popts:
222
- if opt == '-O':
223
- O_opts.append(arg)
224
- elif opt == '-P':
225
- P_opts.append(arg)
226
- elif opt == '-F':
227
- F_opts.append(arg)
228
- opts[opt] = arg
229
-
230
- if opts.pop('-h', None) is not None:
231
- print(usage)
138
+ def main_inner(parser, argns):
139
+ if argns.help:
140
+ parser.print_help()
232
141
  return 0
233
142
 
234
- if opts.pop('-V', None) is not None:
235
- print('Pygments version %s, (c) 2006-2020 by Georg Brandl.' % __version__)
143
+ if argns.V:
144
+ print('Pygments version %s, (c) 2006-2021 by Georg Brandl, Matthäus '
145
+ 'Chajdas and contributors.' % __version__)
236
146
  return 0
237
147
 
148
+ def is_only_option(opt):
149
+ return not any(v for (k, v) in vars(argns).items() if k != opt)
150
+
238
151
  # handle ``pygmentize -L``
239
- L_opt = opts.pop('-L', None)
240
- if L_opt is not None:
241
- if opts:
242
- print(usage, file=sys.stderr)
152
+ if argns.L is not None:
153
+ if not is_only_option('L'):
154
+ parser.print_help(sys.stderr)
243
155
  return 2
244
-
245
156
  # print version
246
157
  main(['', '-V'])
247
- if not args:
248
- args = ['lexer', 'formatter', 'filter', 'style']
249
- for arg in args:
250
- _print_list(arg.rstrip('s'))
158
+ allowed_types = {'lexer', 'formatter', 'filter', 'style'}
159
+ largs = [arg.rstrip('s') for arg in argns.L]
160
+ if any(arg not in allowed_types for arg in largs):
161
+ parser.print_help(sys.stderr)
162
+ return 0
163
+ if not largs:
164
+ largs = allowed_types
165
+ for arg in largs:
166
+ _print_list(arg)
251
167
  return 0
252
168
 
253
169
  # handle ``pygmentize -H``
254
- H_opt = opts.pop('-H', None)
255
- if H_opt is not None:
256
- if opts or len(args) != 2:
257
- print(usage, file=sys.stderr)
170
+ if argns.H:
171
+ if not is_only_option('H'):
172
+ parser.print_help(sys.stderr)
258
173
  return 2
259
-
260
- what, name = args # pylint: disable=unbalanced-tuple-unpacking
174
+ what, name = argns.H
261
175
  if what not in ('lexer', 'formatter', 'filter'):
262
- print(usage, file=sys.stderr)
176
+ parser.print_help(sys.stderr)
263
177
  return 2
264
-
265
178
  return _print_help(what, name)
266
179
 
267
180
  # parse -O options
268
- parsed_opts = _parse_options(O_opts)
269
- opts.pop('-O', None)
181
+ parsed_opts = _parse_options(argns.O or [])
270
182
 
271
183
  # parse -P options
272
- for p_opt in P_opts:
184
+ for p_opt in argns.P or []:
273
185
  try:
274
186
  name, value = p_opt.split('=', 1)
275
187
  except ValueError:
276
188
  parsed_opts[p_opt] = True
277
189
  else:
278
190
  parsed_opts[name] = value
279
- opts.pop('-P', None)
280
191
 
281
192
  # encodings
282
193
  inencoding = parsed_opts.get('inencoding', parsed_opts.get('encoding'))
283
194
  outencoding = parsed_opts.get('outencoding', parsed_opts.get('encoding'))
284
195
 
285
196
  # handle ``pygmentize -N``
286
- infn = opts.pop('-N', None)
287
- if infn is not None:
288
- lexer = find_lexer_class_for_filename(infn)
197
+ if argns.N:
198
+ lexer = find_lexer_class_for_filename(argns.N)
289
199
  if lexer is None:
290
200
  lexer = TextLexer
291
201
 
292
202
  print(lexer.aliases[0])
293
203
  return 0
294
204
 
205
+ # handle ``pygmentize -C``
206
+ if argns.C:
207
+ inp = sys.stdin.buffer.read()
208
+ try:
209
+ lexer = guess_lexer(inp, inencoding=inencoding)
210
+ except ClassNotFound:
211
+ lexer = TextLexer
212
+
213
+ print(lexer.aliases[0])
214
+ return 0
215
+
295
216
  # handle ``pygmentize -S``
296
- S_opt = opts.pop('-S', None)
297
- a_opt = opts.pop('-a', None)
217
+ S_opt = argns.S
218
+ a_opt = argns.a
298
219
  if S_opt is not None:
299
- f_opt = opts.pop('-f', None)
220
+ f_opt = argns.f
300
221
  if not f_opt:
301
- print(usage, file=sys.stderr)
222
+ parser.print_help(sys.stderr)
302
223
  return 2
303
- if opts or args:
304
- print(usage, file=sys.stderr)
224
+ if argns.l or argns.INPUTFILE:
225
+ parser.print_help(sys.stderr)
305
226
  return 2
306
227
 
307
228
  try:
@@ -315,24 +236,21 @@ def main_inner(popts, args, usage):
315
236
  return 0
316
237
 
317
238
  # if no -S is given, -a is not allowed
318
- if a_opt is not None:
319
- print(usage, file=sys.stderr)
239
+ if argns.a is not None:
240
+ parser.print_help(sys.stderr)
320
241
  return 2
321
242
 
322
243
  # parse -F options
323
- F_opts = _parse_filters(F_opts)
324
- opts.pop('-F', None)
244
+ F_opts = _parse_filters(argns.F or [])
325
245
 
326
- allow_custom_lexer_formatter = False
327
246
  # -x: allow custom (eXternal) lexers and formatters
328
- if opts.pop('-x', None) is not None:
329
- allow_custom_lexer_formatter = True
247
+ allow_custom_lexer_formatter = bool(argns.x)
330
248
 
331
249
  # select lexer
332
250
  lexer = None
333
251
 
334
252
  # given by name?
335
- lexername = opts.pop('-l', None)
253
+ lexername = argns.l
336
254
  if lexername:
337
255
  # custom lexer, located relative to user's cwd
338
256
  if allow_custom_lexer_formatter and '.py' in lexername:
@@ -365,17 +283,13 @@ def main_inner(popts, args, usage):
365
283
  # read input code
366
284
  code = None
367
285
 
368
- if args:
369
- if len(args) > 1:
370
- print(usage, file=sys.stderr)
371
- return 2
372
-
373
- if '-s' in opts:
286
+ if argns.INPUTFILE:
287
+ if argns.s:
374
288
  print('Error: -s option not usable when input file specified',
375
289
  file=sys.stderr)
376
290
  return 2
377
291
 
378
- infn = args[0]
292
+ infn = argns.INPUTFILE
379
293
  try:
380
294
  with open(infn, 'rb') as infp:
381
295
  code = infp.read()
@@ -390,7 +304,7 @@ def main_inner(popts, args, usage):
390
304
  try:
391
305
  lexer = get_lexer_for_filename(infn, code, **parsed_opts)
392
306
  except ClassNotFound as err:
393
- if '-g' in opts:
307
+ if argns.g:
394
308
  try:
395
309
  lexer = guess_lexer(code, **parsed_opts)
396
310
  except ClassNotFound:
@@ -402,7 +316,7 @@ def main_inner(popts, args, usage):
402
316
  print('Error:', err, file=sys.stderr)
403
317
  return 1
404
318
 
405
- elif '-s' not in opts: # treat stdin as full file (-s support is later)
319
+ elif not argns.s: # treat stdin as full file (-s support is later)
406
320
  # read code from terminal, always in binary mode since we want to
407
321
  # decode ourselves and be tolerant with it
408
322
  code = sys.stdin.buffer.read() # use .buffer to get a binary stream
@@ -430,8 +344,8 @@ def main_inner(popts, args, usage):
430
344
  return 1
431
345
 
432
346
  # select formatter
433
- outfn = opts.pop('-o', None)
434
- fmter = opts.pop('-f', None)
347
+ outfn = argns.o
348
+ fmter = argns.f
435
349
  if fmter:
436
350
  # custom formatter, located relative to user's cwd
437
351
  if allow_custom_lexer_formatter and '.py' in fmter:
@@ -447,7 +361,7 @@ def main_inner(popts, args, usage):
447
361
 
448
362
  if filename and name:
449
363
  fmter = load_formatter_from_file(filename, name,
450
- **parsed_opts)
364
+ **parsed_opts)
451
365
  else:
452
366
  fmter = load_formatter_from_file(fmter, **parsed_opts)
453
367
  except ClassNotFound as err:
@@ -513,7 +427,7 @@ def main_inner(popts, args, usage):
513
427
  lexer = LatexEmbeddedLexer(left, right, lexer)
514
428
 
515
429
  # ... and do it!
516
- if '-s' not in opts:
430
+ if not argns.s:
517
431
  # process whole input as per normal...
518
432
  try:
519
433
  highlight(code, lexer, fmter, outfile)
@@ -541,22 +455,128 @@ def main_inner(popts, args, usage):
541
455
  outfile.close()
542
456
 
543
457
 
458
+ class HelpFormatter(argparse.HelpFormatter):
459
+ def __init__(self, prog, indent_increment=2, max_help_position=16, width=None):
460
+ if width is None:
461
+ try:
462
+ width = shutil.get_terminal_size().columns - 2
463
+ except Exception:
464
+ pass
465
+ argparse.HelpFormatter.__init__(self, prog, indent_increment,
466
+ max_help_position, width)
467
+
468
+
544
469
  def main(args=sys.argv):
545
470
  """
546
471
  Main command line entry point.
547
472
  """
548
- usage = USAGE % ((args[0],) * 6)
549
-
550
- try:
551
- popts, args = getopt.getopt(args[1:], "l:f:F:o:O:P:LS:a:N:vhVHgsx")
552
- except getopt.GetoptError:
553
- print(usage, file=sys.stderr)
554
- return 2
473
+ desc = "Highlight an input file and write the result to an output file."
474
+ parser = argparse.ArgumentParser(description=desc, add_help=False,
475
+ formatter_class=HelpFormatter)
476
+
477
+ operation = parser.add_argument_group('Main operation')
478
+ lexersel = operation.add_mutually_exclusive_group()
479
+ lexersel.add_argument(
480
+ '-l', metavar='LEXER',
481
+ help='Specify the lexer to use. (Query names with -L.) If not '
482
+ 'given and -g is not present, the lexer is guessed from the filename.')
483
+ lexersel.add_argument(
484
+ '-g', action='store_true',
485
+ help='Guess the lexer from the file contents, or pass through '
486
+ 'as plain text if nothing can be guessed.')
487
+ operation.add_argument(
488
+ '-F', metavar='FILTER[:options]', action='append',
489
+ help='Add a filter to the token stream. (Query names with -L.) '
490
+ 'Filter options are given after a colon if necessary.')
491
+ operation.add_argument(
492
+ '-f', metavar='FORMATTER',
493
+ help='Specify the formatter to use. (Query names with -L.) '
494
+ 'If not given, the formatter is guessed from the output filename, '
495
+ 'and defaults to the terminal formatter if the output is to the '
496
+ 'terminal or an unknown file extension.')
497
+ operation.add_argument(
498
+ '-O', metavar='OPTION=value[,OPTION=value,...]', action='append',
499
+ help='Give options to the lexer and formatter as a comma-separated '
500
+ 'list of key-value pairs. '
501
+ 'Example: `-O bg=light,python=cool`.')
502
+ operation.add_argument(
503
+ '-P', metavar='OPTION=value', action='append',
504
+ help='Give a single option to the lexer and formatter - with this '
505
+ 'you can pass options whose value contains commas and equal signs. '
506
+ 'Example: `-P "heading=Pygments, the Python highlighter"`.')
507
+ operation.add_argument(
508
+ '-o', metavar='OUTPUTFILE',
509
+ help='Where to write the output. Defaults to standard output.')
510
+
511
+ operation.add_argument(
512
+ 'INPUTFILE', nargs='?',
513
+ help='Where to read the input. Defaults to standard input.')
514
+
515
+ flags = parser.add_argument_group('Operation flags')
516
+ flags.add_argument(
517
+ '-v', action='store_true',
518
+ help='Print a detailed traceback on unhandled exceptions, which '
519
+ 'is useful for debugging and bug reports.')
520
+ flags.add_argument(
521
+ '-s', action='store_true',
522
+ help='Process lines one at a time until EOF, rather than waiting to '
523
+ 'process the entire file. This only works for stdin, only for lexers '
524
+ 'with no line-spanning constructs, and is intended for streaming '
525
+ 'input such as you get from `tail -f`. '
526
+ 'Example usage: `tail -f sql.log | pygmentize -s -l sql`.')
527
+ flags.add_argument(
528
+ '-x', action='store_true',
529
+ help='Allow custom lexers and formatters to be loaded from a .py file '
530
+ 'relative to the current working directory. For example, '
531
+ '`-l ./customlexer.py -x`. By default, this option expects a file '
532
+ 'with a class named CustomLexer or CustomFormatter; you can also '
533
+ 'specify your own class name with a colon (`-l ./lexer.py:MyLexer`). '
534
+ 'Users should be very careful not to use this option with untrusted '
535
+ 'files, because it will import and run them.')
536
+
537
+ special_modes_group = parser.add_argument_group(
538
+ 'Special modes - do not do any highlighting')
539
+ special_modes = special_modes_group.add_mutually_exclusive_group()
540
+ special_modes.add_argument(
541
+ '-S', metavar='STYLE -f formatter',
542
+ help='Print style definitions for STYLE for a formatter '
543
+ 'given with -f. The argument given by -a is formatter '
544
+ 'dependent.')
545
+ special_modes.add_argument(
546
+ '-L', nargs='*', metavar='WHAT',
547
+ help='List lexers, formatters, styles or filters -- '
548
+ 'give additional arguments for the thing(s) you want to list '
549
+ '(e.g. "styles"), or omit them to list everything.')
550
+ special_modes.add_argument(
551
+ '-N', metavar='FILENAME',
552
+ help='Guess and print out a lexer name based solely on the given '
553
+ 'filename. Does not take input or highlight anything. If no specific '
554
+ 'lexer can be determined, "text" is printed.')
555
+ special_modes.add_argument(
556
+ '-C', action='store_true',
557
+ help='Like -N, but print out a lexer name based solely on '
558
+ 'a given content from standard input.')
559
+ special_modes.add_argument(
560
+ '-H', action='store', nargs=2, metavar=('NAME', 'TYPE'),
561
+ help='Print detailed help for the object <name> of type <type>, '
562
+ 'where <type> is one of "lexer", "formatter" or "filter".')
563
+ special_modes.add_argument(
564
+ '-V', action='store_true',
565
+ help='Print the package version.')
566
+ special_modes.add_argument(
567
+ '-h', '--help', action='store_true',
568
+ help='Print this help.')
569
+ special_modes_group.add_argument(
570
+ '-a', metavar='ARG',
571
+ help='Formatter-specific additional argument for the -S (print '
572
+ 'style sheet) mode.')
573
+
574
+ argns = parser.parse_args(args[1:])
555
575
 
556
576
  try:
557
- return main_inner(popts, args, usage)
577
+ return main_inner(parser, argns)
558
578
  except Exception:
559
- if '-v' in dict(popts):
579
+ if argns.v:
560
580
  print(file=sys.stderr)
561
581
  print('*' * 65, file=sys.stderr)
562
582
  print('An unhandled exception occurred while highlighting.',
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.console
4
3
  ~~~~~~~~~~~~~~~~
5
4
 
6
5
  Format colored console output.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10
 
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.filter
4
3
  ~~~~~~~~~~~~~~~
5
4
 
6
5
  Module that implements the default filter.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10
 
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.filters
4
3
  ~~~~~~~~~~~~~~~~
@@ -6,7 +5,7 @@
6
5
  Module containing filter lookup functions and default
7
6
  filters.
8
7
 
9
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
8
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
10
9
  :license: BSD, see LICENSE for details.
11
10
  """
12
11
 
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.formatter
4
3
  ~~~~~~~~~~~~~~~~~~
5
4
 
6
5
  Base formatter class.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10
 
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.formatters
4
3
  ~~~~~~~~~~~~~~~~~~~
5
4
 
6
5
  Pygments formatters.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10
 
@@ -107,7 +106,7 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
107
106
  formatter_class = custom_namespace[formattername]
108
107
  # And finally instantiate it with the options
109
108
  return formatter_class(**options)
110
- except IOError as err:
109
+ except OSError as err:
111
110
  raise ClassNotFound('cannot read %s: %s' % (filename, err))
112
111
  except ClassNotFound:
113
112
  raise
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.formatters._mapping
4
3
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -9,7 +8,7 @@
9
8
 
10
9
  Do not alter the FORMATTERS dictionary by hand.
11
10
 
12
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
11
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
13
12
  :license: BSD, see LICENSE for details.
14
13
  """
15
14
 
@@ -23,6 +22,7 @@ FORMATTERS = {
23
22
  'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
24
23
  'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
25
24
  'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
25
+ 'PangoMarkupFormatter': ('pygments.formatters.pangomarkup', 'Pango Markup', ('pango', 'pangomarkup'), (), 'Format tokens as Pango Markup code. It can then be rendered to an SVG.'),
26
26
  'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
27
27
  'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'),
28
28
  'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
@@ -1,11 +1,10 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  pygments.formatters.bbcode
4
3
  ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
4
 
6
5
  BBcode formatter.
7
6
 
8
- :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS.
7
+ :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9
8
  :license: BSD, see LICENSE for details.
10
9
  """
11
10