Skip to content
This repository was archived by the owner on Oct 5, 2019. It is now read-only.

Commit ffe6efe

Browse files
author
Anteru
committed
Merged in lucatorella/pygments-main (pull request #813)
Add support for @import keyword in Objective-C
2 parents b3710c3 + 67b0eb9 commit ffe6efe

38 files changed

+2509
-56
lines changed

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Other contributors, listed alphabetically, are:
132132
* Stephen McKamey -- Duel/JBST lexer
133133
* Brian McKenna -- F# lexer
134134
* Charles McLaughlin -- Puppet lexer
135+
* Kurt McKee -- Tera Term macro lexer
135136
* Lukas Meuser -- BBCode formatter, Lua lexer
136137
* Cat Miller -- Pig lexer
137138
* Paul Miller -- LiveScript lexer
@@ -221,5 +222,7 @@ Other contributors, listed alphabetically, are:
221222
* Rob Zimmerman -- Kal lexer
222223
* Vincent Zurczak -- Roboconf lexer
223224
* Rostyslav Golda -- FloScript lexer
225+
* GitHub, Inc -- DASM16, Augeas, TOML, and Slash lexers
226+
* Simon Garnotel -- FreeFem++ lexer
224227

225228
Many thanks for all contributions!

CHANGES

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,66 @@ Issue numbers refer to the tracker at
66
pull request numbers to the requests at
77
<https://bitbucket.org/birkenfeld/pygments-main/pull-requests/merged>.
88

9+
Version 2.4.1
10+
-------------
11+
12+
- Updated lexers:
13+
14+
* Coq (#1430)
15+
* MSDOS Session (PR#734)
16+
* Prolog (#1511)
17+
* TypeScript (#1515)
18+
19+
- Support CSS variables in stylesheets (PR#814)
20+
- Fix F# lexer name (PR#709)
21+
- Fix ``TerminalFormatter`` using bold for bright text (#1480)
22+
923
Version 2.4.0
1024
-------------
11-
(not released yet)
25+
(released May 8, 2019)
1226

1327
- Added lexers:
1428

29+
* Augeas (PR#807)
30+
* BBC Basic (PR#806)
31+
* Boa (PR#756)
1532
* Charm++ CI (PR#788)
33+
* DASM16 (PR#807)
1634
* FloScript (PR#750)
35+
* FreeFem++ (PR#785)
1736
* Hspec (PR#790)
37+
* Pony (PR#627)
1838
* SGF (PR#780)
39+
* Slash (PR#807)
1940
* Slurm (PR#760)
41+
* Tera Term Language (PR#749)
42+
* TOML (PR#807)
2043
* Unicon (PR#731)
2144
* VBScript (PR#673)
2245

2346
- Updated lexers:
2447

48+
* Apache2 (PR#766)
2549
* Cypher (PR#746)
2650
* LLVM (PR#792)
51+
* Makefiles (PR#766)
2752
* PHP (#1482)
53+
* Rust
2854
* SQL (PR#672)
2955
* Stan (PR#774)
3056
* Stata (PR#800)
3157
* Terraform (PR#787)
58+
* YAML
3259

3360
- Add solarized style (PR#708)
3461
- Add support for Markdown reference-style links (PR#753)
62+
- Add license information to generated HTML/CSS files (#1496)
3563
- Change ANSI color names (PR#777)
3664
- Fix catastrophic backtracking in the bash lexer (#1494)
3765
- Fix documentation failing to build using Sphinx 2.0 (#1501)
3866
- Fix incorrect links in the Lisp and R lexer documentation (PR#775)
3967
- Fix rare unicode errors on Python 2.7 (PR#798, #1492)
68+
- Fix lexers popping from an empty stack (#1506)
4069
- TypoScript uses ``.typoscript`` now (#1498)
4170
- Updated Trove classifiers and ``pip`` requirements (PR#799)
4271

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2006-2017 by the respective authors (see AUTHORS file).
1+
Copyright (c) 2006-2019 by the respective authors (see AUTHORS file).
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

doc/languages.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ Programming languages
1414
* AppleScript
1515
* Assembly (various)
1616
* Asymptote
17+
* `Augeas <http://augeas.net>`_
1718
* Awk
19+
* BBC Basic
1820
* Befunge
21+
* `Boa <http://boa.cs.iastate.edu/docs/index.php>`_
1922
* Boo
2023
* BrainFuck
2124
* C, C++
@@ -31,6 +34,7 @@ Programming languages
3134
* `Cython <http://cython.org>`_
3235
* `D <http://dlang.org>`_
3336
* Dart
37+
* DCPU-16
3438
* Delphi
3539
* Dylan
3640
* `Elm <http://elm-lang.org/>`_
@@ -41,6 +45,7 @@ Programming languages
4145
* `Fennel <https://fennel-lang.org/>`_
4246
* `FloScript <http://ioflo.com/>`_
4347
* Fortran
48+
* `FreeFEM++ <https://freefem.org/>`_
4449
* F#
4550
* GAP
4651
* Gherkin (Cucumber)
@@ -70,6 +75,7 @@ Programming languages
7075
* OCaml
7176
* PHP
7277
* `Perl 5 <http://perl.org>`_ and `Perl 6 <https://perl6.org>`_
78+
* `Pony <https://www.ponylang.io/>`_
7379
* PovRay
7480
* PostScript
7581
* PowerShell
@@ -85,10 +91,13 @@ Programming languages
8591
* Scheme
8692
* Scilab
8793
* `SGF <https://www.red-bean.com/sgf/>`_
94+
* `Slash <https://github.com/arturadib/Slash-A>`_
8895
* `Slurm <https://slurm.schedmd.com/overview.html>`_
8996
* Smalltalk
9097
* SNOBOL
9198
* Tcl
99+
* `Tera Term language <https://ttssh2.osdn.jp/>`_
100+
* `TOML <https://github.com/toml-lang/toml>`_
92101
* Vala
93102
* Verilog
94103
* VHDL

pygments/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from pygments.util import StringIO, BytesIO
3131

32-
__version__ = '2.3.1'
32+
__version__ = '2.4.0'
3333
__docformat__ = 'restructuredtext'
3434

3535
__all__ = ['lex', 'format', 'highlight']

pygments/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
x = 30
3131
for d, l in zip(dark_colors, light_colors):
3232
codes[d] = esc + "%im" % x
33-
codes[l] = esc + "%i;01m" % x
33+
codes[l] = esc + "%im" % (60 + x)
3434
x += 1
3535

3636
del d, l, x

pygments/formatters/html.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Formatter for HTML output.
77
8-
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
8+
:copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
99
:license: BSD, see LICENSE for details.
1010
"""
1111

@@ -41,6 +41,11 @@ def escape_html(text, table=_escape_html_table):
4141
"""Escape &, <, > as well as single and double quotes for HTML."""
4242
return text.translate(table)
4343

44+
def webify(color):
45+
if color.startswith('calc') or color.startswith('var'):
46+
return color
47+
else:
48+
return '#' + color
4449

4550
def _get_ttype_class(ttype):
4651
fname = STANDARD_TYPES.get(ttype)
@@ -55,6 +60,11 @@ def _get_ttype_class(ttype):
5560

5661

5762
CSSFILE_TEMPLATE = '''\
63+
/*
64+
generated by Pygments <http://pygments.org>
65+
Copyright 2006-2019 by the Pygments team.
66+
Licensed under the BSD license, see LICENSE for details.
67+
*/
5868
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
5969
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
6070
pre { line-height: 125%%; }
@@ -64,7 +74,11 @@ def _get_ttype_class(ttype):
6474
DOC_HEADER = '''\
6575
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
6676
"http://www.w3.org/TR/html4/strict.dtd">
67-
77+
<!--
78+
generated by Pygments <http://pygments.org>
79+
Copyright 2006-2019 by the Pygments team.
80+
Licensed under the BSD license, see LICENSE for details.
81+
-->
6882
<html>
6983
<head>
7084
<title>%(title)s</title>
@@ -322,11 +336,17 @@ class ``"special"`` (default: ``0``).
322336
.. versionadded:: 1.6
323337
324338
`filename`
325-
A string used to generate a filename when rendering <pre> blocks,
339+
A string used to generate a filename when rendering ``<pre>`` blocks,
326340
for example if displaying source code.
327341
328342
.. versionadded:: 2.1
329343
344+
`wrapcode`
345+
Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended
346+
by the HTML5 specification.
347+
348+
.. versionadded:: 2.4
349+
330350
331351
**Subclassing the HTML formatter**
332352
@@ -395,6 +415,7 @@ def __init__(self, **options):
395415
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
396416
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
397417
self.filename = self._decodeifneeded(options.get('filename', ''))
418+
self.wrapcode = get_bool_opt(options, 'wrapcode', False)
398419

399420
if self.tagsfile:
400421
if not ctags:
@@ -451,17 +472,17 @@ def _create_stylesheet(self):
451472
name = self._get_css_class(ttype)
452473
style = ''
453474
if ndef['color']:
454-
style += 'color: #%s; ' % ndef['color']
475+
style += 'color: %s; ' % webify(ndef['color'])
455476
if ndef['bold']:
456477
style += 'font-weight: bold; '
457478
if ndef['italic']:
458479
style += 'font-style: italic; '
459480
if ndef['underline']:
460481
style += 'text-decoration: underline; '
461482
if ndef['bgcolor']:
462-
style += 'background-color: #%s; ' % ndef['bgcolor']
483+
style += 'background-color: %s; ' % webify(ndef['bgcolor'])
463484
if ndef['border']:
464-
style += 'border: 1px solid #%s; ' % ndef['border']
485+
style += 'border: 1px solid %s; ' % webify(ndef['border'])
465486
if style:
466487
t2c[ttype] = name
467488
# save len(ttype) to enable ordering the styles by
@@ -708,6 +729,12 @@ def _wrap_pre(self, inner):
708729
yield tup
709730
yield 0, '</pre>'
710731

732+
def _wrap_code(self, inner):
733+
yield 0, '<code>'
734+
for tup in inner:
735+
yield tup
736+
yield 0, '</code>'
737+
711738
def _format_lines(self, tokensource):
712739
"""
713740
Just format the tokens, without any wrapping tags.
@@ -814,7 +841,10 @@ def wrap(self, source, outfile):
814841
individual lines, in custom generators. See docstring
815842
for `format`. Can be overridden.
816843
"""
817-
return self._wrap_div(self._wrap_pre(source))
844+
if self.wrapcode:
845+
return self._wrap_div(self._wrap_pre(self._wrap_code(source)))
846+
else:
847+
return self._wrap_div(self._wrap_pre(source))
818848

819849
def format_unencoded(self, tokensource, outfile):
820850
"""

pygments/lexer.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,20 @@ def get_tokens_unprocessed(self, text, stack=('root',)):
639639
if isinstance(new_state, tuple):
640640
for state in new_state:
641641
if state == '#pop':
642-
statestack.pop()
642+
if len(statestack) > 1:
643+
statestack.pop()
643644
elif state == '#push':
644645
statestack.append(statestack[-1])
645646
else:
646647
statestack.append(state)
647648
elif isinstance(new_state, int):
648-
# pop
649-
del statestack[new_state:]
649+
# pop, but keep at least one state on the stack
650+
# (random code leading to unexpected pops should
651+
# not allow exceptions)
652+
if abs(new_state) >= len(statestack):
653+
del statestack[1:]
654+
else:
655+
del statestack[new_state:]
650656
elif new_state == '#push':
651657
statestack.append(statestack[-1])
652658
else:
@@ -724,14 +730,18 @@ def get_tokens_unprocessed(self, text=None, context=None):
724730
if isinstance(new_state, tuple):
725731
for state in new_state:
726732
if state == '#pop':
727-
ctx.stack.pop()
733+
if len(ctx.stack) > 1:
734+
ctx.stack.pop()
728735
elif state == '#push':
729736
ctx.stack.append(ctx.stack[-1])
730737
else:
731738
ctx.stack.append(state)
732739
elif isinstance(new_state, int):
733-
# pop
734-
del ctx.stack[new_state:]
740+
# see RegexLexer for why this check is made
741+
if abs(new_state) >= len(ctx.stack):
742+
del ctx.state[1:]
743+
else:
744+
del ctx.stack[new_state:]
735745
elif new_state == '#push':
736746
ctx.stack.append(ctx.stack[-1])
737747
else:

0 commit comments

Comments
 (0)