Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
MoinMoin.parser.highlight.Parser Class Reference
Collaboration diagram for MoinMoin.parser.highlight.Parser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def format

Public Attributes

 request
 raw
 filename
 parsername
 syntax

Static Public Attributes

string parsername = "highlight"
 Dependencies = Dependencies
 extensions = extensions

Private Attributes

 _code_id

Detailed Description

Definition at line 111 of file highlight.py.


Constructor & Destructor Documentation

def MoinMoin.parser.highlight.Parser.__init__ (   self,
  raw,
  request,
  filename = None,
  format_args = '',
  kw 
)

Definition at line 116 of file highlight.py.

00116 
00117     def __init__(self, raw, request, filename=None, format_args='', **kw):
00118         self.request = request
00119         self.raw = raw.strip('\n')
00120         self.filename = filename
00121 
00122         if self.parsername == 'highlight':
00123             # user is directly using the highlight parser
00124             parts = format_args.split(None)
00125             if parts:
00126                 self.syntax = parts[0]
00127             else:
00128                 self.syntax = 'text'
00129             if len(parts) > 1:
00130                 params = ' '.join(parts[1:])
00131             else:
00132                 params = ''
00133         else:
00134             # a compatibility wrapper inherited from this class
00135             self.syntax = self.parsername
00136             params = format_args
00137         self.show_nums, self.num_start, self.num_step, attrs = parse_start_step(request, params)


Member Function Documentation

def MoinMoin.parser.highlight.Parser.format (   self,
  formatter 
)

Definition at line 138 of file highlight.py.

00138 
00139     def format(self, formatter):
00140         _ = self.request.getText
00141         fmt = PygmentsFormatter(formatter)
00142         fmt.result.append(formatter.div(1, css_class="highlight %s" % self.syntax))
00143         self._code_id = hash_new('sha1', self.raw.encode(config.charset)).hexdigest()
00144         msg = None
00145         if self.filename is not None:
00146             try:
00147                 lexer = pygments.lexers.get_lexer_for_filename(self.filename)
00148             except pygments.util.ClassNotFound:
00149                 fmt.result.append(formatter.text(self.filename))
00150                 lexer = pygments.lexers.TextLexer()
00151         else:
00152             try:
00153                 lexer = pygments.lexers.get_lexer_by_name(self.syntax)
00154             except pygments.util.ClassNotFound:
00155                 f = self.request.formatter
00156                 url = ''.join([
00157                                f.url(1, href=Page(self.request, _("HelpOnParsers")).url(self.request, escape=0)),
00158                                _("HelpOnParsers"),
00159                                f.url(0)])
00160                 msg = _("Syntax highlighting not supported for '%(syntax)s', see %(highlight_help_page)s.") % {"syntax": wikiutil.escape(self.syntax),
00161                                                                                                                "highlight_help_page": url
00162                                                                                                               }
00163                 lexer = pygments.lexers.TextLexer()
00164         fmt.result.append(formatter.code_area(1, self._code_id, self.parsername, self.show_nums, self.num_start, self.num_step, msg))
00165         pygments.highlight(self.raw, lexer, fmt)
00166         fmt.result.append(formatter.code_area(0, self._code_id))
00167         fmt.result.append(formatter.div(0))
00168         self.request.write("".join(fmt.result))
00169 

Member Data Documentation

Definition at line 142 of file highlight.py.

Definition at line 113 of file highlight.py.

Definition at line 114 of file highlight.py.

Definition at line 119 of file highlight.py.

string MoinMoin.parser.highlight.Parser.parsername = "highlight" [static]

Definition at line 112 of file highlight.py.

Definition at line 121 of file highlight.py.

Definition at line 118 of file highlight.py.

Definition at line 117 of file highlight.py.

Definition at line 125 of file highlight.py.


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