當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。