一、安装markdwon依赖
pip install markdown
二、将markdown内容转为html
def read_md_file(file_path):
with open(file_path, 'r', encoding='UTF-8') as file:
text = file.read()
html = markdown.markdown(text)
return html
需要注意,如果文件为UTF-8格式,需要指定.md
文件的编码格式,否则运行报错
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa1 in position 23: illegal multibyte sequence
当前文章价值2.14元,扫一扫支付后添加微信提供帮助!(如不能解决您的问题,可以申请退款)
评论已关闭!