Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
MoinMoin.support.pygments.formatters.bbcode.BBCodeFormatter Class Reference
Inheritance diagram for MoinMoin.support.pygments.formatters.bbcode.BBCodeFormatter:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.formatters.bbcode.BBCodeFormatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def format_unencoded

Public Attributes

 styles

Static Public Attributes

string name = 'BBCode'
list aliases = ['bbcode', 'bb']
list filenames = []

Private Member Functions

def _make_styles

Private Attributes

 _code
 _mono

Detailed Description

Format tokens with BBcodes. These formatting codes are used by many
bulletin boards, so you can highlight your sourcecode with pygments before
posting it there.

This formatter has no support for background colors and borders, as there
are no common BBcode tags for that.

Some board systems (e.g. phpBB) don't support colors in their [code] tag,
so you can't use the highlighting together with that tag.
Text in a [code] tag usually is shown with a monospace font (which this
formatter can do with the ``monofont`` option) and no spaces (which you
need for indentation) are removed.

Additional options accepted:

`style`
    The style to use, can be a string or a Style subclass (default:
    ``'default'``).

`codetag`
    If set to true, put the output into ``[code]`` tags (default:
    ``false``)

`monofont`
    If set to true, add a tag to show the code with a monospace font
    (default: ``false``).

Definition at line 19 of file bbcode.py.


Constructor & Destructor Documentation

Definition at line 52 of file bbcode.py.

00052 
00053     def __init__(self, **options):
00054         Formatter.__init__(self, **options)
00055         self._code = get_bool_opt(options, 'codetag', False)
00056         self._mono = get_bool_opt(options, 'monofont', False)
00057 
00058         self.styles = {}
00059         self._make_styles()


Member Function Documentation

Definition at line 60 of file bbcode.py.

00060 
00061     def _make_styles(self):
00062         for ttype, ndef in self.style:
00063             start = end = ''
00064             if ndef['color']:
00065                 start += '[color=#%s]' % ndef['color']
00066                 end = '[/color]' + end
00067             if ndef['bold']:
00068                 start += '[b]'
00069                 end = '[/b]' + end
00070             if ndef['italic']:
00071                 start += '[i]'
00072                 end = '[/i]' + end
00073             if ndef['underline']:
00074                 start += '[u]'
00075                 end = '[/u]' + end
00076             # there are no common BBcodes for background-color and border
00077 
00078             self.styles[ttype] = start, end

Definition at line 79 of file bbcode.py.

00079 
00080     def format_unencoded(self, tokensource, outfile):
00081         if self._code:
00082             outfile.write('[code]')
00083         if self._mono:
00084             outfile.write('[font=monospace]')
00085 
00086         lastval = ''
00087         lasttype = None
00088 
00089         for ttype, value in tokensource:
00090             while ttype not in self.styles:
00091                 ttype = ttype.parent
00092             if ttype == lasttype:
00093                 lastval += value
00094             else:
00095                 if lastval:
00096                     start, end = self.styles[lasttype]
00097                     outfile.write(''.join((start, lastval, end)))
00098                 lastval = value
00099                 lasttype = ttype
00100 
00101         if lastval:
00102             start, end = self.styles[lasttype]
00103             outfile.write(''.join((start, lastval, end)))
00104 
00105         if self._mono:
00106             outfile.write('[/font]')
00107         if self._code:
00108             outfile.write('[/code]')
00109         if self._code or self._mono:
00110             outfile.write('\n')

Here is the caller graph for this function:


Member Data Documentation

Definition at line 54 of file bbcode.py.

Definition at line 55 of file bbcode.py.

Definition at line 49 of file bbcode.py.

Definition at line 50 of file bbcode.py.

Definition at line 48 of file bbcode.py.

Definition at line 57 of file bbcode.py.


The documentation for this class was generated from the following file: