本文整理汇总了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