summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
Diffstat (limited to 'pygments')
-rw-r--r--pygments/__init__.py2
-rw-r--r--pygments/formatters/html.py33
-rw-r--r--pygments/lexer.py22
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/asm.py2
-rw-r--r--pygments/lexers/basic.py2
-rw-r--r--pygments/lexers/boa.py14
-rw-r--r--pygments/lexers/rust.py2
8 files changed, 63 insertions, 16 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py
index 4dd38fee..0da0649d 100644
--- a/pygments/__init__.py
+++ b/pygments/__init__.py
@@ -29,7 +29,7 @@ import sys
from pygments.util import StringIO, BytesIO
-__version__ = '2.3.1'
+__version__ = '2.4.0'
__docformat__ = 'restructuredtext'
__all__ = ['lex', 'format', 'highlight']
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index bbddf507..d65c09ce 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -5,7 +5,7 @@
Formatter for HTML output.
- :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
+ :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
@@ -60,6 +60,11 @@ def _get_ttype_class(ttype):
CSSFILE_TEMPLATE = '''\
+/*
+generated by Pygments <http://pygments.org>
+Copyright 2006-2019 by the Pygments team.
+Licensed under the BSD license, see LICENSE for details.
+*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 125%%; }
@@ -69,7 +74,11 @@ pre { line-height: 125%%; }
DOC_HEADER = '''\
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
-
+<!--
+generated by Pygments <http://pygments.org>
+Copyright 2006-2019 by the Pygments team.
+Licensed under the BSD license, see LICENSE for details.
+-->
<html>
<head>
<title>%(title)s</title>
@@ -327,11 +336,17 @@ class HtmlFormatter(Formatter):
.. versionadded:: 1.6
`filename`
- A string used to generate a filename when rendering <pre> blocks,
+ A string used to generate a filename when rendering ``<pre>`` blocks,
for example if displaying source code.
.. versionadded:: 2.1
+ `wrapcode`
+ Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended
+ by the HTML5 specification.
+
+ .. versionadded:: 2.4
+
**Subclassing the HTML formatter**
@@ -400,6 +415,7 @@ class HtmlFormatter(Formatter):
self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
self.filename = self._decodeifneeded(options.get('filename', ''))
+ self.wrapcode = get_bool_opt(options, 'wrapcode', False)
if self.tagsfile:
if not ctags:
@@ -713,6 +729,12 @@ class HtmlFormatter(Formatter):
yield tup
yield 0, '</pre>'
+ def _wrap_code(self, inner):
+ yield 0, '<code>'
+ for tup in inner:
+ yield tup
+ yield 0, '</code>'
+
def _format_lines(self, tokensource):
"""
Just format the tokens, without any wrapping tags.
@@ -819,7 +841,10 @@ class HtmlFormatter(Formatter):
individual lines, in custom generators. See docstring
for `format`. Can be overridden.
"""
- return self._wrap_div(self._wrap_pre(source))
+ if self.wrapcode:
+ return self._wrap_div(self._wrap_pre(self._wrap_code(source)))
+ else:
+ return self._wrap_div(self._wrap_pre(source))
def format_unencoded(self, tokensource, outfile):
"""
diff --git a/pygments/lexer.py b/pygments/lexer.py
index 90905ba5..62d66318 100644
--- a/pygments/lexer.py
+++ b/pygments/lexer.py
@@ -639,14 +639,20 @@ class RegexLexer(Lexer):
if isinstance(new_state, tuple):
for state in new_state:
if state == '#pop':
- statestack.pop()
+ if len(statestack) > 1:
+ statestack.pop()
elif state == '#push':
statestack.append(statestack[-1])
else:
statestack.append(state)
elif isinstance(new_state, int):
- # pop
- del statestack[new_state:]
+ # pop, but keep at least one state on the stack
+ # (random code leading to unexpected pops should
+ # not allow exceptions)
+ if abs(new_state) >= len(statestack):
+ del statestack[1:]
+ else:
+ del statestack[new_state:]
elif new_state == '#push':
statestack.append(statestack[-1])
else:
@@ -724,14 +730,18 @@ class ExtendedRegexLexer(RegexLexer):
if isinstance(new_state, tuple):
for state in new_state:
if state == '#pop':
- ctx.stack.pop()
+ if len(ctx.stack) > 1:
+ ctx.stack.pop()
elif state == '#push':
ctx.stack.append(ctx.stack[-1])
else:
ctx.stack.append(state)
elif isinstance(new_state, int):
- # pop
- del ctx.stack[new_state:]
+ # see RegexLexer for why this check is made
+ if abs(new_state) >= len(ctx.stack):
+ del ctx.state[1:]
+ else:
+ del ctx.stack[new_state:]
elif new_state == '#push':
ctx.stack.append(ctx.stack[-1])
else:
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index e4e8cf43..aea19b4e 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -442,7 +442,7 @@ LEXERS = {
'UcodeLexer': ('pygments.lexers.unicon', 'ucode', ('ucode',), ('*.u', '*.u1', '*.u2'), ()),
'UniconLexer': ('pygments.lexers.unicon', 'Unicon', ('unicon',), ('*.icn',), ('text/unicon',)),
'UrbiscriptLexer': ('pygments.lexers.urbi', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)),
- 'VBScriptLexer': ('pygments.lexers.basic', 'VBScript', (), ('*.vbs', '*.VBS'), ()),
+ 'VBScriptLexer': ('pygments.lexers.basic', 'VBScript', ('vbscript',), ('*.vbs', '*.VBS'), ()),
'VCLLexer': ('pygments.lexers.varnish', 'VCL', ('vcl',), ('*.vcl',), ('text/x-vclsrc',)),
'VCLSnippetLexer': ('pygments.lexers.varnish', 'VCLSnippets', ('vclsnippets', 'vclsnippet'), (), ('text/x-vclsnippet',)),
'VCTreeStatusLexer': ('pygments.lexers.console', 'VCTreeStatus', ('vctreestatus',), (), ()),
diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py
index 7100868c..b522450c 100644
--- a/pygments/lexers/asm.py
+++ b/pygments/lexers/asm.py
@@ -690,7 +690,7 @@ class Dasm16Lexer(RegexLexer):
# Regexes yo
char = r'[a-zA-Z$._0-9@]'
- identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)'
+ identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)'
number = r'[+-]?(?:0[xX][a-zA-Z0-9]+|\d+)'
binary_number = r'0b[01_]+'
instruction = r'(?i)(' + '|'.join(INSTRUCTIONS) + ')'
diff --git a/pygments/lexers/basic.py b/pygments/lexers/basic.py
index 1aa3274c..f93d6d52 100644
--- a/pygments/lexers/basic.py
+++ b/pygments/lexers/basic.py
@@ -510,7 +510,7 @@ class VBScriptLexer(RegexLexer):
.. versionadded:: 2.4
"""
name = 'VBScript'
- aliases = []
+ aliases = ['vbscript']
filenames = ['*.vbs', '*.VBS']
flags = re.IGNORECASE
diff --git a/pygments/lexers/boa.py b/pygments/lexers/boa.py
index 41398cd4..dda31eb4 100644
--- a/pygments/lexers/boa.py
+++ b/pygments/lexers/boa.py
@@ -1,4 +1,14 @@
# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.boa
+ ~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for the Boa language.
+
+ :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
import re
from pygments.lexer import RegexLexer, words
@@ -11,7 +21,9 @@ line_re = re.compile('.*?\n')
class BoaLexer(RegexLexer):
"""
- http://boa.cs.iastate.edu/docs/
+ Lexer for the `Boa <http://boa.cs.iastate.edu/docs/>`_ language.
+
+ .. versionadded:: 2.4
"""
name = 'Boa'
aliases = ['boa']
diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py
index 10097fba..b7b8cb7e 100644
--- a/pygments/lexers/rust.py
+++ b/pygments/lexers/rust.py
@@ -29,7 +29,7 @@ class RustLexer(RegexLexer):
keyword_types = (
words(('u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64',
- 'usize', 'isize', 'f32', 'f64', 'str', 'bool'),
+ 'i128', 'u128', 'usize', 'isize', 'f32', 'f64', 'str', 'bool'),
suffix=r'\b'),
Keyword.Type)