Have the same README both in Markdown and reStructuredText

后端 未结 8 1275
旧时难觅i
旧时难觅i 2020-12-22 16:29

I have a project hosted on GitHub. For this I have written my README using the Markdown syntax in order to have it nicely formatted on GitHub.

As my project is in Py

8条回答
  •  爱一瞬间的悲伤
    2020-12-22 17:03

    As @Chris suggested, you can use Pandoc to convert Markdown to RST. This can be simply automated using pypandoc module and some magic in setup.py:

    from setuptools import setup
    try:
        from pypandoc import convert
        read_md = lambda f: convert(f, 'rst')
    except ImportError:
        print("warning: pypandoc module not found, could not convert Markdown to RST")
        read_md = lambda f: open(f, 'r').read()
    
    setup(
        # name, version, ...
        long_description=read_md('README.md'),
        install_requires=[]
    )
    

    This will automatically convert README.md to RST for the long description using on PyPi. When pypandoc is not available, then it just reads README.md without the conversion – to not force others to install pypandoc when they wanna just build the module, not upload to PyPi.

    So you can write in Markdown as usual and don’t care about RST mess anymore. ;)

提交回复
热议问题