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
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# pygments.rb
|
2
|
+
|
3
|
+
A Ruby wrapper for the Python [pygments syntax highlighter](http://pygments.org/).
|
4
|
+
|
5
|
+
pygments.rb works by talking over a simple pipe to a long-lived
|
6
|
+
Python child process. This library replaces [github/albino](https://github.com/github/albino),
|
7
|
+
as well as a version of pygments.rb that used an embedded Python
|
8
|
+
interpreter.
|
9
|
+
|
10
|
+
Each Ruby process that runs has its own 'personal Python';
|
11
|
+
for example, 4 Unicorn workers will have one Python process each.
|
12
|
+
If a Python process dies, a new one will be spawned on the next
|
13
|
+
pygments.rb request.
|
14
|
+
|
15
|
+
## system requirements
|
16
|
+
|
17
|
+
- Python 2.5+
|
18
|
+
|
19
|
+
## usage
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
require 'pygments'
|
23
|
+
```
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
Pygments.highlight(File.read(__FILE__), :lexer => 'ruby')
|
27
|
+
```
|
28
|
+
|
29
|
+
Encoding and other lexer/formatter options can be passed in via an
|
30
|
+
options hash:
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
Pygments.highlight('code', :options => {:encoding => 'utf-8'})
|
34
|
+
```
|
35
|
+
|
36
|
+
pygments.rb defaults to using an HTML formatter.
|
37
|
+
To use a formatter other than `html`, specify it explicitly
|
38
|
+
like so:
|
39
|
+
|
40
|
+
``` ruby
|
41
|
+
Pygments.highlight('code', :formatter => 'bbcode')
|
42
|
+
Pygments.highlight('code', :formatter => 'terminal')
|
43
|
+
```
|
44
|
+
|
45
|
+
To generate CSS for HTML formatted code, use the `#css` method:
|
46
|
+
|
47
|
+
``` ruby
|
48
|
+
Pygments.css
|
49
|
+
Pygments.css('.highlight')
|
50
|
+
```
|
51
|
+
|
52
|
+
Other Pygments high-level API methods are also available.
|
53
|
+
These methods return arrays detailing all the available lexers, formatters,
|
54
|
+
and styles.
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
Pygments.lexers
|
58
|
+
Pygments.formatters
|
59
|
+
Pygments.styles
|
60
|
+
```
|
61
|
+
|
62
|
+
To use a custom pygments installation, specify the path to
|
63
|
+
`Pygments#start`:
|
64
|
+
|
65
|
+
``` ruby
|
66
|
+
Pygments.start("/path/to/pygments")
|
67
|
+
```
|
68
|
+
|
69
|
+
## benchmarks
|
70
|
+
|
71
|
+
|
72
|
+
$ ruby bench.rb 50
|
73
|
+
Benchmarking....
|
74
|
+
Size: 698 bytes
|
75
|
+
Iterations: 50
|
76
|
+
user system total real
|
77
|
+
pygments popen 0.010000 0.010000 0.020000 ( 0.460370)
|
78
|
+
pygments popen (process already started) 0.010000 0.000000 0.010000 ( 0.272975)
|
79
|
+
pygments popen (process already started 2) 0.000000 0.000000 0.000000 ( 0.273589)
|
80
|
+
|
81
|
+
$ ruby bench.rb 10
|
82
|
+
Benchmarking....
|
83
|
+
Size: 15523 bytes
|
84
|
+
Iterations: 10
|
85
|
+
user system total real
|
86
|
+
pygments popen 0.000000 0.000000 0.000000 ( 0.819419)
|
87
|
+
pygments popen (process already started) 0.010000 0.000000 0.010000 ( 0.676515)
|
88
|
+
pygments popen (process already started 2) 0.000000 0.010000 0.010000 ( 0.674189)
|
89
|
+
|
90
|
+
|
91
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
# ==========================================================
|
7
|
+
# Packaging
|
8
|
+
# ==========================================================
|
9
|
+
|
10
|
+
GEMSPEC = eval(File.read('pygments.rb.gemspec'))
|
11
|
+
|
12
|
+
require 'rake/gempackagetask'
|
13
|
+
Rake::GemPackageTask.new(GEMSPEC) do |pkg|
|
14
|
+
end
|
15
|
+
|
16
|
+
# ==========================================================
|
17
|
+
# Testing
|
18
|
+
# ==========================================================
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new 'test' do |t|
|
22
|
+
t.test_files = FileList['test/test_*.rb']
|
23
|
+
t.ruby_opts = ['-rubygems']
|
24
|
+
end
|
25
|
+
|
26
|
+
# ==========================================================
|
27
|
+
# Benchmarking
|
28
|
+
# ==========================================================
|
29
|
+
|
30
|
+
task :bench do
|
31
|
+
sh "ruby bench.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
# ==========================================================
|
35
|
+
# Cache lexers
|
36
|
+
# # ==========================================================
|
37
|
+
|
38
|
+
# Write all the lexers to a file for easy lookup
|
39
|
+
task :lexers do
|
40
|
+
sh "ruby cache-lexers.rb"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# ==========================================================
|
45
|
+
# Vendor
|
46
|
+
# ==========================================================
|
47
|
+
|
48
|
+
namespace :vendor do
|
49
|
+
file 'vendor/pygments-main' do |f|
|
50
|
+
sh "hg clone https://bitbucket.org/birkenfeld/pygments-main #{f.name}"
|
51
|
+
sh "hg --repository #{f.name} identify --id > #{f.name}/REVISION"
|
52
|
+
rm_rf Dir["#{f.name}/.hg*"]
|
53
|
+
end
|
54
|
+
|
55
|
+
task :clobber do
|
56
|
+
rm_rf 'vendor/pygments-main'
|
57
|
+
end
|
58
|
+
|
59
|
+
# Load all the custom lexers in the `vendor/custom_lexers` folder
|
60
|
+
# and stick them in our custom Pygments vendor
|
61
|
+
task :load_lexers do
|
62
|
+
LEXERS_DIR = 'vendor/pygments-main/pygments/lexers'
|
63
|
+
lexers = FileList['vendor/custom_lexers/*.py']
|
64
|
+
lexers.each { |l| FileUtils.copy l, LEXERS_DIR }
|
65
|
+
FileUtils.cd(LEXERS_DIR) { sh "python _mapping.py" }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Load all the custom formatters in the `vendor/custom_formatters` folder
|
69
|
+
# and stick them in our custom Pygments vendor
|
70
|
+
task :load_formatters do
|
71
|
+
FORMATTERS_DIR = 'vendor/pygments-main/pygments/formatters'
|
72
|
+
formatters = FileList['vendor/custom_formatters/*.py']
|
73
|
+
formatters.each { |f| FileUtils.copy f, FORMATTERS_DIR }
|
74
|
+
FileUtils.cd(FORMATTERS_DIR) { sh "python _mapping.py" }
|
75
|
+
end
|
76
|
+
|
77
|
+
task :update => [:clobber, 'vendor/pygments-main', :load_lexers, :load_formatters]
|
78
|
+
end
|
data/bench.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/lib/pygments.rb')
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
include Benchmark
|
5
|
+
# number of iterations
|
6
|
+
num = ARGV[0] ? ARGV[0].to_i : 10
|
7
|
+
|
8
|
+
# we can also repeat the code itself
|
9
|
+
repeats = ARGV[1] ? ARGV[1].to_i : 1
|
10
|
+
|
11
|
+
code = File.open('test/test_data.py').read.to_s * repeats
|
12
|
+
|
13
|
+
puts "Benchmarking....\n"
|
14
|
+
puts "Size: " + code.bytesize.to_s + " bytes\n"
|
15
|
+
puts "Iterations: " + num.to_s + "\n"
|
16
|
+
|
17
|
+
Benchmark.bm(40) do |x|
|
18
|
+
x.report("pygments popen ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
|
19
|
+
x.report("pygments popen (process already started) ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
|
20
|
+
x.report("pygments popen (process already started 2) ") { for i in 1..num; Pygments.highlight(code, :lexer => 'python'); end }
|
21
|
+
end
|
22
|
+
|
data/cache-lexers.rb
ADDED
data/lexers
ADDED
Binary file
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module Pygments
|
2
|
+
class Lexer < Struct.new(:name, :aliases, :filenames, :mimetypes)
|
3
|
+
@lexers = []
|
4
|
+
@index = {}
|
5
|
+
@name_index = {}
|
6
|
+
@alias_index = {}
|
7
|
+
@extname_index = {}
|
8
|
+
@mimetypes_index = {}
|
9
|
+
|
10
|
+
# Internal: Create a new Lexer object
|
11
|
+
#
|
12
|
+
# hash - A hash of attributes
|
13
|
+
#
|
14
|
+
# Returns a Lexer object
|
15
|
+
def self.create(hash)
|
16
|
+
lexer = new(hash[:name], hash[:aliases], hash[:filenames], hash[:mimetypes])
|
17
|
+
|
18
|
+
@lexers << lexer
|
19
|
+
|
20
|
+
@index[lexer.name.downcase] = @name_index[lexer.name] = lexer
|
21
|
+
|
22
|
+
lexer.aliases.each do |name|
|
23
|
+
@alias_index[name] = lexer
|
24
|
+
@index[name.downcase] ||= lexer
|
25
|
+
end
|
26
|
+
|
27
|
+
lexer.filenames.each do |filename|
|
28
|
+
extnames = []
|
29
|
+
|
30
|
+
extname = File.extname(filename)
|
31
|
+
if m = extname.match(/\[(.+)\]/)
|
32
|
+
m[1].scan(/./).each do |s|
|
33
|
+
extnames << extname.sub(m[0], s)
|
34
|
+
end
|
35
|
+
elsif extname != ""
|
36
|
+
extnames << extname
|
37
|
+
end
|
38
|
+
|
39
|
+
extnames.each do |extname|
|
40
|
+
@extname_index[extname] = lexer
|
41
|
+
@index[extname.downcase.sub(/^\./, "")] ||= lexer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
lexer.mimetypes.each do |type|
|
46
|
+
@mimetypes_index[type] = lexer
|
47
|
+
end
|
48
|
+
|
49
|
+
lexer
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Get all Lexers
|
53
|
+
#
|
54
|
+
# Returns an Array of Lexers
|
55
|
+
def self.all
|
56
|
+
@lexers
|
57
|
+
end
|
58
|
+
|
59
|
+
# Public: Look up Lexer by name or alias.
|
60
|
+
#
|
61
|
+
# name - A String name or alias
|
62
|
+
#
|
63
|
+
# Lexer.find('Ruby')
|
64
|
+
# => #<Lexer name="Ruby">
|
65
|
+
#
|
66
|
+
# Returns the Lexer or nil if none was found.
|
67
|
+
def self.find(name)
|
68
|
+
@index[name.to_s.downcase]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Public: Alias for find.
|
72
|
+
def self.[](name)
|
73
|
+
find(name)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Public: Look up Lexer by its proper name.
|
77
|
+
#
|
78
|
+
# name - The String name of the Lexer
|
79
|
+
#
|
80
|
+
# Examples
|
81
|
+
#
|
82
|
+
# Lexer.find_by_name('Ruby')
|
83
|
+
# # => #<Lexer name="Ruby">
|
84
|
+
#
|
85
|
+
# Returns the Lexer or nil if none was found.
|
86
|
+
def self.find_by_name(name)
|
87
|
+
@name_index[name]
|
88
|
+
end
|
89
|
+
|
90
|
+
# Public: Look up Lexer by one of its aliases.
|
91
|
+
#
|
92
|
+
# name - A String alias of the Lexer
|
93
|
+
#
|
94
|
+
# Examples
|
95
|
+
#
|
96
|
+
# Lexer.find_by_alias('rb')
|
97
|
+
# # => #<Lexer name="Ruby">
|
98
|
+
#
|
99
|
+
# Returns the Lexer or nil if none was found.
|
100
|
+
def self.find_by_alias(name)
|
101
|
+
@alias_index[name]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Public: Look up Lexer by one of it's file extensions.
|
105
|
+
#
|
106
|
+
# extname - A String file extension.
|
107
|
+
#
|
108
|
+
# Examples
|
109
|
+
#
|
110
|
+
# Lexer.find_by_extname('.rb')
|
111
|
+
# # => #<Lexer name="Ruby">
|
112
|
+
#
|
113
|
+
# Returns the Lexer or nil if none was found.
|
114
|
+
def self.find_by_extname(extname)
|
115
|
+
@extname_index[extname]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Public: Look up Lexer by one of it's mime types.
|
119
|
+
#
|
120
|
+
# type - A mime type String.
|
121
|
+
#
|
122
|
+
# Examples
|
123
|
+
#
|
124
|
+
# Lexer.find_by_mimetype('application/x-ruby')
|
125
|
+
# # => #<Lexer name="Ruby">
|
126
|
+
#
|
127
|
+
# Returns the Lexer or nil if none was found.
|
128
|
+
def self.find_by_mimetype(type)
|
129
|
+
@mimetypes_index[type]
|
130
|
+
end
|
131
|
+
|
132
|
+
# Public: Highlight syntax of text
|
133
|
+
#
|
134
|
+
# text - String of code to be highlighted
|
135
|
+
# options - Hash of options (defaults to {})
|
136
|
+
#
|
137
|
+
# Returns html String
|
138
|
+
def highlight(text, options = {})
|
139
|
+
options[:lexer] = aliases.first
|
140
|
+
Pygments.highlight(text, options)
|
141
|
+
end
|
142
|
+
|
143
|
+
alias_method :==, :equal?
|
144
|
+
alias_method :eql?, :equal?
|
145
|
+
end
|
146
|
+
|
147
|
+
lexers.values.each { |h| Lexer.create(h) }
|
148
|
+
end
|
@@ -0,0 +1,344 @@
|
|
1
|
+
#!/usr/bin/env python2
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
import sys, re, os, signal, resource
|
5
|
+
import traceback
|
6
|
+
if 'PYGMENTS_PATH' in os.environ:
|
7
|
+
sys.path.insert(0, os.environ['PYGMENTS_PATH'])
|
8
|
+
|
9
|
+
dirname = os.path.dirname
|
10
|
+
|
11
|
+
base_dir = dirname(dirname(dirname(os.path.abspath(__file__))))
|
12
|
+
sys.path.append(base_dir + "/vendor")
|
13
|
+
sys.path.append(base_dir + "/vendor/pygments-main")
|
14
|
+
sys.path.append(base_dir + "/vendor/simplejson")
|
15
|
+
|
16
|
+
import pygments
|
17
|
+
from pygments import lexers, formatters, styles, filters
|
18
|
+
|
19
|
+
from threading import Lock
|
20
|
+
|
21
|
+
try:
|
22
|
+
import json
|
23
|
+
except ImportError:
|
24
|
+
import simplejson as json
|
25
|
+
|
26
|
+
def _convert_keys(dictionary):
|
27
|
+
if not isinstance(dictionary, dict):
|
28
|
+
return dictionary
|
29
|
+
return dict((str(k), _convert_keys(v))
|
30
|
+
for k, v in dictionary.items())
|
31
|
+
|
32
|
+
def _write_error(error):
|
33
|
+
res = {"error": error}
|
34
|
+
out_header = json.dumps(res).encode('utf-8')
|
35
|
+
bits = _get_fixed_bits_from_header(out_header)
|
36
|
+
sys.stdout.write(bits + "\n")
|
37
|
+
sys.stdout.flush()
|
38
|
+
sys.stdout.write(out_header + "\n")
|
39
|
+
sys.stdout.flush()
|
40
|
+
return
|
41
|
+
|
42
|
+
def _get_fixed_bits_from_header(out_header):
|
43
|
+
size = len(out_header)
|
44
|
+
return "".join(map(lambda y:str((size>>y)&1), range(32-1, -1, -1)))
|
45
|
+
|
46
|
+
def _signal_handler(signal, frame):
|
47
|
+
"""
|
48
|
+
Handle the signal given in the first argument, exiting gracefully
|
49
|
+
"""
|
50
|
+
sys.exit(0)
|
51
|
+
|
52
|
+
class Mentos(object):
|
53
|
+
"""
|
54
|
+
Interacts with pygments.rb to provide access to pygments functionality
|
55
|
+
"""
|
56
|
+
def __init__(self):
|
57
|
+
pass
|
58
|
+
|
59
|
+
def return_lexer(self, lexer, args, inputs, code=None):
|
60
|
+
"""
|
61
|
+
Accepting a variety of possible inputs, return a Lexer object.
|
62
|
+
|
63
|
+
The inputs argument should be a hash with at least one of the following
|
64
|
+
keys:
|
65
|
+
|
66
|
+
- 'lexer' ("python")
|
67
|
+
- 'mimetype' ("text/x-ruby")
|
68
|
+
- 'filename' ("yeaaah.py")
|
69
|
+
|
70
|
+
The code argument should be a string, such as "import derp".
|
71
|
+
|
72
|
+
The code guessing method is not especially great. It is advised that
|
73
|
+
clients pass in a literal lexer name whenever possible, which provides
|
74
|
+
the best probability of match (100 percent).
|
75
|
+
"""
|
76
|
+
|
77
|
+
if lexer:
|
78
|
+
if inputs:
|
79
|
+
return lexers.get_lexer_by_name(lexer, **inputs)
|
80
|
+
else:
|
81
|
+
return lexers.get_lexer_by_name(lexer)
|
82
|
+
|
83
|
+
if inputs:
|
84
|
+
if 'lexer' in inputs:
|
85
|
+
return lexers.get_lexer_by_name(inputs['lexer'], **inputs)
|
86
|
+
|
87
|
+
elif 'mimetype' in inputs:
|
88
|
+
return lexers.get_lexer_for_mimetype(inputs['mimetype'], **inputs)
|
89
|
+
|
90
|
+
elif 'filename' in inputs:
|
91
|
+
name = inputs['filename']
|
92
|
+
|
93
|
+
# If we have code and a filename, pygments allows us to guess
|
94
|
+
# with both. This is better than just guessing with code.
|
95
|
+
if code:
|
96
|
+
return lexers.guess_lexer_for_filename(name, code, **inputs)
|
97
|
+
else:
|
98
|
+
return lexers.get_lexer_for_filename(name, **inputs)
|
99
|
+
|
100
|
+
# If all we got is code, try anyway.
|
101
|
+
if code:
|
102
|
+
return lexers.guess_lexer(code, **inputs)
|
103
|
+
|
104
|
+
else:
|
105
|
+
return None
|
106
|
+
|
107
|
+
|
108
|
+
def highlight_text(self, code, lexer, formatter_name, args, kwargs):
|
109
|
+
"""
|
110
|
+
Highlight the relevant code, and return a result string.
|
111
|
+
The default formatter is html, but alternate formatters can be passed in via
|
112
|
+
the formatter_name argument. Additional paramters can be passed as args
|
113
|
+
or kwargs.
|
114
|
+
"""
|
115
|
+
# Default to html if we don't have the formatter name.
|
116
|
+
if formatter_name:
|
117
|
+
_format_name = str(formatter_name)
|
118
|
+
else:
|
119
|
+
_format_name = "html"
|
120
|
+
|
121
|
+
# Return a lexer object
|
122
|
+
lexer = self.return_lexer(lexer, args, kwargs, code)
|
123
|
+
|
124
|
+
# Make sure we sucessfuly got a lexer
|
125
|
+
if lexer:
|
126
|
+
formatter = pygments.formatters.get_formatter_by_name(str.lower(_format_name), **kwargs)
|
127
|
+
|
128
|
+
# Do the damn thing.
|
129
|
+
res = pygments.highlight(code, lexer, formatter)
|
130
|
+
|
131
|
+
return res
|
132
|
+
|
133
|
+
else:
|
134
|
+
_write_error("No lexer")
|
135
|
+
|
136
|
+
def get_data(self, method, lexer, args, kwargs, text=None):
|
137
|
+
"""
|
138
|
+
Based on the method argument, determine the action we'd like pygments
|
139
|
+
to do. Then return the data generated from pygments.
|
140
|
+
"""
|
141
|
+
if kwargs:
|
142
|
+
formatter_name = kwargs.get("formatter", None)
|
143
|
+
opts = kwargs.get("options", {})
|
144
|
+
|
145
|
+
# Ensure there's a 'method' key before proceeeding
|
146
|
+
if method:
|
147
|
+
res = None
|
148
|
+
|
149
|
+
# Now check what that method is. For the get methods, pygments
|
150
|
+
# itself returns generators, so we make them lists so we can serialize
|
151
|
+
# easier.
|
152
|
+
if method == 'get_all_styles':
|
153
|
+
res = json.dumps(list(pygments.styles.get_all_styles()))
|
154
|
+
|
155
|
+
elif method == 'get_all_filters':
|
156
|
+
res = json.dumps(list(pygments.filters.get_all_filters()))
|
157
|
+
|
158
|
+
elif method == 'get_all_lexers':
|
159
|
+
res = json.dumps(list(pygments.lexers.get_all_lexers()))
|
160
|
+
|
161
|
+
elif method == 'get_all_formatters':
|
162
|
+
res = [ [ft.__name__, ft.name, ft.aliases] for ft in pygments.formatters.get_all_formatters() ]
|
163
|
+
res = json.dumps(res)
|
164
|
+
|
165
|
+
elif method == 'highlight':
|
166
|
+
try:
|
167
|
+
text = text.decode('utf-8')
|
168
|
+
except UnicodeDecodeError:
|
169
|
+
# The text may already be encoded
|
170
|
+
text = text
|
171
|
+
res = self.highlight_text(text, lexer, formatter_name, args, _convert_keys(opts))
|
172
|
+
|
173
|
+
elif method == 'css':
|
174
|
+
kwargs = _convert_keys(kwargs)
|
175
|
+
fmt = pygments.formatters.get_formatter_by_name(args[0], **kwargs)
|
176
|
+
res = fmt.get_style_defs(args[1])
|
177
|
+
|
178
|
+
elif method == 'lexer_name_for':
|
179
|
+
lexer = self.return_lexer(None, args, kwargs, text)
|
180
|
+
|
181
|
+
if lexer:
|
182
|
+
# We don't want the Lexer itself, just the name.
|
183
|
+
# Take the first alias.
|
184
|
+
res = lexer.aliases[0]
|
185
|
+
|
186
|
+
else:
|
187
|
+
_write_error("No lexer")
|
188
|
+
|
189
|
+
else:
|
190
|
+
_write_error("Invalid method " + method)
|
191
|
+
|
192
|
+
return res
|
193
|
+
|
194
|
+
|
195
|
+
def _send_data(self, res, method):
|
196
|
+
|
197
|
+
# Base header. We'll build on this, adding keys as necessary.
|
198
|
+
base_header = {"method": method}
|
199
|
+
|
200
|
+
res_bytes = len(res) + 1
|
201
|
+
base_header["bytes"] = res_bytes
|
202
|
+
|
203
|
+
out_header = json.dumps(base_header).encode('utf-8')
|
204
|
+
|
205
|
+
# Following the protocol, send over a fixed size represenation of the
|
206
|
+
# size of the JSON header
|
207
|
+
bits = _get_fixed_bits_from_header(out_header)
|
208
|
+
|
209
|
+
# Send it to Rubyland
|
210
|
+
sys.stdout.write(bits + "\n")
|
211
|
+
sys.stdout.flush()
|
212
|
+
|
213
|
+
# Send the header.
|
214
|
+
sys.stdout.write(out_header + "\n")
|
215
|
+
sys.stdout.flush()
|
216
|
+
|
217
|
+
# Finally, send the result
|
218
|
+
sys.stdout.write(res + "\n")
|
219
|
+
sys.stdout.flush()
|
220
|
+
|
221
|
+
|
222
|
+
def _get_ids(self, text):
|
223
|
+
start_id = text[:8]
|
224
|
+
end_id = text[-8:]
|
225
|
+
return start_id, end_id
|
226
|
+
|
227
|
+
def _check_and_return_text(self, text, start_id, end_id):
|
228
|
+
|
229
|
+
# Sanity check.
|
230
|
+
id_regex = re.compile('[A-Z]{8}')
|
231
|
+
|
232
|
+
if not id_regex.match(start_id) and not id_regex.match(end_id):
|
233
|
+
_write_error("ID check failed. Not an ID.")
|
234
|
+
|
235
|
+
if not start_id == end_id:
|
236
|
+
_write_error("ID check failed. ID's did not match.")
|
237
|
+
|
238
|
+
# Passed the sanity check. Remove the id's and return
|
239
|
+
text = text[10:-10]
|
240
|
+
return text
|
241
|
+
|
242
|
+
def _parse_header(self, header):
|
243
|
+
method = header["method"]
|
244
|
+
args = header.get("args", [])
|
245
|
+
kwargs = header.get("kwargs", {})
|
246
|
+
lexer = kwargs.get("lexer", None)
|
247
|
+
return (method, args, kwargs, lexer)
|
248
|
+
|
249
|
+
def start(self):
|
250
|
+
"""
|
251
|
+
Main loop, waiting for inputs on stdin. When it gets some data,
|
252
|
+
it goes to work.
|
253
|
+
|
254
|
+
mentos exposes most of the "High-level API" of pygments. It always
|
255
|
+
expects and requires a JSON header of metadata. If there is data to be
|
256
|
+
pygmentized, this header will be followed by the text to be pygmentized.
|
257
|
+
|
258
|
+
The header is of form:
|
259
|
+
{ "method": "highlight", "args": [], "kwargs": {"arg1": "v"}, "bytes": 128, "fd": "8"}
|
260
|
+
"""
|
261
|
+
lock = Lock()
|
262
|
+
|
263
|
+
while True:
|
264
|
+
# The loop begins by reading off a simple 32-arity string
|
265
|
+
# representing an integer of 32 bits. This is the length of
|
266
|
+
# our JSON header.
|
267
|
+
size = sys.stdin.read(32)
|
268
|
+
|
269
|
+
lock.acquire()
|
270
|
+
|
271
|
+
try:
|
272
|
+
# Read from stdin the amount of bytes we were told to expect.
|
273
|
+
header_bytes = int(size, 2)
|
274
|
+
|
275
|
+
# Sanity check the size
|
276
|
+
size_regex = re.compile('[0-1]{32}')
|
277
|
+
if not size_regex.match(size):
|
278
|
+
_write_error("Size received is not valid.")
|
279
|
+
|
280
|
+
line = sys.stdin.read(header_bytes)
|
281
|
+
|
282
|
+
header = json.loads(line)
|
283
|
+
|
284
|
+
method, args, kwargs, lexer = self._parse_header(header)
|
285
|
+
_bytes = 0
|
286
|
+
|
287
|
+
if lexer:
|
288
|
+
lexer = str(lexer)
|
289
|
+
|
290
|
+
# Read more bytes if necessary
|
291
|
+
if kwargs:
|
292
|
+
_bytes = kwargs.get("bytes", 0)
|
293
|
+
|
294
|
+
# Read up to the given number bytes (possibly 0)
|
295
|
+
text = sys.stdin.read(_bytes)
|
296
|
+
|
297
|
+
# Sanity check the return.
|
298
|
+
if _bytes:
|
299
|
+
start_id, end_id = self._get_ids(text)
|
300
|
+
text = self._check_and_return_text(text, start_id, end_id)
|
301
|
+
|
302
|
+
# Get the actual data from pygments.
|
303
|
+
res = self.get_data(method, lexer, args, kwargs, text)
|
304
|
+
|
305
|
+
# Put back the sanity check values.
|
306
|
+
if method == "highlight":
|
307
|
+
res = start_id + " " + res + " " + end_id
|
308
|
+
|
309
|
+
self._send_data(res, method)
|
310
|
+
|
311
|
+
except:
|
312
|
+
tb = traceback.format_exc()
|
313
|
+
_write_error(tb)
|
314
|
+
|
315
|
+
finally:
|
316
|
+
lock.release()
|
317
|
+
|
318
|
+
def main():
|
319
|
+
|
320
|
+
# Signal handlers to trap signals.
|
321
|
+
signal.signal(signal.SIGINT, _signal_handler)
|
322
|
+
signal.signal(signal.SIGTERM, _signal_handler)
|
323
|
+
signal.signal(signal.SIGHUP, _signal_handler)
|
324
|
+
|
325
|
+
mentos = Mentos()
|
326
|
+
|
327
|
+
# close fd's inherited from the ruby parent
|
328
|
+
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
329
|
+
if maxfd == resource.RLIM_INFINITY:
|
330
|
+
maxfd = 65536
|
331
|
+
|
332
|
+
for fd in range(3, maxfd):
|
333
|
+
try:
|
334
|
+
os.close(fd)
|
335
|
+
except:
|
336
|
+
pass
|
337
|
+
|
338
|
+
mentos.start()
|
339
|
+
|
340
|
+
if __name__ == "__main__":
|
341
|
+
main()
|
342
|
+
|
343
|
+
|
344
|
+
|