mortar-pygments.rb 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (472) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG.md +71 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +17 -0
  5. data/README.md +121 -0
  6. data/Rakefile +66 -0
  7. data/bench.rb +22 -0
  8. data/cache-lexers.rb +8 -0
  9. data/lexers +0 -0
  10. data/lib/pygments/lexer.rb +148 -0
  11. data/lib/pygments/mentos.py +351 -0
  12. data/lib/pygments/popen.rb +406 -0
  13. data/lib/pygments/version.rb +3 -0
  14. data/lib/pygments.rb +8 -0
  15. data/pygments.rb.gemspec +25 -0
  16. data/test/test_data.c +2581 -0
  17. data/test/test_data.py +514 -0
  18. data/test/test_data_generated +2582 -0
  19. data/test/test_pygments.rb +287 -0
  20. data/vendor/custom_lexers/github.py +565 -0
  21. data/vendor/pygments-main/AUTHORS +153 -0
  22. data/vendor/pygments-main/CHANGES +889 -0
  23. data/vendor/pygments-main/LICENSE +25 -0
  24. data/vendor/pygments-main/MANIFEST.in +6 -0
  25. data/vendor/pygments-main/Makefile +59 -0
  26. data/vendor/pygments-main/REVISION +1 -0
  27. data/vendor/pygments-main/TODO +15 -0
  28. data/vendor/pygments-main/docs/generate.py +472 -0
  29. data/vendor/pygments-main/docs/pygmentize.1 +94 -0
  30. data/vendor/pygments-main/docs/src/api.txt +270 -0
  31. data/vendor/pygments-main/docs/src/authors.txt +5 -0
  32. data/vendor/pygments-main/docs/src/changelog.txt +5 -0
  33. data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
  34. data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
  35. data/vendor/pygments-main/docs/src/filters.txt +42 -0
  36. data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
  37. data/vendor/pygments-main/docs/src/formatters.txt +48 -0
  38. data/vendor/pygments-main/docs/src/index.txt +69 -0
  39. data/vendor/pygments-main/docs/src/installation.txt +71 -0
  40. data/vendor/pygments-main/docs/src/integrate.txt +48 -0
  41. data/vendor/pygments-main/docs/src/java.txt +70 -0
  42. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +603 -0
  43. data/vendor/pygments-main/docs/src/lexers.txt +67 -0
  44. data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
  45. data/vendor/pygments-main/docs/src/plugins.txt +93 -0
  46. data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
  47. data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
  48. data/vendor/pygments-main/docs/src/styles.txt +143 -0
  49. data/vendor/pygments-main/docs/src/tokens.txt +349 -0
  50. data/vendor/pygments-main/docs/src/unicode.txt +49 -0
  51. data/vendor/pygments-main/external/autopygmentize +64 -0
  52. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +144 -0
  53. data/vendor/pygments-main/external/markdown-processor.py +67 -0
  54. data/vendor/pygments-main/external/moin-parser.py +112 -0
  55. data/vendor/pygments-main/external/pygments.bashcomp +38 -0
  56. data/vendor/pygments-main/external/rst-directive-old.py +77 -0
  57. data/vendor/pygments-main/external/rst-directive.py +83 -0
  58. data/vendor/pygments-main/ez_setup.py +276 -0
  59. data/vendor/pygments-main/pygmentize +7 -0
  60. data/vendor/pygments-main/pygments/__init__.py +91 -0
  61. data/vendor/pygments-main/pygments/cmdline.py +441 -0
  62. data/vendor/pygments-main/pygments/console.py +74 -0
  63. data/vendor/pygments-main/pygments/filter.py +74 -0
  64. data/vendor/pygments-main/pygments/filters/__init__.py +356 -0
  65. data/vendor/pygments-main/pygments/formatter.py +95 -0
  66. data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
  67. data/vendor/pygments-main/pygments/formatters/_mapping.py +92 -0
  68. data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
  69. data/vendor/pygments-main/pygments/formatters/html.py +821 -0
  70. data/vendor/pygments-main/pygments/formatters/img.py +553 -0
  71. data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
  72. data/vendor/pygments-main/pygments/formatters/other.py +115 -0
  73. data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
  74. data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
  75. data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
  76. data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
  77. data/vendor/pygments-main/pygments/lexer.py +765 -0
  78. data/vendor/pygments-main/pygments/lexers/__init__.py +240 -0
  79. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
  80. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
  81. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +5172 -0
  82. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
  83. data/vendor/pygments-main/pygments/lexers/_mapping.py +355 -0
  84. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +562 -0
  85. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
  86. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +233 -0
  87. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +557 -0
  88. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +40 -0
  89. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
  90. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +360 -0
  91. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -0
  92. data/vendor/pygments-main/pygments/lexers/agile.py +2290 -0
  93. data/vendor/pygments-main/pygments/lexers/asm.py +398 -0
  94. data/vendor/pygments-main/pygments/lexers/compiled.py +3723 -0
  95. data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
  96. data/vendor/pygments-main/pygments/lexers/dotnet.py +671 -0
  97. data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
  98. data/vendor/pygments-main/pygments/lexers/functional.py +2731 -0
  99. data/vendor/pygments-main/pygments/lexers/github.py +565 -0
  100. data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
  101. data/vendor/pygments-main/pygments/lexers/jvm.py +1112 -0
  102. data/vendor/pygments-main/pygments/lexers/math.py +1918 -0
  103. data/vendor/pygments-main/pygments/lexers/other.py +3778 -0
  104. data/vendor/pygments-main/pygments/lexers/parsers.py +778 -0
  105. data/vendor/pygments-main/pygments/lexers/shell.py +424 -0
  106. data/vendor/pygments-main/pygments/lexers/special.py +100 -0
  107. data/vendor/pygments-main/pygments/lexers/sql.py +609 -0
  108. data/vendor/pygments-main/pygments/lexers/templates.py +1742 -0
  109. data/vendor/pygments-main/pygments/lexers/text.py +1893 -0
  110. data/vendor/pygments-main/pygments/lexers/web.py +4045 -0
  111. data/vendor/pygments-main/pygments/modeline.py +40 -0
  112. data/vendor/pygments-main/pygments/plugin.py +74 -0
  113. data/vendor/pygments-main/pygments/scanner.py +104 -0
  114. data/vendor/pygments-main/pygments/style.py +117 -0
  115. data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
  116. data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
  117. data/vendor/pygments-main/pygments/styles/borland.py +51 -0
  118. data/vendor/pygments-main/pygments/styles/bw.py +49 -0
  119. data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
  120. data/vendor/pygments-main/pygments/styles/default.py +73 -0
  121. data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
  122. data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
  123. data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
  124. data/vendor/pygments-main/pygments/styles/manni.py +75 -0
  125. data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
  126. data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
  127. data/vendor/pygments-main/pygments/styles/native.py +65 -0
  128. data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
  129. data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
  130. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  131. data/vendor/pygments-main/pygments/styles/tango.py +141 -0
  132. data/vendor/pygments-main/pygments/styles/trac.py +63 -0
  133. data/vendor/pygments-main/pygments/styles/vim.py +63 -0
  134. data/vendor/pygments-main/pygments/styles/vs.py +38 -0
  135. data/vendor/pygments-main/pygments/token.py +195 -0
  136. data/vendor/pygments-main/pygments/unistring.py +140 -0
  137. data/vendor/pygments-main/pygments/util.py +277 -0
  138. data/vendor/pygments-main/scripts/check_sources.py +242 -0
  139. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +32 -0
  140. data/vendor/pygments-main/scripts/epydoc.css +280 -0
  141. data/vendor/pygments-main/scripts/find_codetags.py +205 -0
  142. data/vendor/pygments-main/scripts/find_error.py +170 -0
  143. data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
  144. data/vendor/pygments-main/scripts/pylintrc +301 -0
  145. data/vendor/pygments-main/scripts/reindent.py +291 -0
  146. data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
  147. data/vendor/pygments-main/setup.cfg +7 -0
  148. data/vendor/pygments-main/setup.py +90 -0
  149. data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
  150. data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
  151. data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
  152. data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
  153. data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
  154. data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
  155. data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
  156. data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
  157. data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
  158. data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
  159. data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
  160. data/vendor/pygments-main/tests/examplefiles/BOM.js +1 -0
  161. data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
  162. data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -0
  163. data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
  164. data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
  165. data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
  166. data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
  167. data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
  168. data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
  169. data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
  170. data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
  171. data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
  172. data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
  173. data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
  174. data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
  175. data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
  176. data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
  177. data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
  178. data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
  179. data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
  180. data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
  181. data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
  182. data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
  183. data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
  184. data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
  185. data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
  186. data/vendor/pygments-main/tests/examplefiles/autoit_submit.au3 +25 -0
  187. data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
  188. data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
  189. data/vendor/pygments-main/tests/examplefiles/bigtest.nsi +308 -0
  190. data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
  191. data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
  192. data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -0
  193. data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
  194. data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
  195. data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
  196. data/vendor/pygments-main/tests/examplefiles/classes.dylan +125 -0
  197. data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
  198. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  199. data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
  200. data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
  201. data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
  202. data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
  203. data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
  204. data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
  205. data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
  206. data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
  207. data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
  208. data/vendor/pygments-main/tests/examplefiles/example.Rd +78 -0
  209. data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
  210. data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
  211. data/vendor/pygments-main/tests/examplefiles/example.ceylon +52 -0
  212. data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
  213. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  214. data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -0
  215. data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
  216. data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
  217. data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
  218. data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
  219. data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
  220. data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
  221. data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
  222. data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
  223. data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -0
  224. data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
  225. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  226. data/vendor/pygments-main/tests/examplefiles/example.msc +43 -0
  227. data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
  228. data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
  229. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  230. data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
  231. data/vendor/pygments-main/tests/examplefiles/example.prg +161 -0
  232. data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
  233. data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
  234. data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
  235. data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
  236. data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
  237. data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
  238. data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
  239. data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -0
  240. data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
  241. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  242. data/vendor/pygments-main/tests/examplefiles/example.stan +108 -0
  243. data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
  244. data/vendor/pygments-main/tests/examplefiles/example.ts +28 -0
  245. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  246. data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
  247. data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
  248. data/vendor/pygments-main/tests/examplefiles/example.xtend +34 -0
  249. data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
  250. data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
  251. data/vendor/pygments-main/tests/examplefiles/example2.msc +79 -0
  252. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  253. data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
  254. data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
  255. data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
  256. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  257. data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
  258. data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
  259. data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
  260. data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
  261. data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +133 -0
  262. data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
  263. data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
  264. data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
  265. data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
  266. data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
  267. data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
  268. data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
  269. data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
  270. data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
  271. data/vendor/pygments-main/tests/examplefiles/http_request_example +15 -0
  272. data/vendor/pygments-main/tests/examplefiles/http_response_example +29 -0
  273. data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
  274. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -0
  275. data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
  276. data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
  277. data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
  278. data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
  279. data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
  280. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  281. data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
  282. data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
  283. data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
  284. data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
  285. data/vendor/pygments-main/tests/examplefiles/json.lasso +301 -0
  286. data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -0
  287. data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
  288. data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
  289. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +41 -0
  290. data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -0
  291. data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
  292. data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
  293. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  294. data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
  295. data/vendor/pygments-main/tests/examplefiles/matlab_sample +30 -0
  296. data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
  297. data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
  298. data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
  299. data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -0
  300. data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
  301. data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
  302. data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
  303. data/vendor/pygments-main/tests/examplefiles/nanomsg.intr +95 -0
  304. data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
  305. data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
  306. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
  307. data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
  308. data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
  309. data/vendor/pygments-main/tests/examplefiles/objc_example.m +32 -0
  310. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
  311. data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
  312. data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
  313. data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
  314. data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
  315. data/vendor/pygments-main/tests/examplefiles/phpMyAdmin.spec +163 -0
  316. data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
  317. data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
  318. data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
  319. data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
  320. data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
  321. data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
  322. data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
  323. data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
  324. data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
  325. data/vendor/pygments-main/tests/examplefiles/pytb_test3.pytb +4 -0
  326. data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
  327. data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
  328. data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
  329. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
  330. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
  331. data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
  332. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  333. data/vendor/pygments-main/tests/examplefiles/robotframework.txt +39 -0
  334. data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
  335. data/vendor/pygments-main/tests/examplefiles/rust_example.rs +233 -0
  336. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  337. data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -0
  338. data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
  339. data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
  340. data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
  341. data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
  342. data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
  343. data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
  344. data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
  345. data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
  346. data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
  347. data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
  348. data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
  349. data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
  350. data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
  351. data/vendor/pygments-main/tests/examplefiles/test.R +153 -0
  352. data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
  353. data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
  354. data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
  355. data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
  356. data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
  357. data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
  358. data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
  359. data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
  360. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  361. data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
  362. data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
  363. data/vendor/pygments-main/tests/examplefiles/test.cu +36 -0
  364. data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
  365. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  366. data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
  367. data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
  368. data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
  369. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  370. data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
  371. data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
  372. data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
  373. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  374. data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
  375. data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
  376. data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
  377. data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
  378. data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
  379. data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
  380. data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
  381. data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
  382. data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
  383. data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
  384. data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
  385. data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
  386. data/vendor/pygments-main/tests/examplefiles/test.opa +10 -0
  387. data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
  388. data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
  389. data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
  390. data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
  391. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  392. data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
  393. data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
  394. data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
  395. data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
  396. data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
  397. data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
  398. data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
  399. data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
  400. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  401. data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
  402. data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
  403. data/vendor/pygments-main/tests/examplefiles/test2.pypylog +120 -0
  404. data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
  405. data/vendor/pygments-main/tests/examplefiles/type.lisp +1218 -0
  406. data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
  407. data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
  408. data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
  409. data/vendor/pygments-main/tests/examplefiles/unix-io.lid +37 -0
  410. data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
  411. data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
  412. data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
  413. data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
  414. data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
  415. data/vendor/pygments-main/tests/old_run.py +138 -0
  416. data/vendor/pygments-main/tests/run.py +49 -0
  417. data/vendor/pygments-main/tests/support/tags +36 -0
  418. data/vendor/pygments-main/tests/support.py +15 -0
  419. data/vendor/pygments-main/tests/test_basic_api.py +295 -0
  420. data/vendor/pygments-main/tests/test_clexer.py +31 -0
  421. data/vendor/pygments-main/tests/test_cmdline.py +105 -0
  422. data/vendor/pygments-main/tests/test_examplefiles.py +99 -0
  423. data/vendor/pygments-main/tests/test_html_formatter.py +178 -0
  424. data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
  425. data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
  426. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  427. data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
  428. data/vendor/pygments-main/tests/test_token.py +46 -0
  429. data/vendor/pygments-main/tests/test_using_api.py +40 -0
  430. data/vendor/pygments-main/tests/test_util.py +135 -0
  431. data/vendor/simplejson/.gitignore +10 -0
  432. data/vendor/simplejson/.travis.yml +5 -0
  433. data/vendor/simplejson/CHANGES.txt +291 -0
  434. data/vendor/simplejson/LICENSE.txt +19 -0
  435. data/vendor/simplejson/MANIFEST.in +5 -0
  436. data/vendor/simplejson/README.rst +19 -0
  437. data/vendor/simplejson/conf.py +179 -0
  438. data/vendor/simplejson/index.rst +628 -0
  439. data/vendor/simplejson/scripts/make_docs.py +18 -0
  440. data/vendor/simplejson/setup.py +104 -0
  441. data/vendor/simplejson/simplejson/__init__.py +510 -0
  442. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  443. data/vendor/simplejson/simplejson/decoder.py +425 -0
  444. data/vendor/simplejson/simplejson/encoder.py +567 -0
  445. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  446. data/vendor/simplejson/simplejson/scanner.py +77 -0
  447. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  448. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  449. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  450. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  451. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  452. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  453. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  454. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  455. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  456. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  457. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  458. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  459. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  460. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  461. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  462. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  463. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  464. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  465. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  466. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  467. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  468. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  469. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  470. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  471. data/vendor/simplejson/simplejson/tool.py +39 -0
  472. metadata +566 -0
@@ -0,0 +1,821 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.formatters.html
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ Formatter for HTML output.
7
+
8
+ :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import os
13
+ import sys
14
+ import os.path
15
+ import StringIO
16
+
17
+ from pygments.formatter import Formatter
18
+ from pygments.token import Token, Text, STANDARD_TYPES
19
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
20
+
21
+ try:
22
+ import ctags
23
+ except ImportError:
24
+ ctags = None
25
+
26
+ __all__ = ['HtmlFormatter']
27
+
28
+
29
+ _escape_html_table = {
30
+ ord('&'): u'&',
31
+ ord('<'): u'&lt;',
32
+ ord('>'): u'&gt;',
33
+ ord('"'): u'&quot;',
34
+ ord("'"): u'&#39;',
35
+ }
36
+
37
+ def escape_html(text, table=_escape_html_table):
38
+ """Escape &, <, > as well as single and double quotes for HTML."""
39
+ return text.translate(table)
40
+
41
+ def get_random_id():
42
+ """Return a random id for javascript fields."""
43
+ from random import random
44
+ from time import time
45
+ try:
46
+ from hashlib import sha1 as sha
47
+ except ImportError:
48
+ import sha
49
+ sha = sha.new
50
+ return sha('%s|%s' % (random(), time())).hexdigest()
51
+
52
+
53
+ def _get_ttype_class(ttype):
54
+ fname = STANDARD_TYPES.get(ttype)
55
+ if fname:
56
+ return fname
57
+ aname = ''
58
+ while fname is None:
59
+ aname = '-' + ttype[-1] + aname
60
+ ttype = ttype.parent
61
+ fname = STANDARD_TYPES.get(ttype)
62
+ return fname + aname
63
+
64
+
65
+ CSSFILE_TEMPLATE = '''\
66
+ td.linenos { background-color: #f0f0f0; padding-right: 10px; }
67
+ span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
68
+ pre { line-height: 125%%; }
69
+ %(styledefs)s
70
+ '''
71
+
72
+ DOC_HEADER = '''\
73
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
74
+ "http://www.w3.org/TR/html4/strict.dtd">
75
+
76
+ <html>
77
+ <head>
78
+ <title>%(title)s</title>
79
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
80
+ <style type="text/css">
81
+ ''' + CSSFILE_TEMPLATE + '''
82
+ </style>
83
+ </head>
84
+ <body>
85
+ <h2>%(title)s</h2>
86
+
87
+ '''
88
+
89
+ DOC_HEADER_EXTERNALCSS = '''\
90
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
91
+ "http://www.w3.org/TR/html4/strict.dtd">
92
+
93
+ <html>
94
+ <head>
95
+ <title>%(title)s</title>
96
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
97
+ <link rel="stylesheet" href="%(cssfile)s" type="text/css">
98
+ </head>
99
+ <body>
100
+ <h2>%(title)s</h2>
101
+
102
+ '''
103
+
104
+ DOC_FOOTER = '''\
105
+ </body>
106
+ </html>
107
+ '''
108
+
109
+
110
+ class HtmlFormatter(Formatter):
111
+ r"""
112
+ Format tokens as HTML 4 ``<span>`` tags within a ``<pre>`` tag, wrapped
113
+ in a ``<div>`` tag. The ``<div>``'s CSS class can be set by the `cssclass`
114
+ option.
115
+
116
+ If the `linenos` option is set to ``"table"``, the ``<pre>`` is
117
+ additionally wrapped inside a ``<table>`` which has one row and two
118
+ cells: one containing the line numbers and one containing the code.
119
+ Example:
120
+
121
+ .. sourcecode:: html
122
+
123
+ <div class="highlight" >
124
+ <table><tr>
125
+ <td class="linenos" title="click to toggle"
126
+ onclick="with (this.firstChild.style)
127
+ { display = (display == '') ? 'none' : '' }">
128
+ <pre>1
129
+ 2</pre>
130
+ </td>
131
+ <td class="code">
132
+ <pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar):
133
+ <span class="Ke">pass</span>
134
+ </pre>
135
+ </td>
136
+ </tr></table></div>
137
+
138
+ (whitespace added to improve clarity).
139
+
140
+ Wrapping can be disabled using the `nowrap` option.
141
+
142
+ A list of lines can be specified using the `hl_lines` option to make these
143
+ lines highlighted (as of Pygments 0.11).
144
+
145
+ With the `full` option, a complete HTML 4 document is output, including
146
+ the style definitions inside a ``<style>`` tag, or in a separate file if
147
+ the `cssfile` option is given.
148
+
149
+ When `tagsfile` is set to the path of a ctags index file, it is used to
150
+ generate hyperlinks from names to their definition. You must enable
151
+ `anchorlines` and run ctags with the `-n` option for this to work. The
152
+ `python-ctags` module from PyPI must be installed to use this feature;
153
+ otherwise a `RuntimeError` will be raised.
154
+
155
+ The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
156
+ containing CSS rules for the CSS classes used by the formatter. The
157
+ argument `arg` can be used to specify additional CSS selectors that
158
+ are prepended to the classes. A call `fmter.get_style_defs('td .code')`
159
+ would result in the following CSS classes:
160
+
161
+ .. sourcecode:: css
162
+
163
+ td .code .kw { font-weight: bold; color: #00FF00 }
164
+ td .code .cm { color: #999999 }
165
+ ...
166
+
167
+ If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
168
+ `get_style_defs()` method to request multiple prefixes for the tokens:
169
+
170
+ .. sourcecode:: python
171
+
172
+ formatter.get_style_defs(['div.syntax pre', 'pre.syntax'])
173
+
174
+ The output would then look like this:
175
+
176
+ .. sourcecode:: css
177
+
178
+ div.syntax pre .kw,
179
+ pre.syntax .kw { font-weight: bold; color: #00FF00 }
180
+ div.syntax pre .cm,
181
+ pre.syntax .cm { color: #999999 }
182
+ ...
183
+
184
+ Additional options accepted:
185
+
186
+ `nowrap`
187
+ If set to ``True``, don't wrap the tokens at all, not even inside a ``<pre>``
188
+ tag. This disables most other options (default: ``False``).
189
+
190
+ `full`
191
+ Tells the formatter to output a "full" document, i.e. a complete
192
+ self-contained document (default: ``False``).
193
+
194
+ `title`
195
+ If `full` is true, the title that should be used to caption the
196
+ document (default: ``''``).
197
+
198
+ `style`
199
+ The style to use, can be a string or a Style subclass (default:
200
+ ``'default'``). This option has no effect if the `cssfile`
201
+ and `noclobber_cssfile` option are given and the file specified in
202
+ `cssfile` exists.
203
+
204
+ `noclasses`
205
+ If set to true, token ``<span>`` tags will not use CSS classes, but
206
+ inline styles. This is not recommended for larger pieces of code since
207
+ it increases output size by quite a bit (default: ``False``).
208
+
209
+ `classprefix`
210
+ Since the token types use relatively short class names, they may clash
211
+ with some of your own class names. In this case you can use the
212
+ `classprefix` option to give a string to prepend to all Pygments-generated
213
+ CSS class names for token types.
214
+ Note that this option also affects the output of `get_style_defs()`.
215
+
216
+ `cssclass`
217
+ CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``).
218
+ If you set this option, the default selector for `get_style_defs()`
219
+ will be this class.
220
+
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'``.
224
+
225
+ `cssstyles`
226
+ Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
227
+
228
+ `prestyles`
229
+ Inline CSS styles for the ``<pre>`` tag (default: ``''``). *New in
230
+ Pygments 0.11.*
231
+
232
+ `cssfile`
233
+ If the `full` option is true and this option is given, it must be the
234
+ name of an external file. If the filename does not include an absolute
235
+ path, the file's path will be assumed to be relative to the main output
236
+ 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.*
238
+
239
+ `noclobber_cssfile`
240
+ If `cssfile` is given and the specified file exists, the css file will
241
+ not be overwritten. This allows the use of the `full` option in
242
+ combination with a user specified css file. Default is ``False``.
243
+ *New in Pygments 1.1.*
244
+
245
+ `linenos`
246
+ If set to ``'table'``, output line numbers as a table with two cells,
247
+ one containing the line numbers, the other the whole code. This is
248
+ copy-and-paste-friendly, but may cause alignment problems with some
249
+ browsers or fonts. If set to ``'inline'``, the line numbers will be
250
+ integrated in the ``<pre>`` tag that contains the code (that setting
251
+ is *new in Pygments 0.8*).
252
+
253
+ For compatibility with Pygments 0.7 and earlier, every true value
254
+ except ``'inline'`` means the same as ``'table'`` (in particular, that
255
+ means also ``True``).
256
+
257
+ The default value is ``False``, which means no line numbers at all.
258
+
259
+ **Note:** with the default ("table") line number mechanism, the line
260
+ numbers and code can have different line heights in Internet Explorer
261
+ unless you give the enclosing ``<pre>`` tags an explicit ``line-height``
262
+ CSS property (you get the default line spacing with ``line-height:
263
+ 125%``).
264
+
265
+ `hl_lines`
266
+ Specify a list of lines to be highlighted. *New in Pygments 0.11.*
267
+
268
+ `linenostart`
269
+ The line number for the first line (default: ``1``).
270
+
271
+ `linenostep`
272
+ If set to a number n > 1, only every nth line number is printed.
273
+
274
+ `linenospecial`
275
+ If set to a number n > 0, every nth line number is given the CSS
276
+ class ``"special"`` (default: ``0``).
277
+
278
+ `nobackground`
279
+ If set to ``True``, the formatter won't output the background color
280
+ for the wrapping element (this automatically defaults to ``False``
281
+ 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.*
284
+
285
+ `lineseparator`
286
+ This string is output between lines of code. It defaults to ``"\n"``,
287
+ 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.*
290
+
291
+ `lineanchors`
292
+ If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
293
+ 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.*
295
+
296
+ `linespans`
297
+ If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
298
+ 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.*
300
+
301
+ `anchorlinenos`
302
+ If set to `True`, will wrap line numbers in <a> tags. Used in
303
+ combination with `linenos` and `lineanchors`.
304
+
305
+ `tagsfile`
306
+ If set to the path of a ctags file, wrap names in anchor tags that
307
+ link to their definitions. `lineanchors` should be used, and the
308
+ tags file should specify line numbers (see the `-n` option to ctags).
309
+ *New in Pygments 1.6.*
310
+
311
+ `tagurlformat`
312
+ A string formatting pattern used to generate links to ctags definitions.
313
+ Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
314
+ Defaults to an empty string, resulting in just `#prefix-number` links.
315
+ *New in Pygments 1.6.*
316
+
317
+
318
+ **Subclassing the HTML formatter**
319
+
320
+ *New in Pygments 0.7.*
321
+
322
+ The HTML formatter is now built in a way that allows easy subclassing, thus
323
+ customizing the output HTML code. The `format()` method calls
324
+ `self._format_lines()` which returns a generator that yields tuples of ``(1,
325
+ line)``, where the ``1`` indicates that the ``line`` is a line of the
326
+ formatted source code.
327
+
328
+ If the `nowrap` option is set, the generator is the iterated over and the
329
+ resulting HTML is output.
330
+
331
+ Otherwise, `format()` calls `self.wrap()`, which wraps the generator with
332
+ other generators. These may add some HTML code to the one generated by
333
+ `_format_lines()`, either by modifying the lines generated by the latter,
334
+ then yielding them again with ``(1, line)``, and/or by yielding other HTML
335
+ code before or after the lines, with ``(0, html)``. The distinction between
336
+ source lines and other code makes it possible to wrap the generator multiple
337
+ times.
338
+
339
+ The default `wrap()` implementation adds a ``<div>`` and a ``<pre>`` tag.
340
+
341
+ A custom `HtmlFormatter` subclass could look like this:
342
+
343
+ .. sourcecode:: python
344
+
345
+ class CodeHtmlFormatter(HtmlFormatter):
346
+
347
+ def wrap(self, source, outfile):
348
+ return self._wrap_code(source)
349
+
350
+ def _wrap_code(self, source):
351
+ yield 0, '<code>'
352
+ for i, t in source:
353
+ if i == 1:
354
+ # it's a line of formatted code
355
+ t += '<br>'
356
+ yield i, t
357
+ yield 0, '</code>'
358
+
359
+ This results in wrapping the formatted lines with a ``<code>`` tag, where the
360
+ source lines are broken using ``<br>`` tags.
361
+
362
+ After calling `wrap()`, the `format()` method also adds the "line numbers"
363
+ and/or "full document" wrappers if the respective options are set. Then, all
364
+ HTML yielded by the wrapped generator is output.
365
+ """
366
+
367
+ name = 'HTML'
368
+ aliases = ['html']
369
+ filenames = ['*.html', '*.htm']
370
+
371
+ def __init__(self, **options):
372
+ Formatter.__init__(self, **options)
373
+ self.title = self._decodeifneeded(self.title)
374
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
375
+ self.noclasses = get_bool_opt(options, 'noclasses', False)
376
+ self.classprefix = options.get('classprefix', '')
377
+ self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
378
+ self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
379
+ self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
380
+ self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
381
+ self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
382
+ self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
383
+ self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
384
+
385
+ if self.tagsfile:
386
+ if not ctags:
387
+ raise RuntimeError('The "ctags" package must to be installed '
388
+ 'to be able to use the "tagsfile" feature.')
389
+ self._ctags = ctags.CTags(self.tagsfile)
390
+
391
+ linenos = options.get('linenos', False)
392
+ if linenos == 'inline':
393
+ self.linenos = 2
394
+ elif linenos:
395
+ # compatibility with <= 0.7
396
+ self.linenos = 1
397
+ else:
398
+ self.linenos = 0
399
+ self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
400
+ self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
401
+ self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
402
+ self.nobackground = get_bool_opt(options, 'nobackground', False)
403
+ self.lineseparator = options.get('lineseparator', '\n')
404
+ self.lineanchors = options.get('lineanchors', '')
405
+ self.linespans = options.get('linespans', '')
406
+ self.anchorlinenos = options.get('anchorlinenos', False)
407
+ self.hl_lines = set()
408
+ for lineno in get_list_opt(options, 'hl_lines', []):
409
+ try:
410
+ self.hl_lines.add(int(lineno))
411
+ except ValueError:
412
+ pass
413
+
414
+ self._create_stylesheet()
415
+
416
+ def _get_css_class(self, ttype):
417
+ """Return the css class of this token type prefixed with
418
+ the classprefix option."""
419
+ ttypeclass = _get_ttype_class(ttype)
420
+ if ttypeclass:
421
+ return self.classprefix + ttypeclass
422
+ return ''
423
+
424
+ def _create_stylesheet(self):
425
+ t2c = self.ttype2class = {Token: ''}
426
+ c2s = self.class2style = {}
427
+ for ttype, ndef in self.style:
428
+ name = self._get_css_class(ttype)
429
+ style = ''
430
+ if ndef['color']:
431
+ style += 'color: #%s; ' % ndef['color']
432
+ if ndef['bold']:
433
+ style += 'font-weight: bold; '
434
+ if ndef['italic']:
435
+ style += 'font-style: italic; '
436
+ if ndef['underline']:
437
+ style += 'text-decoration: underline; '
438
+ if ndef['bgcolor']:
439
+ style += 'background-color: #%s; ' % ndef['bgcolor']
440
+ if ndef['border']:
441
+ style += 'border: 1px solid #%s; ' % ndef['border']
442
+ if style:
443
+ t2c[ttype] = name
444
+ # save len(ttype) to enable ordering the styles by
445
+ # hierarchy (necessary for CSS cascading rules!)
446
+ c2s[name] = (style[:-2], ttype, len(ttype))
447
+
448
+ def get_style_defs(self, arg=None):
449
+ """
450
+ Return CSS style definitions for the classes produced by the current
451
+ highlighting style. ``arg`` can be a string or list of selectors to
452
+ insert before the token type classes.
453
+ """
454
+ if arg is None:
455
+ arg = ('cssclass' in self.options and '.'+self.cssclass or '')
456
+ if isinstance(arg, basestring):
457
+ args = [arg]
458
+ else:
459
+ args = list(arg)
460
+
461
+ def prefix(cls):
462
+ if cls:
463
+ cls = '.' + cls
464
+ tmp = []
465
+ for arg in args:
466
+ tmp.append((arg and arg + ' ' or '') + cls)
467
+ return ', '.join(tmp)
468
+
469
+ styles = [(level, ttype, cls, style)
470
+ for cls, (style, ttype, level) in self.class2style.iteritems()
471
+ if cls and style]
472
+ styles.sort()
473
+ lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
474
+ for (level, ttype, cls, style) in styles]
475
+ if arg and not self.nobackground and \
476
+ self.style.background_color is not None:
477
+ text_style = ''
478
+ if Text in self.ttype2class:
479
+ text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
480
+ lines.insert(0, '%s { background: %s;%s }' %
481
+ (prefix(''), self.style.background_color, text_style))
482
+ if self.style.highlight_color is not None:
483
+ lines.insert(0, '%s.hll { background-color: %s }' %
484
+ (prefix(''), self.style.highlight_color))
485
+ return '\n'.join(lines)
486
+
487
+ def _decodeifneeded(self, value):
488
+ if isinstance(value, bytes):
489
+ if self.encoding:
490
+ return value.decode(self.encoding)
491
+ return value.decode()
492
+ return value
493
+
494
+ def _wrap_full(self, inner, outfile):
495
+ if self.cssfile:
496
+ if os.path.isabs(self.cssfile):
497
+ # it's an absolute filename
498
+ cssfilename = self.cssfile
499
+ else:
500
+ try:
501
+ filename = outfile.name
502
+ if not filename or filename[0] == '<':
503
+ # pseudo files, e.g. name == '<fdopen>'
504
+ raise AttributeError
505
+ cssfilename = os.path.join(os.path.dirname(filename),
506
+ self.cssfile)
507
+ except AttributeError:
508
+ print >>sys.stderr, 'Note: Cannot determine output file name, ' \
509
+ 'using current directory as base for the CSS file name'
510
+ cssfilename = self.cssfile
511
+ # write CSS file only if noclobber_cssfile isn't given as an option.
512
+ try:
513
+ if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
514
+ cf = open(cssfilename, "w")
515
+ cf.write(CSSFILE_TEMPLATE %
516
+ {'styledefs': self.get_style_defs('body')})
517
+ cf.close()
518
+ except IOError, err:
519
+ err.strerror = 'Error writing CSS file: ' + err.strerror
520
+ raise
521
+
522
+ yield 0, (DOC_HEADER_EXTERNALCSS %
523
+ dict(title = self.title,
524
+ cssfile = self.cssfile,
525
+ encoding = self.encoding))
526
+ else:
527
+ yield 0, (DOC_HEADER %
528
+ dict(title = self.title,
529
+ styledefs = self.get_style_defs('body'),
530
+ encoding = self.encoding))
531
+
532
+ for t, line in inner:
533
+ yield t, line
534
+ yield 0, DOC_FOOTER
535
+
536
+ def _wrap_tablelinenos(self, inner):
537
+ dummyoutfile = StringIO.StringIO()
538
+ lncount = 0
539
+ for t, line in inner:
540
+ if t:
541
+ lncount += 1
542
+ dummyoutfile.write(line)
543
+
544
+ fl = self.linenostart
545
+ mw = len(str(lncount + fl - 1))
546
+ sp = self.linenospecial
547
+ st = self.linenostep
548
+ la = self.lineanchors
549
+ aln = self.anchorlinenos
550
+ nocls = self.noclasses
551
+ if sp:
552
+ lines = []
553
+
554
+ for i in range(fl, fl+lncount):
555
+ if i % st == 0:
556
+ if i % sp == 0:
557
+ if aln:
558
+ lines.append('<a href="#%s-%d" class="special">%*d</a>' %
559
+ (la, i, mw, i))
560
+ else:
561
+ lines.append('<span class="special">%*d</span>' % (mw, i))
562
+ else:
563
+ if aln:
564
+ lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
565
+ else:
566
+ lines.append('%*d' % (mw, i))
567
+ else:
568
+ lines.append('')
569
+ ls = '\n'.join(lines)
570
+ else:
571
+ lines = []
572
+ for i in range(fl, fl+lncount):
573
+ if i % st == 0:
574
+ if aln:
575
+ lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
576
+ else:
577
+ lines.append('%*d' % (mw, i))
578
+ else:
579
+ lines.append('')
580
+ ls = '\n'.join(lines)
581
+
582
+ # in case you wonder about the seemingly redundant <div> here: since the
583
+ # content in the other cell also is wrapped in a div, some browsers in
584
+ # some configurations seem to mess up the formatting...
585
+ if nocls:
586
+ yield 0, ('<table class="%stable">' % self.cssclass +
587
+ '<tr><td><div class="linenodiv" '
588
+ 'style="background-color: #f0f0f0; padding-right: 10px">'
589
+ '<pre style="line-height: 125%">' +
590
+ ls + '</pre></div></td><td class="code">')
591
+ else:
592
+ yield 0, ('<table class="%stable">' % self.cssclass +
593
+ '<tr><td class="linenos"><div class="linenodiv"><pre>' +
594
+ ls + '</pre></div></td><td class="code">')
595
+ yield 0, dummyoutfile.getvalue()
596
+ yield 0, '</td></tr></table>'
597
+
598
+ def _wrap_inlinelinenos(self, inner):
599
+ # need a list of lines since we need the width of a single number :(
600
+ lines = list(inner)
601
+ sp = self.linenospecial
602
+ st = self.linenostep
603
+ num = self.linenostart
604
+ mw = len(str(len(lines) + num - 1))
605
+
606
+ if self.noclasses:
607
+ if sp:
608
+ for t, line in lines:
609
+ if num%sp == 0:
610
+ style = 'background-color: #ffffc0; padding: 0 5px 0 5px'
611
+ else:
612
+ style = 'background-color: #f0f0f0; padding: 0 5px 0 5px'
613
+ yield 1, '<span style="%s">%*s</span> ' % (
614
+ style, mw, (num%st and ' ' or num)) + line
615
+ num += 1
616
+ else:
617
+ for t, line in lines:
618
+ yield 1, ('<span style="background-color: #f0f0f0; '
619
+ 'padding: 0 5px 0 5px">%*s</span> ' % (
620
+ mw, (num%st and ' ' or num)) + line)
621
+ num += 1
622
+ elif sp:
623
+ for t, line in lines:
624
+ yield 1, '<span class="lineno%s">%*s</span> ' % (
625
+ num%sp == 0 and ' special' or '', mw,
626
+ (num%st and ' ' or num)) + line
627
+ num += 1
628
+ else:
629
+ for t, line in lines:
630
+ yield 1, '<span class="lineno">%*s</span> ' % (
631
+ mw, (num%st and ' ' or num)) + line
632
+ num += 1
633
+
634
+ def _wrap_lineanchors(self, inner):
635
+ s = self.lineanchors
636
+ i = self.linenostart - 1 # subtract 1 since we have to increment i
637
+ # *before* yielding
638
+ for t, line in inner:
639
+ if t:
640
+ i += 1
641
+ yield 1, '<a name="%s-%d"></a>' % (s, i) + line
642
+ else:
643
+ yield 0, line
644
+
645
+ def _wrap_linespans(self, inner):
646
+ s = self.linespans
647
+ i = self.linenostart - 1
648
+ for t, line in inner:
649
+ if t:
650
+ i += 1
651
+ yield 1, '<span id="%s-%d">%s</span>' % (s, i, line)
652
+ else:
653
+ yield 0, line
654
+
655
+ def _wrap_div(self, inner):
656
+ style = []
657
+ if (self.noclasses and not self.nobackground and
658
+ self.style.background_color is not None):
659
+ style.append('background: %s' % (self.style.background_color,))
660
+ if self.cssstyles:
661
+ style.append(self.cssstyles)
662
+ style = '; '.join(style)
663
+
664
+ yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass)
665
+ + (style and (' style="%s"' % style)) + '>')
666
+ for tup in inner:
667
+ yield tup
668
+ yield 0, '</div>\n'
669
+
670
+ def _wrap_pre(self, inner):
671
+ style = []
672
+ if self.prestyles:
673
+ style.append(self.prestyles)
674
+ if self.noclasses:
675
+ style.append('line-height: 125%')
676
+ style = '; '.join(style)
677
+
678
+ yield 0, ('<pre' + (style and ' style="%s"' % style) + '>')
679
+ for tup in inner:
680
+ yield tup
681
+ yield 0, '</pre>'
682
+
683
+ def _format_lines(self, tokensource):
684
+ """
685
+ Just format the tokens, without any wrapping tags.
686
+ Yield individual lines.
687
+ """
688
+ nocls = self.noclasses
689
+ lsep = self.lineseparator
690
+ # for <span style=""> lookup only
691
+ getcls = self.ttype2class.get
692
+ c2s = self.class2style
693
+ escape_table = _escape_html_table
694
+ tagsfile = self.tagsfile
695
+
696
+ lspan = ''
697
+ line = ''
698
+ for ttype, value in tokensource:
699
+ if nocls:
700
+ cclass = getcls(ttype)
701
+ while cclass is None:
702
+ ttype = ttype.parent
703
+ cclass = getcls(ttype)
704
+ cspan = cclass and '<span style="%s">' % c2s[cclass][0] or ''
705
+ else:
706
+ cls = self._get_css_class(ttype)
707
+ cspan = cls and '<span class="%s">' % cls or ''
708
+
709
+ parts = value.translate(escape_table).split('\n')
710
+
711
+ if tagsfile and ttype in Token.Name:
712
+ filename, linenumber = self._lookup_ctag(value)
713
+ if linenumber:
714
+ base, filename = os.path.split(filename)
715
+ if base:
716
+ base += '/'
717
+ filename, extension = os.path.splitext(filename)
718
+ url = self.tagurlformat % {'path': base, 'fname': filename,
719
+ 'fext': extension}
720
+ parts[0] = "<a href=\"%s#%s-%d\">%s" % \
721
+ (url, self.lineanchors, linenumber, parts[0])
722
+ parts[-1] = parts[-1] + "</a>"
723
+
724
+ # for all but the last line
725
+ for part in parts[:-1]:
726
+ if line:
727
+ if lspan != cspan:
728
+ line += (lspan and '</span>') + cspan + part + \
729
+ (cspan and '</span>') + lsep
730
+ else: # both are the same
731
+ line += part + (lspan and '</span>') + lsep
732
+ yield 1, line
733
+ line = ''
734
+ elif part:
735
+ yield 1, cspan + part + (cspan and '</span>') + lsep
736
+ else:
737
+ yield 1, lsep
738
+ # for the last line
739
+ if line and parts[-1]:
740
+ if lspan != cspan:
741
+ line += (lspan and '</span>') + cspan + parts[-1]
742
+ lspan = cspan
743
+ else:
744
+ line += parts[-1]
745
+ elif parts[-1]:
746
+ line = cspan + parts[-1]
747
+ lspan = cspan
748
+ # else we neither have to open a new span nor set lspan
749
+
750
+ if line:
751
+ yield 1, line + (lspan and '</span>') + lsep
752
+
753
+ def _lookup_ctag(self, token):
754
+ entry = ctags.TagEntry()
755
+ if self._ctags.find(entry, token, 0):
756
+ return entry['file'], entry['lineNumber']
757
+ else:
758
+ return None, None
759
+
760
+ def _highlight_lines(self, tokensource):
761
+ """
762
+ Highlighted the lines specified in the `hl_lines` option by
763
+ post-processing the token stream coming from `_format_lines`.
764
+ """
765
+ hls = self.hl_lines
766
+
767
+ for i, (t, value) in enumerate(tokensource):
768
+ if t != 1:
769
+ yield t, value
770
+ if i + 1 in hls: # i + 1 because Python indexes start at 0
771
+ if self.noclasses:
772
+ style = ''
773
+ if self.style.highlight_color is not None:
774
+ style = (' style="background-color: %s"' %
775
+ (self.style.highlight_color,))
776
+ yield 1, '<span%s>%s</span>' % (style, value)
777
+ else:
778
+ yield 1, '<span class="hll">%s</span>' % value
779
+ else:
780
+ yield 1, value
781
+
782
+ def wrap(self, source, outfile):
783
+ """
784
+ Wrap the ``source``, which is a generator yielding
785
+ individual lines, in custom generators. See docstring
786
+ for `format`. Can be overridden.
787
+ """
788
+ return self._wrap_div(self._wrap_pre(source))
789
+
790
+ def format_unencoded(self, tokensource, outfile):
791
+ """
792
+ The formatting process uses several nested generators; which of
793
+ them are used is determined by the user's options.
794
+
795
+ Each generator should take at least one argument, ``inner``,
796
+ and wrap the pieces of text generated by this.
797
+
798
+ Always yield 2-tuples: (code, text). If "code" is 1, the text
799
+ is part of the original tokensource being highlighted, if it's
800
+ 0, the text is some piece of wrapping. This makes it possible to
801
+ use several different wrappers that process the original source
802
+ linewise, e.g. line number generators.
803
+ """
804
+ source = self._format_lines(tokensource)
805
+ if self.hl_lines:
806
+ source = self._highlight_lines(source)
807
+ if not self.nowrap:
808
+ if self.linenos == 2:
809
+ source = self._wrap_inlinelinenos(source)
810
+ if self.lineanchors:
811
+ source = self._wrap_lineanchors(source)
812
+ if self.linespans:
813
+ source = self._wrap_linespans(source)
814
+ source = self.wrap(source, outfile)
815
+ if self.linenos == 1:
816
+ source = self._wrap_tablelinenos(source)
817
+ if self.full:
818
+ source = self._wrap_full(source, outfile)
819
+
820
+ for t, piece in source:
821
+ outfile.write(piece)