Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.parser.text_creole.Emitter Class Reference

List of all members.

Public Member Functions

def __init__
def get_text
def document_emit
def text_emit
def separator_emit
def paragraph_emit
def bullet_list_emit
def number_list_emit
def list_item_emit
def table_emit
def table_row_emit
def table_cell_emit
def table_head_emit
def emphasis_emit
def strong_emit
def header_emit
def code_emit
def link_emit
def image_emit
def macro_emit
def break_emit
def preformatted_emit
def default_emit
def emit_children
def emit_node
def emit

Public Attributes

 root
 formatter
 request
 form
 macro

Static Public Attributes

tuple addr_re

Detailed Description

Generate the output for the document
tree consisting of DocNodes.

Definition at line 84 of file text_creole.py.


Constructor & Destructor Documentation

def MoinMoin.parser.text_creole.Emitter.__init__ (   self,
  root,
  formatter,
  request,
  macro 
)

Definition at line 97 of file text_creole.py.

00097 
00098     def __init__(self, root, formatter, request, macro):
00099         self.root = root
00100         self.formatter = formatter
00101         self.request = request
00102         self.form = request.form
00103         self.macro = macro


Member Function Documentation

Definition at line 395 of file text_creole.py.

00395 
00396     def break_emit(self, node):
00397         return self.formatter.linebreak(preformatted=0)
00398 
00399 # Not used
00400 #    def blockquote_emit(self, node):
00401 #        return ''.join([
00402 #            self.formatter.rawHTML('<blockquote>'),
00403 #            self.emit_children(node),
00404 #            self.formatter.rawHTML('</blockquote>'),
00405 #        ])

Definition at line 130 of file text_creole.py.

00130 
00131     def bullet_list_emit(self, node):
00132         return ''.join([
00133             self.formatter.bullet_list(1),
00134             self.emit_children(node),
00135             self.formatter.bullet_list(0),
00136         ])

Here is the call graph for this function:

Definition at line 237 of file text_creole.py.

00237 
00238     def code_emit(self, node):
00239 # XXX The current formatter will replace all spaces with &nbsp;, so we need
00240 # to use rawHTML instead, until that is fixed.
00241 #        return ''.join([
00242 #            self.formatter.code(1),
00243 #            self.formatter.text(node.content or ''),
00244 #            self.formatter.code(0),
00245 #        ])
00246         return ''.join([
00247             self.formatter.rawHTML('<tt>'),
00248             self.formatter.text(node.content or ''),
00249             self.formatter.rawHTML('</tt>'),
00250         ])
00251 
00252 # Not used
00253 #    def abbr_emit(self, node):
00254 #        return ''.join([
00255 #            self.formatter.rawHTML('<abbr title="%s">' % node.title),
00256 #            self.formatter.text(node.content or ''),
00257 #            self.formatter.rawHTML('</abbr>'),
00258 #        ])

Fallback function for emitting unknown nodes.

Definition at line 432 of file text_creole.py.

00432 
00433     def default_emit(self, node):
00434         """Fallback function for emitting unknown nodes."""
00435 
00436         return ''.join([
00437             self.formatter.preformatted(1),
00438             self.formatter.text('<%s>\n' % node.kind),
00439             self.emit_children(node),
00440             self.formatter.preformatted(0),
00441         ])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 114 of file text_creole.py.

00114 
00115     def document_emit(self, node):
00116         return self.emit_children(node)

Here is the call graph for this function:

Emit the document represented by self.root DOM tree.

Definition at line 453 of file text_creole.py.

00453 
00454     def emit(self):
00455         """Emit the document represented by self.root DOM tree."""
00456 
00457         # Try to disable 'smart' formatting if possible
00458         magic_save = getattr(self.formatter, 'no_magic', False)
00459         self.formatter.no_magic = True
00460         output = '\n'.join([
00461             self.emit_node(self.root),
00462         ])
00463         # restore 'smart' formatting if it was set
00464         self.formatter.no_magic = magic_save
00465         return output

Here is the call graph for this function:

Here is the caller graph for this function:

Emit all the children of a node.

Definition at line 442 of file text_creole.py.

00442 
00443     def emit_children(self, node):
00444         """Emit all the children of a node."""
00445 
00446         return ''.join([self.emit_node(child) for child in node.children])

Here is the call graph for this function:

Here is the caller graph for this function:

Emit a single node.

Definition at line 447 of file text_creole.py.

00447 
00448     def emit_node(self, node):
00449         """Emit a single node."""
00450 
00451         emit = getattr(self, '%s_emit' % node.kind, self.default_emit)
00452         return emit(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file text_creole.py.

00203 
00204     def emphasis_emit(self, node):
00205         return ''.join([
00206             self.formatter.emphasis(1),
00207             self.emit_children(node),
00208             self.formatter.emphasis(0),
00209         ])
00210 
00211 # Not used
00212 #    def quote_emit(self, node):
00213 #        return ''.join([
00214 #            self.formatter.rawHTML('<q>'),
00215 #            self.emit_children(node),
00216 #            self.formatter.rawHTML('</q>'),
00217 #        ])

Here is the call graph for this function:

Try to emit whatever text is in the node.

Definition at line 104 of file text_creole.py.

00104 
00105     def get_text(self, node):
00106         """Try to emit whatever text is in the node."""
00107 
00108         try:
00109             return node.children[0].content or ''
00110         except:
00111             return node.content or ''

Here is the caller graph for this function:

Definition at line 229 of file text_creole.py.

00229 
00230     def header_emit(self, node):
00231         text = self.get_text(node)
00232         return ''.join([
00233             self.formatter.heading(1, node.level, id=text),
00234             self.formatter.text(text),
00235             self.formatter.heading(0, node.level),
00236         ])

Here is the call graph for this function:

Definition at line 317 of file text_creole.py.

00317 
00318     def image_emit(self, node):
00319         target = node.content
00320         text = self.get_text(node)
00321         m = self.addr_re.match(target)
00322         if m:
00323             if m.group('page_name'):
00324                 # inserted anchors
00325                 url = wikiutil.url_unquote(target)
00326                 if target.startswith('#'):
00327                     return self.formatter.anchordef(url[1:])
00328                 # default to images
00329                 return self.formatter.attachment_image(
00330                     url, alt=text, html_class='image')
00331             elif m.group('extern_addr'):
00332                 # external link
00333                 address = m.group('extern_addr')
00334                 proto = m.group('extern_proto')
00335                 url = wikiutil.url_unquote(address)
00336                 return self.formatter.image(
00337                     src=url, alt=text, html_class='external_image')
00338             elif m.group('attach_scheme'):
00339                 # link to an attachment
00340                 scheme = m.group('attach_scheme')
00341                 attachment = m.group('attach_addr')
00342                 url = wikiutil.url_unquote(attachment)
00343                 if scheme == 'image':
00344                     return self.formatter.attachment_image(
00345                         url, alt=text, html_class='image')
00346                 elif scheme == 'drawing':
00347                     url = wikiutil.drawing2fname(url)
00348                     return self.formatter.attachment_drawing(url, text, alt=text)
00349                 else:
00350                     pass
00351             elif m.group('inter_wiki'):
00352                 # interwiki link
00353                 pass
00354 #        return "".join(["{{", self.formatter.text(target), "}}"])
00355         url = wikiutil.url_unquote(node.content)
00356         return self.formatter.attachment_inlined(url, text)
00357 
00358 # Not used
00359 #    def drawing_emit(self, node):
00360 #        url = wikiutil.url_unquote(node.content)
00361 #        text = self.get_text(node)
00362 #        return self.formatter.attachment_drawing(url, text)
00363 
00364 # Not used
00365 #    def figure_emit(self, node):
00366 #        text = self.get_text(node)
00367 #        url = wikiutil.url_unquote(node.content)
00368 #        return ''.join([
00369 #            self.formatter.rawHTML('<div class="figure">'),
00370 #            self.get_image(url, text), self.emit_children(node),
00371 #            self.formatter.rawHTML('</div>'),
00372 #        ])
00373 
00374 # Not used
00375 #    def bad_link_emit(self, node):
00376 #        return self.formatter.text(''.join([
00377 #            '[[',
00378 #            node.content or '',
00379 #            ']]',
00380 #        ]))

Here is the call graph for this function:

Definition at line 259 of file text_creole.py.

00259 
00260     def link_emit(self, node):
00261         target = node.content
00262         m = self.addr_re.match(target)
00263         if m:
00264             if m.group('page_name'):
00265                 # link to a page
00266                 word = m.group('page_name')
00267                 if word.startswith(wikiutil.PARENT_PREFIX):
00268                     word = word[wikiutil.PARENT_PREFIX_LEN:]
00269                 elif word.startswith(wikiutil.CHILD_PREFIX):
00270                     word = "%s/%s" % (self.formatter.page.page_name,
00271                         word[wikiutil.CHILD_PREFIX_LEN:])
00272                 word, anchor = wikiutil.split_anchor(word)
00273                 return ''.join([
00274                     self.formatter.pagelink(1, word, anchor=anchor),
00275                     self.emit_children(node) or self.formatter.text(target),
00276                     self.formatter.pagelink(0, word),
00277                 ])
00278             elif m.group('extern_addr'):
00279                 # external link
00280                 address = m.group('extern_addr')
00281                 proto = m.group('extern_proto')
00282                 return ''.join([
00283                     self.formatter.url(1, address, css=proto),
00284                     self.emit_children(node) or self.formatter.text(target),
00285                     self.formatter.url(0),
00286                 ])
00287             elif m.group('inter_wiki'):
00288                 # interwiki link
00289                 wiki = m.group('inter_wiki')
00290                 page = m.group('inter_page')
00291                 page, anchor = wikiutil.split_anchor(page)
00292                 return ''.join([
00293                     self.formatter.interwikilink(1, wiki, page, anchor=anchor),
00294                     self.emit_children(node) or self.formatter.text(page),
00295                     self.formatter.interwikilink(0),
00296                 ])
00297             elif m.group('attach_scheme'):
00298                 # link to an attachment
00299                 scheme = m.group('attach_scheme')
00300                 attachment = m.group('attach_addr')
00301                 url = wikiutil.url_unquote(attachment)
00302                 text = self.get_text(node)
00303                 return ''.join([
00304                         self.formatter.attachment_link(1, url),
00305                         self.formatter.text(text),
00306                         self.formatter.attachment_link(0)
00307                     ])
00308         return "".join(["[[", self.formatter.text(target), "]]"])
00309 
00310 # Not used
00311 #    def anchor_link_emit(self, node):
00312 #        return ''.join([
00313 #            self.formatter.url(1, node.content, css='anchor'),
00314 #            self.emit_children(node),
00315 #            self.formatter.url(0),
00316 #        ])

Here is the call graph for this function:

Definition at line 144 of file text_creole.py.

00144 
00145     def list_item_emit(self, node):
00146         return ''.join([
00147             self.formatter.listitem(1),
00148             self.emit_children(node),
00149             self.formatter.listitem(0),
00150         ])
00151 
00152 # Not used
00153 #    def definition_list_emit(self, node):
00154 #        return ''.join([
00155 #            self.formatter.definition_list(1),
00156 #            self.emit_children(node),
00157 #            self.formatter.definition_list(0),
00158 #        ])
00159 
00160 # Not used
00161 #    def term_emit(self, node):
00162 #        return ''.join([
00163 #            self.formatter.definition_term(1),
00164 #            self.emit_children(node),
00165 #            self.formatter.definition_term(0),
00166 #        ])
00167 
00168 # Not used
00169 #    def definition_emit(self, node):
00170 #        return ''.join([
00171 #            self.formatter.definition_desc(1),
00172 #            self.emit_children(node),
00173 #            self.formatter.definition_desc(0),
00174 #        ])

Here is the call graph for this function:

Definition at line 381 of file text_creole.py.

00381 
00382     def macro_emit(self, node):
00383         macro_name = node.content
00384         args = node.args
00385         return self.formatter.macro(self.macro, macro_name, args)
00386 
00387 # Not used
00388 #    def section_emit(self, node):
00389 #        return ''.join([
00390 #            self.formatter.rawHTML(
00391 #                '<div class="%s" style="%s">' % (node.sect, node.style)),
00392 #            self.emit_children(node),
00393 #            self.formatter.rawHTML('</div>'),
00394 #        ])

Definition at line 137 of file text_creole.py.

00137 
00138     def number_list_emit(self, node):
00139         return ''.join([
00140             self.formatter.number_list(1),
00141             self.emit_children(node),
00142             self.formatter.number_list(0),
00143         ])

Here is the call graph for this function:

Definition at line 123 of file text_creole.py.

00123 
00124     def paragraph_emit(self, node):
00125         return ''.join([
00126             self.formatter.paragraph(1),
00127             self.emit_children(node),
00128             self.formatter.paragraph(0),
00129         ])

Here is the call graph for this function:

Definition at line 406 of file text_creole.py.

00406 
00407     def preformatted_emit(self, node):
00408         parser_name = getattr(node, 'sect', '')
00409         if parser_name:
00410             # The formatter.parser will *sometimes* just return the result
00411             # and *sometimes* try to write it directly. We need to take both
00412             # cases into account!
00413             lines = node.content.split(u'\n')
00414             buf = StringIO.StringIO()
00415             try:
00416                 try:
00417                     self.request.redirect(buf)
00418                     ret = self.formatter.parser(parser_name, lines)
00419                 finally:
00420                     self.request.redirect()
00421                 buf.flush()
00422                 writ = buf.getvalue()
00423                 buf.close()
00424                 return ret + writ
00425             except wikiutil.PluginMissingError:
00426                 pass
00427         return ''.join([
00428             self.formatter.preformatted(1),
00429             self.formatter.text(node.content),
00430             self.formatter.preformatted(0),
00431         ])

Definition at line 120 of file text_creole.py.

00120 
00121     def separator_emit(self, node):
00122         return self.formatter.rule()

Definition at line 218 of file text_creole.py.

00218 
00219     def strong_emit(self, node):
00220         return ''.join([
00221             self.formatter.strong(1),
00222             self.emit_children(node),
00223             self.formatter.strong(0),
00224         ])
00225 
00226 # Not used
00227 #    def smiley_emit(self, node):
00228 #        return self.formatter.smiley(node.content)

Here is the call graph for this function:

Definition at line 189 of file text_creole.py.

00189 
00190     def table_cell_emit(self, node):
00191         return ''.join([
00192             self.formatter.table_cell(1, attrs=getattr(node, 'attrs', '')),
00193             self.emit_children(node),
00194             self.formatter.table_cell(0),
00195         ])

Here is the call graph for this function:

Definition at line 175 of file text_creole.py.

00175 
00176     def table_emit(self, node):
00177         return ''.join([
00178             self.formatter.table(1, attrs=getattr(node, 'attrs', '')),
00179             self.emit_children(node),
00180             self.formatter.table(0),
00181         ])

Here is the call graph for this function:

Definition at line 196 of file text_creole.py.

00196 
00197     def table_head_emit(self, node):
00198         return ''.join([
00199             self.formatter.rawHTML('<th>'),
00200             self.emit_children(node),
00201             self.formatter.rawHTML('</th>'),
00202         ])

Here is the call graph for this function:

Definition at line 182 of file text_creole.py.

00182 
00183     def table_row_emit(self, node):
00184         return ''.join([
00185             self.formatter.table_row(1, attrs=getattr(node, 'attrs', '')),
00186             self.emit_children(node),
00187             self.formatter.table_row(0),
00188         ])

Here is the call graph for this function:

Definition at line 117 of file text_creole.py.

00117 
00118     def text_emit(self, node):
00119         return self.formatter.text(node.content or '')


Member Data Documentation

Initial value:
re.compile('|'.join([
            Rules.extern,
            Rules.attach,
            Rules.interwiki,
            Rules.page
        ]), re.X | re.U)

Definition at line 90 of file text_creole.py.

Definition at line 101 of file text_creole.py.

Definition at line 99 of file text_creole.py.

Definition at line 102 of file text_creole.py.

Definition at line 100 of file text_creole.py.

Definition at line 98 of file text_creole.py.


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