当前位置: 首页>>代码示例>>Python>>正文


Python FormatterBase.macro方法代码示例

本文整理汇总了Python中MoinMoin.formatter.FormatterBase.macro方法的典型用法代码示例。如果您正苦于以下问题:Python FormatterBase.macro方法的具体用法?Python FormatterBase.macro怎么用?Python FormatterBase.macro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoinMoin.formatter.FormatterBase的用法示例。


在下文中一共展示了FormatterBase.macro方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: macro

# 需要导入模块: from MoinMoin.formatter import FormatterBase [as 别名]
# 或者: from MoinMoin.formatter.FormatterBase import macro [as 别名]
    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,代码行数:60,代码来源:text_docbook.py

示例2: macro

# 需要导入模块: from MoinMoin.formatter import FormatterBase [as 别名]
# 或者: from MoinMoin.formatter.FormatterBase import macro [as 别名]
    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,代码行数:58,代码来源:text_docbook.py

示例3: macro

# 需要导入模块: from MoinMoin.formatter import FormatterBase [as 别名]
# 或者: from MoinMoin.formatter.FormatterBase import macro [as 别名]
 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,代码行数:11,代码来源:application_xml.py

示例4: macro

# 需要导入模块: from MoinMoin.formatter import FormatterBase [as 别名]
# 或者: from MoinMoin.formatter.FormatterBase import macro [as 别名]
 def macro(self, macro_obj, name, args, markup=None):
     try:
         # plugins that are defined in the macro class itself
         # can't generate headings this way, but that's fine
         gen_headings = wikiutil.importPlugin(self.request.cfg, 'macro',
                                              name, 'generates_headings')
         return FormatterBase.macro(self, macro_obj, name, args, markup)
     except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
         pass
     return ''
开发者ID:130s,项目名称:roswiki,代码行数:12,代码来源:TOC.py


注:本文中的MoinMoin.formatter.FormatterBase.macro方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。