summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/formatters/html.py6
-rw-r--r--tests/test_html_formatter.py20
-rw-r--r--tests/test_latex_formatter.py3
3 files changed, 19 insertions, 10 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 3b75e4e6..f3257f03 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -79,7 +79,7 @@ DOC_HEADER_EXTERNALCSS = '''\
<head>
<title>%(title)s</title>
<meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
- <link rel="stylesheet" href="%(cssfile)s">
+ <link rel="stylesheet" href="%(cssfile)s" type="text/css">
</head>
<body>
<h2>%(title)s</h2>
@@ -465,8 +465,10 @@ class HtmlFormatter(Formatter):
line += part + (lspan and '</span>') + lsep
yield 1, line
line = ''
- else:
+ elif part:
yield 1, cspan + part + (cspan and '</span>') + lsep
+ else:
+ yield 1, lsep
# for the last line
if line and parts[-1]:
if lspan != cspan:
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 5297d1f0..b3b133e9 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -8,20 +8,31 @@
"""
import os
+import re
import unittest
import StringIO
-import random
import tempfile
from os.path import join, dirname, isfile
-from pygments import lexers, formatters
-from pygments.token import _TokenType
-from pygments.formatters import HtmlFormatter
from pygments.lexers import PythonLexer
+from pygments.formatters import HtmlFormatter, NullFormatter
+from pygments.formatters.html import escape_html
tokensource = list(PythonLexer().get_tokens(file(os.path.join(testdir, testfile)).read()))
class HtmlFormatterTest(unittest.TestCase):
+ def test_correct_output(self):
+ hfmt = HtmlFormatter(nowrap=True)
+ houtfile = StringIO.StringIO()
+ hfmt.format(tokensource, houtfile)
+
+ nfmt = NullFormatter()
+ noutfile = StringIO.StringIO()
+ nfmt.format(tokensource, noutfile)
+
+ stripped_html = re.sub('<.*?>', '', houtfile.getvalue())
+ escaped_text = escape_html(noutfile.getvalue())
+ self.assertEquals(stripped_html, escaped_text)
def test_external_css(self):
# test correct behavior
@@ -46,7 +57,6 @@ class HtmlFormatterTest(unittest.TestCase):
except OSError:
pass
-
def test_all_options(self):
for optdict in [dict(nowrap=True),
dict(linenos=True),
diff --git a/tests/test_latex_formatter.py b/tests/test_latex_formatter.py
index 376abb81..ae543265 100644
--- a/tests/test_latex_formatter.py
+++ b/tests/test_latex_formatter.py
@@ -9,11 +9,8 @@
import os
import unittest
-import StringIO
import tempfile
-from pygments import lexers, formatters
-from pygments.token import _TokenType
from pygments.formatters import LatexFormatter
from pygments.lexers import PythonLexer