home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from pygments.formatter import Formatter
- from pygments.util import get_bool_opt
- __all__ = [
- 'BBCodeFormatter']
-
- class BBCodeFormatter(Formatter):
- name = 'BBCode'
- aliases = [
- 'bbcode',
- 'bb']
- filenames = []
-
- def __init__(self, **options):
- Formatter.__init__(self, **options)
- self._code = get_bool_opt(options, 'codetag', False)
- self._mono = get_bool_opt(options, 'monofont', False)
- self.styles = { }
- self._make_styles()
-
-
- def _make_styles(self):
- for ttype, ndef in self.style:
- start = end = ''
- if ndef['color']:
- start += '[color=#%s]' % ndef['color']
- end = '[/color]' + end
-
- if ndef['bold']:
- start += '[b]'
- end = '[/b]' + end
-
- if ndef['italic']:
- start += '[i]'
- end = '[/i]' + end
-
- if ndef['underline']:
- start += '[u]'
- end = '[/u]' + end
-
- self.styles[ttype] = (start, end)
-
-
-
- def format_unencoded(self, tokensource, outfile):
- if self._code:
- outfile.write('[code]')
-
- if self._mono:
- outfile.write('[font=monospace]')
-
- lastval = ''
- lasttype = None
- for ttype, value in tokensource:
- while ttype not in self.styles:
- ttype = ttype.parent
- if ttype == lasttype:
- lastval += value
- continue
- if lastval:
- (start, end) = self.styles[lasttype]
- outfile.write(''.join((start, lastval, end)))
-
- lastval = value
- lasttype = ttype
-
- if lastval:
- (start, end) = self.styles[lasttype]
- outfile.write(''.join((start, lastval, end)))
-
- if self._mono:
- outfile.write('[/font]')
-
- if self._code:
- outfile.write('[/code]')
-
- if self._code or self._mono:
- outfile.write('\n')
-
-
-
-