summaryrefslogtreecommitdiff
path: root/pygments/formatters/html.py
diff options
context:
space:
mode:
authorthatch <devnull@localhost>2009-09-18 18:17:01 -0700
committerthatch <devnull@localhost>2009-09-18 18:17:01 -0700
commite094a385a64026229ca70fe57b0829f3e83ba194 (patch)
tree7786c0c02bca7371595747f968cb86ab9ce492bd /pygments/formatters/html.py
parent0f2d25c0fb7c54347038ff0fe77bed59d1c5f3f3 (diff)
downloadpygments-e094a385a64026229ca70fe57b0829f3e83ba194.tar.gz
#427: Improve inline style handling in !HtmlFormatter
Diffstat (limited to 'pygments/formatters/html.py')
-rw-r--r--pygments/formatters/html.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py
index 674856fa..5eb1c882 100644
--- a/pygments/formatters/html.py
+++ b/pygments/formatters/html.py
@@ -582,15 +582,29 @@ class HtmlFormatter(Formatter):
yield 0, line
def _wrap_div(self, inner):
+ style = []
+ if (self.noclasses and not self.nobackground and
+ self.style.background_color is not None):
+ style.append('background: %s' % (self.style.background_color,))
+ if self.cssstyles:
+ style.append(self.cssstyles)
+ style = '; '.join(style)
+
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass)
- + (self.cssstyles and ' style="%s"' % self.cssstyles) + '>')
+ + (style and (' style="%s"' % style)) + '>')
for tup in inner:
yield tup
yield 0, '</div>\n'
def _wrap_pre(self, inner):
- yield 0, ('<pre'
- + (self.prestyles and ' style="%s"' % self.prestyles) + '>')
+ style = []
+ if self.prestyles:
+ style.append(self.prestyles)
+ if self.noclasses:
+ style.append('line-height: 125%')
+ style = '; '.join(style)
+
+ yield 0, ('<pre' + (style and ' style="%s"' % style) + '>')
for tup in inner:
yield tup
yield 0, '</pre>'
@@ -661,7 +675,14 @@ class HtmlFormatter(Formatter):
if t != 1:
yield t, value
if i + 1 in hls: # i + 1 because Python indexes start at 0
- yield 1, '<span class="hll">%s</span>' % value
+ if self.noclasses:
+ style = ''
+ if self.style.highlight_color is not None:
+ style = (' style="background-color: %s"' %
+ (self.style.highlight_color,))
+ yield 1, '<span%s>%s</span>' % (style, value)
+ else:
+ yield 1, '<span class="hll">%s</span>' % value
else:
yield 1, value