Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.parser.highlight.PygmentsFormatter Class Reference

List of all members.

Public Member Functions

def __init__
def get_class
def format

Public Attributes

 result
 formatter

Static Public Attributes

tuple line_re = re.compile(r'(\n)')

Detailed Description

a formatter for Pygments that uses the moin formatter for creating output 

Definition at line 32 of file highlight.py.


Constructor & Destructor Documentation

Definition at line 36 of file highlight.py.

00036 
00037     def __init__(self, formatter):
00038         pygments.formatter.Formatter.__init__(self)
00039         self.result = []
00040         self.formatter = formatter


Member Function Documentation

def MoinMoin.parser.highlight.PygmentsFormatter.format (   self,
  tokensource,
  outfile 
)

Definition at line 85 of file highlight.py.

00085 
00086     def format(self, tokensource, outfile):
00087         line_ready = False
00088         fmt = self.formatter
00089         result = self.result
00090         for ttype, value in tokensource:
00091             class_ = self.get_class(ttype)
00092             if value:
00093                 for line in self.line_re.split(value):
00094                     if not line_ready:
00095                         result.append(fmt.code_line(1))
00096                         line_ready = True
00097                     if line == '\n':
00098                         result.append(fmt.code_line(0))
00099                         line_ready = False
00100                     else:
00101                         if class_:
00102                             result.append(fmt.code_token(1, class_))
00103                         result.append(fmt.text(line))
00104                         if class_:
00105                             result.append(fmt.code_token(0, class_))
00106         result[-2] = ''
00107         result[-1] = ''
00108 #        if line_ready:
00109 #            result.append(fmt.code_line(0))
00110 

Here is the call graph for this function:

Definition at line 41 of file highlight.py.

00041 
00042     def get_class(self, ttype):
00043         if ttype in Token.Text:
00044             return None
00045         # Reuse existing MoinMoin css class names
00046         elif ttype in Token.Operator.Word:
00047             return 'ResWord'
00048         elif ttype in Token.Comment.Preproc:
00049             return 'Preprc'
00050         elif ttype in Token.Keyword.Constant:
00051             return 'ConsWord'
00052         elif ttype in Token.Keyword:
00053             return 'ResWord'
00054         elif ttype in Token.Name.Builtin:
00055             return 'ResWord'
00056         elif ttype in Token.Name.Constant:
00057             return 'ConsWord'
00058         elif ttype in Token.String.Char:
00059             return 'Char'
00060         elif ttype in Token.String.Escape:
00061             return 'SPChar'
00062         elif ttype in Token.String:
00063             return 'String'
00064         elif ttype in Token.Number:
00065             return 'Number'
00066         elif ttype in Token.Name:
00067             return 'ID'
00068         elif ttype in Token.Comment:
00069             return 'Comment'
00070         elif ttype in Token.Generic.Heading:
00071             return 'Comment'
00072         elif ttype in Token.Generic.Subheading:
00073             return 'DiffSeparator'
00074         elif ttype in Token.Generic.Inserted:
00075             return 'DiffAdded'
00076         elif ttype in Token.Generic.Deleted:
00077             return 'DiffRemoved'
00078         elif ttype in Token.Generic.Strong:
00079             return 'DiffChanged'
00080         else:
00081             # skip tags that have no class defined
00082             return None
00083             # ... or use the token's name when nothing apropriate
00084             # return str(ttype).replace(".", " ")

Here is the caller graph for this function:


Member Data Documentation

Definition at line 39 of file highlight.py.

tuple MoinMoin.parser.highlight.PygmentsFormatter.line_re = re.compile(r'(\n)') [static]

Definition at line 34 of file highlight.py.

Definition at line 38 of file highlight.py.


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