本文整理匯總了Python中docutils.io方法的典型用法代碼示例。如果您正苦於以下問題:Python docutils.io方法的具體用法?Python docutils.io怎麽用?Python docutils.io使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類docutils
的用法示例。
在下文中一共展示了docutils.io方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write
# 需要導入模塊: import docutils [as 別名]
# 或者: from docutils import io [as 別名]
def write(self, document, destination):
"""
Process a document into its final form.
Translate `document` (a Docutils document tree) into the Writer's
native format, and write it out to its `destination` (a
`docutils.io.Output` subclass object).
Normally not overridden or extended in subclasses.
"""
self.document = document
self.language = languages.get_language(
document.settings.language_code,
document.reporter)
self.destination = destination
self.translate()
output = self.destination.write(self.output)
return output
示例2: format_doc
# 需要導入模塊: import docutils [as 別名]
# 或者: from docutils import io [as 別名]
def format_doc(docstring):
'''Return parsed documentation string, stripping RST markup.
'''
if not docstring:
return ''
# pylint: disable=unused-variable
output, pub = docutils.core.publish_programmatically(
source_class=docutils.io.StringInput,
source=' '.join(docstring.strip().split()),
source_path=None,
destination_class=docutils.io.NullOutput, destination=None,
destination_path=None,
reader=None, reader_name='standalone',
parser=None, parser_name='restructuredtext',
writer=None, writer_name='null',
settings=None, settings_spec=None, settings_overrides=None,
config_section=None, enable_exit_status=None)
return pub.writer.document.astext()
示例3: _generate_html
# 需要導入模塊: import docutils [as 別名]
# 或者: from docutils import io [as 別名]
def _generate_html(data):
extra_params = {'initial_header_level': '2',
'syntax_highlight': 'short',
'input_encoding': 'utf-8',
'exit_status_level': 2,
'compact_p': False,
'embed_stylesheet': False}
pub = docutils.core.Publisher(
source_class=docutils.io.StringInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=data, source_path=None)
pub.publish(enable_exit_status=True)
return pub.writer.parts['body']
示例4: _get_publisher
# 需要導入模塊: import docutils [as 別名]
# 或者: from docutils import io [as 別名]
def _get_publisher(self, source, source_file_path):
# This is a slightly modified copy of `RstReader._get_publisher`
extra_params = {'initial_header_level': '4',
'syntax_highlight': 'short',
'input_encoding': 'utf-8',
'exit_status_level': 2,
'embed_stylesheet': False}
user_params = self.settings.get('DOCUTILS_SETTINGS')
if user_params:
extra_params.update(user_params)
pub = docutils.core.Publisher(
source_class=docutils.io.StringInput,
destination_class=docutils.io.StringOutput)
pub.set_components('standalone', 'restructuredtext', 'html')
pub.writer.translator_class = PelicanHTMLTranslator
pub.process_programmatic_settings(None, extra_params, None)
pub.set_source(source=source, source_path=source_file_path)
pub.publish(enable_exit_status=True)
return pub
# You need to have a read method, which takes a filename and returns
# some content and the associated metadata.