<s> """<STR_LIT>""" <EOL> from pygments . formatter import Formatter <EOL> from pygments . util import get_bool_opt , get_int_opt <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def escape_html ( text ) : <EOL> """<STR_LIT>""" <EOL> return text . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) . replace ( '<STR_LIT:>>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) . replace ( "<STR_LIT:'>" , '<STR_LIT>' ) <EOL> class2style = { } <EOL> class SvgFormatter ( Formatter ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> aliases = [ '<STR_LIT>' ] <EOL> filenames = [ '<STR_LIT>' ] <EOL> def __init__ ( self , ** options ) : <EOL> Formatter . __init__ ( self , ** options ) <EOL> self . nowrap = get_bool_opt ( options , '<STR_LIT>' , False ) <EOL> self . fontfamily = options . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . fontsize = options . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . xoffset = get_int_opt ( options , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> fs = self . fontsize . strip ( ) <EOL> if fs . endswith ( '<STR_LIT>' ) : fs = fs [ : - <NUM_LIT:2> ] . strip ( ) <EOL> try : <EOL> int_fs = int ( fs ) <EOL> except : <EOL> int_fs = <NUM_LIT:20> <EOL> self . yoffset = get_int_opt ( options , '<STR_LIT>' , int_fs ) <EOL> self . ystep = get_int_opt ( options , '<STR_LIT>' , int_fs + <NUM_LIT:5> ) <EOL> self . spacehack = get_bool_opt ( options , '<STR_LIT>' , True ) <EOL> self . _stylecache = { } <EOL> def format_unencoded ( self , tokensource , outfile ) : <EOL> """<STR_LIT>""" <EOL> x = self . xoffset <EOL> y = self . yoffset <EOL> if not self . nowrap : <EOL> if self . encoding : <EOL> outfile . write ( '<STR_LIT>' % <EOL> self . encoding ) <EOL> else : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' % <EOL> ( self . fontfamily , self . fontsize ) ) <EOL> outfile . write ( '<STR_LIT>' % ( x , y ) ) <EOL> for ttype , value in tokensource : <EOL> style = self . _get_style ( ttype ) <EOL> tspan = style and '<STR_LIT>' + style + '<STR_LIT:>>' or '<STR_LIT>' <EOL> tspanend = tspan and '<STR_LIT>' or '<STR_LIT>' <EOL> value = escape_html ( value ) <EOL> if self . spacehack : <EOL> value = value . expandtabs ( ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> parts = value . split ( '<STR_LIT:\n>' ) <EOL> for part in parts [ : - <NUM_LIT:1> ] : <EOL> outfile . write ( tspan + part + tspanend ) <EOL> y += self . ystep <EOL> outfile . write ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( x , y ) ) <EOL> outfile . write ( tspan + parts [ - <NUM_LIT:1> ] + tspanend ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> if not self . nowrap : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> def _get_style ( self , tokentype ) : <EOL> if tokentype in self . _stylecache : <EOL> return self . _stylecache [ tokentype ] <EOL> otokentype = tokentype <EOL> while not self . style . styles_token ( tokentype ) : <EOL> tokentype = tokentype . parent <EOL> value = self . style . style_for_token ( tokentype ) <EOL> result = '<STR_LIT>' <EOL> if value [ '<STR_LIT>' ] : <EOL> result = '<STR_LIT>' + value [ '<STR_LIT>' ] + '<STR_LIT:">' <EOL> if value [ '<STR_LIT>' ] : <EOL> result += '<STR_LIT>' <EOL> if value [ '<STR_LIT>' ] : <EOL> result += '<STR_LIT>' <EOL> self . _stylecache [ otokentype ] = result <EOL> return result </s>
