gitlab-pygments.rb 0.3.2 → 0.5.4
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/.gitignore +1 -0
- data/CHANGELOG.md +71 -0
- data/Gemfile +1 -1
- data/LICENSE +17 -0
- data/README.md +28 -1
- data/Rakefile +2 -5
- data/lexers +0 -0
- data/lib/pygments/mentos.py +19 -12
- data/lib/pygments/popen.rb +21 -4
- data/lib/pygments/version.rb +1 -1
- data/pygments.rb.gemspec +2 -0
- data/test/test_pygments.rb +13 -2
- data/vendor/custom_lexers/github.py +206 -3
- data/vendor/pygments-main/AUTHORS +41 -3
- data/vendor/pygments-main/CHANGES +132 -5
- data/vendor/pygments-main/LICENSE +1 -1
- data/vendor/pygments-main/Makefile +1 -1
- data/vendor/pygments-main/REVISION +1 -1
- data/vendor/pygments-main/docs/generate.py +1 -1
- data/vendor/pygments-main/docs/src/api.txt +1 -1
- data/vendor/pygments-main/docs/src/index.txt +1 -1
- data/vendor/pygments-main/docs/src/integrate.txt +5 -0
- data/vendor/pygments-main/docs/src/java.txt +70 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +52 -0
- data/vendor/pygments-main/external/autopygmentize +64 -0
- data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +144 -0
- data/vendor/pygments-main/external/markdown-processor.py +2 -2
- data/vendor/pygments-main/external/moin-parser.py +1 -1
- data/vendor/pygments-main/external/rst-directive-old.py +1 -1
- data/vendor/pygments-main/external/rst-directive.py +1 -1
- data/vendor/pygments-main/pygmentize +1 -1
- data/vendor/pygments-main/pygments/__init__.py +2 -2
- data/vendor/pygments-main/pygments/cmdline.py +14 -6
- 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 +3 -4
- data/vendor/pygments-main/pygments/formatter.py +4 -1
- data/vendor/pygments-main/pygments/formatters/__init__.py +1 -1
- data/vendor/pygments-main/pygments/formatters/_mapping.py +3 -3
- data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
- data/vendor/pygments-main/pygments/formatters/html.py +73 -2
- data/vendor/pygments-main/pygments/formatters/img.py +2 -2
- data/vendor/pygments-main/pygments/formatters/latex.py +9 -9
- data/vendor/pygments-main/pygments/formatters/other.py +1 -3
- data/vendor/pygments-main/pygments/formatters/rtf.py +1 -1
- data/vendor/pygments-main/pygments/formatters/svg.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal.py +1 -1
- data/vendor/pygments-main/pygments/formatters/terminal256.py +1 -1
- data/vendor/pygments-main/pygments/lexer.py +78 -10
- data/vendor/pygments-main/pygments/lexers/__init__.py +13 -2
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +5172 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_mapping.py +92 -36
- data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +562 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +2 -2
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +4 -3
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +557 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +11 -0
- data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +360 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -3
- data/vendor/pygments-main/pygments/lexers/agile.py +525 -38
- data/vendor/pygments-main/pygments/lexers/asm.py +45 -7
- data/vendor/pygments-main/pygments/lexers/compiled.py +1257 -425
- data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +97 -62
- data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +931 -32
- data/vendor/pygments-main/pygments/lexers/github.py +206 -3
- data/vendor/pygments-main/pygments/lexers/hdl.py +3 -3
- data/vendor/pygments-main/pygments/lexers/jvm.py +309 -44
- data/vendor/pygments-main/pygments/lexers/math.py +876 -30
- data/vendor/pygments-main/pygments/lexers/other.py +956 -517
- data/vendor/pygments-main/pygments/lexers/parsers.py +85 -2
- data/vendor/pygments-main/pygments/lexers/shell.py +81 -18
- data/vendor/pygments-main/pygments/lexers/special.py +1 -1
- data/vendor/pygments-main/pygments/lexers/sql.py +2 -2
- data/vendor/pygments-main/pygments/lexers/templates.py +119 -8
- data/vendor/pygments-main/pygments/lexers/text.py +155 -15
- data/vendor/pygments-main/pygments/lexers/web.py +1578 -397
- data/vendor/pygments-main/pygments/modeline.py +40 -0
- data/vendor/pygments-main/pygments/plugin.py +1 -1
- data/vendor/pygments-main/pygments/scanner.py +1 -1
- data/vendor/pygments-main/pygments/style.py +1 -1
- data/vendor/pygments-main/pygments/styles/__init__.py +1 -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/manni.py +1 -1
- data/vendor/pygments-main/pygments/styles/monokai.py +1 -1
- 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/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/token.py +1 -1
- data/vendor/pygments-main/pygments/unistring.py +36 -26
- data/vendor/pygments-main/pygments/util.py +46 -1
- data/vendor/pygments-main/scripts/check_sources.py +2 -2
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +2 -0
- data/vendor/pygments-main/scripts/find_codetags.py +1 -1
- data/vendor/pygments-main/scripts/find_error.py +5 -6
- data/vendor/pygments-main/setup.cfg +1 -0
- data/vendor/pygments-main/setup.py +6 -4
- data/vendor/pygments-main/tests/examplefiles/BOM.js +1 -0
- data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -0
- data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
- data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
- data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
- data/vendor/pygments-main/tests/examplefiles/autoit_submit.au3 +25 -0
- data/vendor/pygments-main/tests/examplefiles/bigtest.nsi +308 -0
- data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
- data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +89 -4
- data/vendor/pygments-main/tests/examplefiles/example.Rd +78 -0
- data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
- data/vendor/pygments-main/tests/examplefiles/example.ceylon +52 -0
- data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -0
- data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
- data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -0
- data/vendor/pygments-main/tests/examplefiles/example.msc +43 -0
- data/vendor/pygments-main/tests/examplefiles/example.prg +161 -0
- data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
- data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
- data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
- data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +108 -0
- data/vendor/pygments-main/tests/examplefiles/example.ts +28 -0
- data/vendor/pygments-main/tests/examplefiles/example.xtend +34 -0
- data/vendor/pygments-main/tests/examplefiles/example2.msc +79 -0
- data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +133 -0
- data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
- data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
- data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +2 -1
- data/vendor/pygments-main/tests/examplefiles/http_response_example +4 -2
- data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -0
- data/vendor/pygments-main/tests/examplefiles/json.lasso +301 -0
- data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -0
- data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +41 -0
- data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +5 -2
- data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
- data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
- data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -0
- data/vendor/pygments-main/tests/examplefiles/nanomsg.intr +95 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +7 -0
- data/vendor/pygments-main/tests/examplefiles/phpMyAdmin.spec +163 -0
- data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test3.pytb +4 -0
- data/vendor/pygments-main/tests/examplefiles/robotframework.txt +39 -0
- data/vendor/pygments-main/tests/examplefiles/rust_example.rs +233 -0
- data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -0
- data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
- data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +149 -115
- data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
- data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
- data/vendor/pygments-main/tests/examplefiles/test.cu +36 -0
- data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
- data/vendor/pygments-main/tests/examplefiles/test.opa +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
- data/vendor/pygments-main/tests/examplefiles/test2.pypylog +120 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +16 -0
- data/vendor/pygments-main/tests/examplefiles/unix-io.lid +37 -0
- data/vendor/pygments-main/tests/old_run.py +1 -1
- data/vendor/pygments-main/tests/run.py +3 -2
- data/vendor/pygments-main/tests/support/tags +36 -0
- data/vendor/pygments-main/tests/test_basic_api.py +4 -3
- data/vendor/pygments-main/tests/test_clexer.py +1 -1
- data/vendor/pygments-main/tests/test_cmdline.py +1 -1
- data/vendor/pygments-main/tests/test_examplefiles.py +3 -1
- data/vendor/pygments-main/tests/test_html_formatter.py +17 -1
- data/vendor/pygments-main/tests/test_latex_formatter.py +1 -1
- data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
- data/vendor/pygments-main/tests/test_perllexer.py +1 -1
- data/vendor/pygments-main/tests/test_regexlexer.py +1 -1
- data/vendor/pygments-main/tests/test_token.py +1 -1
- data/vendor/pygments-main/tests/test_using_api.py +1 -1
- data/vendor/pygments-main/tests/test_util.py +22 -3
- metadata +84 -16
@@ -5,18 +5,23 @@
|
|
5
5
|
|
6
6
|
Formatter for HTML output.
|
7
7
|
|
8
|
-
:copyright: Copyright 2006-
|
8
|
+
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
11
|
|
12
12
|
import os
|
13
13
|
import sys
|
14
|
+
import os.path
|
14
15
|
import StringIO
|
15
16
|
|
16
17
|
from pygments.formatter import Formatter
|
17
18
|
from pygments.token import Token, Text, STANDARD_TYPES
|
18
19
|
from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
|
19
20
|
|
21
|
+
try:
|
22
|
+
import ctags
|
23
|
+
except ImportError:
|
24
|
+
ctags = None
|
20
25
|
|
21
26
|
__all__ = ['HtmlFormatter']
|
22
27
|
|
@@ -141,6 +146,12 @@ class HtmlFormatter(Formatter):
|
|
141
146
|
the style definitions inside a ``<style>`` tag, or in a separate file if
|
142
147
|
the `cssfile` option is given.
|
143
148
|
|
149
|
+
When `tagsfile` is set to the path of a ctags index file, it is used to
|
150
|
+
generate hyperlinks from names to their definition. You must enable
|
151
|
+
`anchorlines` and run ctags with the `-n` option for this to work. The
|
152
|
+
`python-ctags` module from PyPI must be installed to use this feature;
|
153
|
+
otherwise a `RuntimeError` will be raised.
|
154
|
+
|
144
155
|
The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
|
145
156
|
containing CSS rules for the CSS classes used by the formatter. The
|
146
157
|
argument `arg` can be used to specify additional CSS selectors that
|
@@ -282,10 +293,27 @@ class HtmlFormatter(Formatter):
|
|
282
293
|
output line in an anchor tag with a ``name`` of ``foo-linenumber``.
|
283
294
|
This allows easy linking to certain lines. *New in Pygments 0.9.*
|
284
295
|
|
296
|
+
`linespans`
|
297
|
+
If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
|
298
|
+
output line in a span tag with an ``id`` of ``foo-linenumber``.
|
299
|
+
This allows easy access to lines via javascript. *New in Pygments 1.6.*
|
300
|
+
|
285
301
|
`anchorlinenos`
|
286
302
|
If set to `True`, will wrap line numbers in <a> tags. Used in
|
287
303
|
combination with `linenos` and `lineanchors`.
|
288
304
|
|
305
|
+
`tagsfile`
|
306
|
+
If set to the path of a ctags file, wrap names in anchor tags that
|
307
|
+
link to their definitions. `lineanchors` should be used, and the
|
308
|
+
tags file should specify line numbers (see the `-n` option to ctags).
|
309
|
+
*New in Pygments 1.6.*
|
310
|
+
|
311
|
+
`tagurlformat`
|
312
|
+
A string formatting pattern used to generate links to ctags definitions.
|
313
|
+
Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
|
314
|
+
Defaults to an empty string, resulting in just `#prefix-number` links.
|
315
|
+
*New in Pygments 1.6.*
|
316
|
+
|
289
317
|
|
290
318
|
**Subclassing the HTML formatter**
|
291
319
|
|
@@ -351,6 +379,14 @@ class HtmlFormatter(Formatter):
|
|
351
379
|
self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
|
352
380
|
self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
|
353
381
|
self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
|
382
|
+
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
|
383
|
+
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
|
384
|
+
|
385
|
+
if self.tagsfile:
|
386
|
+
if not ctags:
|
387
|
+
raise RuntimeError('The "ctags" package must to be installed '
|
388
|
+
'to be able to use the "tagsfile" feature.')
|
389
|
+
self._ctags = ctags.CTags(self.tagsfile)
|
354
390
|
|
355
391
|
linenos = options.get('linenos', False)
|
356
392
|
if linenos == 'inline':
|
@@ -366,6 +402,7 @@ class HtmlFormatter(Formatter):
|
|
366
402
|
self.nobackground = get_bool_opt(options, 'nobackground', False)
|
367
403
|
self.lineseparator = options.get('lineseparator', '\n')
|
368
404
|
self.lineanchors = options.get('lineanchors', '')
|
405
|
+
self.linespans = options.get('linespans', '')
|
369
406
|
self.anchorlinenos = options.get('anchorlinenos', False)
|
370
407
|
self.hl_lines = set()
|
371
408
|
for lineno in get_list_opt(options, 'hl_lines', []):
|
@@ -596,7 +633,8 @@ class HtmlFormatter(Formatter):
|
|
596
633
|
|
597
634
|
def _wrap_lineanchors(self, inner):
|
598
635
|
s = self.lineanchors
|
599
|
-
i = self.linenostart - 1 # subtract 1 since we have to increment i
|
636
|
+
i = self.linenostart - 1 # subtract 1 since we have to increment i
|
637
|
+
# *before* yielding
|
600
638
|
for t, line in inner:
|
601
639
|
if t:
|
602
640
|
i += 1
|
@@ -604,6 +642,16 @@ class HtmlFormatter(Formatter):
|
|
604
642
|
else:
|
605
643
|
yield 0, line
|
606
644
|
|
645
|
+
def _wrap_linespans(self, inner):
|
646
|
+
s = self.linespans
|
647
|
+
i = self.linenostart - 1
|
648
|
+
for t, line in inner:
|
649
|
+
if t:
|
650
|
+
i += 1
|
651
|
+
yield 1, '<span id="%s-%d">%s</span>' % (s, i, line)
|
652
|
+
else:
|
653
|
+
yield 0, line
|
654
|
+
|
607
655
|
def _wrap_div(self, inner):
|
608
656
|
style = []
|
609
657
|
if (self.noclasses and not self.nobackground and
|
@@ -643,6 +691,7 @@ class HtmlFormatter(Formatter):
|
|
643
691
|
getcls = self.ttype2class.get
|
644
692
|
c2s = self.class2style
|
645
693
|
escape_table = _escape_html_table
|
694
|
+
tagsfile = self.tagsfile
|
646
695
|
|
647
696
|
lspan = ''
|
648
697
|
line = ''
|
@@ -659,6 +708,19 @@ class HtmlFormatter(Formatter):
|
|
659
708
|
|
660
709
|
parts = value.translate(escape_table).split('\n')
|
661
710
|
|
711
|
+
if tagsfile and ttype in Token.Name:
|
712
|
+
filename, linenumber = self._lookup_ctag(value)
|
713
|
+
if linenumber:
|
714
|
+
base, filename = os.path.split(filename)
|
715
|
+
if base:
|
716
|
+
base += '/'
|
717
|
+
filename, extension = os.path.splitext(filename)
|
718
|
+
url = self.tagurlformat % {'path': base, 'fname': filename,
|
719
|
+
'fext': extension}
|
720
|
+
parts[0] = "<a href=\"%s#%s-%d\">%s" % \
|
721
|
+
(url, self.lineanchors, linenumber, parts[0])
|
722
|
+
parts[-1] = parts[-1] + "</a>"
|
723
|
+
|
662
724
|
# for all but the last line
|
663
725
|
for part in parts[:-1]:
|
664
726
|
if line:
|
@@ -688,6 +750,13 @@ class HtmlFormatter(Formatter):
|
|
688
750
|
if line:
|
689
751
|
yield 1, line + (lspan and '</span>') + lsep
|
690
752
|
|
753
|
+
def _lookup_ctag(self, token):
|
754
|
+
entry = ctags.TagEntry()
|
755
|
+
if self._ctags.find(entry, token, 0):
|
756
|
+
return entry['file'], entry['lineNumber']
|
757
|
+
else:
|
758
|
+
return None, None
|
759
|
+
|
691
760
|
def _highlight_lines(self, tokensource):
|
692
761
|
"""
|
693
762
|
Highlighted the lines specified in the `hl_lines` option by
|
@@ -740,6 +809,8 @@ class HtmlFormatter(Formatter):
|
|
740
809
|
source = self._wrap_inlinelinenos(source)
|
741
810
|
if self.lineanchors:
|
742
811
|
source = self._wrap_lineanchors(source)
|
812
|
+
if self.linespans:
|
813
|
+
source = self._wrap_linespans(source)
|
743
814
|
source = self.wrap(source, outfile)
|
744
815
|
if self.linenos == 1:
|
745
816
|
source = self._wrap_tablelinenos(source)
|
@@ -5,12 +5,11 @@
|
|
5
5
|
|
6
6
|
Formatter for Pixmap output.
|
7
7
|
|
8
|
-
:copyright: Copyright 2006-
|
8
|
+
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
11
|
|
12
12
|
import sys
|
13
|
-
from commands import getstatusoutput
|
14
13
|
|
15
14
|
from pygments.formatter import Formatter
|
16
15
|
from pygments.util import get_bool_opt, get_int_opt, \
|
@@ -73,6 +72,7 @@ class FontManager(object):
|
|
73
72
|
self._create_nix()
|
74
73
|
|
75
74
|
def _get_nix_font_path(self, name, style):
|
75
|
+
from commands import getstatusoutput
|
76
76
|
exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
|
77
77
|
(name, style))
|
78
78
|
if not exit:
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Formatter for LaTeX fancyvrb output.
|
7
7
|
|
8
|
-
:copyright: Copyright 2006-
|
8
|
+
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
11
|
|
@@ -306,17 +306,17 @@ class LatexFormatter(Formatter):
|
|
306
306
|
realoutfile = outfile
|
307
307
|
outfile = StringIO()
|
308
308
|
|
309
|
-
outfile.write(
|
309
|
+
outfile.write(ur'\begin{Verbatim}[commandchars=\\\{\}')
|
310
310
|
if self.linenos:
|
311
311
|
start, step = self.linenostart, self.linenostep
|
312
|
-
outfile.write(',numbers=left' +
|
313
|
-
(start and ',firstnumber=%d' % start or '') +
|
314
|
-
(step and ',stepnumber=%d' % step or ''))
|
312
|
+
outfile.write(u',numbers=left' +
|
313
|
+
(start and u',firstnumber=%d' % start or u'') +
|
314
|
+
(step and u',stepnumber=%d' % step or u''))
|
315
315
|
if self.mathescape or self.texcomments:
|
316
|
-
outfile.write(
|
316
|
+
outfile.write(ur',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
|
317
317
|
if self.verboptions:
|
318
|
-
outfile.write(',' + self.verboptions)
|
319
|
-
outfile.write(']\n')
|
318
|
+
outfile.write(u',' + self.verboptions)
|
319
|
+
outfile.write(u']\n')
|
320
320
|
|
321
321
|
for ttype, value in tokensource:
|
322
322
|
if ttype in Token.Comment:
|
@@ -366,7 +366,7 @@ class LatexFormatter(Formatter):
|
|
366
366
|
else:
|
367
367
|
outfile.write(value)
|
368
368
|
|
369
|
-
outfile.write('\\end{Verbatim}\n')
|
369
|
+
outfile.write(u'\\end{Verbatim}\n')
|
370
370
|
|
371
371
|
if self.full:
|
372
372
|
realoutfile.write(DOC_TEMPLATE %
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Other formatters: NullFormatter, RawTokenFormatter.
|
7
7
|
|
8
|
-
:copyright: Copyright 2006-
|
8
|
+
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
11
|
|
@@ -102,8 +102,6 @@ class RawTokenFormatter(Formatter):
|
|
102
102
|
outfile.write(text.encode())
|
103
103
|
flush = outfile.flush
|
104
104
|
|
105
|
-
lasttype = None
|
106
|
-
lastval = u''
|
107
105
|
if self.error_color:
|
108
106
|
for ttype, value in tokensource:
|
109
107
|
line = "%s\t%r\n" % (ttype, value)
|
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
Base lexer classes.
|
7
7
|
|
8
|
-
:copyright: Copyright 2006-
|
8
|
+
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
|
9
9
|
:license: BSD, see LICENSE for details.
|
10
10
|
"""
|
11
|
-
import re
|
11
|
+
import re, itertools
|
12
12
|
|
13
13
|
from pygments.filter import apply_filters, Filter
|
14
14
|
from pygments.filters import get_filter_by_name
|
@@ -18,7 +18,7 @@ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
|
|
18
18
|
|
19
19
|
|
20
20
|
__all__ = ['Lexer', 'RegexLexer', 'ExtendedRegexLexer', 'DelegatingLexer',
|
21
|
-
'LexerContext', 'include', 'bygroups', 'using', 'this']
|
21
|
+
'LexerContext', 'include', 'inherit', 'bygroups', 'using', 'this']
|
22
22
|
|
23
23
|
|
24
24
|
_encoding_map = [('\xef\xbb\xbf', 'utf-8'),
|
@@ -72,15 +72,18 @@ class Lexer(object):
|
|
72
72
|
#: Shortcuts for the lexer
|
73
73
|
aliases = []
|
74
74
|
|
75
|
-
#:
|
75
|
+
#: File name globs
|
76
76
|
filenames = []
|
77
77
|
|
78
|
-
#:
|
78
|
+
#: Secondary file name globs
|
79
79
|
alias_filenames = []
|
80
80
|
|
81
|
-
#:
|
81
|
+
#: MIME types
|
82
82
|
mimetypes = []
|
83
83
|
|
84
|
+
#: Priority, should multiple lexers match and no content is provided
|
85
|
+
priority = 0
|
86
|
+
|
84
87
|
__metaclass__ = LexerMeta
|
85
88
|
|
86
89
|
def __init__(self, **options):
|
@@ -163,6 +166,10 @@ class Lexer(object):
|
|
163
166
|
text = decoded
|
164
167
|
else:
|
165
168
|
text = text.decode(self.encoding)
|
169
|
+
else:
|
170
|
+
if text.startswith(u'\ufeff'):
|
171
|
+
text = text[len(u'\ufeff'):]
|
172
|
+
|
166
173
|
# text now *is* a unicode string
|
167
174
|
text = text.replace('\r\n', '\n')
|
168
175
|
text = text.replace('\r', '\n')
|
@@ -238,6 +245,16 @@ class include(str):
|
|
238
245
|
pass
|
239
246
|
|
240
247
|
|
248
|
+
class _inherit(object):
|
249
|
+
"""
|
250
|
+
Indicates the a state should inherit from its superclass.
|
251
|
+
"""
|
252
|
+
def __repr__(self):
|
253
|
+
return 'inherit'
|
254
|
+
|
255
|
+
inherit = _inherit()
|
256
|
+
|
257
|
+
|
241
258
|
class combined(tuple):
|
242
259
|
"""
|
243
260
|
Indicates a state combined from multiple states.
|
@@ -428,6 +445,9 @@ class RegexLexerMeta(LexerMeta):
|
|
428
445
|
tokens.extend(cls._process_state(unprocessed, processed,
|
429
446
|
str(tdef)))
|
430
447
|
continue
|
448
|
+
if isinstance(tdef, _inherit):
|
449
|
+
# processed already
|
450
|
+
continue
|
431
451
|
|
432
452
|
assert type(tdef) is tuple, "wrong rule def %r" % tdef
|
433
453
|
|
@@ -456,6 +476,49 @@ class RegexLexerMeta(LexerMeta):
|
|
456
476
|
cls._process_state(tokendefs, processed, state)
|
457
477
|
return processed
|
458
478
|
|
479
|
+
def get_tokendefs(cls):
|
480
|
+
"""
|
481
|
+
Merge tokens from superclasses in MRO order, returning a single tokendef
|
482
|
+
dictionary.
|
483
|
+
|
484
|
+
Any state that is not defined by a subclass will be inherited
|
485
|
+
automatically. States that *are* defined by subclasses will, by
|
486
|
+
default, override that state in the superclass. If a subclass wishes to
|
487
|
+
inherit definitions from a superclass, it can use the special value
|
488
|
+
"inherit", which will cause the superclass' state definition to be
|
489
|
+
included at that point in the state.
|
490
|
+
"""
|
491
|
+
tokens = {}
|
492
|
+
inheritable = {}
|
493
|
+
for c in itertools.chain((cls,), cls.__mro__):
|
494
|
+
toks = c.__dict__.get('tokens', {})
|
495
|
+
|
496
|
+
for state, items in toks.iteritems():
|
497
|
+
curitems = tokens.get(state)
|
498
|
+
if curitems is None:
|
499
|
+
tokens[state] = items
|
500
|
+
try:
|
501
|
+
inherit_ndx = items.index(inherit)
|
502
|
+
except ValueError:
|
503
|
+
continue
|
504
|
+
inheritable[state] = inherit_ndx
|
505
|
+
continue
|
506
|
+
|
507
|
+
inherit_ndx = inheritable.pop(state, None)
|
508
|
+
if inherit_ndx is None:
|
509
|
+
continue
|
510
|
+
|
511
|
+
# Replace the "inherit" value with the items
|
512
|
+
curitems[inherit_ndx:inherit_ndx+1] = items
|
513
|
+
try:
|
514
|
+
new_inh_ndx = items.index(inherit)
|
515
|
+
except ValueError:
|
516
|
+
pass
|
517
|
+
else:
|
518
|
+
inheritable[state] = inherit_ndx + new_inh_ndx
|
519
|
+
|
520
|
+
return tokens
|
521
|
+
|
459
522
|
def __call__(cls, *args, **kwds):
|
460
523
|
"""Instantiate cls after preprocessing its token definitions."""
|
461
524
|
if '_tokens' not in cls.__dict__:
|
@@ -465,7 +528,7 @@ class RegexLexerMeta(LexerMeta):
|
|
465
528
|
# don't process yet
|
466
529
|
pass
|
467
530
|
else:
|
468
|
-
cls._tokens = cls.process_tokendef('', cls.
|
531
|
+
cls._tokens = cls.process_tokendef('', cls.get_tokendefs())
|
469
532
|
|
470
533
|
return type.__call__(cls, *args, **kwds)
|
471
534
|
|
@@ -606,7 +669,13 @@ class ExtendedRegexLexer(RegexLexer):
|
|
606
669
|
if new_state is not None:
|
607
670
|
# state transition
|
608
671
|
if isinstance(new_state, tuple):
|
609
|
-
|
672
|
+
for state in new_state:
|
673
|
+
if state == '#pop':
|
674
|
+
ctx.stack.pop()
|
675
|
+
elif state == '#push':
|
676
|
+
ctx.stack.append(statestack[-1])
|
677
|
+
else:
|
678
|
+
ctx.stack.append(state)
|
610
679
|
elif isinstance(new_state, int):
|
611
680
|
# pop
|
612
681
|
del ctx.stack[new_state:]
|
@@ -622,10 +691,10 @@ class ExtendedRegexLexer(RegexLexer):
|
|
622
691
|
break
|
623
692
|
if text[ctx.pos] == '\n':
|
624
693
|
# at EOL, reset state to "root"
|
625
|
-
ctx.pos += 1
|
626
694
|
ctx.stack = ['root']
|
627
695
|
statetokens = tokendefs['root']
|
628
696
|
yield ctx.pos, Text, u'\n'
|
697
|
+
ctx.pos += 1
|
629
698
|
continue
|
630
699
|
yield ctx.pos, Error, text[ctx.pos]
|
631
700
|
ctx.pos += 1
|
@@ -694,4 +763,3 @@ def do_insertions(insertions, tokens):
|
|
694
763
|
except StopIteration:
|
695
764
|
insleft = False
|
696
765
|
break # not strictly necessary
|
697
|
-
|