3 pygments.formatters.html |
3 pygments.formatters.html |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Formatter for HTML output. |
6 Formatter for HTML output. |
7 |
7 |
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 import sys, os |
11 |
|
12 import os |
|
13 import sys |
12 import io |
14 import io |
13 |
|
14 try: |
|
15 set |
|
16 except NameError: |
|
17 from sets import Set as set |
|
18 |
15 |
19 from pygments.formatter import Formatter |
16 from pygments.formatter import Formatter |
20 from pygments.token import Token, Text, STANDARD_TYPES |
17 from pygments.token import Token, Text, STANDARD_TYPES |
21 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes |
18 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes |
22 |
19 |
580 yield 1, '<a name="%s-%d"></a>' % (s, i) + line |
577 yield 1, '<a name="%s-%d"></a>' % (s, i) + line |
581 else: |
578 else: |
582 yield 0, line |
579 yield 0, line |
583 |
580 |
584 def _wrap_div(self, inner): |
581 def _wrap_div(self, inner): |
|
582 style = [] |
|
583 if (self.noclasses and not self.nobackground and |
|
584 self.style.background_color is not None): |
|
585 style.append('background: %s' % (self.style.background_color,)) |
|
586 if self.cssstyles: |
|
587 style.append(self.cssstyles) |
|
588 style = '; '.join(style) |
|
589 |
585 yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) |
590 yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) |
586 + (self.cssstyles and ' style="%s"' % self.cssstyles) + '>') |
591 + (style and (' style="%s"' % style)) + '>') |
587 for tup in inner: |
592 for tup in inner: |
588 yield tup |
593 yield tup |
589 yield 0, '</div>\n' |
594 yield 0, '</div>\n' |
590 |
595 |
591 def _wrap_pre(self, inner): |
596 def _wrap_pre(self, inner): |
592 yield 0, ('<pre' |
597 style = [] |
593 + (self.prestyles and ' style="%s"' % self.prestyles) + '>') |
598 if self.prestyles: |
|
599 style.append(self.prestyles) |
|
600 if self.noclasses: |
|
601 style.append('line-height: 125%') |
|
602 style = '; '.join(style) |
|
603 |
|
604 yield 0, ('<pre' + (style and ' style="%s"' % style) + '>') |
594 for tup in inner: |
605 for tup in inner: |
595 yield tup |
606 yield tup |
596 yield 0, '</pre>' |
607 yield 0, '</pre>' |
597 |
608 |
598 def _format_lines(self, tokensource): |
609 def _format_lines(self, tokensource): |
659 |
670 |
660 for i, (t, value) in enumerate(tokensource): |
671 for i, (t, value) in enumerate(tokensource): |
661 if t != 1: |
672 if t != 1: |
662 yield t, value |
673 yield t, value |
663 if i + 1 in hls: # i + 1 because Python indexes start at 0 |
674 if i + 1 in hls: # i + 1 because Python indexes start at 0 |
664 yield 1, '<span class="hll">%s</span>' % value |
675 if self.noclasses: |
|
676 style = '' |
|
677 if self.style.highlight_color is not None: |
|
678 style = (' style="background-color: %s"' % |
|
679 (self.style.highlight_color,)) |
|
680 yield 1, '<span%s>%s</span>' % (style, value) |
|
681 else: |
|
682 yield 1, '<span class="hll">%s</span>' % value |
665 else: |
683 else: |
666 yield 1, value |
684 yield 1, value |
667 |
685 |
668 def wrap(self, source, outfile): |
686 def wrap(self, source, outfile): |
669 """ |
687 """ |