gitlab-pygments.rb 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/README.md +91 -0
- data/Rakefile +78 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +344 -0
- data/lib/pygments/popen.rb +389 -0
- data/lib/pygments/version.rb +3 -0
- data/lib/pygments.rb +8 -0
- data/pygments.rb.gemspec +24 -0
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +276 -0
- data/vendor/custom_formatters/gitlab.py +171 -0
- data/vendor/custom_lexers/github.py +362 -0
- data/vendor/pygments-main/AUTHORS +115 -0
- data/vendor/pygments-main/CHANGES +762 -0
- data/vendor/pygments-main/LICENSE +25 -0
- data/vendor/pygments-main/MANIFEST.in +6 -0
- data/vendor/pygments-main/Makefile +59 -0
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/TODO +15 -0
- data/vendor/pygments-main/docs/generate.py +472 -0
- data/vendor/pygments-main/docs/pygmentize.1 +94 -0
- data/vendor/pygments-main/docs/src/api.txt +270 -0
- data/vendor/pygments-main/docs/src/authors.txt +5 -0
- data/vendor/pygments-main/docs/src/changelog.txt +5 -0
- data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
- data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
- data/vendor/pygments-main/docs/src/filters.txt +42 -0
- data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
- data/vendor/pygments-main/docs/src/formatters.txt +48 -0
- data/vendor/pygments-main/docs/src/index.txt +69 -0
- data/vendor/pygments-main/docs/src/installation.txt +71 -0
- data/vendor/pygments-main/docs/src/integrate.txt +43 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
- data/vendor/pygments-main/docs/src/lexers.txt +67 -0
- data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
- data/vendor/pygments-main/docs/src/plugins.txt +93 -0
- data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
- data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
- data/vendor/pygments-main/docs/src/styles.txt +143 -0
- data/vendor/pygments-main/docs/src/tokens.txt +349 -0
- data/vendor/pygments-main/docs/src/unicode.txt +49 -0
- data/vendor/pygments-main/external/markdown-processor.py +67 -0
- data/vendor/pygments-main/external/moin-parser.py +112 -0
- data/vendor/pygments-main/external/pygments.bashcomp +38 -0
- data/vendor/pygments-main/external/rst-directive-old.py +77 -0
- data/vendor/pygments-main/external/rst-directive.py +83 -0
- data/vendor/pygments-main/ez_setup.py +276 -0
- data/vendor/pygments-main/pygmentize +7 -0
- data/vendor/pygments-main/pygments/__init__.py +91 -0
- data/vendor/pygments-main/pygments/cmdline.py +433 -0
- data/vendor/pygments-main/pygments/console.py +74 -0
- data/vendor/pygments-main/pygments/filter.py +74 -0
- data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
- data/vendor/pygments-main/pygments/formatter.py +92 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
- data/vendor/pygments-main/pygments/formatters/html.py +750 -0
- data/vendor/pygments-main/pygments/formatters/img.py +553 -0
- data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
- data/vendor/pygments-main/pygments/formatters/other.py +117 -0
- data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
- data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
- data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
- data/vendor/pygments-main/pygments/lexer.py +697 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
- data/vendor/pygments-main/pygments/lexers/github.py +362 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
- data/vendor/pygments-main/pygments/lexers/special.py +100 -0
- data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
- data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
- data/vendor/pygments-main/pygments/plugin.py +74 -0
- data/vendor/pygments-main/pygments/scanner.py +104 -0
- data/vendor/pygments-main/pygments/style.py +117 -0
- data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
- data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
- data/vendor/pygments-main/pygments/styles/borland.py +51 -0
- data/vendor/pygments-main/pygments/styles/bw.py +49 -0
- data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
- data/vendor/pygments-main/pygments/styles/default.py +73 -0
- data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
- data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
- data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
- data/vendor/pygments-main/pygments/styles/manni.py +75 -0
- data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
- data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
- data/vendor/pygments-main/pygments/styles/native.py +65 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
- data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +141 -0
- data/vendor/pygments-main/pygments/styles/trac.py +63 -0
- data/vendor/pygments-main/pygments/styles/vim.py +63 -0
- data/vendor/pygments-main/pygments/styles/vs.py +38 -0
- data/vendor/pygments-main/pygments/token.py +195 -0
- data/vendor/pygments-main/pygments/unistring.py +130 -0
- data/vendor/pygments-main/pygments/util.py +232 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
- data/vendor/pygments-main/scripts/epydoc.css +280 -0
- data/vendor/pygments-main/scripts/find_codetags.py +205 -0
- data/vendor/pygments-main/scripts/find_error.py +171 -0
- data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
- data/vendor/pygments-main/scripts/pylintrc +301 -0
- data/vendor/pygments-main/scripts/reindent.py +291 -0
- data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
- data/vendor/pygments-main/setup.cfg +6 -0
- data/vendor/pygments-main/setup.py +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
- data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
- data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
- data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
- data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
- data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
- data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
- data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
- data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
- data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
- data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
- data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
- data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
- data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
- data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
- data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
- data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
- data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
- data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
- data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
- data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
- data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
- data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
- data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
- data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
- data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
- data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
- data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
- data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
- data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
- data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
- data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
- data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
- data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
- data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
- data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
- data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
- data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
- data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
- data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
- data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
- data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
- data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
- data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
- data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
- data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
- data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
- data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
- data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
- data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
- data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
- data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
- data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
- data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
- data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
- data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
- data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
- data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
- data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
- data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
- data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
- data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
- data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
- data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
- data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
- data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
- data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
- data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
- data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
- data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
- data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
- data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
- data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
- data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
- data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
- data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
- data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
- data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
- data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
- data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
- data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
- data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
- data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
- data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
- data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
- data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
- data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
- data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
- data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
- data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
- data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
- data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
- data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
- data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
- data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
- data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
- data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
- data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
- data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
- data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
- data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
- data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
- data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
- data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
- data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
- data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
- data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
- data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
- data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
- data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
- data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
- data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
- data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
- data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
- data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
- data/vendor/pygments-main/tests/old_run.py +138 -0
- data/vendor/pygments-main/tests/run.py +48 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/test_basic_api.py +294 -0
- data/vendor/pygments-main/tests/test_clexer.py +31 -0
- data/vendor/pygments-main/tests/test_cmdline.py +105 -0
- data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
- data/vendor/pygments-main/tests/test_token.py +46 -0
- data/vendor/pygments-main/tests/test_using_api.py +40 -0
- data/vendor/pygments-main/tests/test_util.py +116 -0
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +492 -0
@@ -0,0 +1,378 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.latex
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Formatter for LaTeX fancyvrb output.
|
7
|
+
|
8
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
9
|
+
:license: BSD, see LICENSE for details.
|
10
|
+
"""
|
11
|
+
|
12
|
+
from pygments.formatter import Formatter
|
13
|
+
from pygments.token import Token, STANDARD_TYPES
|
14
|
+
from pygments.util import get_bool_opt, get_int_opt, StringIO
|
15
|
+
|
16
|
+
|
17
|
+
__all__ = ['LatexFormatter']
|
18
|
+
|
19
|
+
|
20
|
+
def escape_tex(text, commandprefix):
|
21
|
+
return text.replace('\\', '\x00'). \
|
22
|
+
replace('{', '\x01'). \
|
23
|
+
replace('}', '\x02'). \
|
24
|
+
replace('\x00', r'\%sZbs{}' % commandprefix). \
|
25
|
+
replace('\x01', r'\%sZob{}' % commandprefix). \
|
26
|
+
replace('\x02', r'\%sZcb{}' % commandprefix). \
|
27
|
+
replace('^', r'\%sZca{}' % commandprefix). \
|
28
|
+
replace('_', r'\%sZus{}' % commandprefix). \
|
29
|
+
replace('&', r'\%sZam{}' % commandprefix). \
|
30
|
+
replace('<', r'\%sZlt{}' % commandprefix). \
|
31
|
+
replace('>', r'\%sZgt{}' % commandprefix). \
|
32
|
+
replace('#', r'\%sZsh{}' % commandprefix). \
|
33
|
+
replace('%', r'\%sZpc{}' % commandprefix). \
|
34
|
+
replace('$', r'\%sZdl{}' % commandprefix). \
|
35
|
+
replace('-', r'\%sZhy{}' % commandprefix). \
|
36
|
+
replace("'", r'\%sZsq{}' % commandprefix). \
|
37
|
+
replace('"', r'\%sZdq{}' % commandprefix). \
|
38
|
+
replace('~', r'\%sZti{}' % commandprefix)
|
39
|
+
|
40
|
+
|
41
|
+
DOC_TEMPLATE = r'''
|
42
|
+
\documentclass{%(docclass)s}
|
43
|
+
\usepackage{fancyvrb}
|
44
|
+
\usepackage{color}
|
45
|
+
\usepackage[%(encoding)s]{inputenc}
|
46
|
+
%(preamble)s
|
47
|
+
|
48
|
+
%(styledefs)s
|
49
|
+
|
50
|
+
\begin{document}
|
51
|
+
|
52
|
+
\section*{%(title)s}
|
53
|
+
|
54
|
+
%(code)s
|
55
|
+
\end{document}
|
56
|
+
'''
|
57
|
+
|
58
|
+
## Small explanation of the mess below :)
|
59
|
+
#
|
60
|
+
# The previous version of the LaTeX formatter just assigned a command to
|
61
|
+
# each token type defined in the current style. That obviously is
|
62
|
+
# problematic if the highlighted code is produced for a different style
|
63
|
+
# than the style commands themselves.
|
64
|
+
#
|
65
|
+
# This version works much like the HTML formatter which assigns multiple
|
66
|
+
# CSS classes to each <span> tag, from the most specific to the least
|
67
|
+
# specific token type, thus falling back to the parent token type if one
|
68
|
+
# is not defined. Here, the classes are there too and use the same short
|
69
|
+
# forms given in token.STANDARD_TYPES.
|
70
|
+
#
|
71
|
+
# Highlighted code now only uses one custom command, which by default is
|
72
|
+
# \PY and selectable by the commandprefix option (and in addition the
|
73
|
+
# escapes \PYZat, \PYZlb and \PYZrb which haven't been renamed for
|
74
|
+
# backwards compatibility purposes).
|
75
|
+
#
|
76
|
+
# \PY has two arguments: the classes, separated by +, and the text to
|
77
|
+
# render in that style. The classes are resolved into the respective
|
78
|
+
# style commands by magic, which serves to ignore unknown classes.
|
79
|
+
#
|
80
|
+
# The magic macros are:
|
81
|
+
# * \PY@it, \PY@bf, etc. are unconditionally wrapped around the text
|
82
|
+
# to render in \PY@do. Their definition determines the style.
|
83
|
+
# * \PY@reset resets \PY@it etc. to do nothing.
|
84
|
+
# * \PY@toks parses the list of classes, using magic inspired by the
|
85
|
+
# keyval package (but modified to use plusses instead of commas
|
86
|
+
# because fancyvrb redefines commas inside its environments).
|
87
|
+
# * \PY@tok processes one class, calling the \PY@tok@classname command
|
88
|
+
# if it exists.
|
89
|
+
# * \PY@tok@classname sets the \PY@it etc. to reflect the chosen style
|
90
|
+
# for its class.
|
91
|
+
# * \PY resets the style, parses the classnames and then calls \PY@do.
|
92
|
+
#
|
93
|
+
# Tip: to read this code, print it out in substituted form using e.g.
|
94
|
+
# >>> print STYLE_TEMPLATE % {'cp': 'PY'}
|
95
|
+
|
96
|
+
STYLE_TEMPLATE = r'''
|
97
|
+
\makeatletter
|
98
|
+
\def\%(cp)s@reset{\let\%(cp)s@it=\relax \let\%(cp)s@bf=\relax%%
|
99
|
+
\let\%(cp)s@ul=\relax \let\%(cp)s@tc=\relax%%
|
100
|
+
\let\%(cp)s@bc=\relax \let\%(cp)s@ff=\relax}
|
101
|
+
\def\%(cp)s@tok#1{\csname %(cp)s@tok@#1\endcsname}
|
102
|
+
\def\%(cp)s@toks#1+{\ifx\relax#1\empty\else%%
|
103
|
+
\%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
|
104
|
+
\def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%%
|
105
|
+
\%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}}
|
106
|
+
\def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
|
107
|
+
|
108
|
+
%(styles)s
|
109
|
+
|
110
|
+
\def\%(cp)sZbs{\char`\\}
|
111
|
+
\def\%(cp)sZus{\char`\_}
|
112
|
+
\def\%(cp)sZob{\char`\{}
|
113
|
+
\def\%(cp)sZcb{\char`\}}
|
114
|
+
\def\%(cp)sZca{\char`\^}
|
115
|
+
\def\%(cp)sZam{\char`\&}
|
116
|
+
\def\%(cp)sZlt{\char`\<}
|
117
|
+
\def\%(cp)sZgt{\char`\>}
|
118
|
+
\def\%(cp)sZsh{\char`\#}
|
119
|
+
\def\%(cp)sZpc{\char`\%%}
|
120
|
+
\def\%(cp)sZdl{\char`\$}
|
121
|
+
\def\%(cp)sZhy{\char`\-}
|
122
|
+
\def\%(cp)sZsq{\char`\'}
|
123
|
+
\def\%(cp)sZdq{\char`\"}
|
124
|
+
\def\%(cp)sZti{\char`\~}
|
125
|
+
%% for compatibility with earlier versions
|
126
|
+
\def\%(cp)sZat{@}
|
127
|
+
\def\%(cp)sZlb{[}
|
128
|
+
\def\%(cp)sZrb{]}
|
129
|
+
\makeatother
|
130
|
+
'''
|
131
|
+
|
132
|
+
|
133
|
+
def _get_ttype_name(ttype):
|
134
|
+
fname = STANDARD_TYPES.get(ttype)
|
135
|
+
if fname:
|
136
|
+
return fname
|
137
|
+
aname = ''
|
138
|
+
while fname is None:
|
139
|
+
aname = ttype[-1] + aname
|
140
|
+
ttype = ttype.parent
|
141
|
+
fname = STANDARD_TYPES.get(ttype)
|
142
|
+
return fname + aname
|
143
|
+
|
144
|
+
|
145
|
+
class LatexFormatter(Formatter):
|
146
|
+
r"""
|
147
|
+
Format tokens as LaTeX code. This needs the `fancyvrb` and `color`
|
148
|
+
standard packages.
|
149
|
+
|
150
|
+
Without the `full` option, code is formatted as one ``Verbatim``
|
151
|
+
environment, like this:
|
152
|
+
|
153
|
+
.. sourcecode:: latex
|
154
|
+
|
155
|
+
\begin{Verbatim}[commandchars=\\{\}]
|
156
|
+
\PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
|
157
|
+
\PY{k}{pass}
|
158
|
+
\end{Verbatim}
|
159
|
+
|
160
|
+
The special command used here (``\PY``) and all the other macros it needs
|
161
|
+
are output by the `get_style_defs` method.
|
162
|
+
|
163
|
+
With the `full` option, a complete LaTeX document is output, including
|
164
|
+
the command definitions in the preamble.
|
165
|
+
|
166
|
+
The `get_style_defs()` method of a `LatexFormatter` returns a string
|
167
|
+
containing ``\def`` commands defining the macros needed inside the
|
168
|
+
``Verbatim`` environments.
|
169
|
+
|
170
|
+
Additional options accepted:
|
171
|
+
|
172
|
+
`style`
|
173
|
+
The style to use, can be a string or a Style subclass (default:
|
174
|
+
``'default'``).
|
175
|
+
|
176
|
+
`full`
|
177
|
+
Tells the formatter to output a "full" document, i.e. a complete
|
178
|
+
self-contained document (default: ``False``).
|
179
|
+
|
180
|
+
`title`
|
181
|
+
If `full` is true, the title that should be used to caption the
|
182
|
+
document (default: ``''``).
|
183
|
+
|
184
|
+
`docclass`
|
185
|
+
If the `full` option is enabled, this is the document class to use
|
186
|
+
(default: ``'article'``).
|
187
|
+
|
188
|
+
`preamble`
|
189
|
+
If the `full` option is enabled, this can be further preamble commands,
|
190
|
+
e.g. ``\usepackage`` (default: ``''``).
|
191
|
+
|
192
|
+
`linenos`
|
193
|
+
If set to ``True``, output line numbers (default: ``False``).
|
194
|
+
|
195
|
+
`linenostart`
|
196
|
+
The line number for the first line (default: ``1``).
|
197
|
+
|
198
|
+
`linenostep`
|
199
|
+
If set to a number n > 1, only every nth line number is printed.
|
200
|
+
|
201
|
+
`verboptions`
|
202
|
+
Additional options given to the Verbatim environment (see the *fancyvrb*
|
203
|
+
docs for possible values) (default: ``''``).
|
204
|
+
|
205
|
+
`commandprefix`
|
206
|
+
The LaTeX commands used to produce colored output are constructed
|
207
|
+
using this prefix and some letters (default: ``'PY'``).
|
208
|
+
*New in Pygments 0.7.*
|
209
|
+
|
210
|
+
*New in Pygments 0.10:* the default is now ``'PY'`` instead of ``'C'``.
|
211
|
+
|
212
|
+
`texcomments`
|
213
|
+
If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
|
214
|
+
in comment tokens is not escaped so that LaTeX can render it (default:
|
215
|
+
``False``). *New in Pygments 1.2.*
|
216
|
+
|
217
|
+
`mathescape`
|
218
|
+
If set to ``True``, enables LaTeX math mode escape in comments. That
|
219
|
+
is, ``'$...$'`` inside a comment will trigger math mode (default:
|
220
|
+
``False``). *New in Pygments 1.2.*
|
221
|
+
"""
|
222
|
+
name = 'LaTeX'
|
223
|
+
aliases = ['latex', 'tex']
|
224
|
+
filenames = ['*.tex']
|
225
|
+
|
226
|
+
def __init__(self, **options):
|
227
|
+
Formatter.__init__(self, **options)
|
228
|
+
self.docclass = options.get('docclass', 'article')
|
229
|
+
self.preamble = options.get('preamble', '')
|
230
|
+
self.linenos = get_bool_opt(options, 'linenos', False)
|
231
|
+
self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
|
232
|
+
self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
|
233
|
+
self.verboptions = options.get('verboptions', '')
|
234
|
+
self.nobackground = get_bool_opt(options, 'nobackground', False)
|
235
|
+
self.commandprefix = options.get('commandprefix', 'PY')
|
236
|
+
self.texcomments = get_bool_opt(options, 'texcomments', False)
|
237
|
+
self.mathescape = get_bool_opt(options, 'mathescape', False)
|
238
|
+
|
239
|
+
self._create_stylesheet()
|
240
|
+
|
241
|
+
|
242
|
+
def _create_stylesheet(self):
|
243
|
+
t2n = self.ttype2name = {Token: ''}
|
244
|
+
c2d = self.cmd2def = {}
|
245
|
+
cp = self.commandprefix
|
246
|
+
|
247
|
+
def rgbcolor(col):
|
248
|
+
if col:
|
249
|
+
return ','.join(['%.2f' %(int(col[i] + col[i + 1], 16) / 255.0)
|
250
|
+
for i in (0, 2, 4)])
|
251
|
+
else:
|
252
|
+
return '1,1,1'
|
253
|
+
|
254
|
+
for ttype, ndef in self.style:
|
255
|
+
name = _get_ttype_name(ttype)
|
256
|
+
cmndef = ''
|
257
|
+
if ndef['bold']:
|
258
|
+
cmndef += r'\let\$$@bf=\textbf'
|
259
|
+
if ndef['italic']:
|
260
|
+
cmndef += r'\let\$$@it=\textit'
|
261
|
+
if ndef['underline']:
|
262
|
+
cmndef += r'\let\$$@ul=\underline'
|
263
|
+
if ndef['roman']:
|
264
|
+
cmndef += r'\let\$$@ff=\textrm'
|
265
|
+
if ndef['sans']:
|
266
|
+
cmndef += r'\let\$$@ff=\textsf'
|
267
|
+
if ndef['mono']:
|
268
|
+
cmndef += r'\let\$$@ff=\textsf'
|
269
|
+
if ndef['color']:
|
270
|
+
cmndef += (r'\def\$$@tc##1{\textcolor[rgb]{%s}{##1}}' %
|
271
|
+
rgbcolor(ndef['color']))
|
272
|
+
if ndef['border']:
|
273
|
+
cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
|
274
|
+
r'\fcolorbox[rgb]{%s}{%s}{\strut ##1}}' %
|
275
|
+
(rgbcolor(ndef['border']),
|
276
|
+
rgbcolor(ndef['bgcolor'])))
|
277
|
+
elif ndef['bgcolor']:
|
278
|
+
cmndef += (r'\def\$$@bc##1{\setlength{\fboxsep}{0pt}'
|
279
|
+
r'\colorbox[rgb]{%s}{\strut ##1}}' %
|
280
|
+
rgbcolor(ndef['bgcolor']))
|
281
|
+
if cmndef == '':
|
282
|
+
continue
|
283
|
+
cmndef = cmndef.replace('$$', cp)
|
284
|
+
t2n[ttype] = name
|
285
|
+
c2d[name] = cmndef
|
286
|
+
|
287
|
+
def get_style_defs(self, arg=''):
|
288
|
+
"""
|
289
|
+
Return the command sequences needed to define the commands
|
290
|
+
used to format text in the verbatim environment. ``arg`` is ignored.
|
291
|
+
"""
|
292
|
+
cp = self.commandprefix
|
293
|
+
styles = []
|
294
|
+
for name, definition in self.cmd2def.iteritems():
|
295
|
+
styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
|
296
|
+
(cp, name, definition))
|
297
|
+
return STYLE_TEMPLATE % {'cp': self.commandprefix,
|
298
|
+
'styles': '\n'.join(styles)}
|
299
|
+
|
300
|
+
def format_unencoded(self, tokensource, outfile):
|
301
|
+
# TODO: add support for background colors
|
302
|
+
t2n = self.ttype2name
|
303
|
+
cp = self.commandprefix
|
304
|
+
|
305
|
+
if self.full:
|
306
|
+
realoutfile = outfile
|
307
|
+
outfile = StringIO()
|
308
|
+
|
309
|
+
outfile.write(r'\begin{Verbatim}[commandchars=\\\{\}')
|
310
|
+
if self.linenos:
|
311
|
+
start, step = self.linenostart, self.linenostep
|
312
|
+
outfile.write(',numbers=left' +
|
313
|
+
(start and ',firstnumber=%d' % start or '') +
|
314
|
+
(step and ',stepnumber=%d' % step or ''))
|
315
|
+
if self.mathescape or self.texcomments:
|
316
|
+
outfile.write(r',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
|
317
|
+
if self.verboptions:
|
318
|
+
outfile.write(',' + self.verboptions)
|
319
|
+
outfile.write(']\n')
|
320
|
+
|
321
|
+
for ttype, value in tokensource:
|
322
|
+
if ttype in Token.Comment:
|
323
|
+
if self.texcomments:
|
324
|
+
# Try to guess comment starting lexeme and escape it ...
|
325
|
+
start = value[0:1]
|
326
|
+
for i in xrange(1, len(value)):
|
327
|
+
if start[0] != value[i]:
|
328
|
+
break
|
329
|
+
start += value[i]
|
330
|
+
|
331
|
+
value = value[len(start):]
|
332
|
+
start = escape_tex(start, self.commandprefix)
|
333
|
+
|
334
|
+
# ... but do not escape inside comment.
|
335
|
+
value = start + value
|
336
|
+
elif self.mathescape:
|
337
|
+
# Only escape parts not inside a math environment.
|
338
|
+
parts = value.split('$')
|
339
|
+
in_math = False
|
340
|
+
for i, part in enumerate(parts):
|
341
|
+
if not in_math:
|
342
|
+
parts[i] = escape_tex(part, self.commandprefix)
|
343
|
+
in_math = not in_math
|
344
|
+
value = '$'.join(parts)
|
345
|
+
else:
|
346
|
+
value = escape_tex(value, self.commandprefix)
|
347
|
+
else:
|
348
|
+
value = escape_tex(value, self.commandprefix)
|
349
|
+
styles = []
|
350
|
+
while ttype is not Token:
|
351
|
+
try:
|
352
|
+
styles.append(t2n[ttype])
|
353
|
+
except KeyError:
|
354
|
+
# not in current style
|
355
|
+
styles.append(_get_ttype_name(ttype))
|
356
|
+
ttype = ttype.parent
|
357
|
+
styleval = '+'.join(reversed(styles))
|
358
|
+
if styleval:
|
359
|
+
spl = value.split('\n')
|
360
|
+
for line in spl[:-1]:
|
361
|
+
if line:
|
362
|
+
outfile.write("\\%s{%s}{%s}" % (cp, styleval, line))
|
363
|
+
outfile.write('\n')
|
364
|
+
if spl[-1]:
|
365
|
+
outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1]))
|
366
|
+
else:
|
367
|
+
outfile.write(value)
|
368
|
+
|
369
|
+
outfile.write('\\end{Verbatim}\n')
|
370
|
+
|
371
|
+
if self.full:
|
372
|
+
realoutfile.write(DOC_TEMPLATE %
|
373
|
+
dict(docclass = self.docclass,
|
374
|
+
preamble = self.preamble,
|
375
|
+
title = self.title,
|
376
|
+
encoding = self.encoding or 'latin1',
|
377
|
+
styledefs = self.get_style_defs(),
|
378
|
+
code = outfile.getvalue()))
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.other
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Other formatters: NullFormatter, RawTokenFormatter.
|
7
|
+
|
8
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
9
|
+
:license: BSD, see LICENSE for details.
|
10
|
+
"""
|
11
|
+
|
12
|
+
from pygments.formatter import Formatter
|
13
|
+
from pygments.util import OptionError, get_choice_opt, b
|
14
|
+
from pygments.token import Token
|
15
|
+
from pygments.console import colorize
|
16
|
+
|
17
|
+
__all__ = ['NullFormatter', 'RawTokenFormatter']
|
18
|
+
|
19
|
+
|
20
|
+
class NullFormatter(Formatter):
|
21
|
+
"""
|
22
|
+
Output the text unchanged without any formatting.
|
23
|
+
"""
|
24
|
+
name = 'Text only'
|
25
|
+
aliases = ['text', 'null']
|
26
|
+
filenames = ['*.txt']
|
27
|
+
|
28
|
+
def format(self, tokensource, outfile):
|
29
|
+
enc = self.encoding
|
30
|
+
for ttype, value in tokensource:
|
31
|
+
if enc:
|
32
|
+
outfile.write(value.encode(enc))
|
33
|
+
else:
|
34
|
+
outfile.write(value)
|
35
|
+
|
36
|
+
|
37
|
+
class RawTokenFormatter(Formatter):
|
38
|
+
r"""
|
39
|
+
Format tokens as a raw representation for storing token streams.
|
40
|
+
|
41
|
+
The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later
|
42
|
+
be converted to a token stream with the `RawTokenLexer`, described in the
|
43
|
+
`lexer list <lexers.txt>`_.
|
44
|
+
|
45
|
+
Only two options are accepted:
|
46
|
+
|
47
|
+
`compress`
|
48
|
+
If set to ``'gz'`` or ``'bz2'``, compress the output with the given
|
49
|
+
compression algorithm after encoding (default: ``''``).
|
50
|
+
`error_color`
|
51
|
+
If set to a color name, highlight error tokens using that color. If
|
52
|
+
set but with no value, defaults to ``'red'``.
|
53
|
+
*New in Pygments 0.11.*
|
54
|
+
|
55
|
+
"""
|
56
|
+
name = 'Raw tokens'
|
57
|
+
aliases = ['raw', 'tokens']
|
58
|
+
filenames = ['*.raw']
|
59
|
+
|
60
|
+
unicodeoutput = False
|
61
|
+
|
62
|
+
def __init__(self, **options):
|
63
|
+
Formatter.__init__(self, **options)
|
64
|
+
if self.encoding:
|
65
|
+
raise OptionError('the raw formatter does not support the '
|
66
|
+
'encoding option')
|
67
|
+
self.encoding = 'ascii' # let pygments.format() do the right thing
|
68
|
+
self.compress = get_choice_opt(options, 'compress',
|
69
|
+
['', 'none', 'gz', 'bz2'], '')
|
70
|
+
self.error_color = options.get('error_color', None)
|
71
|
+
if self.error_color is True:
|
72
|
+
self.error_color = 'red'
|
73
|
+
if self.error_color is not None:
|
74
|
+
try:
|
75
|
+
colorize(self.error_color, '')
|
76
|
+
except KeyError:
|
77
|
+
raise ValueError("Invalid color %r specified" %
|
78
|
+
self.error_color)
|
79
|
+
|
80
|
+
def format(self, tokensource, outfile):
|
81
|
+
try:
|
82
|
+
outfile.write(b(''))
|
83
|
+
except TypeError:
|
84
|
+
raise TypeError('The raw tokens formatter needs a binary '
|
85
|
+
'output file')
|
86
|
+
if self.compress == 'gz':
|
87
|
+
import gzip
|
88
|
+
outfile = gzip.GzipFile('', 'wb', 9, outfile)
|
89
|
+
def write(text):
|
90
|
+
outfile.write(text.encode())
|
91
|
+
flush = outfile.flush
|
92
|
+
elif self.compress == 'bz2':
|
93
|
+
import bz2
|
94
|
+
compressor = bz2.BZ2Compressor(9)
|
95
|
+
def write(text):
|
96
|
+
outfile.write(compressor.compress(text.encode()))
|
97
|
+
def flush():
|
98
|
+
outfile.write(compressor.flush())
|
99
|
+
outfile.flush()
|
100
|
+
else:
|
101
|
+
def write(text):
|
102
|
+
outfile.write(text.encode())
|
103
|
+
flush = outfile.flush
|
104
|
+
|
105
|
+
lasttype = None
|
106
|
+
lastval = u''
|
107
|
+
if self.error_color:
|
108
|
+
for ttype, value in tokensource:
|
109
|
+
line = "%s\t%r\n" % (ttype, value)
|
110
|
+
if ttype is Token.Error:
|
111
|
+
write(colorize(self.error_color, line))
|
112
|
+
else:
|
113
|
+
write(line)
|
114
|
+
else:
|
115
|
+
for ttype, value in tokensource:
|
116
|
+
write("%s\t%r\n" % (ttype, value))
|
117
|
+
flush()
|