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

你可能感兴趣的文章

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

资源分享

分类:WordPress 标签:,
ubuntu系统一键快速安装shadowsocks-libev服务完整教程,小白也会用 ubuntu系统一键快速安装shadowso
OpenTelemetry 可观测性实战:从零搭建全链路追踪系统 OpenTelemetry 可观测性实战:
Genymotion启动提示”Unable to start the virtual device“ Genymotion启动提示”Unable t
Open Claw Qwen 模型配置指南 Open Claw Qwen 模型配置指南

评论已关闭!