summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/formatters/html.py12
-rw-r--r--tests/test_html_formatter.py27
2 files changed, 23 insertions, 16 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 2c6de4ca..f15edc7e 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -36,21 +36,11 @@ _escape_html_table = {
ord("'"): u''',
}
+
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/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 5b1b2576..92a0415b 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -68,15 +68,32 @@ class HtmlFormatterTest(unittest.TestCase):
pass
def test_all_options(self):
- for optdict in [dict(nowrap=True),
- dict(linenos=True),
- dict(linenos=True, full=True),
- dict(linenos=True, full=True, noclasses=True)]:
-
+ def check(optdict):
outfile = StringIO()
fmt = HtmlFormatter(**optdict)
fmt.format(tokensource, outfile)
+ for optdict in [
+ dict(nowrap=True),
+ dict(linenos=True, full=True),
+ dict(linenos=True, linespans='L'),
+ dict(hl_lines=[1, 5, 10, 'xxx']),
+ dict(hl_lines=[1, 5, 10], noclasses=True),
+ ]:
+ check(optdict)
+
+ for linenos in [False, 'table', 'inline']:
+ for noclasses in [False, True]:
+ for linenospecial in [0, 5]:
+ for anchorlinenos in [False, True]:
+ optdict = dict(
+ linenos=linenos,
+ noclasses=noclasses,
+ linenospecial=linenospecial,
+ anchorlinenos=anchorlinenos,
+ )
+ check(optdict)
+
def test_linenos(self):
optdict = dict(linenos=True)
outfile = StringIO()