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,136 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.rtf
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
A formatter that generates RTF files.
|
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
|
+
|
14
|
+
|
15
|
+
__all__ = ['RtfFormatter']
|
16
|
+
|
17
|
+
|
18
|
+
class RtfFormatter(Formatter):
|
19
|
+
"""
|
20
|
+
Format tokens as RTF markup. This formatter automatically outputs full RTF
|
21
|
+
documents with color information and other useful stuff. Perfect for Copy and
|
22
|
+
Paste into Microsoft® Word® documents.
|
23
|
+
|
24
|
+
*New in Pygments 0.6.*
|
25
|
+
|
26
|
+
Additional options accepted:
|
27
|
+
|
28
|
+
`style`
|
29
|
+
The style to use, can be a string or a Style subclass (default:
|
30
|
+
``'default'``).
|
31
|
+
|
32
|
+
`fontface`
|
33
|
+
The used font famliy, for example ``Bitstream Vera Sans``. Defaults to
|
34
|
+
some generic font which is supposed to have fixed width.
|
35
|
+
"""
|
36
|
+
name = 'RTF'
|
37
|
+
aliases = ['rtf']
|
38
|
+
filenames = ['*.rtf']
|
39
|
+
|
40
|
+
unicodeoutput = False
|
41
|
+
|
42
|
+
def __init__(self, **options):
|
43
|
+
"""
|
44
|
+
Additional options accepted:
|
45
|
+
|
46
|
+
``fontface``
|
47
|
+
Name of the font used. Could for example be ``'Courier New'``
|
48
|
+
to further specify the default which is ``'\fmodern'``. The RTF
|
49
|
+
specification claims that ``\fmodern`` are "Fixed-pitch serif
|
50
|
+
and sans serif fonts". Hope every RTF implementation thinks
|
51
|
+
the same about modern...
|
52
|
+
"""
|
53
|
+
Formatter.__init__(self, **options)
|
54
|
+
self.fontface = options.get('fontface') or ''
|
55
|
+
|
56
|
+
def _escape(self, text):
|
57
|
+
return text.replace('\\', '\\\\') \
|
58
|
+
.replace('{', '\\{') \
|
59
|
+
.replace('}', '\\}')
|
60
|
+
|
61
|
+
def _escape_text(self, text):
|
62
|
+
# empty strings, should give a small performance improvment
|
63
|
+
if not text:
|
64
|
+
return ''
|
65
|
+
|
66
|
+
# escape text
|
67
|
+
text = self._escape(text)
|
68
|
+
if self.encoding in ('utf-8', 'utf-16', 'utf-32'):
|
69
|
+
encoding = 'iso-8859-15'
|
70
|
+
else:
|
71
|
+
encoding = self.encoding or 'iso-8859-15'
|
72
|
+
|
73
|
+
buf = []
|
74
|
+
for c in text:
|
75
|
+
if ord(c) > 128:
|
76
|
+
ansic = c.encode(encoding, 'ignore') or '?'
|
77
|
+
if ord(ansic) > 128:
|
78
|
+
ansic = '\\\'%x' % ord(ansic)
|
79
|
+
else:
|
80
|
+
ansic = c
|
81
|
+
buf.append(r'\ud{\u%d%s}' % (ord(c), ansic))
|
82
|
+
else:
|
83
|
+
buf.append(str(c))
|
84
|
+
|
85
|
+
return ''.join(buf).replace('\n', '\\par\n')
|
86
|
+
|
87
|
+
def format_unencoded(self, tokensource, outfile):
|
88
|
+
# rtf 1.8 header
|
89
|
+
outfile.write(r'{\rtf1\ansi\deff0'
|
90
|
+
r'{\fonttbl{\f0\fmodern\fprq1\fcharset0%s;}}'
|
91
|
+
r'{\colortbl;' % (self.fontface and
|
92
|
+
' ' + self._escape(self.fontface) or
|
93
|
+
''))
|
94
|
+
|
95
|
+
# convert colors and save them in a mapping to access them later.
|
96
|
+
color_mapping = {}
|
97
|
+
offset = 1
|
98
|
+
for _, style in self.style:
|
99
|
+
for color in style['color'], style['bgcolor'], style['border']:
|
100
|
+
if color and color not in color_mapping:
|
101
|
+
color_mapping[color] = offset
|
102
|
+
outfile.write(r'\red%d\green%d\blue%d;' % (
|
103
|
+
int(color[0:2], 16),
|
104
|
+
int(color[2:4], 16),
|
105
|
+
int(color[4:6], 16)
|
106
|
+
))
|
107
|
+
offset += 1
|
108
|
+
outfile.write(r'}\f0')
|
109
|
+
|
110
|
+
# highlight stream
|
111
|
+
for ttype, value in tokensource:
|
112
|
+
while not self.style.styles_token(ttype) and ttype.parent:
|
113
|
+
ttype = ttype.parent
|
114
|
+
style = self.style.style_for_token(ttype)
|
115
|
+
buf = []
|
116
|
+
if style['bgcolor']:
|
117
|
+
buf.append(r'\cb%d' % color_mapping[style['bgcolor']])
|
118
|
+
if style['color']:
|
119
|
+
buf.append(r'\cf%d' % color_mapping[style['color']])
|
120
|
+
if style['bold']:
|
121
|
+
buf.append(r'\b')
|
122
|
+
if style['italic']:
|
123
|
+
buf.append(r'\i')
|
124
|
+
if style['underline']:
|
125
|
+
buf.append(r'\ul')
|
126
|
+
if style['border']:
|
127
|
+
buf.append(r'\chbrdr\chcfpat%d' %
|
128
|
+
color_mapping[style['border']])
|
129
|
+
start = ''.join(buf)
|
130
|
+
if start:
|
131
|
+
outfile.write('{%s ' % start)
|
132
|
+
outfile.write(self._escape_text(value))
|
133
|
+
if start:
|
134
|
+
outfile.write('}')
|
135
|
+
|
136
|
+
outfile.write('}')
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.svg
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Formatter for SVG 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.util import get_bool_opt, get_int_opt
|
14
|
+
|
15
|
+
__all__ = ['SvgFormatter']
|
16
|
+
|
17
|
+
|
18
|
+
def escape_html(text):
|
19
|
+
"""Escape &, <, > as well as single and double quotes for HTML."""
|
20
|
+
return text.replace('&', '&'). \
|
21
|
+
replace('<', '<'). \
|
22
|
+
replace('>', '>'). \
|
23
|
+
replace('"', '"'). \
|
24
|
+
replace("'", ''')
|
25
|
+
|
26
|
+
|
27
|
+
class2style = {}
|
28
|
+
|
29
|
+
class SvgFormatter(Formatter):
|
30
|
+
"""
|
31
|
+
Format tokens as an SVG graphics file. This formatter is still experimental.
|
32
|
+
Each line of code is a ``<text>`` element with explicit ``x`` and ``y``
|
33
|
+
coordinates containing ``<tspan>`` elements with the individual token styles.
|
34
|
+
|
35
|
+
By default, this formatter outputs a full SVG document including doctype
|
36
|
+
declaration and the ``<svg>`` root element.
|
37
|
+
|
38
|
+
*New in Pygments 0.9.*
|
39
|
+
|
40
|
+
Additional options accepted:
|
41
|
+
|
42
|
+
`nowrap`
|
43
|
+
Don't wrap the SVG ``<text>`` elements in ``<svg><g>`` elements and
|
44
|
+
don't add a XML declaration and a doctype. If true, the `fontfamily`
|
45
|
+
and `fontsize` options are ignored. Defaults to ``False``.
|
46
|
+
|
47
|
+
`fontfamily`
|
48
|
+
The value to give the wrapping ``<g>`` element's ``font-family``
|
49
|
+
attribute, defaults to ``"monospace"``.
|
50
|
+
|
51
|
+
`fontsize`
|
52
|
+
The value to give the wrapping ``<g>`` element's ``font-size``
|
53
|
+
attribute, defaults to ``"14px"``.
|
54
|
+
|
55
|
+
`xoffset`
|
56
|
+
Starting offset in X direction, defaults to ``0``.
|
57
|
+
|
58
|
+
`yoffset`
|
59
|
+
Starting offset in Y direction, defaults to the font size if it is given
|
60
|
+
in pixels, or ``20`` else. (This is necessary since text coordinates
|
61
|
+
refer to the text baseline, not the top edge.)
|
62
|
+
|
63
|
+
`ystep`
|
64
|
+
Offset to add to the Y coordinate for each subsequent line. This should
|
65
|
+
roughly be the text size plus 5. It defaults to that value if the text
|
66
|
+
size is given in pixels, or ``25`` else.
|
67
|
+
|
68
|
+
`spacehack`
|
69
|
+
Convert spaces in the source to `` ``, which are non-breaking
|
70
|
+
spaces. SVG provides the ``xml:space`` attribute to control how
|
71
|
+
whitespace inside tags is handled, in theory, the ``preserve`` value
|
72
|
+
could be used to keep all whitespace as-is. However, many current SVG
|
73
|
+
viewers don't obey that rule, so this option is provided as a workaround
|
74
|
+
and defaults to ``True``.
|
75
|
+
"""
|
76
|
+
name = 'SVG'
|
77
|
+
aliases = ['svg']
|
78
|
+
filenames = ['*.svg']
|
79
|
+
|
80
|
+
def __init__(self, **options):
|
81
|
+
# XXX outencoding
|
82
|
+
Formatter.__init__(self, **options)
|
83
|
+
self.nowrap = get_bool_opt(options, 'nowrap', False)
|
84
|
+
self.fontfamily = options.get('fontfamily', 'monospace')
|
85
|
+
self.fontsize = options.get('fontsize', '14px')
|
86
|
+
self.xoffset = get_int_opt(options, 'xoffset', 0)
|
87
|
+
fs = self.fontsize.strip()
|
88
|
+
if fs.endswith('px'): fs = fs[:-2].strip()
|
89
|
+
try:
|
90
|
+
int_fs = int(fs)
|
91
|
+
except:
|
92
|
+
int_fs = 20
|
93
|
+
self.yoffset = get_int_opt(options, 'yoffset', int_fs)
|
94
|
+
self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
|
95
|
+
self.spacehack = get_bool_opt(options, 'spacehack', True)
|
96
|
+
self._stylecache = {}
|
97
|
+
|
98
|
+
def format_unencoded(self, tokensource, outfile):
|
99
|
+
"""
|
100
|
+
Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
|
101
|
+
tuples and write it into ``outfile``.
|
102
|
+
|
103
|
+
For our implementation we put all lines in their own 'line group'.
|
104
|
+
"""
|
105
|
+
x = self.xoffset
|
106
|
+
y = self.yoffset
|
107
|
+
if not self.nowrap:
|
108
|
+
if self.encoding:
|
109
|
+
outfile.write('<?xml version="1.0" encoding="%s"?>\n' %
|
110
|
+
self.encoding)
|
111
|
+
else:
|
112
|
+
outfile.write('<?xml version="1.0"?>\n')
|
113
|
+
outfile.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" '
|
114
|
+
'"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/'
|
115
|
+
'svg10.dtd">\n')
|
116
|
+
outfile.write('<svg xmlns="http://www.w3.org/2000/svg">\n')
|
117
|
+
outfile.write('<g font-family="%s" font-size="%s">\n' %
|
118
|
+
(self.fontfamily, self.fontsize))
|
119
|
+
outfile.write('<text x="%s" y="%s" xml:space="preserve">' % (x, y))
|
120
|
+
for ttype, value in tokensource:
|
121
|
+
style = self._get_style(ttype)
|
122
|
+
tspan = style and '<tspan' + style + '>' or ''
|
123
|
+
tspanend = tspan and '</tspan>' or ''
|
124
|
+
value = escape_html(value)
|
125
|
+
if self.spacehack:
|
126
|
+
value = value.expandtabs().replace(' ', ' ')
|
127
|
+
parts = value.split('\n')
|
128
|
+
for part in parts[:-1]:
|
129
|
+
outfile.write(tspan + part + tspanend)
|
130
|
+
y += self.ystep
|
131
|
+
outfile.write('</text>\n<text x="%s" y="%s" '
|
132
|
+
'xml:space="preserve">' % (x, y))
|
133
|
+
outfile.write(tspan + parts[-1] + tspanend)
|
134
|
+
outfile.write('</text>')
|
135
|
+
|
136
|
+
if not self.nowrap:
|
137
|
+
outfile.write('</g></svg>\n')
|
138
|
+
|
139
|
+
def _get_style(self, tokentype):
|
140
|
+
if tokentype in self._stylecache:
|
141
|
+
return self._stylecache[tokentype]
|
142
|
+
otokentype = tokentype
|
143
|
+
while not self.style.styles_token(tokentype):
|
144
|
+
tokentype = tokentype.parent
|
145
|
+
value = self.style.style_for_token(tokentype)
|
146
|
+
result = ''
|
147
|
+
if value['color']:
|
148
|
+
result = ' fill="#' + value['color'] + '"'
|
149
|
+
if value['bold']:
|
150
|
+
result += ' font-weight="bold"'
|
151
|
+
if value['italic']:
|
152
|
+
result += ' font-style="italic"'
|
153
|
+
self._stylecache[otokentype] = result
|
154
|
+
return result
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.terminal
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Formatter for terminal output with ANSI sequences.
|
7
|
+
|
8
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
9
|
+
:license: BSD, see LICENSE for details.
|
10
|
+
"""
|
11
|
+
|
12
|
+
import sys
|
13
|
+
|
14
|
+
from pygments.formatter import Formatter
|
15
|
+
from pygments.token import Keyword, Name, Comment, String, Error, \
|
16
|
+
Number, Operator, Generic, Token, Whitespace
|
17
|
+
from pygments.console import ansiformat
|
18
|
+
from pygments.util import get_choice_opt
|
19
|
+
|
20
|
+
|
21
|
+
__all__ = ['TerminalFormatter']
|
22
|
+
|
23
|
+
|
24
|
+
#: Map token types to a tuple of color values for light and dark
|
25
|
+
#: backgrounds.
|
26
|
+
TERMINAL_COLORS = {
|
27
|
+
Token: ('', ''),
|
28
|
+
|
29
|
+
Whitespace: ('lightgray', 'darkgray'),
|
30
|
+
Comment: ('lightgray', 'darkgray'),
|
31
|
+
Comment.Preproc: ('teal', 'turquoise'),
|
32
|
+
Keyword: ('darkblue', 'blue'),
|
33
|
+
Keyword.Type: ('teal', 'turquoise'),
|
34
|
+
Operator.Word: ('purple', 'fuchsia'),
|
35
|
+
Name.Builtin: ('teal', 'turquoise'),
|
36
|
+
Name.Function: ('darkgreen', 'green'),
|
37
|
+
Name.Namespace: ('_teal_', '_turquoise_'),
|
38
|
+
Name.Class: ('_darkgreen_', '_green_'),
|
39
|
+
Name.Exception: ('teal', 'turquoise'),
|
40
|
+
Name.Decorator: ('darkgray', 'lightgray'),
|
41
|
+
Name.Variable: ('darkred', 'red'),
|
42
|
+
Name.Constant: ('darkred', 'red'),
|
43
|
+
Name.Attribute: ('teal', 'turquoise'),
|
44
|
+
Name.Tag: ('blue', 'blue'),
|
45
|
+
String: ('brown', 'brown'),
|
46
|
+
Number: ('darkblue', 'blue'),
|
47
|
+
|
48
|
+
Generic.Deleted: ('red', 'red'),
|
49
|
+
Generic.Inserted: ('darkgreen', 'green'),
|
50
|
+
Generic.Heading: ('**', '**'),
|
51
|
+
Generic.Subheading: ('*purple*', '*fuchsia*'),
|
52
|
+
Generic.Error: ('red', 'red'),
|
53
|
+
|
54
|
+
Error: ('_red_', '_red_'),
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
class TerminalFormatter(Formatter):
|
59
|
+
r"""
|
60
|
+
Format tokens with ANSI color sequences, for output in a text console.
|
61
|
+
Color sequences are terminated at newlines, so that paging the output
|
62
|
+
works correctly.
|
63
|
+
|
64
|
+
The `get_style_defs()` method doesn't do anything special since there is
|
65
|
+
no support for common styles.
|
66
|
+
|
67
|
+
Options accepted:
|
68
|
+
|
69
|
+
`bg`
|
70
|
+
Set to ``"light"`` or ``"dark"`` depending on the terminal's background
|
71
|
+
(default: ``"light"``).
|
72
|
+
|
73
|
+
`colorscheme`
|
74
|
+
A dictionary mapping token types to (lightbg, darkbg) color names or
|
75
|
+
``None`` (default: ``None`` = use builtin colorscheme).
|
76
|
+
"""
|
77
|
+
name = 'Terminal'
|
78
|
+
aliases = ['terminal', 'console']
|
79
|
+
filenames = []
|
80
|
+
|
81
|
+
def __init__(self, **options):
|
82
|
+
Formatter.__init__(self, **options)
|
83
|
+
self.darkbg = get_choice_opt(options, 'bg',
|
84
|
+
['light', 'dark'], 'light') == 'dark'
|
85
|
+
self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS
|
86
|
+
|
87
|
+
def format(self, tokensource, outfile):
|
88
|
+
# hack: if the output is a terminal and has an encoding set,
|
89
|
+
# use that to avoid unicode encode problems
|
90
|
+
if not self.encoding and hasattr(outfile, "encoding") and \
|
91
|
+
hasattr(outfile, "isatty") and outfile.isatty() and \
|
92
|
+
sys.version_info < (3,):
|
93
|
+
self.encoding = outfile.encoding
|
94
|
+
return Formatter.format(self, tokensource, outfile)
|
95
|
+
|
96
|
+
def format_unencoded(self, tokensource, outfile):
|
97
|
+
for ttype, value in tokensource:
|
98
|
+
color = self.colorscheme.get(ttype)
|
99
|
+
while color is None:
|
100
|
+
ttype = ttype[:-1]
|
101
|
+
color = self.colorscheme.get(ttype)
|
102
|
+
if color:
|
103
|
+
color = color[self.darkbg]
|
104
|
+
spl = value.split('\n')
|
105
|
+
for line in spl[:-1]:
|
106
|
+
if line:
|
107
|
+
outfile.write(ansiformat(color, line))
|
108
|
+
outfile.write('\n')
|
109
|
+
if spl[-1]:
|
110
|
+
outfile.write(ansiformat(color, spl[-1]))
|
111
|
+
else:
|
112
|
+
outfile.write(value)
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.formatters.terminal256
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Formatter for 256-color terminal output with ANSI sequences.
|
7
|
+
|
8
|
+
RGB-to-XTERM color conversion routines adapted from xterm256-conv
|
9
|
+
tool (http://frexx.de/xterm-256-notes/data/xterm256-conv2.tar.bz2)
|
10
|
+
by Wolfgang Frisch.
|
11
|
+
|
12
|
+
Formatter version 1.
|
13
|
+
|
14
|
+
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
|
15
|
+
:license: BSD, see LICENSE for details.
|
16
|
+
"""
|
17
|
+
|
18
|
+
# TODO:
|
19
|
+
# - Options to map style's bold/underline/italic/border attributes
|
20
|
+
# to some ANSI attrbutes (something like 'italic=underline')
|
21
|
+
# - An option to output "style RGB to xterm RGB/index" conversion table
|
22
|
+
# - An option to indicate that we are running in "reverse background"
|
23
|
+
# xterm. This means that default colors are white-on-black, not
|
24
|
+
# black-on-while, so colors like "white background" need to be converted
|
25
|
+
# to "white background, black foreground", etc...
|
26
|
+
|
27
|
+
import sys
|
28
|
+
|
29
|
+
from pygments.formatter import Formatter
|
30
|
+
|
31
|
+
|
32
|
+
__all__ = ['Terminal256Formatter']
|
33
|
+
|
34
|
+
|
35
|
+
class EscapeSequence:
|
36
|
+
def __init__(self, fg=None, bg=None, bold=False, underline=False):
|
37
|
+
self.fg = fg
|
38
|
+
self.bg = bg
|
39
|
+
self.bold = bold
|
40
|
+
self.underline = underline
|
41
|
+
|
42
|
+
def escape(self, attrs):
|
43
|
+
if len(attrs):
|
44
|
+
return "\x1b[" + ";".join(attrs) + "m"
|
45
|
+
return ""
|
46
|
+
|
47
|
+
def color_string(self):
|
48
|
+
attrs = []
|
49
|
+
if self.fg is not None:
|
50
|
+
attrs.extend(("38", "5", "%i" % self.fg))
|
51
|
+
if self.bg is not None:
|
52
|
+
attrs.extend(("48", "5", "%i" % self.bg))
|
53
|
+
if self.bold:
|
54
|
+
attrs.append("01")
|
55
|
+
if self.underline:
|
56
|
+
attrs.append("04")
|
57
|
+
return self.escape(attrs)
|
58
|
+
|
59
|
+
def reset_string(self):
|
60
|
+
attrs = []
|
61
|
+
if self.fg is not None:
|
62
|
+
attrs.append("39")
|
63
|
+
if self.bg is not None:
|
64
|
+
attrs.append("49")
|
65
|
+
if self.bold or self.underline:
|
66
|
+
attrs.append("00")
|
67
|
+
return self.escape(attrs)
|
68
|
+
|
69
|
+
class Terminal256Formatter(Formatter):
|
70
|
+
r"""
|
71
|
+
Format tokens with ANSI color sequences, for output in a 256-color
|
72
|
+
terminal or console. Like in `TerminalFormatter` color sequences
|
73
|
+
are terminated at newlines, so that paging the output works correctly.
|
74
|
+
|
75
|
+
The formatter takes colors from a style defined by the `style` option
|
76
|
+
and converts them to nearest ANSI 256-color escape sequences. Bold and
|
77
|
+
underline attributes from the style are preserved (and displayed).
|
78
|
+
|
79
|
+
*New in Pygments 0.9.*
|
80
|
+
|
81
|
+
Options accepted:
|
82
|
+
|
83
|
+
`style`
|
84
|
+
The style to use, can be a string or a Style subclass (default:
|
85
|
+
``'default'``).
|
86
|
+
"""
|
87
|
+
name = 'Terminal256'
|
88
|
+
aliases = ['terminal256', 'console256', '256']
|
89
|
+
filenames = []
|
90
|
+
|
91
|
+
def __init__(self, **options):
|
92
|
+
Formatter.__init__(self, **options)
|
93
|
+
|
94
|
+
self.xterm_colors = []
|
95
|
+
self.best_match = {}
|
96
|
+
self.style_string = {}
|
97
|
+
|
98
|
+
self.usebold = 'nobold' not in options
|
99
|
+
self.useunderline = 'nounderline' not in options
|
100
|
+
|
101
|
+
self._build_color_table() # build an RGB-to-256 color conversion table
|
102
|
+
self._setup_styles() # convert selected style's colors to term. colors
|
103
|
+
|
104
|
+
def _build_color_table(self):
|
105
|
+
# colors 0..15: 16 basic colors
|
106
|
+
|
107
|
+
self.xterm_colors.append((0x00, 0x00, 0x00)) # 0
|
108
|
+
self.xterm_colors.append((0xcd, 0x00, 0x00)) # 1
|
109
|
+
self.xterm_colors.append((0x00, 0xcd, 0x00)) # 2
|
110
|
+
self.xterm_colors.append((0xcd, 0xcd, 0x00)) # 3
|
111
|
+
self.xterm_colors.append((0x00, 0x00, 0xee)) # 4
|
112
|
+
self.xterm_colors.append((0xcd, 0x00, 0xcd)) # 5
|
113
|
+
self.xterm_colors.append((0x00, 0xcd, 0xcd)) # 6
|
114
|
+
self.xterm_colors.append((0xe5, 0xe5, 0xe5)) # 7
|
115
|
+
self.xterm_colors.append((0x7f, 0x7f, 0x7f)) # 8
|
116
|
+
self.xterm_colors.append((0xff, 0x00, 0x00)) # 9
|
117
|
+
self.xterm_colors.append((0x00, 0xff, 0x00)) # 10
|
118
|
+
self.xterm_colors.append((0xff, 0xff, 0x00)) # 11
|
119
|
+
self.xterm_colors.append((0x5c, 0x5c, 0xff)) # 12
|
120
|
+
self.xterm_colors.append((0xff, 0x00, 0xff)) # 13
|
121
|
+
self.xterm_colors.append((0x00, 0xff, 0xff)) # 14
|
122
|
+
self.xterm_colors.append((0xff, 0xff, 0xff)) # 15
|
123
|
+
|
124
|
+
# colors 16..232: the 6x6x6 color cube
|
125
|
+
|
126
|
+
valuerange = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
|
127
|
+
|
128
|
+
for i in range(217):
|
129
|
+
r = valuerange[(i // 36) % 6]
|
130
|
+
g = valuerange[(i // 6) % 6]
|
131
|
+
b = valuerange[i % 6]
|
132
|
+
self.xterm_colors.append((r, g, b))
|
133
|
+
|
134
|
+
# colors 233..253: grayscale
|
135
|
+
|
136
|
+
for i in range(1, 22):
|
137
|
+
v = 8 + i * 10
|
138
|
+
self.xterm_colors.append((v, v, v))
|
139
|
+
|
140
|
+
def _closest_color(self, r, g, b):
|
141
|
+
distance = 257*257*3 # "infinity" (>distance from #000000 to #ffffff)
|
142
|
+
match = 0
|
143
|
+
|
144
|
+
for i in range(0, 254):
|
145
|
+
values = self.xterm_colors[i]
|
146
|
+
|
147
|
+
rd = r - values[0]
|
148
|
+
gd = g - values[1]
|
149
|
+
bd = b - values[2]
|
150
|
+
d = rd*rd + gd*gd + bd*bd
|
151
|
+
|
152
|
+
if d < distance:
|
153
|
+
match = i
|
154
|
+
distance = d
|
155
|
+
return match
|
156
|
+
|
157
|
+
def _color_index(self, color):
|
158
|
+
index = self.best_match.get(color, None)
|
159
|
+
if index is None:
|
160
|
+
try:
|
161
|
+
rgb = int(str(color), 16)
|
162
|
+
except ValueError:
|
163
|
+
rgb = 0
|
164
|
+
|
165
|
+
r = (rgb >> 16) & 0xff
|
166
|
+
g = (rgb >> 8) & 0xff
|
167
|
+
b = rgb & 0xff
|
168
|
+
index = self._closest_color(r, g, b)
|
169
|
+
self.best_match[color] = index
|
170
|
+
return index
|
171
|
+
|
172
|
+
def _setup_styles(self):
|
173
|
+
for ttype, ndef in self.style:
|
174
|
+
escape = EscapeSequence()
|
175
|
+
if ndef['color']:
|
176
|
+
escape.fg = self._color_index(ndef['color'])
|
177
|
+
if ndef['bgcolor']:
|
178
|
+
escape.bg = self._color_index(ndef['bgcolor'])
|
179
|
+
if self.usebold and ndef['bold']:
|
180
|
+
escape.bold = True
|
181
|
+
if self.useunderline and ndef['underline']:
|
182
|
+
escape.underline = True
|
183
|
+
self.style_string[str(ttype)] = (escape.color_string(),
|
184
|
+
escape.reset_string())
|
185
|
+
|
186
|
+
def format(self, tokensource, outfile):
|
187
|
+
# hack: if the output is a terminal and has an encoding set,
|
188
|
+
# use that to avoid unicode encode problems
|
189
|
+
if not self.encoding and hasattr(outfile, "encoding") and \
|
190
|
+
hasattr(outfile, "isatty") and outfile.isatty() and \
|
191
|
+
sys.version_info < (3,):
|
192
|
+
self.encoding = outfile.encoding
|
193
|
+
return Formatter.format(self, tokensource, outfile)
|
194
|
+
|
195
|
+
def format_unencoded(self, tokensource, outfile):
|
196
|
+
for ttype, value in tokensource:
|
197
|
+
not_found = True
|
198
|
+
while ttype and not_found:
|
199
|
+
try:
|
200
|
+
#outfile.write( "<" + str(ttype) + ">" )
|
201
|
+
on, off = self.style_string[str(ttype)]
|
202
|
+
|
203
|
+
# Like TerminalFormatter, add "reset colors" escape sequence
|
204
|
+
# on newline.
|
205
|
+
spl = value.split('\n')
|
206
|
+
for line in spl[:-1]:
|
207
|
+
if line:
|
208
|
+
outfile.write(on + line + off)
|
209
|
+
outfile.write('\n')
|
210
|
+
if spl[-1]:
|
211
|
+
outfile.write(on + spl[-1] + off)
|
212
|
+
|
213
|
+
not_found = False
|
214
|
+
#outfile.write( '#' + str(ttype) + '#' )
|
215
|
+
|
216
|
+
except KeyError:
|
217
|
+
#ottype = ttype
|
218
|
+
ttype = ttype[:-1]
|
219
|
+
#outfile.write( '!' + str(ottype) + '->' + str(ttype) + '!' )
|
220
|
+
|
221
|
+
if not_found:
|
222
|
+
outfile.write(value)
|