本文整理汇总了Python中MoinMoin.formatter.FormatterBase类的典型用法代码示例。如果您正苦于以下问题:Python FormatterBase类的具体用法?Python FormatterBase怎么用?Python FormatterBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormatterBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, request, **kw):
FormatterBase.__init__(self, request, **kw)
self.document = minidom.Document()
self.document.documentElement = self.document.createElement('xml')
self.position = self.document.documentElement
self.tag_stack = [('xml', {})]
开发者ID:steveyen,项目名称:moingo,代码行数:7,代码来源:dom_xml.py
示例2: paragraph
def paragraph(self, on, **kw):
# Maintain the accessible flag `in_p`
FormatterBase.paragraph(self, on)
if on:
return self._output()
else:
return self._output_EOL_BLK()
开发者ID:dwf,项目名称:moin2rst,代码行数:7,代码来源:text_x-rst.py
示例3: pagelink
def pagelink(self, on, pagename="", page=None, **kw):
FormatterBase.pagelink(self, on, pagename, page, **kw)
if page is None:
page = Page(self.request, pagename, formatter=self)
link_text = page.link_to(self.request, on=on, **kw)
self._curr.xml_append(tree.text(U(link_text)))
return ""
开发者ID:pombredanne,项目名称:akara,代码行数:7,代码来源:application_xml.py
示例4: paragraph
def paragraph(self, on, **kw):
FormatterBase.paragraph(self, on)
if on:
self.paragraph_begin()
else:
self.paragraph_end()
return ''
开发者ID:IvanLogvinov,项目名称:soar,代码行数:7,代码来源:text_plain.py
示例5: __init__
def __init__(self, request, **kw):
FormatterBase.__init__(self, request, **kw)
self.members = []
self._bullet_list_level = 0
self._inside_link = False
self._new_member = ''
开发者ID:IvanLogvinov,项目名称:soar,代码行数:7,代码来源:groups.py
示例6: preformatted
def preformatted(self, on, **kw):
FormatterBase.preformatted(self, on)
snip = u'---%<'
snip = snip + (u'-' * (78 - len(snip)))
if on:
return u'\n' + snip + u'\n'
else:
return snip + u'\n'
开发者ID:steveyen,项目名称:moingo,代码行数:8,代码来源:text_plain.py
示例7: macro
def macro(self, macro_obj, name, args, markup=None):
"""As far as the DocBook formatter is concerned there are three
kinds of macros: Bad, Handled and Unknown.
The Bad ones are the ones that are known not to work, and are on its
blacklist. They will be ignored and an XML comment will be written
noting that the macro is not supported.
Handled macros are such macros that code is written to handle them.
For example for the FootNote macro it means that instead of executing
the macro, a DocBook footnote entity is created, with the relevant
pieces of information filles in.
The Unknown are handled by executing the macro and capturing any
textual output. There shouldn't be any textual output since macros
should call formatter methods. This is unfortunately not always true,
so the output it is then fed in to an xml parser and the
resulting nodes copied to the DocBook-dom tree. If the output is not
valid xml then a comment is written in the DocBook that the macro
should be fixed.
"""
# Another alternative would be to feed the output to rawHTML or even
# combining these two approaches. The _best_ alternative would be to
# fix the macros.
excludes = (u"articleinfo", u"title")
if name in self.blacklisted_macros:
self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)
elif name == u"FootNote":
footnote = tree.element(None, u"footnote")
self._addTextElem(footnote, u"para", str(args))
self.cur.xml_append(footnote)
elif name == u"Include":
was_in_para = self.cur.xml_qname == u"para"
if was_in_para:
self.paragraph(0)
text = FormatterBase.macro(self, macro_obj, name, args)
if text.strip():
self._includeExternalDocument(text, exclude=excludes)
if was_in_para:
self.paragraph(1)
else:
text = FormatterBase.macro(self, macro_obj, name, args)
if text:
try:
self._includeExternalDocument(text, exclude=excludes)
# FIXME: check for parse-related errors, realy
except ExpatError:
self._emitComment(
u"The macro %s caused an error and should be blacklisted (and you might want to file a bug with the developer). It returned the following data which caused the docbook-formatter to choke. '%s'"
% (name, text)
)
return u""
开发者ID:pombredanne,项目名称:akara,代码行数:58,代码来源:text_docbook.py
示例8: __init__
def __init__(self, request, **kw):
FormatterBase.__init__(self, request, **kw)
self._current_depth = 1
self._base_depth = 0
self.in_pre = 0
self._doc = tree.entity()
self._curr = self._doc
# self._writer = structwriter(indent=u"yes", encoding=config.charset)
return
开发者ID:pombredanne,项目名称:akara,代码行数:9,代码来源:application_xml.py
示例9: __init__
def __init__(self, request, **kw):
FormatterBase.__init__(self, request, **kw)
self._in_code_area = 0
self._in_code_line = 0
self._code_area_state = [0, -1, -1, 0]
self._in_list = 0
self._did_para = 0
self._url = None
self._text = None # XXX does not work with links in headings!!!!!
开发者ID:steveyen,项目名称:moingo,代码行数:9,代码来源:text_plain.py
示例10: macro
def macro(self, macro_obj, name, args, markup=None):
"""As far as the DocBook formatter is conserned there are three
kinds of macros: Bad, Handled and Unknown.
The Bad ones are the ones that are known not to work, and are on its
blacklist. They will be ignored and an XML comment will be written
noting that the macro is not supported.
Handled macros are such macros that code is written to handle them.
For example for the FootNote macro it means that instead of executing
the macro, a DocBook footnote entity is created, with the relevant
pieces of information filles in.
The Unknown are handled by executing the macro and capturing any
textual output. There shouldn't be any textual output since macros
should call formatter methods. This is unfortunately not always true,
so the output it is then fed in to an xml parser and the
resulting nodes copied to the DocBook-dom tree. If the output is not
valid xml then a comment is written in the DocBook that the macro
should be fixed.
"""
# Another alternative would be to feed the output to rawHTML or even
# combining these two approaches. The _best_ alternative would be to
# fix the macros.
excludes=("articleinfo", "title")
if name in self.blacklisted_macros:
self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)
elif name == "FootNote":
footnote = self.doc.createElement('footnote')
self._addTextElem(footnote, "para", str(args))
self.cur.appendChild(footnote)
elif name == "Include":
was_in_para = self.cur.nodeName == "para"
if was_in_para:
self.paragraph(0)
text = FormatterBase.macro(self, macro_obj, name, args)
if text.strip():
self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
if was_in_para:
self.paragraph(1)
else:
text = FormatterBase.macro(self, macro_obj, name, args)
if text:
from xml.parsers.expat import ExpatError
try:
xml_dom = Sax.FromXml(text).documentElement.childNodes
self._copyExternalNodes(xml_dom, exclude=excludes)
except ExpatError:
self._emitComment("The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug." % (name, text))
return u""
开发者ID:steveyen,项目名称:moingo,代码行数:56,代码来源:text_docbook.py
示例11: _close_tag
def _close_tag(self, tag):
""" low level function: closes tag right now
must be the last opened tag!!!
"""
if tag == 'p':
FormatterBase.paragraph(self, 0)
if self.tag_stack[-1][0] != tag:
raise ValueError, "closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag)
self.position = self.position.parentNode
return self.tag_stack.pop()
开发者ID:steveyen,项目名称:moingo,代码行数:10,代码来源:dom_xml.py
示例12: preformatted
def preformatted(self, on, **kw):
# Maintain the accessible flag `in_pre`
FormatterBase.preformatted(self, on)
if on:
# TODO Minmized styles should be supported
result = self._output_EOL_BLK(u"::")
self._indentation += 3
return result
else:
self._indentation -= 3
return self._output_EOL_BLK()
开发者ID:ismaelbej,项目名称:moin2rst,代码行数:11,代码来源:text_x-rst.py
示例13: pagelink
def pagelink(self, on, pagename='', page=None, **kw):
""" Link to a page.
formatter.text_python will use an optimized call with a page!=None
parameter. DO NOT USE THIS YOURSELF OR IT WILL BREAK.
See wikiutil.link_tag() for possible keyword parameters.
"""
FormatterBase.pagelink(self, on, pagename, page, **kw)
if page is None:
page = Page(self.request, pagename, formatter=self)
return page.link_to(self.request, on=on, **kw)
开发者ID:IvanLogvinov,项目名称:soar,代码行数:12,代码来源:text_gedit.py
示例14: preformatted
def preformatted(self, on, **kw):
FormatterBase.preformatted(self, on)
snip = u'%s\n' % u'---%<'.ljust(78 - self._indent, u'-')
if on:
self.paragraph_begin()
return self.wrap(snip)
else:
if self._textbuf and not self._textbuf.endswith('\n'):
self._textbuf += '\n'
result = self.wrap(snip)
self.paragraph_end()
return result
开发者ID:IvanLogvinov,项目名称:soar,代码行数:12,代码来源:text_plain.py
示例15: paragraph
def paragraph(self, on, **kw):
FormatterBase.paragraph(self, on)
# Let's prevent empty paras
if not on:
if not self._hasContent(self.cur):
oldnode = self.cur
self.cur = oldnode.xml_parent
self.cur.xml_remove(oldnode)
return ""
# Let's prevent para inside para
if on and self.cur.xml_qname == u"para":
return ""
return self._handleNode(u"para", on)
开发者ID:pombredanne,项目名称:akara,代码行数:15,代码来源:text_docbook.py
示例16: paragraph
def paragraph(self, on, **kw):
FormatterBase.paragraph(self, on)
# Let's prevent empty paras
if not on:
if not self._hasContent(self.cur):
oldnode = self.cur
self.cur = oldnode.parentNode
self.cur.removeChild(oldnode)
return ""
# Let's prevent para inside para
if on and self.cur.nodeName == "para":
return ""
return self._handleNode("para", on)
开发者ID:Kartstig,项目名称:engineering-inventions-wiki,代码行数:15,代码来源:text_docbook.py
示例17: image
def image(self, src=None, **kw):
valid_attrs = ['src', 'width', 'height', 'alt', 'title']
attrs = {'src': src}
for key, value in kw.items():
if key in valid_attrs:
attrs[key] = value
return FormatterBase.image(self, **attrs) + '</img>'
开发者ID:IvanLogvinov,项目名称:soar,代码行数:7,代码来源:text_xml.py
示例18: _open_tag
def _open_tag(self, tag, **attrs):
""" low level function: opens tag right now
@param tag: tag name, string
@param attrs: attributes keywords, ascii or unicode
"""
if tag == 'p':
FormatterBase.paragraph(self, 1)
self.tag_stack.append((tag, attrs))
node = self.document.createElement(tag)
for name, value in attrs.items():
if value:
node.setAttribute(name, unicode(value))
self.position.appendChild(node)
self.position = node
return ''
开发者ID:steveyen,项目名称:moingo,代码行数:16,代码来源:dom_xml.py
示例19: __init__
def __init__(self, request, **kw):
FormatterBase.__init__(self, request, **kw)
self._in_code_area = 0
self._in_code_line = 0
self._code_area_state = [0, -1, -1, 0]
self._lists = []
self._url = None
self._text = None # XXX does not work with links in headings!!!!!
self._text_stack = []
self._skip_text = False
self._wrap_skip_text = False
self._textbuf = ''
self._indent = 0
self._listitem_on = []
self._empty_line_count = 2
self._paragraph_ended = False
self._paragraph_skip_begin = True
开发者ID:IvanLogvinov,项目名称:soar,代码行数:17,代码来源:text_plain.py
示例20: macro
def macro(self, macro_obj, name, args, markup=None):
# Macro response are (unescaped) markup. Do what little clean-up we camn, and cross fingers
output = FormatterBase.macro(self, macro_obj, name, args, markup=markup)
# response is Unicode
if output:
output_body = markup_fragment(inputsource.text(output.encode(config.charset)))
# print "macro 2", repr(output)
self._curr.xml_append(output_body)
return ""
开发者ID:pombredanne,项目名称:akara,代码行数:9,代码来源:application_xml.py
注:本文中的MoinMoin.formatter.FormatterBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论