How to use the pypandoc.convert_file function in pypandoc

To help you get started, we’ve selected a few pypandoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bebraw / pypandoc / tests.py View on Github external
def test_convert_with_custom_writer(self):
        lua_file_content = self.create_sample_lua()
        with closed_tempfile('.md', text='# title\n') as file_name:
            with closed_tempfile('.lua', text=lua_file_content, dir_name="foo-bar+baz",
                                 check_case=True) as lua_file_name:
                expected = u'<h1>title</h1>{0}'.format(os.linesep)
                received = pypandoc.convert_file(file_name, lua_file_name)
                self.assertEqualExceptForNewlineEnd(expected, received)
github bebraw / pypandoc / tests.py View on Github external
def test_basic_conversion_from_file_with_format(self):
        with closed_tempfile('.md', text='# some title\n') as file_name:
            expected = u'some title{0}=========={0}{0}'.format(os.linesep)
            received = pypandoc.convert_file(file_name, 'rst', format='md')
            self.assertEqualExceptForNewlineEnd(expected, received)

            received = pypandoc.convert_file(file_name, 'rst', format='md')
            self.assertEqualExceptForNewlineEnd(expected, received)
github bebraw / pypandoc / tests.py View on Github external
def test_basic_conversion_from_file(self):
        with closed_tempfile('.md', text='# some title\n') as file_name:
            expected = u'some title{0}=========={0}{0}'.format(os.linesep)
            received = pypandoc.convert_file(file_name, 'rst')
            self.assertEqualExceptForNewlineEnd(expected, received)
github cropsinsilico / yggdrasil / setup.py View on Github external
if 'sdist' not in sys.argv:
    # Attempt to install languages
    installed_languages = install_languages.install_all_languages(from_setup=True)
    # Set coverage options in .coveragerc
    create_coveragerc.create_coveragerc(installed_languages)


# Create .rst README from .md and get long description
if os.path.isfile('README.rst'):
    with open('README.rst', 'r') as file:
        long_description = file.read()
elif os.path.isfile('README.md'):
    try:
        import pypandoc
        pypandoc.convert_file('README.md', 'rst', outputfile='README.rst')
        long_description = pypandoc.convert_file('README.md', 'rst')
    except (ImportError, IOError):
        with open('README.md', 'r') as file:
            long_description = file.read()
else:
    raise IOError("Could not find README.rst or README.md")


# Create requirements list based on platform
with open("requirements.txt", 'r') as fd:
    requirements = fd.read().splitlines()
with open("requirements_testing.txt", 'r') as fd:
    test_requirements = fd.read().splitlines()
# with open("requirements_optional.txt", 'r') as fd:
#     optional_requirements = fd.read().splitlines()
github mbadry1 / DeepLearning.ai-Summary / download.py View on Github external
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")
github JetBrains / youtrack-python-scripts / setup.py View on Github external
from os import path
from setuptools import setup

here = path.abspath(path.dirname(__file__))

# Try to convert markdown readme file to rst format
try:
    import pypandoc
    md_file = path.join(here, 'README.md')
    rst_file = path.join(here, 'README.rst')
    pypandoc.convert_file(source_file=md_file, outputfile=rst_file, to='rst')
except (ImportError, OSError, IOError, RuntimeError):
    pass

# Get the long description from the relevant file
with open(path.join(here, 'README.rst')) as f:
    long_description = f.read()

# Get version from file
with open(path.join(here, 'version')) as f:
    version = f.read().strip()


setup(
    name='youtrack-scripts',
    version=version,
    python_requires='&gt;=2.6, &lt;3',
github ralphwetzel / theonionbox / setup.py View on Github external
if (old_md_hash != current_md_hash) or (old_html_hash != current_html_hash):
        from grip import export
        export(path='README.md', out_filename='readme/README.html', title=f"{stamp['__title__']} v{stamp['__version__']}")
        hash_changed = True
    else:
        print('Skiping generation of README.html; files unchanged!')

    do_rst = False
    if do_rst is True:
        if (old_md_hash != current_md_hash) or (old_rst_hash != current_rst_hash):
            # path defined by: brew install pandoc
            # os.environ.setdefault('PYPANDOC_PANDOC', '/usr/local/Cellar/pandoc/2.1')
            from pypandoc import convert_file
            print('Generating README.rst')
            convert_file('README.md', 'rst', outputfile="readme/README.rst")
            hash_changed = True
        else:
            print('Skiping generation of README.rst; files unchanged!')
    else:
        print('Generation of README.rst intentionally deactivated!')

    if hash_changed is True:
        with open('readme/README.hash', 'w') as f:
            f.write(current_md_hash+'\n'+current_html_hash+'\n'+current_rst_hash)
github danielhers / tupa / setup.py View on Github external
this_file = __file__
except NameError:
    this_file = sys.argv[0]
os.chdir(os.path.dirname(os.path.abspath(this_file)))

with open("requirements.txt") as f:
    install_requires = f.read().splitlines()

try:
    # noinspection PyPackageRequirements
    import pypandoc
    try:
        pypandoc.convert_file("README.md", "rst", outputfile="README.rst")
    except (IOError, ImportError, RuntimeError):
        pass
    long_description = pypandoc.convert_file("README.md", "rst")
except (IOError, ImportError, RuntimeError):
    long_description = ""


class install(_install):
    # noinspection PyBroadException
    def run(self):
        # Install requirements
        self.announce("Installing dependencies...")
        run(["pip", "--no-cache-dir", "install"] + install_requires, check=True)

        # Install actual package
        _install.run(self)


setup(name="TUPA",
github vkbo / novelWriter / nw / gui / dialogs / export.py View on Github external
return False

        outFile  = path.splitext(inFile)[0]+GuiExportPandoc.FMT_EXT[outFmt]
        fileName = path.basename(outFile)

        if path.isfile(outFile) and self.mainConf.showGUI:
            msgBox = QMessageBox()
            msgRes = msgBox.question(
                self.theParent, "Overwrite",
                ("File '%s' already exists.<br>Do you want to overwrite it?" % fileName)
            )
            if msgRes != QMessageBox.Yes:
                return False

        try:
            pypandoc.convert_file(
                source_file = inFile,
                format      = inFmt,
                outputfile  = outFile,
                to          = pFmt[outFmt],
                extra_args  = (),
                encoding    = "utf-8",
                filters     = None
            )
        except Exception as e:
            self.theParent.makeAlert(
                ["Failed to convert file using pypandoc + Pandoc.",
                str(e)], nwAlert.ERROR
            )
            return False

        return True
github RadioAstronomySoftwareGroup / pyuvsim / docs / make_index.py View on Github external
def write_index_rst(readme_file=None, write_file=None):
    t = Time.now()
    t.out_subfmt = 'date'
    out = ('.. pyuvsim documentation master file, created by\n'
           '   make_index.py on {date}\n\n').format(date=t.iso)

    print(readme_file)
    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')

    pypandoc.convert_file(readme_file, 'md')
    readme_text = pypandoc.convert_file(readme_file, 'rst')

    out += readme_text

    out += ('\n\nFurther Documentation\n====================================\n'
            '.. toctree::\n'
            '   :maxdepth: 2\n\n'
            '   comparison\n'
            '   usage\n'
            '   parameter_files\n'
            '   classes\n'
            '   developers\n')

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

    if write_file is None: