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


Python pypandoc.convert_file方法代码示例

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


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

示例1: main

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def main():
    marks_down_links = {
        "Standford CS231n 2017 Summary":
            "https://raw.githubusercontent.com/mbadry1/CS231n-2017-Summary/master/README.md",
    }

    # Extracting pandoc version
    print("pandoc_version:", pypandoc.get_pandoc_version())
    print("pandoc_path:", pypandoc.get_pandoc_path())
    print("\n")

    # Starting downloading and converting
    for key, value in marks_down_links.items():
        print("Converting", key)
        pypandoc.convert_file(
            value,
            'pdf',
            extra_args=['--latex-engine=xelatex', '-V', 'geometry:margin=1.5cm'],
            outputfile=(key + ".pdf")
        )
        print("Converting", key, "completed") 
开发者ID:mbadry1,项目名称:CS231n-2017-Summary,代码行数:23,代码来源:download.py

示例2: convert_log

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def convert_log(file, file_format='html'):
    """
    Converts the log file to a given file format

    :param file: The filename and path
    :param file_format: The desired format
    """
    output_filename = os.path.splitext(file)[0] + '.' + file_format
    output = pypandoc.convert_file(file, file_format, outputfile=output_filename)
    assert output == ""

# The End 
开发者ID:IndEcol,项目名称:ODYM,代码行数:14,代码来源:ODYM_Functions.py

示例3: read_md

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def read_md(f): return convert_file(f, 'rst').replace("~",'^')	# Hack to pass the 'rst_lint.py' - PyPI 
开发者ID:operatorequals,项目名称:httpimport,代码行数:3,代码来源:setup.py

示例4: main

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def main():
    home_link = "https://raw.githubusercontent.com/mbadry1/DeepLearning.ai-Summary/master/"
    marks_down_links = {
        "Deeplearning.ai summary Homepage":
            home_link + "Readme.md",
        "01- Neural Networks and Deep Learning":
            home_link + "1-%20Neural%20Networks%20and%20Deep%20Learning/Readme.md",
        "02- Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization":
            home_link + "2-%20Improving%20Deep%20Neural%20Networks/Readme.md",
        "03- Structuring Machine Learning Projects":
            home_link + "3-%20Structuring%20Machine%20Learning%20Projects/Readme.md",
        "04- Convolutional Neural Networks":
            home_link + "4-%20Convolutional%20Neural%20Networks/Readme.md",
        "05- Sequence Models":
            home_link + "5-%20Sequence%20Models/Readme.md",
    }

    # Extracting pandoc version
    print("pandoc_version:", pypandoc.get_pandoc_version())
    print("pandoc_path:", pypandoc.get_pandoc_path())
    print("\n")

    # Starting downloading and converting
    for key, value in marks_down_links.items():
        print("Converting", key)
        pypandoc.convert_file(
            value,
            'pdf',
            extra_args=['--pdf-engine=xelatex', '-V', 'geometry:margin=1.5cm'],
            outputfile=(key + ".pdf")
        )
        print("Converting", key, "completed") 
开发者ID:mbadry1,项目名称:DeepLearning.ai-Summary,代码行数:34,代码来源:download.py

示例5: _load_readme

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def _load_readme(self):
        readme = self._config['package']['readme']
        readme_path = os.path.join(self._dir, readme)

        if self.has_markdown_readme():
            if not pypandoc:
                warnings.warn(
                    'Markdown README files require the pandoc utility '
                    'and the pypandoc package.'
                )
            else:
                self._readme = pypandoc.convert_file(readme_path, 'rst')
        else:
            with open(readme_path) as f:
                self._readme = f.read() 
开发者ID:sdispater,项目名称:poet,代码行数:17,代码来源:poet.py

示例6: read_md

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def read_md(filename):
    try:
        from pypandoc import convert_file
        return convert_file(filename, 'rst')
    except (ImportError, OSError):
        return open(filename).read() 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:8,代码来源:setup.py

示例7: convert_markdown_to_rst

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def convert_markdown_to_rst(file):
      return convert_file(file, 'rst') 
开发者ID:egnyte,项目名称:gitlabform,代码行数:4,代码来源:setup.py

示例8: long_description

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def long_description(filename = 'README.md'):
    if os.path.isfile(os.path.expandvars(filename)):
      try:
          import pypandoc
          long_description = pypandoc.convert_file(filename, 'rst')
      except ImportError:
          long_description = open(filename).read()
    else:
        long_description = ''
    return long_description 
开发者ID:wdbm,项目名称:spin,代码行数:12,代码来源:setup.py

示例9: from_file

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def from_file(self, filename, **opts):
        self.tmp_dir = wd = tempfile.mkdtemp()
        target_file = os.path.join(wd, 'post.md')

        import pypandoc
        pypandoc.convert_file(
            filename,
            format='docx',
            to='markdown-grid_tables',
            outputfile=target_file,
            extra_args=[
                '--standalone',
                '--wrap=none',
                '--extract-media={}'.format(wd)
            ]
        )

        with open(target_file) as f:
            md = f.read()

        # Image embeddings exported from docx files have fixed sizes in inches
        # which browsers do not understand. We remove these annotations.
        md = re.sub(r'(\!\[[^\]]+?\]\([^\)]+?\))\{[^\}]+?\}', lambda m: m.group(1), md)

        # Write markdown content to knowledge post (images will be extracted later)
        self.kp_write(md) 
开发者ID:airbnb,项目名称:knowledge-repo,代码行数:28,代码来源:docx.py

示例10: read_md

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def read_md(f):
        return convert_file(f, 'rst')

    # read_md = lambda f: convert(f, 'rst') 
开发者ID:watson-developer-cloud,项目名称:python-sdk,代码行数:6,代码来源:setup.py

示例11: read_md

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def read_md(path):
    long_desc = ""
    if os.path.exists(path):
        try:
            from pypandoc import convert_file
            long_desc = convert_file(path, 'rst')
        except:
            try:
                long_desc = open(path, 'r').read()
            except:
                pass
    return long_desc 
开发者ID:dessibelle,项目名称:sorl-thumbnail-serializer-field,代码行数:14,代码来源:setup.py

示例12: write_index_rst

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def write_index_rst(readme_file=None, write_file=None):
    t = Time.now()
    t.out_subfmt = "date"
    out = (
        ".. pyuvdata documentation master file, created by\n"
        "   make_index.py on {date}\n\n"
    ).format(date=t.iso)

    if readme_file is None:
        main_path = os.path.dirname(
            os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
        )
        readme_file = os.path.join(main_path, "README.md")

    readme_text = pypandoc.convert_file(readme_file, "rst")

    # convert relative links in readme to explicit links
    readme_text = readme_text.replace(
        "<docs/",
        "<https://github.com/RadioAstronomySoftwareGroup/pyuvdata/tree/master/docs/",
    )

    readme_text = readme_text.replace(
        "<.github/",
        "<https://github.com/RadioAstronomySoftwareGroup/pyuvdata/tree/master/.github/",
    )

    out += readme_text
    out += (
        "\n\nFurther Documentation\n====================================\n"
        ".. toctree::\n"
        "   :maxdepth: 1\n\n"
        "   tutorial\n"
        "   uvdata_parameters\n"
        "   uvdata\n"
        "   uvcal_parameters\n"
        "   uvcal\n"
        "   uvbeam_parameters\n"
        "   uvbeam\n"
        "   uvflag_parameters\n"
        "   uvflag\n"
        "   cst_settings_yaml\n"
        "   utility_functions\n"
        "   known_telescopes\n"
        "   developer_docs\n"
    )

    out.replace(u"\u2018", "'").replace(u"\u2019", "'").replace(u"\xa0", " ")

    if write_file is None:
        write_path = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
        write_file = os.path.join(write_path, "index.rst")
    F = open(write_file, "w")
    F.write(out)
    print("wrote " + write_file) 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:57,代码来源:make_index.py

示例13: html_to_docx

# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert_file [as 别名]
def html_to_docx(htmlfile, docxfile, handler=None, metadata=None):
    """ Convert html file to docx file.

    Parameters
    ----------

    htmlfile : str
        Filename of the notebook exported as html
    docxfile : str
        Filename for the notebook exported as docx
    handler : tornado.web.RequestHandler, optional
        Handler that serviced the bundle request
    metadata : dict, optional
        Dicts with metadata information of the notebook
    """

    # check if html file exists
    if not os.path.isfile(htmlfile):
        raise FileNotFoundError(f'html-file does not exist: {htmlfile}')

    # check if export path exists
    if os.path.dirname(docxfile) != '' and not os.path.isdir(os.path.dirname(docxfile)):
        raise FileNotFoundError(f'Path to docx-file does not exist: {os.path.dirname(docxfile)}')

    # set extra args for pandoc
    extra_args = []
    if metadata is not None and 'authors' in metadata:
        if isinstance(metadata['authors'], list) and all(
            ['name' in x for x in metadata['authors']]
        ):
            extra_args.append(
                f'--metadata=author:' f'{", ".join([x["name"] for x in metadata["authors"]])}'
            )
        elif handler is not None:
            handler.log.warning(
                'Author metadata has wrong format, see https://github.com/m-rossi/jupyter_docx_bun'
                'dler/blob/master/README.md'
            )
    if metadata is not None and 'subtitle' in metadata:
        extra_args.append(f'--metadata=subtitle:{metadata["subtitle"]}')
    if metadata is not None and 'date' in metadata:
        extra_args.append(f'--metadata=date:{metadata["date"]}')

    # convert to docx
    pypandoc.convert_file(
        htmlfile,
        'docx',
        format='html+tex_math_dollars',
        outputfile=docxfile,
        extra_args=extra_args,
    ) 
开发者ID:m-rossi,项目名称:jupyter-docx-bundler,代码行数:53,代码来源:converters.py


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