pygments.rb 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +40 -0
- data/README.md +3 -0
- data/lexers +0 -0
- data/lib/pygments/popen.rb +3 -2
- data/lib/pygments/version.rb +1 -1
- data/pygments.rb.gemspec +2 -1
- data/vendor/pygments-main/AUTHORS +20 -1
- data/vendor/pygments-main/CHANGES +55 -3
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/MANIFEST.in +1 -1
- data/vendor/pygments-main/Makefile +5 -8
- data/vendor/pygments-main/REVISION +1 -1
- data/vendor/pygments-main/doc/Makefile +153 -0
- data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
- data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
- data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
- data/vendor/pygments-main/doc/_templates/docssidebar.html +3 -0
- data/vendor/pygments-main/doc/_templates/indexsidebar.html +25 -0
- data/vendor/pygments-main/doc/_themes/pygments14/layout.html +98 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
- data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +401 -0
- data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +15 -0
- data/vendor/pygments-main/doc/conf.py +249 -0
- data/vendor/pygments-main/doc/docs/api.rst +316 -0
- data/vendor/pygments-main/doc/docs/authors.rst +4 -0
- data/vendor/pygments-main/doc/docs/changelog.rst +1 -0
- data/vendor/pygments-main/{docs/src/cmdline.txt → doc/docs/cmdline.rst} +9 -11
- data/vendor/pygments-main/{docs/src/filterdevelopment.txt → doc/docs/filterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/filters.txt → doc/docs/filters.rst} +4 -5
- data/vendor/pygments-main/{docs/src/formatterdevelopment.txt → doc/docs/formatterdevelopment.rst} +1 -1
- data/vendor/pygments-main/{docs/src/formatters.txt → doc/docs/formatters.rst} +6 -6
- data/vendor/pygments-main/doc/docs/index.rst +66 -0
- data/vendor/pygments-main/{docs/src/integrate.txt → doc/docs/integrate.rst} +3 -7
- data/vendor/pygments-main/{docs/src/java.txt → doc/docs/java.rst} +0 -0
- data/vendor/pygments-main/{docs/src/lexerdevelopment.txt → doc/docs/lexerdevelopment.rst} +13 -14
- data/vendor/pygments-main/{docs/src/lexers.txt → doc/docs/lexers.rst} +7 -5
- data/vendor/pygments-main/{docs/src/moinmoin.txt → doc/docs/moinmoin.rst} +0 -0
- data/vendor/pygments-main/{docs/src/plugins.txt → doc/docs/plugins.rst} +0 -0
- data/vendor/pygments-main/{docs/src/quickstart.txt → doc/docs/quickstart.rst} +22 -19
- data/vendor/pygments-main/{docs/src/rstdirective.txt → doc/docs/rstdirective.rst} +0 -0
- data/vendor/pygments-main/{docs/src/styles.txt → doc/docs/styles.rst} +2 -2
- data/vendor/pygments-main/{docs/src/tokens.txt → doc/docs/tokens.rst} +10 -7
- data/vendor/pygments-main/{docs/src/unicode.txt → doc/docs/unicode.rst} +8 -7
- data/vendor/pygments-main/doc/download.rst +41 -0
- data/vendor/pygments-main/doc/faq.rst +143 -0
- data/vendor/pygments-main/doc/index.rst +53 -0
- data/vendor/pygments-main/doc/languages.rst +151 -0
- data/vendor/pygments-main/doc/make.bat +190 -0
- data/vendor/pygments-main/{docs → doc}/pygmentize.1 +0 -0
- data/vendor/pygments-main/external/autopygmentize +65 -48
- data/vendor/pygments-main/external/markdown-processor.py +15 -15
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +2 -3
- data/vendor/pygments-main/ez_setup.py +340 -234
- data/vendor/pygments-main/pygments/__init__.py +4 -4
- data/vendor/pygments-main/pygments/cmdline.py +81 -68
- data/vendor/pygments-main/pygments/console.py +1 -1
- data/vendor/pygments-main/pygments/filter.py +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +11 -9
- data/vendor/pygments-main/pygments/formatter.py +3 -3
- data/vendor/pygments-main/pygments/formatters/__init__.py +5 -3
- data/vendor/pygments-main/pygments/formatters/_mapping.py +16 -5
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +44 -26
- data/vendor/pygments-main/pygments/formatters/img.py +21 -14
- data/vendor/pygments-main/pygments/formatters/latex.py +104 -12
- data/vendor/pygments-main/pygments/formatters/other.py +53 -6
- data/vendor/pygments-main/pygments/formatters/rtf.py +30 -16
- data/vendor/pygments-main/pygments/formatters/svg.py +2 -2
- data/vendor/pygments-main/pygments/formatters/terminal.py +41 -1
- data/vendor/pygments-main/pygments/formatters/terminal256.py +2 -2
- data/vendor/pygments-main/pygments/lexer.py +59 -39
- data/vendor/pygments-main/pygments/lexers/__init__.py +38 -15
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +15 -15
- data/vendor/pygments-main/pygments/lexers/_cocoabuiltins.py +73 -0
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +11 -1
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +14 -8
- data/vendor/pygments-main/pygments/lexers/_mapping.py +81 -30
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +1067 -95
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +7 -7
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +5 -4
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +12 -7
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +112 -18
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/agile.py +644 -382
- data/vendor/pygments-main/pygments/lexers/asm.py +66 -29
- data/vendor/pygments-main/pygments/lexers/compiled.py +1643 -174
- data/vendor/pygments-main/pygments/lexers/dalvik.py +27 -6
- data/vendor/pygments-main/pygments/lexers/dotnet.py +45 -33
- data/vendor/pygments-main/pygments/lexers/foxpro.py +3 -3
- data/vendor/pygments-main/pygments/lexers/functional.py +1510 -570
- data/vendor/pygments-main/pygments/lexers/graph.py +81 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +29 -30
- data/vendor/pygments-main/pygments/lexers/inferno.py +96 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +622 -207
- data/vendor/pygments-main/pygments/lexers/math.py +438 -70
- data/vendor/pygments-main/pygments/lexers/other.py +885 -171
- data/vendor/pygments-main/pygments/lexers/parsers.py +24 -24
- data/vendor/pygments-main/pygments/lexers/qbasic.py +157 -0
- data/vendor/pygments-main/pygments/lexers/rdf.py +99 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +28 -25
- data/vendor/pygments-main/pygments/lexers/special.py +7 -8
- data/vendor/pygments-main/pygments/lexers/sql.py +56 -23
- data/vendor/pygments-main/pygments/lexers/templates.py +377 -59
- data/vendor/pygments-main/pygments/lexers/text.py +208 -46
- data/vendor/pygments-main/pygments/lexers/web.py +729 -264
- data/vendor/pygments-main/pygments/modeline.py +1 -1
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/sphinxext.py +153 -0
- data/vendor/pygments-main/pygments/style.py +3 -2
- data/vendor/pygments-main/pygments/styles/__init__.py +5 -1
- data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
- data/vendor/pygments-main/pygments/styles/borland.py +1 -1
- data/vendor/pygments-main/pygments/styles/bw.py +1 -1
- data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
- data/vendor/pygments-main/pygments/styles/default.py +1 -1
- data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
- data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
- data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
- data/vendor/pygments-main/pygments/styles/igor.py +29 -0
- data/vendor/pygments-main/pygments/styles/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +4 -4
- data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
- data/vendor/pygments-main/pygments/styles/native.py +1 -1
- data/vendor/pygments-main/pygments/styles/paraiso_dark.py +125 -0
- data/vendor/pygments-main/pygments/styles/paraiso_light.py +125 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
- data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
- data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
- data/vendor/pygments-main/pygments/styles/tango.py +1 -1
- data/vendor/pygments-main/pygments/styles/trac.py +1 -1
- data/vendor/pygments-main/pygments/styles/vim.py +1 -1
- data/vendor/pygments-main/pygments/styles/vs.py +1 -1
- data/vendor/pygments-main/pygments/styles/xcode.py +51 -0
- data/vendor/pygments-main/pygments/token.py +4 -1
- data/vendor/pygments-main/pygments/unistring.py +6 -5
- data/vendor/pygments-main/pygments/util.py +35 -21
- data/vendor/pygments-main/scripts/check_sources.py +28 -44
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +5 -4
- data/vendor/pygments-main/scripts/find_codetags.py +27 -19
- data/vendor/pygments-main/scripts/find_error.py +16 -13
- data/vendor/pygments-main/scripts/get_vimkw.py +3 -3
- data/vendor/pygments-main/scripts/vim2pygments.py +9 -7
- data/vendor/pygments-main/setup.py +19 -19
- data/vendor/pygments-main/tests/examplefiles/99_bottles_of_beer.chpl +118 -0
- data/vendor/pygments-main/tests/examplefiles/Error.pmod +38 -0
- data/vendor/pygments-main/tests/examplefiles/FakeFile.pike +360 -0
- data/vendor/pygments-main/tests/examplefiles/{ANTLRv3.g → antlr_ANTLRv3.g} +0 -0
- data/vendor/pygments-main/tests/examplefiles/clojure-weird-keywords.clj +5 -0
- data/vendor/pygments-main/tests/examplefiles/core.cljs +52 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +13 -1
- data/vendor/pygments-main/tests/examplefiles/demo.hbs +12 -0
- data/vendor/pygments-main/tests/examplefiles/ember.handlebars +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.als +217 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +1 -1
- data/vendor/pygments-main/tests/examplefiles/example.chai +6 -0
- data/vendor/pygments-main/tests/examplefiles/example.coffee +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.e +124 -0
- data/vendor/pygments-main/tests/examplefiles/example.f90 +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.feature +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.gd +23 -0
- data/vendor/pygments-main/tests/examplefiles/example.gi +64 -0
- data/vendor/pygments-main/tests/examplefiles/example.groovy +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.hs +27 -0
- data/vendor/pygments-main/tests/examplefiles/example.hx +44 -1
- data/vendor/pygments-main/tests/examplefiles/example.i6t +32 -0
- data/vendor/pygments-main/tests/examplefiles/example.i7x +45 -0
- data/vendor/pygments-main/tests/examplefiles/example.inf +374 -0
- data/vendor/pygments-main/tests/examplefiles/example.j +564 -0
- data/vendor/pygments-main/tests/examplefiles/example.java +16 -0
- data/vendor/pygments-main/tests/examplefiles/example.kal +75 -0
- data/vendor/pygments-main/tests/examplefiles/example.liquid +42 -0
- data/vendor/pygments-main/tests/examplefiles/example.ma +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.mq4 +187 -0
- data/vendor/pygments-main/tests/examplefiles/example.mqh +123 -0
- data/vendor/pygments-main/tests/examplefiles/example.ni +57 -0
- data/vendor/pygments-main/tests/examplefiles/example.nix +80 -0
- data/vendor/pygments-main/tests/examplefiles/example.pp +8 -0
- data/vendor/pygments-main/tests/examplefiles/example.red +257 -0
- data/vendor/pygments-main/tests/examplefiles/example.reds +150 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +677 -29
- data/vendor/pygments-main/tests/examplefiles/example.sh +22 -0
- data/vendor/pygments-main/tests/examplefiles/example.slim +31 -0
- data/vendor/pygments-main/tests/examplefiles/example.sls +51 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +2 -0
- data/vendor/pygments-main/tests/examplefiles/example.todotxt +9 -0
- data/vendor/pygments-main/tests/examplefiles/exampleScript.cfc +241 -0
- data/vendor/pygments-main/tests/examplefiles/exampleTag.cfc +18 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +192 -350
- data/vendor/pygments-main/tests/examplefiles/hash_syntax.rb +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.at +6 -0
- data/vendor/pygments-main/tests/examplefiles/hello.golo +5 -0
- data/vendor/pygments-main/tests/examplefiles/hello.lsl +12 -0
- data/vendor/pygments-main/tests/examplefiles/{File.hy → hybris_File.hy} +0 -0
- data/vendor/pygments-main/tests/examplefiles/{mg_sample.pro → idl_sample.pro} +0 -0
- data/vendor/pygments-main/tests/examplefiles/iex_example +23 -0
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +24 -24
- data/vendor/pygments-main/tests/examplefiles/language.hy +165 -0
- data/vendor/pygments-main/tests/examplefiles/limbo.b +456 -0
- data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +3 -1
- data/vendor/pygments-main/tests/examplefiles/main.cmake +2 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +163 -16
- data/vendor/pygments-main/tests/examplefiles/{example.p → openedge_example} +0 -0
- data/vendor/pygments-main/tests/examplefiles/pawn_example +25 -0
- data/vendor/pygments-main/tests/examplefiles/qbasic_example +2 -0
- data/vendor/pygments-main/tests/examplefiles/r6rs-comments.scm +23 -0
- data/vendor/pygments-main/tests/examplefiles/{robotframework.txt → robotframework_test.txt} +0 -0
- data/vendor/pygments-main/tests/examplefiles/rql-queries.rql +34 -0
- data/vendor/pygments-main/tests/examplefiles/scope.cirru +43 -0
- data/vendor/pygments-main/tests/examplefiles/sparql.rq +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +37 -5
- data/vendor/pygments-main/tests/examplefiles/test.apl +26 -0
- data/vendor/pygments-main/tests/examplefiles/test.cyp +123 -0
- data/vendor/pygments-main/tests/examplefiles/test.idr +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.mask +41 -0
- data/vendor/pygments-main/tests/examplefiles/test.pan +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +3 -1
- data/vendor/pygments-main/tests/examplefiles/test.pig +148 -0
- data/vendor/pygments-main/tests/examplefiles/test.pwn +253 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +27 -7
- data/vendor/pygments-main/tests/examplefiles/test.rsl +111 -0
- data/vendor/pygments-main/tests/examplefiles/test.swift +65 -0
- data/vendor/pygments-main/tests/examplefiles/test.zep +33 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.go +10 -0
- data/vendor/pygments-main/tests/examplefiles/{test.bas → vbnet_test.bas} +0 -0
- data/vendor/pygments-main/tests/examplefiles/vctreestatus_hg +4 -0
- data/vendor/pygments-main/tests/examplefiles/vimrc +21 -0
- data/vendor/pygments-main/tests/run.py +14 -19
- data/vendor/pygments-main/tests/string_asserts.py +22 -0
- data/vendor/pygments-main/tests/test_basic_api.py +28 -14
- data/vendor/pygments-main/tests/test_cfm.py +46 -0
- data/vendor/pygments-main/tests/test_clexer.py +208 -3
- data/vendor/pygments-main/tests/test_cmdline.py +6 -5
- data/vendor/pygments-main/tests/test_examplefiles.py +30 -19
- data/vendor/pygments-main/tests/test_html_formatter.py +15 -13
- data/vendor/pygments-main/tests/test_latex_formatter.py +4 -2
- data/vendor/pygments-main/tests/test_lexers_other.py +11 -11
- data/vendor/pygments-main/tests/test_objectiveclexer.py +81 -0
- data/vendor/pygments-main/tests/test_perllexer.py +1 -1
- data/vendor/pygments-main/tests/test_qbasiclexer.py +43 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +8 -1
- data/vendor/pygments-main/tests/test_rtf_formatter.py +109 -0
- data/vendor/pygments-main/tests/test_string_asserts.py +39 -0
- data/vendor/pygments-main/tests/test_token.py +3 -3
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +1 -1
- metadata +138 -51
- data/vendor/pygments-main/docs/generate.py +0 -472
- data/vendor/pygments-main/docs/src/api.txt +0 -270
- data/vendor/pygments-main/docs/src/authors.txt +0 -5
- data/vendor/pygments-main/docs/src/changelog.txt +0 -5
- data/vendor/pygments-main/docs/src/index.txt +0 -69
- data/vendor/pygments-main/docs/src/installation.txt +0 -71
- data/vendor/pygments-main/external/rst-directive-old.py +0 -77
- data/vendor/pygments-main/scripts/reindent.py +0 -291
- data/vendor/pygments-main/tests/examplefiles/import.hs +0 -4
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +0 -24
- data/vendor/pygments-main/tests/old_run.py +0 -138
|
@@ -5,20 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
Base formatter class.
|
|
7
7
|
|
|
8
|
-
:copyright: Copyright 2006-
|
|
8
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
9
9
|
:license: BSD, see LICENSE for details.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
import codecs
|
|
13
13
|
|
|
14
|
-
from pygments.util import get_bool_opt
|
|
14
|
+
from pygments.util import get_bool_opt, string_types
|
|
15
15
|
from pygments.styles import get_style_by_name
|
|
16
16
|
|
|
17
17
|
__all__ = ['Formatter']
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def _lookup_style(style):
|
|
21
|
-
if isinstance(style,
|
|
21
|
+
if isinstance(style, string_types):
|
|
22
22
|
return get_style_by_name(style)
|
|
23
23
|
return style
|
|
24
24
|
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
Pygments formatters.
|
|
7
7
|
|
|
8
|
-
:copyright: Copyright 2006-
|
|
8
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
9
9
|
:license: BSD, see LICENSE for details.
|
|
10
10
|
"""
|
|
11
11
|
import os.path
|
|
12
12
|
import fnmatch
|
|
13
|
+
import re
|
|
13
14
|
|
|
14
15
|
from pygments.formatters._mapping import FORMATTERS
|
|
15
16
|
from pygments.plugin import find_plugin_formatters
|
|
@@ -34,7 +35,8 @@ def _init_formatter_cache():
|
|
|
34
35
|
for alias in cls.aliases:
|
|
35
36
|
_formatter_alias_cache[alias] = cls
|
|
36
37
|
for fn in cls.filenames:
|
|
37
|
-
_formatter_filename_cache.append((
|
|
38
|
+
_formatter_filename_cache.append((
|
|
39
|
+
re.compile(fnmatch.translate(fn)), cls))
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
def find_formatter_class(name):
|
|
@@ -55,7 +57,7 @@ def get_formatter_for_filename(fn, **options):
|
|
|
55
57
|
_init_formatter_cache()
|
|
56
58
|
fn = os.path.basename(fn)
|
|
57
59
|
for pattern, cls in _formatter_filename_cache:
|
|
58
|
-
if
|
|
60
|
+
if pattern.match(fn):
|
|
59
61
|
return cls(**options)
|
|
60
62
|
raise ClassNotFound("No formatter found for file name %r" % fn)
|
|
61
63
|
|
|
@@ -3,16 +3,25 @@
|
|
|
3
3
|
pygments.formatters._mapping
|
|
4
4
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
5
5
|
|
|
6
|
-
Formatter mapping
|
|
7
|
-
you change something on a builtin formatter
|
|
6
|
+
Formatter mapping definitions. This file is generated by itself. Everytime
|
|
7
|
+
you change something on a builtin formatter definition, run this script from
|
|
8
8
|
the formatters folder to update it.
|
|
9
9
|
|
|
10
10
|
Do not alter the FORMATTERS dictionary by hand.
|
|
11
11
|
|
|
12
|
-
:copyright: Copyright 2006-
|
|
12
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
13
13
|
:license: BSD, see LICENSE for details.
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
|
+
from __future__ import print_function
|
|
17
|
+
try:
|
|
18
|
+
import pygments
|
|
19
|
+
except ImportError:
|
|
20
|
+
# This block makes this mapping work like the lexer one -- not requiring
|
|
21
|
+
# that Pygments already be on your PYTHONPATH.
|
|
22
|
+
import os.path, sys
|
|
23
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
24
|
+
|
|
16
25
|
# start
|
|
17
26
|
from pygments.formatters.bbcode import BBCodeFormatter
|
|
18
27
|
from pygments.formatters.html import HtmlFormatter
|
|
@@ -23,6 +32,7 @@ from pygments.formatters.img import JpgImageFormatter
|
|
|
23
32
|
from pygments.formatters.latex import LatexFormatter
|
|
24
33
|
from pygments.formatters.other import NullFormatter
|
|
25
34
|
from pygments.formatters.other import RawTokenFormatter
|
|
35
|
+
from pygments.formatters.other import TestcaseFormatter
|
|
26
36
|
from pygments.formatters.rtf import RtfFormatter
|
|
27
37
|
from pygments.formatters.svg import SvgFormatter
|
|
28
38
|
from pygments.formatters.terminal import TerminalFormatter
|
|
@@ -41,7 +51,8 @@ FORMATTERS = {
|
|
|
41
51
|
RtfFormatter: ('RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft\xc2\xae Word\xc2\xae documents.'),
|
|
42
52
|
SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
|
|
43
53
|
Terminal256Formatter: ('Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
|
|
44
|
-
TerminalFormatter: ('Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.')
|
|
54
|
+
TerminalFormatter: ('Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
|
|
55
|
+
TestcaseFormatter: ('Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
if __name__ == '__main__':
|
|
@@ -57,7 +68,7 @@ if __name__ == '__main__':
|
|
|
57
68
|
for filename in os.listdir('.'):
|
|
58
69
|
if filename.endswith('.py') and not filename.startswith('_'):
|
|
59
70
|
module_name = 'pygments.formatters.%s' % filename[:-3]
|
|
60
|
-
print
|
|
71
|
+
print(module_name)
|
|
61
72
|
module = __import__(module_name, None, None, [''])
|
|
62
73
|
for formatter_name in module.__all__:
|
|
63
74
|
imports.append((module_name, formatter_name))
|
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
Formatter for HTML output.
|
|
7
7
|
|
|
8
|
-
:copyright: Copyright 2006-
|
|
8
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
9
9
|
:license: BSD, see LICENSE for details.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
+
from __future__ import print_function
|
|
13
|
+
|
|
12
14
|
import os
|
|
13
15
|
import sys
|
|
14
16
|
import os.path
|
|
15
|
-
import StringIO
|
|
16
17
|
|
|
17
18
|
from pygments.formatter import Formatter
|
|
18
19
|
from pygments.token import Token, Text, STANDARD_TYPES
|
|
19
|
-
from pygments.util import get_bool_opt, get_int_opt, get_list_opt,
|
|
20
|
+
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
|
21
|
+
StringIO, string_types, iteritems
|
|
20
22
|
|
|
21
23
|
try:
|
|
22
24
|
import ctags
|
|
@@ -218,29 +220,34 @@ class HtmlFormatter(Formatter):
|
|
|
218
220
|
If you set this option, the default selector for `get_style_defs()`
|
|
219
221
|
will be this class.
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
.. versionadded:: 0.9
|
|
224
|
+
If you select the ``'table'`` line numbers, the wrapping table will
|
|
225
|
+
have a CSS class of this string plus ``'table'``, the default is
|
|
226
|
+
accordingly ``'highlighttable'``.
|
|
224
227
|
|
|
225
228
|
`cssstyles`
|
|
226
229
|
Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
|
|
227
230
|
|
|
228
231
|
`prestyles`
|
|
229
|
-
Inline CSS styles for the ``<pre>`` tag (default: ``''``).
|
|
230
|
-
|
|
232
|
+
Inline CSS styles for the ``<pre>`` tag (default: ``''``).
|
|
233
|
+
|
|
234
|
+
.. versionadded:: 0.11
|
|
231
235
|
|
|
232
236
|
`cssfile`
|
|
233
237
|
If the `full` option is true and this option is given, it must be the
|
|
234
238
|
name of an external file. If the filename does not include an absolute
|
|
235
239
|
path, the file's path will be assumed to be relative to the main output
|
|
236
240
|
file's path, if the latter can be found. The stylesheet is then written
|
|
237
|
-
to this file instead of the HTML file.
|
|
241
|
+
to this file instead of the HTML file.
|
|
242
|
+
|
|
243
|
+
.. versionadded:: 0.6
|
|
238
244
|
|
|
239
245
|
`noclobber_cssfile`
|
|
240
246
|
If `cssfile` is given and the specified file exists, the css file will
|
|
241
247
|
not be overwritten. This allows the use of the `full` option in
|
|
242
248
|
combination with a user specified css file. Default is ``False``.
|
|
243
|
-
|
|
249
|
+
|
|
250
|
+
.. versionadded:: 1.1
|
|
244
251
|
|
|
245
252
|
`linenos`
|
|
246
253
|
If set to ``'table'``, output line numbers as a table with two cells,
|
|
@@ -263,7 +270,9 @@ class HtmlFormatter(Formatter):
|
|
|
263
270
|
125%``).
|
|
264
271
|
|
|
265
272
|
`hl_lines`
|
|
266
|
-
Specify a list of lines to be highlighted.
|
|
273
|
+
Specify a list of lines to be highlighted.
|
|
274
|
+
|
|
275
|
+
.. versionadded:: 0.11
|
|
267
276
|
|
|
268
277
|
`linenostart`
|
|
269
278
|
The line number for the first line (default: ``1``).
|
|
@@ -279,24 +288,30 @@ class HtmlFormatter(Formatter):
|
|
|
279
288
|
If set to ``True``, the formatter won't output the background color
|
|
280
289
|
for the wrapping element (this automatically defaults to ``False``
|
|
281
290
|
when there is no wrapping element [eg: no argument for the
|
|
282
|
-
`get_syntax_defs` method given]) (default: ``False``).
|
|
283
|
-
|
|
291
|
+
`get_syntax_defs` method given]) (default: ``False``).
|
|
292
|
+
|
|
293
|
+
.. versionadded:: 0.6
|
|
284
294
|
|
|
285
295
|
`lineseparator`
|
|
286
296
|
This string is output between lines of code. It defaults to ``"\n"``,
|
|
287
297
|
which is enough to break a line inside ``<pre>`` tags, but you can
|
|
288
|
-
e.g. set it to ``"<br>"`` to get HTML line breaks.
|
|
289
|
-
|
|
298
|
+
e.g. set it to ``"<br>"`` to get HTML line breaks.
|
|
299
|
+
|
|
300
|
+
.. versionadded:: 0.7
|
|
290
301
|
|
|
291
302
|
`lineanchors`
|
|
292
303
|
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
|
293
304
|
output line in an anchor tag with a ``name`` of ``foo-linenumber``.
|
|
294
|
-
This allows easy linking to certain lines.
|
|
305
|
+
This allows easy linking to certain lines.
|
|
306
|
+
|
|
307
|
+
.. versionadded:: 0.9
|
|
295
308
|
|
|
296
309
|
`linespans`
|
|
297
310
|
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
|
298
311
|
output line in a span tag with an ``id`` of ``foo-linenumber``.
|
|
299
|
-
This allows easy access to lines via javascript.
|
|
312
|
+
This allows easy access to lines via javascript.
|
|
313
|
+
|
|
314
|
+
.. versionadded:: 1.6
|
|
300
315
|
|
|
301
316
|
`anchorlinenos`
|
|
302
317
|
If set to `True`, will wrap line numbers in <a> tags. Used in
|
|
@@ -306,18 +321,20 @@ class HtmlFormatter(Formatter):
|
|
|
306
321
|
If set to the path of a ctags file, wrap names in anchor tags that
|
|
307
322
|
link to their definitions. `lineanchors` should be used, and the
|
|
308
323
|
tags file should specify line numbers (see the `-n` option to ctags).
|
|
309
|
-
|
|
324
|
+
|
|
325
|
+
.. versionadded:: 1.6
|
|
310
326
|
|
|
311
327
|
`tagurlformat`
|
|
312
328
|
A string formatting pattern used to generate links to ctags definitions.
|
|
313
329
|
Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
|
|
314
330
|
Defaults to an empty string, resulting in just `#prefix-number` links.
|
|
315
|
-
|
|
331
|
+
|
|
332
|
+
.. versionadded:: 1.6
|
|
316
333
|
|
|
317
334
|
|
|
318
335
|
**Subclassing the HTML formatter**
|
|
319
336
|
|
|
320
|
-
|
|
337
|
+
.. versionadded:: 0.7
|
|
321
338
|
|
|
322
339
|
The HTML formatter is now built in a way that allows easy subclassing, thus
|
|
323
340
|
customizing the output HTML code. The `format()` method calls
|
|
@@ -453,7 +470,7 @@ class HtmlFormatter(Formatter):
|
|
|
453
470
|
"""
|
|
454
471
|
if arg is None:
|
|
455
472
|
arg = ('cssclass' in self.options and '.'+self.cssclass or '')
|
|
456
|
-
if isinstance(arg,
|
|
473
|
+
if isinstance(arg, string_types):
|
|
457
474
|
args = [arg]
|
|
458
475
|
else:
|
|
459
476
|
args = list(arg)
|
|
@@ -467,7 +484,7 @@ class HtmlFormatter(Formatter):
|
|
|
467
484
|
return ', '.join(tmp)
|
|
468
485
|
|
|
469
486
|
styles = [(level, ttype, cls, style)
|
|
470
|
-
for cls, (style, ttype, level) in self.class2style
|
|
487
|
+
for cls, (style, ttype, level) in iteritems(self.class2style)
|
|
471
488
|
if cls and style]
|
|
472
489
|
styles.sort()
|
|
473
490
|
lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
|
|
@@ -505,8 +522,9 @@ class HtmlFormatter(Formatter):
|
|
|
505
522
|
cssfilename = os.path.join(os.path.dirname(filename),
|
|
506
523
|
self.cssfile)
|
|
507
524
|
except AttributeError:
|
|
508
|
-
print
|
|
509
|
-
'using current directory as base for the CSS file name'
|
|
525
|
+
print('Note: Cannot determine output file name, ' \
|
|
526
|
+
'using current directory as base for the CSS file name',
|
|
527
|
+
file=sys.stderr)
|
|
510
528
|
cssfilename = self.cssfile
|
|
511
529
|
# write CSS file only if noclobber_cssfile isn't given as an option.
|
|
512
530
|
try:
|
|
@@ -515,7 +533,7 @@ class HtmlFormatter(Formatter):
|
|
|
515
533
|
cf.write(CSSFILE_TEMPLATE %
|
|
516
534
|
{'styledefs': self.get_style_defs('body')})
|
|
517
535
|
cf.close()
|
|
518
|
-
except IOError
|
|
536
|
+
except IOError as err:
|
|
519
537
|
err.strerror = 'Error writing CSS file: ' + err.strerror
|
|
520
538
|
raise
|
|
521
539
|
|
|
@@ -534,7 +552,7 @@ class HtmlFormatter(Formatter):
|
|
|
534
552
|
yield 0, DOC_FOOTER
|
|
535
553
|
|
|
536
554
|
def _wrap_tablelinenos(self, inner):
|
|
537
|
-
dummyoutfile = StringIO
|
|
555
|
+
dummyoutfile = StringIO()
|
|
538
556
|
lncount = 0
|
|
539
557
|
for t, line in inner:
|
|
540
558
|
if t:
|
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
Formatter for Pixmap output.
|
|
7
7
|
|
|
8
|
-
:copyright: Copyright 2006-
|
|
8
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
9
9
|
:license: BSD, see LICENSE for details.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
import sys
|
|
13
13
|
|
|
14
14
|
from pygments.formatter import Formatter
|
|
15
|
-
from pygments.util import get_bool_opt, get_int_opt, \
|
|
16
|
-
|
|
15
|
+
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
|
16
|
+
get_choice_opt, xrange
|
|
17
17
|
|
|
18
18
|
# Import this carefully
|
|
19
19
|
try:
|
|
@@ -25,7 +25,10 @@ except ImportError:
|
|
|
25
25
|
try:
|
|
26
26
|
import _winreg
|
|
27
27
|
except ImportError:
|
|
28
|
-
|
|
28
|
+
try:
|
|
29
|
+
import winreg as _winreg
|
|
30
|
+
except ImportError:
|
|
31
|
+
_winreg = None
|
|
29
32
|
|
|
30
33
|
__all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
|
|
31
34
|
'BmpImageFormatter']
|
|
@@ -72,7 +75,10 @@ class FontManager(object):
|
|
|
72
75
|
self._create_nix()
|
|
73
76
|
|
|
74
77
|
def _get_nix_font_path(self, name, style):
|
|
75
|
-
|
|
78
|
+
try:
|
|
79
|
+
from commands import getstatusoutput
|
|
80
|
+
except ImportError:
|
|
81
|
+
from subprocess import getstatusoutput
|
|
76
82
|
exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
|
|
77
83
|
(name, style))
|
|
78
84
|
if not exit:
|
|
@@ -169,7 +175,7 @@ class ImageFormatter(Formatter):
|
|
|
169
175
|
Create a PNG image from source code. This uses the Python Imaging Library to
|
|
170
176
|
generate a pixmap from the source code.
|
|
171
177
|
|
|
172
|
-
|
|
178
|
+
.. versionadded:: 0.10
|
|
173
179
|
|
|
174
180
|
Additional options accepted:
|
|
175
181
|
|
|
@@ -258,12 +264,16 @@ class ImageFormatter(Formatter):
|
|
|
258
264
|
Default: 6
|
|
259
265
|
|
|
260
266
|
`hl_lines`
|
|
261
|
-
Specify a list of lines to be highlighted.
|
|
267
|
+
Specify a list of lines to be highlighted.
|
|
268
|
+
|
|
269
|
+
.. versionadded:: 1.2
|
|
262
270
|
|
|
263
271
|
Default: empty list
|
|
264
272
|
|
|
265
273
|
`hl_color`
|
|
266
|
-
Specify the color for highlighting lines.
|
|
274
|
+
Specify the color for highlighting lines.
|
|
275
|
+
|
|
276
|
+
.. versionadded:: 1.2
|
|
267
277
|
|
|
268
278
|
Default: highlight color of the selected style
|
|
269
279
|
"""
|
|
@@ -513,8 +523,7 @@ class GifImageFormatter(ImageFormatter):
|
|
|
513
523
|
Create a GIF image from source code. This uses the Python Imaging Library to
|
|
514
524
|
generate a pixmap from the source code.
|
|
515
525
|
|
|
516
|
-
|
|
517
|
-
suitable `image_format` option to the `ImageFormatter`.)
|
|
526
|
+
.. versionadded:: 1.0
|
|
518
527
|
"""
|
|
519
528
|
|
|
520
529
|
name = 'img_gif'
|
|
@@ -528,8 +537,7 @@ class JpgImageFormatter(ImageFormatter):
|
|
|
528
537
|
Create a JPEG image from source code. This uses the Python Imaging Library to
|
|
529
538
|
generate a pixmap from the source code.
|
|
530
539
|
|
|
531
|
-
|
|
532
|
-
suitable `image_format` option to the `ImageFormatter`.)
|
|
540
|
+
.. versionadded:: 1.0
|
|
533
541
|
"""
|
|
534
542
|
|
|
535
543
|
name = 'img_jpg'
|
|
@@ -543,8 +551,7 @@ class BmpImageFormatter(ImageFormatter):
|
|
|
543
551
|
Create a bitmap image from source code. This uses the Python Imaging Library to
|
|
544
552
|
generate a pixmap from the source code.
|
|
545
553
|
|
|
546
|
-
|
|
547
|
-
suitable `image_format` option to the `ImageFormatter`.)
|
|
554
|
+
.. versionadded:: 1.0
|
|
548
555
|
"""
|
|
549
556
|
|
|
550
557
|
name = 'img_bmp'
|
|
@@ -5,13 +5,17 @@
|
|
|
5
5
|
|
|
6
6
|
Formatter for LaTeX fancyvrb output.
|
|
7
7
|
|
|
8
|
-
:copyright: Copyright 2006-
|
|
8
|
+
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
|
|
9
9
|
:license: BSD, see LICENSE for details.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
+
from __future__ import division
|
|
13
|
+
|
|
12
14
|
from pygments.formatter import Formatter
|
|
15
|
+
from pygments.lexer import Lexer
|
|
13
16
|
from pygments.token import Token, STANDARD_TYPES
|
|
14
|
-
from pygments.util import get_bool_opt, get_int_opt, StringIO
|
|
17
|
+
from pygments.util import get_bool_opt, get_int_opt, StringIO, xrange, \
|
|
18
|
+
iteritems
|
|
15
19
|
|
|
16
20
|
|
|
17
21
|
__all__ = ['LatexFormatter']
|
|
@@ -152,7 +156,7 @@ class LatexFormatter(Formatter):
|
|
|
152
156
|
|
|
153
157
|
.. sourcecode:: latex
|
|
154
158
|
|
|
155
|
-
\begin{Verbatim}[commandchars
|
|
159
|
+
\begin{Verbatim}[commandchars=\\\{\}]
|
|
156
160
|
\PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
|
|
157
161
|
\PY{k}{pass}
|
|
158
162
|
\end{Verbatim}
|
|
@@ -205,19 +209,33 @@ class LatexFormatter(Formatter):
|
|
|
205
209
|
`commandprefix`
|
|
206
210
|
The LaTeX commands used to produce colored output are constructed
|
|
207
211
|
using this prefix and some letters (default: ``'PY'``).
|
|
208
|
-
*New in Pygments 0.7.*
|
|
209
212
|
|
|
210
|
-
|
|
213
|
+
.. versionadded:: 0.7
|
|
214
|
+
.. versionchanged:: 0.10
|
|
215
|
+
The default is now ``'PY'`` instead of ``'C'``.
|
|
211
216
|
|
|
212
217
|
`texcomments`
|
|
213
218
|
If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
|
|
214
219
|
in comment tokens is not escaped so that LaTeX can render it (default:
|
|
215
|
-
``False``).
|
|
220
|
+
``False``).
|
|
221
|
+
|
|
222
|
+
.. versionadded:: 1.2
|
|
216
223
|
|
|
217
224
|
`mathescape`
|
|
218
225
|
If set to ``True``, enables LaTeX math mode escape in comments. That
|
|
219
226
|
is, ``'$...$'`` inside a comment will trigger math mode (default:
|
|
220
|
-
``False``).
|
|
227
|
+
``False``).
|
|
228
|
+
|
|
229
|
+
.. versionadded:: 1.2
|
|
230
|
+
|
|
231
|
+
`escapeinside`
|
|
232
|
+
If set to a string of length 2, enables escaping to LaTeX. Text
|
|
233
|
+
delimited by these 2 characters is read as LaTeX code and
|
|
234
|
+
typeset accordingly. It has no effect in string literals. It has
|
|
235
|
+
no effect in comments if `texcomments` or `mathescape` is
|
|
236
|
+
set. (default: ``''``).
|
|
237
|
+
|
|
238
|
+
.. versionadded:: 2.0
|
|
221
239
|
"""
|
|
222
240
|
name = 'LaTeX'
|
|
223
241
|
aliases = ['latex', 'tex']
|
|
@@ -235,6 +253,13 @@ class LatexFormatter(Formatter):
|
|
|
235
253
|
self.commandprefix = options.get('commandprefix', 'PY')
|
|
236
254
|
self.texcomments = get_bool_opt(options, 'texcomments', False)
|
|
237
255
|
self.mathescape = get_bool_opt(options, 'mathescape', False)
|
|
256
|
+
self.escapeinside = options.get('escapeinside', '')
|
|
257
|
+
|
|
258
|
+
if len(self.escapeinside) == 2:
|
|
259
|
+
self.left = self.escapeinside[0]
|
|
260
|
+
self.right = self.escapeinside[1]
|
|
261
|
+
else:
|
|
262
|
+
self.escapeinside = ''
|
|
238
263
|
|
|
239
264
|
self._create_stylesheet()
|
|
240
265
|
|
|
@@ -291,7 +316,7 @@ class LatexFormatter(Formatter):
|
|
|
291
316
|
"""
|
|
292
317
|
cp = self.commandprefix
|
|
293
318
|
styles = []
|
|
294
|
-
for name, definition in self.cmd2def
|
|
319
|
+
for name, definition in iteritems(self.cmd2def):
|
|
295
320
|
styles.append(r'\expandafter\def\csname %s@tok@%s\endcsname{%s}' %
|
|
296
321
|
(cp, name, definition))
|
|
297
322
|
return STYLE_TEMPLATE % {'cp': self.commandprefix,
|
|
@@ -306,14 +331,14 @@ class LatexFormatter(Formatter):
|
|
|
306
331
|
realoutfile = outfile
|
|
307
332
|
outfile = StringIO()
|
|
308
333
|
|
|
309
|
-
outfile.write(
|
|
334
|
+
outfile.write(u'\\begin{Verbatim}[commandchars=\\\\\\{\\}')
|
|
310
335
|
if self.linenos:
|
|
311
336
|
start, step = self.linenostart, self.linenostep
|
|
312
337
|
outfile.write(u',numbers=left' +
|
|
313
338
|
(start and u',firstnumber=%d' % start or u'') +
|
|
314
339
|
(step and u',stepnumber=%d' % step or u''))
|
|
315
|
-
if self.mathescape or self.texcomments:
|
|
316
|
-
outfile.write(
|
|
340
|
+
if self.mathescape or self.texcomments or self.escapeinside:
|
|
341
|
+
outfile.write(u',codes={\\catcode`\\$=3\\catcode`\\^=7\\catcode`\\_=8}')
|
|
317
342
|
if self.verboptions:
|
|
318
343
|
outfile.write(u',' + self.verboptions)
|
|
319
344
|
outfile.write(u']\n')
|
|
@@ -342,9 +367,22 @@ class LatexFormatter(Formatter):
|
|
|
342
367
|
parts[i] = escape_tex(part, self.commandprefix)
|
|
343
368
|
in_math = not in_math
|
|
344
369
|
value = '$'.join(parts)
|
|
370
|
+
elif self.escapeinside:
|
|
371
|
+
text = value
|
|
372
|
+
value = ''
|
|
373
|
+
while len(text) > 0:
|
|
374
|
+
a,sep1,text = text.partition(self.left)
|
|
375
|
+
if len(sep1) > 0:
|
|
376
|
+
b,sep2,text = text.partition(self.right)
|
|
377
|
+
if len(sep2) > 0:
|
|
378
|
+
value += escape_tex(a, self.commandprefix) + b
|
|
379
|
+
else:
|
|
380
|
+
value += escape_tex(a + sep1 + b, self.commandprefix)
|
|
381
|
+
else:
|
|
382
|
+
value = value + escape_tex(a, self.commandprefix)
|
|
345
383
|
else:
|
|
346
384
|
value = escape_tex(value, self.commandprefix)
|
|
347
|
-
|
|
385
|
+
elif ttype not in Token.Escape:
|
|
348
386
|
value = escape_tex(value, self.commandprefix)
|
|
349
387
|
styles = []
|
|
350
388
|
while ttype is not Token:
|
|
@@ -376,3 +414,57 @@ class LatexFormatter(Formatter):
|
|
|
376
414
|
encoding = self.encoding or 'latin1',
|
|
377
415
|
styledefs = self.get_style_defs(),
|
|
378
416
|
code = outfile.getvalue()))
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class LatexEmbeddedLexer(Lexer):
|
|
420
|
+
r"""
|
|
421
|
+
|
|
422
|
+
This lexer takes one lexer as argument, the lexer for the language
|
|
423
|
+
being formatted, and the left and right delimiters for escaped text.
|
|
424
|
+
|
|
425
|
+
First everything is scanned using the language lexer to obtain
|
|
426
|
+
strings and comments. All other consecutive tokens are merged and
|
|
427
|
+
the resulting text is scanned for escaped segments, which are given
|
|
428
|
+
the Token.Escape type. Finally text that is not escaped is scanned
|
|
429
|
+
again with the language lexer.
|
|
430
|
+
"""
|
|
431
|
+
def __init__(self, left, right, lang, **options):
|
|
432
|
+
self.left = left
|
|
433
|
+
self.right = right
|
|
434
|
+
self.lang = lang
|
|
435
|
+
Lexer.__init__(self, **options)
|
|
436
|
+
|
|
437
|
+
def get_tokens_unprocessed(self, text):
|
|
438
|
+
buf = ''
|
|
439
|
+
for i, t, v in self.lang.get_tokens_unprocessed(text):
|
|
440
|
+
if t in Token.Comment or t in Token.String:
|
|
441
|
+
if buf:
|
|
442
|
+
for x in self.get_tokens_aux(idx, buf):
|
|
443
|
+
yield x
|
|
444
|
+
buf = ''
|
|
445
|
+
yield i, t, v
|
|
446
|
+
else:
|
|
447
|
+
if not buf:
|
|
448
|
+
idx = i
|
|
449
|
+
buf += v
|
|
450
|
+
if buf:
|
|
451
|
+
for x in self.get_tokens_aux(idx, buf):
|
|
452
|
+
yield x
|
|
453
|
+
|
|
454
|
+
def get_tokens_aux(self, index, text):
|
|
455
|
+
while text:
|
|
456
|
+
a, sep1, text = text.partition(self.left)
|
|
457
|
+
if a:
|
|
458
|
+
for i, t, v in self.lang.get_tokens_unprocessed(a):
|
|
459
|
+
yield index + i, t, v
|
|
460
|
+
index += len(a)
|
|
461
|
+
if sep1:
|
|
462
|
+
b, sep2, text = text.partition(self.right)
|
|
463
|
+
if sep2:
|
|
464
|
+
yield index + len(sep1), Token.Escape, b
|
|
465
|
+
index += len(sep1) + len(b) + len(sep2)
|
|
466
|
+
else:
|
|
467
|
+
yield index, Token.Error, sep1
|
|
468
|
+
index += len(sep1)
|
|
469
|
+
text = b
|
|
470
|
+
|