Python pypandoc.convert() Examples
The following are 30
code examples of pypandoc.convert().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pypandoc
, or try the search function
.
Example #1
Source File: setup.py From codimension with GNU General Public License v3.0 | 6 votes |
def getLongDescription(): """Provides the long description""" try: import pypandoc converted = pypandoc.convert('README.md', 'rst').splitlines() no_travis = [line for line in converted if 'travis-ci.org' not in line] long_description = '\n'.join(no_travis) # Pypi index does not like this link long_description = long_description.replace('|Build Status|', '') except Exception as exc: print('pypandoc package is not installed: the markdown ' 'README.md convertion to rst failed: ' + str(exc), file=sys.stderr) # pandoc is not installed, fallback to using raw contents with io.open('README.md', encoding='utf-8') as f: long_description = f.read() return long_description
Example #2
Source File: main.py From word2html with MIT License | 6 votes |
def convert_to_html(filename): # Do the conversion with pandoc output = pypandoc.convert(filename, 'html') # Clean up with tidy... output, errors = tidy_document(output, options={ 'numeric-entities': 1, 'wrap': 80, }) print(errors) # replace smart quotes. output = output.replace(u"\u2018", '‘').replace(u"\u2019", '’') output = output.replace(u"\u201c", "“").replace(u"\u201d", "”") # write the output filename, ext = os.path.splitext(filename) filename = "{0}.html".format(filename) with open(filename, 'w') as f: # Python 2 "fix". If this isn't a string, encode it. if type(output) is not str: output = output.encode('utf-8') f.write(output) print("Done! Output written to: {}\n".format(filename))
Example #3
Source File: setup.py From xbbg with Apache License 2.0 | 6 votes |
def parse_description(markdown=True): """ Parse the description in the README file """ if markdown: return parse_markdown() try: from pypandoc import convert readme_file = f'{PACKAGE_ROOT}/docs/index.rst' if not path.exists(readme_file): raise ImportError return convert(readme_file, 'rst') except ImportError: return parse_markdown()
Example #4
Source File: setup.py From pytest-ansible with MIT License | 6 votes |
def long_description(*paths): '''Returns a RST formated string. ''' result = '' # attempt to import pandoc try: import pypandoc except (ImportError, OSError) as e: print("Unable to import pypandoc - %s" % e) return result # attempt md -> rst conversion try: for path in paths: result += '\n' + pypandoc.convert( path, 'rst', format='markdown' ) except (OSError, IOError) as e: print("Failed to convert with pypandoc - %s" % e) return result return result
Example #5
Source File: setup.py From pylink with Apache License 2.0 | 6 votes |
def long_description(): """Reads and returns the contents of the README. On failure, returns the project long description. Returns: The project's long description. """ cwd = os.path.abspath(os.path.dirname(__file__)) readme_path = os.path.join(cwd, 'README.md') if not os.path.exists(readme_path): return pylink.__long_description__ try: import pypandoc return pypandoc.convert(readme_path, 'rst') except (IOError, ImportError): pass return open(readme_path, 'r').read()
Example #6
Source File: setup.py From B2HANDLE with Apache License 2.0 | 5 votes |
def find_version(*file_paths): version_file = read(*file_paths) version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") # Note: The package maintainer needs pypandoc and pygments to properly convert # the Markdown-formatted README into RestructuredText before uploading to PyPi # See https://bitbucket.org/pypa/pypi/issues/148/support-markdown-for-readmes
Example #7
Source File: setup.py From nanoservice with MIT License | 5 votes |
def read_long_description(readme_file): """ Read package long description from README file """ try: import pypandoc except (ImportError, OSError) as exception: print('No pypandoc or pandoc: %s' % (exception,)) if sys.version_info.major == 3: handle = open(readme_file, encoding='utf-8') else: handle = open(readme_file) long_description = handle.read() handle.close() return long_description else: return pypandoc.convert(readme_file, 'rst')
Example #8
Source File: setup.py From PyTLDR with GNU General Public License v3.0 | 5 votes |
def read(filename): filepath = os.path.join(os.path.dirname(__file__), filename) try: # Convert GitHub markdown to restructured text (needed for upload to PyPI) from pypandoc import convert return convert(filepath, 'rst') except ImportError: return open(filepath).read()
Example #9
Source File: setup.py From pcodedmp with GNU General Public License v3.0 | 5 votes |
def read_md(f): return convert(f, 'rst', format='md')
Example #10
Source File: setup.py From gitver with Apache License 2.0 | 5 votes |
def readme(): if make_sdist: try: import pypandoc return pypandoc.convert('README.md', 'rst') except ImportError: print "Warning: the \"pypandoc\" package and/or the pandoc " \ "binary can't be found on your system: if you want to " \ "generate the README.rst for PyPI you'll need to install " \ "them properly, else a fallback description will be used." # falling back to a simple description return 'Simple version string management for git'
Example #11
Source File: setup.py From py3tftp with MIT License | 5 votes |
def readme(): with open('README.md', 'r') as f: readme_md = f.read() if pypandoc: readme_rst = pypandoc.convert(readme_md, 'rst', format='md') return readme_rst else: return readme_md
Example #12
Source File: setup.py From oi with MIT License | 5 votes |
def read_long_description(readme_file): """ Read package long description from README file """ try: import pypandoc except (ImportError, OSError) as e: print('No pypandoc or pandoc: %s' % (e,)) if is_py3: fh = open(readme_file, encoding='utf-8') else: fh = open(readme_file) long_description = fh.read() fh.close() return long_description else: return pypandoc.convert(readme_file, 'rst')
Example #13
Source File: setup.py From pi_ina219 with MIT License | 5 votes |
def read_long_description(): try: import pypandoc return pypandoc.convert('README.md', 'rst') except(IOError, ImportError): return ""
Example #14
Source File: setup.py From aesthetics with Apache License 2.0 | 5 votes |
def get_long_description(): try: import pypandoc long_description = pypandoc.convert('README.md', 'rst') except (IOError, ImportError): with open('README.txt') as fhan: long_description = fhan.read() return long_description
Example #15
Source File: common_setup.py From pytest-plugins with MIT License | 5 votes |
def common_setup(src_dir): this_dir = os.path.dirname(__file__) readme_file = os.path.join(this_dir, 'README.md') changelog_file = os.path.join(this_dir, 'CHANGES.md') version_file = os.path.join(this_dir, 'VERSION') # Convert Markdown to RST for PyPI try: import pypandoc long_description = pypandoc.convert(readme_file, 'rst') changelog = pypandoc.convert(changelog_file, 'rst') except (IOError, ImportError, OSError): long_description = open(readme_file).read() changelog = open(changelog_file).read() # Gather trailing arguments for pytest, this can't be done using setuptools' api if 'test' in sys.argv: PyTest.pytest_args = sys.argv[sys.argv.index('test') + 1:] if PyTest.pytest_args: sys.argv = sys.argv[:-len(PyTest.pytest_args)] PyTest.src_dir = src_dir return dict( # Version is shared between all the projects in this repo version=open(version_file).read().strip(), long_description='\n'.join((long_description, changelog)), url='https://github.com/manahl/pytest-plugins', license='MIT license', platforms=['unix', 'linux'], cmdclass={'test': PyTest, 'egg_info': EggInfo}, include_package_data=True )
Example #16
Source File: setup.py From ricloud with GNU Lesser General Public License v3.0 | 5 votes |
def markdown2rst(path): try: import pypandoc return pypandoc.convert(path, 'rst', 'md') except ImportError: with open(path, 'r') as f: return f.read()
Example #17
Source File: setup.py From tcping with MIT License | 5 votes |
def read_long_description(): try: import pypandoc return pypandoc.convert('README.md', 'rst') except(IOError, ImportError, RuntimeError): return ""
Example #18
Source File: setup.py From pep8radius with MIT License | 5 votes |
def readme(): try: import pypandoc return pypandoc.convert('README.md', 'rst', format='md') except (IOError, ImportError): with open('README.md') as f: return f.read()
Example #19
Source File: setup.py From python-cjdns with GNU General Public License v3.0 | 5 votes |
def readme(fname): """Reads a markdown file and returns the contents formatted as rst""" md = open(os.path.join(os.path.dirname(__file__), fname)).read() output = md try: import pypandoc output = pypandoc.convert(md, 'rst', format='md') except ImportError: pass return output
Example #20
Source File: main.py From Reddit-GoodReads-Bot with MIT License | 5 votes |
def html_to_md(string): # remove the <br> tags before conversion if not string: return string = string.replace('<br>', ' ') return pypandoc.convert(string, 'md', format='html')
Example #21
Source File: setup.py From iot-python with Eclipse Public License 1.0 | 5 votes |
def read_md(f): return convert(f, 'rst')
Example #22
Source File: setup.py From Expert-Python-Programming_Second-Edition with BSD 3-Clause "New" or "Revised" License | 5 votes |
def read_md(f): return convert(f, 'rst')
Example #23
Source File: conf.py From aliyun-log-cli with MIT License | 5 votes |
def convert_file(src_file, target_folder='.'): file_name = os.path.basename(src_file) new_file_name = os.path.splitext(file_name)[0] + '.rst' new_file_path = os.path.sep.join([target_folder, new_file_name]) print("**** convert: " + src_file + " to " + new_file_path) if six.PY3: open(new_file_path, "w").write(pypandoc.convert(src_file, 'rst')) else: open(new_file_path, "w").write(pypandoc.convert(src_file, 'rst').encode('utf8'))
Example #24
Source File: setup.py From healthcareai-py with MIT License | 5 votes |
def readme(): # I really prefer Markdown to reStructuredText. PyPi does not. This allows me # to have things how I'd like, but not throw complaints when people are trying # to install the package and they don't have pypandoc or the README in the # right place. # From https://coderwall.com/p/qawuyq/use-markdown-readme-s-in-python-modules try: import pypandoc long_description = pypandoc.convert('README.md', 'rst') except (IOError, ImportError): with open('README.md') as f: return f.read() else: return long_description
Example #25
Source File: setup.py From hdidx with MIT License | 5 votes |
def read_md(fpath): return convert(fpath, 'rst')
Example #26
Source File: setup.py From trackerjacker with MIT License | 5 votes |
def get_readme(): try: import pypandoc readme_data = pypandoc.convert('README.md', 'rst') except(IOError, ImportError): readme_data = open('README.md').read() return readme_data
Example #27
Source File: setup.py From neleval with Apache License 2.0 | 5 votes |
def read_markdown(filename): path = os.path.join(os.path.dirname(__file__), filename) if not os.path.exists(path): if 'sdist' in sys.argv: print('WARNING: did not find %r' % filename, file=sys.stderro) return try: import pypandoc except ImportError: if 'sdist' in sys.argv: print('WARNING: Could not import pypandoc to convert README.md to RST!', file=sys.stderr) return open(path).read() return pypandoc.convert(path, 'rst')
Example #28
Source File: setup.py From OmNomNom with GNU Affero General Public License v3.0 | 5 votes |
def readme(): with open('README.md') as f: content = f.read() try: # noinspection PyUnresolvedReferences from pypandoc import convert return convert(content, 'rst', 'md') except ImportError: print("warning: pypandoc module not found, could not convert Markdown to RST") return content
Example #29
Source File: doxygen2sphinx.py From AutoWIG with Apache License 2.0 | 5 votes |
def desc_converter(desc): desc = pypandoc.convert(desc, to='rst', format='markdown') return re.sub(r'\[STRIKEOUT:(\:.*)\:``(.*)``\]', r'\1:`\2`', desc).rstrip().replace(r'"', "'")
Example #30
Source File: setup.py From python-thumbnails with MIT License | 5 votes |
def _read_long_description(): try: import pypandoc return pypandoc.convert('README.md', 'rst', format='markdown') except Exception: return None