summaryrefslogtreecommitdiff
path: root/pygments/formatters
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2015-01-21 08:33:36 +0100
committerGeorg Brandl <georg@python.org>2015-01-21 08:33:36 +0100
commitfe72d20b50c75089fa1262b9f03fcb29c9e49282 (patch)
treefb249a513bd3e4bde8fdf01c2448df20b1928a53 /pygments/formatters
parent13705acbd57b936990c63a12de05ce29834b6afb (diff)
parent8cff73f38805fbd29af82fb2aa47956a4a93d22e (diff)
downloadpygments-fe72d20b50c75089fa1262b9f03fcb29c9e49282.tar.gz
merge with stable
Diffstat (limited to 'pygments/formatters')
-rw-r--r--pygments/formatters/html.py12
-rw-r--r--pygments/formatters/latex.py23
2 files changed, 12 insertions, 23 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index babf7ebc..55548d30 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -36,21 +36,11 @@ _escape_html_table = {
ord("'"): u'&#39;',
}
+
def escape_html(text, table=_escape_html_table):
"""Escape &, <, > as well as single and double quotes for HTML."""
return text.translate(table)
-def get_random_id():
- """Return a random id for javascript fields."""
- from random import random
- from time import time
- try:
- from hashlib import sha1 as sha
- except ImportError:
- import sha
- sha = sha.new
- return sha('%s|%s' % (random(), time())).hexdigest()
-
def _get_ttype_class(ttype):
fname = STANDARD_TYPES.get(ttype)
diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py
index e6747e18..15e68e37 100644
--- a/pygments/formatters/latex.py
+++ b/pygments/formatters/latex.py
@@ -360,7 +360,7 @@ class LatexFormatter(Formatter):
start += value[i]
value = value[len(start):]
- start = escape_tex(start, self.commandprefix)
+ start = escape_tex(start, cp)
# ... but do not escape inside comment.
value = start + value
@@ -370,26 +370,26 @@ class LatexFormatter(Formatter):
in_math = False
for i, part in enumerate(parts):
if not in_math:
- parts[i] = escape_tex(part, self.commandprefix)
+ parts[i] = escape_tex(part, cp)
in_math = not in_math
value = '$'.join(parts)
elif self.escapeinside:
text = value
value = ''
- while len(text) > 0:
+ while text:
a, sep1, text = text.partition(self.left)
- if len(sep1) > 0:
+ if sep1:
b, sep2, text = text.partition(self.right)
- if len(sep2) > 0:
- value += escape_tex(a, self.commandprefix) + b
+ if sep2:
+ value += escape_tex(a, cp) + b
else:
- value += escape_tex(a + sep1 + b, self.commandprefix)
+ value += escape_tex(a + sep1 + b, cp)
else:
- value = value + escape_tex(a, self.commandprefix)
+ value += escape_tex(a, cp)
else:
- value = escape_tex(value, self.commandprefix)
+ value = escape_tex(value, cp)
elif ttype not in Token.Escape:
- value = escape_tex(value, self.commandprefix)
+ value = escape_tex(value, cp)
styles = []
while ttype is not Token:
try:
@@ -423,8 +423,7 @@ class LatexFormatter(Formatter):
class LatexEmbeddedLexer(Lexer):
- r"""
-
+ """
This lexer takes one lexer as argument, the lexer for the language
being formatted, and the left and right delimiters for escaped text.