summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAna Nelson <ana@ananelson.com>2011-10-02 11:36:48 -0700
committerAna Nelson <ana@ananelson.com>2011-10-02 11:36:48 -0700
commit067693dc8c01a9635bc4dd9a33d3b8737b372347 (patch)
treee9321aef7125c8568717da49fae0835558cff986
parentf83a828ec5ff775cd313213385d4bce06efda8e6 (diff)
downloadpygments-067693dc8c01a9635bc4dd9a33d3b8737b372347.tar.gz
Fix specifyng the starting line number in lineanchors mode. Add tests for line numbering.
-rw-r--r--pygments/formatters/html.py2
-rw-r--r--tests/test_html_formatter.py32
2 files changed, 33 insertions, 1 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 1f0ca680..f6c6400a 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -596,7 +596,7 @@ class HtmlFormatter(Formatter):
def _wrap_lineanchors(self, inner):
s = self.lineanchors
- i = 0
+ i = self.linenostart - 1 # subtract 1 since we have to increment i *before* yielding
for t, line in inner:
if t:
i += 1
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 5a506755..58a50c74 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -75,6 +75,38 @@ class HtmlFormatterTest(unittest.TestCase):
fmt = HtmlFormatter(**optdict)
fmt.format(tokensource, outfile)
+ def test_linenos(self):
+ optdict = dict(linenos=True)
+ outfile = StringIO.StringIO()
+ fmt = HtmlFormatter(**optdict)
+ fmt.format(tokensource, outfile)
+ html = outfile.getvalue()
+ self.assert_(re.search("<pre>\s+1\s+2\s+3", html))
+
+ def test_linenos_with_startnum(self):
+ optdict = dict(linenos=True, linenostart=5)
+ outfile = StringIO.StringIO()
+ fmt = HtmlFormatter(**optdict)
+ fmt.format(tokensource, outfile)
+ html = outfile.getvalue()
+ self.assert_(re.search("<pre>\s+5\s+6\s+7", html))
+
+ def test_lineanchors(self):
+ optdict = dict(lineanchors="foo")
+ outfile = StringIO.StringIO()
+ fmt = HtmlFormatter(**optdict)
+ fmt.format(tokensource, outfile)
+ html = outfile.getvalue()
+ self.assert_(re.search("<pre><a name=\"foo-1\">", html))
+
+ def test_lineanchors_with_startnum(self):
+ optdict = dict(lineanchors="foo", linenostart=5)
+ outfile = StringIO.StringIO()
+ fmt = HtmlFormatter(**optdict)
+ fmt.format(tokensource, outfile)
+ html = outfile.getvalue()
+ self.assert_(re.search("<pre><a name=\"foo-5\">", html))
+
def test_valid_output(self):
# test all available wrappers
fmt = HtmlFormatter(full=True, linenos=True, noclasses=True,