pygments.rb 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +3 -0
  4. data/lexers +0 -0
  5. data/lib/pygments/popen.rb +3 -2
  6. data/lib/pygments/version.rb +1 -1
  7. data/pygments.rb.gemspec +2 -1
  8. data/vendor/pygments-main/AUTHORS +20 -1
  9. data/vendor/pygments-main/CHANGES +55 -3
  10. data/vendor/pygments-main/LICENSE +1 -1
  11. data/vendor/pygments-main/MANIFEST.in +1 -1
  12. data/vendor/pygments-main/Makefile +5 -8
  13. data/vendor/pygments-main/REVISION +1 -1
  14. data/vendor/pygments-main/doc/Makefile +153 -0
  15. data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
  16. data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
  17. data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
  18. data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
  19. data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
  20. data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
  21. data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
  22. data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
  23. data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
  24. data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
  25. data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
  26. data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
  27. data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
  28. data/vendor/pygments-main/doc/conf.py +249 -0
  29. data/vendor/pygments-main/doc/docs/api.rst +316 -0
  30. data/vendor/pygments-main/doc/docs/authors.rst +4 -0
  31. data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
  32. data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
  33. data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
  34. data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
  35. data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
  36. data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
  37. data/vendor/pygments-main/doc/docs/index.rst +66 -0
  38. data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
  39. data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
  40. data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
  41. data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
  42. data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
  43. data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
  44. data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
  45. data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
  46. data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
  47. data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
  48. data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
  49. data/vendor/pygments-main/doc/download.rst +41 -0
  50. data/vendor/pygments-main/doc/faq.rst +143 -0
  51. data/vendor/pygments-main/doc/index.rst +53 -0
  52. data/vendor/pygments-main/doc/languages.rst +151 -0
  53. data/vendor/pygments-main/doc/make.bat +190 -0
  54. data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
  55. data/vendor/pygments-main/external/autopygmentize +65 -48
  56. data/vendor/pygments-main/external/markdown-processor.py +15 -15
  57. data/vendor/pygments-main/external/moin-parser.py +1 -1
  58. data/vendor/pygments-main/external/rst-directive.py +2 -3
  59. data/vendor/pygments-main/ez_setup.py +340 -234
  60. data/vendor/pygments-main/pygments/__init__.py +4 -4
  61. data/vendor/pygments-main/pygments/cmdline.py +81 -68
  62. data/vendor/pygments-main/pygments/console.py +1 -1
  63. data/vendor/pygments-main/pygments/filter.py +1 -1
  64. data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
  65. data/vendor/pygments-main/pygments/formatter.py +3 -3
  66. data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
  67. data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
  68. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  69. data/vendor/pygments-main/pygments/formatters/html.py +44 -26
  70. data/vendor/pygments-main/pygments/formatters/img.py +21 -14
  71. data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
  72. data/vendor/pygments-main/pygments/formatters/other.py +53 -6
  73. data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
  74. data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
  75. data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
  76. data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
  77. data/vendor/pygments-main/pygments/lexer.py +59 -39
  78. data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
  79. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
  80. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
  81. data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
  82. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
  83. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
  84. data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
  85. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
  86. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
  87. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
  88. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
  89. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
  90. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
  91. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
  92. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
  93. data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
  94. data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
  95. data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
  96. data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
  97. data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
  98. data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
  99. data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
  100. data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
  101. data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
  102. data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
  103. data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
  104. data/vendor/pygments-main/pygments/lexers/math.py +438 -70
  105. data/vendor/pygments-main/pygments/lexers/other.py +885 -171
  106. data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
  107. data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
  108. data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
  109. data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
  110. data/vendor/pygments-main/pygments/lexers/special.py +7 -8
  111. data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
  112. data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
  113. data/vendor/pygments-main/pygments/lexers/text.py +208 -46
  114. data/vendor/pygments-main/pygments/lexers/web.py +729 -264
  115. data/vendor/pygments-main/pygments/modeline.py +1 -1
  116. data/vendor/pygments-main/pygments/plugin.py +1 -1
  117. data/vendor/pygments-main/pygments/scanner.py +1 -1
  118. data/vendor/pygments-main/pygments/sphinxext.py +153 -0
  119. data/vendor/pygments-main/pygments/style.py +3 -2
  120. data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
  121. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  122. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  123. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  124. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  125. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  126. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  127. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  128. data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
  129. data/vendor/pygments-main/pygments/styles/igor.py +29 -0
  130. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  131. data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
  132. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  133. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  134. data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
  135. data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
  136. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  137. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  138. data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
  139. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  140. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  141. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  142. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  143. data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
  144. data/vendor/pygments-main/pygments/token.py +4 -1
  145. data/vendor/pygments-main/pygments/unistring.py +6 -5
  146. data/vendor/pygments-main/pygments/util.py +35 -21
  147. data/vendor/pygments-main/scripts/check_sources.py +28 -44
  148. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
  149. data/vendor/pygments-main/scripts/find_codetags.py +27 -19
  150. data/vendor/pygments-main/scripts/find_error.py +16 -13
  151. data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
  152. data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
  153. data/vendor/pygments-main/setup.py +19 -19
  154. data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
  155. data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
  156. data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
  157. data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
  158. data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
  159. data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
  160. data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
  161. data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
  162. data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
  163. data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
  164. data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
  165. data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
  166. data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
  167. data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
  168. data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
  169. data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
  170. data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
  171. data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
  172. data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
  173. data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
  174. data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
  175. data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
  176. data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
  177. data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
  178. data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
  179. data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
  180. data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
  181. data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
  182. data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
  183. data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
  184. data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
  185. data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
  186. data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
  187. data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
  188. data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
  189. data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
  190. data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
  191. data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
  192. data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
  193. data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
  194. data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
  195. data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
  196. data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
  197. data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
  198. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
  199. data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
  200. data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
  201. data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
  202. data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
  203. data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
  204. data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
  205. data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
  206. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
  207. data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
  208. data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
  209. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
  210. data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
  211. data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
  212. data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
  213. data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
  214. data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
  215. data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
  216. data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
  217. data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
  218. data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
  219. data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
  220. data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
  221. data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
  222. data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
  223. data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
  224. data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
  225. data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
  226. data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
  227. data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
  228. data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
  229. data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
  230. data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
  231. data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
  232. data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
  233. data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
  234. data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
  235. data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
  236. data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
  237. data/vendor/pygments-main/tests/run.py +14 -19
  238. data/vendor/pygments-main/tests/string_asserts.py +22 -0
  239. data/vendor/pygments-main/tests/test_basic_api.py +28 -14
  240. data/vendor/pygments-main/tests/test_cfm.py +46 -0
  241. data/vendor/pygments-main/tests/test_clexer.py +208 -3
  242. data/vendor/pygments-main/tests/test_cmdline.py +6 -5
  243. data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
  244. data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
  245. data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
  246. data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
  247. data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
  248. data/vendor/pygments-main/tests/test_perllexer.py +1 -1
  249. data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
  250. data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
  251. data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
  252. data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
  253. data/vendor/pygments-main/tests/test_token.py +3 -3
  254. data/vendor/pygments-main/tests/test_using_api.py +1 -1
  255. data/vendor/pygments-main/tests/test_util.py +1 -1
  256. metadata +138 -51
  257. data/vendor/pygments-main/docs/generate.py +0 -472
  258. data/vendor/pygments-main/docs/src/api.txt +0 -270
  259. data/vendor/pygments-main/docs/src/authors.txt +0 -5
  260. data/vendor/pygments-main/docs/src/changelog.txt +0 -5
  261. data/vendor/pygments-main/docs/src/index.txt +0 -69
  262. data/vendor/pygments-main/docs/src/installation.txt +0 -71
  263. data/vendor/pygments-main/external/rst-directive-old.py +0 -77
  264. data/vendor/pygments-main/scripts/reindent.py +0 -291
  265. data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
  266. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
  267. data/vendor/pygments-main/tests/old_run.py +0 -138
@@ -1,472 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- """
4
- Generate Pygments Documentation
5
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
-
7
- Generates a bunch of html files containing the documentation.
8
-
9
- :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
10
- :license: BSD, see LICENSE for details.
11
- """
12
-
13
- import os
14
- import sys
15
- from datetime import datetime
16
- from cgi import escape
17
-
18
- from docutils import nodes
19
- from docutils.parsers.rst import directives
20
- from docutils.core import publish_parts
21
- from docutils.writers import html4css1
22
-
23
- from jinja2 import Template
24
-
25
- # try to use the right Pygments to build the docs
26
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
27
-
28
- from pygments import highlight, __version__
29
- from pygments.lexers import get_lexer_by_name
30
- from pygments.formatters import HtmlFormatter
31
-
32
-
33
- LEXERDOC = '''
34
- `%s`
35
- %s
36
- :Short names: %s
37
- :Filename patterns: %s
38
- :Mimetypes: %s
39
-
40
- '''
41
-
42
- def generate_lexer_docs():
43
- from pygments.lexers import LEXERS
44
-
45
- out = []
46
-
47
- modules = {}
48
- moduledocstrings = {}
49
- for classname, data in sorted(LEXERS.iteritems(), key=lambda x: x[0]):
50
- module = data[0]
51
- mod = __import__(module, None, None, [classname])
52
- cls = getattr(mod, classname)
53
- if not cls.__doc__:
54
- print "Warning: %s does not have a docstring." % classname
55
- modules.setdefault(module, []).append((
56
- classname,
57
- cls.__doc__,
58
- ', '.join(data[2]) or 'None',
59
- ', '.join(data[3]).replace('*', '\\*').replace('_', '\\') or 'None',
60
- ', '.join(data[4]) or 'None'))
61
- if module not in moduledocstrings:
62
- moduledocstrings[module] = mod.__doc__
63
-
64
- for module, lexers in sorted(modules.iteritems(), key=lambda x: x[0]):
65
- heading = moduledocstrings[module].splitlines()[4].strip().rstrip('.')
66
- out.append('\n' + heading + '\n' + '-'*len(heading) + '\n')
67
- for data in lexers:
68
- out.append(LEXERDOC % data)
69
- return ''.join(out).decode('utf-8')
70
-
71
- def generate_formatter_docs():
72
- from pygments.formatters import FORMATTERS
73
-
74
- out = []
75
- for cls, data in sorted(FORMATTERS.iteritems(),
76
- key=lambda x: x[0].__name__):
77
- heading = cls.__name__
78
- out.append('`' + heading + '`\n' + '-'*(2+len(heading)) + '\n')
79
- out.append(cls.__doc__)
80
- out.append('''
81
- :Short names: %s
82
- :Filename patterns: %s
83
-
84
-
85
- ''' % (', '.join(data[1]) or 'None', ', '.join(data[2]).replace('*', '\\*') or 'None'))
86
- return ''.join(out).decode('utf-8')
87
-
88
- def generate_filter_docs():
89
- from pygments.filters import FILTERS
90
-
91
- out = []
92
- for name, cls in FILTERS.iteritems():
93
- out.append('''
94
- `%s`
95
- %s
96
- :Name: %s
97
- ''' % (cls.__name__, cls.__doc__, name))
98
- return ''.join(out).decode('utf-8')
99
-
100
- def generate_changelog():
101
- fn = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
102
- 'CHANGES'))
103
- f = file(fn)
104
- result = []
105
- in_header = False
106
- header = True
107
- for line in f:
108
- if header:
109
- if not in_header and line.strip():
110
- in_header = True
111
- elif in_header and not line.strip():
112
- header = False
113
- else:
114
- result.append(line.rstrip())
115
- f.close()
116
- return '\n'.join(result).decode('utf-8')
117
-
118
- def generate_authors():
119
- fn = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
120
- 'AUTHORS'))
121
- f = file(fn)
122
- r = f.read().rstrip().decode('utf-8')
123
- f.close()
124
- return r
125
-
126
- LEXERDOCS = generate_lexer_docs()
127
- FORMATTERDOCS = generate_formatter_docs()
128
- FILTERDOCS = generate_filter_docs()
129
- CHANGELOG = generate_changelog()
130
- AUTHORS = generate_authors()
131
-
132
-
133
- PYGMENTS_FORMATTER = HtmlFormatter(style='pastie', cssclass='syntax')
134
-
135
- USAGE = '''\
136
- Usage: %s <mode> <destination> [<source.txt> ...]
137
-
138
- Generate either python or html files out of the documentation.
139
-
140
- Mode can either be python or html.\
141
- ''' % sys.argv[0]
142
-
143
- TEMPLATE = '''\
144
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
145
- "http://www.w3.org/TR/html4/strict.dtd">
146
- <html>
147
- <head>
148
- <title>{{ title }} &mdash; Pygments</title>
149
- <meta http-equiv="content-type" content="text/html; charset=utf-8">
150
- <style type="text/css">
151
- {{ style }}
152
- </style>
153
- </head>
154
- <body>
155
- <div id="content">
156
- <h1 class="heading">Pygments</h1>
157
- <h2 class="subheading">{{ title }}</h2>
158
- {% if file_id != "index" %}
159
- <a id="backlink" href="index.html">&laquo; Back To Index</a>
160
- {% endif %}
161
- {% if toc %}
162
- <div class="toc">
163
- <h2>Contents</h2>
164
- <ul class="contents">
165
- {% for key, value in toc %}
166
- <li><a href="{{ key }}">{{ value }}</a></li>
167
- {% endfor %}
168
- </ul>
169
- </div>
170
- {% endif %}
171
- {{ body }}
172
- </div>
173
- </body>
174
- <!-- generated on: {{ generation_date }}
175
- file id: {{ file_id }} -->
176
- </html>\
177
- '''
178
-
179
- STYLESHEET = '''\
180
- body {
181
- background-color: #f2f2f2;
182
- margin: 0;
183
- padding: 0;
184
- font-family: 'Georgia', serif;
185
- color: #111;
186
- }
187
-
188
- #content {
189
- background-color: white;
190
- padding: 20px;
191
- margin: 20px auto 20px auto;
192
- max-width: 800px;
193
- border: 4px solid #ddd;
194
- }
195
-
196
- h1 {
197
- font-weight: normal;
198
- font-size: 40px;
199
- color: #09839A;
200
- }
201
-
202
- h2 {
203
- font-weight: normal;
204
- font-size: 30px;
205
- color: #C73F00;
206
- }
207
-
208
- h1.heading {
209
- margin: 0 0 30px 0;
210
- }
211
-
212
- h2.subheading {
213
- margin: -30px 0 0 45px;
214
- }
215
-
216
- h3 {
217
- margin-top: 30px;
218
- }
219
-
220
- table.docutils {
221
- border-collapse: collapse;
222
- border: 2px solid #aaa;
223
- margin: 0.5em 1.5em 0.5em 1.5em;
224
- }
225
-
226
- table.docutils td {
227
- padding: 2px;
228
- border: 1px solid #ddd;
229
- }
230
-
231
- p, li, dd, dt, blockquote {
232
- font-size: 15px;
233
- color: #333;
234
- }
235
-
236
- p {
237
- line-height: 150%;
238
- margin-bottom: 0;
239
- margin-top: 10px;
240
- }
241
-
242
- hr {
243
- border-top: 1px solid #ccc;
244
- border-bottom: 0;
245
- border-right: 0;
246
- border-left: 0;
247
- margin-bottom: 10px;
248
- margin-top: 20px;
249
- }
250
-
251
- dl {
252
- margin-left: 10px;
253
- }
254
-
255
- li, dt {
256
- margin-top: 5px;
257
- }
258
-
259
- dt {
260
- font-weight: bold;
261
- }
262
-
263
- th {
264
- text-align: left;
265
- }
266
-
267
- a {
268
- color: #990000;
269
- }
270
-
271
- a:hover {
272
- color: #c73f00;
273
- }
274
-
275
- pre {
276
- background-color: #f9f9f9;
277
- border-top: 1px solid #ccc;
278
- border-bottom: 1px solid #ccc;
279
- padding: 5px;
280
- font-size: 13px;
281
- font-family: Bitstream Vera Sans Mono,monospace;
282
- }
283
-
284
- tt {
285
- font-size: 13px;
286
- font-family: Bitstream Vera Sans Mono,monospace;
287
- color: black;
288
- padding: 1px 2px 1px 2px;
289
- background-color: #f0f0f0;
290
- }
291
-
292
- cite {
293
- /* abusing <cite>, it's generated by ReST for `x` */
294
- font-size: 13px;
295
- font-family: Bitstream Vera Sans Mono,monospace;
296
- font-weight: bold;
297
- font-style: normal;
298
- }
299
-
300
- #backlink {
301
- float: right;
302
- font-size: 11px;
303
- color: #888;
304
- }
305
-
306
- div.toc {
307
- margin: 0 0 10px 0;
308
- }
309
-
310
- div.toc h2 {
311
- font-size: 20px;
312
- }
313
- ''' #'
314
-
315
-
316
- def pygments_directive(name, arguments, options, content, lineno,
317
- content_offset, block_text, state, state_machine):
318
- try:
319
- lexer = get_lexer_by_name(arguments[0])
320
- except ValueError:
321
- # no lexer found
322
- lexer = get_lexer_by_name('text')
323
- parsed = highlight(u'\n'.join(content), lexer, PYGMENTS_FORMATTER)
324
- return [nodes.raw('', parsed, format="html")]
325
- pygments_directive.arguments = (1, 0, 1)
326
- pygments_directive.content = 1
327
- directives.register_directive('sourcecode', pygments_directive)
328
-
329
-
330
- def create_translator(link_style):
331
- class Translator(html4css1.HTMLTranslator):
332
- def visit_reference(self, node):
333
- refuri = node.get('refuri')
334
- if refuri is not None and '/' not in refuri and refuri.endswith('.txt'):
335
- node['refuri'] = link_style(refuri[:-4])
336
- html4css1.HTMLTranslator.visit_reference(self, node)
337
- return Translator
338
-
339
-
340
- class DocumentationWriter(html4css1.Writer):
341
-
342
- def __init__(self, link_style):
343
- html4css1.Writer.__init__(self)
344
- self.translator_class = create_translator(link_style)
345
-
346
- def translate(self):
347
- html4css1.Writer.translate(self)
348
- # generate table of contents
349
- contents = self.build_contents(self.document)
350
- contents_doc = self.document.copy()
351
- contents_doc.children = contents
352
- contents_visitor = self.translator_class(contents_doc)
353
- contents_doc.walkabout(contents_visitor)
354
- self.parts['toc'] = self._generated_toc
355
-
356
- def build_contents(self, node, level=0):
357
- sections = []
358
- i = len(node) - 1
359
- while i >= 0 and isinstance(node[i], nodes.section):
360
- sections.append(node[i])
361
- i -= 1
362
- sections.reverse()
363
- toc = []
364
- for section in sections:
365
- try:
366
- reference = nodes.reference('', '', refid=section['ids'][0], *section[0])
367
- except IndexError:
368
- continue
369
- ref_id = reference['refid']
370
- text = escape(reference.astext())
371
- toc.append((ref_id, text))
372
-
373
- self._generated_toc = [('#%s' % href, caption) for href, caption in toc]
374
- # no further processing
375
- return []
376
-
377
-
378
- def generate_documentation(data, link_style):
379
- writer = DocumentationWriter(link_style)
380
- data = data.replace('[builtin_lexer_docs]', LEXERDOCS).\
381
- replace('[builtin_formatter_docs]', FORMATTERDOCS).\
382
- replace('[builtin_filter_docs]', FILTERDOCS).\
383
- replace('[changelog]', CHANGELOG).\
384
- replace('[authors]', AUTHORS)
385
- parts = publish_parts(
386
- data,
387
- writer=writer,
388
- settings_overrides={
389
- 'initial_header_level': 3,
390
- 'field_name_limit': 50,
391
- }
392
- )
393
- return {
394
- 'title': parts['title'],
395
- 'body': parts['body'],
396
- 'toc': parts['toc']
397
- }
398
-
399
-
400
- def handle_python(filename, fp, dst):
401
- now = datetime.now()
402
- title = os.path.basename(filename)[:-4]
403
- content = fp.read()
404
- def urlize(href):
405
- # create links for the pygments webpage
406
- if href == 'index.txt':
407
- return '/docs/'
408
- else:
409
- return '/docs/%s/' % href
410
- parts = generate_documentation(content, urlize)
411
- result = file(os.path.join(dst, title + '.py'), 'w')
412
- result.write('# -*- coding: utf-8 -*-\n')
413
- result.write('"""\n Pygments Documentation - %s\n' % title)
414
- result.write(' %s\n\n' % ('~' * (24 + len(title))))
415
- result.write(' Generated on: %s\n"""\n\n' % now)
416
- result.write('import datetime\n')
417
- result.write('DATE = %r\n' % now)
418
- result.write('TITLE = %r\n' % parts['title'])
419
- result.write('TOC = %r\n' % parts['toc'])
420
- result.write('BODY = %r\n' % parts['body'])
421
- result.close()
422
-
423
-
424
- def handle_html(filename, fp, dst):
425
- now = datetime.now()
426
- title = os.path.basename(filename)[:-4]
427
- content = fp.read().decode('utf-8')
428
- c = generate_documentation(content, (lambda x: './%s.html' % x))
429
- result = file(os.path.join(dst, title + '.html'), 'w')
430
- c['style'] = STYLESHEET + PYGMENTS_FORMATTER.get_style_defs('.syntax')
431
- c['generation_date'] = now
432
- c['file_id'] = title
433
- t = Template(TEMPLATE)
434
- result.write(t.render(c).encode('utf-8'))
435
- result.close()
436
-
437
-
438
- def run(handle_file, dst, sources=()):
439
- path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))
440
- if not sources:
441
- sources = [os.path.join(path, fn) for fn in os.listdir(path)]
442
- if not os.path.isdir(dst):
443
- os.makedirs(dst)
444
- print 'Making docs for Pygments %s in %s' % (__version__, dst)
445
- for fn in sources:
446
- if not os.path.isfile(fn):
447
- continue
448
- print 'Processing %s' % fn
449
- f = open(fn)
450
- try:
451
- handle_file(fn, f, dst)
452
- finally:
453
- f.close()
454
-
455
-
456
- def main(mode, dst='build/', *sources):
457
- try:
458
- handler = {
459
- 'html': handle_html,
460
- 'python': handle_python
461
- }[mode]
462
- except KeyError:
463
- print 'Error: unknown mode "%s"' % mode
464
- sys.exit(1)
465
- run(handler, os.path.realpath(dst), sources)
466
-
467
-
468
- if __name__ == '__main__':
469
- if len(sys.argv) == 1:
470
- print USAGE
471
- else:
472
- main(*sys.argv[1:])