<s> """<STR_LIT>""" <EOL> from pygments . formatter import Formatter <EOL> from pygments . util import get_bool_opt <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class BBCodeFormatter ( Formatter ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> aliases = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> filenames = [ ] <EOL> def __init__ ( self , ** options ) : <EOL> Formatter . __init__ ( self , ** options ) <EOL> self . _code = get_bool_opt ( options , '<STR_LIT>' , False ) <EOL> self . _mono = get_bool_opt ( options , '<STR_LIT>' , False ) <EOL> self . styles = { } <EOL> self . _make_styles ( ) <EOL> def _make_styles ( self ) : <EOL> for ttype , ndef in self . style : <EOL> start = end = '<STR_LIT>' <EOL> if ndef [ '<STR_LIT>' ] : <EOL> start += '<STR_LIT>' % ndef [ '<STR_LIT>' ] <EOL> end = '<STR_LIT>' + end <EOL> if ndef [ '<STR_LIT>' ] : <EOL> start += '<STR_LIT>' <EOL> end = '<STR_LIT>' + end <EOL> if ndef [ '<STR_LIT>' ] : <EOL> start += '<STR_LIT>' <EOL> end = '<STR_LIT>' + end <EOL> if ndef [ '<STR_LIT>' ] : <EOL> start += '<STR_LIT>' <EOL> end = '<STR_LIT>' + end <EOL> self . styles [ ttype ] = start , end <EOL> def format ( self , tokensource , outfile ) : <EOL> if self . _code : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> if self . _mono : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> enc = self . encoding <EOL> lastval = '<STR_LIT>' <EOL> lasttype = None <EOL> for ttype , value in tokensource : <EOL> if enc : <EOL> value = value . encode ( enc ) <EOL> while ttype not in self . styles : <EOL> ttype = ttype . parent <EOL> if ttype == lasttype : <EOL> lastval += value <EOL> else : <EOL> if lastval : <EOL> start , end = self . styles [ lasttype ] <EOL> outfile . write ( '<STR_LIT>' . join ( ( start , lastval , end ) ) ) <EOL> lastval = value <EOL> lasttype = ttype <EOL> if lastval : <EOL> start , end = self . styles [ lasttype ] <EOL> outfile . write ( '<STR_LIT>' . join ( ( start , lastval , end ) ) ) <EOL> if self . _mono : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> if self . _code : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> if self . _code or self . _mono : <EOL> outfile . write ( '<STR_LIT:\n>' ) </s>
