本文整理汇总了Python中pypandoc.convert方法的典型用法代码示例。如果您正苦于以下问题:Python pypandoc.convert方法的具体用法?Python pypandoc.convert怎么用?Python pypandoc.convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypandoc
的用法示例。
在下文中一共展示了pypandoc.convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getLongDescription
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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
示例2: parse_description
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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()
示例3: long_description
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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()
示例4: long_description
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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
示例5: convert_to_html
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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))
示例6: read_md
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def read_md(f):
return convert(f, 'rst')
示例7: readme
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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
示例8: read_md
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def read_md(fpath):
return convert(fpath, 'rst')
示例9: get_readme
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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
示例10: read_markdown
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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')
示例11: readme
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
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
示例12: desc_converter
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def desc_converter(desc):
desc = pypandoc.convert(desc, to='rst', format='markdown')
return re.sub(r'\[STRIKEOUT:(\:.*)\:``(.*)``\]', r'\1:`\2`', desc).rstrip().replace(r'"', "'")
示例13: _read_long_description
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def _read_long_description():
try:
import pypandoc
return pypandoc.convert('README.md', 'rst', format='markdown')
except Exception:
return None
示例14: md2rst
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def md2rst(obj):
if WITH_PANDOC:
return pypandoc.convert(obj, to='rst', format='markdown')
else:
return obj.replace('```', '\n')
示例15: convert_md
# 需要导入模块: import pypandoc [as 别名]
# 或者: from pypandoc import convert [as 别名]
def convert_md():
with open(RST_README_PATH, 'wb') as readme:
converted = convert(MD_README_PATH, 'rst')
readme.write(converted.encode('utf-8'))