本文整理汇总了Python中docutils.core方法的典型用法代码示例。如果您正苦于以下问题:Python docutils.core方法的具体用法?Python docutils.core怎么用?Python docutils.core使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils
的用法示例。
在下文中一共展示了docutils.core方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_doc
# 需要导入模块: import docutils [as 别名]
# 或者: from docutils import core [as 别名]
def convert_doc(rst_string, view_file_url=None):
""" Utility to load an RST file and turn it into fancy HTML. """
rst = modify_rst(rst_string, view_file_url)
overrides = {"report_level": "quiet"}
try:
html = docutils.core.publish_parts(
source=rst, writer_name="html", settings_overrides=overrides
)
except Exception:
return "<pre>%s</pre>" % jinja2.escape(rst)
else:
html_string = html["html_body"]
html_string = modify_html(html_string)
html_string = markupsafe.Markup(html_string)
return html_string
示例2: format_doc
# 需要导入模块: import docutils [as 别名]
# 或者: from docutils import core [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: run
# 需要导入模块: import docutils [as 别名]
# 或者: from docutils import core [as 别名]
def run(self):
import os
import pathlib
from babel.messages.frontend import CommandLineInterface
self.announce("Compiling ui translation files", level=distutils.log.INFO)
ui_dir = pathlib.Path("parsec/core/gui")
tr_dir = ui_dir / "tr"
rc_dir = ui_dir / "rc" / "translations"
os.makedirs(rc_dir, exist_ok=True)
languages = ["fr", "en"]
for lang in languages:
args = [
"_",
"compile",
"-i",
str(tr_dir / f"parsec_{lang}.po"),
"-o",
str(rc_dir / f"parsec_{lang}.mo"),
]
CommandLineInterface().run(args)
示例4: _get_publisher
# 需要导入模块: import docutils [as 别名]
# 或者: from docutils import core [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.