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


Python pypandoc.convert_text方法代码示例

本文整理汇总了Python中pypandoc.convert_text方法的典型用法代码示例。如果您正苦于以下问题:Python pypandoc.convert_text方法的具体用法?Python pypandoc.convert_text怎么用?Python pypandoc.convert_text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypandoc的用法示例。


在下文中一共展示了pypandoc.convert_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _convert_md_table_to_rst

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def _convert_md_table_to_rst(table):
    """Convert a markdown table to rst format"""
    if len(table) < 3:
        return ''
    out = '```eval_rst\n.. list-table::\n   :header-rows: 1\n\n'
    for i,l in enumerate(table):
        cols = l.split('|')[1:-1]
        if i == 0:
            ncol = len(cols)
        else:
            if len(cols) != ncol:
                return ''
        if i == 1:
            for c in cols:
                if len(c) is not 0 and '---' not in c:
                    return ''
        else:
            for j,c in enumerate(cols):
                out += '   * - ' if j == 0 else '     - '
                out += pypandoc.convert_text(
                    c, 'rst', format='md').replace('\n', ' ').replace('\r', '') + '\n'
    out += '```\n'
    return out 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:25,代码来源:mxdoc.py

示例2: create

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def create(self, variables, md_output, pdf_output):
        env = Environment(loader=PackageLoader('qanta', 'reporting/templates'))
        template = env.get_template(self.template)
        markdown = template.render(variables)
        if md_output is not None:
            with open(md_output, 'w') as f:
                f.write(markdown)
        try:
            import pypandoc
            pypandoc.convert_text(
                markdown,
                'pdf',
                format='md',
                outputfile=pdf_output,
                extra_args=['-V', 'geometry:margin=.75in']
            )
        except Exception as e:
            log.warn('Pandoc was not installed or there was an error calling it, omitting PDF report')
            log.warn(str(e)) 
开发者ID:Pinafore,项目名称:qb,代码行数:21,代码来源:report_generator.py

示例3: convert_issue_data

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def convert_issue_data(self, redmine_issue):
        """
        Generate the data for a new GitHub issue
        """
        description_md = convert_text(
            redmine_issue['description'], 'markdown_github', 'textile'
        )
        porting_note = '###### ported from Redmine #%s (created %s)' % (
            redmine_issue['id'],
            redmine_issue['created_on'].split('T')[0]
        )
        if self.is_closed(redmine_issue):
            porting_note = '%s (CLOSED %s)' % (
                porting_note,
                redmine_issue['closed_on'].split('T')[0]
            )
        body = "%s\n\n%s" % (porting_note, description_md)
        title = "%(subject)s (RM#%(id)s)" % redmine_issue
        return {
            "title": title,
            "body": body,
            "assignees": ["adam-iris"],
        } 
开发者ID:iris-edu,项目名称:pyweed,代码行数:25,代码来源:redmine_to_github.py

示例4: fill_notebook

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def fill_notebook(work_notebook, script_blocks, gallery_conf):
    """Writes the Jupyter notebook cells

    If available, uses pypandoc to convert rst to markdown.

    Parameters
    ----------
    script_blocks : list
        Each list element should be a tuple of (label, content, lineno).
    """
    for blabel, bcontent, lineno in script_blocks:
        if blabel == 'code':
            add_code_cell(work_notebook, bcontent)
        else:
            if gallery_conf["pypandoc"] is False:
                markdown = rst2md(bcontent + '\n')
            else:
                import pypandoc
                # pandoc automatically addds \n to the end
                markdown = pypandoc.convert_text(
                    bcontent, to='md', format='rst', **gallery_conf["pypandoc"]
                )
            add_markdown_cell(work_notebook, markdown) 
开发者ID:sphinx-gallery,项目名称:sphinx-gallery,代码行数:25,代码来源:notebook.py

示例5: rst_to_notebook

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def rst_to_notebook(infile, outfile, diridx=False):
    """Convert an rst file to a notebook file."""

    # Read infile into a string
    with open(infile, 'r') as fin:
        rststr = fin.read()
    # Convert string from rst to markdown
    mdfmt = 'markdown_github+tex_math_dollars+fenced_code_attributes'
    mdstr = pypandoc.convert_text(rststr, mdfmt, format='rst',
                                  extra_args=['--atx-headers'])
    # In links, replace .py extensions with .ipynb
    mdstr = re.sub(r'\(([^\)]+).py\)', r'(\1.ipynb)', mdstr)
    # Links to subdirectories require explicit index file inclusion
    if diridx:
        mdstr = re.sub(r']\(([^\)/]+)\)', r'](\1/index.ipynb)', mdstr)
    # Enclose the markdown within triple quotes and convert from
    # python to notebook
    mdstr = '"""' + mdstr + '"""'
    nb = py2jn.py_string_to_notebook(mdstr)
    py2jn.tools.write_notebook(nb, outfile, nbver=4) 
开发者ID:bwohlberg,项目名称:sporco,代码行数:22,代码来源:docntbk.py

示例6: pandoc_process

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def pandoc_process(app, what, name, obj, options, lines):
    """"Convert docstrings in Markdown into reStructureText using pandoc
    """

    if not lines:
        return None

    input_format = app.config.mkdsupport_use_parser
    output_format = 'rst'

    # Since default encoding for sphinx.ext.autodoc is unicode and pypandoc.convert_text, which will always return a
    # unicode string, expects unicode or utf-8 encodes string, there is on need for dealing with coding
    text = SEP.join(lines)
    text = pypandoc.convert_text(text, output_format, format=input_format)

    # The 'lines' in Sphinx is a list of strings and the value should be changed
    del lines[:]
    lines.extend(text.split(SEP)) 
开发者ID:UWNETLAB,项目名称:metaknowledge,代码行数:20,代码来源:mkdsupport.py

示例7: convert

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def convert(content, from_format, to_format, use_file=False):
    if use_file:
        filename = make_file(to_format)
    else:
        filename = None
    output = pypandoc.convert_text(
        content, to_format, format=from_format, outputfile=filename)
    if use_file:
        content = read_file(filename)
        try:
            return content.decode('UTF-8')
        except UnicodeDecodeError:
            return content.decode('latin-1')
    else:
        return output 
开发者ID:rapid7,项目名称:insightconnect-plugins,代码行数:17,代码来源:utils.py

示例8: __init__

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def __init__(self, source_data):
        try:
            import pypandoc
        except ImportError as e:
            # pypandoc package may do not installed in the system since the package is
            # an optional dependency
            raise PypandocImportError(e)

        super().__init__(pypandoc.convert_text(source_data, "html", format="mediawiki")) 
开发者ID:thombashi,项目名称:pytablereader,代码行数:11,代码来源:formatter.py

示例9: convert_rst_to_md

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def convert_rst_to_md(text):
    return pypandoc.convert_text(
        text, "md", format="rst", extra_args=["--wrap=preserve"]
    ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:6,代码来源:publish-gh-release-notes.py

示例10: html2markdown

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def html2markdown(html: str) -> str:
    """
    Returns the given HTML as equivalent Markdown-structured text.
    """
    try:
        return pypandoc.convert_text(html, 'md', format='html')
    except OSError:
        msg = "It's recommended to install the `pandoc` library for converting " \
              "HTML into Markdown-structured text. It tends to have better results" \
              "than `html2text`, which is now used as a fallback."
        print(msg)
        return html2text(html) 
开发者ID:Debakel,项目名称:feedDiasp,代码行数:14,代码来源:RSSParser.py

示例11: md2rst

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def md2rst(comment):
    """Convert a comment from protobuf markdown to restructuredtext.

    This method:
    - Replaces proto links with literals (e.g. [Foo][bar.baz.Foo] -> `Foo`)
    - Resolves relative URLs to https://cloud.google.com
    - Runs pandoc to convert from markdown to restructuredtext
    """
    comment = _replace_proto_link(comment)
    comment = _replace_relative_link(comment)
    # Calling pypandoc.convert_text is slow, so we try to avoid it if there are
    # no special characters in the markdown.
    if any([i in comment for i in '`[]*_']):
        comment = pypandoc.convert_text(comment, 'rst', format='commonmark')
        # Comments are now valid restructuredtext, but there is a problem. They
        # are being inserted back into a descriptor set, and there is an
        # expectation that each line of a comment will begin with a space, to
        # separate it from the '//' that begins the comment. You would think
        # that we could ignore this detail, but it will cause formatting
        # problems down the line in gapic-generator because parsing code will
        # try to remove the leading space, affecting the indentation of lines
        # that actually do begin with a space, so we insert the additional
        # space now. Comments that are not processed by pypandoc will already
        # have a leading space, so should not be changed.
        comment = _insert_spaces(comment)
    return comment 
开发者ID:googleapis,项目名称:artman,代码行数:28,代码来源:descriptor_set_tasks.py

示例12: read

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def read(self, contents, context=None):
        assert isinstance(contents, str)
        js = pypandoc.convert_text(contents, 'json', format=PANDOC_MARKDOWN_FORMAT)
        ast = ASTPlugin().loads(js)
        return ast 
开发者ID:podoc,项目名称:podoc,代码行数:7,代码来源:_markdown.py

示例13: get_pandoc_api_version

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def get_pandoc_api_version():
    import pypandoc
    return json.loads(pypandoc.convert_text('', 'json', format='markdown'))['pandoc-api-version'] 
开发者ID:podoc,项目名称:podoc,代码行数:5,代码来源:utils.py

示例14: html2markdown

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def html2markdown(html):
    """Converts `html` to Markdown-formatted text
    """
    markdown_text = pypandoc.convert_text(html, 'markdown_strict', format='html')
    return markdown_text 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:7,代码来源:converters.py

示例15: twlight_wikicode2html

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_text [as 别名]
def twlight_wikicode2html(value):
    """Passes string through pandoc and returns html"""
    output = pypandoc.convert_text(value, "html", format="mediawiki")
    return output 
开发者ID:WikipediaLibrary,项目名称:TWLight,代码行数:6,代码来源:twlight_wikicode2html.py


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