commit 4a5321f7f51c070de7e5e278e480cfbbee49a12b Author: David Malcolm dmalcolm@redhat.com Date: Thu Jun 30 14:54:14 2011 -0400
CFG renderer: cope with pygments styles that have a "bold" prefix
gccutils.py | 27 +++++++++++++++++++++++---- 1 files changed, 23 insertions(+), 4 deletions(-) --- diff --git a/gccutils.py b/gccutils.py index fa21012..4eba0f0 100644 --- a/gccutils.py +++ b/gccutils.py @@ -212,8 +212,21 @@ try: Formatter.__init__(self) self.style = style
- def color_for_token(self, token): - return self.style.styles[token] + def style_for_token(self, token): + # Return a (hexcolor, isbold) pair, where hexcolor could be None + + # Lookup up pygments' color for this token type: + col = self.style.styles[token] + + isbold = False + + # Extract a pure hex color specifier of the form that graphviz can + # deal with + if col: + if col.startswith('bold '): + isbold = True + col = col[5:] + return (col, isbold)
def format_unencoded(self, tokensource, outfile): from pprint import pprint @@ -230,9 +243,12 @@ try: if t == Token.Literal.String.Escape: continue
- color = self.color_for_token(t) + color, isbold = self.style_for_token(t) if 0: - print ('color: %r' % color) + print ('(color, isbold): (%r, %r)' % (color, isbold)) + + if isbold: + outfile.write('<b>')
# Avoid empty color="" values: if color: @@ -242,6 +258,9 @@ try: else: outfile.write(self.to_html(piece))
+ if isbold: + outfile.write('</b>') + from pygments import highlight from pygments.lexers import CLexer from pygments.formatters import HtmlFormatter
gcc-python-plugin-commits@lists.stg.fedorahosted.org