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


Python Publisher.document方法代码示例

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


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

示例1: _docutils_rest_to

# 需要导入模块: from docutils.core import Publisher [as 别名]
# 或者: from docutils.core.Publisher import document [as 别名]
def _docutils_rest_to(rest, writer):
    """ Uses docutils to convert a ReST string to HTML. Returns a tuple
        containg the HTML string and the list of warning nodes that were
        removed from the HTML.
    """
    # Make sure any Sphinx polution of docutils has been removed.
    if Sphinx is not None:
        for key, value in docutils_roles.items():
            if value.__module__.startswith('sphinx'):
                docutils_roles.pop(key)

    pub = Publisher(source_class=docutils.io.StringInput,
                    destination_class=docutils.io.StringOutput)
    pub.set_reader('standalone', None, 'restructuredtext')
    pub.set_writer(writer)
    pub.writer.default_stylesheet_path=''
    pub.get_settings() # Get the default settings
    pub.settings.halt_level = 6 # Don't halt on errors
    pub.settings.warning_stream = StringIO()

    pub.set_source(rest)
    pub.set_destination()
    pub.document = pub.reader.read(pub.source, pub.parser, pub.settings)
    pub.apply_transforms()

    # Walk the node structure of a docutils document and remove 'problematic'
    # and 'system_message' nodes. Save the system_message nodes.
    warning_nodes = []
    for node in pub.document.traverse(docutils.nodes.problematic):
        node.parent.replace(node, node.children[0])
    for node in pub.document.traverse(docutils.nodes.system_message):
        warning_nodes.append(node)
        node.parent.remove(node)

    return pub.writer.write(pub.document, pub.destination), warning_nodes
开发者ID:bergtholdt,项目名称:rested,代码行数:37,代码来源:util.py


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