本文整理汇总了Python中docutils.core.Publisher.apply_transforms方法的典型用法代码示例。如果您正苦于以下问题:Python Publisher.apply_transforms方法的具体用法?Python Publisher.apply_transforms怎么用?Python Publisher.apply_transforms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.core.Publisher
的用法示例。
在下文中一共展示了Publisher.apply_transforms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _docutils_rest_to
# 需要导入模块: from docutils.core import Publisher [as 别名]
# 或者: from docutils.core.Publisher import apply_transforms [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
示例2: pformat
# 需要导入模块: from docutils.core import Publisher [as 别名]
# 或者: from docutils.core.Publisher import apply_transforms [as 别名]
print 'symbol_footnotes', pformat(document.symbol_footnotes)
print 'symbol_footnote_refs', pformat(document.symbol_footnote_refs)
print 'footnotes', pformat(document.footnotes)
print 'citations', pformat(document.citations)
print 'autofootnote_start', pformat(document.autofootnote_start)
print 'symbol_footnote_start', pformat(document.symbol_footnote_start)
print 'id_start', pformat(document.id_start)
print 'transform_messages', pformat(document.transform_messages)
print 'transformer', pformat(document.transformer)
print 'decoration', pformat(document.decoration)
sys.exit()
#dump(document)
### 2. Render doctree to output format,
### apply completion transforms.
pub.source = io.DocTreeInput(document)
pub.destination_class = io.FileOutput
pub.set_destination()
pub.reader = doctree.Reader(parser_name='null')
pub.writer = Writer()
pub.apply_transforms()
output = pub.writer.write(pub.document, pub.destination)
#pub.writer.assemble_parts()
# ----