python读取markdown文件内容

2024-02-24 14:03 python读取markdown文件内容已关闭评论

一、安装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元,扫一扫支付后添加微信提供帮助!(如不能解决您的问题,可以申请退款)

你可能感兴趣的文章

来源:每日教程每日一例,深入学习实用技术教程,关注公众号TeachCourse
转载请注明出处: https://www.teachcourse.cn/3004.html ,谢谢支持!

资源分享

分类:WordPress 标签:,
一个例子让我理解WebViewClient各方法重写的作用 一个例子让我理解WebViewClie
生活杂谈之网站SEO优化方法-卢松松外链工具 生活杂谈之网站SEO优化方法-卢
关于universal imageloader缓存你需要知道的秘密 关于universal imageloader缓存你
python库tkinter实现选择多文件上传 python库tkinter实现选择多文件上

评论已关闭!