代码示例
# -*- coding: utf-8 -*- # @File : markdown_to_rst.py # @Date : 2018-08-20 # @Author : Peng Shiyu import requests def md_to_rst(from_file, to_file): """ 将markdown格式转换为rst格式 @param from_file: {str} markdown文件的路径 @param to_file: {str} rst文件的路径 """ response = requests.post( url='http://c.docverter.com/convert', data={'to': 'rst', 'from': 'markdown'}, files={'input_files[]': open(from_file, 'rb')} ) if response.ok: with open(to_file, "wb") as f: f.write(response.content) if __name__ == '__main__': md_to_rst("README.md", "README.rst")
转换结果:
README.md
# 文章标题 代码示例 `` print("hello world!") ``
备注:` 有三个,为了避免冲突只写了2个
README.rst
文章标题 ======== 代码示例 :: print("hello world!")