当前位置: 首页>>代码示例>>Python>>正文


Python m2r.convert方法代码示例

本文整理汇总了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() 
开发者ID:altair-viz,项目名称:altair,代码行数:18,代码来源:generate_schema_wrapper.py

示例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') 
开发者ID:dephell,项目名称:dephell,代码行数:12,代码来源:_readme.py

示例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 
开发者ID:sphinx-contrib,项目名称:openapi,代码行数:15,代码来源:utils.py

示例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') 
开发者ID:holzschu,项目名称:Carnets,代码行数:57,代码来源:pandoc.py


注:本文中的m2r.convert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。