python代码实现md转html
来源:互联网 发布:拍照软件mix 编辑:程序博客网 时间:2024/06/05 04:52
今天git上下载了一个电子书,格式是MD格式的,想弄成HTML格式后看,就自动动手写了一个转成脚本。
md是markdown格式的,用markdown模块来转
command = 'C:\\Python27\\python.exe c:\\Python27\\Scripts\\markdown_py -o html5 -f '+htmlfile+" "+fullfilename
因为有中文,所以转换后的HTML文件开头加进去了
<meta http-equiv="content-type" content="text/html; charset=UTF-8">不加的话,打开中文是乱码。
#encoding=utf-8from time import sleepimport osimport os.path__author__ = {'author':'pygocc','qq':'644234366','createdate':'2015-09-10'}rootdir = raw_input("请输入要转换的目录:")def mdtohtml(fullfilename): try: htmlfile = fullfilename+".html" command = 'C:\\Python27\\python.exe c:\\Python27\\Scripts\\markdown_py -o html5 -f '+htmlfile+" "+fullfilename os.system(command) existhtml = False i = 0 while(True): if os.path.isfile(htmlfile)==True: existhtml = True break if i>=5: print "tohtmlfile failed:",htmlfile break i = i+1 sleep(0.1) if existhtml == True: fp = open(htmlfile,"r+") pos = fp.tell() if pos == 0: fp.write('<meta http-equiv="content-type" content="text/html; charset=UTF-8">') fp.close() except Exception,e: print e.messagefor parent,dirnames,filenames in os.walk(rootdir): for filename in filenames: fullfilename = os.path.join(parent,filename) ext = fullfilename[-3:] if ext == '.md': # print fullfilename mdtohtml(fullfilename)
这个可以输入要转的目录,会把里面的所有.md结尾的文件都转成HTML文件,并在HTML文件开头出加入编码定义。
0 0
- python代码实现md转html
- markdown转HTML(使用editor.md)
- HTML标签全称md
- 学习python实战:年会抽奖程序的实现.md
- MD摘要代码
- 隐藏html代码实现代码
- python实现的html转xlsx,xlsx转html
- 将.md转化为.html
- java实现MD加密
- MD算法Java实现
- html下拉表单实现代码
- Html表格代码实现打印
- vue之html代码实现
- python小游戏实现代码
- PCA python代码实现
- python代码实现SVM
- 深度学习第三天: LeNet在Python实现Mnist手写数字.md
- html代码转码与反转码JS实现
- js正则表达式
- 违背商业道德,酷派的劈腿理由为何站不住脚?
- 多线程之使用信号量
- 我对设计模式的理解
- hdu 汉诺塔V 1995 递推
- python代码实现md转html
- mybatis分页
- SVD在推荐系统中的应用详解以及算法推导
- 统计学笔记
- 各种OJ资料规集
- 黑马程序员_java08_多线程
- 1072. Gas Station (30)
- TestNG 基本注解
- codeforces 392 B. Tower of Hanoi(汉诺塔 DP)