- 使用
pip install markdown
模块
- 只做到了分行;
- 表格,-,和空格还没能无缝转换
- 代码如下:
import os
import codecs
import markdown
def convert_markdown_to_html(markdown_file):
with codecs.open(markdown_file,'r',encoding='utf-8') as file:
markdown_text = file.read()
html_text = markdown.markdown(markdown_text,extensions=['nl2br'])
html_file = os.path.splitext(markdown_file)[0] + '.html'
with codecs.open(html_file,'w',encoding='utf-8') as file:
file.write(html_text)
markdown_file = ".//test.md"
convert_markdown_to_html(markdown_file)