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