本文共 691 字,大约阅读时间需要 2 分钟。
# -*- coding: utf-8
import markdown
import os
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def md2html(mdstr):
exts = ['markdown.extensions.extra', 'markdown.extensions.codehilite','markdown.extensions.tables','markdown.extensions.toc']
html = '''
%s
'''
ret = markdown.markdown(mdstr,extensions=exts)
return html % ret
if __name__ == '__main__':
if len(sys.argv)
print('usage: md2html source_filename target_file')
sys.exit()
infile = open(sys.argv[1],'r')
md = infile.read()
infile.close()
if os.path.exists(sys.argv[2]):
os.remove(sys.argv[2])
outfile = open(sys.argv[2],'a')
outfile.write(md2html(md))
outfile.close()
print('convert %s to %s success!'%(sys.argv[1],sys.argv[2]))
转载地址:http://wowra.baihongyu.com/