本文整理汇总了Python中m2r.convert方法的典型用法代码示例。如果您正苦于以下问题:Python m2r.convert方法的具体用法?Python m2r.convert怎么用?Python m2r.convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类m2r
的用法示例。
在下文中一共展示了m2r.convert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_description
# 需要导入模块: import m2r [as 别名]
# 或者: from m2r import convert [as 别名]
def _process_description(self, description):
description = "".join(
[
reSpecial.sub("", d) if i % 2 else d
for i, d in enumerate(reLink.split(description))
]
) # remove formatting from links
description = m2r.convert(description)
description = description.replace(m2r.prolog, "")
description = description.replace(":raw-html-m2r:", ":raw-html:")
description = description.replace(r"\ ,", ",")
description = description.replace(r"\ ", " ")
# turn explicit references into anonymous references
description = description.replace(">`_", ">`__")
description += "\n"
return description.strip()
示例2: as_rst
# 需要导入模块: import m2r [as 别名]
# 或者: from m2r import convert [as 别名]
def as_rst(self) -> str:
if self.markup == 'rst':
return self.path.read_text()
if self.markup == 'md':
content = convert(self.path.read_text())
content = content.replace('.. code-block:: toml', '.. code-block::')
return content
if self.markup == 'txt':
return self.path.read_text()
raise ValueError('invalid markup')
示例3: get_text_converter
# 需要导入模块: import m2r [as 别名]
# 或者: from m2r import convert [as 别名]
def get_text_converter(options):
"""Decide on a text converter for prose."""
if 'format' in options:
if options['format'] == 'markdown':
if convert_markdown is None:
raise ValueError(
"Markdown conversion isn't available, "
"install the [markdown] extra."
)
return convert_markdown
# No conversion needed.
return lambda s: s
示例4: pandoc
# 需要导入模块: import m2r [as 别名]
# 或者: from m2r import convert [as 别名]
def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):
"""Convert an input string using pandoc.
Pandoc converts an input string `from` a format `to` a target format.
Parameters
----------
source : string
Input string, assumed to be valid format `from`.
fmt : string
The name of the input format (markdown, etc.)
to : string
The name of the output format (html, etc.)
Returns
-------
out : unicode
Output as returned by pandoc.
Raises
------
PandocMissing
If pandoc is not installed.
Any error messages generated by pandoc are printed to stderr.
"""
cmd = ['pandoc', '-f', fmt, '-t', to]
if extra_args:
cmd.extend(extra_args)
# iOS: we cannot call pandoc, so we just don't convert markdown cells.
# This is not perfect (...) but it lets the conversion machine work.
# iOS: we replaced pandoc with a mistune plugin. It's not as good but it works
# iOS, TODO: tables in LaTeX, html in LaTeX
if (sys.platform == 'darwin' and platform.machine().startswith('iP')):
if (fmt.startswith('markdown') and to.startswith('latex')):
markdown_to_latex = mistune.Markdown(renderer=LatexRenderer())
return markdown_to_latex(source)
elif (fmt.startswith('markdown') and to.startswith('rst')):
return convert(source) # m2r markdown to rst conversion
elif (fmt.startswith('markdown') and to.startswith('asciidoc')):
markdown_to_asciidoc = mistune.Markdown(renderer=AsciidocRenderer())
return markdown_to_asciidoc(source)
else:
return source
# this will raise an exception that will pop us out of here
check_pandoc_version()
# we can safely continue
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, _ = p.communicate(cast_bytes(source, encoding))
out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()
return out.rstrip('\n')