Commits

ananelson committed b965f9c

Fix specifyng the starting line number in lineanchors mode. Add tests for line numbering.

  • Participants
  • Parent commits d1a3f36

Comments (0)

Files changed (2)

pygments/formatters/html.py

 
     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

tests/test_html_formatter.py

             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,